@rocicorp/zero 0.25.0-canary.8 → 0.25.0-canary.9

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 (272) hide show
  1. package/out/shared/src/deep-merge.d.ts +20 -3
  2. package/out/shared/src/deep-merge.d.ts.map +1 -1
  3. package/out/shared/src/deep-merge.js +27 -0
  4. package/out/shared/src/deep-merge.js.map +1 -0
  5. package/out/shared/src/logging.d.ts.map +1 -1
  6. package/out/shared/src/logging.js +25 -9
  7. package/out/shared/src/logging.js.map +1 -1
  8. package/out/shared/src/object-traversal.d.ts +19 -0
  9. package/out/shared/src/object-traversal.d.ts.map +1 -0
  10. package/out/shared/src/object-traversal.js +27 -0
  11. package/out/shared/src/object-traversal.js.map +1 -0
  12. package/out/zero/package.json.js +1 -1
  13. package/out/zero/src/pg.js +0 -2
  14. package/out/zero/src/pg.js.map +1 -1
  15. package/out/zero/src/server.js +0 -2
  16. package/out/zero/src/server.js.map +1 -1
  17. package/out/zero/src/zero.js +19 -3
  18. package/out/zero/src/zero.js.map +1 -1
  19. package/out/zero-cache/src/auth/jwt.d.ts +3 -0
  20. package/out/zero-cache/src/auth/jwt.d.ts.map +1 -1
  21. package/out/zero-cache/src/auth/jwt.js.map +1 -1
  22. package/out/zero-cache/src/auth/write-authorizer.d.ts +2 -1
  23. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  24. package/out/zero-cache/src/auth/write-authorizer.js +1 -11
  25. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  26. package/out/zero-cache/src/config/zero-config.d.ts +27 -0
  27. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  28. package/out/zero-cache/src/config/zero-config.js +35 -7
  29. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  30. package/out/zero-cache/src/custom/fetch.d.ts +5 -5
  31. package/out/zero-cache/src/custom/fetch.d.ts.map +1 -1
  32. package/out/zero-cache/src/custom/fetch.js +14 -11
  33. package/out/zero-cache/src/custom/fetch.js.map +1 -1
  34. package/out/zero-cache/src/custom-queries/transform-query.d.ts.map +1 -1
  35. package/out/zero-cache/src/custom-queries/transform-query.js +2 -4
  36. package/out/zero-cache/src/custom-queries/transform-query.js.map +1 -1
  37. package/out/zero-cache/src/db/specs.d.ts +1 -1
  38. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  39. package/out/zero-cache/src/server/change-streamer.js +9 -9
  40. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  41. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  42. package/out/zero-cache/src/server/syncer.js +20 -8
  43. package/out/zero-cache/src/server/syncer.js.map +1 -1
  44. package/out/zero-cache/src/services/analyze.d.ts +1 -1
  45. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  46. package/out/zero-cache/src/services/analyze.js +10 -1
  47. package/out/zero-cache/src/services/analyze.js.map +1 -1
  48. package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +5 -5
  49. package/out/zero-cache/src/services/change-source/pg/schema/published.d.ts +2 -2
  50. package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +1 -1
  51. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts +11 -2
  52. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  53. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +36 -0
  54. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  55. package/out/zero-cache/src/services/http-service.d.ts +5 -4
  56. package/out/zero-cache/src/services/http-service.d.ts.map +1 -1
  57. package/out/zero-cache/src/services/http-service.js +15 -10
  58. package/out/zero-cache/src/services/http-service.js.map +1 -1
  59. package/out/zero-cache/src/services/mutagen/mutagen.d.ts +2 -1
  60. package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
  61. package/out/zero-cache/src/services/mutagen/mutagen.js +3 -2
  62. package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
  63. package/out/zero-cache/src/services/mutagen/pusher.d.ts +198 -0
  64. package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
  65. package/out/zero-cache/src/services/mutagen/pusher.js +5 -5
  66. package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
  67. package/out/zero-cache/src/services/run-ast.d.ts +4 -0
  68. package/out/zero-cache/src/services/run-ast.d.ts.map +1 -1
  69. package/out/zero-cache/src/services/run-ast.js +8 -1
  70. package/out/zero-cache/src/services/run-ast.js.map +1 -1
  71. package/out/zero-cache/src/services/view-syncer/inspect-handler.d.ts.map +1 -1
  72. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +2 -1
  73. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  74. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  75. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +15 -8
  76. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  77. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +4 -4
  78. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  79. package/out/zero-cache/src/services/view-syncer/view-syncer.js +48 -25
  80. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  81. package/out/zero-cache/src/workers/connection.js +20 -15
  82. package/out/zero-cache/src/workers/connection.js.map +1 -1
  83. package/out/zero-cache/src/workers/syncer.d.ts.map +1 -1
  84. package/out/zero-cache/src/workers/syncer.js +3 -3
  85. package/out/zero-cache/src/workers/syncer.js.map +1 -1
  86. package/out/zero-client/src/client/bindings.d.ts +4 -4
  87. package/out/zero-client/src/client/bindings.d.ts.map +1 -1
  88. package/out/zero-client/src/client/bindings.js.map +1 -1
  89. package/out/zero-client/src/client/connection.d.ts +1 -1
  90. package/out/zero-client/src/client/connection.d.ts.map +1 -1
  91. package/out/zero-client/src/client/connection.js +1 -1
  92. package/out/zero-client/src/client/connection.js.map +1 -1
  93. package/out/zero-client/src/client/crud.d.ts +7 -5
  94. package/out/zero-client/src/client/crud.d.ts.map +1 -1
  95. package/out/zero-client/src/client/crud.js +7 -7
  96. package/out/zero-client/src/client/crud.js.map +1 -1
  97. package/out/zero-client/src/client/custom.d.ts +7 -5
  98. package/out/zero-client/src/client/custom.d.ts.map +1 -1
  99. package/out/zero-client/src/client/custom.js +12 -7
  100. package/out/zero-client/src/client/custom.js.map +1 -1
  101. package/out/zero-client/src/client/inspector/inspector.d.ts +5 -1
  102. package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
  103. package/out/zero-client/src/client/inspector/inspector.js +7 -0
  104. package/out/zero-client/src/client/inspector/inspector.js.map +1 -1
  105. package/out/zero-client/src/client/inspector/lazy-inspector.d.ts.map +1 -1
  106. package/out/zero-client/src/client/inspector/lazy-inspector.js +13 -13
  107. package/out/zero-client/src/client/inspector/lazy-inspector.js.map +1 -1
  108. package/out/zero-client/src/client/make-mutate-property.d.ts +43 -0
  109. package/out/zero-client/src/client/make-mutate-property.d.ts.map +1 -0
  110. package/out/zero-client/src/client/make-mutate-property.js +38 -0
  111. package/out/zero-client/src/client/make-mutate-property.js.map +1 -0
  112. package/out/zero-client/src/client/make-replicache-mutators.d.ts +34 -0
  113. package/out/zero-client/src/client/make-replicache-mutators.d.ts.map +1 -0
  114. package/out/zero-client/src/client/make-replicache-mutators.js +103 -0
  115. package/out/zero-client/src/client/make-replicache-mutators.js.map +1 -0
  116. package/out/zero-client/src/client/options.d.ts +39 -27
  117. package/out/zero-client/src/client/options.d.ts.map +1 -1
  118. package/out/zero-client/src/client/options.js.map +1 -1
  119. package/out/zero-client/src/client/version.js +1 -1
  120. package/out/zero-client/src/client/zero.d.ts +23 -33
  121. package/out/zero-client/src/client/zero.d.ts.map +1 -1
  122. package/out/zero-client/src/client/zero.js +52 -118
  123. package/out/zero-client/src/client/zero.js.map +1 -1
  124. package/out/zero-client/src/mod.d.ts +12 -7
  125. package/out/zero-client/src/mod.d.ts.map +1 -1
  126. package/out/zero-protocol/src/analyze-query-result.d.ts +236 -0
  127. package/out/zero-protocol/src/analyze-query-result.d.ts.map +1 -1
  128. package/out/zero-protocol/src/analyze-query-result.js +128 -2
  129. package/out/zero-protocol/src/analyze-query-result.js.map +1 -1
  130. package/out/zero-protocol/src/ast.d.ts +1 -1
  131. package/out/zero-protocol/src/connect.d.ts.map +1 -1
  132. package/out/zero-protocol/src/connect.js +4 -0
  133. package/out/zero-protocol/src/connect.js.map +1 -1
  134. package/out/zero-protocol/src/custom-queries.d.ts +1 -1
  135. package/out/zero-protocol/src/down.d.ts +99 -0
  136. package/out/zero-protocol/src/down.d.ts.map +1 -1
  137. package/out/zero-protocol/src/error.d.ts +4 -4
  138. package/out/zero-protocol/src/inspect-down.d.ts +297 -0
  139. package/out/zero-protocol/src/inspect-down.d.ts.map +1 -1
  140. package/out/zero-protocol/src/inspect-up.d.ts +4 -0
  141. package/out/zero-protocol/src/inspect-up.d.ts.map +1 -1
  142. package/out/zero-protocol/src/inspect-up.js +2 -1
  143. package/out/zero-protocol/src/inspect-up.js.map +1 -1
  144. package/out/zero-protocol/src/protocol-version.d.ts +1 -1
  145. package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
  146. package/out/zero-protocol/src/protocol-version.js +1 -1
  147. package/out/zero-protocol/src/protocol-version.js.map +1 -1
  148. package/out/zero-protocol/src/push.d.ts +1 -1
  149. package/out/zero-protocol/src/up.d.ts +1 -0
  150. package/out/zero-protocol/src/up.d.ts.map +1 -1
  151. package/out/zero-react/src/components/inspector.d.ts +3 -2
  152. package/out/zero-react/src/components/inspector.d.ts.map +1 -1
  153. package/out/zero-react/src/components/inspector.js.map +1 -1
  154. package/out/zero-react/src/components/zero-inspector.d.ts +3 -2
  155. package/out/zero-react/src/components/zero-inspector.d.ts.map +1 -1
  156. package/out/zero-react/src/components/zero-inspector.js.map +1 -1
  157. package/out/zero-react/src/use-query.d.ts +5 -4
  158. package/out/zero-react/src/use-query.d.ts.map +1 -1
  159. package/out/zero-react/src/use-query.js +4 -3
  160. package/out/zero-react/src/use-query.js.map +1 -1
  161. package/out/zero-react/src/zero-provider.d.ts +7 -7
  162. package/out/zero-react/src/zero-provider.d.ts.map +1 -1
  163. package/out/zero-react/src/zero-provider.js.map +1 -1
  164. package/out/zero-schema/src/builder/schema-builder.js +1 -1
  165. package/out/zero-schema/src/builder/schema-builder.js.map +1 -1
  166. package/out/zero-server/src/custom.d.ts +4 -5
  167. package/out/zero-server/src/custom.d.ts.map +1 -1
  168. package/out/zero-server/src/custom.js.map +1 -1
  169. package/out/zero-server/src/mod.d.ts +0 -1
  170. package/out/zero-server/src/mod.d.ts.map +1 -1
  171. package/out/zero-server/src/process-mutations.d.ts +9 -14
  172. package/out/zero-server/src/process-mutations.d.ts.map +1 -1
  173. package/out/zero-server/src/process-mutations.js +151 -105
  174. package/out/zero-server/src/process-mutations.js.map +1 -1
  175. package/out/zero-server/src/push-processor.d.ts +5 -3
  176. package/out/zero-server/src/push-processor.d.ts.map +1 -1
  177. package/out/zero-server/src/push-processor.js +17 -25
  178. package/out/zero-server/src/push-processor.js.map +1 -1
  179. package/out/zero-server/src/queries/process-queries.js +1 -1
  180. package/out/zero-server/src/queries/process-queries.js.map +1 -1
  181. package/out/zero-server/src/zql-database.d.ts.map +1 -1
  182. package/out/zero-server/src/zql-database.js +1 -1
  183. package/out/zero-server/src/zql-database.js.map +1 -1
  184. package/out/zero-solid/src/use-query.d.ts +3 -3
  185. package/out/zero-solid/src/use-query.d.ts.map +1 -1
  186. package/out/zero-solid/src/use-query.js +27 -38
  187. package/out/zero-solid/src/use-query.js.map +1 -1
  188. package/out/zero-solid/src/use-zero-connection-state.d.ts.map +1 -1
  189. package/out/zero-solid/src/use-zero-connection-state.js +7 -5
  190. package/out/zero-solid/src/use-zero-connection-state.js.map +1 -1
  191. package/out/zero-solid/src/use-zero-online.d.ts.map +1 -1
  192. package/out/zero-solid/src/use-zero-online.js +7 -5
  193. package/out/zero-solid/src/use-zero-online.js.map +1 -1
  194. package/out/zero-solid/src/use-zero.d.ts +6 -5
  195. package/out/zero-solid/src/use-zero.d.ts.map +1 -1
  196. package/out/zero-solid/src/use-zero.js +2 -6
  197. package/out/zero-solid/src/use-zero.js.map +1 -1
  198. package/out/zql/src/builder/builder.d.ts +2 -1
  199. package/out/zql/src/builder/builder.d.ts.map +1 -1
  200. package/out/zql/src/builder/builder.js +4 -3
  201. package/out/zql/src/builder/builder.js.map +1 -1
  202. package/out/zql/src/mutate/custom.d.ts +15 -6
  203. package/out/zql/src/mutate/custom.d.ts.map +1 -1
  204. package/out/zql/src/mutate/custom.js +6 -6
  205. package/out/zql/src/mutate/custom.js.map +1 -1
  206. package/out/zql/src/mutate/mutator-registry.d.ts +142 -0
  207. package/out/zql/src/mutate/mutator-registry.d.ts.map +1 -0
  208. package/out/zql/src/mutate/mutator-registry.js +97 -0
  209. package/out/zql/src/mutate/mutator-registry.js.map +1 -0
  210. package/out/zql/src/mutate/mutator.d.ts +98 -0
  211. package/out/zql/src/mutate/mutator.d.ts.map +1 -0
  212. package/out/zql/src/mutate/mutator.js +35 -0
  213. package/out/zql/src/mutate/mutator.js.map +1 -0
  214. package/out/zql/src/planner/planner-connection.d.ts +7 -15
  215. package/out/zql/src/planner/planner-connection.d.ts.map +1 -1
  216. package/out/zql/src/planner/planner-connection.js +30 -24
  217. package/out/zql/src/planner/planner-connection.js.map +1 -1
  218. package/out/zql/src/planner/planner-debug.d.ts +37 -43
  219. package/out/zql/src/planner/planner-debug.d.ts.map +1 -1
  220. package/out/zql/src/planner/planner-debug.js +242 -0
  221. package/out/zql/src/planner/planner-debug.js.map +1 -0
  222. package/out/zql/src/planner/planner-fan-in.d.ts.map +1 -1
  223. package/out/zql/src/planner/planner-fan-in.js +11 -8
  224. package/out/zql/src/planner/planner-fan-in.js.map +1 -1
  225. package/out/zql/src/planner/planner-fan-out.d.ts.map +1 -1
  226. package/out/zql/src/planner/planner-fan-out.js +11 -8
  227. package/out/zql/src/planner/planner-fan-out.js.map +1 -1
  228. package/out/zql/src/planner/planner-graph.d.ts.map +1 -1
  229. package/out/zql/src/planner/planner-graph.js +13 -5
  230. package/out/zql/src/planner/planner-graph.js.map +1 -1
  231. package/out/zql/src/planner/planner-join.d.ts.map +1 -1
  232. package/out/zql/src/planner/planner-join.js +12 -9
  233. package/out/zql/src/planner/planner-join.js.map +1 -1
  234. package/out/zql/src/planner/planner-node.d.ts +4 -0
  235. package/out/zql/src/planner/planner-node.d.ts.map +1 -1
  236. package/out/zql/src/planner/planner-node.js +8 -0
  237. package/out/zql/src/planner/planner-node.js.map +1 -0
  238. package/out/zql/src/query/create-builder.d.ts +7 -0
  239. package/out/zql/src/query/create-builder.d.ts.map +1 -0
  240. package/out/zql/src/query/create-builder.js +44 -0
  241. package/out/zql/src/query/create-builder.js.map +1 -0
  242. package/out/zql/src/query/named.d.ts +1 -7
  243. package/out/zql/src/query/named.d.ts.map +1 -1
  244. package/out/zql/src/query/named.js +0 -21
  245. package/out/zql/src/query/named.js.map +1 -1
  246. package/out/zql/src/query/query-impl.d.ts +4 -3
  247. package/out/zql/src/query/query-impl.d.ts.map +1 -1
  248. package/out/zql/src/query/query-impl.js +3 -0
  249. package/out/zql/src/query/query-impl.js.map +1 -1
  250. package/out/zql/src/query/query-internals.js +0 -4
  251. package/out/zql/src/query/query-internals.js.map +1 -1
  252. package/out/zql/src/query/query-registry.d.ts +253 -0
  253. package/out/zql/src/query/query-registry.d.ts.map +1 -0
  254. package/out/zql/src/query/query-registry.js +131 -0
  255. package/out/zql/src/query/query-registry.js.map +1 -0
  256. package/out/zql/src/query/query.d.ts +16 -1
  257. package/out/zql/src/query/query.d.ts.map +1 -1
  258. package/out/zql/src/query/schema-query.d.ts +6 -0
  259. package/out/zql/src/query/schema-query.d.ts.map +1 -0
  260. package/out/zql/src/query/validate-input.js +12 -13
  261. package/out/zql/src/query/validate-input.js.map +1 -1
  262. package/package.json +2 -1
  263. package/out/zero-server/src/query-registry.d.ts +0 -10
  264. package/out/zero-server/src/query-registry.d.ts.map +0 -1
  265. package/out/zero-server/src/query-registry.js +0 -35
  266. package/out/zero-server/src/query-registry.js.map +0 -1
  267. package/out/zql/src/query/define-query.d.ts +0 -75
  268. package/out/zql/src/query/define-query.d.ts.map +0 -1
  269. package/out/zql/src/query/define-query.js +0 -47
  270. package/out/zql/src/query/define-query.js.map +0 -1
  271. package/out/zql/src/query/query-definitions.d.ts +0 -32
  272. package/out/zql/src/query/query-definitions.d.ts.map +0 -1
@@ -0,0 +1,98 @@
1
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import type { ReadonlyJSONValue } from '../../../shared/src/json.ts';
3
+ import type { Schema } from '../../../zero-types/src/schema.ts';
4
+ import type { AnyTransaction, Transaction } from './custom.ts';
5
+ declare const defineMutatorTag: unique symbol;
6
+ export declare function isMutatorDefinition<TSchema extends Schema, TContext, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TWrappedTransaction = unknown>(f: unknown): f is MutatorDefinition<TSchema, TContext, TInput, TOutput, TWrappedTransaction>;
7
+ export type MutatorDefinition<TSchema extends Schema, TContext, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TWrappedTransaction> = ((options: {
8
+ args: TOutput;
9
+ ctx: TContext;
10
+ tx: Transaction<TSchema, TWrappedTransaction>;
11
+ }) => Promise<void>) & {
12
+ [defineMutatorTag]: true;
13
+ validator: StandardSchemaV1<TInput, TOutput> | undefined;
14
+ };
15
+ export declare function defineMutator<TSchema extends Schema, TContext, TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined, TWrappedTransaction>(validator: StandardSchemaV1<TInput, TOutput>, mutator: (options: {
16
+ args: TOutput;
17
+ ctx: TContext;
18
+ tx: Transaction<TSchema, TWrappedTransaction>;
19
+ }) => Promise<void>): MutatorDefinition<TSchema, TContext, TInput, TOutput, TWrappedTransaction>;
20
+ export declare function defineMutator<TSchema extends Schema, TContext, TArgs extends ReadonlyJSONValue | undefined, TWrappedTransaction>(mutator: (options: {
21
+ args: TArgs;
22
+ ctx: TContext;
23
+ tx: Transaction<TSchema, TWrappedTransaction>;
24
+ }) => Promise<void>): MutatorDefinition<TSchema, TContext, TArgs, TArgs, TWrappedTransaction>;
25
+ export declare function defineMutatorWithType<TSchema extends Schema>(): TypedDefineMutator<TSchema, unknown, unknown>;
26
+ export declare function defineMutatorWithType<TSchema extends Schema, TContext>(): TypedDefineMutator<TSchema, TContext, unknown>;
27
+ export declare function defineMutatorWithType<TSchema extends Schema, TContext, TWrappedTransaction>(): TypedDefineMutator<TSchema, TContext, TWrappedTransaction>;
28
+ /**
29
+ * The return type of defineMutatorWithType. A function matching the
30
+ * defineMutator overloads but with Schema, Context, and WrappedTransaction
31
+ * pre-bound.
32
+ */
33
+ type TypedDefineMutator<TSchema extends Schema, TContext, TWrappedTransaction> = {
34
+ <TArgs extends ReadonlyJSONValue | undefined>(mutator: (options: {
35
+ args: TArgs;
36
+ ctx: TContext;
37
+ tx: Transaction<TSchema, TWrappedTransaction>;
38
+ }) => Promise<void>): MutatorDefinition<TSchema, TContext, TArgs, TArgs, TWrappedTransaction>;
39
+ <TInput extends ReadonlyJSONValue | undefined, TOutput extends ReadonlyJSONValue | undefined>(validator: StandardSchemaV1<TInput, TOutput>, mutator: (options: {
40
+ args: TOutput;
41
+ ctx: TContext;
42
+ tx: Transaction<TSchema, TWrappedTransaction>;
43
+ }) => Promise<void>): MutatorDefinition<TSchema, TContext, TInput, TOutput, TWrappedTransaction>;
44
+ };
45
+ /**
46
+ * A callable wrapper around a MutatorDefinition, created by `defineMutators()`.
47
+ *
48
+ * Accessed like `mutators.foo.bar`, and called to create a MutationRequest:
49
+ * `mutators.foo.bar(42)` returns a `MutationRequest`.
50
+ *
51
+ * The `fn` property is used for execution and takes raw JSON args (for rebase
52
+ * and server wire format cases) that are validated internally.
53
+ *
54
+ * @template TSchema - The schema type
55
+ * @template TContext - The context type available during mutation execution
56
+ * @template TArgsInput - The argument type accepted by the callable (before validation)
57
+ * @template TWrappedTransaction - The wrapped transaction type
58
+ */
59
+ export type Mutator<TSchema extends Schema, TContext, TArgsInput extends ReadonlyJSONValue | undefined, TWrappedTransaction = unknown> = MutatorCallable<TSchema, TContext, TArgsInput, TWrappedTransaction> & {
60
+ readonly mutatorName: string;
61
+ /**
62
+ * Execute the mutation. Args are ReadonlyJSONValue because this is called
63
+ * during rebase (from stored JSON) and on the server (from wire format).
64
+ * Validation happens internally before the recipe function runs.
65
+ *
66
+ * The tx parameter uses AnyTransaction to avoid contravariance issues when
67
+ * calling from generic code. The implementation casts to the specific type.
68
+ */
69
+ readonly fn: (options: {
70
+ args: TArgsInput;
71
+ ctx: TContext;
72
+ tx: AnyTransaction;
73
+ }) => Promise<void>;
74
+ };
75
+ type MutatorCallable<TSchema extends Schema, TContext, TArgsInput extends ReadonlyJSONValue | undefined, TWrappedTransaction> = [TArgsInput] extends [undefined] ? () => MutationRequest<TSchema, TContext, TArgsInput, TWrappedTransaction> : undefined extends TArgsInput ? (args?: TArgsInput) => MutationRequest<TSchema, TContext, TArgsInput, TWrappedTransaction> : (args: TArgsInput) => MutationRequest<TSchema, TContext, TArgsInput, TWrappedTransaction>;
76
+ export type AnyMutator = Mutator<Schema, any, any, any>;
77
+ /**
78
+ * The result of calling a Mutator with arguments.
79
+ *
80
+ * Created by `mutators.foo.bar(42)`, executed by `zero.mutate(mr)` on the client
81
+ * or `mr.mutator.fn({tx, ctx, args: mr.args})` on the server.
82
+ *
83
+ * @template TSchema - The schema type
84
+ * @template TContext - The context type available during mutation execution
85
+ * @template TArgsInput - The argument type (before validation, sent to server)
86
+ * @template TWrappedTransaction - The wrapped transaction type
87
+ */
88
+ export type MutationRequest<TSchema extends Schema, TContext, TArgsInput extends ReadonlyJSONValue | undefined, TWrappedTransaction> = {
89
+ readonly mutator: Mutator<TSchema, TContext, TArgsInput, TWrappedTransaction>;
90
+ readonly args: TArgsInput;
91
+ };
92
+ /**
93
+ * Checks if a value is a Mutator (the result of processing a MutatorDefinition
94
+ * through defineMutators).
95
+ */
96
+ export declare function isMutator(value: unknown): value is AnyMutator;
97
+ export {};
98
+ //# sourceMappingURL=mutator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutator.d.ts","sourceRoot":"","sources":["../../../../../zql/src/mutate/mutator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,6BAA6B,CAAC;AAEnE,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mCAAmC,CAAC;AAC9D,OAAO,KAAK,EAAC,cAAc,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AAM7D,QAAA,MAAM,gBAAgB,eAAW,CAAC;AAElC,wBAAgB,mBAAmB,CACjC,OAAO,SAAS,MAAM,EACtB,QAAQ,EACR,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,iBAAiB,GAAG,SAAS,EAC7C,mBAAmB,GAAG,OAAO,EAE7B,CAAC,EAAE,OAAO,GACT,CAAC,IAAI,iBAAiB,CACvB,OAAO,EACP,QAAQ,EACR,MAAM,EACN,OAAO,EACP,mBAAmB,CACpB,CAGA;AAED,MAAM,MAAM,iBAAiB,CAC3B,OAAO,SAAS,MAAM,EACtB,QAAQ,EACR,MAAM,SAAS,iBAAiB,GAAG,SAAS,EAC5C,OAAO,SAAS,iBAAiB,GAAG,SAAS,EAC7C,mBAAmB,IACjB,CAAC,CAAC,OAAO,EAAE;IACb,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,QAAQ,CAAC;IACd,EAAE,EAAE,WAAW,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;CAC/C,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG;IACrB,CAAC,gBAAgB,CAAC,EAAE,IAAI,CAAC;IACzB,SAAS,EAAE,gBAAgB,CAAC,MAAM,EA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 function isMutatorDefinition(f) {
4
+ return typeof f === "function" && !!f[defineMutatorTag];
5
+ }
6
+ function defineMutator(validatorOrMutator, mutator) {
7
+ let validator;
8
+ let actualMutator;
9
+ if (typeof validatorOrMutator === "function") {
10
+ validator = void 0;
11
+ actualMutator = validatorOrMutator;
12
+ } else {
13
+ validator = validatorOrMutator;
14
+ actualMutator = must(mutator);
15
+ }
16
+ const f = actualMutator;
17
+ f[defineMutatorTag] = true;
18
+ f.validator = validator;
19
+ return f;
20
+ }
21
+ function defineMutatorWithType() {
22
+ return defineMutator;
23
+ }
24
+ function isMutator(value) {
25
+ return typeof value === "function" && // oxlint-disable-next-line no-explicit-any
26
+ typeof value.mutatorName === "string" && // oxlint-disable-next-line no-explicit-any
27
+ typeof value.fn === "function";
28
+ }
29
+ export {
30
+ defineMutator,
31
+ defineMutatorWithType,
32
+ isMutator,
33
+ isMutatorDefinition
34
+ };
35
+ //# sourceMappingURL=mutator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutator.js","sources":["../../../../../zql/src/mutate/mutator.ts"],"sourcesContent":["import type {StandardSchemaV1} from '@standard-schema/spec';\nimport type {ReadonlyJSONValue} from '../../../shared/src/json.ts';\nimport {must} from '../../../shared/src/must.ts';\nimport type {Schema} from '../../../zero-types/src/schema.ts';\nimport type {AnyTransaction, Transaction} from './custom.ts';\n\n// ----------------------------------------------------------------------------\n// defineMutator\n// ----------------------------------------------------------------------------\n\nconst defineMutatorTag = Symbol();\n\nexport function isMutatorDefinition<\n TSchema extends Schema,\n TContext,\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction = unknown,\n>(\n f: unknown,\n): f is MutatorDefinition<\n TSchema,\n TContext,\n TInput,\n TOutput,\n TWrappedTransaction\n> {\n // oxlint-disable-next-line no-explicit-any\n return typeof f === 'function' && !!(f as any)[defineMutatorTag];\n}\n\nexport type MutatorDefinition<\n TSchema extends Schema,\n TContext,\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n> = ((options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n}) => Promise<void>) & {\n [defineMutatorTag]: true;\n validator: StandardSchemaV1<TInput, TOutput> | undefined;\n};\n\n// Overload 1: Call with validator\nexport function defineMutator<\n TSchema extends Schema,\n TContext,\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n>(\n validator: StandardSchemaV1<TInput, TOutput>,\n mutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TSchema, TContext, TInput, TOutput, TWrappedTransaction>;\n\n// Overload 2: Call without validator\nexport function defineMutator<\n TSchema extends Schema,\n TContext,\n TArgs extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n>(\n mutator: (options: {\n args: TArgs;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TSchema, TContext, TArgs, TArgs, TWrappedTransaction>;\n\n// Implementation\nexport function defineMutator<\n TSchema extends Schema,\n TContext,\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n>(\n validatorOrMutator:\n | StandardSchemaV1<TInput, TOutput>\n | ((options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>),\n mutator?: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n): MutatorDefinition<TSchema, TContext, TInput, TOutput, TWrappedTransaction> {\n let validator: StandardSchemaV1<TInput, TOutput> | undefined;\n let actualMutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>;\n\n if (typeof validatorOrMutator === 'function') {\n // defineMutator(mutator) - no validator\n validator = undefined;\n actualMutator = validatorOrMutator;\n } else {\n // defineMutator(validator, mutator)\n validator = validatorOrMutator;\n actualMutator = must(mutator);\n }\n\n const f = actualMutator as MutatorDefinition<\n TSchema,\n TContext,\n TInput,\n TOutput,\n TWrappedTransaction\n >;\n f[defineMutatorTag] = true;\n f.validator = validator;\n return f;\n}\n\n// Overload 1: Just Schema\nexport function defineMutatorWithType<\n TSchema extends Schema,\n>(): TypedDefineMutator<TSchema, unknown, unknown>;\n\n// Overload 2: Schema and Context\nexport function defineMutatorWithType<\n TSchema extends Schema,\n TContext,\n>(): TypedDefineMutator<TSchema, TContext, unknown>;\n\n// Overload 3: Schema, Context, and WrappedTransaction\nexport function defineMutatorWithType<\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n>(): TypedDefineMutator<TSchema, TContext, TWrappedTransaction>;\n\n// Implementation\nexport function defineMutatorWithType() {\n return defineMutator;\n}\n\n/**\n * The return type of defineMutatorWithType. A function matching the\n * defineMutator overloads but with Schema, Context, and WrappedTransaction\n * pre-bound.\n */\ntype TypedDefineMutator<\n TSchema extends Schema,\n TContext,\n TWrappedTransaction,\n> = {\n // Without validator\n <TArgs extends ReadonlyJSONValue | undefined>(\n mutator: (options: {\n args: TArgs;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n ): MutatorDefinition<TSchema, TContext, TArgs, TArgs, TWrappedTransaction>;\n\n // With validator\n <\n TInput extends ReadonlyJSONValue | undefined,\n TOutput extends ReadonlyJSONValue | undefined,\n >(\n validator: StandardSchemaV1<TInput, TOutput>,\n mutator: (options: {\n args: TOutput;\n ctx: TContext;\n tx: Transaction<TSchema, TWrappedTransaction>;\n }) => Promise<void>,\n ): MutatorDefinition<TSchema, TContext, TInput, TOutput, TWrappedTransaction>;\n};\n\n// ----------------------------------------------------------------------------\n// Mutator and MutationRequest types\n// ----------------------------------------------------------------------------\n\n/**\n * A callable wrapper around a MutatorDefinition, created by `defineMutators()`.\n *\n * Accessed like `mutators.foo.bar`, and called to create a MutationRequest:\n * `mutators.foo.bar(42)` returns a `MutationRequest`.\n *\n * The `fn` property is used for execution and takes raw JSON args (for rebase\n * and server wire format cases) that are validated internally.\n *\n * @template TSchema - The schema type\n * @template TContext - The context type available during mutation execution\n * @template TArgsInput - The argument type accepted by the callable (before validation)\n * @template TWrappedTransaction - The wrapped transaction type\n */\nexport type Mutator<\n TSchema extends Schema,\n TContext,\n TArgsInput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction = unknown,\n> = MutatorCallable<TSchema, TContext, TArgsInput, TWrappedTransaction> & {\n readonly mutatorName: string;\n /**\n * Execute the mutation. Args are ReadonlyJSONValue because this is called\n * during rebase (from stored JSON) and on the server (from wire format).\n * Validation happens internally before the recipe function runs.\n *\n * The tx parameter uses AnyTransaction to avoid contravariance issues when\n * calling from generic code. The implementation casts to the specific type.\n */\n readonly fn: (options: {\n args: TArgsInput;\n ctx: TContext;\n tx: AnyTransaction;\n }) => Promise<void>;\n};\n\n// Helper type for the callable part of Mutator\n// When TArgsInput is undefined, the function is callable with 0 args\n// When TArgsInput includes undefined (optional), args is optional\n// Otherwise, args is required\ntype MutatorCallable<\n TSchema extends Schema,\n TContext,\n TArgsInput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n> = [TArgsInput] extends [undefined]\n ? () => MutationRequest<TSchema, TContext, TArgsInput, TWrappedTransaction>\n : undefined extends TArgsInput\n ? (\n args?: TArgsInput,\n ) => MutationRequest<TSchema, TContext, TArgsInput, TWrappedTransaction>\n : (\n args: TArgsInput,\n ) => MutationRequest<TSchema, TContext, TArgsInput, TWrappedTransaction>;\n\n// oxlint-disable-next-line no-explicit-any\nexport type AnyMutator = Mutator<Schema, any, any, any>;\n\n/**\n * The result of calling a Mutator with arguments.\n *\n * Created by `mutators.foo.bar(42)`, executed by `zero.mutate(mr)` on the client\n * or `mr.mutator.fn({tx, ctx, args: mr.args})` on the server.\n *\n * @template TSchema - The schema type\n * @template TContext - The context type available during mutation execution\n * @template TArgsInput - The argument type (before validation, sent to server)\n * @template TWrappedTransaction - The wrapped transaction type\n */\nexport type MutationRequest<\n TSchema extends Schema,\n TContext,\n TArgsInput extends ReadonlyJSONValue | undefined,\n TWrappedTransaction,\n> = {\n readonly mutator: Mutator<TSchema, TContext, TArgsInput, TWrappedTransaction>;\n readonly args: TArgsInput;\n};\n\n/**\n * Checks if a value is a Mutator (the result of processing a MutatorDefinition\n * through defineMutators).\n */\nexport function isMutator(value: unknown): value is AnyMutator {\n return (\n typeof value === 'function' &&\n // oxlint-disable-next-line no-explicit-any\n typeof (value as any).mutatorName === 'string' &&\n // oxlint-disable-next-line no-explicit-any\n typeof (value as any).fn === 'function'\n );\n}\n"],"names":[],"mappings":";AAUA,MAAM,mBAAmB,OAAA;AAElB,SAAS,oBAOd,GAOA;AAEA,SAAO,OAAO,MAAM,cAAc,CAAC,CAAE,EAAU,gBAAgB;AACjE;AAgDO,SAAS,cAOd,oBAOA,SAK4E;AAC5E,MAAI;AACJ,MAAI;AAMJ,MAAI,OAAO,uBAAuB,YAAY;AAE5C,gBAAY;AACZ,oBAAgB;AAAA,EAClB,OAAO;AAEL,gBAAY;AACZ,oBAAgB,KAAK,OAAO;AAAA,EAC9B;AAEA,QAAM,IAAI;AAOV,IAAE,gBAAgB,IAAI;AACtB,IAAE,YAAY;AACd,SAAO;AACT;AAqBO,SAAS,wBAAwB;AACtC,SAAO;AACT;AA0HO,SAAS,UAAU,OAAqC;AAC7D,SACE,OAAO,UAAU;AAAA,EAEjB,OAAQ,MAAc,gBAAgB;AAAA,EAEtC,OAAQ,MAAc,OAAO;AAEjC;"}
@@ -100,22 +100,14 @@ export declare class PlannerConnection {
100
100
  * Used by PlannerGraph to restore planning state.
101
101
  */
102
102
  restoreConstraints(constraints: Map<string, PlannerConstraint | undefined>): void;
103
- /**
104
- * Get current constraints for debugging.
105
- * Returns a copy of the constraints map.
106
- */
107
- getConstraintsForDebug(): Map<string, PlannerConstraint | undefined>;
108
- /**
109
- * Get filters for debugging.
110
- * Returns the filters applied to this connection.
111
- */
103
+ /** Get current constraints for debugging. */
104
+ getConstraintsForDebug(): Record<string, PlannerConstraint | undefined>;
105
+ /** Get filters for debugging. */
112
106
  getFiltersForDebug(): Condition | undefined;
113
- /**
114
- * Get estimated cost for each constraint branch.
115
- * Returns a map of constraint key to cost estimate.
116
- * Forces cost calculation if not already cached.
117
- */
118
- getConstraintCostsForDebug(): Map<string, CostEstimate>;
107
+ /** Get sort/ordering for debugging. */
108
+ getSortForDebug(): Ordering;
109
+ /** Get estimated cost for each constraint branch. */
110
+ getConstraintCostsForDebug(): Record<string, CostEstimate>;
119
111
  }
120
112
  type FanoutEst = {
121
113
  fanout: number;
@@ -1 +1 @@
1
- {"version":3,"file":"planner-connection.d.ts","sourceRoot":"","sources":["../../../../../zql/src/planner/planner-connection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,qBAAa,iBAAiB;;IAC5B,QAAQ,CAAC,IAAI,EAAG,YAAY,CAAU;IAQtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAM7B;;;;OAIG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;gBAqBxB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,mBAAmB,EAC1B,IAAI,EAAE,Q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AI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,CAChC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,UAAU,EAAE,iBAAiB,GAAG,SAAS,KACtC,aAAa,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { assert } from "../../../shared/src/asserts.js";
2
2
  import { mergeConstraints } from "./planner-constraint.js";
3
+ import { omitFanout } from "./planner-node.js";
3
4
  class PlannerConnection {
4
5
  kind = "connection";
5
6
  // ========================================================================
@@ -126,15 +127,18 @@ class PlannerConnection {
126
127
  fanout
127
128
  };
128
129
  this.#cachedConstraintCosts.set(key, cost);
129
- planDebugger?.log({
130
- type: "node-cost",
131
- nodeType: "connection",
132
- node: this.name,
133
- branchPattern,
134
- downstreamChildSelectivity,
135
- costEstimate: cost,
136
- filters: this.#filters
137
- });
130
+ if (planDebugger) {
131
+ planDebugger.log({
132
+ type: "node-cost",
133
+ nodeType: "connection",
134
+ node: this.name,
135
+ branchPattern,
136
+ downstreamChildSelectivity,
137
+ costEstimate: omitFanout(cost),
138
+ filters: this.#filters,
139
+ ordering: this.#sort
140
+ });
141
+ }
138
142
  return cost;
139
143
  }
140
144
  /**
@@ -180,27 +184,29 @@ class PlannerConnection {
180
184
  }
181
185
  this.#cachedConstraintCosts.clear();
182
186
  }
183
- /**
184
- * Get current constraints for debugging.
185
- * Returns a copy of the constraints map.
186
- */
187
+ /** Get current constraints for debugging. */
187
188
  getConstraintsForDebug() {
188
- return new Map(this.#constraints);
189
+ const record = {};
190
+ for (const [key, value] of this.#constraints) {
191
+ record[key] = value;
192
+ }
193
+ return record;
189
194
  }
190
- /**
191
- * Get filters for debugging.
192
- * Returns the filters applied to this connection.
193
- */
195
+ /** Get filters for debugging. */
194
196
  getFiltersForDebug() {
195
197
  return this.#filters;
196
198
  }
197
- /**
198
- * Get estimated cost for each constraint branch.
199
- * Returns a map of constraint key to cost estimate.
200
- * Forces cost calculation if not already cached.
201
- */
199
+ /** Get sort/ordering for debugging. */
200
+ getSortForDebug() {
201
+ return this.#sort;
202
+ }
203
+ /** Get estimated cost for each constraint branch. */
202
204
  getConstraintCostsForDebug() {
203
- return new Map(this.#cachedConstraintCosts);
205
+ const record = {};
206
+ for (const [key, value] of this.#cachedConstraintCosts) {
207
+ record[key] = value;
208
+ }
209
+ return record;
204
210
  }
205
211
  }
206
212
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"planner-connection.js","sources":["../../../../../zql/src/planner/planner-connection.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Condition, Ordering} from '../../../zero-protocol/src/ast.ts';\nimport {\n mergeConstraints,\n type PlannerConstraint,\n} from './planner-constraint.ts';\nimport type {PlanDebugger} from './planner-debug.ts';\nimport type {\n CostEstimate,\n JoinOrConnection,\n PlannerNode,\n} from './planner-node.ts';\n\n/**\n * Represents a connection to a source (table scan).\n *\n * # Dual State Pattern\n * Like all planner nodes, PlannerConnection separates:\n * 1. immutable structure: Ordering, filters, cost model (set at construction)\n * 2. mutable state: Pinned status, constraints (mutated during planning)\n *\n * # Cost Estimation\n * The ordering and filters determine the initial cost. As planning progresses,\n * constraints from parent joins refine the cost estimate.\n *\n * # Constraint Flow\n * When a connection is pinned as the outer loop, it reveals constraints for\n * connected joins. These constraints propagate through the graph, allowing\n * other connections to update their cost estimates.\n *\n * Example:\n *\n * ```ts\n * builder.issue.whereExists('assignee', a => a.where('name', 'Alice'))\n * ```\n *\n * ```\n * [issue] [assignee]\n * | |\n * | +-- where name = 'Alice'\n * \\ /\n * \\ /\n * [join]\n * |\n * ```\n *\n * - Initial state: Both connections have no constraints, costs are unconstrained\n * - If `issue` chosen first: Reveals constraint `assignee_id` for assignee connection\n * - If `assignee` chosen first: Reveals constraint `assignee_id` for issue connection\n * - Updated costs guide the next selection\n *\n * # Lifecycle\n * 1. Construct with immutable structure (ordering, filters, cost model)\n * 2. Wire to output node during graph construction\n * 3. Planning mutates pinned status and accumulates constraints\n * 4. reset() clears mutable state for replanning\n */\nexport class PlannerConnection {\n readonly kind = 'connection' as const;\n\n // ========================================================================\n // IMMUTABLE STRUCTURE (set during construction, never changes)\n // ========================================================================\n readonly #sort: Ordering;\n readonly #filters: Condition | undefined;\n readonly #model: ConnectionCostModel;\n readonly table: string;\n readonly name: string; // Human-readable name for debugging (defaults to table name)\n readonly #baseConstraints: PlannerConstraint | undefined; // Constraints from parent correlation\n readonly #baseLimit: number | undefined; // Original limit from query structure (never modified)\n readonly selectivity: number; // Fraction of rows passing filters (1.0 = no filtering)\n #output?: PlannerNode | undefined; // Set once during graph construction\n\n // ========================================================================\n // MUTABLE PLANNING STATE (changes during plan search)\n // ========================================================================\n /**\n * Current limit during planning. Can be cleared (set to undefined) when a\n * parent join is flipped, indicating this connection is now in an outer loop\n * and should not be limited by EXISTS semantics.\n */\n limit: number | undefined;\n\n /**\n * Constraints accumulated from parent joins during planning.\n * Key is a path through the graph (e.g., \"0,1\" for branch pattern [0,1]).\n *\n * Undefined constraints are possible when a FO converts to UFO and only\n * a single join in the UFO is flipped - other branches report undefined.\n */\n readonly #constraints: Map<string, PlannerConstraint | undefined>;\n\n readonly #isRoot: boolean;\n\n /**\n * Cached per-constraint costs to avoid redundant cost model calls.\n * Maps constraint key (branch pattern string) to computed cost.\n * Invalidated when constraints change.\n */\n #cachedConstraintCosts: Map<string, CostEstimate> = new Map();\n\n constructor(\n table: string,\n model: ConnectionCostModel,\n sort: Ordering,\n filters: Condition | undefined,\n isRoot: boolean,\n baseConstraints?: PlannerConstraint,\n limit?: number,\n name?: string,\n ) {\n this.table = table;\n this.name = name ?? table;\n this.#sort = sort;\n this.#filters = filters;\n this.#model = model;\n this.#baseConstraints = baseConstraints;\n this.#baseLimit = limit;\n this.limit = limit;\n this.#constraints = new Map();\n this.#isRoot = isRoot;\n\n // Compute selectivity for EXISTS child connections (baseLimit === 1)\n // Selectivity = fraction of rows that pass filters\n if (limit !== undefined && filters) {\n const costWithFilters = model(table, sort, filters, undefined);\n const costWithoutFilters = model(table, sort, undefined, undefined);\n this.selectivity =\n costWithoutFilters.rows > 0\n ? costWithFilters.rows / costWithoutFilters.rows\n : 1.0;\n } else {\n // Root connections or connections without filters\n this.selectivity = 1.0;\n }\n }\n\n setOutput(node: PlannerNode): void {\n this.#output = node;\n }\n\n get output(): PlannerNode {\n assert(this.#output !== undefined, 'Output not set');\n return this.#output;\n }\n\n closestJoinOrSource(): JoinOrConnection {\n return 'connection';\n }\n\n /**\n * Constraints are uniquely identified by their path through the\n * graph.\n *\n * FO represents all sub-joins as a single path.\n * UFO represents each sub-join as a separate path.\n * The first branch in a UFO will match the path of FO so no re-set needs to happen\n * when swapping from FO to UFO.\n *\n * FO swaps to UFO when a join inside FO-FI gets flipped.\n *\n * The max of the last element of the paths is the number of\n * root branches.\n */\n propagateConstraints(\n path: number[],\n c: PlannerConstraint | undefined,\n from?: PlannerNode,\n planDebugger?: PlanDebugger,\n ): void {\n const key = path.join(',');\n this.#constraints.set(key, c);\n // Constraints changed, invalidate cost caches\n this.#cachedConstraintCosts.clear();\n\n planDebugger?.log({\n type: 'node-constraint',\n nodeType: 'connection',\n node: this.name,\n branchPattern: path,\n constraint: c,\n from: from?.kind ?? 'unknown',\n });\n }\n\n estimateCost(\n downstreamChildSelectivity: number,\n branchPattern: number[],\n planDebugger?: PlanDebugger,\n ): CostEstimate {\n // Branch pattern specified - return cost for this specific branch\n const key = branchPattern.join(',');\n\n // Check per-constraint cache first\n let cost = this.#cachedConstraintCosts.get(key);\n if (cost !== undefined) {\n return cost;\n }\n\n // Cache miss - compute and cache\n const constraint = this.#constraints.get(key);\n // Merge base constraints with propagated constraints\n const mergedConstraint = mergeConstraints(\n this.#baseConstraints,\n constraint,\n );\n const {startupCost, fanout, rows} = this.#model(\n this.table,\n this.#sort,\n this.#filters,\n mergedConstraint,\n );\n cost = {\n startupCost,\n scanEst:\n this.limit === undefined\n ? rows\n : Math.min(rows, this.limit / downstreamChildSelectivity),\n cost: 0,\n returnedRows: rows,\n selectivity: this.selectivity,\n limit: this.limit,\n fanout,\n };\n this.#cachedConstraintCosts.set(key, cost);\n\n planDebugger?.log({\n type: 'node-cost',\n nodeType: 'connection',\n node: this.name,\n branchPattern,\n downstreamChildSelectivity,\n costEstimate: cost,\n filters: this.#filters,\n });\n\n return cost;\n }\n\n /**\n * Remove the limit from this connection.\n * Called when a parent join is flipped, making this connection part of an\n * outer loop that should produce all rows rather than stopping at the limit.\n */\n unlimit(): void {\n if (this.#isRoot) {\n // We cannot unlimit root connections\n return;\n }\n if (this.limit !== undefined) {\n this.limit = undefined;\n // Limit changes do not impact connection costs.\n // Limit is taken into account at the join level.\n // Given that, we do not need to invalidate cost caches here.\n }\n }\n\n /**\n * Propagate unlimiting when a parent join is flipped.\n * For connections, we simply remove the limit.\n */\n propagateUnlimitFromFlippedJoin(): void {\n this.unlimit();\n }\n\n reset() {\n this.#constraints.clear();\n this.limit = this.#baseLimit;\n // Clear all cost caches\n this.#cachedConstraintCosts.clear();\n }\n\n /**\n * Capture constraint state for snapshotting.\n * Used by PlannerGraph to save/restore planning state.\n */\n captureConstraints(): Map<string, PlannerConstraint | undefined> {\n return new Map(this.#constraints);\n }\n\n /**\n * Restore constraint state from a snapshot.\n * Used by PlannerGraph to restore planning state.\n */\n restoreConstraints(\n constraints: Map<string, PlannerConstraint | undefined>,\n ): void {\n this.#constraints.clear();\n for (const [key, value] of constraints) {\n this.#constraints.set(key, value);\n }\n // Constraints changed, invalidate cost caches\n this.#cachedConstraintCosts.clear();\n }\n\n /**\n * Get current constraints for debugging.\n * Returns a copy of the constraints map.\n */\n getConstraintsForDebug(): Map<string, PlannerConstraint | undefined> {\n return new Map(this.#constraints);\n }\n\n /**\n * Get filters for debugging.\n * Returns the filters applied to this connection.\n */\n getFiltersForDebug(): Condition | undefined {\n return this.#filters;\n }\n\n /**\n * Get estimated cost for each constraint branch.\n * Returns a map of constraint key to cost estimate.\n * Forces cost calculation if not already cached.\n */\n getConstraintCostsForDebug(): Map<string, CostEstimate> {\n // Return copy of cached costs\n return new Map(this.#cachedConstraintCosts);\n }\n}\n\ntype FanoutEst = {\n fanout: number;\n confidence: 'high' | 'med' | 'none';\n};\nexport type FanoutCostModel = (columns: string[]) => FanoutEst;\n\nexport type CostModelCost = {\n startupCost: number;\n rows: number;\n fanout: FanoutCostModel;\n};\nexport type ConnectionCostModel = (\n table: string,\n sort: Ordering,\n filters: Condition | undefined,\n constraint: PlannerConstraint | undefined,\n) => CostModelCost;\n"],"names":[],"mappings":";;AAyDO,MAAM,kBAAkB;AAAA,EACpB,OAAO;AAAA;AAAA;AAAA;AAAA,EAKP;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASS;AAAA,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,6CAAwD,IAAA;AAAA,EAExD,YACE,OACA,OACA,MACA,SACA,QACA,iBACA,OACA,MACA;AACA,SAAK,QAAQ;AACb,SAAK,OAAO,QAAQ;AACpB,SAAK,QAAQ;AACb,SAAK,WAAW;AAChB,SAAK,SAAS;AACd,SAAK,mBAAmB;AACxB,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,mCAAmB,IAAA;AACxB,SAAK,UAAU;AAIf,QAAI,UAAU,UAAa,SAAS;AAClC,YAAM,kBAAkB,MAAM,OAAO,MAAM,SAAS,MAAS;AAC7D,YAAM,qBAAqB,MAAM,OAAO,MAAM,QAAW,MAAS;AAClE,WAAK,cACH,mBAAmB,OAAO,IACtB,gBAAgB,OAAO,mBAAmB,OAC1C;AAAA,IACR,OAAO;AAEL,WAAK,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,IAAI,KAAK,IAAI;AAEzC,kBAAc,IAAI;AAAA,MAChB,MAAM;AAAA,MACN,UAAU;AAAA,MACV,MAAM,KAAK;AAAA,MACX;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd,SAAS,KAAK;AAAA,IAAA,CACf;AAED,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,UAAgB;AACd,QAAI,KAAK,SAAS;AAEhB;AAAA,IACF;AACA,QAAI,KAAK,UAAU,QAAW;AAC5B,WAAK,QAAQ;AAAA,IAIf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,kCAAwC;AACtC,SAAK,QAAA;AAAA,EACP;AAAA,EAEA,QAAQ;AACN,SAAK,aAAa,MAAA;AAClB,SAAK,QAAQ,KAAK;AAElB,SAAK,uBAAuB,MAAA;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAiE;AAC/D,WAAO,IAAI,IAAI,KAAK,YAAY;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,mBACE,aACM;AACN,SAAK,aAAa,MAAA;AAClB,eAAW,CAAC,KAAK,KAAK,KAAK,aAAa;AACtC,WAAK,aAAa,IAAI,KAAK,KAAK;AAAA,IAClC;AAEA,SAAK,uBAAuB,MAAA;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,yBAAqE;AACnE,WAAO,IAAI,IAAI,KAAK,YAAY;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAA4C;AAC1C,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,6BAAwD;AAEtD,WAAO,IAAI,IAAI,KAAK,sBAAsB;AAAA,EAC5C;AACF;"}
1
+ {"version":3,"file":"planner-connection.js","sources":["../../../../../zql/src/planner/planner-connection.ts"],"sourcesContent":["import {assert} from '../../../shared/src/asserts.ts';\nimport type {Condition, Ordering} from '../../../zero-protocol/src/ast.ts';\nimport {\n mergeConstraints,\n type PlannerConstraint,\n} from './planner-constraint.ts';\nimport type {PlanDebugger} from './planner-debug.ts';\nimport {omitFanout} from './planner-node.ts';\nimport type {\n CostEstimate,\n JoinOrConnection,\n PlannerNode,\n} from './planner-node.ts';\n\n/**\n * Represents a connection to a source (table scan).\n *\n * # Dual State Pattern\n * Like all planner nodes, PlannerConnection separates:\n * 1. immutable structure: Ordering, filters, cost model (set at construction)\n * 2. mutable state: Pinned status, constraints (mutated during planning)\n *\n * # Cost Estimation\n * The ordering and filters determine the initial cost. As planning progresses,\n * constraints from parent joins refine the cost estimate.\n *\n * # Constraint Flow\n * When a connection is pinned as the outer loop, it reveals constraints for\n * connected joins. These constraints propagate through the graph, allowing\n * other connections to update their cost estimates.\n *\n * Example:\n *\n * ```ts\n * builder.issue.whereExists('assignee', a => a.where('name', 'Alice'))\n * ```\n *\n * ```\n * [issue] [assignee]\n * | |\n * | +-- where name = 'Alice'\n * \\ /\n * \\ /\n * [join]\n * |\n * ```\n *\n * - Initial state: Both connections have no constraints, costs are unconstrained\n * - If `issue` chosen first: Reveals constraint `assignee_id` for assignee connection\n * - If `assignee` chosen first: Reveals constraint `assignee_id` for issue connection\n * - Updated costs guide the next selection\n *\n * # Lifecycle\n * 1. Construct with immutable structure (ordering, filters, cost model)\n * 2. Wire to output node during graph construction\n * 3. Planning mutates pinned status and accumulates constraints\n * 4. reset() clears mutable state for replanning\n */\nexport class PlannerConnection {\n readonly kind = 'connection' as const;\n\n // ========================================================================\n // IMMUTABLE STRUCTURE (set during construction, never changes)\n // ========================================================================\n readonly #sort: Ordering;\n readonly #filters: Condition | undefined;\n readonly #model: ConnectionCostModel;\n readonly table: string;\n readonly name: string; // Human-readable name for debugging (defaults to table name)\n readonly #baseConstraints: PlannerConstraint | undefined; // Constraints from parent correlation\n readonly #baseLimit: number | undefined; // Original limit from query structure (never modified)\n readonly selectivity: number; // Fraction of rows passing filters (1.0 = no filtering)\n #output?: PlannerNode | undefined; // Set once during graph construction\n\n // ========================================================================\n // MUTABLE PLANNING STATE (changes during plan search)\n // ========================================================================\n /**\n * Current limit during planning. Can be cleared (set to undefined) when a\n * parent join is flipped, indicating this connection is now in an outer loop\n * and should not be limited by EXISTS semantics.\n */\n limit: number | undefined;\n\n /**\n * Constraints accumulated from parent joins during planning.\n * Key is a path through the graph (e.g., \"0,1\" for branch pattern [0,1]).\n *\n * Undefined constraints are possible when a FO converts to UFO and only\n * a single join in the UFO is flipped - other branches report undefined.\n */\n readonly #constraints: Map<string, PlannerConstraint | undefined>;\n\n readonly #isRoot: boolean;\n\n /**\n * Cached per-constraint costs to avoid redundant cost model calls.\n * Maps constraint key (branch pattern string) to computed cost.\n * Invalidated when constraints change.\n */\n #cachedConstraintCosts: Map<string, CostEstimate> = new Map();\n\n constructor(\n table: string,\n model: ConnectionCostModel,\n sort: Ordering,\n filters: Condition | undefined,\n isRoot: boolean,\n baseConstraints?: PlannerConstraint,\n limit?: number,\n name?: string,\n ) {\n this.table = table;\n this.name = name ?? table;\n this.#sort = sort;\n this.#filters = filters;\n this.#model = model;\n this.#baseConstraints = baseConstraints;\n this.#baseLimit = limit;\n this.limit = limit;\n this.#constraints = new Map();\n this.#isRoot = isRoot;\n\n // Compute selectivity for EXISTS child connections (baseLimit === 1)\n // Selectivity = fraction of rows that pass filters\n if (limit !== undefined && filters) {\n const costWithFilters = model(table, sort, filters, undefined);\n const costWithoutFilters = model(table, sort, undefined, undefined);\n this.selectivity =\n costWithoutFilters.rows > 0\n ? costWithFilters.rows / costWithoutFilters.rows\n : 1.0;\n } else {\n // Root connections or connections without filters\n this.selectivity = 1.0;\n }\n }\n\n setOutput(node: PlannerNode): void {\n this.#output = node;\n }\n\n get output(): PlannerNode {\n assert(this.#output !== undefined, 'Output not set');\n return this.#output;\n }\n\n closestJoinOrSource(): JoinOrConnection {\n return 'connection';\n }\n\n /**\n * Constraints are uniquely identified by their path through the\n * graph.\n *\n * FO represents all sub-joins as a single path.\n * UFO represents each sub-join as a separate path.\n * The first branch in a UFO will match the path of FO so no re-set needs to happen\n * when swapping from FO to UFO.\n *\n * FO swaps to UFO when a join inside FO-FI gets flipped.\n *\n * The max of the last element of the paths is the number of\n * root branches.\n */\n propagateConstraints(\n path: number[],\n c: PlannerConstraint | undefined,\n from?: PlannerNode,\n planDebugger?: PlanDebugger,\n ): void {\n const key = path.join(',');\n this.#constraints.set(key, c);\n // Constraints changed, invalidate cost caches\n this.#cachedConstraintCosts.clear();\n\n planDebugger?.log({\n type: 'node-constraint',\n nodeType: 'connection',\n node: this.name,\n branchPattern: path,\n constraint: c,\n from: from?.kind ?? 'unknown',\n });\n }\n\n estimateCost(\n downstreamChildSelectivity: number,\n branchPattern: number[],\n planDebugger?: PlanDebugger,\n ): CostEstimate {\n // Branch pattern specified - return cost for this specific branch\n const key = branchPattern.join(',');\n\n // Check per-constraint cache first\n let cost = this.#cachedConstraintCosts.get(key);\n if (cost !== undefined) {\n return cost;\n }\n\n // Cache miss - compute and cache\n const constraint = this.#constraints.get(key);\n // Merge base constraints with propagated constraints\n const mergedConstraint = mergeConstraints(\n this.#baseConstraints,\n constraint,\n );\n const {startupCost, fanout, rows} = this.#model(\n this.table,\n this.#sort,\n this.#filters,\n mergedConstraint,\n );\n cost = {\n startupCost,\n scanEst:\n this.limit === undefined\n ? rows\n : Math.min(rows, this.limit / downstreamChildSelectivity),\n cost: 0,\n returnedRows: rows,\n selectivity: this.selectivity,\n limit: this.limit,\n fanout,\n };\n this.#cachedConstraintCosts.set(key, cost);\n\n if (planDebugger) {\n planDebugger.log({\n type: 'node-cost',\n nodeType: 'connection',\n node: this.name,\n branchPattern,\n downstreamChildSelectivity,\n costEstimate: omitFanout(cost),\n filters: this.#filters,\n ordering: this.#sort,\n });\n }\n\n return cost;\n }\n\n /**\n * Remove the limit from this connection.\n * Called when a parent join is flipped, making this connection part of an\n * outer loop that should produce all rows rather than stopping at the limit.\n */\n unlimit(): void {\n if (this.#isRoot) {\n // We cannot unlimit root connections\n return;\n }\n if (this.limit !== undefined) {\n this.limit = undefined;\n // Limit changes do not impact connection costs.\n // Limit is taken into account at the join level.\n // Given that, we do not need to invalidate cost caches here.\n }\n }\n\n /**\n * Propagate unlimiting when a parent join is flipped.\n * For connections, we simply remove the limit.\n */\n propagateUnlimitFromFlippedJoin(): void {\n this.unlimit();\n }\n\n reset() {\n this.#constraints.clear();\n this.limit = this.#baseLimit;\n // Clear all cost caches\n this.#cachedConstraintCosts.clear();\n }\n\n /**\n * Capture constraint state for snapshotting.\n * Used by PlannerGraph to save/restore planning state.\n */\n captureConstraints(): Map<string, PlannerConstraint | undefined> {\n return new Map(this.#constraints);\n }\n\n /**\n * Restore constraint state from a snapshot.\n * Used by PlannerGraph to restore planning state.\n */\n restoreConstraints(\n constraints: Map<string, PlannerConstraint | undefined>,\n ): void {\n this.#constraints.clear();\n for (const [key, value] of constraints) {\n this.#constraints.set(key, value);\n }\n // Constraints changed, invalidate cost caches\n this.#cachedConstraintCosts.clear();\n }\n\n /** Get current constraints for debugging. */\n getConstraintsForDebug(): Record<string, PlannerConstraint | undefined> {\n const record: Record<string, PlannerConstraint | undefined> = {};\n for (const [key, value] of this.#constraints) {\n record[key] = value;\n }\n return record;\n }\n\n /** Get filters for debugging. */\n getFiltersForDebug(): Condition | undefined {\n return this.#filters;\n }\n\n /** Get sort/ordering for debugging. */\n getSortForDebug(): Ordering {\n return this.#sort;\n }\n\n /** Get estimated cost for each constraint branch. */\n getConstraintCostsForDebug(): Record<string, CostEstimate> {\n const record: Record<string, CostEstimate> = {};\n for (const [key, value] of this.#cachedConstraintCosts) {\n record[key] = value;\n }\n return record;\n }\n}\n\ntype FanoutEst = {\n fanout: number;\n confidence: 'high' | 'med' | 'none';\n};\nexport type FanoutCostModel = (columns: string[]) => FanoutEst;\n\nexport type CostModelCost = {\n startupCost: number;\n rows: number;\n fanout: FanoutCostModel;\n};\nexport type ConnectionCostModel = (\n table: string,\n sort: Ordering,\n filters: Condition | undefined,\n constra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SAAS;AAEhB;AAAA,IACF;AACA,QAAI,KAAK,UAAU,QAAW;AAC5B,WAAK,QAAQ;AAAA,IAIf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,kCAAwC;AACtC,SAAK,QAAA;AAAA,EACP;AAAA,EAEA,QAAQ;AACN,SAAK,aAAa,MAAA;AAClB,SAAK,QAAQ,KAAK;AAElB,SAAK,uBAAuB,MAAA;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAiE;AAC/D,WAAO,IAAI,IAAI,KAAK,YAAY;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,mBACE,aACM;AACN,SAAK,aAAa,MAAA;AAClB,eAAW,CAAC,KAAK,KAAK,KAAK,aAAa;AACtC,WAAK,aAAa,IAAI,KAAK,KAAK;AAAA,IAClC;AAEA,SAAK,uBAAuB,MAAA;AAAA,EAC9B;AAAA;AAAA,EAGA,yBAAwE;AACtE,UAAM,SAAwD,CAAA;AAC9D,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,cAAc;AAC5C,aAAO,GAAG,IAAI;AAAA,IAChB;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,qBAA4C;AAC1C,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,kBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,6BAA2D;AACzD,UAAM,SAAuC,CAAA;AAC7C,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK,wBAAwB;AACtD,aAAO,GAAG,IAAI;AAAA,IAChB;AACA,WAAO;AAAA,EACT;AACF;"}
@@ -1,4 +1,6 @@
1
- import type { Condition } from '../../../zero-protocol/src/ast.ts';
1
+ import type * as v from '../../../shared/src/valita.ts';
2
+ import type { Condition, Ordering } from '../../../zero-protocol/src/ast.ts';
3
+ import type { attemptStartEventJSONSchema, bestPlanSelectedEventJSONSchema, connectionSelectedEventJSONSchema, nodeConstraintEventJSONSchema, PlanDebugEventJSON, planFailedEventJSONSchema } from '../../../zero-protocol/src/analyze-query-result.ts';
2
4
  import type { PlannerConstraint } from './planner-constraint.ts';
3
5
  import type { CostEstimate, JoinType } from './planner-node.ts';
4
6
  import type { PlanState } from './planner-graph.ts';
@@ -10,11 +12,7 @@ import type { PlanState } from './planner-graph.ts';
10
12
  /**
11
13
  * Starting a new planning attempt with a different root connection.
12
14
  */
13
- export type AttemptStartEvent = {
14
- type: 'attempt-start';
15
- attemptNumber: number;
16
- totalAttempts: number;
17
- };
15
+ export type AttemptStartEvent = v.Infer<typeof attemptStartEventJSONSchema>;
18
16
  /**
19
17
  * Snapshot of connection costs before selecting the next connection.
20
18
  */
@@ -24,22 +22,16 @@ export type ConnectionCostsEvent = {
24
22
  costs: Array<{
25
23
  connection: string;
26
24
  cost: number;
27
- costEstimate: CostEstimate;
25
+ costEstimate: Omit<CostEstimate, 'fanout'>;
28
26
  pinned: boolean;
29
- constraints: Map<string, PlannerConstraint | undefined>;
30
- constraintCosts: Map<string, CostEstimate>;
27
+ constraints: Record<string, PlannerConstraint | undefined>;
28
+ constraintCosts: Record<string, Omit<CostEstimate, 'fanout'>>;
31
29
  }>;
32
30
  };
33
31
  /**
34
32
  * A connection was chosen and pinned.
35
33
  */
36
- export type ConnectionSelectedEvent = {
37
- type: 'connection-selected';
38
- attemptNumber: number;
39
- connection: string;
40
- cost: number;
41
- isRoot: boolean;
42
- };
34
+ export type ConnectionSelectedEvent = v.Infer<typeof connectionSelectedEventJSONSchema>;
43
35
  /**
44
36
  * Constraints have been propagated through the graph.
45
37
  */
@@ -48,8 +40,8 @@ export type ConstraintsPropagatedEvent = {
48
40
  attemptNumber: number;
49
41
  connectionConstraints: Array<{
50
42
  connection: string;
51
- constraints: Map<string, PlannerConstraint | undefined>;
52
- constraintCosts: Map<string, CostEstimate>;
43
+ constraints: Record<string, PlannerConstraint | undefined>;
44
+ constraintCosts: Record<string, Omit<CostEstimate, 'fanout'>>;
53
45
  }>;
54
46
  };
55
47
  /**
@@ -69,24 +61,11 @@ export type PlanCompleteEvent = {
69
61
  /**
70
62
  * Planning attempt failed (e.g., unflippable join).
71
63
  */
72
- export type PlanFailedEvent = {
73
- type: 'plan-failed';
74
- attemptNumber: number;
75
- reason: string;
76
- };
64
+ export type PlanFailedEvent = v.Infer<typeof planFailedEventJSONSchema>;
77
65
  /**
78
66
  * The best plan across all attempts was selected.
79
67
  */
80
- export type BestPlanSelectedEvent = {
81
- type: 'best-plan-selected';
82
- bestAttemptNumber: number;
83
- totalCost: number;
84
- flipPattern: number;
85
- joinStates: Array<{
86
- join: string;
87
- type: JoinType;
88
- }>;
89
- };
68
+ export type BestPlanSelectedEvent = v.Infer<typeof bestPlanSelectedEventJSONSchema>;
90
69
  /**
91
70
  * A node computed its cost estimate during planning.
92
71
  * Emitted by nodes during estimateCost() traversal.
@@ -99,8 +78,9 @@ export type NodeCostEvent = {
99
78
  node: string;
100
79
  branchPattern: number[];
101
80
  downstreamChildSelectivity: number;
102
- costEstimate: CostEstimate;
81
+ costEstimate: Omit<CostEstimate, 'fanout'>;
103
82
  filters?: Condition | undefined;
83
+ ordering?: Ordering | undefined;
104
84
  joinType?: JoinType | undefined;
105
85
  };
106
86
  /**
@@ -108,15 +88,7 @@ export type NodeCostEvent = {
108
88
  * Emitted by nodes during propagateConstraints() traversal.
109
89
  * attemptNumber is added by the debugger.
110
90
  */
111
- export type NodeConstraintEvent = {
112
- type: 'node-constraint';
113
- attemptNumber?: number;
114
- nodeType: 'connection' | 'join' | 'fan-out' | 'fan-in' | 'terminus';
115
- node: string;
116
- branchPattern: number[];
117
- constraint: PlannerConstraint | undefined;
118
- from: string;
119
- };
91
+ export type NodeConstraintEvent = v.Infer<typeof nodeConstraintEventJSONSchema>;
120
92
  /**
121
93
  * Union of all debug event types.
122
94
  */
@@ -146,4 +118,26 @@ export declare class AccumulatorDebugger implements PlanDebugger {
146
118
  */
147
119
  format(): string;
148
120
  }
121
+ /**
122
+ * Serialize an array of debug events to JSON-compatible format.
123
+ * The fanout function is already omitted when events are created.
124
+ * The planSnapshot is excluded as it's internal state not needed for debugging.
125
+ */
126
+ export declare function serializePlanDebugEvents(events: PlanDebugEvent[]): PlanDebugEventJSON[];
127
+ /**
128
+ * Format planner debug events as a human-readable string.
129
+ * Works with JSON-serialized events (from inspector API) or native events (from AccumulatorDebugger).
130
+ *
131
+ * @param events - Array of planner debug events (either JSON or native format)
132
+ * @returns Formatted string showing planning attempts, costs, and final plan selection
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const result = await inspector.analyzeQuery(query, { plannerDebug: true });
137
+ * if (result.plannerEvents) {
138
+ * console.log(formatPlannerEvents(result.plannerEvents));
139
+ * }
140
+ * ```
141
+ */
142
+ export declare function formatPlannerEvents(events: PlanDebugEventJSON[] | PlanDebugEvent[]): string;
149
143
  //# sourceMappingURL=planner-debug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"planner-debug.d.ts","sourceRoot":"","sources":["../../../../../zql/src/planner/planner-debug.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAC9D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAC;AAElD;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,eAAe,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,kBAAkB,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;QACX,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE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