@rocicorp/zero 0.26.0-canary.8 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (275) hide show
  1. package/out/ast-to-zql/src/ast-to-zql.d.ts.map +1 -1
  2. package/out/ast-to-zql/src/ast-to-zql.js +16 -27
  3. package/out/ast-to-zql/src/ast-to-zql.js.map +1 -1
  4. package/out/otel/src/log-options.d.ts +2 -2
  5. package/out/replicache/src/bg-interval.d.ts.map +1 -1
  6. package/out/replicache/src/bg-interval.js +3 -0
  7. package/out/replicache/src/bg-interval.js.map +1 -1
  8. package/out/shared/src/arrays.js +1 -1
  9. package/out/shared/src/arrays.js.map +1 -1
  10. package/out/shared/src/browser-env.js +0 -4
  11. package/out/shared/src/browser-env.js.map +1 -1
  12. package/out/shared/src/btree-set.js +4 -1
  13. package/out/shared/src/btree-set.js.map +1 -1
  14. package/out/shared/src/options.js +1 -1
  15. package/out/shared/src/options.js.map +1 -1
  16. package/out/shared/src/queue.js +1 -1
  17. package/out/shared/src/queue.js.map +1 -1
  18. package/out/z2s/src/compiler.d.ts.map +1 -1
  19. package/out/z2s/src/compiler.js +13 -11
  20. package/out/z2s/src/compiler.js.map +1 -1
  21. package/out/zero/package.json.js +1 -1
  22. package/out/zero/src/react.js +1 -3
  23. package/out/zero/src/react.js.map +1 -1
  24. package/out/zero-cache/src/auth/read-authorizer.js +0 -7
  25. package/out/zero-cache/src/auth/read-authorizer.js.map +1 -1
  26. package/out/zero-cache/src/config/network.d.ts +3 -2
  27. package/out/zero-cache/src/config/network.d.ts.map +1 -1
  28. package/out/zero-cache/src/config/network.js +9 -2
  29. package/out/zero-cache/src/config/network.js.map +1 -1
  30. package/out/zero-cache/src/config/server-context.d.ts +16 -0
  31. package/out/zero-cache/src/config/server-context.d.ts.map +1 -0
  32. package/out/zero-cache/src/config/server-context.js +32 -0
  33. package/out/zero-cache/src/config/server-context.js.map +1 -0
  34. package/out/zero-cache/src/config/zero-config.d.ts +3 -3
  35. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  36. package/out/zero-cache/src/config/zero-config.js +2 -6
  37. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  38. package/out/zero-cache/src/db/migration.d.ts.map +1 -1
  39. package/out/zero-cache/src/db/migration.js +40 -51
  40. package/out/zero-cache/src/db/migration.js.map +1 -1
  41. package/out/zero-cache/src/db/run-transaction.d.ts +17 -0
  42. package/out/zero-cache/src/db/run-transaction.d.ts.map +1 -0
  43. package/out/zero-cache/src/db/run-transaction.js +24 -0
  44. package/out/zero-cache/src/db/run-transaction.js.map +1 -0
  45. package/out/zero-cache/src/db/transaction-pool.d.ts.map +1 -1
  46. package/out/zero-cache/src/db/transaction-pool.js +3 -3
  47. package/out/zero-cache/src/db/transaction-pool.js.map +1 -1
  48. package/out/zero-cache/src/scripts/decommission.d.ts +1 -1
  49. package/out/zero-cache/src/scripts/deploy-permissions.js +2 -1
  50. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  51. package/out/zero-cache/src/scripts/permissions.d.ts +1 -1
  52. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  53. package/out/zero-cache/src/server/change-streamer.js +6 -2
  54. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  55. package/out/zero-cache/src/server/main.js +1 -1
  56. package/out/zero-cache/src/server/main.js.map +1 -1
  57. package/out/zero-cache/src/server/runner/run-worker.d.ts.map +1 -1
  58. package/out/zero-cache/src/server/runner/run-worker.js +7 -3
  59. package/out/zero-cache/src/server/runner/run-worker.js.map +1 -1
  60. package/out/zero-cache/src/services/change-source/common/backfill-manager.d.ts +1 -1
  61. package/out/zero-cache/src/services/change-source/common/backfill-manager.js +4 -4
  62. package/out/zero-cache/src/services/change-source/common/backfill-manager.js.map +1 -1
  63. package/out/zero-cache/src/services/change-source/common/replica-schema.d.ts.map +1 -1
  64. package/out/zero-cache/src/services/change-source/common/replica-schema.js +11 -0
  65. package/out/zero-cache/src/services/change-source/common/replica-schema.js.map +1 -1
  66. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts +5 -2
  67. package/out/zero-cache/src/services/change-source/custom/change-source.d.ts.map +1 -1
  68. package/out/zero-cache/src/services/change-source/custom/change-source.js +6 -6
  69. package/out/zero-cache/src/services/change-source/custom/change-source.js.map +1 -1
  70. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +6 -4
  71. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  72. package/out/zero-cache/src/services/change-source/pg/change-source.js +130 -43
  73. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  74. package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
  75. package/out/zero-cache/src/services/change-source/pg/decommission.js +2 -1
  76. package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
  77. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +4 -1
  78. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  79. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +35 -10
  80. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  81. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js +1 -1
  82. package/out/zero-cache/src/services/change-source/pg/logical-replication/stream.js.map +1 -1
  83. package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
  84. package/out/zero-cache/src/services/change-source/pg/schema/init.js +10 -0
  85. package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
  86. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +6 -3
  87. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
  88. package/out/zero-cache/src/services/change-source/pg/schema/shard.js +19 -10
  89. package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
  90. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts +1 -0
  91. package/out/zero-cache/src/services/change-source/protocol/current/data.d.ts.map +1 -1
  92. package/out/zero-cache/src/services/change-source/protocol/current/data.js +4 -2
  93. package/out/zero-cache/src/services/change-source/protocol/current/data.js.map +1 -1
  94. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts +3 -0
  95. package/out/zero-cache/src/services/change-source/protocol/current/downstream.d.ts.map +1 -1
  96. package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts +6 -4
  97. package/out/zero-cache/src/services/change-source/protocol/current/status.d.ts.map +1 -1
  98. package/out/zero-cache/src/services/change-source/protocol/current/status.js.map +1 -1
  99. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts +2 -2
  100. package/out/zero-cache/src/services/change-streamer/backup-monitor.d.ts.map +1 -1
  101. package/out/zero-cache/src/services/change-streamer/backup-monitor.js +30 -12
  102. package/out/zero-cache/src/services/change-streamer/backup-monitor.js.map +1 -1
  103. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js +23 -3
  104. package/out/zero-cache/src/services/change-streamer/change-streamer-service.js.map +1 -1
  105. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts +1 -0
  106. package/out/zero-cache/src/services/change-streamer/change-streamer.d.ts.map +1 -1
  107. package/out/zero-cache/src/services/change-streamer/forwarder.js +1 -1
  108. package/out/zero-cache/src/services/change-streamer/forwarder.js.map +1 -1
  109. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts +1 -1
  110. package/out/zero-cache/src/services/change-streamer/schema/tables.d.ts.map +1 -1
  111. package/out/zero-cache/src/services/change-streamer/schema/tables.js +12 -4
  112. package/out/zero-cache/src/services/change-streamer/schema/tables.js.map +1 -1
  113. package/out/zero-cache/src/services/change-streamer/storer.d.ts +11 -2
  114. package/out/zero-cache/src/services/change-streamer/storer.d.ts.map +1 -1
  115. package/out/zero-cache/src/services/change-streamer/storer.js +80 -42
  116. package/out/zero-cache/src/services/change-streamer/storer.js.map +1 -1
  117. package/out/zero-cache/src/services/litestream/commands.d.ts +1 -1
  118. package/out/zero-cache/src/services/litestream/commands.d.ts.map +1 -1
  119. package/out/zero-cache/src/services/litestream/commands.js +2 -1
  120. package/out/zero-cache/src/services/litestream/commands.js.map +1 -1
  121. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  122. package/out/zero-cache/src/services/mutagen/mutagen.js +22 -17
  123. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  124. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts +10 -1
  125. package/out/zero-cache/src/services/replicator/schema/replication-state.d.ts.map +1 -1
  126. package/out/zero-cache/src/services/replicator/schema/replication-state.js +49 -9
  127. package/out/zero-cache/src/services/replicator/schema/replication-state.js.map +1 -1
  128. package/out/zero-cache/src/services/running-state.d.ts +1 -0
  129. package/out/zero-cache/src/services/running-state.d.ts.map +1 -1
  130. package/out/zero-cache/src/services/running-state.js +3 -0
  131. package/out/zero-cache/src/services/running-state.js.map +1 -1
  132. package/out/zero-cache/src/services/view-syncer/cvr-purger.d.ts.map +1 -1
  133. package/out/zero-cache/src/services/view-syncer/cvr-purger.js +32 -28
  134. package/out/zero-cache/src/services/view-syncer/cvr-purger.js.map +1 -1
  135. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  136. package/out/zero-cache/src/services/view-syncer/cvr-store.js +329 -155
  137. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  138. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  139. package/out/zero-cache/src/services/view-syncer/cvr.js +387 -345
  140. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  141. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  142. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +68 -16
  143. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  144. package/out/zero-cache/src/services/view-syncer/row-record-cache.d.ts.map +1 -1
  145. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +13 -8
  146. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  147. package/out/zero-cache/src/services/view-syncer/tracer.d.ts +2 -0
  148. package/out/zero-cache/src/services/view-syncer/tracer.d.ts.map +1 -0
  149. package/out/zero-cache/src/services/view-syncer/tracer.js +7 -0
  150. package/out/zero-cache/src/services/view-syncer/tracer.js.map +1 -0
  151. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  152. package/out/zero-cache/src/services/view-syncer/view-syncer.js +58 -43
  153. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  154. package/out/zero-cache/src/types/pg.js +0 -4
  155. package/out/zero-cache/src/types/pg.js.map +1 -1
  156. package/out/zero-cache/src/types/streams.d.ts +3 -1
  157. package/out/zero-cache/src/types/streams.d.ts.map +1 -1
  158. package/out/zero-cache/src/types/streams.js +1 -1
  159. package/out/zero-cache/src/types/streams.js.map +1 -1
  160. package/out/zero-cache/src/types/subscription.d.ts +7 -1
  161. package/out/zero-cache/src/types/subscription.d.ts.map +1 -1
  162. package/out/zero-cache/src/types/subscription.js +8 -2
  163. package/out/zero-cache/src/types/subscription.js.map +1 -1
  164. package/out/zero-client/src/client/options.d.ts +7 -7
  165. package/out/zero-client/src/client/options.d.ts.map +1 -1
  166. package/out/zero-client/src/client/options.js.map +1 -1
  167. package/out/zero-client/src/client/query-manager.js +1 -1
  168. package/out/zero-client/src/client/query-manager.js.map +1 -1
  169. package/out/zero-client/src/client/version.js +1 -1
  170. package/out/zero-client/src/client/zero-poke-handler.d.ts +5 -5
  171. package/out/zero-client/src/client/zero-poke-handler.d.ts.map +1 -1
  172. package/out/zero-client/src/client/zero-poke-handler.js +15 -17
  173. package/out/zero-client/src/client/zero-poke-handler.js.map +1 -1
  174. package/out/zero-client/src/client/zero.d.ts +6 -2
  175. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  176. package/out/zero-client/src/client/zero.js +44 -8
  177. package/out/zero-client/src/client/zero.js.map +1 -1
  178. package/out/zero-client/src/mod.d.ts +1 -1
  179. package/out/zero-client/src/mod.d.ts.map +1 -1
  180. package/out/zero-protocol/src/ast.d.ts +2 -9
  181. package/out/zero-protocol/src/ast.d.ts.map +1 -1
  182. package/out/zero-protocol/src/ast.js +15 -32
  183. package/out/zero-protocol/src/ast.js.map +1 -1
  184. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  185. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  186. package/out/zero-protocol/src/protocol-version.js +5 -2
  187. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  188. package/out/zero-react/src/mod.d.ts +0 -2
  189. package/out/zero-react/src/mod.d.ts.map +1 -1
  190. package/out/zero-react/src/use-query.d.ts +6 -6
  191. package/out/zero-react/src/use-query.d.ts.map +1 -1
  192. package/out/zero-react/src/use-query.js +9 -2
  193. package/out/zero-react/src/use-query.js.map +1 -1
  194. package/out/zero-react/src/zero-provider.d.ts +5 -5
  195. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  196. package/out/zero-react/src/zero-provider.js.map +1 -1
  197. package/out/zero-solid/src/solid-view.d.ts +0 -42
  198. package/out/zero-solid/src/solid-view.d.ts.map +1 -1
  199. package/out/zero-solid/src/solid-view.js +1 -1
  200. package/out/zero-solid/src/solid-view.js.map +1 -1
  201. package/out/zero-solid/src/use-query.d.ts +4 -4
  202. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  203. package/out/zero-solid/src/use-query.js.map +1 -1
  204. package/out/zero-solid/src/use-zero.d.ts +5 -5
  205. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  206. package/out/zero-solid/src/use-zero.js.map +1 -1
  207. package/out/zero-types/src/default-types.d.ts +2 -0
  208. package/out/zero-types/src/default-types.d.ts.map +1 -1
  209. package/out/zql/src/builder/builder.d.ts.map +1 -1
  210. package/out/zql/src/builder/builder.js +6 -48
  211. package/out/zql/src/builder/builder.js.map +1 -1
  212. package/out/zql/src/builder/filter.d.ts.map +1 -1
  213. package/out/zql/src/builder/filter.js +0 -1
  214. package/out/zql/src/builder/filter.js.map +1 -1
  215. package/out/zql/src/ivm/array-view.d.ts.map +1 -1
  216. package/out/zql/src/ivm/array-view.js +6 -57
  217. package/out/zql/src/ivm/array-view.js.map +1 -1
  218. package/out/zql/src/ivm/view-apply-change.d.ts +3 -50
  219. package/out/zql/src/ivm/view-apply-change.d.ts.map +1 -1
  220. package/out/zql/src/ivm/view-apply-change.js +105 -358
  221. package/out/zql/src/ivm/view-apply-change.js.map +1 -1
  222. package/out/zql/src/mutate/mutator-registry.d.ts +3 -3
  223. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -1
  224. package/out/zql/src/mutate/mutator-registry.js.map +1 -1
  225. package/out/zql/src/planner/planner-builder.d.ts.map +1 -1
  226. package/out/zql/src/planner/planner-builder.js +1 -2
  227. package/out/zql/src/planner/planner-builder.js.map +1 -1
  228. package/out/zql/src/query/complete-ordering.js +0 -6
  229. package/out/zql/src/query/complete-ordering.js.map +1 -1
  230. package/out/zql/src/query/expression.d.ts +2 -19
  231. package/out/zql/src/query/expression.d.ts.map +1 -1
  232. package/out/zql/src/query/expression.js +6 -50
  233. package/out/zql/src/query/expression.js.map +1 -1
  234. package/out/zql/src/query/query-delegate-base.js +3 -1
  235. package/out/zql/src/query/query-delegate-base.js.map +1 -1
  236. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  237. package/out/zql/src/query/query-impl.js +8 -12
  238. package/out/zql/src/query/query-impl.js.map +1 -1
  239. package/out/zql/src/query/query-internals.js.map +1 -1
  240. package/out/zql/src/query/query-registry.d.ts +3 -3
  241. package/out/zql/src/query/query-registry.d.ts.map +1 -1
  242. package/out/zql/src/query/query-registry.js.map +1 -1
  243. package/out/zql/src/query/query.d.ts +28 -5
  244. package/out/zql/src/query/query.d.ts.map +1 -1
  245. package/out/zqlite/src/query-builder.d.ts +0 -2
  246. package/out/zqlite/src/query-builder.d.ts.map +1 -1
  247. package/out/zqlite/src/query-builder.js.map +1 -1
  248. package/out/zqlite/src/resolve-scalar-subqueries.d.ts +10 -2
  249. package/out/zqlite/src/resolve-scalar-subqueries.d.ts.map +1 -1
  250. package/out/zqlite/src/resolve-scalar-subqueries.js +41 -9
  251. package/out/zqlite/src/resolve-scalar-subqueries.js.map +1 -1
  252. package/out/zqlite/src/sqlite-cost-model.d.ts.map +1 -1
  253. package/out/zqlite/src/sqlite-cost-model.js +0 -1
  254. package/out/zqlite/src/sqlite-cost-model.js.map +1 -1
  255. package/package.json +3 -5
  256. package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts +0 -4
  257. package/out/zero-cache/src/services/change-source/custom/sync-schema.d.ts.map +0 -1
  258. package/out/zero-cache/src/services/change-source/custom/sync-schema.js +0 -14
  259. package/out/zero-cache/src/services/change-source/custom/sync-schema.js.map +0 -1
  260. package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts +0 -5
  261. package/out/zero-cache/src/services/change-source/pg/sync-schema.d.ts.map +0 -1
  262. package/out/zero-cache/src/services/change-source/pg/sync-schema.js +0 -14
  263. package/out/zero-cache/src/services/change-source/pg/sync-schema.js.map +0 -1
  264. package/out/zero-react/src/paging-reducer.d.ts +0 -61
  265. package/out/zero-react/src/paging-reducer.d.ts.map +0 -1
  266. package/out/zero-react/src/paging-reducer.js +0 -77
  267. package/out/zero-react/src/paging-reducer.js.map +0 -1
  268. package/out/zero-react/src/use-rows.d.ts +0 -39
  269. package/out/zero-react/src/use-rows.d.ts.map +0 -1
  270. package/out/zero-react/src/use-rows.js +0 -130
  271. package/out/zero-react/src/use-rows.js.map +0 -1
  272. package/out/zero-react/src/use-zero-virtualizer.d.ts +0 -122
  273. package/out/zero-react/src/use-zero-virtualizer.d.ts.map +0 -1
  274. package/out/zero-react/src/use-zero-virtualizer.js +0 -342
  275. package/out/zero-react/src/use-zero-virtualizer.js.map +0 -1
@@ -25,7 +25,7 @@ export { ANYONE_CAN, ANYONE_CAN_DO_ANYTHING, definePermissions, NOBODY_CAN, } fr
25
25
  export type { AssetPermissions, PermissionRule, PermissionsConfig, } from '../../zero-schema/src/permissions.ts';
26
26
  export { type TableSchema } from '../../zero-schema/src/table-schema.ts';
27
27
  export type { SchemaValue, SchemaValueWithCustomType, ValueType, } from '../../zero-schema/src/table-schema.ts';
28
- export type { DefaultContext, DefaultSchema, DefaultTypes, DefaultWrappedTransaction, } from '../../zero-types/src/default-types.ts';
28
+ export type { BaseDefaultContext, BaseDefaultSchema, DefaultContext, DefaultSchema, DefaultTypes, DefaultWrappedTransaction, } from '../../zero-types/src/default-types.ts';
29
29
  export type { Schema } from '../../zero-types/src/schema.ts';
30
30
  export type { Change } from '../../zql/src/ivm/change.ts';
31
31
  export type { Node } from '../../zql/src/ivm/data.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../zero-client/src/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,2BAA2B,EAAC,MAAM,yCAAyC,CAAC;AACzF,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,YAAY,EAAC,eAAe,EAAC,MAAM,2CAA2C,CAAC;AAC/E,OAAO,EAAC,gBAAgB,EAAC,MAAM,sCAAsC,CAAC;AACtE,YAAY,EACV,WAAW,IAAI,aAAa,EAC5B,IAAI,IAAI,MAAM,EACd,KAAK,IAAI,OAAO,EAChB,KAAK,IAAI,OAAO,GACjB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AAClE,OAAO,EACL,gBAAgB,EAChB,YAAY,GACb,MAAM,uDAAuD,CAAC;AAC/D,YAAY,EAAC,aAAa,EAAE,QAAQ,EAAC,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAC,sBAAsB,EAAC,MAAM,kDAAkD,CAAC;AACxF,YAAY,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AACvD,YAAY,EAAC,KAAK,EAAC,MAAM,2BAA2B,CAAC;AACrD,YAAY,EACV,UAAU,EACV,SAAS,EACT,kBAAkB,EA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= v.Infer<typeof parameterReferenceSchema>;
46
46
  export declare const simpleConditionSchema: v.Type<SimpleCondition>;
47
47
  export declare const correlatedSubqueryConditionOperatorSchema: v.Type<CorrelatedSubqueryConditionOperator>;
48
48
  export declare const correlatedSubqueryConditionSchema: v.Type<CorrelatedSubqueryCondition>;
49
- export declare const scalarSubqueryConditionSchema: v.Type<ScalarSubqueryCondition>;
50
49
  export declare const conditionSchema: v.Type<Condition>;
51
50
  export type CompoundKey = readonly [string, ...string[]];
52
51
  export declare const compoundKeySchema: v.Type<CompoundKey>;
@@ -119,7 +118,7 @@ export type LiteralValue = string | number | boolean | null | ReadonlyArray<stri
119
118
  * ivm1 supports Conjunctions and Disjunctions.
120
119
  * We'll support them in the future.
121
120
  */
122
- export type Condition = SimpleCondition | Conjunction | Disjunction | CorrelatedSubqueryCondition | ScalarSubqueryCondition;
121
+ export type Condition = SimpleCondition | Conjunction | Disjunction | CorrelatedSubqueryCondition;
123
122
  export type SimpleCondition = {
124
123
  readonly type: 'simple';
125
124
  readonly op: SimpleOperator;
@@ -143,16 +142,10 @@ export type CorrelatedSubqueryCondition = {
143
142
  related: CorrelatedSubquery;
144
143
  op: CorrelatedSubqueryConditionOperator;
145
144
  flip?: boolean | undefined;
145
+ scalar?: boolean | undefined;
146
146
  [planIdSymbol]?: number | undefined;
147
147
  };
148
148
  export type CorrelatedSubqueryConditionOperator = 'EXISTS' | 'NOT EXISTS';
149
- export type ScalarSubqueryCondition = {
150
- type: 'scalarSubquery';
151
- op: '=' | 'IS NOT';
152
- parentField: string;
153
- subquery: AST;
154
- childField: string;
155
- };
156
149
  export declare function normalizeAST(ast: AST): Required<AST>;
157
150
  export declare function mapAST(ast: AST, mapper: NameMapper): Required<AST>;
158
151
  export declare function mapCondition(cond: Condition, table: string, mapper: NameMapper): Condition;
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../../../zero-protocol/src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA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 const correlatedSubqueryConditionSchema = readonlyObject({
74
74
  type: literal("correlatedSubquery"),
75
75
  related: lazy(() => correlatedSubquerySchema),
76
76
  op: correlatedSubqueryConditionOperatorSchema,
77
- flip: boolean().optional()
78
- });
79
- const scalarSubqueryConditionSchema = readonlyObject({
80
- type: literal("scalarSubquery"),
81
- op: literalUnion("=", "IS NOT"),
82
- parentField: string(),
83
- subquery: lazy(() => astSchema),
84
- childField: string()
77
+ flip: boolean().optional(),
78
+ scalar: boolean().optional()
85
79
  });
86
80
  const conditionSchema = union(
87
81
  simpleConditionSchema,
88
82
  lazy(() => conjunctionSchema),
89
83
  lazy(() => disjunctionSchema),
90
- correlatedSubqueryConditionSchema,
91
- scalarSubqueryConditionSchema
84
+ correlatedSubqueryConditionSchema
92
85
  );
93
86
  const conjunctionSchema = readonlyObject({
94
87
  type: literal("and"),
@@ -99,7 +92,10 @@ const disjunctionSchema = readonlyObject({
99
92
  conditions: readonlyArray(conditionSchema)
100
93
  });
101
94
  function mustCompoundKey(field) {
102
- assert(Array.isArray(field) && field.length >= 1);
95
+ assert(
96
+ Array.isArray(field) && field.length >= 1,
97
+ "Expected non-empty array for compound key"
98
+ );
103
99
  return field;
104
100
  }
105
101
  const compoundKeySchema = readonly(
@@ -192,13 +188,6 @@ function transformWhere(where, table, transform) {
192
188
  subquery: transformAST(subquery, transform)
193
189
  }
194
190
  };
195
- } else if (where.type === "scalarSubquery") {
196
- return {
197
- ...where,
198
- parentField: columnName(table, where.parentField),
199
- childField: columnName(where.subquery.table, where.childField),
200
- subquery: transformAST(where.subquery, transform)
201
- };
202
191
  }
203
192
  return {
204
193
  type: where.type,
@@ -258,20 +247,11 @@ function cmpCondition(a, b) {
258
247
  if (b.type !== "correlatedSubquery") {
259
248
  return -1;
260
249
  }
261
- return cmpRelated(a.related, b.related) || compareUTF8MaybeNull(a.op, b.op);
250
+ return cmpRelated(a.related, b.related) || compareUTF8MaybeNull(a.op, b.op) || cmpOptionalBool(a.flip, b.flip) || cmpOptionalBool(a.scalar, b.scalar);
262
251
  }
263
252
  if (b.type === "correlatedSubquery") {
264
253
  return -1;
265
254
  }
266
- if (a.type === "scalarSubquery") {
267
- if (b.type !== "scalarSubquery") {
268
- return -1;
269
- }
270
- return compareUTF8(a.parentField, b.parentField) || compareUTF8(a.childField, b.childField) || compareUTF8MaybeNull(a.op, b.op);
271
- }
272
- if (b.type === "scalarSubquery") {
273
- return 1;
274
- }
275
255
  const val = compareUTF8MaybeNull(a.type, b.type);
276
256
  if (val !== 0) {
277
257
  return val;
@@ -290,10 +270,10 @@ function compareValuePosition(a, b) {
290
270
  }
291
271
  switch (a.type) {
292
272
  case "literal":
293
- assert(b.type === "literal");
273
+ assert(b.type === "literal", "Expected literal type for comparison");
294
274
  return compareUTF8(String(a.value), String(b.value));
295
275
  case "column":
296
- assert(b.type === "column");
276
+ assert(b.type === "column", "Expected column type for comparison");
297
277
  return compareUTF8(a.name, b.name);
298
278
  case "static":
299
279
  throw new Error(
@@ -305,7 +285,7 @@ function cmpRelated(a, b) {
305
285
  return compareUTF8(must(a.subquery.alias), must(b.subquery.alias));
306
286
  }
307
287
  function flattened(cond) {
308
- if (cond.type === "simple" || cond.type === "correlatedSubquery" || cond.type === "scalarSubquery") {
288
+ if (cond.type === "simple" || cond.type === "correlatedSubquery") {
309
289
  return cond;
310
290
  }
311
291
  const conditions = defined(
@@ -337,6 +317,10 @@ function compareUTF8MaybeNull(a, b) {
337
317
  }
338
318
  return 0;
339
319
  }
320
+ function cmpOptionalBool(a, b) {
321
+ const toNum = (v2) => v2 === void 0 ? 0 : v2 ? 2 : 1;
322
+ return toNum(a) - toNum(b);
323
+ }
340
324
  export {
341
325
  SUBQ_PREFIX,
342
326
  astSchema,
@@ -355,7 +339,6 @@ export {
355
339
  orderOpsSchema,
356
340
  orderingSchema,
357
341
  planIdSymbol,
358
- scalarSubqueryConditionSchema,
359
342
  selectorSchema,
360
343
  simpleConditionSchema,
361
344
  simpleOperatorSchema,
@@ -1 +1 @@
1
- {"version":3,"file":"ast.js","sources":["../../../../zero-protocol/src/ast.ts"],"sourcesContent":["/**\n * Wire-format representation of the zql AST interface.\n *\n * `v.Type<...>` types are explicitly declared to facilitate Typescript verification\n * that the schemas satisfy the zql type definitions. (Incidentally, explicit types\n * are also required for recursive schema definitions.)\n */\n\nimport {compareUTF8} from 'compare-utf8';\nimport {defined} from '../../shared/src/arrays.ts';\nimport {assert} from '../../shared/src/asserts.ts';\nimport {must} from '../../shared/src/must.ts';\nimport * as v from '../../shared/src/valita.ts';\nimport type {NameMapper} from '../../zero-types/src/name-mapper.ts';\nimport {rowSchema, type Row} from './data.ts';\n\nexport const SUBQ_PREFIX = 'zsubq_';\n\nexport const selectorSchema = v.string();\nexport const toStaticParam = Symbol();\nexport const planIdSymbol = Symbol('planId');\n\nconst orderingElementSchema = v.readonly(\n v.tuple([selectorSchema, v.literalUnion('asc', 'desc')]),\n);\n\nexport const orderingSchema = v.readonlyArray(orderingElementSchema);\nexport type System = 'permissions' | 'client' | 'test';\n\nexport const primitiveSchema = v.union(\n v.string(),\n v.number(),\n v.boolean(),\n v.null(),\n);\n\nexport const equalityOpsSchema = v.literalUnion('=', '!=', 'IS', 'IS NOT');\n\nexport const orderOpsSchema = v.literalUnion('<', '>', '<=', '>=');\n\nexport const likeOpsSchema = v.literalUnion(\n 'LIKE',\n 'NOT LIKE',\n 'ILIKE',\n 'NOT ILIKE',\n);\n\nexport const inOpsSchema = v.literalUnion('IN', 'NOT IN');\n\nexport const simpleOperatorSchema = v.union(\n equalityOpsSchema,\n orderOpsSchema,\n likeOpsSchema,\n inOpsSchema,\n);\n\nconst literalReferenceSchema: v.Type<LiteralReference> = v.readonlyObject({\n type: v.literal('literal'),\n value: v.union(\n v.string(),\n v.number(),\n v.boolean(),\n v.null(),\n v.readonlyArray(v.union(v.string(), v.number(), v.boolean())),\n ),\n});\nconst columnReferenceSchema: v.Type<ColumnReference> = v.readonlyObject({\n type: v.literal('column'),\n name: v.string(),\n});\n\n/**\n * A parameter is a value that is not known at the time the query is written\n * and is resolved at runtime.\n *\n * Static parameters refer to something provided by the caller.\n * Static parameters are injected when the query pipeline is built from the AST\n * and do not change for the life of that pipeline.\n *\n * An example static parameter is the current authentication data.\n * When a user is authenticated, queries on the server have access\n * to the user's authentication data in order to evaluate authorization rules.\n * Authentication data doesn't change over the life of a query as a change\n * in auth data would represent a log-in / log-out of the user.\n *\n * AncestorParameters refer to rows encountered while running the query.\n * They are used by subqueries to refer to rows emitted by parent queries.\n */\nconst parameterReferenceSchema = v.readonlyObject({\n type: v.literal('static'),\n // The \"namespace\" of the injected parameter.\n // Write authorization will send the value of a row\n // prior to the mutation being run (preMutationRow).\n // Read and write authorization will both send the\n // current authentication data (authData).\n anchor: v.literalUnion('authData', 'preMutationRow'),\n field: v.union(v.string(), v.array(v.string())),\n});\n\nconst conditionValueSchema = v.union(\n literalReferenceSchema,\n columnReferenceSchema,\n parameterReferenceSchema,\n);\n\nexport type Parameter = v.Infer<typeof parameterReferenceSchema>;\n\nexport const simpleConditionSchema: v.Type<SimpleCondition> = v.readonlyObject({\n type: v.literal('simple'),\n op: simpleOperatorSchema,\n left: conditionValueSchema,\n right: v.union(parameterReferenceSchema, literalReferenceSchema),\n});\n\ntype ConditionValue = v.Infer<typeof conditionValueSchema>;\n\nexport const correlatedSubqueryConditionOperatorSchema: v.Type<CorrelatedSubqueryConditionOperator> =\n v.literalUnion('EXISTS', 'NOT EXISTS');\n\nexport const correlatedSubqueryConditionSchema: v.Type<CorrelatedSubqueryCondition> =\n v.readonlyObject({\n type: v.literal('correlatedSubquery'),\n related: v.lazy(() => correlatedSubquerySchema),\n op: correlatedSubqueryConditionOperatorSchema,\n flip: v.boolean().optional(),\n });\n\nexport const scalarSubqueryConditionSchema: v.Type<ScalarSubqueryCondition> =\n v.readonlyObject({\n type: v.literal('scalarSubquery'),\n op: v.literalUnion('=', 'IS NOT'),\n parentField: v.string(),\n subquery: v.lazy(() => astSchema),\n childField: v.string(),\n });\n\nexport const conditionSchema: v.Type<Condition> = v.union(\n simpleConditionSchema,\n v.lazy(() => conjunctionSchema),\n v.lazy(() => disjunctionSchema),\n correlatedSubqueryConditionSchema,\n scalarSubqueryConditionSchema,\n);\n\nconst conjunctionSchema: v.Type<Conjunction> = v.readonlyObject({\n type: v.literal('and'),\n conditions: v.readonlyArray(conditionSchema),\n});\n\nconst disjunctionSchema: v.Type<Disjunction> = v.readonlyObject({\n type: v.literal('or'),\n conditions: v.readonlyArray(conditionSchema),\n});\n\nexport type CompoundKey = readonly [string, ...string[]];\n\nfunction mustCompoundKey(field: readonly string[]): CompoundKey {\n assert(Array.isArray(field) && field.length >= 1);\n return field as unknown as CompoundKey;\n}\n\nexport const compoundKeySchema: v.Type<CompoundKey> = v.readonly(\n v.tuple([v.string()]).concat(v.array(v.string())),\n);\n\nconst correlationSchema = v.readonlyObject({\n parentField: compoundKeySchema,\n childField: compoundKeySchema,\n});\n\n// Split out so that its inferred type can be checked against\n// Omit<CorrelatedSubquery, 'correlation'> in ast-type-test.ts.\n// The mutually-recursive reference of the 'other' field to astSchema\n// is the only thing added in v.lazy. The v.lazy is necessary due to the\n// mutually-recursive types, but v.lazy prevents inference of the resulting\n// type.\nexport const correlatedSubquerySchemaOmitSubquery = v.readonlyObject({\n correlation: correlationSchema,\n hidden: v.boolean().optional(),\n system: v.literalUnion('permissions', 'client', 'test').optional(),\n});\n\nexport const correlatedSubquerySchema: v.Type<CorrelatedSubquery> =\n correlatedSubquerySchemaOmitSubquery.extend({\n subquery: v.lazy(() => astSchema),\n });\n\nexport const astSchema: v.Type<AST> = v.readonlyObject({\n schema: v.string().optional(),\n table: v.string(),\n alias: v.string().optional(),\n where: conditionSchema.optional(),\n related: v.readonlyArray(correlatedSubquerySchema).optional(),\n limit: v.number().optional(),\n orderBy: orderingSchema.optional(),\n start: v\n .object({\n row: rowSchema,\n exclusive: v.boolean(),\n })\n .optional(),\n});\n\nexport type Bound = {\n row: Row;\n exclusive: boolean;\n};\n\n/**\n * As in SQL you can have multiple orderings. We don't currently\n * support ordering on anything other than the root query.\n */\nexport type OrderPart = readonly [field: string, direction: 'asc' | 'desc'];\nexport type Ordering = readonly OrderPart[];\n\nexport type SimpleOperator = EqualityOps | OrderOps | LikeOps | InOps;\nexport type EqualityOps = '=' | '!=' | 'IS' | 'IS NOT';\nexport type OrderOps = '<' | '>' | '<=' | '>=';\nexport type LikeOps = 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE';\nexport type InOps = 'IN' | 'NOT IN';\n\nexport type AST = {\n readonly schema?: string | undefined;\n readonly table: string;\n\n // A query would be aliased if the AST is a subquery.\n // e.g., when two subqueries select from the same table\n // they need an alias to differentiate them.\n // `SELECT\n // [SELECT * FROM issue WHERE issue.id = outer.parentId] AS parent\n // [SELECT * FROM issue WHERE issue.parentId = outer.id] AS children\n // FROM issue as outer`\n readonly alias?: string | undefined;\n\n // `select` is missing given we return all columns for now.\n\n // The PipelineBuilder will pick what to use to correlate\n // a subquery with a parent query. It can choose something from the\n // where conditions or choose the _first_ `related` entry.\n // Choosing the first `related` entry is almost always the best choice if\n // one exists.\n readonly where?: Condition | undefined;\n\n readonly related?: readonly CorrelatedSubquery[] | undefined;\n readonly start?: Bound | undefined;\n readonly limit?: number | undefined;\n readonly orderBy?: Ordering | undefined;\n};\n\nexport type Correlation = {\n readonly parentField: CompoundKey;\n readonly childField: CompoundKey;\n};\n\nexport type CorrelatedSubquery = {\n /**\n * Only equality correlation are supported for now.\n * E.g., direct foreign key relationships.\n */\n readonly correlation: Correlation;\n readonly subquery: AST;\n readonly system?: System | undefined;\n // If a hop in the subquery chain should be hidden from the output view.\n // A common example is junction edges. The query API provides the illusion\n // that they don't exist: `issue.related('labels')` instead of `issue.related('issue_labels').related('labels')`.\n // To maintain this illusion, the junction edge should be hidden.\n // When `hidden` is set to true, this hop will not be included in the output view\n // but its children will be.\n readonly hidden?: boolean | undefined;\n};\n\nexport type ValuePosition = LiteralReference | Parameter | ColumnReference;\n\nexport type ColumnReference = {\n readonly type: 'column';\n /**\n * Not a path yet as we're currently not allowing\n * comparisons across tables. This will need to\n * be a path through the tree in the near future.\n */\n readonly name: string;\n};\n\nexport type LiteralReference = {\n readonly type: 'literal';\n readonly value: LiteralValue;\n};\n\nexport type LiteralValue =\n | string\n | number\n | boolean\n | null\n | ReadonlyArray<string | number | boolean>;\n\n/**\n * Starting only with SimpleCondition for now.\n * ivm1 supports Conjunctions and Disjunctions.\n * We'll support them in the future.\n */\nexport type Condition =\n | SimpleCondition\n | Conjunction\n | Disjunction\n | CorrelatedSubqueryCondition\n | ScalarSubqueryCondition;\n\nexport type SimpleCondition = {\n readonly type: 'simple';\n readonly op: SimpleOperator;\n readonly left: ValuePosition;\n\n /**\n * `null` is absent since we do not have an `IS` or `IS NOT`\n * operator defined and `null != null` in SQL.\n */\n readonly right: Exclude<ValuePosition, ColumnReference>;\n};\n\nexport type Conjunction = {\n type: 'and';\n conditions: readonly Condition[];\n};\n\nexport type Disjunction = {\n type: 'or';\n conditions: readonly Condition[];\n};\n\nexport type CorrelatedSubqueryCondition = {\n type: 'correlatedSubquery';\n related: CorrelatedSubquery;\n op: CorrelatedSubqueryConditionOperator;\n flip?: boolean | undefined;\n [planIdSymbol]?: number | undefined;\n};\n\nexport type CorrelatedSubqueryConditionOperator = 'EXISTS' | 'NOT EXISTS';\n\nexport type ScalarSubqueryCondition = {\n type: 'scalarSubquery';\n op: '=' | 'IS NOT';\n parentField: string;\n subquery: AST;\n childField: string;\n};\n\ninterface ASTTransform {\n tableName(orig: string): string;\n columnName(origTable: string, origColumn: string): string;\n related(subqueries: CorrelatedSubquery[]): readonly CorrelatedSubquery[];\n where(cond: Condition): Condition | undefined;\n // conjunction or disjunction, called when traversing the return value of where()\n conditions(conds: Condition[]): readonly Condition[];\n}\n\nfunction transformAST(ast: AST, transform: ASTTransform): Required<AST> {\n // Name mapping functions (e.g. to server names)\n const {tableName, columnName} = transform;\n const colName = (c: string) => columnName(ast.table, c);\n const key = (table: string, k: CompoundKey) => {\n const serverKey = k.map(col => columnName(table, col));\n return mustCompoundKey(serverKey);\n };\n\n const where = ast.where ? transform.where(ast.where) : undefined;\n const transformed = {\n schema: ast.schema,\n table: tableName(ast.table),\n alias: ast.alias,\n where: where ? transformWhere(where, ast.table, transform) : undefined,\n related: ast.related\n ? transform.related(\n ast.related.map(\n r =>\n ({\n correlation: {\n parentField: key(ast.table, r.correlation.parentField),\n childField: key(r.subquery.table, r.correlation.childField),\n },\n hidden: r.hidden,\n subquery: transformAST(r.subquery, transform),\n system: r.system,\n }) satisfies Required<CorrelatedSubquery>,\n ),\n )\n : undefined,\n start: ast.start\n ? {\n ...ast.start,\n row: Object.fromEntries(\n Object.entries(ast.start.row).map(([col, val]) => [\n colName(col),\n val,\n ]),\n ),\n }\n : undefined,\n limit: ast.limit,\n orderBy: ast.orderBy?.map(([col, dir]) => [colName(col), dir] as const),\n };\n\n return transformed;\n}\n\nfunction transformWhere(\n where: Condition,\n table: string,\n transform: ASTTransform,\n): Condition {\n // Name mapping functions (e.g. to server names)\n const {columnName} = transform;\n const condValue = (c: ConditionValue) =>\n c.type !== 'column' ? c : {...c, name: columnName(table, c.name)};\n const key = (table: string, k: CompoundKey) => {\n const serverKey = k.map(col => columnName(table, col));\n return mustCompoundKey(serverKey);\n };\n\n if (where.type === 'simple') {\n return {...where, left: condValue(where.left)};\n } else if (where.type === 'correlatedSubquery') {\n const {correlation, subquery} = where.related;\n return {\n ...where,\n related: {\n ...where.related,\n correlation: {\n parentField: key(table, correlation.parentField),\n childField: key(subquery.table, correlation.childField),\n },\n subquery: transformAST(subquery, transform),\n },\n };\n } else if (where.type === 'scalarSubquery') {\n return {\n ...where,\n parentField: columnName(table, where.parentField),\n childField: columnName(where.subquery.table, where.childField),\n subquery: transformAST(where.subquery, transform),\n };\n }\n\n return {\n type: where.type,\n conditions: transform.conditions(\n where.conditions.map(c => transformWhere(c, table, transform)),\n ),\n };\n}\n\nconst normalizeCache = new WeakMap<AST, Required<AST>>();\n\nconst NORMALIZE_TRANSFORM: ASTTransform = {\n tableName: t => t,\n columnName: (_, c) => c,\n related: sortedRelated,\n where: flattened,\n conditions: c => c.sort(cmpCondition),\n};\n\nexport function normalizeAST(ast: AST): Required<AST> {\n let normalized = normalizeCache.get(ast);\n if (!normalized) {\n normalized = transformAST(ast, NORMALIZE_TRANSFORM);\n normalizeCache.set(ast, normalized);\n }\n return normalized;\n}\n\nexport function mapAST(ast: AST, mapper: NameMapper) {\n return transformAST(ast, {\n tableName: table => mapper.tableName(table),\n columnName: (table, col) => mapper.columnName(table, col),\n related: r => r,\n where: w => w,\n conditions: c => c,\n });\n}\n\nexport function mapCondition(\n cond: Condition,\n table: string,\n mapper: NameMapper,\n) {\n return transformWhere(cond, table, {\n tableName: table => mapper.tableName(table),\n columnName: (table, col) => mapper.columnName(table, col),\n related: r => r,\n where: w => w,\n conditions: c => c,\n });\n}\n\nfunction sortedRelated(\n related: CorrelatedSubquery[],\n): readonly CorrelatedSubquery[] {\n return related.sort(cmpRelated);\n}\n\nfunction cmpCondition(a: Condition, b: Condition): number {\n if (a.type === 'simple') {\n if (b.type !== 'simple') {\n return -1; // Order SimpleConditions first\n }\n\n return (\n compareValuePosition(a.left, b.left) ||\n compareUTF8MaybeNull(a.op, b.op) ||\n compareValuePosition(a.right, b.right)\n );\n }\n\n if (b.type === 'simple') {\n return 1; // Order SimpleConditions first\n }\n\n if (a.type === 'correlatedSubquery') {\n if (b.type !== 'correlatedSubquery') {\n return -1; // Order subquery before conjuctions/disjuctions\n }\n return cmpRelated(a.related, b.related) || compareUTF8MaybeNull(a.op, b.op);\n }\n if (b.type === 'correlatedSubquery') {\n return -1; // Order correlatedSubquery before conjuctions/disjuctions\n }\n\n if (a.type === 'scalarSubquery') {\n if (b.type !== 'scalarSubquery') {\n return -1; // Order scalarSubquery before conjunctions/disjunctions\n }\n return (\n compareUTF8(a.parentField, b.parentField) ||\n compareUTF8(a.childField, b.childField) ||\n compareUTF8MaybeNull(a.op, b.op)\n );\n }\n if (b.type === 'scalarSubquery') {\n return 1;\n }\n\n const val = compareUTF8MaybeNull(a.type, b.type);\n if (val !== 0) {\n return val;\n }\n for (\n let l = 0, r = 0;\n l < a.conditions.length && r < b.conditions.length;\n l++, r++\n ) {\n const val = cmpCondition(a.conditions[l], b.conditions[r]);\n if (val !== 0) {\n return val;\n }\n }\n // prefixes first\n return a.conditions.length - b.conditions.length;\n}\n\nfunction compareValuePosition(a: ValuePosition, b: ValuePosition): number {\n if (a.type !== b.type) {\n return compareUTF8(a.type, b.type);\n }\n switch (a.type) {\n case 'literal':\n assert(b.type === 'literal');\n return compareUTF8(String(a.value), String(b.value));\n case 'column':\n assert(b.type === 'column');\n return compareUTF8(a.name, b.name);\n case 'static':\n throw new Error(\n 'Static parameters should be resolved before normalization',\n );\n }\n}\n\nfunction cmpRelated(a: CorrelatedSubquery, b: CorrelatedSubquery): number {\n return compareUTF8(must(a.subquery.alias), must(b.subquery.alias));\n}\n\n/**\n * Returns a flattened version of the Conditions in which nested Conjunctions with\n * the same operation ('AND' or 'OR') are flattened to the same level. e.g.\n *\n * ```\n * ((a AND b) AND (c AND (d OR (e OR f)))) -> (a AND b AND c AND (d OR e OR f))\n * ```\n *\n * Also flattens singleton Conjunctions regardless of operator, and removes\n * empty Conjunctions.\n */\nfunction flattened(cond: Condition): Condition | undefined {\n if (\n cond.type === 'simple' ||\n cond.type === 'correlatedSubquery' ||\n cond.type === 'scalarSubquery'\n ) {\n return cond;\n }\n const conditions = defined(\n cond.conditions.flatMap(c =>\n c.type === cond.type ? c.conditions.map(c => flattened(c)) : flattened(c),\n ),\n );\n\n switch (conditions.length) {\n case 0:\n return undefined;\n case 1:\n return conditions[0];\n default:\n return {\n type: cond.type,\n conditions,\n };\n }\n}\n\nfunction compareUTF8MaybeNull(a: string | null, b: string | null): number {\n if (a !== null && b !== null) {\n return compareUTF8(a, b);\n }\n if (b !== null) {\n return -1;\n }\n if (a !== null) {\n return 1;\n }\n return 0;\n}\n"],"names":["v.string","v.readonly","v.tuple","v.literalUnion","v.readonlyArray","v.union","v.number","v.boolean","v.null","v.readonlyObject","v.literal","v.array","v.lazy","v.object","table","val","c"],"mappings":";;;;;;;AAgBO,MAAM,cAAc;AAEpB,MAAM,iBAAiBA,OAAE;AACzB,MAAM,gBAAgB,OAAA;AACtB,MAAM,eAAe,OAAO,QAAQ;AAE3C,MAAM,wBAAwBC;AAAAA,EAC5BC,MAAQ,CAAC,gBAAgBC,aAAe,OAAO,MAAM,CAAC,CAAC;AACzD;AAEO,MAAM,iBAAiBC,cAAgB,qBAAqB;AAGpCC;AAAAA,EAC7BL,OAAE;AAAA,EACFM,OAAE;AAAA,EACFC,QAAE;AAAA,EACFC,MAAE;AACJ;AAEO,MAAM,oBAAoBL,aAAe,KAAK,MAAM,MAAM,QAAQ;AAElE,MAAM,iBAAiBA,aAAe,KAAK,KAAK,MAAM,IAAI;AAE1D,MAAM,gBAAgBA;AAAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,cAAcA,aAAe,MAAM,QAAQ;AAEjD,MAAM,uBAAuBE;AAAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,yBAAmDI,eAAiB;AAAA,EACxE,MAAMC,QAAU,SAAS;AAAA,EACzB,OAAOL;AAAAA,IACLL,OAAE;AAAA,IACFM,OAAE;AAAA,IACFC,QAAE;AAAA,IACFC,MAAE;AAAA,IACFJ,cAAgBC,MAAQL,OAAE,GAAUM,OAAE,GAAUC,QAAE,CAAS,CAAC;AAAA,EAAA;AAEhE,CAAC;AACD,MAAM,wBAAiDE,eAAiB;AAAA,EACtE,MAAMC,QAAU,QAAQ;AAAA,EACxB,MAAMV,OAAE;AACV,CAAC;AAmBD,MAAM,2BAA2BS,eAAiB;AAAA,EAChD,MAAMC,QAAU,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,QAAQP,aAAe,YAAY,gBAAgB;AAAA,EACnD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,WAAW,CAAC;AAAA,IACrB;AACE,aAAO;AAAA,QACL,MAAM,KAAK;AAAA,QACX;AAAA,MAAA;AAAA,EACF;AAEN;AAEA,SAAS,qBAAqB,GAAkB,GAA0B;AACxE,MAAI,MAAM,QAAQ,MAAM,MAAM;AAC5B,WAAO,YAAY,GAAG,CAAC;AAAA,EACzB;AACA,MAAI,MAAM,MAAM;AACd,WAAO;AAAA,EACT;AACA,MAAI,MAAM,MAAM;AACd,WAAO;AAAA,EACT;AACA,SAAO;AACT;"}
1
+ {"version":3,"file":"ast.js","sources":["../../../../zero-protocol/src/ast.ts"],"sourcesContent":["/**\n * Wire-format representation of the zql AST interface.\n *\n * `v.Type<...>` types are explicitly declared to facilitate Typescript verification\n * that the schemas satisfy the zql type definitions. (Incidentally, explicit types\n * are also required for recursive schema definitions.)\n */\n\nimport {compareUTF8} from 'compare-utf8';\nimport {defined} from '../../shared/src/arrays.ts';\nimport {assert} from '../../shared/src/asserts.ts';\nimport {must} from '../../shared/src/must.ts';\nimport * as v from '../../shared/src/valita.ts';\nimport type {NameMapper} from '../../zero-types/src/name-mapper.ts';\nimport {rowSchema, type Row} from './data.ts';\n\nexport const SUBQ_PREFIX = 'zsubq_';\n\nexport const selectorSchema = v.string();\nexport const toStaticParam = Symbol();\nexport const planIdSymbol = Symbol('planId');\n\nconst orderingElementSchema = v.readonly(\n v.tuple([selectorSchema, v.literalUnion('asc', 'desc')]),\n);\n\nexport const orderingSchema = v.readonlyArray(orderingElementSchema);\nexport type System = 'permissions' | 'client' | 'test';\n\nexport const primitiveSchema = v.union(\n v.string(),\n v.number(),\n v.boolean(),\n v.null(),\n);\n\nexport const equalityOpsSchema = v.literalUnion('=', '!=', 'IS', 'IS NOT');\n\nexport const orderOpsSchema = v.literalUnion('<', '>', '<=', '>=');\n\nexport const likeOpsSchema = v.literalUnion(\n 'LIKE',\n 'NOT LIKE',\n 'ILIKE',\n 'NOT ILIKE',\n);\n\nexport const inOpsSchema = v.literalUnion('IN', 'NOT IN');\n\nexport const simpleOperatorSchema = v.union(\n equalityOpsSchema,\n orderOpsSchema,\n likeOpsSchema,\n inOpsSchema,\n);\n\nconst literalReferenceSchema: v.Type<LiteralReference> = v.readonlyObject({\n type: v.literal('literal'),\n value: v.union(\n v.string(),\n v.number(),\n v.boolean(),\n v.null(),\n v.readonlyArray(v.union(v.string(), v.number(), v.boolean())),\n ),\n});\nconst columnReferenceSchema: v.Type<ColumnReference> = v.readonlyObject({\n type: v.literal('column'),\n name: v.string(),\n});\n\n/**\n * A parameter is a value that is not known at the time the query is written\n * and is resolved at runtime.\n *\n * Static parameters refer to something provided by the caller.\n * Static parameters are injected when the query pipeline is built from the AST\n * and do not change for the life of that pipeline.\n *\n * An example static parameter is the current authentication data.\n * When a user is authenticated, queries on the server have access\n * to the user's authentication data in order to evaluate authorization rules.\n * Authentication data doesn't change over the life of a query as a change\n * in auth data would represent a log-in / log-out of the user.\n *\n * AncestorParameters refer to rows encountered while running the query.\n * They are used by subqueries to refer to rows emitted by parent queries.\n */\nconst parameterReferenceSchema = v.readonlyObject({\n type: v.literal('static'),\n // The \"namespace\" of the injected parameter.\n // Write authorization will send the value of a row\n // prior to the mutation being run (preMutationRow).\n // Read and write authorization will both send the\n // current authentication data (authData).\n anchor: v.literalUnion('authData', 'preMutationRow'),\n field: v.union(v.string(), v.array(v.string())),\n});\n\nconst conditionValueSchema = v.union(\n literalReferenceSchema,\n columnReferenceSchema,\n parameterReferenceSchema,\n);\n\nexport type Parameter = v.Infer<typeof parameterReferenceSchema>;\n\nexport const simpleConditionSchema: v.Type<SimpleCondition> = v.readonlyObject({\n type: v.literal('simple'),\n op: simpleOperatorSchema,\n left: conditionValueSchema,\n right: v.union(parameterReferenceSchema, literalReferenceSchema),\n});\n\ntype ConditionValue = v.Infer<typeof conditionValueSchema>;\n\nexport const correlatedSubqueryConditionOperatorSchema: v.Type<CorrelatedSubqueryConditionOperator> =\n v.literalUnion('EXISTS', 'NOT EXISTS');\n\nexport const correlatedSubqueryConditionSchema: v.Type<CorrelatedSubqueryCondition> =\n v.readonlyObject({\n type: v.literal('correlatedSubquery'),\n related: v.lazy(() => correlatedSubquerySchema),\n op: correlatedSubqueryConditionOperatorSchema,\n flip: v.boolean().optional(),\n scalar: v.boolean().optional(),\n });\n\nexport const conditionSchema: v.Type<Condition> = v.union(\n simpleConditionSchema,\n v.lazy(() => conjunctionSchema),\n v.lazy(() => disjunctionSchema),\n correlatedSubqueryConditionSchema,\n);\n\nconst conjunctionSchema: v.Type<Conjunction> = v.readonlyObject({\n type: v.literal('and'),\n conditions: v.readonlyArray(conditionSchema),\n});\n\nconst disjunctionSchema: v.Type<Disjunction> = v.readonlyObject({\n type: v.literal('or'),\n conditions: v.readonlyArray(conditionSchema),\n});\n\nexport type CompoundKey = readonly [string, ...string[]];\n\nfunction mustCompoundKey(field: readonly string[]): CompoundKey {\n assert(\n Array.isArray(field) && field.length >= 1,\n 'Expected non-empty array for compound key',\n );\n return field as unknown as CompoundKey;\n}\n\nexport const compoundKeySchema: v.Type<CompoundKey> = v.readonly(\n v.tuple([v.string()]).concat(v.array(v.string())),\n);\n\nconst correlationSchema = v.readonlyObject({\n parentField: compoundKeySchema,\n childField: compoundKeySchema,\n});\n\n// Split out so that its inferred type can be checked against\n// Omit<CorrelatedSubquery, 'correlation'> in ast-type-test.ts.\n// The mutually-recursive reference of the 'other' field to astSchema\n// is the only thing added in v.lazy. The v.lazy is necessary due to the\n// mutually-recursive types, but v.lazy prevents inference of the resulting\n// type.\nexport const correlatedSubquerySchemaOmitSubquery = v.readonlyObject({\n correlation: correlationSchema,\n hidden: v.boolean().optional(),\n system: v.literalUnion('permissions', 'client', 'test').optional(),\n});\n\nexport const correlatedSubquerySchema: v.Type<CorrelatedSubquery> =\n correlatedSubquerySchemaOmitSubquery.extend({\n subquery: v.lazy(() => astSchema),\n });\n\nexport const astSchema: v.Type<AST> = v.readonlyObject({\n schema: v.string().optional(),\n table: v.string(),\n alias: v.string().optional(),\n where: conditionSchema.optional(),\n related: v.readonlyArray(correlatedSubquerySchema).optional(),\n limit: v.number().optional(),\n orderBy: orderingSchema.optional(),\n start: v\n .object({\n row: rowSchema,\n exclusive: v.boolean(),\n })\n .optional(),\n});\n\nexport type Bound = {\n row: Row;\n exclusive: boolean;\n};\n\n/**\n * As in SQL you can have multiple orderings. We don't currently\n * support ordering on anything other than the root query.\n */\nexport type OrderPart = readonly [field: string, direction: 'asc' | 'desc'];\nexport type Ordering = readonly OrderPart[];\n\nexport type SimpleOperator = EqualityOps | OrderOps | LikeOps | InOps;\nexport type EqualityOps = '=' | '!=' | 'IS' | 'IS NOT';\nexport type OrderOps = '<' | '>' | '<=' | '>=';\nexport type LikeOps = 'LIKE' | 'NOT LIKE' | 'ILIKE' | 'NOT ILIKE';\nexport type InOps = 'IN' | 'NOT IN';\n\nexport type AST = {\n readonly schema?: string | undefined;\n readonly table: string;\n\n // A query would be aliased if the AST is a subquery.\n // e.g., when two subqueries select from the same table\n // they need an alias to differentiate them.\n // `SELECT\n // [SELECT * FROM issue WHERE issue.id = outer.parentId] AS parent\n // [SELECT * FROM issue WHERE issue.parentId = outer.id] AS children\n // FROM issue as outer`\n readonly alias?: string | undefined;\n\n // `select` is missing given we return all columns for now.\n\n // The PipelineBuilder will pick what to use to correlate\n // a subquery with a parent query. It can choose something from the\n // where conditions or choose the _first_ `related` entry.\n // Choosing the first `related` entry is almost always the best choice if\n // one exists.\n readonly where?: Condition | undefined;\n\n readonly related?: readonly CorrelatedSubquery[] | undefined;\n readonly start?: Bound | undefined;\n readonly limit?: number | undefined;\n readonly orderBy?: Ordering | undefined;\n};\n\nexport type Correlation = {\n readonly parentField: CompoundKey;\n readonly childField: CompoundKey;\n};\n\nexport type CorrelatedSubquery = {\n /**\n * Only equality correlation are supported for now.\n * E.g., direct foreign key relationships.\n */\n readonly correlation: Correlation;\n readonly subquery: AST;\n readonly system?: System | undefined;\n // If a hop in the subquery chain should be hidden from the output view.\n // A common example is junction edges. The query API provides the illusion\n // that they don't exist: `issue.related('labels')` instead of `issue.related('issue_labels').related('labels')`.\n // To maintain this illusion, the junction edge should be hidden.\n // When `hidden` is set to true, this hop will not be included in the output view\n // but its children will be.\n readonly hidden?: boolean | undefined;\n};\n\nexport type ValuePosition = LiteralReference | Parameter | ColumnReference;\n\nexport type ColumnReference = {\n readonly type: 'column';\n /**\n * Not a path yet as we're currently not allowing\n * comparisons across tables. This will need to\n * be a path through the tree in the near future.\n */\n readonly name: string;\n};\n\nexport type LiteralReference = {\n readonly type: 'literal';\n readonly value: LiteralValue;\n};\n\nexport type LiteralValue =\n | string\n | number\n | boolean\n | null\n | ReadonlyArray<string | number | boolean>;\n\n/**\n * Starting only with SimpleCondition for now.\n * ivm1 supports Conjunctions and Disjunctions.\n * We'll support them in the future.\n */\nexport type Condition =\n | SimpleCondition\n | Conjunction\n | Disjunction\n | CorrelatedSubqueryCondition;\n\nexport type SimpleCondition = {\n readonly type: 'simple';\n readonly op: SimpleOperator;\n readonly left: ValuePosition;\n\n /**\n * `null` is absent since we do not have an `IS` or `IS NOT`\n * operator defined and `null != null` in SQL.\n */\n readonly right: Exclude<ValuePosition, ColumnReference>;\n};\n\nexport type Conjunction = {\n type: 'and';\n conditions: readonly Condition[];\n};\n\nexport type Disjunction = {\n type: 'or';\n conditions: readonly Condition[];\n};\n\nexport type CorrelatedSubqueryCondition = {\n type: 'correlatedSubquery';\n related: CorrelatedSubquery;\n op: CorrelatedSubqueryConditionOperator;\n flip?: boolean | undefined;\n scalar?: boolean | undefined;\n [planIdSymbol]?: number | undefined;\n};\n\nexport type CorrelatedSubqueryConditionOperator = 'EXISTS' | 'NOT EXISTS';\n\ninterface ASTTransform {\n tableName(orig: string): string;\n columnName(origTable: string, origColumn: string): string;\n related(subqueries: CorrelatedSubquery[]): readonly CorrelatedSubquery[];\n where(cond: Condition): Condition | undefined;\n // conjunction or disjunction, called when traversing the return value of where()\n conditions(conds: Condition[]): readonly Condition[];\n}\n\nfunction transformAST(ast: AST, transform: ASTTransform): Required<AST> {\n // Name mapping functions (e.g. to server names)\n const {tableName, columnName} = transform;\n const colName = (c: string) => columnName(ast.table, c);\n const key = (table: string, k: CompoundKey) => {\n const serverKey = k.map(col => columnName(table, col));\n return mustCompoundKey(serverKey);\n };\n\n const where = ast.where ? transform.where(ast.where) : undefined;\n const transformed = {\n schema: ast.schema,\n table: tableName(ast.table),\n alias: ast.alias,\n where: where ? transformWhere(where, ast.table, transform) : undefined,\n related: ast.related\n ? transform.related(\n ast.related.map(\n r =>\n ({\n correlation: {\n parentField: key(ast.table, r.correlation.parentField),\n childField: key(r.subquery.table, r.correlation.childField),\n },\n hidden: r.hidden,\n subquery: transformAST(r.subquery, transform),\n system: r.system,\n }) satisfies Required<CorrelatedSubquery>,\n ),\n )\n : undefined,\n start: ast.start\n ? {\n ...ast.start,\n row: Object.fromEntries(\n Object.entries(ast.start.row).map(([col, val]) => [\n colName(col),\n val,\n ]),\n ),\n }\n : undefined,\n limit: ast.limit,\n orderBy: ast.orderBy?.map(([col, dir]) => [colName(col), dir] as const),\n };\n\n return transformed;\n}\n\nfunction transformWhere(\n where: Condition,\n table: string,\n transform: ASTTransform,\n): Condition {\n // Name mapping functions (e.g. to server names)\n const {columnName} = transform;\n const condValue = (c: ConditionValue) =>\n c.type !== 'column' ? c : {...c, name: columnName(table, c.name)};\n const key = (table: string, k: CompoundKey) => {\n const serverKey = k.map(col => columnName(table, col));\n return mustCompoundKey(serverKey);\n };\n\n if (where.type === 'simple') {\n return {...where, left: condValue(where.left)};\n } else if (where.type === 'correlatedSubquery') {\n const {correlation, subquery} = where.related;\n return {\n ...where,\n related: {\n ...where.related,\n correlation: {\n parentField: key(table, correlation.parentField),\n childField: key(subquery.table, correlation.childField),\n },\n subquery: transformAST(subquery, transform),\n },\n };\n }\n\n return {\n type: where.type,\n conditions: transform.conditions(\n where.conditions.map(c => transformWhere(c, table, transform)),\n ),\n };\n}\n\nconst normalizeCache = new WeakMap<AST, Required<AST>>();\n\nconst NORMALIZE_TRANSFORM: ASTTransform = {\n tableName: t => t,\n columnName: (_, c) => c,\n related: sortedRelated,\n where: flattened,\n conditions: c => c.sort(cmpCondition),\n};\n\nexport function normalizeAST(ast: AST): Required<AST> {\n let normalized = normalizeCache.get(ast);\n if (!normalized) {\n normalized = transformAST(ast, NORMALIZE_TRANSFORM);\n normalizeCache.set(ast, normalized);\n }\n return normalized;\n}\n\nexport function mapAST(ast: AST, mapper: NameMapper) {\n return transformAST(ast, {\n tableName: table => mapper.tableName(table),\n columnName: (table, col) => mapper.columnName(table, col),\n related: r => r,\n where: w => w,\n conditions: c => c,\n });\n}\n\nexport function mapCondition(\n cond: Condition,\n table: string,\n mapper: NameMapper,\n) {\n return transformWhere(cond, table, {\n tableName: table => mapper.tableName(table),\n columnName: (table, col) => mapper.columnName(table, col),\n related: r => r,\n where: w => w,\n conditions: c => c,\n });\n}\n\nfunction sortedRelated(\n related: CorrelatedSubquery[],\n): readonly CorrelatedSubquery[] {\n return related.sort(cmpRelated);\n}\n\nfunction cmpCondition(a: Condition, b: Condition): number {\n if (a.type === 'simple') {\n if (b.type !== 'simple') {\n return -1; // Order SimpleConditions first\n }\n\n return (\n compareValuePosition(a.left, b.left) ||\n compareUTF8MaybeNull(a.op, b.op) ||\n compareValuePosition(a.right, b.right)\n );\n }\n\n if (b.type === 'simple') {\n return 1; // Order SimpleConditions first\n }\n\n if (a.type === 'correlatedSubquery') {\n if (b.type !== 'correlatedSubquery') {\n return -1; // Order subquery before conjuctions/disjuctions\n }\n return (\n cmpRelated(a.related, b.related) ||\n compareUTF8MaybeNull(a.op, b.op) ||\n cmpOptionalBool(a.flip, b.flip) ||\n cmpOptionalBool(a.scalar, b.scalar)\n );\n }\n if (b.type === 'correlatedSubquery') {\n return -1; // Order correlatedSubquery before conjuctions/disjuctions\n }\n\n const val = compareUTF8MaybeNull(a.type, b.type);\n if (val !== 0) {\n return val;\n }\n for (\n let l = 0, r = 0;\n l < a.conditions.length && r < b.conditions.length;\n l++, r++\n ) {\n const val = cmpCondition(a.conditions[l], b.conditions[r]);\n if (val !== 0) {\n return val;\n }\n }\n // prefixes first\n return a.conditions.length - b.conditions.length;\n}\n\nfunction compareValuePosition(a: ValuePosition, b: ValuePosition): number {\n if (a.type !== b.type) {\n return compareUTF8(a.type, b.type);\n }\n switch (a.type) {\n case 'literal':\n assert(b.type === 'literal', 'Expected literal type for comparison');\n return compareUTF8(String(a.value), String(b.value));\n case 'column':\n assert(b.type === 'column', 'Expected column type for comparison');\n return compareUTF8(a.name, b.name);\n case 'static':\n throw new Error(\n 'Static parameters should be resolved before normalization',\n );\n }\n}\n\nfunction cmpRelated(a: CorrelatedSubquery, b: CorrelatedSubquery): number {\n return compareUTF8(must(a.subquery.alias), must(b.subquery.alias));\n}\n\n/**\n * Returns a flattened version of the Conditions in which nested Conjunctions with\n * the same operation ('AND' or 'OR') are flattened to the same level. e.g.\n *\n * ```\n * ((a AND b) AND (c AND (d OR (e OR f)))) -> (a AND b AND c AND (d OR e OR f))\n * ```\n *\n * Also flattens singleton Conjunctions regardless of operator, and removes\n * empty Conjunctions.\n */\nfunction flattened(cond: Condition): Condition | undefined {\n if (cond.type === 'simple' || cond.type === 'correlatedSubquery') {\n return cond;\n }\n const conditions = defined(\n cond.conditions.flatMap(c =>\n c.type === cond.type ? c.conditions.map(c => flattened(c)) : flattened(c),\n ),\n );\n\n switch (conditions.length) {\n case 0:\n return undefined;\n case 1:\n return conditions[0];\n default:\n return {\n type: cond.type,\n conditions,\n };\n }\n}\n\nfunction compareUTF8MaybeNull(a: string | null, b: string | null): number {\n if (a !== null && b !== null) {\n return compareUTF8(a, b);\n }\n if (b !== null) {\n return -1;\n }\n if (a !== null) {\n return 1;\n }\n return 0;\n}\n\nfunction cmpOptionalBool(\n a: boolean | undefined,\n b: boolean | undefined,\n): number {\n // undefined < false < true\n const toNum = (v: boolean | undefined) => (v === undefined ? 0 : v ? 2 : 1);\n return toNum(a) - toNum(b);\n}\n"],"names":["v.string","v.readonly","v.tuple","v.literalUnion","v.readonlyArray","v.union","v.number","v.boolean","v.null","v.readonlyObject","v.literal","v.array","v.lazy","v.object","table","val","c","v"],"mappings":";;;;;;;AAgBO,MAAM,cAAc;AAEpB,MAAM,iBAAiBA,OAAE;AACzB,MAAM,gBAAgB,OAAA;AACtB,MAAM,eAAe,OAAO,QAAQ;AAE3C,MAAM,wBAAwBC;AAAAA,EAC5BC,MAAQ,CAAC,gBAAgBC,aAAe,OAAO,MAAM,CAAC,CAAC;AACzD;AAEO,MAAM,iBAAiBC,cAAgB,qBAAqB;AAGpCC;AAAAA,EAC7BL,OAAE;AAAA,EACFM,OAAE;AAAA,EACFC,QAAE;AAAA,EACFC,MAAE;AACJ;AAEO,MAAM,oBAAoBL,aAAe,KAAK,MAAM,MAAM,QAAQ;AAElE,MAAM,iBAAiBA,aAAe,KAAK,KAAK,MAAM,IAAI;AAE1D,MAAM,gBAAgBA;AAAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,MAAM,cAAcA,aAAe,MAAM,QAAQ;AAEjD,MAAM,uBAAuBE;AAAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,yBAAmDI,eAAiB;AAAA,EACxE,MAAMC,QAAU,SAAS;AAAA,EACzB,OAAOL;AAAAA,IACLL,OAAE;AAAA,IACFM,OAAE;AAAA,IACFC,QAAE;AAAA,IACFC,MAAE;AAAA,IACFJ,cAAgBC,MAAQL,OAAE,GAAUM,OAAE,GAAUC,QAAE,CAAS,CAAC;AAAA,EAAA;AAEhE,CAAC;AACD,MAAM,wBAAiDE,eAAiB;AAAA,EACtE,MAAMC,QAAU,QAAQ;AAAA,EACxB,MAAMV,OAAE;AACV,CAAC;AAmBD,MAAM,2BAA2BS,eAAiB;AAAA,EAChD,MAAMC,QAAU,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,QAAQP,aAAe,YAAY,gBAAgB;AAAA,EACnD,OAAOE,MAAQL,OAAE,GAA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,IACrD,KAAK;AACH,aAAO,EAAE,SAAS,UAAU,qCAAqC;AACjE,aAAO,YAAY,EAAE,MAAM,EAAE,IAAI;AAAA,IACnC,KAAK;AACH,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,EACF;AAEN;AAEA,SAAS,WAAW,GAAuB,GAA+B;AACxE,SAAO,YAAY,KAAK,EAAE,SAAS,KAAK,GAAG,KAAK,EAAE,SAAS,KAAK,CAAC;AACnE;AAaA,SAAS,UAAU,MAAwC;AACzD,MAAI,KAAK,SAAS,YAAY,KAAK,SAAS,sBAAsB;AAChE,WAAO;AAAA,EACT;AACA,QAAM,aAAa;AAAA,IACjB,KAAK,WAAW;AAAA,MAAQ,CAAA,MACtB,EAAE,SAAS,KAAK,OAAO,EAAE,WAAW,IAAI,CAAAC,OAAK,UAAUA,EAAC,CAAC,IAAI,UAAU,CAAC;AAAA,IAAA;AAAA,EAC1E;AAGF,UAAQ,WAAW,QAAA;AAAA,IACjB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO,WAAW,CAAC;AAAA,IACrB;AACE,aAAO;AAAA,QACL,MAAM,KAAK;AAAA,QACX;AAAA,MAAA;AAAA,EACF;AAEN;AAEA,SAAS,qBAAqB,GAAkB,GAA0B;AACxE,MAAI,MAAM,QAAQ,MAAM,MAAM;AAC5B,WAAO,YAAY,GAAG,CAAC;AAAA,EACzB;AACA,MAAI,MAAM,MAAM;AACd,WAAO;AAAA,EACT;AACA,MAAI,MAAM,MAAM;AACd,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,gBACP,GACA,GACQ;AAER,QAAM,QAAQ,CAACC,OAA4BA,OAAM,SAAY,IAAIA,KAAI,IAAI;AACzE,SAAO,MAAM,CAAC,IAAI,MAAM,CAAC;AAC3B;"}
@@ -10,7 +10,7 @@
10
10
  * release. The server (`zero-cache`) must be deployed before clients start
11
11
  * running the new code.
12
12
  */
13
- export declare const PROTOCOL_VERSION = 48;
13
+ export declare const PROTOCOL_VERSION = 49;
14
14
  /**
15
15
  * The minimum server-supported sync protocol version (i.e. the version
16
16
  * declared in the "/sync/v{#}/connect" URL). The contract for
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-version.d.ts","sourceRoot":"","sources":["../../../../zero-protocol/src/protocol-version.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AA2CH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,kCAAkC,KAAK,CAAC"}
1
+ {"version":3,"file":"protocol-version.d.ts","sourceRoot":"","sources":["../../../../zero-protocol/src/protocol-version.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AA4CH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;;;;;;;;GASG;AACH,eAAO,MAAM,kCAAkC,KAAK,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import { assert } from "../../shared/src/asserts.js";
2
- const PROTOCOL_VERSION = 48;
2
+ const PROTOCOL_VERSION = 49;
3
3
  const MIN_SERVER_SUPPORTED_SYNC_PROTOCOL = 30;
4
- assert(MIN_SERVER_SUPPORTED_SYNC_PROTOCOL < PROTOCOL_VERSION);
4
+ assert(
5
+ MIN_SERVER_SUPPORTED_SYNC_PROTOCOL < PROTOCOL_VERSION,
6
+ "MIN_SERVER_SUPPORTED_SYNC_PROTOCOL must be less than PROTOCOL_VERSION"
7
+ );
5
8
  export {
6
9
  MIN_SERVER_SUPPORTED_SYNC_PROTOCOL,
7
10
  PROTOCOL_VERSION
@@ -1 +1 @@
1
- {"version":3,"file":"protocol-version.js","sources":["../../../../zero-protocol/src/protocol-version.ts"],"sourcesContent":["import {assert} from '../../shared/src/asserts.ts';\n\n/**\n * The current `PROTOCOL_VERSION` of the code.\n *\n * The `PROTOCOL_VERSION` encompasses both the wire-protocol of the `/sync/...`\n * connection between the browser and `zero-cache`, as well as the format of\n * the `AST` objects stored in both components (i.e. IDB and CVR).\n *\n * A change in the `AST` schema (e.g. new functionality added) must be\n * accompanied by an increment of the `PROTOCOL_VERSION` and a new major\n * release. The server (`zero-cache`) must be deployed before clients start\n * running the new code.\n */\n// History:\n// -- Version 5 adds support for `pokeEnd.cookie`. (0.14)\n// -- Version 6 makes `pokeStart.cookie` optional. (0.16)\n// -- Version 7 introduces the initConnection.clientSchema field. (0.17)\n// -- Version 8 drops support for Version 5 (0.18).\n// -- Version 11 adds inspect queries. (0.18)\n// -- Version 12 adds 'timestamp' and 'date' types to the ClientSchema ValueType. (not shipped, reversed by version 14)\n// -- Version 14 removes 'timestamp' and 'date' types from the ClientSchema ValueType. (0.18)\n// -- Version 15 adds a `userPushParams` field to `initConnection` (0.19)\n// -- Version 16 adds a new error type (alreadyProcessed) to mutation responses (0.19)\n// -- Version 17 deprecates `AST` in downstream query puts. It was never used anyway. (0.21)\n// -- Version 18 adds `name` and `args` to the `queries-patch` protocol (0.21)\n// -- Version 19 adds `activeClients` to the `initConnection` protocol (0.22)\n// -- Version 20 changes inspector down message (0.22)\n// -- Version 21 removes `AST` in downstream query puts which was deprecated in Version 17, removes support for versions < 18 (0.22)\n// -- Version 22 adds an optional 'userQueryParams' field to `initConnection` (0.22)\n// -- Version 23 add `mutationResults` to poke (0.22)\n// -- Version 24 adds `ackMutationResults` to upstream (0.22).\n// -- version 25 modifies `mutationsResults` to include `del` patches (0.22)\n// -- version 26 adds inspect/metrics and adds metrics to inspect/query (0.23)\n// -- version 27 adds inspect/version (0.23)\n// -- version 28 adds more inspect/metrics (0.23)\n// -- version 29 adds error responses for custom queries (0.23)\n// -- version 30 adds an optional primaryKey to the ClientSchema (0.24)\n// -- version 31 adds admin password authentication to inspector RPC calls (0.24)\n// -- version 32 adds analyze-query to the inspector RPC calls (0.24)\n// -- version 33 adds `flip` to CorrelatedSubquery (0.25)\n// -- version 34 moves `flip` from CorrelatedSubquery to CorrelatedSubqueryCondition (0.25)\n// -- version 35 adds `readRows`, `readRowCountsByQuery` and `readRowCount` to analyze-query result (0.25)\n// -- version 36 changes inspector analyze-query and adds error response to RPC (0.25)\n// -- version 37 adds `elapsed` to AnalyzeQueryResult (0.25)\n// -- version 38 adds structured push/transform error responses (0.25)\n// -- version 39 removes per-transform error types and adds `message` to app error (0.25)\n// -- version 40 adds `dbRowScansByQuery` to AnalyzeQueryResult (0.25)\n// -- version 41 makes ClientSchema.primaryKey required (0.25)\n// -- version 42 adds planner events to AnalyzeQueryResult (0.25)\n// -- version 43 renames `plans` to `sqlitePlans`, `plannerEvents` to `joinPlans`, and `plannerDebug` option to `joinPlans` (0.25)\n// -- version 44 adds profileID to connection URL (0.25)\n// -- version 45 adds userPushHeaders and userQueryHeaders to initConnection (0.25)\n// -- version 46 adds scalarSubquery condition type to AST\n// -- version 47 adds optional auth token to push body\n// -- version 48 adds updateAuth\nexport const PROTOCOL_VERSION = 48;\n\n/**\n * The minimum server-supported sync protocol version (i.e. the version\n * declared in the \"/sync/v{#}/connect\" URL). The contract for\n * backwards compatibility is that a `zero-cache` supports the current\n * `PROTOCOL_VERSION` and at least the previous one (i.e. `PROTOCOL_VERSION - 1`)\n * if not earlier ones as well. This corresponds to supporting clients running\n * the current release and the previous (major) release. Any client connections\n * from protocol versions before `MIN_SERVER_SUPPORTED_PROTOCOL_VERSION` are\n * closed with a `VersionNotSupported` error.\n */\nexport const MIN_SERVER_SUPPORTED_SYNC_PROTOCOL = 30;\n\nassert(MIN_SERVER_SUPPORTED_SYNC_PROTOCOL < PROTOCOL_VERSION);\n"],"names":[],"mappings":";AAwDO,MAAM,mBAAmB;AAYzB,MAAM,qCAAqC;AAElD,OAAO,qCAAqC,gBAAgB;"}
1
+ {"version":3,"file":"protocol-version.js","sources":["../../../../zero-protocol/src/protocol-version.ts"],"sourcesContent":["import {assert} from '../../shared/src/asserts.ts';\n\n/**\n * The current `PROTOCOL_VERSION` of the code.\n *\n * The `PROTOCOL_VERSION` encompasses both the wire-protocol of the `/sync/...`\n * connection between the browser and `zero-cache`, as well as the format of\n * the `AST` objects stored in both components (i.e. IDB and CVR).\n *\n * A change in the `AST` schema (e.g. new functionality added) must be\n * accompanied by an increment of the `PROTOCOL_VERSION` and a new major\n * release. The server (`zero-cache`) must be deployed before clients start\n * running the new code.\n */\n// History:\n// -- Version 5 adds support for `pokeEnd.cookie`. (0.14)\n// -- Version 6 makes `pokeStart.cookie` optional. (0.16)\n// -- Version 7 introduces the initConnection.clientSchema field. (0.17)\n// -- Version 8 drops support for Version 5 (0.18).\n// -- Version 11 adds inspect queries. (0.18)\n// -- Version 12 adds 'timestamp' and 'date' types to the ClientSchema ValueType. (not shipped, reversed by version 14)\n// -- Version 14 removes 'timestamp' and 'date' types from the ClientSchema ValueType. (0.18)\n// -- Version 15 adds a `userPushParams` field to `initConnection` (0.19)\n// -- Version 16 adds a new error type (alreadyProcessed) to mutation responses (0.19)\n// -- Version 17 deprecates `AST` in downstream query puts. It was never used anyway. (0.21)\n// -- Version 18 adds `name` and `args` to the `queries-patch` protocol (0.21)\n// -- Version 19 adds `activeClients` to the `initConnection` protocol (0.22)\n// -- Version 20 changes inspector down message (0.22)\n// -- Version 21 removes `AST` in downstream query puts which was deprecated in Version 17, removes support for versions < 18 (0.22)\n// -- Version 22 adds an optional 'userQueryParams' field to `initConnection` (0.22)\n// -- Version 23 add `mutationResults` to poke (0.22)\n// -- Version 24 adds `ackMutationResults` to upstream (0.22).\n// -- version 25 modifies `mutationsResults` to include `del` patches (0.22)\n// -- version 26 adds inspect/metrics and adds metrics to inspect/query (0.23)\n// -- version 27 adds inspect/version (0.23)\n// -- version 28 adds more inspect/metrics (0.23)\n// -- version 29 adds error responses for custom queries (0.23)\n// -- version 30 adds an optional primaryKey to the ClientSchema (0.24)\n// -- version 31 adds admin password authentication to inspector RPC calls (0.24)\n// -- version 32 adds analyze-query to the inspector RPC calls (0.24)\n// -- version 33 adds `flip` to CorrelatedSubquery (0.25)\n// -- version 34 moves `flip` from CorrelatedSubquery to CorrelatedSubqueryCondition (0.25)\n// -- version 35 adds `readRows`, `readRowCountsByQuery` and `readRowCount` to analyze-query result (0.25)\n// -- version 36 changes inspector analyze-query and adds error response to RPC (0.25)\n// -- version 37 adds `elapsed` to AnalyzeQueryResult (0.25)\n// -- version 38 adds structured push/transform error responses (0.25)\n// -- version 39 removes per-transform error types and adds `message` to app error (0.25)\n// -- version 40 adds `dbRowScansByQuery` to AnalyzeQueryResult (0.25)\n// -- version 41 makes ClientSchema.primaryKey required (0.25)\n// -- version 42 adds planner events to AnalyzeQueryResult (0.25)\n// -- version 43 renames `plans` to `sqlitePlans`, `plannerEvents` to `joinPlans`, and `plannerDebug` option to `joinPlans` (0.25)\n// -- version 44 adds profileID to connection URL (0.25)\n// -- version 45 adds userPushHeaders and userQueryHeaders to initConnection (0.25)\n// -- version 46 adds scalarSubquery condition type to AST\n// -- version 47 adds optional auth token to push body\n// -- version 48 adds updateAuth\n// -- version 49 adds `scalar` to CorrelatedSubqueryCondition, removes scalarSubquery\nexport const PROTOCOL_VERSION = 49;\n\n/**\n * The minimum server-supported sync protocol version (i.e. the version\n * declared in the \"/sync/v{#}/connect\" URL). The contract for\n * backwards compatibility is that a `zero-cache` supports the current\n * `PROTOCOL_VERSION` and at least the previous one (i.e. `PROTOCOL_VERSION - 1`)\n * if not earlier ones as well. This corresponds to supporting clients running\n * the current release and the previous (major) release. Any client connections\n * from protocol versions before `MIN_SERVER_SUPPORTED_PROTOCOL_VERSION` are\n * closed with a `VersionNotSupported` error.\n */\nexport const MIN_SERVER_SUPPORTED_SYNC_PROTOCOL = 30;\n\nassert(\n MIN_SERVER_SUPPORTED_SYNC_PROTOCOL < PROTOCOL_VERSION,\n 'MIN_SERVER_SUPPORTED_SYNC_PROTOCOL must be less than PROTOCOL_VERSION',\n);\n"],"names":[],"mappings":";AAyDO,MAAM,mBAAmB;AAYzB,MAAM,qCAAqC;AAElD;AAAA,EACE,qCAAqC;AAAA,EACrC;AACF;"}
@@ -1,7 +1,5 @@
1
1
  export { useConnectionState } from './use-connection-state.tsx';
2
2
  export { useQuery, useSuspenseQuery, type MaybeQueryResult, type QueryResult, type UseQueryOptions, } from './use-query.tsx';
3
- export type { GetPageQuery, GetQueryReturnType, GetSingleQuery, } from './use-rows.ts';
4
3
  export { useZeroOnline } from './use-zero-online.tsx';
5
- export { useZeroVirtualizer, type PermalinkHistoryState, type UseZeroVirtualizerOptions, type ZeroVirtualizerResult, } from './use-zero-virtualizer.ts';
6
4
  export { createUseZero, useZero, ZeroContext, ZeroProvider, type ZeroProviderProps, } from './zero-provider.tsx';
7
5
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../zero-react/src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,GAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,EACb,OAAO,EACP,WAAW,EACX,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../../zero-react/src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EACL,QAAQ,EACR,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,eAAe,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,aAAa,EACb,OAAO,EACP,WAAW,EACX,YAAY,EACZ,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { CustomMutatorDefs, DefaultContext, DefaultSchema, Falsy, HumanReadable, PullRow, Query, QueryOrQueryRequest, QueryResultDetails, ReadonlyJSONValue, Schema, TTL, Zero } from './zero.ts';
1
+ import type { BaseDefaultContext, BaseDefaultSchema, CustomMutatorDefs, DefaultContext, DefaultSchema, Falsy, HumanReadable, PullRow, Query, QueryOrQueryRequest, QueryResultDetails, ReadonlyJSONValue, TTL, Zero } from './zero.ts';
2
2
  export type QueryResult<TReturn> = readonly [
3
3
  HumanReadable<TReturn>,
4
4
  QueryResultDetails & {}
@@ -35,10 +35,10 @@ export type UseSuspenseQueryOptions = UseQueryOptions & {
35
35
  */
36
36
  suspendUntil?: 'complete' | 'partial';
37
37
  };
38
- export declare function useQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext>, options?: UseQueryOptions | boolean): QueryResult<TReturn>;
39
- export declare function useQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext> | Falsy, options?: UseQueryOptions | boolean): MaybeQueryResult<TReturn>;
40
- export declare function useSuspenseQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext>, options?: UseSuspenseQueryOptions | boolean): QueryResult<TReturn>;
41
- export declare function useSuspenseQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends Schema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext> | Falsy, options?: UseSuspenseQueryOptions | boolean): MaybeQueryResult<TReturn>;
38
+ export declare function useQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends BaseDefaultSchema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext extends BaseDefaultContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext>, options?: UseQueryOptions | boolean): QueryResult<TReturn>;
39
+ export declare function useQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends BaseDefaultSchema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext extends BaseDefaultContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext> | Falsy, options?: UseQueryOptions | boolean): MaybeQueryResult<TReturn>;
40
+ export declare function useSuspenseQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends BaseDefaultSchema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext extends BaseDefaultContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext>, options?: UseSuspenseQueryOptions | boolean): QueryResult<TReturn>;
41
+ export declare function useSuspenseQuery<TTable extends keyof TSchema['tables'] & string, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TSchema extends BaseDefaultSchema = DefaultSchema, TReturn = PullRow<TTable, TSchema>, TContext extends BaseDefaultContext = DefaultContext>(query: QueryOrQueryRequest<TTable, TInput, TOutput, TSchema, TReturn, TContext> | Falsy, options?: UseSuspenseQueryOptions | boolean): MaybeQueryResult<TReturn>;
42
42
  export declare function getAllViewsSizeForTesting(store: ViewStore): number;
43
43
  /**
44
44
  * A global store of all active views.
@@ -91,7 +91,7 @@ export declare function getAllViewsSizeForTesting(store: ViewStore): number;
91
91
  export declare class ViewStore {
92
92
  #private;
93
93
  constructor();
94
- getView<TTable extends keyof TSchema['tables'] & string, TSchema extends Schema, TReturn, MD extends CustomMutatorDefs | undefined, TContext>(zero: Zero<TSchema, MD, TContext>, q: Query<TTable, TSchema, TReturn>, enabled: boolean, ttl: TTL): {
94
+ getView<TTable extends keyof TSchema['tables'] & string, TSchema extends BaseDefaultSchema, TReturn, MD extends CustomMutatorDefs | undefined, TContext extends BaseDefaultContext>(zero: Zero<TSchema, MD, TContext>, q: Query<TTable, TSchema, TReturn>, enabled: boolean, ttl: TTL): {
95
95
  getSnapshot: () => QueryResult<TReturn>;
96
96
  subscribeReactInternals: (internals: () => void) => () => void;
97
97
  updateTTL: (ttl: TTL) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../../../zero-react/src/use-query.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAEV,iBAAiB,EACjB,cAAc,EACd,aAAa,EAEb,KAAK,EACL,aAAa,EACb,OAAO,EACP,KAAK,EAEL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EAEjB,MAAM,EACN,GAAG,EAEH,IAAI,EACL,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,WAAW,CAAC,OAAO,IAAI,SAAS;IAC1C,aAAa,CAAC,OAAO,CAAC;IACtB,kBAAkB,GAAG,EAAE;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,O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,MAAM,EAC/C,OAAO,SAAS,iBAAiB,EACjC,OAAO,EACP,EAAE,SAAS,iBAAiB,GAAG,SAAS,EACxC,QAAQ,SAAS,kBAAkB,EAEnC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,EACjC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAClC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,GAAG,GACP;QACD,WAAW,EAAE,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;QACxC,uBAAuB,EAAE,CAAC,SAAS,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;QAC/D,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;QAC9B,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;QACrC,QAAQ,EAAE,OAAO,CAAC;QAClB,QAAQ,EAAE,OAAO,CAAC;KACnB;CAgCF"}
@@ -1,5 +1,6 @@
1
1
  import { resolver } from "@rocicorp/resolver";
2
2
  import React, { useSyncExternalStore } from "react";
3
+ import { deepClone } from "../../shared/src/deep-clone.js";
3
4
  import "compare-utf8";
4
5
  import "../../zero-protocol/src/ast.js";
5
6
  import "js-xxhash";
@@ -189,6 +190,7 @@ class ViewWrapper {
189
190
  #nonEmptyResolver = resolver();
190
191
  #zero;
191
192
  #singular;
193
+ #destroyTimer;
192
194
  constructor(query, zero, ttl, onDematerialized) {
193
195
  this.#query = query;
194
196
  this.#zero = zero;
@@ -200,7 +202,7 @@ class ViewWrapper {
200
202
  this.#materializeIfNeeded();
201
203
  }
202
204
  #onData = (snap, resultType, error) => {
203
- const data = snap;
205
+ const data = snap === void 0 ? snap : deepClone(snap);
204
206
  this.#snapshot = getSnapshot(
205
207
  this.#singular,
206
208
  data,
@@ -243,11 +245,16 @@ class ViewWrapper {
243
245
  getSnapshot = () => this.#snapshot;
244
246
  subscribeReactInternals = (internals) => {
245
247
  this.#reactInternals.add(internals);
248
+ if (this.#destroyTimer !== void 0) {
249
+ clearTimeout(this.#destroyTimer);
250
+ this.#destroyTimer = void 0;
251
+ }
246
252
  this.#materializeIfNeeded();
247
253
  return () => {
248
254
  this.#reactInternals.delete(internals);
249
255
  if (this.#reactInternals.size === 0) {
250
- setTimeout(() => {
256
+ this.#destroyTimer = setTimeout(() => {
257
+ this.#destroyTimer = void 0;
251
258
  if (this.#view === void 0) {
252
259
  return;
253
260
  }