@rocicorp/zero 0.25.0-canary.9 → 0.25.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 (517) hide show
  1. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  2. package/out/analyze-query/src/run-ast.d.ts +1 -1
  3. package/out/analyze-query/src/run-ast.d.ts.map +1 -1
  4. package/out/analyze-query/src/run-ast.js +10 -8
  5. package/out/analyze-query/src/run-ast.js.map +1 -1
  6. package/out/otel/src/log-options.d.ts +1 -1
  7. package/out/otel/src/log-options.d.ts.map +1 -1
  8. package/out/otel/src/log-options.js +0 -1
  9. package/out/otel/src/log-options.js.map +1 -1
  10. package/out/replicache/src/persist/idb-databases-store.d.ts +1 -0
  11. package/out/replicache/src/persist/idb-databases-store.d.ts.map +1 -1
  12. package/out/replicache/src/persist/idb-databases-store.js +13 -2
  13. package/out/replicache/src/persist/idb-databases-store.js.map +1 -1
  14. package/out/shared/src/deep-merge.d.ts +6 -4
  15. package/out/shared/src/deep-merge.d.ts.map +1 -1
  16. package/out/shared/src/deep-merge.js +2 -1
  17. package/out/shared/src/deep-merge.js.map +1 -1
  18. package/out/shared/src/iterables.d.ts +0 -1
  19. package/out/shared/src/iterables.d.ts.map +1 -1
  20. package/out/shared/src/iterables.js +0 -34
  21. package/out/shared/src/iterables.js.map +1 -1
  22. package/out/shared/src/options-types.d.ts +113 -0
  23. package/out/shared/src/options-types.d.ts.map +1 -0
  24. package/out/shared/src/options.d.ts +2 -111
  25. package/out/shared/src/options.d.ts.map +1 -1
  26. package/out/shared/src/options.js.map +1 -1
  27. package/out/shared/src/record-proxy.d.ts +13 -0
  28. package/out/shared/src/record-proxy.d.ts.map +1 -0
  29. package/out/shared/src/record-proxy.js +59 -0
  30. package/out/shared/src/record-proxy.js.map +1 -0
  31. package/out/z2s/src/compiler.d.ts.map +1 -1
  32. package/out/z2s/src/compiler.js +4 -2
  33. package/out/z2s/src/compiler.js.map +1 -1
  34. package/out/zero/package.json.js +1 -1
  35. package/out/zero/src/adapters/drizzle.d.ts +1 -1
  36. package/out/zero/src/adapters/drizzle.d.ts.map +1 -1
  37. package/out/zero/src/adapters/drizzle.js +4 -1
  38. package/out/zero/src/bindings.d.ts +2 -0
  39. package/out/zero/src/bindings.d.ts.map +1 -0
  40. package/out/zero/src/bindings.js +27 -0
  41. package/out/zero/src/bindings.js.map +1 -0
  42. package/out/zero/src/pg.js +7 -5
  43. package/out/zero/src/react.js +2 -4
  44. package/out/zero/src/react.js.map +1 -1
  45. package/out/zero/src/server.js +7 -5
  46. package/out/zero/src/solid.js +2 -2
  47. package/out/zero/src/zero-cache-dev.js +11 -5
  48. package/out/zero/src/zero-cache-dev.js.map +1 -1
  49. package/out/zero/src/zero.js +6 -6
  50. package/out/zero-cache/src/auth/read-authorizer.d.ts +1 -1
  51. package/out/zero-cache/src/auth/read-authorizer.d.ts.map +1 -1
  52. package/out/zero-cache/src/auth/read-authorizer.js +1 -1
  53. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  54. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  55. package/out/zero-cache/src/auth/write-authorizer.js +25 -17
  56. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  57. package/out/zero-cache/src/config/zero-config.d.ts +40 -4
  58. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  59. package/out/zero-cache/src/config/zero-config.js +58 -19
  60. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  61. package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
  62. package/out/zero-cache/src/db/transaction-pool.js +3 -6
  63. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  64. package/out/zero-cache/src/scripts/deploy-permissions.js +6 -3
  65. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  66. package/out/zero-cache/src/scripts/permissions.d.ts.map +1 -1
  67. package/out/zero-cache/src/scripts/permissions.js +11 -13
  68. package/out/zero-cache/src/scripts/permissions.js.map +1 -1
  69. package/out/zero-cache/src/server/anonymous-otel-start.d.ts +10 -1
  70. package/out/zero-cache/src/server/anonymous-otel-start.d.ts.map +1 -1
  71. package/out/zero-cache/src/server/anonymous-otel-start.js +34 -18
  72. package/out/zero-cache/src/server/anonymous-otel-start.js.map +1 -1
  73. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  74. package/out/zero-cache/src/server/change-streamer.js +2 -8
  75. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  76. package/out/zero-cache/src/server/otel-diag-logger.d.ts.map +1 -1
  77. package/out/zero-cache/src/server/otel-diag-logger.js +1 -21
  78. package/out/zero-cache/src/server/otel-diag-logger.js.map +1 -1
  79. package/out/zero-cache/src/server/otel-start.d.ts.map +1 -1
  80. package/out/zero-cache/src/server/otel-start.js +1 -5
  81. package/out/zero-cache/src/server/otel-start.js.map +1 -1
  82. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  83. package/out/zero-cache/src/server/syncer.js +7 -1
  84. package/out/zero-cache/src/server/syncer.js.map +1 -1
  85. package/out/zero-cache/src/services/analyze.d.ts +2 -2
  86. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  87. package/out/zero-cache/src/services/analyze.js +55 -42
  88. package/out/zero-cache/src/services/analyze.js.map +1 -1
  89. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  90. package/out/zero-cache/src/services/change-source/pg/change-source.js +62 -42
  91. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  92. package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts.map +1 -1
  93. package/out/zero-cache/src/services/change-source/pg/schema/published.js +3 -2
  94. package/out/zero-cache/src/services/change-source/pg/schema/published.js.map +1 -1
  95. package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts +1 -0
  96. package/out/zero-cache/src/services/change-source/protocol/current/control.d.ts.map +1 -1
  97. package/out/zero-cache/src/services/change-source/protocol/current/control.js +5 -1
  98. package/out/zero-cache/src/services/change-source/protocol/current/control.js.map +1 -1
  99. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +2 -0
  100. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  101. package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts +8 -0
  102. package/out/zero-cache/src/services/change-source/protocol/current/json.d.ts.map +1 -0
  103. package/out/zero-cache/src/services/change-source/protocol/current/json.js +19 -0
  104. package/out/zero-cache/src/services/change-source/protocol/current/json.js.map +1 -0
  105. package/out/zero-cache/src/services/change-source/protocol/current.d.ts +1 -0
  106. package/out/zero-cache/src/services/change-source/protocol/current.d.ts.map +1 -1
  107. package/out/zero-cache/src/services/change-source/protocol/current.js +3 -0
  108. package/out/zero-cache/src/services/change-source/protocol/current.js.map +1 -1
  109. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +0 -2
  110. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  111. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +0 -5
  112. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  113. package/out/zero-cache/src/services/change-streamer/change-streamer-service.d.ts.map +1 -1
  114. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +8 -1
  115. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  116. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  117. package/out/zero-cache/src/services/change-streamer/storer.js +2 -3
  118. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  119. package/out/zero-cache/src/services/http-service.d.ts +0 -1
  120. package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
  121. package/out/zero-cache/src/services/http-service.js +0 -4
  122. package/out/zero-cache/src/services/http-service.js.map +1 -1
  123. package/out/zero-cache/src/services/litestream/commands.js +3 -2
  124. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  125. package/out/zero-cache/src/services/mutagen/pusher.d.ts +4 -4
  126. package/out/zero-cache/src/services/replicator/replication-status.d.ts +2 -0
  127. package/out/zero-cache/src/services/replicator/replication-status.d.ts.map +1 -1
  128. package/out/zero-cache/src/services/replicator/replication-status.js +14 -1
  129. package/out/zero-cache/src/services/replicator/replication-status.js.map +1 -1
  130. package/out/zero-cache/src/services/run-ast.d.ts +1 -1
  131. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  132. package/out/zero-cache/src/services/run-ast.js +5 -1
  133. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  134. package/out/zero-cache/src/services/view-syncer/active-users-gauge.d.ts +2 -1
  135. package/out/zero-cache/src/services/view-syncer/active-users-gauge.d.ts.map +1 -1
  136. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js +26 -13
  137. package/out/zero-cache/src/services/view-syncer/active-users-gauge.js.map +1 -1
  138. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts +1 -1
  139. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
  140. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +39 -15
  141. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  142. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +4 -1
  143. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  144. package/out/zero-cache/src/services/view-syncer/cvr-store.js +31 -9
  145. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  146. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +3 -0
  147. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  148. package/out/zero-cache/src/services/view-syncer/cvr.js +11 -0
  149. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  150. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +1 -1
  151. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  152. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +11 -11
  153. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  154. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +81 -27
  155. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  156. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts +1 -0
  157. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts.map +1 -1
  158. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +23 -10
  159. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  160. package/out/zero-cache/src/services/view-syncer/schema/init.d.ts.map +1 -1
  161. package/out/zero-cache/src/services/view-syncer/schema/init.js +31 -1
  162. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
  163. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts +2 -2
  164. package/out/zero-cache/src/services/view-syncer/snapshotter.d.ts.map +1 -1
  165. package/out/zero-cache/src/services/view-syncer/snapshotter.js +19 -4
  166. package/out/zero-cache/src/services/view-syncer/snapshotter.js.map +1 -1
  167. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +2 -1
  168. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  169. package/out/zero-cache/src/services/view-syncer/view-syncer.js +31 -29
  170. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  171. package/out/zero-cache/src/workers/connect-params.d.ts +1 -0
  172. package/out/zero-cache/src/workers/connect-params.d.ts.map +1 -1
  173. package/out/zero-cache/src/workers/connect-params.js +2 -0
  174. package/out/zero-cache/src/workers/connect-params.js.map +1 -1
  175. package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
  176. package/out/zero-cache/src/workers/syncer-ws-message-handler.js +2 -0
  177. package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
  178. package/out/zero-client/src/client/bindings.d.ts +12 -42
  179. package/out/zero-client/src/client/bindings.d.ts.map +1 -1
  180. package/out/zero-client/src/client/connection-manager.d.ts +3 -3
  181. package/out/zero-client/src/client/connection-manager.d.ts.map +1 -1
  182. package/out/zero-client/src/client/connection-manager.js.map +1 -1
  183. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  184. package/out/zero-client/src/client/connection.js +8 -1
  185. package/out/zero-client/src/client/connection.js.map +1 -1
  186. package/out/zero-client/src/client/crud-impl.d.ts +11 -0
  187. package/out/zero-client/src/client/crud-impl.d.ts.map +1 -0
  188. package/out/zero-client/src/client/crud-impl.js +102 -0
  189. package/out/zero-client/src/client/crud-impl.js.map +1 -0
  190. package/out/zero-client/src/client/crud.d.ts +10 -42
  191. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  192. package/out/zero-client/src/client/crud.js +28 -110
  193. package/out/zero-client/src/client/crud.js.map +1 -1
  194. package/out/zero-client/src/client/custom.d.ts +11 -6
  195. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  196. package/out/zero-client/src/client/custom.js +12 -53
  197. package/out/zero-client/src/client/custom.js.map +1 -1
  198. package/out/zero-client/src/client/delete-clients-manager.d.ts +1 -1
  199. package/out/zero-client/src/client/delete-clients-manager.d.ts.map +1 -1
  200. package/out/zero-client/src/client/delete-clients-manager.js +30 -3
  201. package/out/zero-client/src/client/delete-clients-manager.js.map +1 -1
  202. package/out/zero-client/src/client/error.d.ts +6 -1
  203. package/out/zero-client/src/client/error.d.ts.map +1 -1
  204. package/out/zero-client/src/client/error.js +2 -2
  205. package/out/zero-client/src/client/error.js.map +1 -1
  206. package/out/zero-client/src/client/ivm-branch.d.ts.map +1 -1
  207. package/out/zero-client/src/client/ivm-branch.js +20 -13
  208. package/out/zero-client/src/client/ivm-branch.js.map +1 -1
  209. package/out/zero-client/src/client/make-mutate-property.d.ts +6 -9
  210. package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -1
  211. package/out/zero-client/src/client/make-mutate-property.js +5 -10
  212. package/out/zero-client/src/client/make-mutate-property.js.map +1 -1
  213. package/out/zero-client/src/client/make-replicache-mutators.d.ts +2 -2
  214. package/out/zero-client/src/client/make-replicache-mutators.d.ts.map +1 -1
  215. package/out/zero-client/src/client/make-replicache-mutators.js +16 -11
  216. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -1
  217. package/out/zero-client/src/client/mutator-proxy.d.ts +3 -2
  218. package/out/zero-client/src/client/mutator-proxy.d.ts.map +1 -1
  219. package/out/zero-client/src/client/mutator-proxy.js +16 -5
  220. package/out/zero-client/src/client/mutator-proxy.js.map +1 -1
  221. package/out/zero-client/src/client/options.d.ts +5 -4
  222. package/out/zero-client/src/client/options.d.ts.map +1 -1
  223. package/out/zero-client/src/client/options.js.map +1 -1
  224. package/out/zero-client/src/client/version.js +1 -1
  225. package/out/zero-client/src/client/zero.d.ts +27 -13
  226. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  227. package/out/zero-client/src/client/zero.js +81 -40
  228. package/out/zero-client/src/client/zero.js.map +1 -1
  229. package/out/zero-client/src/mod.d.ts +17 -16
  230. package/out/zero-client/src/mod.d.ts.map +1 -1
  231. package/out/zero-events/src/status.d.ts +1 -1
  232. package/out/zero-events/src/status.d.ts.map +1 -1
  233. package/out/zero-protocol/src/analyze-query-result.d.ts +2 -2
  234. package/out/zero-protocol/src/analyze-query-result.js +2 -2
  235. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  236. package/out/zero-protocol/src/down.d.ts +2 -2
  237. package/out/zero-protocol/src/inspect-down.d.ts +6 -6
  238. package/out/zero-protocol/src/inspect-up.d.ts +4 -4
  239. package/out/zero-protocol/src/inspect-up.js +1 -1
  240. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  241. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  242. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  243. package/out/zero-protocol/src/protocol-version.js +1 -1
  244. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  245. package/out/zero-protocol/src/up.d.ts +1 -1
  246. package/out/zero-react/src/bindings.d.ts +2 -0
  247. package/out/zero-react/src/bindings.d.ts.map +1 -0
  248. package/out/zero-react/src/mod.d.ts +1 -10
  249. package/out/zero-react/src/mod.d.ts.map +1 -1
  250. package/out/zero-react/src/{use-zero-connection-state.d.ts → use-connection-state.d.ts} +3 -3
  251. package/out/zero-react/src/use-connection-state.d.ts.map +1 -0
  252. package/out/zero-react/src/{use-zero-connection-state.js → use-connection-state.js} +3 -3
  253. package/out/zero-react/src/use-connection-state.js.map +1 -0
  254. package/out/zero-react/src/use-query.d.ts +4 -10
  255. package/out/zero-react/src/use-query.d.ts.map +1 -1
  256. package/out/zero-react/src/use-query.js +26 -21
  257. package/out/zero-react/src/use-query.js.map +1 -1
  258. package/out/zero-react/src/use-zero-online.d.ts +1 -1
  259. package/out/zero-react/src/use-zero-online.js.map +1 -1
  260. package/out/zero-react/src/zero-provider.d.ts +17 -10
  261. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  262. package/out/zero-react/src/zero-provider.js +19 -1
  263. package/out/zero-react/src/zero-provider.js.map +1 -1
  264. package/out/zero-react/src/zero.d.ts +2 -0
  265. package/out/zero-react/src/zero.d.ts.map +1 -0
  266. package/out/zero-schema/src/compiled-permissions.d.ts +22 -2
  267. package/out/zero-schema/src/compiled-permissions.d.ts.map +1 -1
  268. package/out/zero-schema/src/compiled-permissions.js +7 -6
  269. package/out/zero-schema/src/compiled-permissions.js.map +1 -1
  270. package/out/zero-schema/src/permissions.d.ts +11 -8
  271. package/out/zero-schema/src/permissions.d.ts.map +1 -1
  272. package/out/zero-schema/src/permissions.js +2 -8
  273. package/out/zero-schema/src/permissions.js.map +1 -1
  274. package/out/zero-schema/src/schema-config.d.ts +0 -5
  275. package/out/zero-schema/src/schema-config.d.ts.map +1 -1
  276. package/out/zero-schema/src/schema-config.js +1 -1
  277. package/out/zero-schema/src/schema-config.js.map +1 -1
  278. package/out/zero-server/src/custom.d.ts +41 -14
  279. package/out/zero-server/src/custom.d.ts.map +1 -1
  280. package/out/zero-server/src/custom.js +129 -37
  281. package/out/zero-server/src/custom.js.map +1 -1
  282. package/out/zero-server/src/mod.d.ts +1 -1
  283. package/out/zero-server/src/mod.d.ts.map +1 -1
  284. package/out/zero-server/src/process-mutations.d.ts +10 -6
  285. package/out/zero-server/src/process-mutations.d.ts.map +1 -1
  286. package/out/zero-server/src/process-mutations.js +9 -18
  287. package/out/zero-server/src/process-mutations.js.map +1 -1
  288. package/out/zero-server/src/push-processor.d.ts.map +1 -1
  289. package/out/zero-server/src/push-processor.js +10 -8
  290. package/out/zero-server/src/push-processor.js.map +1 -1
  291. package/out/zero-server/src/queries/process-queries.d.ts +14 -2
  292. package/out/zero-server/src/queries/process-queries.d.ts.map +1 -1
  293. package/out/zero-server/src/queries/process-queries.js +18 -15
  294. package/out/zero-server/src/queries/process-queries.js.map +1 -1
  295. package/out/zero-server/src/zql-database.d.ts +6 -6
  296. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  297. package/out/zero-server/src/zql-database.js +5 -17
  298. package/out/zero-server/src/zql-database.js.map +1 -1
  299. package/out/zero-solid/src/bindings.d.ts +2 -0
  300. package/out/zero-solid/src/bindings.d.ts.map +1 -0
  301. package/out/zero-solid/src/mod.d.ts +1 -8
  302. package/out/zero-solid/src/mod.d.ts.map +1 -1
  303. package/out/zero-solid/src/solid-view.d.ts +3 -5
  304. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  305. package/out/zero-solid/src/solid-view.js +9 -6
  306. package/out/zero-solid/src/solid-view.js.map +1 -1
  307. package/out/zero-solid/src/{use-zero-connection-state.d.ts → use-connection-state.d.ts} +3 -3
  308. package/out/zero-solid/src/use-connection-state.d.ts.map +1 -0
  309. package/out/zero-solid/src/{use-zero-connection-state.js → use-connection-state.js} +3 -3
  310. package/out/zero-solid/src/use-connection-state.js.map +1 -0
  311. package/out/zero-solid/src/use-query.d.ts +3 -6
  312. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  313. package/out/zero-solid/src/use-query.js +44 -11
  314. package/out/zero-solid/src/use-query.js.map +1 -1
  315. package/out/zero-solid/src/use-zero-online.d.ts +1 -1
  316. package/out/zero-solid/src/use-zero-online.js.map +1 -1
  317. package/out/zero-solid/src/use-zero.d.ts +19 -9
  318. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  319. package/out/zero-solid/src/use-zero.js +17 -1
  320. package/out/zero-solid/src/use-zero.js.map +1 -1
  321. package/out/zero-solid/src/zero.d.ts +2 -0
  322. package/out/zero-solid/src/zero.d.ts.map +1 -0
  323. package/out/zero-types/src/default-types.d.ts +38 -0
  324. package/out/zero-types/src/default-types.d.ts.map +1 -0
  325. package/out/zero-types/src/schema.d.ts +4 -4
  326. package/out/zql/src/builder/builder.d.ts.map +1 -1
  327. package/out/zql/src/builder/builder.js +1 -13
  328. package/out/zql/src/builder/builder.js.map +1 -1
  329. package/out/zql/src/error.js +1 -10
  330. package/out/zql/src/error.js.map +1 -1
  331. package/out/zql/src/ivm/array-view.d.ts +2 -2
  332. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  333. package/out/zql/src/ivm/array-view.js +4 -1
  334. package/out/zql/src/ivm/array-view.js.map +1 -1
  335. package/out/zql/src/ivm/data.d.ts +7 -2
  336. package/out/zql/src/ivm/data.d.ts.map +1 -1
  337. package/out/zql/src/ivm/data.js +0 -8
  338. package/out/zql/src/ivm/data.js.map +1 -1
  339. package/out/zql/src/ivm/exists.d.ts +6 -4
  340. package/out/zql/src/ivm/exists.d.ts.map +1 -1
  341. package/out/zql/src/ivm/exists.js +60 -91
  342. package/out/zql/src/ivm/exists.js.map +1 -1
  343. package/out/zql/src/ivm/fan-in.d.ts +5 -3
  344. package/out/zql/src/ivm/fan-in.d.ts.map +1 -1
  345. package/out/zql/src/ivm/fan-in.js +12 -5
  346. package/out/zql/src/ivm/fan-in.js.map +1 -1
  347. package/out/zql/src/ivm/fan-out.d.ts +4 -2
  348. package/out/zql/src/ivm/fan-out.d.ts.map +1 -1
  349. package/out/zql/src/ivm/fan-out.js +16 -6
  350. package/out/zql/src/ivm/fan-out.js.map +1 -1
  351. package/out/zql/src/ivm/filter-operators.d.ts +13 -11
  352. package/out/zql/src/ivm/filter-operators.d.ts.map +1 -1
  353. package/out/zql/src/ivm/filter-operators.js +27 -24
  354. package/out/zql/src/ivm/filter-operators.js.map +1 -1
  355. package/out/zql/src/ivm/filter-push.d.ts +2 -1
  356. package/out/zql/src/ivm/filter-push.d.ts.map +1 -1
  357. package/out/zql/src/ivm/filter-push.js +5 -5
  358. package/out/zql/src/ivm/filter-push.js.map +1 -1
  359. package/out/zql/src/ivm/filter.d.ts +4 -2
  360. package/out/zql/src/ivm/filter.d.ts.map +1 -1
  361. package/out/zql/src/ivm/filter.js +10 -4
  362. package/out/zql/src/ivm/filter.js.map +1 -1
  363. package/out/zql/src/ivm/flipped-join.d.ts +1 -2
  364. package/out/zql/src/ivm/flipped-join.d.ts.map +1 -1
  365. package/out/zql/src/ivm/flipped-join.js +133 -103
  366. package/out/zql/src/ivm/flipped-join.js.map +1 -1
  367. package/out/zql/src/ivm/join-utils.d.ts +9 -2
  368. package/out/zql/src/ivm/join-utils.d.ts.map +1 -1
  369. package/out/zql/src/ivm/join-utils.js +20 -0
  370. package/out/zql/src/ivm/join-utils.js.map +1 -1
  371. package/out/zql/src/ivm/join.d.ts +3 -16
  372. package/out/zql/src/ivm/join.d.ts.map +1 -1
  373. package/out/zql/src/ivm/join.js +62 -128
  374. package/out/zql/src/ivm/join.js.map +1 -1
  375. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts +1 -1
  376. package/out/zql/src/ivm/maybe-split-and-push-edit-change.d.ts.map +1 -1
  377. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js +4 -4
  378. package/out/zql/src/ivm/maybe-split-and-push-edit-change.js.map +1 -1
  379. package/out/zql/src/ivm/memory-source.d.ts +7 -6
  380. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  381. package/out/zql/src/ivm/memory-source.js +39 -28
  382. package/out/zql/src/ivm/memory-source.js.map +1 -1
  383. package/out/zql/src/ivm/operator.d.ts +15 -12
  384. package/out/zql/src/ivm/operator.d.ts.map +1 -1
  385. package/out/zql/src/ivm/operator.js +8 -0
  386. package/out/zql/src/ivm/operator.js.map +1 -1
  387. package/out/zql/src/ivm/push-accumulated.d.ts +2 -2
  388. package/out/zql/src/ivm/push-accumulated.d.ts.map +1 -1
  389. package/out/zql/src/ivm/push-accumulated.js +8 -8
  390. package/out/zql/src/ivm/push-accumulated.js.map +1 -1
  391. package/out/zql/src/ivm/skip.d.ts +2 -3
  392. package/out/zql/src/ivm/skip.d.ts.map +1 -1
  393. package/out/zql/src/ivm/skip.js +14 -11
  394. package/out/zql/src/ivm/skip.js.map +1 -1
  395. package/out/zql/src/ivm/source.d.ts +15 -7
  396. package/out/zql/src/ivm/source.d.ts.map +1 -1
  397. package/out/zql/src/ivm/stream.d.ts +2 -0
  398. package/out/zql/src/ivm/stream.d.ts.map +1 -1
  399. package/out/zql/src/ivm/stream.js +5 -14
  400. package/out/zql/src/ivm/stream.js.map +1 -1
  401. package/out/zql/src/ivm/take.d.ts +2 -3
  402. package/out/zql/src/ivm/take.d.ts.map +1 -1
  403. package/out/zql/src/ivm/take.js +168 -140
  404. package/out/zql/src/ivm/take.js.map +1 -1
  405. package/out/zql/src/ivm/union-fan-in.d.ts +4 -4
  406. package/out/zql/src/ivm/union-fan-in.d.ts.map +1 -1
  407. package/out/zql/src/ivm/union-fan-in.js +74 -15
  408. package/out/zql/src/ivm/union-fan-in.js.map +1 -1
  409. package/out/zql/src/ivm/union-fan-out.d.ts +2 -3
  410. package/out/zql/src/ivm/union-fan-out.d.ts.map +1 -1
  411. package/out/zql/src/ivm/union-fan-out.js +3 -6
  412. package/out/zql/src/ivm/union-fan-out.js.map +1 -1
  413. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  414. package/out/zql/src/ivm/view-apply-change.js +4 -4
  415. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  416. package/out/zql/src/ivm/view.d.ts +2 -2
  417. package/out/zql/src/ivm/view.d.ts.map +1 -1
  418. package/out/zql/src/mutate/crud.d.ts +116 -0
  419. package/out/zql/src/mutate/crud.d.ts.map +1 -0
  420. package/out/zql/src/mutate/crud.js +41 -0
  421. package/out/zql/src/mutate/crud.js.map +1 -0
  422. package/out/zql/src/mutate/custom.d.ts +24 -62
  423. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  424. package/out/zql/src/mutate/custom.js +1 -5
  425. package/out/zql/src/mutate/custom.js.map +1 -1
  426. package/out/zql/src/mutate/mutator-registry.d.ts +43 -73
  427. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  428. package/out/zql/src/mutate/mutator-registry.js +25 -34
  429. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  430. package/out/zql/src/mutate/mutator.d.ts +60 -64
  431. package/out/zql/src/mutate/mutator.d.ts.map +1 -1
  432. package/out/zql/src/mutate/mutator.js +8 -9
  433. package/out/zql/src/mutate/mutator.js.map +1 -1
  434. package/out/zql/src/planner/planner-builder.d.ts +2 -1
  435. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  436. package/out/zql/src/planner/planner-builder.js +5 -5
  437. package/out/zql/src/planner/planner-builder.js.map +1 -1
  438. package/out/zql/src/planner/planner-debug.d.ts +3 -3
  439. package/out/zql/src/planner/planner-debug.js.map +1 -1
  440. package/out/zql/src/planner/planner-graph.d.ts +3 -1
  441. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  442. package/out/zql/src/planner/planner-graph.js +5 -5
  443. package/out/zql/src/planner/planner-graph.js.map +1 -1
  444. package/out/zql/src/planner/planner-join.d.ts.map +1 -1
  445. package/out/zql/src/planner/planner-join.js +3 -1
  446. package/out/zql/src/planner/planner-join.js.map +1 -1
  447. package/out/zql/src/query/create-builder.d.ts +4 -1
  448. package/out/zql/src/query/create-builder.d.ts.map +1 -1
  449. package/out/zql/src/query/create-builder.js +24 -36
  450. package/out/zql/src/query/create-builder.js.map +1 -1
  451. package/out/zql/src/query/expression.d.ts +5 -5
  452. package/out/zql/src/query/expression.d.ts.map +1 -1
  453. package/out/zql/src/query/expression.js.map +1 -1
  454. package/out/zql/src/query/measure-push-operator.d.ts +2 -3
  455. package/out/zql/src/query/measure-push-operator.d.ts.map +1 -1
  456. package/out/zql/src/query/measure-push-operator.js +2 -5
  457. package/out/zql/src/query/measure-push-operator.js.map +1 -1
  458. package/out/zql/src/query/query-delegate-base.d.ts +12 -6
  459. package/out/zql/src/query/query-delegate-base.d.ts.map +1 -1
  460. package/out/zql/src/query/query-delegate-base.js +132 -2
  461. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  462. package/out/zql/src/query/query-delegate.d.ts +6 -6
  463. package/out/zql/src/query/query-delegate.d.ts.map +1 -1
  464. package/out/zql/src/query/query-impl.d.ts +27 -28
  465. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  466. package/out/zql/src/query/query-impl.js +41 -168
  467. package/out/zql/src/query/query-impl.js.map +1 -1
  468. package/out/zql/src/query/query-internals.d.ts +6 -6
  469. package/out/zql/src/query/query-internals.d.ts.map +1 -1
  470. package/out/zql/src/query/query-internals.js +2 -2
  471. package/out/zql/src/query/query-internals.js.map +1 -1
  472. package/out/zql/src/query/query-registry.d.ts +108 -122
  473. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  474. package/out/zql/src/query/query-registry.js +43 -53
  475. package/out/zql/src/query/query-registry.js.map +1 -1
  476. package/out/zql/src/query/query.d.ts +63 -37
  477. package/out/zql/src/query/query.d.ts.map +1 -1
  478. package/out/zql/src/query/runnable-query-impl.d.ts +22 -0
  479. package/out/zql/src/query/runnable-query-impl.d.ts.map +1 -0
  480. package/out/zql/src/query/runnable-query-impl.js +60 -0
  481. package/out/zql/src/query/runnable-query-impl.js.map +1 -0
  482. package/out/zql/src/query/schema-query.d.ts +2 -1
  483. package/out/zql/src/query/schema-query.d.ts.map +1 -1
  484. package/out/zql/src/query/static-query.d.ts +2 -15
  485. package/out/zql/src/query/static-query.d.ts.map +1 -1
  486. package/out/zql/src/query/static-query.js +10 -37
  487. package/out/zql/src/query/static-query.js.map +1 -1
  488. package/out/zqlite/src/internal/sql-inline.d.ts +13 -0
  489. package/out/zqlite/src/internal/sql-inline.d.ts.map +1 -0
  490. package/out/zqlite/src/internal/sql-inline.js +45 -0
  491. package/out/zqlite/src/internal/sql-inline.js.map +1 -0
  492. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  493. package/out/zqlite/src/sqlite-cost-model.js +2 -2
  494. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  495. package/out/zqlite/src/table-source.d.ts +10 -3
  496. package/out/zqlite/src/table-source.d.ts.map +1 -1
  497. package/out/zqlite/src/table-source.js +42 -23
  498. package/out/zqlite/src/table-source.js.map +1 -1
  499. package/package.json +9 -5
  500. package/out/zero-client/src/client/bindings.js +0 -33
  501. package/out/zero-client/src/client/bindings.js.map +0 -1
  502. package/out/zero-react/src/components/inspector.d.ts +0 -9
  503. package/out/zero-react/src/components/inspector.d.ts.map +0 -1
  504. package/out/zero-react/src/components/inspector.js +0 -38
  505. package/out/zero-react/src/components/inspector.js.map +0 -1
  506. package/out/zero-react/src/components/mark-icon.d.ts +0 -3
  507. package/out/zero-react/src/components/mark-icon.d.ts.map +0 -1
  508. package/out/zero-react/src/components/mark-icon.js +0 -28
  509. package/out/zero-react/src/components/mark-icon.js.map +0 -1
  510. package/out/zero-react/src/components/zero-inspector.d.ts +0 -8
  511. package/out/zero-react/src/components/zero-inspector.d.ts.map +0 -1
  512. package/out/zero-react/src/components/zero-inspector.js +0 -44
  513. package/out/zero-react/src/components/zero-inspector.js.map +0 -1
  514. package/out/zero-react/src/use-zero-connection-state.d.ts.map +0 -1
  515. package/out/zero-react/src/use-zero-connection-state.js.map +0 -1
  516. package/out/zero-solid/src/use-zero-connection-state.d.ts.map +0 -1
  517. package/out/zero-solid/src/use-zero-connection-state.js.map +0 -1
@@ -7,6 +7,7 @@ import { assertOrderingIncludesPK } from "../query/complete-ordering.js";
7
7
  import { constraintMatchesRow, primaryKeyConstraintFromFilters, constraintMatchesPrimaryKey } from "./constraint.js";
8
8
  import { valuesEqual, makeComparator, compareValues } from "./data.js";
9
9
  import { filterPush } from "./filter-push.js";
10
+ import { skipYields } from "./operator.js";
10
11
  class MemorySource {
11
12
  #tableName;
12
13
  #columns;
@@ -15,6 +16,7 @@ class MemorySource {
15
16
  #indexes = /* @__PURE__ */ new Map();
16
17
  #connections = [];
17
18
  #overlay;
19
+ #pushEpoch = 0;
18
20
  constructor(tableName, columns, primaryKey, primaryIndexData) {
19
21
  this.#tableName = tableName;
20
22
  this.#columns = columns;
@@ -63,7 +65,6 @@ class MemorySource {
63
65
  const input = {
64
66
  getSchema: () => schema,
65
67
  fetch: (req) => this.#fetch(req, connection),
66
- cleanup: (req) => this.#cleanup(req, connection),
67
68
  setOutput: (output) => {
68
69
  connection.output = output;
69
70
  },
@@ -81,7 +82,8 @@ class MemorySource {
81
82
  filters: transformedFilters.filters ? {
82
83
  condition: transformedFilters.filters,
83
84
  predicate: createPredicate(transformedFilters.filters)
84
- } : void 0
85
+ } : void 0,
86
+ lastPushedEpoch: 0
85
87
  };
86
88
  const schema = this.#getSchema(connection);
87
89
  assertOrderingIncludesPK(sort, this.#primaryKey);
@@ -118,10 +120,7 @@ class MemorySource {
118
120
  getIndexKeys() {
119
121
  return [...this.#indexes.keys()];
120
122
  }
121
- *#fetch(req, from) {
122
- const callingConnectionIndex = this.#connections.indexOf(from);
123
- assert(callingConnectionIndex !== -1, "Output not found");
124
- const conn = this.#connections[callingConnectionIndex];
123
+ *#fetch(req, conn) {
125
124
  const { sort: requestedSort, compareRows } = conn;
126
125
  const connectionComparator = (r1, r2) => compareRows(r1, r2) * (req.reverse ? -1 : 1);
127
126
  const pkConstraint = primaryKeyConstraintFromFilters(
@@ -138,7 +137,7 @@ class MemorySource {
138
137
  if (this.#primaryKey.length > 1 || !fetchOrPkConstraint || !constraintMatchesPrimaryKey(fetchOrPkConstraint, this.#primaryKey)) {
139
138
  indexSort.push(...requestedSort);
140
139
  }
141
- const index = this.#getOrCreateIndex(indexSort, from);
140
+ const index = this.#getOrCreateIndex(indexSort, conn);
142
141
  const { data, comparator: compare } = index;
143
142
  const indexComparator = (r1, r2) => compare(r1, r2) * (req.reverse ? -1 : 1);
144
143
  const startAt = req.start?.row;
@@ -168,7 +167,7 @@ class MemorySource {
168
167
  // rather than as the fetch constraint.
169
168
  req.constraint,
170
169
  this.#overlay,
171
- callingConnectionIndex,
170
+ conn.lastPushedEpoch,
172
171
  // Use indexComparator, generateWithOverlayInner has a subtle dependency
173
172
  // on this. Since generateWithConstraint is done after
174
173
  // generateWithOverlay, the generator consumed by generateWithOverlayInner
@@ -182,18 +181,20 @@ class MemorySource {
182
181
  conn.filters?.predicate
183
182
  );
184
183
  const withConstraint = generateWithConstraint(
185
- generateWithStart(withOverlay, req.start, connectionComparator),
184
+ skipYields(
185
+ generateWithStart(withOverlay, req.start, connectionComparator)
186
+ ),
186
187
  // we use `req.constraint` and not `fetchOrPkConstraint` here because we need to
187
188
  // AND the constraint with what could have been the primary key constraint
188
189
  req.constraint
189
190
  );
190
191
  yield* conn.filters ? generateWithFilter(withConstraint, conn.filters.predicate) : withConstraint;
191
192
  }
192
- #cleanup(req, connection) {
193
- return this.#fetch(req, connection);
194
- }
195
- push(change) {
196
- for (const _ of this.genPush(change)) {
193
+ *push(change) {
194
+ for (const result of this.genPush(change)) {
195
+ if (result === "yield") {
196
+ yield result;
197
+ }
197
198
  }
198
199
  }
199
200
  *genPush(change) {
@@ -207,7 +208,8 @@ class MemorySource {
207
208
  change,
208
209
  exists,
209
210
  setOverlay,
210
- writeChange
211
+ writeChange,
212
+ () => ++this.#pushEpoch
211
213
  );
212
214
  }
213
215
  #writeChange(change) {
@@ -250,7 +252,7 @@ function* generateWithFilter(it, filter) {
250
252
  }
251
253
  }
252
254
  }
253
- function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay, writeChange) {
255
+ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay, writeChange, getNextEpoch) {
254
256
  let shouldSplitEdit = false;
255
257
  if (change.type === "edit") {
256
258
  for (const { splitEditKeys } of connections) {
@@ -273,7 +275,8 @@ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay,
273
275
  },
274
276
  exists,
275
277
  setOverlay,
276
- writeChange
278
+ writeChange,
279
+ getNextEpoch()
277
280
  );
278
281
  yield* genPushAndWrite(
279
282
  connections,
@@ -283,7 +286,8 @@ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay,
283
286
  },
284
287
  exists,
285
288
  setOverlay,
286
- writeChange
289
+ writeChange,
290
+ getNextEpoch()
287
291
  );
288
292
  } else {
289
293
  yield* genPushAndWrite(
@@ -291,17 +295,18 @@ function* genPushAndWriteWithSplitEdit(connections, change, exists, setOverlay,
291
295
  change,
292
296
  exists,
293
297
  setOverlay,
294
- writeChange
298
+ writeChange,
299
+ getNextEpoch()
295
300
  );
296
301
  }
297
302
  }
298
- function* genPushAndWrite(connections, change, exists, setOverlay, writeChange) {
299
- for (const x of genPush(connections, change, exists, setOverlay)) {
303
+ function* genPushAndWrite(connections, change, exists, setOverlay, writeChange, pushEpoch) {
304
+ for (const x of genPush(connections, change, exists, setOverlay, pushEpoch)) {
300
305
  yield x;
301
306
  }
302
307
  writeChange(change);
303
308
  }
304
- function* genPush(connections, change, exists, setOverlay) {
309
+ function* genPush(connections, change, exists, setOverlay, pushEpoch) {
305
310
  switch (change.type) {
306
311
  case "add":
307
312
  assert(
@@ -318,9 +323,11 @@ function* genPush(connections, change, exists, setOverlay) {
318
323
  default:
319
324
  unreachable();
320
325
  }
321
- for (const [outputIndex, { output, filters, input }] of connections.entries()) {
326
+ for (const conn of connections) {
327
+ const { output, filters, input } = conn;
322
328
  if (output) {
323
- setOverlay({ outputIndex, change });
329
+ conn.lastPushedEpoch = pushEpoch;
330
+ setOverlay({ epoch: pushEpoch, change });
324
331
  const outputChange = change.type === "edit" ? {
325
332
  type: change.type,
326
333
  oldNode: {
@@ -338,8 +345,8 @@ function* genPush(connections, change, exists, setOverlay) {
338
345
  relationships: {}
339
346
  }
340
347
  };
341
- filterPush(outputChange, output, input, filters?.predicate);
342
- yield;
348
+ yield* filterPush(outputChange, output, input, filters?.predicate);
349
+ yield void 0;
343
350
  }
344
351
  }
345
352
  setOverlay(void 0);
@@ -351,6 +358,10 @@ function* generateWithStart(nodes, start, compare) {
351
358
  }
352
359
  let started = false;
353
360
  for (const node of nodes) {
361
+ if (node === "yield") {
362
+ yield node;
363
+ continue;
364
+ }
354
365
  if (!started) {
355
366
  if (start.basis === "at") {
356
367
  if (compare(node.row, start.row) >= 0) {
@@ -367,9 +378,9 @@ function* generateWithStart(nodes, start, compare) {
367
378
  }
368
379
  }
369
380
  }
370
- function* generateWithOverlay(startAt, rows, constraint, overlay, connectionIndex, compare, filterPredicate) {
381
+ function* generateWithOverlay(startAt, rows, constraint, overlay, lastPushedEpoch, compare, filterPredicate) {
371
382
  let overlayToApply = void 0;
372
- if (overlay && connectionIndex <= overlay.outputIndex) {
383
+ if (overlay && lastPushedEpoch >= overlay.epoch) {
373
384
  overlayToApply = overlay;
374
385
  }
375
386
  const overlays = computeOverlays(
@@ -1 +1 @@
1
- {"version":3,"file":"memory-source.js","sources":["../../../../../zql/src/ivm/memory-source.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {BTreeSet} from '../../../shared/src/btree-set.ts';\nimport {hasOwn} from '../../../shared/src/has-own.ts';\nimport {once} from '../../../shared/src/iterables.ts';\nimport type {\n Condition,\n Ordering,\n OrderPart,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {PrimaryKey} from '../../../zero-protocol/src/primary-key.ts';\nimport type {SchemaValue} from '../../../zero-types/src/schema-value.ts';\nimport type {DebugDelegate} from '../builder/debug-delegate.ts';\nimport {\n createPredicate,\n transformFilters,\n type NoSubqueryCondition,\n} from '../builder/filter.ts';\nimport {assertOrderingIncludesPK} from '../query/complete-ordering.ts';\nimport type {Change} from './change.ts';\nimport {\n constraintMatchesPrimaryKey,\n constraintMatchesRow,\n primaryKeyConstraintFromFilters,\n type Constraint,\n} from './constraint.ts';\nimport {\n compareValues,\n makeComparator,\n valuesEqual,\n type Comparator,\n type Node,\n} from './data.ts';\nimport {filterPush} from './filter-push.ts';\nimport {\n type FetchRequest,\n type Input,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {\n Source,\n SourceChange,\n SourceChangeAdd,\n SourceChangeEdit,\n SourceChangeRemove,\n SourceInput,\n} from './source.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Overlay = {\n outputIndex: number;\n change: SourceChange;\n};\n\nexport type Overlays = {\n add: Row | undefined;\n remove: Row | undefined;\n};\n\ntype Index = {\n comparator: Comparator;\n data: BTreeSet<Row>;\n usedBy: Set<Connection>;\n};\n\nexport type Connection = {\n input: Input;\n output: Output | undefined;\n sort: Ordering;\n splitEditKeys: Set<string> | undefined;\n compareRows: Comparator;\n filters:\n | {\n condition: NoSubqueryCondition;\n predicate: (row: Row) => boolean;\n }\n | undefined;\n readonly debug?: DebugDelegate | undefined;\n};\n\n/**\n * A `MemorySource` is a source that provides data to the pipeline from an\n * in-memory data source.\n *\n * This data is kept in sorted order as downstream pipelines will always expect\n * the data they receive from `pull` to be in sorted order.\n */\nexport class MemorySource implements Source {\n readonly #tableName: string;\n readonly #columns: Record<string, SchemaValue>;\n readonly #primaryKey: PrimaryKey;\n readonly #primaryIndexSort: Ordering;\n readonly #indexes: Map<string, Index> = new Map();\n readonly #connections: Connection[] = [];\n\n #overlay: Overlay | undefined;\n\n constructor(\n tableName: string,\n columns: Record<string, SchemaValue>,\n primaryKey: PrimaryKey,\n primaryIndexData?: BTreeSet<Row>,\n ) {\n this.#tableName = tableName;\n this.#columns = columns;\n this.#primaryKey = primaryKey;\n this.#primaryIndexSort = primaryKey.map(k => [k, 'asc']);\n const comparator = makeBoundComparator(this.#primaryIndexSort);\n this.#indexes.set(JSON.stringify(this.#primaryIndexSort), {\n comparator,\n data: primaryIndexData ?? new BTreeSet<Row>(comparator),\n usedBy: new Set(),\n });\n }\n\n get tableSchema() {\n return {\n name: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n };\n }\n\n fork() {\n const primaryIndex = this.#getPrimaryIndex();\n return new MemorySource(\n this.#tableName,\n this.#columns,\n this.#primaryKey,\n primaryIndex.data.clone(),\n );\n }\n\n get data(): BTreeSet<Row> {\n return this.#getPrimaryIndex().data;\n }\n\n #getSchema(connection: Connection): SourceSchema {\n return {\n tableName: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n sort: connection.sort,\n system: 'client',\n relationships: {},\n isHidden: false,\n compareRows: connection.compareRows,\n };\n }\n\n connect(\n sort: Ordering,\n filters?: Condition,\n splitEditKeys?: Set<string>,\n ): SourceInput {\n const transformedFilters = transformFilters(filters);\n\n const input: SourceInput = {\n getSchema: () => schema,\n fetch: req => this.#fetch(req, connection),\n cleanup: req => this.#cleanup(req, connection),\n setOutput: output => {\n connection.output = output;\n },\n destroy: () => {\n this.#disconnect(input);\n },\n fullyAppliedFilters: !transformedFilters.conditionsRemoved,\n };\n\n const connection: Connection = {\n input,\n output: undefined,\n sort,\n splitEditKeys,\n compareRows: makeComparator(sort),\n filters: transformedFilters.filters\n ? {\n condition: transformedFilters.filters,\n predicate: createPredicate(transformedFilters.filters),\n }\n : undefined,\n };\n const schema = this.#getSchema(connection);\n assertOrderingIncludesPK(sort, this.#primaryKey);\n this.#connections.push(connection);\n return input;\n }\n\n #disconnect(input: Input): void {\n const idx = this.#connections.findIndex(c => c.input === input);\n assert(idx !== -1, 'Connection not found');\n this.#connections.splice(idx, 1);\n\n // TODO: We used to delete unused indexes here. But in common cases like\n // navigating into issue detail pages it caused a ton of constantly\n // building and destroying indexes.\n //\n // Perhaps some intelligent LRU or something is needed here but for now,\n // the opposite extreme of keeping all indexes for the lifetime of the\n // page seems better.\n }\n\n #getPrimaryIndex(): Index {\n const index = this.#indexes.get(JSON.stringify(this.#primaryIndexSort));\n assert(index, 'Primary index not found');\n return index;\n }\n\n #getOrCreateIndex(sort: Ordering, usedBy: Connection): Index {\n const key = JSON.stringify(sort);\n const index = this.#indexes.get(key);\n // Future optimization could use existing index if it's the same just sorted\n // in reverse of needed.\n if (index) {\n index.usedBy.add(usedBy);\n return index;\n }\n\n const comparator = makeBoundComparator(sort);\n\n // When creating these synchronously becomes a problem, a few options:\n // 1. Allow users to specify needed indexes up front\n // 2. Create indexes in a different thread asynchronously (this would require\n // modifying the BTree to be able to be passed over structured-clone, or using\n // a different library.)\n // 3. We could even theoretically do (2) on multiple threads and then merge the\n // results!\n const data = new BTreeSet<Row>(comparator);\n\n // I checked, there's no special path for adding data in bulk faster.\n // The constructor takes an array, but it just calls add/set over and over.\n for (const row of this.#getPrimaryIndex().data) {\n data.add(row);\n }\n\n const newIndex = {comparator, data, usedBy: new Set([usedBy])};\n this.#indexes.set(key, newIndex);\n return newIndex;\n }\n\n // For unit testing that we correctly clean up indexes.\n getIndexKeys(): string[] {\n return [...this.#indexes.keys()];\n }\n\n *#fetch(req: FetchRequest, from: Connection): Stream<Node> {\n const callingConnectionIndex = this.#connections.indexOf(from);\n assert(callingConnectionIndex !== -1, 'Output not found');\n const conn = this.#connections[callingConnectionIndex];\n const {sort: requestedSort, compareRows} = conn;\n const connectionComparator = (r1: Row, r2: Row) =>\n compareRows(r1, r2) * (req.reverse ? -1 : 1);\n\n const pkConstraint = primaryKeyConstraintFromFilters(\n conn.filters?.condition,\n this.#primaryKey,\n );\n // The primary key constraint will be more limiting than the constraint\n // so swap out to that if it exists.\n const fetchOrPkConstraint = pkConstraint ?? req.constraint;\n\n // If there is a constraint, we need an index sorted by it first.\n const indexSort: OrderPart[] = [];\n if (fetchOrPkConstraint) {\n for (const key of Object.keys(fetchOrPkConstraint)) {\n indexSort.push([key, 'asc']);\n }\n }\n\n // For the special case of constraining by PK, we don't need to worry about\n // any requested sort since there can only be one result. Otherwise we also\n // need the index sorted by the requested sort.\n if (\n this.#primaryKey.length > 1 ||\n !fetchOrPkConstraint ||\n !constraintMatchesPrimaryKey(fetchOrPkConstraint, this.#primaryKey)\n ) {\n indexSort.push(...requestedSort);\n }\n\n const index = this.#getOrCreateIndex(indexSort, from);\n const {data, comparator: compare} = index;\n const indexComparator = (r1: Row, r2: Row) =>\n compare(r1, r2) * (req.reverse ? -1 : 1);\n\n const startAt = req.start?.row;\n\n // If there is a constraint, we want to start our scan at the first row that\n // matches the constraint. But because the next OrderPart can be `desc`,\n // it's not true that {[constraintKey]: constraintValue} is the first\n // matching row. Because in that case, the other fields will all be\n // `undefined`, and in Zero `undefined` is always less than any other value.\n // So if the second OrderPart is descending then `undefined` values will\n // actually be the *last* row. We need a way to stay \"start at the first row\n // with this constraint value\". RowBound with the corresponding compareBound\n // comparator accomplishes this. The right thing is probably to teach the\n // btree library to support this concept.\n let scanStart: RowBound | undefined;\n\n if (fetchOrPkConstraint) {\n scanStart = {};\n for (const [key, dir] of indexSort) {\n if (hasOwn(fetchOrPkConstraint, key)) {\n scanStart[key] = fetchOrPkConstraint[key];\n } else {\n if (req.reverse) {\n scanStart[key] = dir === 'asc' ? maxValue : minValue;\n } else {\n scanStart[key] = dir === 'asc' ? minValue : maxValue;\n }\n }\n }\n } else {\n scanStart = startAt;\n }\n\n const rowsIterable = generateRows(data, scanStart, req.reverse);\n const withOverlay = generateWithOverlay(\n startAt,\n pkConstraint ? once(rowsIterable) : rowsIterable,\n // use `req.constraint` here and not `fetchOrPkConstraint` since `fetchOrPkConstraint` could be the\n // primary key constraint. The primary key constraint comes from filters and is acting as a filter\n // rather than as the fetch constraint.\n req.constraint,\n this.#overlay,\n callingConnectionIndex,\n // Use indexComparator, generateWithOverlayInner has a subtle dependency\n // on this. Since generateWithConstraint is done after\n // generateWithOverlay, the generator consumed by generateWithOverlayInner\n // does not end when the constraint stops matching and so the final\n // check to yield an add overlay if not yet yielded is not reached.\n // However, using the indexComparator the add overlay will be less than\n // the first row that does not match the constraint, and so any\n // not yet yielded add overlay will be yielded when the first row\n // not matching the constraint is reached.\n indexComparator,\n conn.filters?.predicate,\n );\n\n const withConstraint = generateWithConstraint(\n generateWithStart(withOverlay, req.start, connectionComparator),\n // we use `req.constraint` and not `fetchOrPkConstraint` here because we need to\n // AND the constraint with what could have been the primary key constraint\n req.constraint,\n );\n\n yield* conn.filters\n ? generateWithFilter(withConstraint, conn.filters.predicate)\n : withConstraint;\n }\n\n #cleanup(req: FetchRequest, connection: Connection): Stream<Node> {\n return this.#fetch(req, connection);\n }\n\n push(change: SourceChange): void {\n for (const _ of this.genPush(change)) {\n // Nothing to do.\n }\n }\n\n *genPush(change: SourceChange) {\n const primaryIndex = this.#getPrimaryIndex();\n const {data} = primaryIndex;\n const exists = (row: Row) => data.has(row);\n const setOverlay = (o: Overlay | undefined) => (this.#overlay = o);\n const writeChange = (c: SourceChange) => this.#writeChange(c);\n yield* genPushAndWriteWithSplitEdit(\n this.#connections,\n change,\n exists,\n setOverlay,\n writeChange,\n );\n }\n\n #writeChange(change: SourceChange) {\n for (const {data} of this.#indexes.values()) {\n switch (change.type) {\n case 'add': {\n const added = data.add(change.row);\n // must succeed since we checked has() above.\n assert(added);\n break;\n }\n case 'remove': {\n const removed = data.delete(change.row);\n // must succeed since we checked has() above.\n assert(removed);\n break;\n }\n case 'edit': {\n // TODO: We could see if the PK (form the index tree's perspective)\n // changed and if not we could use set.\n // We cannot just do `set` with the new value since the `oldRow` might\n // not map to the same entry as the new `row` in the index btree.\n const removed = data.delete(change.oldRow);\n // must succeed since we checked has() above.\n assert(removed);\n data.add(change.row);\n break;\n }\n default:\n unreachable(change);\n }\n }\n }\n}\n\nfunction* generateWithConstraint(\n it: Stream<Node>,\n constraint: Constraint | undefined,\n) {\n for (const node of it) {\n if (constraint && !constraintMatchesRow(constraint, node.row)) {\n break;\n }\n yield node;\n }\n}\n\nfunction* generateWithFilter(it: Stream<Node>, filter: (row: Row) => boolean) {\n for (const node of it) {\n if (filter(node.row)) {\n yield node;\n }\n }\n}\n\nexport function* genPushAndWriteWithSplitEdit(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n) {\n let shouldSplitEdit = false;\n if (change.type === 'edit') {\n for (const {splitEditKeys} of connections) {\n if (splitEditKeys) {\n for (const key of splitEditKeys) {\n if (!valuesEqual(change.row[key], change.oldRow[key])) {\n shouldSplitEdit = true;\n break;\n }\n }\n }\n }\n }\n\n if (change.type === 'edit' && shouldSplitEdit) {\n yield* genPushAndWrite(\n connections,\n {\n type: 'remove',\n row: change.oldRow,\n },\n exists,\n setOverlay,\n writeChange,\n );\n yield* genPushAndWrite(\n connections,\n {\n type: 'add',\n row: change.row,\n },\n exists,\n setOverlay,\n writeChange,\n );\n } else {\n yield* genPushAndWrite(\n connections,\n change,\n exists,\n setOverlay,\n writeChange,\n );\n }\n}\n\nfunction* genPushAndWrite(\n connections: readonly Connection[],\n change: SourceChangeAdd | SourceChangeRemove | SourceChangeEdit,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n) {\n for (const x of genPush(connections, change, exists, setOverlay)) {\n yield x;\n }\n writeChange(change);\n}\n\nfunction* genPush(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => void,\n) {\n switch (change.type) {\n case 'add':\n assert(\n !exists(change.row),\n () => `Row already exists ${stringify(change)}`,\n );\n break;\n case 'remove':\n assert(exists(change.row), () => `Row not found ${stringify(change)}`);\n break;\n case 'edit':\n assert(exists(change.oldRow), () => `Row not found ${stringify(change)}`);\n break;\n default:\n unreachable(change);\n }\n\n for (const [outputIndex, {output, filters, input}] of connections.entries()) {\n if (output) {\n setOverlay({outputIndex, change});\n const outputChange: Change =\n change.type === 'edit'\n ? {\n type: change.type,\n oldNode: {\n row: change.oldRow,\n relationships: {},\n },\n node: {\n row: change.row,\n relationships: {},\n },\n }\n : {\n type: change.type,\n node: {\n row: change.row,\n relationships: {},\n },\n };\n filterPush(outputChange, output, input, filters?.predicate);\n yield;\n }\n }\n\n setOverlay(undefined);\n}\n\nexport function* generateWithStart(\n nodes: Iterable<Node>,\n start: Start | undefined,\n compare: (r1: Row, r2: Row) => number,\n): Stream<Node> {\n if (!start) {\n yield* nodes;\n return;\n }\n let started = false;\n for (const node of nodes) {\n if (!started) {\n if (start.basis === 'at') {\n if (compare(node.row, start.row) >= 0) {\n started = true;\n }\n } else if (start.basis === 'after') {\n if (compare(node.row, start.row) > 0) {\n started = true;\n }\n }\n }\n if (started) {\n yield node;\n }\n }\n}\n\n/**\n * Takes an iterator and overlay.\n * Splices the overlay into the iterator at the correct position.\n *\n * @param startAt - if there is a lower bound to the stream. If the lower bound of the stream\n * is above the overlay, the overlay will be skipped.\n * @param rows - the stream into which the overlay should be spliced\n * @param constraint - constraint that was applied to the rowIterator and should\n * also be applied to the overlay.\n * @param overlay - the overlay values to splice in\n * @param compare - the comparator to use to find the position for the overlay\n */\nexport function* generateWithOverlay(\n startAt: Row | undefined,\n rows: Iterable<Row>,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n connectionIndex: number,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n) {\n let overlayToApply: Overlay | undefined = undefined;\n if (overlay && connectionIndex <= overlay.outputIndex) {\n overlayToApply = overlay;\n }\n const overlays = computeOverlays(\n startAt,\n constraint,\n overlayToApply,\n compare,\n filterPredicate,\n );\n yield* generateWithOverlayInner(rows, overlays, compare);\n}\n\nfunction computeOverlays(\n startAt: Row | undefined,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n): Overlays {\n let overlays: Overlays = {\n add: undefined,\n remove: undefined,\n };\n switch (overlay?.change.type) {\n case 'add':\n overlays = {\n add: overlay.change.row,\n remove: undefined,\n };\n break;\n case 'remove':\n overlays = {\n add: undefined,\n remove: overlay.change.row,\n };\n break;\n case 'edit':\n overlays = {\n add: overlay.change.row,\n remove: overlay.change.oldRow,\n };\n break;\n }\n\n if (startAt) {\n overlays = overlaysForStartAt(overlays, startAt, compare);\n }\n\n if (constraint) {\n overlays = overlaysForConstraint(overlays, constraint);\n }\n\n if (filterPredicate) {\n overlays = overlaysForFilterPredicate(overlays, filterPredicate);\n }\n\n return overlays;\n}\n\nexport {overlaysForStartAt as overlaysForStartAtForTest};\n\nfunction overlaysForStartAt(\n {add, remove}: Overlays,\n startAt: Row,\n compare: Comparator,\n): Overlays {\n const undefinedIfBeforeStartAt = (row: Row | undefined) =>\n row === undefined || compare(row, startAt) < 0 ? undefined : row;\n return {\n add: undefinedIfBeforeStartAt(add),\n remove: undefinedIfBeforeStartAt(remove),\n };\n}\n\nexport {overlaysForConstraint as overlaysForConstraintForTest};\n\nfunction overlaysForConstraint(\n {add, remove}: Overlays,\n constraint: Constraint,\n): Overlays {\n const undefinedIfDoesntMatchConstraint = (row: Row | undefined) =>\n row === undefined || !constraintMatchesRow(constraint, row)\n ? undefined\n : row;\n\n return {\n add: undefinedIfDoesntMatchConstraint(add),\n remove: undefinedIfDoesntMatchConstraint(remove),\n };\n}\n\nfunction overlaysForFilterPredicate(\n {add, remove}: Overlays,\n filterPredicate: (row: Row) => boolean | undefined,\n): Overlays {\n const undefinedIfDoesntMatchFilter = (row: Row | undefined) =>\n row === undefined || !filterPredicate(row) ? undefined : row;\n\n return {\n add: undefinedIfDoesntMatchFilter(add),\n remove: undefinedIfDoesntMatchFilter(remove),\n };\n}\n\nexport function* generateWithOverlayInner(\n rowIterator: Iterable<Row>,\n overlays: Overlays,\n compare: (r1: Row, r2: Row) => number,\n) {\n let addOverlayYielded = false;\n let removeOverlaySkipped = false;\n for (const row of rowIterator) {\n if (!addOverlayYielded && overlays.add) {\n const cmp = compare(overlays.add, row);\n if (cmp < 0) {\n addOverlayYielded = true;\n yield {row: overlays.add, relationships: {}};\n }\n }\n\n if (!removeOverlaySkipped && overlays.remove) {\n const cmp = compare(overlays.remove, row);\n if (cmp === 0) {\n removeOverlaySkipped = true;\n continue;\n }\n }\n yield {row, relationships: {}};\n }\n\n if (!addOverlayYielded && overlays.add) {\n yield {row: overlays.add, relationships: {}};\n }\n}\n\n/**\n * A location to begin scanning an index from. Can either be a specific value\n * or the min or max possible value for the type. This is used to start a scan\n * at the beginning of the rows matching a constraint.\n */\ntype Bound = Value | MinValue | MaxValue;\ntype RowBound = Record<string, Bound>;\nconst minValue = Symbol('min-value');\ntype MinValue = typeof minValue;\nconst maxValue = Symbol('max-value');\ntype MaxValue = typeof maxValue;\n\nfunction makeBoundComparator(sort: Ordering) {\n return (a: RowBound, b: RowBound) => {\n // Hot! Do not use destructuring\n for (const entry of sort) {\n const key = entry[0];\n const cmp = compareBounds(a[key], b[key]);\n if (cmp !== 0) {\n return entry[1] === 'asc' ? cmp : -cmp;\n }\n }\n return 0;\n };\n}\n\nfunction compareBounds(a: Bound, b: Bound): number {\n if (a === b) {\n return 0;\n }\n if (a === minValue) {\n return -1;\n }\n if (b === minValue) {\n return 1;\n }\n if (a === maxValue) {\n return 1;\n }\n if (b === maxValue) {\n return -1;\n }\n return compareValues(a, b);\n}\n\nfunction* generateRows(\n data: BTreeSet<Row>,\n scanStart: RowBound | undefined,\n reverse: boolean | undefined,\n) {\n yield* data[reverse ? 'valuesFromReversed' : 'valuesFrom'](\n scanStart as Row | undefined,\n );\n}\n\nexport function stringify(change: SourceChange) {\n return JSON.stringify(change, (_, v) =>\n typeof v === 'bigint' ? v.toString() : v,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAyFO,MAAM,aAA+B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAmC,IAAA;AAAA,EACnC,eAA6B,CAAA;AAAA,EAEtC;AAAA,EAEA,YACE,WACA,SACA,YACA,kBACA;AACA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AQ,SAAS,QAAQ,GAAG;AACxC,UAAI,QAAQ,GAAG;AACb,+BAAuB;AACvB;AAAA,MACF;AAAA,IACF;AACA,UAAM,EAAC,KAAK,eAAe,GAAC;AAAA,EAC9B;AAEA,MAAI,CAAC,qBAAqB,SAAS,KAAK;AACtC,UAAM,EAAC,KAAK,SAAS,KAAK,eAAe,CAAA,EAAC;AAAA,EAC5C;AACF;AASA,MAAM,WAAW,OAAO,WAAW;AAEnC,MAAM,WAAW,OAAO,WAAW;AAGnC,SAAS,oBAAoB,MAAgB;AAC3C,SAAO,CAAC,GAAa,MAAgB;AAEnC,eAAW,SAAS,MAAM;AACxB,YAAM,MAAM,MAAM,CAAC;AACnB,YAAM,MAAM,cAAc,EAAE,GAAG,GAAG,EAAE,GAAG,CAAC;AACxC,UAAI,QAAQ,GAAG;AACb,eAAO,MAAM,CAAC,MAAM,QAAQ,MAAM,CAAC;AAAA,MACrC;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,cAAc,GAAU,GAAkB;AACjD,MAAI,MAAM,GAAG;AACX,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,SAAO,cAAc,GAAG,CAAC;AAC3B;AAEA,UAAU,aACR,MACA,WACA,SACA;AACA,SAAO,KAAK,UAAU,uBAAuB,YAAY;AAAA,IACvD;AAAA,EAAA;AAEJ;AAEO,SAAS,UAAU,QAAsB;AAC9C,SAAO,KAAK;AAAA,IAAU;AAAA,IAAQ,CAAC,GAAG,MAChC,OAAO,MAAM,WAAW,EAAE,aAAa;AAAA,EAAA;AAE3C;"}
1
+ {"version":3,"file":"memory-source.js","sources":["../../../../../zql/src/ivm/memory-source.ts"],"sourcesContent":["import {assert, unreachable} from '../../../shared/src/asserts.ts';\nimport {BTreeSet} from '../../../shared/src/btree-set.ts';\nimport {hasOwn} from '../../../shared/src/has-own.ts';\nimport {once} from '../../../shared/src/iterables.ts';\nimport type {\n Condition,\n Ordering,\n OrderPart,\n} from '../../../zero-protocol/src/ast.ts';\nimport type {Row, Value} from '../../../zero-protocol/src/data.ts';\nimport type {PrimaryKey} from '../../../zero-protocol/src/primary-key.ts';\nimport type {SchemaValue} from '../../../zero-types/src/schema-value.ts';\nimport type {DebugDelegate} from '../builder/debug-delegate.ts';\nimport {\n createPredicate,\n transformFilters,\n type NoSubqueryCondition,\n} from '../builder/filter.ts';\nimport {assertOrderingIncludesPK} from '../query/complete-ordering.ts';\nimport type {Change} from './change.ts';\nimport {\n constraintMatchesPrimaryKey,\n constraintMatchesRow,\n primaryKeyConstraintFromFilters,\n type Constraint,\n} from './constraint.ts';\nimport {\n compareValues,\n makeComparator,\n valuesEqual,\n type Comparator,\n type Node,\n} from './data.ts';\nimport {filterPush} from './filter-push.ts';\nimport {\n skipYields,\n type FetchRequest,\n type Input,\n type Output,\n type Start,\n} from './operator.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {\n Source,\n SourceChange,\n SourceChangeAdd,\n SourceChangeEdit,\n SourceChangeRemove,\n SourceInput,\n} from './source.ts';\nimport type {Stream} from './stream.ts';\n\nexport type Overlay = {\n epoch: number;\n change: SourceChange;\n};\n\nexport type Overlays = {\n add: Row | undefined;\n remove: Row | undefined;\n};\n\ntype Index = {\n comparator: Comparator;\n data: BTreeSet<Row>;\n usedBy: Set<Connection>;\n};\n\nexport type Connection = {\n input: Input;\n output: Output | undefined;\n sort: Ordering;\n splitEditKeys: Set<string> | undefined;\n compareRows: Comparator;\n filters:\n | {\n condition: NoSubqueryCondition;\n predicate: (row: Row) => boolean;\n }\n | undefined;\n readonly debug?: DebugDelegate | undefined;\n lastPushedEpoch: number;\n};\n\n/**\n * A `MemorySource` is a source that provides data to the pipeline from an\n * in-memory data source.\n *\n * This data is kept in sorted order as downstream pipelines will always expect\n * the data they receive from `pull` to be in sorted order.\n */\nexport class MemorySource implements Source {\n readonly #tableName: string;\n readonly #columns: Record<string, SchemaValue>;\n readonly #primaryKey: PrimaryKey;\n readonly #primaryIndexSort: Ordering;\n readonly #indexes: Map<string, Index> = new Map();\n readonly #connections: Connection[] = [];\n\n #overlay: Overlay | undefined;\n #pushEpoch = 0;\n\n constructor(\n tableName: string,\n columns: Record<string, SchemaValue>,\n primaryKey: PrimaryKey,\n primaryIndexData?: BTreeSet<Row>,\n ) {\n this.#tableName = tableName;\n this.#columns = columns;\n this.#primaryKey = primaryKey;\n this.#primaryIndexSort = primaryKey.map(k => [k, 'asc']);\n const comparator = makeBoundComparator(this.#primaryIndexSort);\n this.#indexes.set(JSON.stringify(this.#primaryIndexSort), {\n comparator,\n data: primaryIndexData ?? new BTreeSet<Row>(comparator),\n usedBy: new Set(),\n });\n }\n\n get tableSchema() {\n return {\n name: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n };\n }\n\n fork() {\n const primaryIndex = this.#getPrimaryIndex();\n return new MemorySource(\n this.#tableName,\n this.#columns,\n this.#primaryKey,\n primaryIndex.data.clone(),\n );\n }\n\n get data(): BTreeSet<Row> {\n return this.#getPrimaryIndex().data;\n }\n\n #getSchema(connection: Connection): SourceSchema {\n return {\n tableName: this.#tableName,\n columns: this.#columns,\n primaryKey: this.#primaryKey,\n sort: connection.sort,\n system: 'client',\n relationships: {},\n isHidden: false,\n compareRows: connection.compareRows,\n };\n }\n\n connect(\n sort: Ordering,\n filters?: Condition,\n splitEditKeys?: Set<string>,\n ): SourceInput {\n const transformedFilters = transformFilters(filters);\n\n const input: SourceInput = {\n getSchema: () => schema,\n fetch: req => this.#fetch(req, connection),\n setOutput: output => {\n connection.output = output;\n },\n destroy: () => {\n this.#disconnect(input);\n },\n fullyAppliedFilters: !transformedFilters.conditionsRemoved,\n };\n\n const connection: Connection = {\n input,\n output: undefined,\n sort,\n splitEditKeys,\n compareRows: makeComparator(sort),\n filters: transformedFilters.filters\n ? {\n condition: transformedFilters.filters,\n predicate: createPredicate(transformedFilters.filters),\n }\n : undefined,\n lastPushedEpoch: 0,\n };\n const schema = this.#getSchema(connection);\n assertOrderingIncludesPK(sort, this.#primaryKey);\n this.#connections.push(connection);\n return input;\n }\n\n #disconnect(input: Input): void {\n const idx = this.#connections.findIndex(c => c.input === input);\n assert(idx !== -1, 'Connection not found');\n this.#connections.splice(idx, 1);\n\n // TODO: We used to delete unused indexes here. But in common cases like\n // navigating into issue detail pages it caused a ton of constantly\n // building and destroying indexes.\n //\n // Perhaps some intelligent LRU or something is needed here but for now,\n // the opposite extreme of keeping all indexes for the lifetime of the\n // page seems better.\n }\n\n #getPrimaryIndex(): Index {\n const index = this.#indexes.get(JSON.stringify(this.#primaryIndexSort));\n assert(index, 'Primary index not found');\n return index;\n }\n\n #getOrCreateIndex(sort: Ordering, usedBy: Connection): Index {\n const key = JSON.stringify(sort);\n const index = this.#indexes.get(key);\n // Future optimization could use existing index if it's the same just sorted\n // in reverse of needed.\n if (index) {\n index.usedBy.add(usedBy);\n return index;\n }\n\n const comparator = makeBoundComparator(sort);\n\n // When creating these synchronously becomes a problem, a few options:\n // 1. Allow users to specify needed indexes up front\n // 2. Create indexes in a different thread asynchronously (this would require\n // modifying the BTree to be able to be passed over structured-clone, or using\n // a different library.)\n // 3. We could even theoretically do (2) on multiple threads and then merge the\n // results!\n const data = new BTreeSet<Row>(comparator);\n\n // I checked, there's no special path for adding data in bulk faster.\n // The constructor takes an array, but it just calls add/set over and over.\n for (const row of this.#getPrimaryIndex().data) {\n data.add(row);\n }\n\n const newIndex = {comparator, data, usedBy: new Set([usedBy])};\n this.#indexes.set(key, newIndex);\n return newIndex;\n }\n\n // For unit testing that we correctly clean up indexes.\n getIndexKeys(): string[] {\n return [...this.#indexes.keys()];\n }\n\n *#fetch(req: FetchRequest, conn: Connection): Stream<Node | 'yield'> {\n const {sort: requestedSort, compareRows} = conn;\n const connectionComparator = (r1: Row, r2: Row) =>\n compareRows(r1, r2) * (req.reverse ? -1 : 1);\n\n const pkConstraint = primaryKeyConstraintFromFilters(\n conn.filters?.condition,\n this.#primaryKey,\n );\n // The primary key constraint will be more limiting than the constraint\n // so swap out to that if it exists.\n const fetchOrPkConstraint = pkConstraint ?? req.constraint;\n\n // If there is a constraint, we need an index sorted by it first.\n const indexSort: OrderPart[] = [];\n if (fetchOrPkConstraint) {\n for (const key of Object.keys(fetchOrPkConstraint)) {\n indexSort.push([key, 'asc']);\n }\n }\n\n // For the special case of constraining by PK, we don't need to worry about\n // any requested sort since there can only be one result. Otherwise we also\n // need the index sorted by the requested sort.\n if (\n this.#primaryKey.length > 1 ||\n !fetchOrPkConstraint ||\n !constraintMatchesPrimaryKey(fetchOrPkConstraint, this.#primaryKey)\n ) {\n indexSort.push(...requestedSort);\n }\n\n const index = this.#getOrCreateIndex(indexSort, conn);\n const {data, comparator: compare} = index;\n const indexComparator = (r1: Row, r2: Row) =>\n compare(r1, r2) * (req.reverse ? -1 : 1);\n\n const startAt = req.start?.row;\n\n // If there is a constraint, we want to start our scan at the first row that\n // matches the constraint. But because the next OrderPart can be `desc`,\n // it's not true that {[constraintKey]: constraintValue} is the first\n // matching row. Because in that case, the other fields will all be\n // `undefined`, and in Zero `undefined` is always less than any other value.\n // So if the second OrderPart is descending then `undefined` values will\n // actually be the *last* row. We need a way to stay \"start at the first row\n // with this constraint value\". RowBound with the corresponding compareBound\n // comparator accomplishes this. The right thing is probably to teach the\n // btree library to support this concept.\n let scanStart: RowBound | undefined;\n\n if (fetchOrPkConstraint) {\n scanStart = {};\n for (const [key, dir] of indexSort) {\n if (hasOwn(fetchOrPkConstraint, key)) {\n scanStart[key] = fetchOrPkConstraint[key];\n } else {\n if (req.reverse) {\n scanStart[key] = dir === 'asc' ? maxValue : minValue;\n } else {\n scanStart[key] = dir === 'asc' ? minValue : maxValue;\n }\n }\n }\n } else {\n scanStart = startAt;\n }\n\n const rowsIterable = generateRows(data, scanStart, req.reverse);\n const withOverlay = generateWithOverlay(\n startAt,\n pkConstraint ? once(rowsIterable) : rowsIterable,\n // use `req.constraint` here and not `fetchOrPkConstraint` since `fetchOrPkConstraint` could be the\n // primary key constraint. The primary key constraint comes from filters and is acting as a filter\n // rather than as the fetch constraint.\n req.constraint,\n this.#overlay,\n conn.lastPushedEpoch,\n // Use indexComparator, generateWithOverlayInner has a subtle dependency\n // on this. Since generateWithConstraint is done after\n // generateWithOverlay, the generator consumed by generateWithOverlayInner\n // does not end when the constraint stops matching and so the final\n // check to yield an add overlay if not yet yielded is not reached.\n // However, using the indexComparator the add overlay will be less than\n // the first row that does not match the constraint, and so any\n // not yet yielded add overlay will be yielded when the first row\n // not matching the constraint is reached.\n indexComparator,\n conn.filters?.predicate,\n );\n\n const withConstraint = generateWithConstraint(\n skipYields(\n generateWithStart(withOverlay, req.start, connectionComparator),\n ),\n // we use `req.constraint` and not `fetchOrPkConstraint` here because we need to\n // AND the constraint with what could have been the primary key constraint\n req.constraint,\n );\n\n yield* conn.filters\n ? generateWithFilter(withConstraint, conn.filters.predicate)\n : withConstraint;\n }\n\n *push(change: SourceChange): Stream<'yield'> {\n for (const result of this.genPush(change)) {\n if (result === 'yield') {\n yield result;\n }\n }\n }\n\n *genPush(change: SourceChange) {\n const primaryIndex = this.#getPrimaryIndex();\n const {data} = primaryIndex;\n const exists = (row: Row) => data.has(row);\n const setOverlay = (o: Overlay | undefined) => (this.#overlay = o);\n const writeChange = (c: SourceChange) => this.#writeChange(c);\n yield* genPushAndWriteWithSplitEdit(\n this.#connections,\n change,\n exists,\n setOverlay,\n writeChange,\n () => ++this.#pushEpoch,\n );\n }\n\n #writeChange(change: SourceChange) {\n for (const {data} of this.#indexes.values()) {\n switch (change.type) {\n case 'add': {\n const added = data.add(change.row);\n // must succeed since we checked has() above.\n assert(added);\n break;\n }\n case 'remove': {\n const removed = data.delete(change.row);\n // must succeed since we checked has() above.\n assert(removed);\n break;\n }\n case 'edit': {\n // TODO: We could see if the PK (form the index tree's perspective)\n // changed and if not we could use set.\n // We cannot just do `set` with the new value since the `oldRow` might\n // not map to the same entry as the new `row` in the index btree.\n const removed = data.delete(change.oldRow);\n // must succeed since we checked has() above.\n assert(removed);\n data.add(change.row);\n break;\n }\n default:\n unreachable(change);\n }\n }\n }\n}\n\nfunction* generateWithConstraint(\n it: Stream<Node>,\n constraint: Constraint | undefined,\n) {\n for (const node of it) {\n if (constraint && !constraintMatchesRow(constraint, node.row)) {\n break;\n }\n yield node;\n }\n}\n\nfunction* generateWithFilter(it: Stream<Node>, filter: (row: Row) => boolean) {\n for (const node of it) {\n if (filter(node.row)) {\n yield node;\n }\n }\n}\n\nexport function* genPushAndWriteWithSplitEdit(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n getNextEpoch: () => number,\n) {\n let shouldSplitEdit = false;\n if (change.type === 'edit') {\n for (const {splitEditKeys} of connections) {\n if (splitEditKeys) {\n for (const key of splitEditKeys) {\n if (!valuesEqual(change.row[key], change.oldRow[key])) {\n shouldSplitEdit = true;\n break;\n }\n }\n }\n }\n }\n\n if (change.type === 'edit' && shouldSplitEdit) {\n yield* genPushAndWrite(\n connections,\n {\n type: 'remove',\n row: change.oldRow,\n },\n exists,\n setOverlay,\n writeChange,\n getNextEpoch(),\n );\n yield* genPushAndWrite(\n connections,\n {\n type: 'add',\n row: change.row,\n },\n exists,\n setOverlay,\n writeChange,\n getNextEpoch(),\n );\n } else {\n yield* genPushAndWrite(\n connections,\n change,\n exists,\n setOverlay,\n writeChange,\n getNextEpoch(),\n );\n }\n}\n\nfunction* genPushAndWrite(\n connections: readonly Connection[],\n change: SourceChangeAdd | SourceChangeRemove | SourceChangeEdit,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => Overlay | undefined,\n writeChange: (c: SourceChange) => void,\n pushEpoch: number,\n) {\n for (const x of genPush(connections, change, exists, setOverlay, pushEpoch)) {\n yield x;\n }\n writeChange(change);\n}\n\nfunction* genPush(\n connections: readonly Connection[],\n change: SourceChange,\n exists: (row: Row) => boolean,\n setOverlay: (o: Overlay | undefined) => void,\n pushEpoch: number,\n) {\n switch (change.type) {\n case 'add':\n assert(\n !exists(change.row),\n () => `Row already exists ${stringify(change)}`,\n );\n break;\n case 'remove':\n assert(exists(change.row), () => `Row not found ${stringify(change)}`);\n break;\n case 'edit':\n assert(exists(change.oldRow), () => `Row not found ${stringify(change)}`);\n break;\n default:\n unreachable(change);\n }\n\n for (const conn of connections) {\n const {output, filters, input} = conn;\n if (output) {\n conn.lastPushedEpoch = pushEpoch;\n setOverlay({epoch: pushEpoch, change});\n const outputChange: Change =\n change.type === 'edit'\n ? {\n type: change.type,\n oldNode: {\n row: change.oldRow,\n relationships: {},\n },\n node: {\n row: change.row,\n relationships: {},\n },\n }\n : {\n type: change.type,\n node: {\n row: change.row,\n relationships: {},\n },\n };\n yield* filterPush(outputChange, output, input, filters?.predicate);\n yield undefined;\n }\n }\n\n setOverlay(undefined);\n}\n\nexport function* generateWithStart(\n nodes: Iterable<Node | 'yield'>,\n start: Start | undefined,\n compare: (r1: Row, r2: Row) => number,\n): Stream<Node | 'yield'> {\n if (!start) {\n yield* nodes;\n return;\n }\n let started = false;\n for (const node of nodes) {\n if (node === 'yield') {\n yield node;\n continue;\n }\n if (!started) {\n if (start.basis === 'at') {\n if (compare(node.row, start.row) >= 0) {\n started = true;\n }\n } else if (start.basis === 'after') {\n if (compare(node.row, start.row) > 0) {\n started = true;\n }\n }\n }\n if (started) {\n yield node;\n }\n }\n}\n\n/**\n * Takes an iterator and overlay.\n * Splices the overlay into the iterator at the correct position.\n *\n * @param startAt - if there is a lower bound to the stream. If the lower bound of the stream\n * is above the overlay, the overlay will be skipped.\n * @param rows - the stream into which the overlay should be spliced\n * @param constraint - constraint that was applied to the rowIterator and should\n * also be applied to the overlay.\n * @param overlay - the overlay values to splice in\n * @param compare - the comparator to use to find the position for the overlay\n */\nexport function* generateWithOverlay(\n startAt: Row | undefined,\n rows: Iterable<Row>,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n lastPushedEpoch: number,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n) {\n let overlayToApply: Overlay | undefined = undefined;\n if (overlay && lastPushedEpoch >= overlay.epoch) {\n overlayToApply = overlay;\n }\n const overlays = computeOverlays(\n startAt,\n constraint,\n overlayToApply,\n compare,\n filterPredicate,\n );\n yield* generateWithOverlayInner(rows, overlays, compare);\n}\n\nfunction computeOverlays(\n startAt: Row | undefined,\n constraint: Constraint | undefined,\n overlay: Overlay | undefined,\n compare: Comparator,\n filterPredicate?: (row: Row) => boolean | undefined,\n): Overlays {\n let overlays: Overlays = {\n add: undefined,\n remove: undefined,\n };\n switch (overlay?.change.type) {\n case 'add':\n overlays = {\n add: overlay.change.row,\n remove: undefined,\n };\n break;\n case 'remove':\n overlays = {\n add: undefined,\n remove: overlay.change.row,\n };\n break;\n case 'edit':\n overlays = {\n add: overlay.change.row,\n remove: overlay.change.oldRow,\n };\n break;\n }\n\n if (startAt) {\n overlays = overlaysForStartAt(overlays, startAt, compare);\n }\n\n if (constraint) {\n overlays = overlaysForConstraint(overlays, constraint);\n }\n\n if (filterPredicate) {\n overlays = overlaysForFilterPredicate(overlays, filterPredicate);\n }\n\n return overlays;\n}\n\nexport {overlaysForStartAt as overlaysForStartAtForTest};\n\nfunction overlaysForStartAt(\n {add, remove}: Overlays,\n startAt: Row,\n compare: Comparator,\n): Overlays {\n const undefinedIfBeforeStartAt = (row: Row | undefined) =>\n row === undefined || compare(row, startAt) < 0 ? undefined : row;\n return {\n add: undefinedIfBeforeStartAt(add),\n remove: undefinedIfBeforeStartAt(remove),\n };\n}\n\nexport {overlaysForConstraint as overlaysForConstraintForTest};\n\nfunction overlaysForConstraint(\n {add, remove}: Overlays,\n constraint: Constraint,\n): Overlays {\n const undefinedIfDoesntMatchConstraint = (row: Row | undefined) =>\n row === undefined || !constraintMatchesRow(constraint, row)\n ? undefined\n : row;\n\n return {\n add: undefinedIfDoesntMatchConstraint(add),\n remove: undefinedIfDoesntMatchConstraint(remove),\n };\n}\n\nfunction overlaysForFilterPredicate(\n {add, remove}: Overlays,\n filterPredicate: (row: Row) => boolean | undefined,\n): Overlays {\n const undefinedIfDoesntMatchFilter = (row: Row | undefined) =>\n row === undefined || !filterPredicate(row) ? undefined : row;\n\n return {\n add: undefinedIfDoesntMatchFilter(add),\n remove: undefinedIfDoesntMatchFilter(remove),\n };\n}\n\nexport function* generateWithOverlayInner(\n rowIterator: Iterable<Row>,\n overlays: Overlays,\n compare: (r1: Row, r2: Row) => number,\n) {\n let addOverlayYielded = false;\n let removeOverlaySkipped = false;\n for (const row of rowIterator) {\n if (!addOverlayYielded && overlays.add) {\n const cmp = compare(overlays.add, row);\n if (cmp < 0) {\n addOverlayYielded = true;\n yield {row: overlays.add, relationships: {}};\n }\n }\n\n if (!removeOverlaySkipped && overlays.remove) {\n const cmp = compare(overlays.remove, row);\n if (cmp === 0) {\n removeOverlaySkipped = true;\n continue;\n }\n }\n yield {row, relationships: {}};\n }\n\n if (!addOverlayYielded && overlays.add) {\n yield {row: overlays.add, relationships: {}};\n }\n}\n\n/**\n * A location to begin scanning an index from. Can either be a specific value\n * or the min or max possible value for the type. This is used to start a scan\n * at the beginning of the rows matching a constraint.\n */\ntype Bound = Value | MinValue | MaxValue;\ntype RowBound = Record<string, Bound>;\nconst minValue = Symbol('min-value');\ntype MinValue = typeof minValue;\nconst maxValue = Symbol('max-value');\ntype MaxValue = typeof maxValue;\n\nfunction makeBoundComparator(sort: Ordering) {\n return (a: RowBound, b: RowBound) => {\n // Hot! Do not use destructuring\n for (const entry of sort) {\n const key = entry[0];\n const cmp = compareBounds(a[key], b[key]);\n if (cmp !== 0) {\n return entry[1] === 'asc' ? cmp : -cmp;\n }\n }\n return 0;\n };\n}\n\nfunction compareBounds(a: Bound, b: Bound): number {\n if (a === b) {\n return 0;\n }\n if (a === minValue) {\n return -1;\n }\n if (b === minValue) {\n return 1;\n }\n if (a === maxValue) {\n return 1;\n }\n if (b === maxValue) {\n return -1;\n }\n return compareValues(a, b);\n}\n\nfunction* generateRows(\n data: BTreeSet<Row>,\n scanStart: RowBound | undefined,\n reverse: boolean | undefined,\n) {\n yield* data[reverse ? 'valuesFromReversed' : 'valuesFrom'](\n scanStart as Row | undefined,\n );\n}\n\nexport function stringify(change: SourceChange) {\n return JSON.stringify(change, (_, v) =>\n typeof v === 'bigint' ? v.toString() : v,\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;AA2FO,MAAM,aAA+B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,+BAAmC,IAAA;AAAA,EACnC,eAA6B,CAAA;AAAA,EAEtC;AAAA,EACA,aAAa;AAAA,EAEb,YACE,WACA,SACA,YACA,kBACA;AACA,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,cAAc;AACnB,SAAK,oBAAoB,WAAW,IAAI,OAAK,CAAC,GAAG,KAAK,CAAC;AACvD,UAAM,aAAa,oBAAoB,KAAK,iBAAiB;AAC7D,SAAK,SAAS,IAAI,KAAK,UAAU,KAAK,iBAAiB,GAAG;AAAA,MACxD;AAAA,MACA,MAAM,oBAAoB,IAAI,SAAc,UAAU;AAAA,MACtD,4BAAY,IAAA;AAAA,IAAI,CACjB;AAAA,EACH;AAAA,EAEA,IAAI,cAAc;AAChB,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,MACX,SAAS,KAAK;AAAA,MACd,YAAY,KAAK;AAAA,IAAA;AAAA,EAErB;AAAA,EAEA,OAAO;AACL,UAAM,eAAe,KAAK,iBAAA;AAC1B,WAAO,IAAI;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,aAAa,KAAK,MAAA;AAAA,IAAM;AAAA,EAE5B;AAAA,EAEA,IAAI,OAAsB;AACxB,WAAO,KAAK,mBAAmB;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AU,GAAkB;AACjD,MAAI,MAAM,GAAG;AACX,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,MAAI,MAAM,UAAU;AAClB,WAAO;AAAA,EACT;AACA,SAAO,cAAc,GAAG,CAAC;AAC3B;AAEA,UAAU,aACR,MACA,WACA,SACA;AACA,SAAO,KAAK,UAAU,uBAAuB,YAAY;AAAA,IACvD;AAAA,EAAA;AAEJ;AAEO,SAAS,UAAU,QAAsB;AAC9C,SAAO,KAAK;AAAA,IAAU;AAAA,IAAQ,CAAC,GAAG,MAChC,OAAO,MAAM,WAAW,EAAE,aAAa;AAAA,EAAA;AAE3C;"}
@@ -24,20 +24,17 @@ export interface Input extends InputBase {
24
24
  /**
25
25
  * Fetch data. May modify the data in place.
26
26
  * Returns nodes sorted in order of `SourceSchema.compareRows`.
27
- */
28
- fetch(req: FetchRequest): Stream<Node>;
29
- /**
30
- * Cleanup maintained state. This is called when `output` will no longer need
31
- * the data returned by {@linkcode fetch}. The receiving operator should clean up any
32
- * resources it has allocated to service such requests.
33
27
  *
34
- * This is different from {@linkcode destroy} which means this input will no longer
35
- * be called at all, for any input.
28
+ * The stream may contain 'yield' to yield control to the caller for purposes
29
+ * of responsiveness.
36
30
  *
37
- * Returns the same thing as {@linkcode fetch}. This allows callers to properly
38
- * propagate the cleanup message through the graph.
31
+ * Contract:
32
+ * - During fetch: If an input yields 'yield', 'yield' must be yielded to the
33
+ * caller of fetch immediately.
34
+ * - During push: If a fetch to an input consumed by the push logic yields
35
+ * 'yield', it must be yielded to the caller of push immediately.
39
36
  */
40
- cleanup(req: FetchRequest): Stream<Node>;
37
+ fetch(req: FetchRequest): Stream<Node | 'yield'>;
41
38
  }
42
39
  export type FetchRequest = {
43
40
  readonly constraint?: Constraint | undefined;
@@ -62,14 +59,20 @@ export interface Output {
62
59
  * Callers must maintain some invariants for correct operation:
63
60
  * - Only add rows which do not already exist (by deep equality).
64
61
  * - Only remove rows which do exist (by deep equality).
62
+ * Implmentation can yield 'yield' to yield control to the caller for purposes
63
+ * of responsiveness.
64
+ * Yield contract:
65
+ * - During a push: If a push call to an output yields 'yield', it must be
66
+ * yielded to the caller of push immediately.
65
67
  */
66
- push(change: Change, pusher: InputBase): void;
68
+ push(change: Change, pusher: InputBase): Stream<'yield'>;
67
69
  }
68
70
  /**
69
71
  * An implementation of Output that throws if pushed to. It is used as the
70
72
  * initial value for for an operator's output before it is set.
71
73
  */
72
74
  export declare const throwOutput: Output;
75
+ export declare function skipYields(stream: Stream<Node | 'yield'>): Stream<Node>;
73
76
  /**
74
77
  * Operators are arranged into pipelines.
75
78
  * They are stateful.
@@ -1 +1 @@
1
- {"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/operator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,6BAA6B,CAAC;AAC3D,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAC5D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,SAAS,IAAI,YAAY,CAAC;IAE1B;;;;OAIG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,KAAM,SAAQ,SAAS;IACtC,+CAA+C;IAC/C,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC;;;O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,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;CAC1D;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,MAIzB,CAAC;AAEF,wBAAiB,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAMxE;AAED;;;;;GAKG;AACH,MAAM,WAAW,QAAS,SAAQ,KAAK,EAAE,MAAM;CAAG;AAElD;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IACzD;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB"}
@@ -3,7 +3,15 @@ const throwOutput = {
3
3
  throw new Error("Output not set");
4
4
  }
5
5
  };
6
+ function* skipYields(stream) {
7
+ for (const node of stream) {
8
+ if (node !== "yield") {
9
+ yield node;
10
+ }
11
+ }
12
+ }
6
13
  export {
14
+ skipYields,
7
15
  throwOutput
8
16
  };
9
17
  //# sourceMappingURL=operator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"operator.js","sources":["../../../../../zql/src/ivm/operator.ts"],"sourcesContent":["import type {JSONValue} from '../../../shared/src/json.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {Change} from './change.ts';\nimport type {Constraint} from './constraint.ts';\nimport type {Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * Input to an operator.\n */\nexport interface InputBase {\n /** The schema of the data this input returns. */\n getSchema(): SourceSchema;\n\n /**\n * Completely destroy the input. Destroying an input\n * causes it to call destroy on its upstreams, fully\n * cleaning up a pipeline.\n */\n destroy(): void;\n}\n\nexport interface Input extends InputBase {\n /** Tell the input where to send its output. */\n setOutput(output: Output): void;\n\n /**\n * Fetch data. May modify the data in place.\n * Returns nodes sorted in order of `SourceSchema.compareRows`.\n */\n fetch(req: FetchRequest): Stream<Node>;\n\n /**\n * Cleanup maintained state. This is called when `output` will no longer need\n * the data returned by {@linkcode fetch}. The receiving operator should clean up any\n * resources it has allocated to service such requests.\n *\n * This is different from {@linkcode destroy} which means this input will no longer\n * be called at all, for any input.\n *\n * Returns the same thing as {@linkcode fetch}. This allows callers to properly\n * propagate the cleanup message through the graph.\n */\n cleanup(req: FetchRequest): Stream<Node>;\n}\n\nexport type FetchRequest = {\n readonly constraint?: Constraint | undefined;\n /** If supplied, `start.row` must have previously been output by fetch or push. */\n readonly start?: Start | undefined;\n\n /** Whether to fetch in reverse order of the SourceSchema's sort. */\n readonly reverse?: boolean | undefined;\n};\n\nexport type Start = {\n readonly row: Row;\n readonly basis: 'at' | 'after';\n};\n\n/**\n * An output for an operator. Typically another Operator but can also be\n * the code running the pipeline.\n */\nexport interface Output {\n /**\n * Push incremental changes to data previously received with fetch().\n * Consumers must apply all pushed changes or incremental result will\n * be incorrect.\n * Callers must maintain some invariants for correct operation:\n * - Only add rows which do not already exist (by deep equality).\n * - Only remove rows which do exist (by deep equality).\n */\n push(change: Change, pusher: InputBase): void;\n}\n\n/**\n * An implementation of Output that throws if pushed to. It is used as the\n * initial value for for an operator's output before it is set.\n */\nexport const throwOutput: Output = {\n push(_change: Change): void {\n throw new Error('Output not set');\n },\n};\n\n/**\n * Operators are arranged into pipelines.\n * They are stateful.\n * Each operator is an input to the next operator in the chain and an output\n * to the previous.\n */\nexport interface Operator extends Input, Output {}\n\n/**\n * Operators get access to storage that they can store their internal\n * state in.\n */\nexport interface Storage {\n set(key: string, value: JSONValue): void;\n get(key: string, def?: JSONValue): JSONValue | undefined;\n /**\n * If options is not specified, defaults to scanning all entries.\n */\n scan(options?: {prefix: string}): Stream<[string, JSONValue]>;\n del(key: string): void;\n}\n"],"names":[],"mappings":"AAiFO,MAAM,cAAsB;AAAA,EACjC,KAAK,SAAuB;AAC1B,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACF;"}
1
+ {"version":3,"file":"operator.js","sources":["../../../../../zql/src/ivm/operator.ts"],"sourcesContent":["import type {JSONValue} from '../../../shared/src/json.ts';\nimport type {Row} from '../../../zero-protocol/src/data.ts';\nimport type {Change} from './change.ts';\nimport type {Constraint} from './constraint.ts';\nimport type {Node} from './data.ts';\nimport type {SourceSchema} from './schema.ts';\nimport type {Stream} from './stream.ts';\n\n/**\n * Input to an operator.\n */\nexport interface InputBase {\n /** The schema of the data this input returns. */\n getSchema(): SourceSchema;\n\n /**\n * Completely destroy the input. Destroying an input\n * causes it to call destroy on its upstreams, fully\n * cleaning up a pipeline.\n */\n destroy(): void;\n}\n\nexport interface Input extends InputBase {\n /** Tell the input where to send its output. */\n setOutput(output: Output): void;\n\n /**\n * Fetch data. May modify the data in place.\n * Returns nodes sorted in order of `SourceSchema.compareRows`.\n *\n * The stream may contain 'yield' to yield control to the caller for purposes\n * of responsiveness.\n *\n * Contract:\n * - During fetch: If an input yields 'yield', 'yield' must be yielded to the\n * caller of fetch immediately.\n * - During push: If a fetch to an input consumed by the push logic yields\n * 'yield', it must be yielded to the caller of push immediately.\n */\n fetch(req: FetchRequest): Stream<Node | 'yield'>;\n}\n\nexport type FetchRequest = {\n readonly constraint?: Constraint | undefined;\n /** If supplied, `start.row` must have previously been output by fetch or push. */\n readonly start?: Start | undefined;\n\n /** Whether to fetch in reverse order of the SourceSchema's sort. */\n readonly reverse?: boolean | undefined;\n};\n\nexport type Start = {\n readonly row: Row;\n readonly basis: 'at' | 'after';\n};\n\n/**\n * An output for an operator. Typically another Operator but can also be\n * the code running the pipeline.\n */\nexport interface Output {\n /**\n * Push incremental changes to data previously received with fetch().\n * Consumers must apply all pushed changes or incremental result will\n * be incorrect.\n * Callers must maintain some invariants for correct operation:\n * - Only add rows which do not already exist (by deep equality).\n * - Only remove rows which do exist (by deep equality).\n * Implmentation can yield 'yield' to yield control to the caller for purposes\n * of responsiveness.\n * Yield contract:\n * - During a push: If a push call to an output yields 'yield', it must be\n * yielded to the caller of push immediately.\n */\n push(change: Change, pusher: InputBase): Stream<'yield'>;\n}\n\n/**\n * An implementation of Output that throws if pushed to. It is used as the\n * initial value for for an operator's output before it is set.\n */\nexport const throwOutput: Output = {\n push(_change: Change): Stream<'yield'> {\n throw new Error('Output not set');\n },\n};\n\nexport function* skipYields(stream: Stream<Node | 'yield'>): Stream<Node> {\n for (const node of stream) {\n if (node !== 'yield') {\n yield node;\n }\n }\n}\n\n/**\n * Operators are arranged into pipelines.\n * They are stateful.\n * Each operator is an input to the next operator in the chain and an output\n * to the previous.\n */\nexport interface Operator extends Input, Output {}\n\n/**\n * Operators get access to storage that they can store their internal\n * state in.\n */\nexport interface Storage {\n set(key: string, value: JSONValue): void;\n get(key: string, def?: JSONValue): JSONValue | undefined;\n /**\n * If options is not specified, defaults to scanning all entries.\n */\n scan(options?: {prefix: string}): Stream<[string, JSONValue]>;\n del(key: string): void;\n}\n"],"names":[],"mappings":"AAkFO,MAAM,cAAsB;AAAA,EACjC,KAAK,SAAkC;AACrC,UAAM,IAAI,MAAM,gBAAgB;AAAA,EAClC;AACF;AAEO,UAAU,WAAW,QAA8C;AACxE,aAAW,QAAQ,QAAQ;AACzB,QAAI,SAAS,SAAS;AACpB,YAAM;AAAA,IACR;AAAA,EACF;AACF;"}
@@ -72,7 +72,7 @@ import type { Stream } from './stream.ts';
72
72
  * If an edit enters and is converted to only add or only remove, it exits as that change.
73
73
  * If an edit enters and exits as edits only, it exits as a single edit.
74
74
  */
75
- export declare function pushAccumulatedChanges(accumulatedPushes: Change[], output: Output, pusher: InputBase, fanOutChangeType: Change['type'], mergeRelationships: (existing: Change, incoming: Change) => Change, addEmptyRelationships: (change: Change) => Change): void;
75
+ export declare function pushAccumulatedChanges(accumulatedPushes: Change[], output: Output, pusher: InputBase, fanOutChangeType: Change['type'], mergeRelationships: (existing: Change, incoming: Change) => Change, addEmptyRelationships: (change: Change) => Change): Stream<'yield'>;
76
76
  /**
77
77
  * Puts relationships from `right` into `left` if they don't already exist in `left`.
78
78
  */
@@ -84,5 +84,5 @@ export declare function makeAddEmptyRelationships(schema: SourceSchema): (change
84
84
  *
85
85
  * This modifies the `relationships` object in place.
86
86
  */
87
- export declare function mergeEmpty(relationships: Record<string, () => Stream<Node>>, relationshipNames: string[]): void;
87
+ export declare function mergeEmpty(relationships: Record<string, () => Stream<Node | 'yield'>>, relationshipNames: string[]): void;
88
88
  //# sourceMappingURL=push-accumulated.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"push-accumulated.d.ts","sourceRoot":"","sources":["../../../../../zql/src/ivm/push-accumulated.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,wBAAgB,sBAAsB,CACpC,iBAAiB,EAAE,MAAM,EAAE,EAC3B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,gB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AM,EAClE,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAChD,MAAM,CAAC,OAAO,CAAC,CA+JjB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAsFtE;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,GACnB,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAoD5B;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC,EAC3D,iBAAiB,EAAE,MAAM,EAAE,QAO5B"}
@@ -1,7 +1,7 @@
1
1
  import { assert, unreachable } from "../../../shared/src/asserts.js";
2
2
  import { must } from "../../../shared/src/must.js";
3
3
  import { emptyArray } from "../../../shared/src/sentinels.js";
4
- function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeType, mergeRelationships2, addEmptyRelationships) {
4
+ function* pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeType, mergeRelationships2, addEmptyRelationships) {
5
5
  if (accumulatedPushes.length === 0) {
6
6
  return;
7
7
  }
@@ -28,7 +28,7 @@ function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeT
28
28
  types.length === 1 && types[0] === "remove",
29
29
  "Fan-in:remove expected all removes"
30
30
  );
31
- output.push(
31
+ yield* output.push(
32
32
  addEmptyRelationships(must(candidatesToPush.get("remove"))),
33
33
  pusher
34
34
  );
@@ -38,7 +38,7 @@ function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeT
38
38
  types.length === 1 && types[0] === "add",
39
39
  "Fan-in:add expected all adds"
40
40
  );
41
- output.push(
41
+ yield* output.push(
42
42
  addEmptyRelationships(must(candidatesToPush.get("add"))),
43
43
  pusher
44
44
  );
@@ -60,11 +60,11 @@ function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeT
60
60
  if (removeChange) {
61
61
  editChange = mergeRelationships2(editChange, removeChange);
62
62
  }
63
- output.push(addEmptyRelationships(editChange), pusher);
63
+ yield* output.push(addEmptyRelationships(editChange), pusher);
64
64
  return;
65
65
  }
66
66
  if (addChange && removeChange) {
67
- output.push(
67
+ yield* output.push(
68
68
  addEmptyRelationships({
69
69
  type: "edit",
70
70
  node: addChange.node,
@@ -74,7 +74,7 @@ function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeT
74
74
  );
75
75
  return;
76
76
  }
77
- output.push(
77
+ yield* output.push(
78
78
  addEmptyRelationships(must(addChange ?? removeChange)),
79
79
  pusher
80
80
  );
@@ -96,7 +96,7 @@ function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeT
96
96
  );
97
97
  const childChange = candidatesToPush.get("child");
98
98
  if (childChange) {
99
- output.push(childChange, pusher);
99
+ yield* output.push(childChange, pusher);
100
100
  return;
101
101
  }
102
102
  const addChange = candidatesToPush.get("add");
@@ -105,7 +105,7 @@ function pushAccumulatedChanges(accumulatedPushes, output, pusher, fanOutChangeT
105
105
  addChange === void 0 || removeChange === void 0,
106
106
  "Fan-in:child expected either add or remove, not both"
107
107
  );
108
- output.push(
108
+ yield* output.push(
109
109
  addEmptyRelationships(must(addChange ?? removeChange)),
110
110
  pusher
111
111
  );