convex 1.45.0 → 1.46.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 (319) hide show
  1. package/CHANGELOG.md +48 -6
  2. package/dist/browser.bundle.js +1 -1
  3. package/dist/browser.bundle.js.map +2 -2
  4. package/dist/cjs/browser/http_client.js.map +2 -2
  5. package/dist/cjs/browser/query_options.js.map +2 -2
  6. package/dist/cjs/browser/simple_client.js.map +2 -2
  7. package/dist/cjs/browser/sync/optimistic_updates.js.map +1 -1
  8. package/dist/cjs/browser/sync/optimistic_updates_impl.js.map +2 -2
  9. package/dist/cjs/cli/codegen.js +2 -0
  10. package/dist/cjs/cli/codegen.js.map +2 -2
  11. package/dist/cjs/cli/deploy.js +1 -0
  12. package/dist/cjs/cli/deploy.js.map +2 -2
  13. package/dist/cjs/cli/docs.js +3 -36
  14. package/dist/cjs/cli/docs.js.map +2 -2
  15. package/dist/cjs/cli/lib/checkForLargeIndexDeletion.js +101 -60
  16. package/dist/cjs/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
  17. package/dist/cjs/cli/lib/checkForSlowSchemaValidation.js +107 -0
  18. package/dist/cjs/cli/lib/checkForSlowSchemaValidation.js.map +7 -0
  19. package/dist/cjs/cli/lib/codegen.js.map +2 -2
  20. package/dist/cjs/cli/lib/components.js +12 -0
  21. package/dist/cjs/cli/lib/components.js.map +2 -2
  22. package/dist/cjs/cli/lib/deploy2.js +29 -2
  23. package/dist/cjs/cli/lib/deploy2.js.map +2 -2
  24. package/dist/cjs/cli/lib/deployApi/evaluateSchema.js +73 -0
  25. package/dist/cjs/cli/lib/deployApi/evaluateSchema.js.map +7 -0
  26. package/dist/cjs/cli/lib/deployApi/finishPush.js +1 -0
  27. package/dist/cjs/cli/lib/deployApi/finishPush.js.map +2 -2
  28. package/dist/cjs/cli/lib/deployApi/startPush.js +1 -1
  29. package/dist/cjs/cli/lib/deployApi/startPush.js.map +2 -2
  30. package/dist/cjs/cli/lib/dev.js +1 -0
  31. package/dist/cjs/cli/lib/dev.js.map +2 -2
  32. package/dist/cjs/cli/lib/generatedFunctionLogsApi.js.map +1 -1
  33. package/dist/cjs/cli/lib/localDeployment/run.js +30 -1
  34. package/dist/cjs/cli/lib/localDeployment/run.js.map +2 -2
  35. package/dist/cjs/cli/lib/localDeployment/upgrade.js +6 -5
  36. package/dist/cjs/cli/lib/localDeployment/upgrade.js.map +2 -2
  37. package/dist/cjs/cli/lib/localDeployment/utils.js +5 -1
  38. package/dist/cjs/cli/lib/localDeployment/utils.js.map +2 -2
  39. package/dist/cjs/cli/lib/run.js +1 -0
  40. package/dist/cjs/cli/lib/run.js.map +2 -2
  41. package/dist/cjs/cli/lib/utils/utils.js +36 -29
  42. package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
  43. package/dist/cjs/index.js +1 -1
  44. package/dist/cjs/index.js.map +1 -1
  45. package/dist/cjs/nextjs/index.js.map +2 -2
  46. package/dist/cjs/react/client.js.map +2 -2
  47. package/dist/cjs/react/hydration.js.map +2 -2
  48. package/dist/cjs/react/queries_observer.js.map +2 -2
  49. package/dist/cjs/react/use_paginated_query2.js.map +2 -2
  50. package/dist/cjs/react/use_queries.js.map +2 -2
  51. package/dist/cjs/server/api.js.map +2 -2
  52. package/dist/cjs/server/components/index.js.map +2 -2
  53. package/dist/cjs/server/cron.js +10 -10
  54. package/dist/cjs/server/cron.js.map +2 -2
  55. package/dist/cjs/server/impl/actions_impl.js.map +2 -2
  56. package/dist/cjs/server/impl/meta_impl.js +8 -2
  57. package/dist/cjs/server/impl/meta_impl.js.map +2 -2
  58. package/dist/cjs/server/impl/scheduler_impl.js.map +2 -2
  59. package/dist/cjs/server/index.js.map +2 -2
  60. package/dist/cjs/server/meta.js.map +1 -1
  61. package/dist/cjs/server/registration.js.map +1 -1
  62. package/dist/cjs/server/scheduler.js.map +1 -1
  63. package/dist/cjs/server/schema.js +50 -3
  64. package/dist/cjs/server/schema.js.map +2 -2
  65. package/dist/cjs/values/validator.js +1 -1
  66. package/dist/cjs/values/validator.js.map +2 -2
  67. package/dist/cjs/values/validators.js +81 -25
  68. package/dist/cjs/values/validators.js.map +2 -2
  69. package/dist/cjs-types/browser/http_client.d.ts +5 -5
  70. package/dist/cjs-types/browser/http_client.d.ts.map +1 -1
  71. package/dist/cjs-types/browser/query_options.d.ts +2 -2
  72. package/dist/cjs-types/browser/query_options.d.ts.map +1 -1
  73. package/dist/cjs-types/browser/simple_client.d.ts +6 -6
  74. package/dist/cjs-types/browser/simple_client.d.ts.map +1 -1
  75. package/dist/cjs-types/browser/sync/optimistic_updates.d.ts +4 -4
  76. package/dist/cjs-types/browser/sync/optimistic_updates.d.ts.map +1 -1
  77. package/dist/cjs-types/browser/sync/optimistic_updates_impl.d.ts.map +1 -1
  78. package/dist/cjs-types/cli/codegen.d.ts.map +1 -1
  79. package/dist/cjs-types/cli/docs.d.ts.map +1 -1
  80. package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts +26 -5
  81. package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
  82. package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts +14 -0
  83. package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -0
  84. package/dist/cjs-types/cli/lib/codegen.d.ts +1 -0
  85. package/dist/cjs-types/cli/lib/codegen.d.ts.map +1 -1
  86. package/dist/cjs-types/cli/lib/components.d.ts +1 -0
  87. package/dist/cjs-types/cli/lib/components.d.ts.map +1 -1
  88. package/dist/cjs-types/cli/lib/deploy2.d.ts +6 -0
  89. package/dist/cjs-types/cli/lib/deploy2.d.ts.map +1 -1
  90. package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts +453 -0
  91. package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -0
  92. package/dist/cjs-types/cli/lib/deployApi/finishPush.d.ts +1 -2
  93. package/dist/cjs-types/cli/lib/deployApi/finishPush.d.ts.map +1 -1
  94. package/dist/cjs-types/cli/lib/dev.d.ts.map +1 -1
  95. package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts +2 -0
  96. package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
  97. package/dist/cjs-types/cli/lib/localDeployment/run.d.ts +2 -0
  98. package/dist/cjs-types/cli/lib/localDeployment/run.d.ts.map +1 -1
  99. package/dist/cjs-types/cli/lib/localDeployment/upgrade.d.ts.map +1 -1
  100. package/dist/cjs-types/cli/lib/localDeployment/utils.d.ts +1 -0
  101. package/dist/cjs-types/cli/lib/localDeployment/utils.d.ts.map +1 -1
  102. package/dist/cjs-types/cli/lib/run.d.ts.map +1 -1
  103. package/dist/cjs-types/cli/lib/utils/utils.d.ts +5 -5
  104. package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
  105. package/dist/cjs-types/index.d.ts +1 -1
  106. package/dist/cjs-types/nextjs/index.d.ts +6 -6
  107. package/dist/cjs-types/nextjs/index.d.ts.map +1 -1
  108. package/dist/cjs-types/react/client.d.ts +15 -15
  109. package/dist/cjs-types/react/client.d.ts.map +1 -1
  110. package/dist/cjs-types/react/hydration.d.ts +3 -3
  111. package/dist/cjs-types/react/hydration.d.ts.map +1 -1
  112. package/dist/cjs-types/react/queries_observer.d.ts +9 -9
  113. package/dist/cjs-types/react/queries_observer.d.ts.map +1 -1
  114. package/dist/cjs-types/react/use_paginated_query2.d.ts.map +1 -1
  115. package/dist/cjs-types/react/use_queries.d.ts +14 -6
  116. package/dist/cjs-types/react/use_queries.d.ts.map +1 -1
  117. package/dist/cjs-types/server/api.d.ts +157 -7
  118. package/dist/cjs-types/server/api.d.ts.map +1 -1
  119. package/dist/cjs-types/server/components/index.d.ts +2 -2
  120. package/dist/cjs-types/server/components/index.d.ts.map +1 -1
  121. package/dist/cjs-types/server/cron.d.ts +21 -20
  122. package/dist/cjs-types/server/cron.d.ts.map +1 -1
  123. package/dist/cjs-types/server/impl/actions_impl.d.ts +4 -4
  124. package/dist/cjs-types/server/impl/actions_impl.d.ts.map +1 -1
  125. package/dist/cjs-types/server/impl/meta_impl.d.ts.map +1 -1
  126. package/dist/cjs-types/server/impl/scheduler_impl.d.ts.map +1 -1
  127. package/dist/cjs-types/server/index.d.ts +1 -1
  128. package/dist/cjs-types/server/index.d.ts.map +1 -1
  129. package/dist/cjs-types/server/meta.d.ts.map +1 -1
  130. package/dist/cjs-types/server/registration.d.ts +7 -7
  131. package/dist/cjs-types/server/registration.d.ts.map +1 -1
  132. package/dist/cjs-types/server/scheduler.d.ts +9 -7
  133. package/dist/cjs-types/server/scheduler.d.ts.map +1 -1
  134. package/dist/cjs-types/server/schema.d.ts +1 -0
  135. package/dist/cjs-types/server/schema.d.ts.map +1 -1
  136. package/dist/cjs-types/values/validator.d.ts.map +1 -1
  137. package/dist/cjs-types/values/validators.d.ts +30 -0
  138. package/dist/cjs-types/values/validators.d.ts.map +1 -1
  139. package/dist/cli.bundle.cjs +347 -133
  140. package/dist/cli.bundle.cjs.map +4 -4
  141. package/dist/esm/browser/http_client.js.map +2 -2
  142. package/dist/esm/browser/query_options.js.map +2 -2
  143. package/dist/esm/browser/simple_client.js.map +2 -2
  144. package/dist/esm/browser/sync/optimistic_updates_impl.js.map +2 -2
  145. package/dist/esm/cli/codegen.js +2 -0
  146. package/dist/esm/cli/codegen.js.map +2 -2
  147. package/dist/esm/cli/deploy.js +1 -0
  148. package/dist/esm/cli/deploy.js.map +2 -2
  149. package/dist/esm/cli/docs.js +3 -43
  150. package/dist/esm/cli/docs.js.map +2 -2
  151. package/dist/esm/cli/lib/checkForLargeIndexDeletion.js +100 -60
  152. package/dist/esm/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
  153. package/dist/esm/cli/lib/checkForSlowSchemaValidation.js +85 -0
  154. package/dist/esm/cli/lib/checkForSlowSchemaValidation.js.map +7 -0
  155. package/dist/esm/cli/lib/codegen.js.map +2 -2
  156. package/dist/esm/cli/lib/components.js +12 -0
  157. package/dist/esm/cli/lib/components.js.map +2 -2
  158. package/dist/esm/cli/lib/deploy2.js +30 -2
  159. package/dist/esm/cli/lib/deploy2.js.map +2 -2
  160. package/dist/esm/cli/lib/deployApi/evaluateSchema.js +46 -0
  161. package/dist/esm/cli/lib/deployApi/evaluateSchema.js.map +7 -0
  162. package/dist/esm/cli/lib/deployApi/finishPush.js +1 -1
  163. package/dist/esm/cli/lib/deployApi/finishPush.js.map +2 -2
  164. package/dist/esm/cli/lib/deployApi/startPush.js +1 -1
  165. package/dist/esm/cli/lib/deployApi/startPush.js.map +2 -2
  166. package/dist/esm/cli/lib/dev.js +1 -0
  167. package/dist/esm/cli/lib/dev.js.map +2 -2
  168. package/dist/esm/cli/lib/localDeployment/run.js +30 -2
  169. package/dist/esm/cli/lib/localDeployment/run.js.map +2 -2
  170. package/dist/esm/cli/lib/localDeployment/upgrade.js +4 -3
  171. package/dist/esm/cli/lib/localDeployment/upgrade.js.map +2 -2
  172. package/dist/esm/cli/lib/localDeployment/utils.js +3 -0
  173. package/dist/esm/cli/lib/localDeployment/utils.js.map +2 -2
  174. package/dist/esm/cli/lib/run.js +1 -0
  175. package/dist/esm/cli/lib/run.js.map +2 -2
  176. package/dist/esm/cli/lib/utils/utils.js +36 -30
  177. package/dist/esm/cli/lib/utils/utils.js.map +2 -2
  178. package/dist/esm/index.js +1 -1
  179. package/dist/esm/index.js.map +1 -1
  180. package/dist/esm/nextjs/index.js.map +2 -2
  181. package/dist/esm/react/client.js.map +2 -2
  182. package/dist/esm/react/hydration.js +3 -1
  183. package/dist/esm/react/hydration.js.map +2 -2
  184. package/dist/esm/react/queries_observer.js +3 -1
  185. package/dist/esm/react/queries_observer.js.map +2 -2
  186. package/dist/esm/react/use_paginated_query2.js +3 -1
  187. package/dist/esm/react/use_paginated_query2.js.map +2 -2
  188. package/dist/esm/react/use_queries.js.map +2 -2
  189. package/dist/esm/server/api.js.map +2 -2
  190. package/dist/esm/server/components/index.js.map +2 -2
  191. package/dist/esm/server/cron.js +13 -11
  192. package/dist/esm/server/cron.js.map +2 -2
  193. package/dist/esm/server/impl/actions_impl.js.map +2 -2
  194. package/dist/esm/server/impl/meta_impl.js +9 -3
  195. package/dist/esm/server/impl/meta_impl.js.map +2 -2
  196. package/dist/esm/server/impl/scheduler_impl.js.map +2 -2
  197. package/dist/esm/server/index.js.map +2 -2
  198. package/dist/esm/server/schema.js +50 -3
  199. package/dist/esm/server/schema.js.map +2 -2
  200. package/dist/esm/values/validator.js +1 -1
  201. package/dist/esm/values/validator.js.map +2 -2
  202. package/dist/esm/values/validators.js +81 -25
  203. package/dist/esm/values/validators.js.map +2 -2
  204. package/dist/esm-types/browser/http_client.d.ts +5 -5
  205. package/dist/esm-types/browser/http_client.d.ts.map +1 -1
  206. package/dist/esm-types/browser/query_options.d.ts +2 -2
  207. package/dist/esm-types/browser/query_options.d.ts.map +1 -1
  208. package/dist/esm-types/browser/simple_client.d.ts +6 -6
  209. package/dist/esm-types/browser/simple_client.d.ts.map +1 -1
  210. package/dist/esm-types/browser/sync/optimistic_updates.d.ts +4 -4
  211. package/dist/esm-types/browser/sync/optimistic_updates.d.ts.map +1 -1
  212. package/dist/esm-types/browser/sync/optimistic_updates_impl.d.ts.map +1 -1
  213. package/dist/esm-types/cli/codegen.d.ts.map +1 -1
  214. package/dist/esm-types/cli/docs.d.ts.map +1 -1
  215. package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts +26 -5
  216. package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
  217. package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts +14 -0
  218. package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -0
  219. package/dist/esm-types/cli/lib/codegen.d.ts +1 -0
  220. package/dist/esm-types/cli/lib/codegen.d.ts.map +1 -1
  221. package/dist/esm-types/cli/lib/components.d.ts +1 -0
  222. package/dist/esm-types/cli/lib/components.d.ts.map +1 -1
  223. package/dist/esm-types/cli/lib/deploy2.d.ts +6 -0
  224. package/dist/esm-types/cli/lib/deploy2.d.ts.map +1 -1
  225. package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts +453 -0
  226. package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -0
  227. package/dist/esm-types/cli/lib/deployApi/finishPush.d.ts +1 -2
  228. package/dist/esm-types/cli/lib/deployApi/finishPush.d.ts.map +1 -1
  229. package/dist/esm-types/cli/lib/dev.d.ts.map +1 -1
  230. package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts +2 -0
  231. package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
  232. package/dist/esm-types/cli/lib/localDeployment/run.d.ts +2 -0
  233. package/dist/esm-types/cli/lib/localDeployment/run.d.ts.map +1 -1
  234. package/dist/esm-types/cli/lib/localDeployment/upgrade.d.ts.map +1 -1
  235. package/dist/esm-types/cli/lib/localDeployment/utils.d.ts +1 -0
  236. package/dist/esm-types/cli/lib/localDeployment/utils.d.ts.map +1 -1
  237. package/dist/esm-types/cli/lib/run.d.ts.map +1 -1
  238. package/dist/esm-types/cli/lib/utils/utils.d.ts +5 -5
  239. package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
  240. package/dist/esm-types/index.d.ts +1 -1
  241. package/dist/esm-types/nextjs/index.d.ts +6 -6
  242. package/dist/esm-types/nextjs/index.d.ts.map +1 -1
  243. package/dist/esm-types/react/client.d.ts +15 -15
  244. package/dist/esm-types/react/client.d.ts.map +1 -1
  245. package/dist/esm-types/react/hydration.d.ts +3 -3
  246. package/dist/esm-types/react/hydration.d.ts.map +1 -1
  247. package/dist/esm-types/react/queries_observer.d.ts +9 -9
  248. package/dist/esm-types/react/queries_observer.d.ts.map +1 -1
  249. package/dist/esm-types/react/use_paginated_query2.d.ts.map +1 -1
  250. package/dist/esm-types/react/use_queries.d.ts +14 -6
  251. package/dist/esm-types/react/use_queries.d.ts.map +1 -1
  252. package/dist/esm-types/server/api.d.ts +157 -7
  253. package/dist/esm-types/server/api.d.ts.map +1 -1
  254. package/dist/esm-types/server/components/index.d.ts +2 -2
  255. package/dist/esm-types/server/components/index.d.ts.map +1 -1
  256. package/dist/esm-types/server/cron.d.ts +21 -20
  257. package/dist/esm-types/server/cron.d.ts.map +1 -1
  258. package/dist/esm-types/server/impl/actions_impl.d.ts +4 -4
  259. package/dist/esm-types/server/impl/actions_impl.d.ts.map +1 -1
  260. package/dist/esm-types/server/impl/meta_impl.d.ts.map +1 -1
  261. package/dist/esm-types/server/impl/scheduler_impl.d.ts.map +1 -1
  262. package/dist/esm-types/server/index.d.ts +1 -1
  263. package/dist/esm-types/server/index.d.ts.map +1 -1
  264. package/dist/esm-types/server/meta.d.ts.map +1 -1
  265. package/dist/esm-types/server/registration.d.ts +7 -7
  266. package/dist/esm-types/server/registration.d.ts.map +1 -1
  267. package/dist/esm-types/server/scheduler.d.ts +9 -7
  268. package/dist/esm-types/server/scheduler.d.ts.map +1 -1
  269. package/dist/esm-types/server/schema.d.ts +1 -0
  270. package/dist/esm-types/server/schema.d.ts.map +1 -1
  271. package/dist/esm-types/values/validator.d.ts.map +1 -1
  272. package/dist/esm-types/values/validators.d.ts +30 -0
  273. package/dist/esm-types/values/validators.d.ts.map +1 -1
  274. package/dist/react.bundle.js +1 -1
  275. package/dist/react.bundle.js.map +2 -2
  276. package/package.json +5 -5
  277. package/src/browser/http_client.ts +43 -10
  278. package/src/browser/query_options.ts +11 -5
  279. package/src/browser/simple_client.ts +35 -14
  280. package/src/browser/sync/optimistic_updates.ts +17 -4
  281. package/src/browser/sync/optimistic_updates_impl.ts +17 -4
  282. package/src/cli/codegen.ts +1 -0
  283. package/src/cli/deploy.ts +1 -0
  284. package/src/cli/docs.ts +3 -44
  285. package/src/cli/lib/checkForLargeIndexDeletion.ts +154 -82
  286. package/src/cli/lib/checkForSlowSchemaValidation.ts +130 -0
  287. package/src/cli/lib/codegen.ts +1 -0
  288. package/src/cli/lib/components.ts +17 -0
  289. package/src/cli/lib/deploy2.ts +56 -1
  290. package/src/cli/lib/deployApi/evaluateSchema.ts +62 -0
  291. package/src/cli/lib/deployApi/finishPush.ts +1 -1
  292. package/src/cli/lib/deployApi/startPush.ts +1 -1
  293. package/src/cli/lib/dev.ts +1 -0
  294. package/src/cli/lib/generatedFunctionLogsApi.ts +2 -0
  295. package/src/cli/lib/localDeployment/run.ts +44 -2
  296. package/src/cli/lib/localDeployment/upgrade.ts +4 -6
  297. package/src/cli/lib/localDeployment/utils.ts +6 -0
  298. package/src/cli/lib/run.ts +1 -0
  299. package/src/cli/lib/utils/utils.ts +63 -35
  300. package/src/index.ts +1 -1
  301. package/src/nextjs/index.ts +19 -8
  302. package/src/react/client.ts +73 -30
  303. package/src/react/hydration.tsx +14 -6
  304. package/src/react/queries_observer.ts +19 -16
  305. package/src/react/use_paginated_query2.ts +10 -6
  306. package/src/react/use_queries.ts +23 -7
  307. package/src/server/api.ts +220 -14
  308. package/src/server/components/index.ts +4 -6
  309. package/src/server/cron.ts +34 -24
  310. package/src/server/impl/actions_impl.ts +13 -4
  311. package/src/server/impl/meta_impl.ts +8 -1
  312. package/src/server/impl/scheduler_impl.ts +13 -6
  313. package/src/server/index.ts +1 -0
  314. package/src/server/meta.ts +25 -0
  315. package/src/server/registration.ts +28 -7
  316. package/src/server/scheduler.ts +22 -7
  317. package/src/server/schema.ts +55 -0
  318. package/src/values/validator.ts +3 -1
  319. package/src/values/validators.ts +84 -26
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/react/client.ts"],
4
- "sourcesContent": ["import { BaseConvexClient } from \"../browser/index.js\";\nimport type {\n OptimisticUpdate,\n PaginatedQueryToken,\n QueryToken,\n PaginationStatus,\n} from \"../browser/index.js\";\nimport React, { useCallback, useContext, useMemo } from \"react\";\nimport { convexToJson, Value } from \"../values/index.js\";\nimport { QueryJournal } from \"../browser/sync/protocol.js\";\nimport {\n AuthTokenFetcher,\n BaseConvexClientOptions,\n ConnectionState,\n BaseConvexClientInterface,\n} from \"../browser/sync/client.js\";\nimport type { UserIdentityAttributes } from \"../browser/sync/protocol.js\";\nimport { RequestForQueries, useQueries } from \"./use_queries.js\";\nimport { useSubscription } from \"./use_subscription.js\";\nimport { parseArgs } from \"../common/index.js\";\nimport {\n ArgsAndOptions,\n FunctionArgs,\n FunctionReference,\n FunctionReturnType,\n OptionalRestArgs,\n getFunctionName,\n makeFunctionReference,\n} from \"../server/api.js\";\nimport { EmptyObject } from \"../server/registration.js\";\nimport {\n instantiateDefaultLogger,\n instantiateNoopLogger,\n Logger,\n} from \"../browser/logging.js\";\nimport type { QueryOptions } from \"../browser/query_options.js\";\nimport { LoadMoreOfPaginatedQuery } from \"../browser/sync/pagination.js\";\nimport {\n PaginatedQueryClient,\n ExtendedTransition,\n} from \"../browser/sync/paginated_query_client.js\";\n\n// When no arguments are passed, extend subscriptions (for APIs that do this by default)\n// for this amount after the subscription would otherwise be dropped.\nconst DEFAULT_EXTEND_SUBSCRIPTION_FOR = 5_000;\n\nif (typeof React === \"undefined\") {\n throw new Error(\"Required dependency 'react' not found\");\n}\n\n// TODO Typedoc doesn't generate documentation for the comment below perhaps\n// because it's a callable interface.\n/**\n * An interface to execute a Convex mutation function on the server.\n *\n * @public\n */\nexport interface ReactMutation<Mutation extends FunctionReference<\"mutation\">> {\n /**\n * Execute the mutation on the server, returning a `Promise` of its return value.\n *\n * @param args - Arguments for the mutation to pass up to the server.\n * @returns The return value of the server-side function call.\n */\n (...args: OptionalRestArgs<Mutation>): Promise<FunctionReturnType<Mutation>>;\n\n /**\n * Define an optimistic update to apply as part of this mutation.\n *\n * This is a temporary update to the local query results to facilitate a\n * fast, interactive UI. It enables query results to update before a mutation\n * executed on the server.\n *\n * When the mutation is invoked, the optimistic update will be applied.\n *\n * Optimistic updates can also be used to temporarily remove queries from the\n * client and create loading experiences until a mutation completes and the\n * new query results are synced.\n *\n * The update will be automatically rolled back when the mutation is fully\n * completed and queries have been updated.\n *\n * @param optimisticUpdate - The optimistic update to apply.\n * @returns A new `ReactMutation` with the update configured.\n *\n * @public\n */\n withOptimisticUpdate<T extends OptimisticUpdate<FunctionArgs<Mutation>>>(\n optimisticUpdate: T &\n (ReturnType<T> extends Promise<any>\n ? \"Optimistic update handlers must be synchronous\"\n : {}),\n ): ReactMutation<Mutation>;\n}\n\n// Exported only for testing.\nexport function createMutation(\n mutationReference: FunctionReference<\"mutation\">,\n client: ConvexReactClient,\n update?: OptimisticUpdate<any>,\n): ReactMutation<any> {\n function mutation(args?: Record<string, Value>): Promise<unknown> {\n assertNotAccidentalArgument(args);\n\n return client.mutation(mutationReference, args, {\n optimisticUpdate: update,\n });\n }\n mutation.withOptimisticUpdate = function withOptimisticUpdate(\n optimisticUpdate: OptimisticUpdate<any>,\n ): ReactMutation<any> {\n if (update !== undefined) {\n throw new Error(\n `Already specified optimistic update for mutation ${getFunctionName(\n mutationReference,\n )}`,\n );\n }\n return createMutation(mutationReference, client, optimisticUpdate);\n };\n return mutation as ReactMutation<any>;\n}\n\n/**\n * An interface to execute a Convex action on the server.\n *\n * @public\n */\nexport interface ReactAction<Action extends FunctionReference<\"action\">> {\n /**\n * Execute the function on the server, returning a `Promise` of its return value.\n *\n * @param args - Arguments for the function to pass up to the server.\n * @returns The return value of the server-side function call.\n * @public\n */\n (...args: OptionalRestArgs<Action>): Promise<FunctionReturnType<Action>>;\n}\n\nfunction createAction(\n actionReference: FunctionReference<\"action\">,\n client: ConvexReactClient,\n): ReactAction<any> {\n return function (args?: Record<string, Value>): Promise<unknown> {\n return client.action(actionReference, args);\n } as ReactAction<any>;\n}\n\n// Watches should be stateless: in QueriesObserver we create a watch just to get\n// the current value.\n/**\n * A watch on the output of a Convex query function.\n *\n * @public\n */\nexport interface Watch<T> {\n /**\n * Initiate a watch on the output of a query.\n *\n * This will subscribe to this query and call\n * the callback whenever the query result changes.\n *\n * **Important: If the client is already subscribed to this query with the\n * same arguments this callback will not be invoked until the query result is\n * updated.** To get the current, local result call\n * {@link react.Watch.localQueryResult}.\n *\n * @param callback - Function that is called whenever the query result changes.\n * @returns - A function that disposes of the subscription.\n */\n onUpdate(callback: () => void): () => void;\n\n /**\n * Get the current result of a query.\n *\n * This will only return a result if we're already subscribed to the query\n * and have received a result from the server or the query value has been set\n * optimistically.\n *\n * @returns The result of the query or `undefined` if it isn't known.\n * @throws An error if the query encountered an error on the server.\n */\n localQueryResult(): T | undefined;\n\n /**\n * @internal\n */\n localQueryLogs(): string[] | undefined;\n\n /**\n * Get the current {@link browser.QueryJournal} for this query.\n *\n * If we have not yet received a result for this query, this will be `undefined`.\n */\n journal(): QueryJournal | undefined;\n}\n\n/**\n * A watch on the output of a paginated Convex query function.\n *\n * @public\n */\nexport interface PaginatedWatch<T> {\n /**\n * Initiate a watch on the output of a paginated query.\n *\n * This will subscribe to this query and call\n * the callback whenever the query result changes.\n *\n * @param callback - Function that is called whenever the query result changes.\n * @returns - A function that disposes of the subscription.\n */\n onUpdate(callback: () => void): () => void;\n\n /**\n * Get the current result of a paginated query.\n *\n * @returns The current results, status, and loadMore function, or `undefined` if not loaded.\n */\n localQueryResult():\n | {\n results: T[];\n status: PaginationStatus;\n loadMore: LoadMoreOfPaginatedQuery;\n }\n | undefined;\n}\n\n/**\n * Options for {@link ConvexReactClient.watchQuery}.\n *\n * @public\n */\nexport interface WatchQueryOptions {\n /**\n * An (optional) journal produced from a previous execution of this query\n * function.\n *\n * If there is an existing subscription to a query function with the same\n * name and arguments, this journal will have no effect.\n */\n journal?: QueryJournal;\n\n /**\n * @internal\n */\n componentPath?: string;\n}\n\n/**\n * Options for {@link ConvexReactClient.watchPaginatedQuery}.\n *\n * @internal\n */\nexport interface WatchPaginatedQueryOptions {\n /**\n * The initial number of items to load.\n */\n initialNumItems: number;\n\n // We may be able to remove this in the future, but to preserve the existing behavior of\n // usePaginatedQuery() it's still here.\n id: number;\n\n /**\n * @internal\n */\n componentPath?: string;\n}\n\n/**\n * Options for {@link ConvexReactClient.mutation}.\n *\n * @public\n */\nexport interface MutationOptions<Args extends Record<string, Value>> {\n /**\n * An optimistic update to apply along with this mutation.\n *\n * An optimistic update locally updates queries while a mutation is pending.\n * Once the mutation completes, the update will be rolled back.\n */\n optimisticUpdate?: OptimisticUpdate<Args> | undefined;\n}\n\n/**\n * Options for {@link ConvexReactClient}.\n *\n * @public\n */\nexport interface ConvexReactClientOptions extends BaseConvexClientOptions {\n /**\n * An already-constructed {@link BaseConvexClient} to use instead of\n * constructing one internally. When provided, this client (and its\n * derived {@link PaginatedQueryClient}) is used for all operations.\n *\n * @internal\n */\n baseClient?: BaseConvexClientInterface;\n\n // FIXME: Ideally we define `ConvexReactClientOptions` as\n // `type ConvexReactClientOptions = BaseConvexClientOptions | { baseClient: BaseConvexClient }`\n // so that callers won\u2019t try to set `BaseConvexClientOptions` attributes that are ineffective.\n // But since `baseClient` is internal at the moment, I don\u2019t think we can do that.\n // We can fix this if we ever make `baseClient` public.\n}\n\n/**\n * A Convex client for use within React.\n *\n * This loads reactive queries and executes mutations over a WebSocket.\n *\n * @public\n */\nexport class ConvexReactClient {\n private address: string;\n private cachedSync?: BaseConvexClientInterface | undefined;\n private cachedPaginatedQueryClient?: PaginatedQueryClient | undefined;\n private listeners: Map<QueryToken | PaginatedQueryToken, Set<() => void>>;\n private options: ConvexReactClientOptions;\n // \"closed\" means this client is done, not just that the underlying WS connection is closed.\n private closed = false;\n private _logger: Logger;\n\n private adminAuth?: string;\n private fakeUserIdentity?: UserIdentityAttributes | undefined;\n\n /**\n * @param address - The url of your Convex deployment, often provided\n * by an environment variable. E.g. `https://small-mouse-123.convex.cloud`.\n * @param options - See {@link ConvexReactClientOptions} for a full description.\n */\n constructor(address: string, options?: ConvexReactClientOptions) {\n // Validate address immediately since validation by the lazily-instantiated\n // internal client does not occur synchronously.\n if (address === undefined) {\n throw new Error(\n \"No address provided to ConvexReactClient.\\n\" +\n \"If trying to deploy to production, make sure to follow all the instructions found at https://docs.convex.dev/production/hosting/\\n\" +\n \"If running locally, make sure to run `convex dev` and ensure the .env.local file is populated.\",\n );\n }\n if (typeof address !== \"string\") {\n throw new Error(\n `ConvexReactClient requires a URL like 'https://happy-otter-123.convex.cloud', received something of type ${typeof address} instead.`,\n );\n }\n if (!address.includes(\"://\")) {\n throw new Error(\"Provided address was not an absolute URL.\");\n }\n this.address = address;\n this.listeners = new Map();\n this._logger =\n options?.logger === false\n ? instantiateNoopLogger({ verbose: options?.verbose ?? false })\n : options?.logger !== true && options?.logger\n ? options.logger\n : instantiateDefaultLogger({ verbose: options?.verbose ?? false });\n this.options = { ...options, logger: this._logger };\n }\n\n /**\n * Return the address for this client, useful for creating a new client.\n *\n * Not guaranteed to match the address with which this client was constructed:\n * it may be canonicalized.\n */\n get url() {\n return this.address;\n }\n\n /**\n * Lazily instantiate the `BaseConvexClient` so we don't create the WebSocket\n * when server-side rendering.\n *\n * @internal\n */\n get sync() {\n if (this.closed) {\n throw new Error(\"ConvexReactClient has already been closed.\");\n }\n if (this.cachedSync) {\n return this.cachedSync;\n }\n // BaseConvexClient and paginated query client are always created together.\n this.cachedSync =\n this.options.baseClient ??\n new BaseConvexClient(\n this.address,\n () => {}, // Use the PaginatedQueryClient's transition instead.\n this.options,\n );\n if (this.adminAuth) {\n this.cachedSync.setAdminAuth(this.adminAuth, this.fakeUserIdentity);\n }\n this.cachedPaginatedQueryClient = new PaginatedQueryClient(\n this.cachedSync,\n (transition) => this.handleTransition(transition),\n );\n return this.cachedSync;\n }\n\n /**\n * Lazily instantiate the `PaginatedQueryClient` so we don't create it\n * when server-side rendering.\n *\n * @internal\n */\n get paginatedQueryClient() {\n // access sync to instantiate the clients\n this.sync;\n if (this.cachedPaginatedQueryClient) {\n return this.cachedPaginatedQueryClient;\n }\n throw new Error(\"Should already be instantiated\");\n }\n\n /**\n * Set the authentication token to be used for subsequent queries and mutations.\n * `fetchToken` will be called automatically again if a token expires.\n * `fetchToken` should return `null` if the token cannot be retrieved, for example\n * when the user's rights were permanently revoked.\n * @param fetchToken - an async function returning the JWT-encoded OpenID Connect Identity Token\n * @param onChange - a callback that will be called when the authentication status changes\n * @param onRefreshChange - a callback called with `true` when the socket is paused to fetch a replacement token after a server rejection, and `false` when refresh completes\n */\n setAuth(\n fetchToken: AuthTokenFetcher,\n onChange?: (isAuthenticated: boolean) => void,\n onRefreshChange?: (isRefreshing: boolean) => void,\n ) {\n if (typeof fetchToken === \"string\") {\n throw new Error(\n \"Passing a string to ConvexReactClient.setAuth is no longer supported, \" +\n \"please upgrade to passing in an async function to handle reauthentication.\",\n );\n }\n this.sync.setAuth(\n fetchToken,\n onChange ??\n (() => {\n // Do nothing\n }),\n onRefreshChange,\n );\n }\n\n /**\n * Clear the current authentication token if set.\n */\n clearAuth() {\n this.sync.clearAuth();\n }\n\n /**\n * @internal\n */\n setAdminAuth(token: string, identity?: UserIdentityAttributes) {\n this.adminAuth = token;\n this.fakeUserIdentity = identity;\n if (this.closed) {\n throw new Error(\"ConvexReactClient has already been closed.\");\n }\n if (this.cachedSync) {\n this.sync.setAdminAuth(token, identity);\n }\n }\n\n /**\n * Construct a new {@link Watch} on a Convex query function.\n *\n * **Most application code should not call this method directly. Instead use\n * the {@link useQuery} hook.**\n *\n * The act of creating a watch does nothing, a Watch is stateless.\n *\n * @param query - A {@link server.FunctionReference} for the public query to run.\n * @param args - An arguments object for the query. If this is omitted,\n * the arguments will be `{}`.\n * @param options - A {@link WatchQueryOptions} options object for this query.\n *\n * @returns The {@link Watch} object.\n */\n watchQuery<Query extends FunctionReference<\"query\">>(\n query: Query,\n ...argsAndOptions: ArgsAndOptions<Query, WatchQueryOptions>\n ): Watch<FunctionReturnType<Query>> {\n const [args, options] = argsAndOptions;\n const name = getFunctionName(query);\n\n return {\n onUpdate: (callback) => {\n const { queryToken, unsubscribe } = this.sync.subscribe(\n name as string,\n args,\n options,\n );\n\n const currentListeners = this.listeners.get(queryToken);\n if (currentListeners !== undefined) {\n currentListeners.add(callback);\n } else {\n this.listeners.set(queryToken, new Set([callback]));\n }\n\n return () => {\n if (this.closed) {\n return;\n }\n\n const currentListeners = this.listeners.get(queryToken)!;\n currentListeners.delete(callback);\n if (currentListeners.size === 0) {\n this.listeners.delete(queryToken);\n }\n unsubscribe();\n };\n },\n\n localQueryResult: () => {\n // Use the cached client because we can't have a query result if we don't\n // even have a client yet!\n if (this.cachedSync) {\n return this.cachedSync.localQueryResult(name, args);\n }\n return undefined;\n },\n\n localQueryLogs: () => {\n if (this.cachedSync) {\n return this.cachedSync.localQueryLogs(name, args);\n }\n return undefined;\n },\n\n journal: () => {\n if (this.cachedSync) {\n return this.cachedSync.queryJournal(name, args);\n }\n return undefined;\n },\n };\n }\n\n // Let's try out a queryOptions-style API.\n // This method is similar to the React Query API `queryClient.prefetchQuery()`.\n // In the future an ensureQueryData(): Promise<Data> method could exist.\n /**\n * Indicates likely future interest in a query subscription.\n *\n * The implementation currently immediately subscribes to a query. In the future this method\n * may prioritize some queries over others, fetch the query result without subscribing, or\n * do nothing in slow network connections or high load scenarios.\n *\n * To use this in a React component, call useQuery() and ignore the return value.\n *\n * @param queryOptions - A query (function reference from an api object) and its args, plus\n * an optional extendSubscriptionFor for how long to subscribe to the query.\n */\n prewarmQuery<Query extends FunctionReference<\"query\">>(\n queryOptions: QueryOptions<Query> & { extendSubscriptionFor?: number },\n ) {\n const extendSubscriptionFor =\n queryOptions.extendSubscriptionFor ?? DEFAULT_EXTEND_SUBSCRIPTION_FOR;\n const watch = this.watchQuery(queryOptions.query, queryOptions.args || {});\n const unsubscribe = watch.onUpdate(() => {});\n setTimeout(unsubscribe, extendSubscriptionFor);\n }\n\n /**\n * Construct a new {@link PaginatedWatch} on a Convex paginated query function.\n *\n * **Most application code should not call this method directly. Instead use\n * the {@link usePaginatedQuery} hook.**\n *\n * The act of creating a watch does nothing, a Watch is stateless.\n *\n * @param query - A {@link server.FunctionReference} for the public query to run.\n * @param args - An arguments object for the query. If this is omitted,\n * the arguments will be `{}`.\n * @param options - A {@link WatchPaginatedQueryOptions} options object for this query.\n *\n * @returns The {@link PaginatedWatch} object.\n *\n * @internal\n */\n watchPaginatedQuery<Query extends FunctionReference<\"query\">>(\n query: Query,\n args: Query[\"_args\"],\n options: WatchPaginatedQueryOptions,\n ): PaginatedWatch<FunctionReturnType<Query>> {\n const name = getFunctionName(query);\n\n return {\n onUpdate: (callback) => {\n const { paginatedQueryToken, unsubscribe } =\n this.paginatedQueryClient.subscribe(name, args || {}, options);\n\n const currentListeners = this.listeners.get(paginatedQueryToken);\n if (currentListeners !== undefined) {\n currentListeners.add(callback);\n } else {\n this.listeners.set(paginatedQueryToken, new Set([callback]));\n }\n\n return () => {\n if (this.closed) {\n return;\n }\n\n const currentListeners = this.listeners.get(paginatedQueryToken)!;\n currentListeners.delete(callback);\n if (currentListeners.size === 0) {\n this.listeners.delete(paginatedQueryToken);\n }\n unsubscribe();\n };\n },\n\n localQueryResult: () => {\n // Use our new paginated query client\n return this.paginatedQueryClient.localQueryResult(name, args, options);\n },\n };\n }\n\n /**\n * Execute a mutation function.\n *\n * @param mutation - A {@link server.FunctionReference} for the public mutation\n * to run.\n * @param args - An arguments object for the mutation. If this is omitted,\n * the arguments will be `{}`.\n * @param options - A {@link MutationOptions} options object for the mutation.\n * @returns A promise of the mutation's result.\n */\n mutation<Mutation extends FunctionReference<\"mutation\">>(\n mutation: Mutation,\n ...argsAndOptions: ArgsAndOptions<\n Mutation,\n MutationOptions<FunctionArgs<Mutation>>\n >\n ): Promise<FunctionReturnType<Mutation>> {\n const [args, options] = argsAndOptions;\n const name = getFunctionName(mutation);\n return this.sync.mutation(name, args, options);\n }\n\n /**\n * Execute an action function.\n *\n * @param action - A {@link server.FunctionReference} for the public action\n * to run.\n * @param args - An arguments object for the action. If this is omitted,\n * the arguments will be `{}`.\n * @returns A promise of the action's result.\n */\n action<Action extends FunctionReference<\"action\">>(\n action: Action,\n ...args: OptionalRestArgs<Action>\n ): Promise<FunctionReturnType<Action>> {\n const name = getFunctionName(action);\n return this.sync.action(name, ...args);\n }\n\n /**\n * Fetch a query result once.\n *\n * **Most application code should subscribe to queries instead, using\n * the {@link useQuery} hook.**\n *\n * @param query - A {@link server.FunctionReference} for the public query\n * to run.\n * @param args - An arguments object for the query. If this is omitted,\n * the arguments will be `{}`.\n * @returns A promise of the query's result.\n */\n query<Query extends FunctionReference<\"query\">>(\n query: Query,\n ...args: OptionalRestArgs<Query>\n ): Promise<FunctionReturnType<Query>> {\n const watch = this.watchQuery(query, ...args);\n const existingResult = watch.localQueryResult();\n if (existingResult !== undefined) {\n return Promise.resolve(existingResult);\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = watch.onUpdate(() => {\n unsubscribe();\n try {\n resolve(watch.localQueryResult());\n } catch (e) {\n reject(e);\n }\n });\n });\n }\n\n /**\n * Get the current {@link ConnectionState} between the client and the Convex\n * backend.\n *\n * @returns The {@link ConnectionState} with the Convex backend.\n */\n connectionState(): ConnectionState {\n return this.sync.connectionState();\n }\n\n /**\n * Subscribe to the {@link ConnectionState} between the client and the Convex\n * backend, calling a callback each time it changes.\n *\n * Subscribed callbacks will be called when any part of ConnectionState changes.\n * ConnectionState may grow in future versions (e.g. to provide a array of\n * inflight requests) in which case callbacks would be called more frequently.\n * ConnectionState may also *lose* properties in future versions as we figure\n * out what information is most useful. As such this API is considered unstable.\n *\n * @returns An unsubscribe function to stop listening.\n */\n subscribeToConnectionState(\n cb: (connectionState: ConnectionState) => void,\n ): () => void {\n return this.sync.subscribeToConnectionState(cb);\n }\n\n /**\n * Get the logger for this client.\n *\n * @returns The {@link Logger} for this client.\n */\n get logger(): Logger {\n return this._logger;\n }\n\n /**\n * Close any network handles associated with this client and stop all subscriptions.\n *\n * Call this method when you're done with a {@link ConvexReactClient} to\n * dispose of its sockets and resources.\n *\n * @returns A `Promise` fulfilled when the connection has been completely closed.\n */\n async close(): Promise<void> {\n this.closed = true;\n // Prevent outstanding React batched updates from invoking listeners.\n this.listeners = new Map();\n if (this.cachedPaginatedQueryClient) {\n this.cachedPaginatedQueryClient = undefined;\n }\n if (this.cachedSync) {\n const sync = this.cachedSync;\n this.cachedSync = undefined;\n await sync.close();\n }\n }\n\n /**\n * Handle transitions from both base client and paginated client.\n * This ensures all transitions are processed synchronously and in order.\n */\n private handleTransition(transition: ExtendedTransition) {\n const simple = transition.queries.map((q) => q.token);\n const paginated = transition.paginatedQueries.map((q) => q.token);\n this.transition([...simple, ...paginated]);\n }\n\n private transition(updatedQueries: (QueryToken | PaginatedQueryToken)[]) {\n for (const queryToken of updatedQueries) {\n const callbacks = this.listeners.get(queryToken);\n if (callbacks) {\n for (const callback of callbacks) {\n callback();\n }\n }\n }\n }\n}\n\nconst ConvexContext = React.createContext<ConvexReactClient>(\n undefined as unknown as ConvexReactClient, // in the future this will be a mocked client for testing\n);\n\n/**\n * Get the {@link ConvexReactClient} within a React component.\n *\n * This relies on the {@link ConvexProvider} being above in the React component tree.\n *\n * @returns The active {@link ConvexReactClient} object, or `undefined`.\n *\n * @public\n */\nexport function useConvex(): ConvexReactClient {\n return useContext(ConvexContext);\n}\n\n/**\n * Provides an active Convex {@link ConvexReactClient} to descendants of this component.\n *\n * Wrap your app in this component to use Convex hooks `useQuery`,\n * `useMutation`, and `useConvex`.\n *\n * @param props - an object with a `client` property that refers to a {@link ConvexReactClient}.\n *\n * @public\n */\nexport const ConvexProvider: React.FC<{\n client: ConvexReactClient;\n children?: React.ReactNode;\n}> = ({ client, children }) => {\n return React.createElement(\n ConvexContext.Provider,\n { value: client },\n children,\n );\n};\n\nexport type OptionalRestArgsOrSkip<FuncRef extends FunctionReference<any>> =\n FuncRef[\"_args\"] extends EmptyObject\n ? [args?: EmptyObject | \"skip\"]\n : [args: FuncRef[\"_args\"] | \"skip\"];\n\n/**\n * Result returned by object-form {@link useQuery_experimental}.\n *\n * @public\n */\nexport type UseQueryResult<QueryResult, ThrowOnError extends boolean = false> =\n | { status: \"pending\" }\n | { status: \"success\"; data: QueryResult }\n | (ThrowOnError extends true ? never : { status: \"error\"; error: Error });\n\ntype UseQueryOptions<\n Query extends FunctionReference<\"query\">,\n ThrowOnError extends boolean,\n> = {\n query: Query;\n args: FunctionArgs<Query> | \"skip\";\n throwOnError?: ThrowOnError;\n};\n\n/**\n * Load a reactive query within a React component.\n *\n * This React hook subscribes to a Convex query and causes a rerender whenever\n * the query result changes. The subscription is managed automatically --\n * it starts when the component mounts and stops when it unmounts.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @example\n * ```tsx\n * import { useQuery } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function TaskList() {\n * // Reactively loads tasks, re-renders when data changes:\n * const tasks = useQuery(api.tasks.list, { completed: false });\n *\n * // Returns `undefined` while loading:\n * if (tasks === undefined) return <div>Loading...</div>;\n *\n * return tasks.map((task) => <div key={task._id}>{task.text}</div>);\n * }\n *\n * // Pass \"skip\" to conditionally disable the query:\n * function MaybeProfile({ userId }: { userId?: Id<\"users\"> }) {\n * const profile = useQuery(\n * api.users.get,\n * userId ? { userId } : \"skip\",\n * );\n * // ...\n * }\n * ```\n *\n * @param query - a {@link server.FunctionReference} for the public query to run\n * like `api.dir1.dir2.filename.func`.\n * @param args - The arguments to the query function or the string `\"skip\"` if the\n * query should not be loaded.\n * @returns the result of the query. Returns `undefined` while loading.\n *\n * @see https://docs.convex.dev/client/react#fetching-data\n * @public\n */\nexport function useQuery<Query extends FunctionReference<\"query\">>(\n query: Query,\n ...args: OptionalRestArgsOrSkip<Query>\n): Query[\"_returnType\"] | undefined {\n const skip = args[0] === \"skip\";\n const argsObject = args[0] === \"skip\" ? {} : parseArgs(args[0]);\n const queryReference =\n typeof query === \"string\"\n ? makeFunctionReference<\"query\", any, any>(query)\n : query;\n\n const queryName = getFunctionName(queryReference);\n\n const queries = useMemo(\n () =>\n skip\n ? ({} as RequestForQueries)\n : { query: { query: queryReference, args: argsObject } },\n // Stringify args so args that are semantically the same don't trigger a\n // rerender. Saves developers from adding `useMemo` on every args usage.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(convexToJson(argsObject)), queryName, skip],\n );\n\n const results = useQueries(queries);\n const result = results[\"query\"];\n\n if (result instanceof Error) {\n throw result;\n }\n return result;\n}\n\n/**\n * Load a reactive query within a React component using an options object.\n *\n * This is an experimental form of {@link useQuery} that accepts a single\n * {@link UseQueryOptions} object instead of positional arguments.\n *\n * Consumers are expected to check the returned object `status` field to\n * make proper use of the result. If an error occurs, it will be present\n * in the result object unless `throwOnError` is `true`, in which case\n * the error will be thrown instead.\n *\n * @example\n * ```tsx\n * import { useQuery_experimental as useQuery } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function TaskList() {\n * const state = useQuery({ query: api.tasks.list, args: { completed: false } });\n *\n * if (state.status === \"pending\") return <div>Loading...</div>;\n * if (state.status === \"error\") return <div>Error: {state.error.message}</div>;\n * return state.data.map((task) => <div key={task._id}>{task.text}</div>);\n * }\n * ```\n *\n * @param options - Query options. Pass `args: \"skip\"` to disable the query.\n * @returns the current query state as a {@link UseQueryResult} object.\n *\n * @see https://docs.convex.dev/client/react#fetching-data\n * @public\n */\nexport function useQuery_experimental<\n Query extends FunctionReference<\"query\">,\n ThrowOnError extends boolean = false,\n>(\n options: UseQueryOptions<Query, ThrowOnError>,\n): UseQueryResult<Query[\"_returnType\"], ThrowOnError>;\n\nexport function useQuery_experimental<\n Query extends FunctionReference<\"query\">,\n ThrowOnError extends boolean = false,\n>(\n options: UseQueryOptions<Query, ThrowOnError>,\n): UseQueryResult<Query[\"_returnType\"], false> {\n const throwOnError = options.throwOnError ?? false;\n const queryReference =\n typeof options.query === \"string\"\n ? (makeFunctionReference<\"query\", any, any>(options.query) as Query)\n : options.query;\n const skip = options.args === \"skip\";\n const argsObject = !skip\n ? parseArgs(options.args as Record<string, Value>)\n : {};\n\n const queryName = getFunctionName(queryReference);\n const queries = useMemo(\n () =>\n skip\n ? ({} as RequestForQueries)\n : { query: { query: queryReference, args: argsObject } },\n // Stringify args so args that are semantically the same don't trigger a\n // rerender. Saves developers from adding `useMemo` on every args usage.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(convexToJson(argsObject)), queryName, skip],\n );\n\n const results = useQueries(queries);\n const result = results[\"query\"];\n\n if (result instanceof Error) {\n if (throwOnError) {\n throw result;\n }\n return {\n error: result,\n status: \"error\",\n };\n }\n\n if (result === undefined) {\n return {\n status: \"pending\",\n };\n }\n\n return {\n data: result,\n status: \"success\",\n };\n}\n\n/**\n * Construct a new {@link ReactMutation}.\n *\n * Returns a function that you can call to execute a Convex mutation. The\n * returned function is stable across renders (same reference identity), so\n * it can be safely used in dependency arrays and memoization.\n *\n * Mutations can optionally be configured with\n * [optimistic updates](https://docs.convex.dev/client/react/optimistic-updates)\n * for instant UI feedback.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @example\n * ```tsx\n * import { useMutation } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function CreateTask() {\n * const createTask = useMutation(api.tasks.create);\n *\n * const handleClick = async () => {\n * await createTask({ text: \"New task\" });\n * };\n *\n * return <button onClick={handleClick}>Add Task</button>;\n * }\n * ```\n *\n * @param mutation - A {@link server.FunctionReference} for the public mutation\n * to run like `api.dir1.dir2.filename.func`.\n * @returns The {@link ReactMutation} object with that name.\n *\n * @see https://docs.convex.dev/client/react#editing-data\n * @public\n */\nexport function useMutation<Mutation extends FunctionReference<\"mutation\">>(\n mutation: Mutation,\n): ReactMutation<Mutation> {\n const mutationReference =\n typeof mutation === \"string\"\n ? makeFunctionReference<\"mutation\", any, any>(mutation)\n : mutation;\n\n const convex = useContext(ConvexContext);\n if (convex === undefined) {\n throw new Error(\n \"Could not find Convex client! `useMutation` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n return useMemo(\n () => createMutation(mutationReference, convex),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [convex, getFunctionName(mutationReference)],\n );\n}\n\n/**\n * Construct a new {@link ReactAction}.\n *\n * Returns a function that you can call to execute a Convex action. Actions\n * can call third-party APIs and perform side effects. The returned function\n * is stable across renders (same reference identity).\n *\n * **Error handling:** Actions can fail (e.g., if an external API is down).\n * Always wrap action calls in try/catch or handle the rejected promise.\n *\n * **Note:** In most cases, calling an action directly from a client is an\n * anti-pattern. Prefer having the client call a mutation that captures the\n * user's intent (by writing to the database) and then schedules the action\n * via `ctx.scheduler.runAfter`. This ensures the intent is durably recorded\n * even if the client disconnects.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @example\n * ```tsx\n * import { useAction } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function GenerateSummary() {\n * const generate = useAction(api.ai.generateSummary);\n *\n * const handleClick = async () => {\n * try {\n * const summary = await generate({ text: \"Some long text...\" });\n * console.log(summary);\n * } catch (error) {\n * console.error(\"Action failed:\", error);\n * }\n * };\n *\n * return <button onClick={handleClick}>Generate</button>;\n * }\n * ```\n *\n * @param action - A {@link server.FunctionReference} for the public action\n * to run like `api.dir1.dir2.filename.func`.\n * @returns The {@link ReactAction} object with that name.\n *\n * @see https://docs.convex.dev/functions/actions#calling-actions-from-clients\n * @public\n */\nexport function useAction<Action extends FunctionReference<\"action\">>(\n action: Action,\n): ReactAction<Action> {\n const convex = useContext(ConvexContext);\n const actionReference =\n typeof action === \"string\"\n ? makeFunctionReference<\"action\", any, any>(action)\n : action;\n\n if (convex === undefined) {\n throw new Error(\n \"Could not find Convex client! `useAction` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n return useMemo(\n () => createAction(actionReference, convex),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [convex, getFunctionName(actionReference)],\n );\n}\n\n/**\n * React hook to get the current {@link ConnectionState} and subscribe to changes.\n *\n * This hook returns the current connection state and automatically rerenders\n * when any part of the connection state changes (e.g., when going online/offline,\n * when requests start/complete, etc.).\n *\n * The shape of ConnectionState may change in the future which may cause this\n * hook to rerender more frequently.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @returns The current {@link ConnectionState} with the Convex backend.\n *\n * @public\n */\nexport function useConvexConnectionState(): ConnectionState {\n const convex = useContext(ConvexContext);\n if (convex === undefined) {\n throw new Error(\n \"Could not find Convex client! `useConvexConnectionState` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n\n const getCurrentValue = useCallback(() => {\n return convex.connectionState();\n }, [convex]);\n\n const subscribe = useCallback(\n (callback: () => void) => {\n return convex.subscribeToConnectionState(() => {\n callback();\n });\n },\n [convex],\n );\n\n return useSubscription({ getCurrentValue, subscribe });\n}\n\n// When a function is called with a single argument that looks like a\n// React SyntheticEvent it was likely called as an event handler.\nfunction assertNotAccidentalArgument(value: any) {\n // these are properties of a React.SyntheticEvent\n // https://reactjs.org/docs/events.html\n if (\n typeof value === \"object\" &&\n value !== null &&\n \"bubbles\" in value &&\n \"persist\" in value &&\n \"isDefaultPrevented\" in value\n ) {\n throw new Error(\n `Convex function called with SyntheticEvent object. Did you use a Convex function as an event handler directly? Event handlers like onClick receive an event object as their first argument. These SyntheticEvent objects are not valid Convex values. Try wrapping the function like \\`const handler = () => myMutation();\\` and using \\`handler\\` in the event handler.`,\n );\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAiC;AAOjC,mBAAwD;AACxD,oBAAoC;AASpC,yBAA8C;AAC9C,8BAAgC;AAChC,oBAA0B;AAC1B,iBAQO;AAEP,qBAIO;AAGP,oCAGO;AAIP,MAAM,kCAAkC;AAExC,IAAI,OAAO,aAAAA,YAAU,aAAa;AAChC,QAAM,IAAI,MAAM,uCAAuC;AACzD;AAgDO,SAAS,eACd,mBACA,QAC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AAa,eAChB,kCAA4C,QAAQ,IACpD;AAEN,QAAM,aAAS,yBAAW,aAAa;AACvC,MAAI,WAAW,QAAW;AACxB,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,aAAO;AAAA,IACL,MAAM,eAAe,mBAAmB,MAAM;AAAA;AAAA,IAE9C,CAAC,YAAQ,4BAAgB,iBAAiB,CAAC;AAAA,EAC7C;AACF;AAgDO,SAAS,UACd,QACqB;AACrB,QAAM,aAAS,yBAAW,aAAa;AACvC,QAAM,kBACJ,OAAO,WAAW,eACd,kCAA0C,MAAM,IAChD;AAEN,MAAI,WAAW,QAAW;AACxB,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,aAAO;AAAA,IACL,MAAM,aAAa,iBAAiB,MAAM;AAAA;AAAA,IAE1C,CAAC,YAAQ,4BAAgB,eAAe,CAAC;AAAA,EAC3C;AACF;AAkBO,SAAS,2BAA4C;AAC1D,QAAM,aAAS,yBAAW,aAAa;AACvC,MAAI,WAAW,QAAW;AACxB,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAEA,QAAM,sBAAkB,0BAAY,MAAM;AACxC,WAAO,OAAO,gBAAgB;AAAA,EAChC,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,gBAAY;AAAA,IAChB,CAAC,aAAyB;AACxB,aAAO,OAAO,2BAA2B,MAAM;AAC7C,iBAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,aAAO,yCAAgB,EAAE,iBAAiB,UAAU,CAAC;AACvD;AAIA,SAAS,4BAA4B,OAAY;AAG/C,MACE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,aAAa,SACb,wBAAwB,OACxB;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { BaseConvexClient } from \"../browser/index.js\";\nimport type {\n OptimisticUpdate,\n PaginatedQueryToken,\n QueryToken,\n PaginationStatus,\n} from \"../browser/index.js\";\nimport React, { useCallback, useContext, useMemo } from \"react\";\nimport { convexToJson, Value } from \"../values/index.js\";\nimport { QueryJournal } from \"../browser/sync/protocol.js\";\nimport {\n AuthTokenFetcher,\n BaseConvexClientOptions,\n ConnectionState,\n BaseConvexClientInterface,\n} from \"../browser/sync/client.js\";\nimport type { UserIdentityAttributes } from \"../browser/sync/protocol.js\";\nimport { RequestForQueries, useQueries } from \"./use_queries.js\";\nimport { useSubscription } from \"./use_subscription.js\";\nimport { parseArgs } from \"../common/index.js\";\nimport {\n ArgsAndOptions,\n FunctionArgs,\n FunctionReturnType,\n OptionalRestArgs,\n getFunctionName,\n makeFunctionReference,\n FunctionReference,\n FunctionReference_future,\n} from \"../server/api.js\";\nimport { EmptyObject } from \"../server/registration.js\";\nimport {\n instantiateDefaultLogger,\n instantiateNoopLogger,\n Logger,\n} from \"../browser/logging.js\";\nimport type { QueryOptions } from \"../browser/query_options.js\";\nimport { LoadMoreOfPaginatedQuery } from \"../browser/sync/pagination.js\";\nimport {\n PaginatedQueryClient,\n ExtendedTransition,\n} from \"../browser/sync/paginated_query_client.js\";\n\n// When no arguments are passed, extend subscriptions (for APIs that do this by default)\n// for this amount after the subscription would otherwise be dropped.\nconst DEFAULT_EXTEND_SUBSCRIPTION_FOR = 5_000;\n\nif (typeof React === \"undefined\") {\n throw new Error(\"Required dependency 'react' not found\");\n}\n\n// TODO Typedoc doesn't generate documentation for the comment below perhaps\n// because it's a callable interface.\n/**\n * An interface to execute a Convex mutation function on the server.\n *\n * @public\n */\nexport interface ReactMutation<\n Mutation extends\n | FunctionReference<\"mutation\">\n | FunctionReference_future<\"mutation\">,\n> {\n /**\n * Execute the mutation on the server, returning a `Promise` of its return value.\n *\n * @param args - Arguments for the mutation to pass up to the server.\n * @returns The return value of the server-side function call.\n */\n (...args: OptionalRestArgs<Mutation>): Promise<FunctionReturnType<Mutation>>;\n\n /**\n * Define an optimistic update to apply as part of this mutation.\n *\n * This is a temporary update to the local query results to facilitate a\n * fast, interactive UI. It enables query results to update before a mutation\n * executed on the server.\n *\n * When the mutation is invoked, the optimistic update will be applied.\n *\n * Optimistic updates can also be used to temporarily remove queries from the\n * client and create loading experiences until a mutation completes and the\n * new query results are synced.\n *\n * The update will be automatically rolled back when the mutation is fully\n * completed and queries have been updated.\n *\n * @param optimisticUpdate - The optimistic update to apply.\n * @returns A new `ReactMutation` with the update configured.\n *\n * @public\n */\n withOptimisticUpdate<T extends OptimisticUpdate<FunctionArgs<Mutation>>>(\n optimisticUpdate: T &\n (ReturnType<T> extends Promise<any>\n ? \"Optimistic update handlers must be synchronous\"\n : {}),\n ): ReactMutation<Mutation>;\n}\n\n// Exported only for testing.\nexport function createMutation(\n mutationReference:\n | FunctionReference<\"mutation\">\n | FunctionReference_future<\"mutation\">,\n client: ConvexReactClient,\n update?: OptimisticUpdate<any>,\n): ReactMutation<any> {\n function mutation(args?: Record<string, Value>): Promise<unknown> {\n assertNotAccidentalArgument(args);\n\n return client.mutation(mutationReference, args, {\n optimisticUpdate: update,\n });\n }\n mutation.withOptimisticUpdate = function withOptimisticUpdate(\n optimisticUpdate: OptimisticUpdate<any>,\n ): ReactMutation<any> {\n if (update !== undefined) {\n throw new Error(\n `Already specified optimistic update for mutation ${getFunctionName(\n mutationReference,\n )}`,\n );\n }\n return createMutation(mutationReference, client, optimisticUpdate);\n };\n return mutation as ReactMutation<any>;\n}\n\n/**\n * An interface to execute a Convex action on the server.\n *\n * @public\n */\nexport interface ReactAction<\n Action extends\n | FunctionReference<\"action\">\n | FunctionReference_future<\"action\">,\n> {\n /**\n * Execute the function on the server, returning a `Promise` of its return value.\n *\n * @param args - Arguments for the function to pass up to the server.\n * @returns The return value of the server-side function call.\n * @public\n */\n (...args: OptionalRestArgs<Action>): Promise<FunctionReturnType<Action>>;\n}\n\nfunction createAction(\n actionReference:\n | FunctionReference<\"action\">\n | FunctionReference_future<\"action\">,\n client: ConvexReactClient,\n): ReactAction<any> {\n return function (args?: Record<string, Value>): Promise<unknown> {\n return client.action(actionReference, args);\n } as ReactAction<any>;\n}\n\n// Watches should be stateless: in QueriesObserver we create a watch just to get\n// the current value.\n/**\n * A watch on the output of a Convex query function.\n *\n * @public\n */\nexport interface Watch<T> {\n /**\n * Initiate a watch on the output of a query.\n *\n * This will subscribe to this query and call\n * the callback whenever the query result changes.\n *\n * **Important: If the client is already subscribed to this query with the\n * same arguments this callback will not be invoked until the query result is\n * updated.** To get the current, local result call\n * {@link react.Watch.localQueryResult}.\n *\n * @param callback - Function that is called whenever the query result changes.\n * @returns - A function that disposes of the subscription.\n */\n onUpdate(callback: () => void): () => void;\n\n /**\n * Get the current result of a query.\n *\n * This will only return a result if we're already subscribed to the query\n * and have received a result from the server or the query value has been set\n * optimistically.\n *\n * @returns The result of the query or `undefined` if it isn't known.\n * @throws An error if the query encountered an error on the server.\n */\n localQueryResult(): T | undefined;\n\n /**\n * @internal\n */\n localQueryLogs(): string[] | undefined;\n\n /**\n * Get the current {@link browser.QueryJournal} for this query.\n *\n * If we have not yet received a result for this query, this will be `undefined`.\n */\n journal(): QueryJournal | undefined;\n}\n\n/**\n * A watch on the output of a paginated Convex query function.\n *\n * @public\n */\nexport interface PaginatedWatch<T> {\n /**\n * Initiate a watch on the output of a paginated query.\n *\n * This will subscribe to this query and call\n * the callback whenever the query result changes.\n *\n * @param callback - Function that is called whenever the query result changes.\n * @returns - A function that disposes of the subscription.\n */\n onUpdate(callback: () => void): () => void;\n\n /**\n * Get the current result of a paginated query.\n *\n * @returns The current results, status, and loadMore function, or `undefined` if not loaded.\n */\n localQueryResult():\n | {\n results: T[];\n status: PaginationStatus;\n loadMore: LoadMoreOfPaginatedQuery;\n }\n | undefined;\n}\n\n/**\n * Options for {@link ConvexReactClient.watchQuery}.\n *\n * @public\n */\nexport interface WatchQueryOptions {\n /**\n * An (optional) journal produced from a previous execution of this query\n * function.\n *\n * If there is an existing subscription to a query function with the same\n * name and arguments, this journal will have no effect.\n */\n journal?: QueryJournal;\n\n /**\n * @internal\n */\n componentPath?: string;\n}\n\n/**\n * Options for {@link ConvexReactClient.watchPaginatedQuery}.\n *\n * @internal\n */\nexport interface WatchPaginatedQueryOptions {\n /**\n * The initial number of items to load.\n */\n initialNumItems: number;\n\n // We may be able to remove this in the future, but to preserve the existing behavior of\n // usePaginatedQuery() it's still here.\n id: number;\n\n /**\n * @internal\n */\n componentPath?: string;\n}\n\n/**\n * Options for {@link ConvexReactClient.mutation}.\n *\n * @public\n */\nexport interface MutationOptions<Args extends Record<string, Value>> {\n /**\n * An optimistic update to apply along with this mutation.\n *\n * An optimistic update locally updates queries while a mutation is pending.\n * Once the mutation completes, the update will be rolled back.\n */\n optimisticUpdate?: OptimisticUpdate<Args> | undefined;\n}\n\n/**\n * Options for {@link ConvexReactClient}.\n *\n * @public\n */\nexport interface ConvexReactClientOptions extends BaseConvexClientOptions {\n /**\n * An already-constructed {@link BaseConvexClient} to use instead of\n * constructing one internally. When provided, this client (and its\n * derived {@link PaginatedQueryClient}) is used for all operations.\n *\n * @internal\n */\n baseClient?: BaseConvexClientInterface;\n\n // FIXME: Ideally we define `ConvexReactClientOptions` as\n // `type ConvexReactClientOptions = BaseConvexClientOptions | { baseClient: BaseConvexClient }`\n // so that callers won\u2019t try to set `BaseConvexClientOptions` attributes that are ineffective.\n // But since `baseClient` is internal at the moment, I don\u2019t think we can do that.\n // We can fix this if we ever make `baseClient` public.\n}\n\n/**\n * A Convex client for use within React.\n *\n * This loads reactive queries and executes mutations over a WebSocket.\n *\n * @public\n */\nexport class ConvexReactClient {\n private address: string;\n private cachedSync?: BaseConvexClientInterface | undefined;\n private cachedPaginatedQueryClient?: PaginatedQueryClient | undefined;\n private listeners: Map<QueryToken | PaginatedQueryToken, Set<() => void>>;\n private options: ConvexReactClientOptions;\n // \"closed\" means this client is done, not just that the underlying WS connection is closed.\n private closed = false;\n private _logger: Logger;\n\n private adminAuth?: string;\n private fakeUserIdentity?: UserIdentityAttributes | undefined;\n\n /**\n * @param address - The url of your Convex deployment, often provided\n * by an environment variable. E.g. `https://small-mouse-123.convex.cloud`.\n * @param options - See {@link ConvexReactClientOptions} for a full description.\n */\n constructor(address: string, options?: ConvexReactClientOptions) {\n // Validate address immediately since validation by the lazily-instantiated\n // internal client does not occur synchronously.\n if (address === undefined) {\n throw new Error(\n \"No address provided to ConvexReactClient.\\n\" +\n \"If trying to deploy to production, make sure to follow all the instructions found at https://docs.convex.dev/production/hosting/\\n\" +\n \"If running locally, make sure to run `convex dev` and ensure the .env.local file is populated.\",\n );\n }\n if (typeof address !== \"string\") {\n throw new Error(\n `ConvexReactClient requires a URL like 'https://happy-otter-123.convex.cloud', received something of type ${typeof address} instead.`,\n );\n }\n if (!address.includes(\"://\")) {\n throw new Error(\"Provided address was not an absolute URL.\");\n }\n this.address = address;\n this.listeners = new Map();\n this._logger =\n options?.logger === false\n ? instantiateNoopLogger({ verbose: options?.verbose ?? false })\n : options?.logger !== true && options?.logger\n ? options.logger\n : instantiateDefaultLogger({ verbose: options?.verbose ?? false });\n this.options = { ...options, logger: this._logger };\n }\n\n /**\n * Return the address for this client, useful for creating a new client.\n *\n * Not guaranteed to match the address with which this client was constructed:\n * it may be canonicalized.\n */\n get url() {\n return this.address;\n }\n\n /**\n * Lazily instantiate the `BaseConvexClient` so we don't create the WebSocket\n * when server-side rendering.\n *\n * @internal\n */\n get sync() {\n if (this.closed) {\n throw new Error(\"ConvexReactClient has already been closed.\");\n }\n if (this.cachedSync) {\n return this.cachedSync;\n }\n // BaseConvexClient and paginated query client are always created together.\n this.cachedSync =\n this.options.baseClient ??\n new BaseConvexClient(\n this.address,\n () => {}, // Use the PaginatedQueryClient's transition instead.\n this.options,\n );\n if (this.adminAuth) {\n this.cachedSync.setAdminAuth(this.adminAuth, this.fakeUserIdentity);\n }\n this.cachedPaginatedQueryClient = new PaginatedQueryClient(\n this.cachedSync,\n (transition) => this.handleTransition(transition),\n );\n return this.cachedSync;\n }\n\n /**\n * Lazily instantiate the `PaginatedQueryClient` so we don't create it\n * when server-side rendering.\n *\n * @internal\n */\n get paginatedQueryClient() {\n // access sync to instantiate the clients\n this.sync;\n if (this.cachedPaginatedQueryClient) {\n return this.cachedPaginatedQueryClient;\n }\n throw new Error(\"Should already be instantiated\");\n }\n\n /**\n * Set the authentication token to be used for subsequent queries and mutations.\n * `fetchToken` will be called automatically again if a token expires.\n * `fetchToken` should return `null` if the token cannot be retrieved, for example\n * when the user's rights were permanently revoked.\n * @param fetchToken - an async function returning the JWT-encoded OpenID Connect Identity Token\n * @param onChange - a callback that will be called when the authentication status changes\n * @param onRefreshChange - a callback called with `true` when the socket is paused to fetch a replacement token after a server rejection, and `false` when refresh completes\n */\n setAuth(\n fetchToken: AuthTokenFetcher,\n onChange?: (isAuthenticated: boolean) => void,\n onRefreshChange?: (isRefreshing: boolean) => void,\n ) {\n if (typeof fetchToken === \"string\") {\n throw new Error(\n \"Passing a string to ConvexReactClient.setAuth is no longer supported, \" +\n \"please upgrade to passing in an async function to handle reauthentication.\",\n );\n }\n this.sync.setAuth(\n fetchToken,\n onChange ??\n (() => {\n // Do nothing\n }),\n onRefreshChange,\n );\n }\n\n /**\n * Clear the current authentication token if set.\n */\n clearAuth() {\n this.sync.clearAuth();\n }\n\n /**\n * @internal\n */\n setAdminAuth(token: string, identity?: UserIdentityAttributes) {\n this.adminAuth = token;\n this.fakeUserIdentity = identity;\n if (this.closed) {\n throw new Error(\"ConvexReactClient has already been closed.\");\n }\n if (this.cachedSync) {\n this.sync.setAdminAuth(token, identity);\n }\n }\n\n /**\n * Construct a new {@link Watch} on a Convex query function.\n *\n * **Most application code should not call this method directly. Instead use\n * the {@link useQuery} hook.**\n *\n * The act of creating a watch does nothing, a Watch is stateless.\n *\n * @param query - A {@link server.FunctionReference} for the public query to run.\n * @param args - An arguments object for the query. If this is omitted,\n * the arguments will be `{}`.\n * @param options - A {@link WatchQueryOptions} options object for this query.\n *\n * @returns The {@link Watch} object.\n */\n watchQuery<\n Query extends\n | FunctionReference<\"query\">\n | FunctionReference_future<\"query\">,\n >(\n query: Query,\n ...argsAndOptions: ArgsAndOptions<Query, WatchQueryOptions>\n ): Watch<FunctionReturnType<Query>> {\n const [args, options] = argsAndOptions;\n const name = getFunctionName(query);\n\n return {\n onUpdate: (callback) => {\n const { queryToken, unsubscribe } = this.sync.subscribe(\n name as string,\n args,\n options,\n );\n\n const currentListeners = this.listeners.get(queryToken);\n if (currentListeners !== undefined) {\n currentListeners.add(callback);\n } else {\n this.listeners.set(queryToken, new Set([callback]));\n }\n\n return () => {\n if (this.closed) {\n return;\n }\n\n const currentListeners = this.listeners.get(queryToken)!;\n currentListeners.delete(callback);\n if (currentListeners.size === 0) {\n this.listeners.delete(queryToken);\n }\n unsubscribe();\n };\n },\n\n localQueryResult: () => {\n // Use the cached client because we can't have a query result if we don't\n // even have a client yet!\n if (this.cachedSync) {\n return this.cachedSync.localQueryResult(name, args);\n }\n return undefined;\n },\n\n localQueryLogs: () => {\n if (this.cachedSync) {\n return this.cachedSync.localQueryLogs(name, args);\n }\n return undefined;\n },\n\n journal: () => {\n if (this.cachedSync) {\n return this.cachedSync.queryJournal(name, args);\n }\n return undefined;\n },\n };\n }\n\n // Let's try out a queryOptions-style API.\n // This method is similar to the React Query API `queryClient.prefetchQuery()`.\n // In the future an ensureQueryData(): Promise<Data> method could exist.\n /**\n * Indicates likely future interest in a query subscription.\n *\n * The implementation currently immediately subscribes to a query. In the future this method\n * may prioritize some queries over others, fetch the query result without subscribing, or\n * do nothing in slow network connections or high load scenarios.\n *\n * To use this in a React component, call useQuery() and ignore the return value.\n *\n * @param queryOptions - A query (function reference from an api object) and its args, plus\n * an optional extendSubscriptionFor for how long to subscribe to the query.\n */\n prewarmQuery<\n Query extends\n | FunctionReference<\"query\">\n | FunctionReference_future<\"query\">,\n >(queryOptions: QueryOptions<Query> & { extendSubscriptionFor?: number }) {\n const extendSubscriptionFor =\n queryOptions.extendSubscriptionFor ?? DEFAULT_EXTEND_SUBSCRIPTION_FOR;\n const watch = this.watchQuery(queryOptions.query, queryOptions.args || {});\n const unsubscribe = watch.onUpdate(() => {});\n setTimeout(unsubscribe, extendSubscriptionFor);\n }\n\n /**\n * Construct a new {@link PaginatedWatch} on a Convex paginated query function.\n *\n * **Most application code should not call this method directly. Instead use\n * the {@link usePaginatedQuery} hook.**\n *\n * The act of creating a watch does nothing, a Watch is stateless.\n *\n * @param query - A {@link server.FunctionReference} for the public query to run.\n * @param args - An arguments object for the query. If this is omitted,\n * the arguments will be `{}`.\n * @param options - A {@link WatchPaginatedQueryOptions} options object for this query.\n *\n * @returns The {@link PaginatedWatch} object.\n *\n * @internal\n */\n watchPaginatedQuery<\n Query extends\n | FunctionReference<\"query\">\n | FunctionReference_future<\"query\">,\n >(\n query: Query,\n args: FunctionArgs<Query>,\n options: WatchPaginatedQueryOptions,\n ): PaginatedWatch<FunctionReturnType<Query>> {\n const name = getFunctionName(query);\n\n return {\n onUpdate: (callback) => {\n const { paginatedQueryToken, unsubscribe } =\n this.paginatedQueryClient.subscribe(name, args || {}, options);\n\n const currentListeners = this.listeners.get(paginatedQueryToken);\n if (currentListeners !== undefined) {\n currentListeners.add(callback);\n } else {\n this.listeners.set(paginatedQueryToken, new Set([callback]));\n }\n\n return () => {\n if (this.closed) {\n return;\n }\n\n const currentListeners = this.listeners.get(paginatedQueryToken)!;\n currentListeners.delete(callback);\n if (currentListeners.size === 0) {\n this.listeners.delete(paginatedQueryToken);\n }\n unsubscribe();\n };\n },\n\n localQueryResult: () => {\n // Use our new paginated query client\n return this.paginatedQueryClient.localQueryResult(name, args, options);\n },\n };\n }\n\n /**\n * Execute a mutation function.\n *\n * @param mutation - A {@link server.FunctionReference} for the public mutation\n * to run.\n * @param args - An arguments object for the mutation. If this is omitted,\n * the arguments will be `{}`.\n * @param options - A {@link MutationOptions} options object for the mutation.\n * @returns A promise of the mutation's result.\n */\n mutation<\n Mutation extends\n | FunctionReference<\"mutation\">\n | FunctionReference_future<\"mutation\">,\n >(\n mutation: Mutation,\n ...argsAndOptions: ArgsAndOptions<\n Mutation,\n MutationOptions<FunctionArgs<Mutation>>\n >\n ): Promise<FunctionReturnType<Mutation>> {\n const [args, options] = argsAndOptions;\n const name = getFunctionName(mutation);\n return this.sync.mutation(name, args, options);\n }\n\n /**\n * Execute an action function.\n *\n * @param action - A {@link server.FunctionReference} for the public action\n * to run.\n * @param args - An arguments object for the action. If this is omitted,\n * the arguments will be `{}`.\n * @returns A promise of the action's result.\n */\n action<\n Action extends\n | FunctionReference<\"action\">\n | FunctionReference_future<\"action\">,\n >(\n action: Action,\n ...args: OptionalRestArgs<Action>\n ): Promise<FunctionReturnType<Action>> {\n const name = getFunctionName(action);\n return this.sync.action(name, ...args);\n }\n\n /**\n * Fetch a query result once.\n *\n * **Most application code should subscribe to queries instead, using\n * the {@link useQuery} hook.**\n *\n * @param query - A {@link server.FunctionReference} for the public query\n * to run.\n * @param args - An arguments object for the query. If this is omitted,\n * the arguments will be `{}`.\n * @returns A promise of the query's result.\n */\n query<\n Query extends\n | FunctionReference<\"query\">\n | FunctionReference_future<\"query\">,\n >(\n query: Query,\n ...args: OptionalRestArgs<Query>\n ): Promise<FunctionReturnType<Query>> {\n const watch = this.watchQuery(query, ...args);\n const existingResult = watch.localQueryResult();\n if (existingResult !== undefined) {\n return Promise.resolve(existingResult);\n }\n return new Promise((resolve, reject) => {\n const unsubscribe = watch.onUpdate(() => {\n unsubscribe();\n try {\n resolve(watch.localQueryResult());\n } catch (e) {\n reject(e);\n }\n });\n });\n }\n\n /**\n * Get the current {@link ConnectionState} between the client and the Convex\n * backend.\n *\n * @returns The {@link ConnectionState} with the Convex backend.\n */\n connectionState(): ConnectionState {\n return this.sync.connectionState();\n }\n\n /**\n * Subscribe to the {@link ConnectionState} between the client and the Convex\n * backend, calling a callback each time it changes.\n *\n * Subscribed callbacks will be called when any part of ConnectionState changes.\n * ConnectionState may grow in future versions (e.g. to provide a array of\n * inflight requests) in which case callbacks would be called more frequently.\n * ConnectionState may also *lose* properties in future versions as we figure\n * out what information is most useful. As such this API is considered unstable.\n *\n * @returns An unsubscribe function to stop listening.\n */\n subscribeToConnectionState(\n cb: (connectionState: ConnectionState) => void,\n ): () => void {\n return this.sync.subscribeToConnectionState(cb);\n }\n\n /**\n * Get the logger for this client.\n *\n * @returns The {@link Logger} for this client.\n */\n get logger(): Logger {\n return this._logger;\n }\n\n /**\n * Close any network handles associated with this client and stop all subscriptions.\n *\n * Call this method when you're done with a {@link ConvexReactClient} to\n * dispose of its sockets and resources.\n *\n * @returns A `Promise` fulfilled when the connection has been completely closed.\n */\n async close(): Promise<void> {\n this.closed = true;\n // Prevent outstanding React batched updates from invoking listeners.\n this.listeners = new Map();\n if (this.cachedPaginatedQueryClient) {\n this.cachedPaginatedQueryClient = undefined;\n }\n if (this.cachedSync) {\n const sync = this.cachedSync;\n this.cachedSync = undefined;\n await sync.close();\n }\n }\n\n /**\n * Handle transitions from both base client and paginated client.\n * This ensures all transitions are processed synchronously and in order.\n */\n private handleTransition(transition: ExtendedTransition) {\n const simple = transition.queries.map((q) => q.token);\n const paginated = transition.paginatedQueries.map((q) => q.token);\n this.transition([...simple, ...paginated]);\n }\n\n private transition(updatedQueries: (QueryToken | PaginatedQueryToken)[]) {\n for (const queryToken of updatedQueries) {\n const callbacks = this.listeners.get(queryToken);\n if (callbacks) {\n for (const callback of callbacks) {\n callback();\n }\n }\n }\n }\n}\n\nconst ConvexContext = React.createContext<ConvexReactClient>(\n undefined as unknown as ConvexReactClient, // in the future this will be a mocked client for testing\n);\n\n/**\n * Get the {@link ConvexReactClient} within a React component.\n *\n * This relies on the {@link ConvexProvider} being above in the React component tree.\n *\n * @returns The active {@link ConvexReactClient} object, or `undefined`.\n *\n * @public\n */\nexport function useConvex(): ConvexReactClient {\n return useContext(ConvexContext);\n}\n\n/**\n * Provides an active Convex {@link ConvexReactClient} to descendants of this component.\n *\n * Wrap your app in this component to use Convex hooks `useQuery`,\n * `useMutation`, and `useConvex`.\n *\n * @param props - an object with a `client` property that refers to a {@link ConvexReactClient}.\n *\n * @public\n */\nexport const ConvexProvider: React.FC<{\n client: ConvexReactClient;\n children?: React.ReactNode;\n}> = ({ client, children }) => {\n return React.createElement(\n ConvexContext.Provider,\n { value: client },\n children,\n );\n};\n\nexport type OptionalRestArgsOrSkip<\n FuncRef extends FunctionReference<any> | FunctionReference_future<any>,\n> =\n FunctionArgs<FuncRef> extends EmptyObject\n ? [args?: EmptyObject | \"skip\"]\n : [args: FunctionArgs<FuncRef> | \"skip\"];\n\n/**\n * Result returned by object-form {@link useQuery_experimental}.\n *\n * @public\n */\nexport type UseQueryResult<QueryResult, ThrowOnError extends boolean = false> =\n | { status: \"pending\" }\n | { status: \"success\"; data: QueryResult }\n | (ThrowOnError extends true ? never : { status: \"error\"; error: Error });\n\ntype UseQueryOptions<\n Query extends FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n ThrowOnError extends boolean,\n> = {\n query: Query;\n args: FunctionArgs<Query> | \"skip\";\n throwOnError?: ThrowOnError;\n};\n\n/**\n * Load a reactive query within a React component.\n *\n * This React hook subscribes to a Convex query and causes a rerender whenever\n * the query result changes. The subscription is managed automatically --\n * it starts when the component mounts and stops when it unmounts.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @example\n * ```tsx\n * import { useQuery } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function TaskList() {\n * // Reactively loads tasks, re-renders when data changes:\n * const tasks = useQuery(api.tasks.list, { completed: false });\n *\n * // Returns `undefined` while loading:\n * if (tasks === undefined) return <div>Loading...</div>;\n *\n * return tasks.map((task) => <div key={task._id}>{task.text}</div>);\n * }\n *\n * // Pass \"skip\" to conditionally disable the query:\n * function MaybeProfile({ userId }: { userId?: Id<\"users\"> }) {\n * const profile = useQuery(\n * api.users.get,\n * userId ? { userId } : \"skip\",\n * );\n * // ...\n * }\n * ```\n *\n * @param query - a {@link server.FunctionReference} for the public query to run\n * like `api.dir1.dir2.filename.func`.\n * @param args - The arguments to the query function or the string `\"skip\"` if the\n * query should not be loaded.\n * @returns the result of the query. Returns `undefined` while loading.\n *\n * @see https://docs.convex.dev/client/react#fetching-data\n * @public\n */\nexport function useQuery<\n Query extends FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n>(\n query: Query,\n ...args: OptionalRestArgsOrSkip<Query>\n): FunctionReturnType<Query> | undefined {\n const skip = args[0] === \"skip\";\n const argsObject = args[0] === \"skip\" ? {} : parseArgs(args[0]);\n const queryReference =\n typeof query === \"string\"\n ? makeFunctionReference<\"query\", any, any>(query)\n : query;\n\n const queryName = getFunctionName(queryReference);\n\n const queries = useMemo(\n () =>\n skip\n ? ({} as RequestForQueries)\n : { query: { query: queryReference, args: argsObject } },\n // Stringify args so args that are semantically the same don't trigger a\n // rerender. Saves developers from adding `useMemo` on every args usage.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(convexToJson(argsObject)), queryName, skip],\n );\n\n const results = useQueries(queries);\n const result = results[\"query\"];\n\n if (result instanceof Error) {\n throw result;\n }\n return result;\n}\n\n/**\n * Load a reactive query within a React component using an options object.\n *\n * This is an experimental form of {@link useQuery} that accepts a single\n * {@link UseQueryOptions} object instead of positional arguments.\n *\n * Consumers are expected to check the returned object `status` field to\n * make proper use of the result. If an error occurs, it will be present\n * in the result object unless `throwOnError` is `true`, in which case\n * the error will be thrown instead.\n *\n * @example\n * ```tsx\n * import { useQuery_experimental as useQuery } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function TaskList() {\n * const state = useQuery({ query: api.tasks.list, args: { completed: false } });\n *\n * if (state.status === \"pending\") return <div>Loading...</div>;\n * if (state.status === \"error\") return <div>Error: {state.error.message}</div>;\n * return state.data.map((task) => <div key={task._id}>{task.text}</div>);\n * }\n * ```\n *\n * @param options - Query options. Pass `args: \"skip\"` to disable the query.\n * @returns the current query state as a {@link UseQueryResult} object.\n *\n * @see https://docs.convex.dev/client/react#fetching-data\n * @public\n */\nexport function useQuery_experimental<\n Query extends FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n ThrowOnError extends boolean = false,\n>(\n options: UseQueryOptions<Query, ThrowOnError>,\n): UseQueryResult<FunctionReturnType<Query>, ThrowOnError>;\n\nexport function useQuery_experimental<\n Query extends FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n ThrowOnError extends boolean = false,\n>(\n options: UseQueryOptions<Query, ThrowOnError>,\n): UseQueryResult<FunctionReturnType<Query>, false> {\n const throwOnError = options.throwOnError ?? false;\n const queryReference =\n typeof options.query === \"string\"\n ? (makeFunctionReference<\"query\", any, any>(options.query) as Query)\n : options.query;\n const skip = options.args === \"skip\";\n const argsObject = !skip\n ? parseArgs(options.args as Record<string, Value>)\n : {};\n\n const queryName = getFunctionName(queryReference);\n const queries = useMemo(\n () =>\n skip\n ? ({} as RequestForQueries)\n : { query: { query: queryReference, args: argsObject } },\n // Stringify args so args that are semantically the same don't trigger a\n // rerender. Saves developers from adding `useMemo` on every args usage.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(convexToJson(argsObject)), queryName, skip],\n );\n\n const results = useQueries(queries);\n const result = results[\"query\"];\n\n if (result instanceof Error) {\n if (throwOnError) {\n throw result;\n }\n return {\n error: result,\n status: \"error\",\n };\n }\n\n if (result === undefined) {\n return {\n status: \"pending\",\n };\n }\n\n return {\n data: result,\n status: \"success\",\n };\n}\n\n/**\n * Construct a new {@link ReactMutation}.\n *\n * Returns a function that you can call to execute a Convex mutation. The\n * returned function is stable across renders (same reference identity), so\n * it can be safely used in dependency arrays and memoization.\n *\n * Mutations can optionally be configured with\n * [optimistic updates](https://docs.convex.dev/client/react/optimistic-updates)\n * for instant UI feedback.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @example\n * ```tsx\n * import { useMutation } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function CreateTask() {\n * const createTask = useMutation(api.tasks.create);\n *\n * const handleClick = async () => {\n * await createTask({ text: \"New task\" });\n * };\n *\n * return <button onClick={handleClick}>Add Task</button>;\n * }\n * ```\n *\n * @param mutation - A {@link server.FunctionReference} for the public mutation\n * to run like `api.dir1.dir2.filename.func`.\n * @returns The {@link ReactMutation} object with that name.\n *\n * @see https://docs.convex.dev/client/react#editing-data\n * @public\n */\nexport function useMutation<\n Mutation extends\n | FunctionReference<\"mutation\">\n | FunctionReference_future<\"mutation\">,\n>(mutation: Mutation): ReactMutation<Mutation> {\n const mutationReference =\n typeof mutation === \"string\"\n ? makeFunctionReference<\"mutation\", any, any>(mutation)\n : mutation;\n\n const convex = useContext(ConvexContext);\n if (convex === undefined) {\n throw new Error(\n \"Could not find Convex client! `useMutation` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n return useMemo(\n () => createMutation(mutationReference, convex),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [convex, getFunctionName(mutationReference)],\n );\n}\n\n/**\n * Construct a new {@link ReactAction}.\n *\n * Returns a function that you can call to execute a Convex action. Actions\n * can call third-party APIs and perform side effects. The returned function\n * is stable across renders (same reference identity).\n *\n * **Error handling:** Actions can fail (e.g., if an external API is down).\n * Always wrap action calls in try/catch or handle the rejected promise.\n *\n * **Note:** In most cases, calling an action directly from a client is an\n * anti-pattern. Prefer having the client call a mutation that captures the\n * user's intent (by writing to the database) and then schedules the action\n * via `ctx.scheduler.runAfter`. This ensures the intent is durably recorded\n * even if the client disconnects.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @example\n * ```tsx\n * import { useAction } from \"convex/react\";\n * import { api } from \"../convex/_generated/api\";\n *\n * function GenerateSummary() {\n * const generate = useAction(api.ai.generateSummary);\n *\n * const handleClick = async () => {\n * try {\n * const summary = await generate({ text: \"Some long text...\" });\n * console.log(summary);\n * } catch (error) {\n * console.error(\"Action failed:\", error);\n * }\n * };\n *\n * return <button onClick={handleClick}>Generate</button>;\n * }\n * ```\n *\n * @param action - A {@link server.FunctionReference} for the public action\n * to run like `api.dir1.dir2.filename.func`.\n * @returns The {@link ReactAction} object with that name.\n *\n * @see https://docs.convex.dev/functions/actions#calling-actions-from-clients\n * @public\n */\nexport function useAction<\n Action extends\n | FunctionReference<\"action\">\n | FunctionReference_future<\"action\">,\n>(action: Action): ReactAction<Action> {\n const convex = useContext(ConvexContext);\n const actionReference =\n typeof action === \"string\"\n ? makeFunctionReference<\"action\", any, any>(action)\n : action;\n\n if (convex === undefined) {\n throw new Error(\n \"Could not find Convex client! `useAction` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n return useMemo(\n () => createAction(actionReference, convex),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [convex, getFunctionName(actionReference)],\n );\n}\n\n/**\n * React hook to get the current {@link ConnectionState} and subscribe to changes.\n *\n * This hook returns the current connection state and automatically rerenders\n * when any part of the connection state changes (e.g., when going online/offline,\n * when requests start/complete, etc.).\n *\n * The shape of ConnectionState may change in the future which may cause this\n * hook to rerender more frequently.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @returns The current {@link ConnectionState} with the Convex backend.\n *\n * @public\n */\nexport function useConvexConnectionState(): ConnectionState {\n const convex = useContext(ConvexContext);\n if (convex === undefined) {\n throw new Error(\n \"Could not find Convex client! `useConvexConnectionState` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n\n const getCurrentValue = useCallback(() => {\n return convex.connectionState();\n }, [convex]);\n\n const subscribe = useCallback(\n (callback: () => void) => {\n return convex.subscribeToConnectionState(() => {\n callback();\n });\n },\n [convex],\n );\n\n return useSubscription({ getCurrentValue, subscribe });\n}\n\n// When a function is called with a single argument that looks like a\n// React SyntheticEvent it was likely called as an event handler.\nfunction assertNotAccidentalArgument(value: any) {\n // these are properties of a React.SyntheticEvent\n // https://reactjs.org/docs/events.html\n if (\n typeof value === \"object\" &&\n value !== null &&\n \"bubbles\" in value &&\n \"persist\" in value &&\n \"isDefaultPrevented\" in value\n ) {\n throw new Error(\n `Convex function called with SyntheticEvent object. Did you use a Convex function as an event handler directly? Event handlers like onClick receive an event object as their first argument. These SyntheticEvent objects are not valid Convex values. Try wrapping the function like \\`const handler = () => myMutation();\\` and using \\`handler\\` in the event handler.`,\n );\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAiC;AAOjC,mBAAwD;AACxD,oBAAoC;AASpC,yBAA8C;AAC9C,8BAAgC;AAChC,oBAA0B;AAC1B,iBASO;AAEP,qBAIO;AAGP,oCAGO;AAIP,MAAM,kCAAkC;AAExC,IAAI,OAAO,aAAAA,YAAU,aAAa;AAChC,QAAM,IAAI,MAAM,uCAAuC;AACzD;AAoDO,SAAS,eACd,mBAGA,QACA,QACoB;AACpB,WAAS,SAAS,MAAgD;AAChE,gCAA4B,IAAI;AAEhC,WAAO,OAAO,SAAS,mBAAmB,MAAM;AAAA,MAC9C,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACA,WAAS,uBAAuB,SAAS,qBACvC,kBACoB;AACpB,QAAI,WAAW,QAAW;AACxB,YAAM,IAAI;AAAA,QACR,wDAAoD;AAAA,UAClD;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO,eAAe,mBAAmB,QAAQ,gBAAgB;AAAA,EACnE;AACA,SAAO;AACT;AAsBA,SAAS,aACP,iBAGA,QACkB;AAClB,SAAO,SAAU,MAAgD;AAC/D,WAAO,OAAO,OAAO,iBAAiB,IAAI;AAAA,EAC5C;AACF;AAwKO,MAAM,kBAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkB7B,YAAY,SAAiB,SAAoC;AA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,EAC3C;AACF;AAkBO,SAAS,2BAA4C;AAC1D,QAAM,aAAS,yBAAW,aAAa;AACvC,MAAI,WAAW,QAAW;AACxB,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAEA,QAAM,sBAAkB,0BAAY,MAAM;AACxC,WAAO,OAAO,gBAAgB;AAAA,EAChC,GAAG,CAAC,MAAM,CAAC;AAEX,QAAM,gBAAY;AAAA,IAChB,CAAC,aAAyB;AACxB,aAAO,OAAO,2BAA2B,MAAM;AAC7C,iBAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AAEA,aAAO,yCAAgB,EAAE,iBAAiB,UAAU,CAAC;AACvD;AAIA,SAAS,4BAA4B,OAAY;AAG/C,MACE,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,aAAa,SACb,wBAAwB,OACxB;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": ["React", "currentListeners"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/react/hydration.tsx"],
4
- "sourcesContent": ["import { useMemo } from \"react\";\nimport { useQuery } from \"../react/client.js\";\nimport { FunctionReference, makeFunctionReference } from \"../server/api.js\";\nimport { jsonToConvex } from \"../values/index.js\";\n\n/**\n * The preloaded query payload, which should be passed to a client component\n * and passed to {@link usePreloadedQuery}.\n *\n * @public\n */\nexport type Preloaded<Query extends FunctionReference<\"query\">> = {\n __type: Query;\n _name: string;\n _argsJSON: string;\n _valueJSON: string;\n};\n\n/**\n * Load a reactive query within a React component using a `Preloaded` payload\n * from a Server Component returned by {@link nextjs.preloadQuery}.\n *\n * This React hook contains internal state that will cause a rerender\n * whenever the query result changes.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @param preloadedQuery - The `Preloaded` query payload from a Server Component.\n * @returns the result of the query. Initially returns the result fetched\n * by the Server Component. Subsequently returns the result fetched by the client.\n *\n * @public\n */\nexport function usePreloadedQuery<Query extends FunctionReference<\"query\">>(\n preloadedQuery: Preloaded<Query>,\n): Query[\"_returnType\"] {\n const args = useMemo(\n () => jsonToConvex(preloadedQuery._argsJSON),\n [preloadedQuery._argsJSON],\n ) as Query[\"_args\"];\n const preloadedResult = useMemo(\n () => jsonToConvex(preloadedQuery._valueJSON),\n [preloadedQuery._valueJSON],\n );\n const result = useQuery(\n makeFunctionReference(preloadedQuery._name) as Query,\n args,\n );\n return result === undefined ? preloadedResult : result;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,oBAAyB;AACzB,iBAAyD;AACzD,oBAA6B;AA8BtB,SAAS,kBACd,gBACsB;AACtB,QAAM,WAAO;AAAA,IACX,UAAM,4BAAa,eAAe,SAAS;AAAA,IAC3C,CAAC,eAAe,SAAS;AAAA,EAC3B;AACA,QAAM,sBAAkB;AAAA,IACtB,UAAM,4BAAa,eAAe,UAAU;AAAA,IAC5C,CAAC,eAAe,UAAU;AAAA,EAC5B;AACA,QAAM,aAAS;AAAA,QACb,kCAAsB,eAAe,KAAK;AAAA,IAC1C;AAAA,EACF;AACA,SAAO,WAAW,SAAY,kBAAkB;AAClD;",
4
+ "sourcesContent": ["import { useMemo } from \"react\";\nimport { useQuery } from \"../react/client.js\";\nimport {\n FunctionArgs,\n FunctionReturnType,\n makeFunctionReference,\n FunctionReference,\n FunctionReference_future,\n} from \"../server/api.js\";\nimport { jsonToConvex } from \"../values/index.js\";\n\n/**\n * The preloaded query payload, which should be passed to a client component\n * and passed to {@link usePreloadedQuery}.\n *\n * @public\n */\nexport type Preloaded<\n Query extends FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n> = {\n __type: Query;\n _name: string;\n _argsJSON: string;\n _valueJSON: string;\n};\n\n/**\n * Load a reactive query within a React component using a `Preloaded` payload\n * from a Server Component returned by {@link nextjs.preloadQuery}.\n *\n * This React hook contains internal state that will cause a rerender\n * whenever the query result changes.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @param preloadedQuery - The `Preloaded` query payload from a Server Component.\n * @returns the result of the query. Initially returns the result fetched\n * by the Server Component. Subsequently returns the result fetched by the client.\n *\n * @public\n */\nexport function usePreloadedQuery<\n Query extends FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n>(preloadedQuery: Preloaded<Query>): FunctionReturnType<Query> {\n const args = useMemo(\n () => jsonToConvex(preloadedQuery._argsJSON),\n [preloadedQuery._argsJSON],\n ) as FunctionArgs<Query>;\n const preloadedResult = useMemo(\n () => jsonToConvex(preloadedQuery._valueJSON),\n [preloadedQuery._valueJSON],\n );\n const result = useQuery(\n makeFunctionReference(preloadedQuery._name) as Query,\n args,\n );\n return result === undefined ? preloadedResult : result;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AACxB,oBAAyB;AACzB,iBAMO;AACP,oBAA6B;AAgCtB,SAAS,kBAEd,gBAA6D;AAC7D,QAAM,WAAO;AAAA,IACX,UAAM,4BAAa,eAAe,SAAS;AAAA,IAC3C,CAAC,eAAe,SAAS;AAAA,EAC3B;AACA,QAAM,sBAAkB;AAAA,IACtB,UAAM,4BAAa,eAAe,UAAU;AAAA,IAC5C,CAAC,eAAe,UAAU;AAAA,EAC5B;AACA,QAAM,aAAS;AAAA,QACb,kCAAsB,eAAe,KAAK;AAAA,IAC1C;AAAA,EACF;AACA,SAAO,WAAW,SAAY,kBAAkB;AAClD;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/react/queries_observer.ts"],
4
- "sourcesContent": ["import { convexToJson, Value } from \"../values/index.js\";\nimport { PaginatedWatch, Watch } from \"./client.js\";\nimport { QueryJournal } from \"../browser/sync/protocol.js\";\nimport { FunctionReference, getFunctionName } from \"../server/api.js\";\nimport { RequestForQueries } from \"./use_queries.js\";\nimport { PaginatedQueryResult } from \"../browser/sync/pagination.js\";\nimport { SubscribeToPaginatedQueryOptions } from \"../browser/sync/paginated_query_client.js\";\n\ntype Identifier = string;\n\ntype QueryInfo = {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n watch: Watch<Value> | PaginatedWatch<Value>;\n unsubscribe: () => void;\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n};\n\nexport interface CreateWatch {\n (\n query: FunctionReference<\"query\">,\n args: Record<string, Value>,\n options: {\n journal?: QueryJournal;\n // Just the existence of this option makes this a paginated query\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n },\n ): Watch<Value> | PaginatedWatch<Value>;\n}\n\n/**\n * A class for observing the results of multiple queries at the same time.\n *\n * Any time the result of a query changes, the listeners are notified.\n */\nexport class QueriesObserver {\n public createWatch: CreateWatch;\n private queries: Record<Identifier, QueryInfo>;\n private listeners: Set<() => void>;\n\n constructor(createWatch: CreateWatch) {\n this.createWatch = createWatch;\n this.queries = {};\n this.listeners = new Set();\n }\n\n setQueries(\n newQueries: Record<\n Identifier,\n {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n }\n >,\n ) {\n // Add the new queries before unsubscribing from the old ones so that\n // the deduping in the `ConvexReactClient` can help if there are duplicates.\n for (const identifier of Object.keys(newQueries)) {\n const { query, args, paginationOptions } = newQueries[identifier];\n // Might throw\n getFunctionName(query);\n\n if (this.queries[identifier] === undefined) {\n // No existing query => add it.\n this.addQuery(\n identifier,\n query,\n args,\n paginationOptions ? { paginationOptions } : {},\n );\n } else {\n const existingInfo = this.queries[identifier];\n\n if (\n getFunctionName(query) !== getFunctionName(existingInfo.query) ||\n JSON.stringify(convexToJson(args)) !==\n JSON.stringify(convexToJson(existingInfo.args)) ||\n JSON.stringify(paginationOptions) !==\n JSON.stringify(existingInfo.paginationOptions)\n ) {\n // Existing query that doesn't match => remove the old and add the new.\n this.removeQuery(identifier);\n this.addQuery(\n identifier,\n query,\n args,\n paginationOptions ? { paginationOptions } : {},\n );\n }\n }\n }\n\n // Prune all the existing queries that we no longer need.\n for (const identifier of Object.keys(this.queries)) {\n if (newQueries[identifier] === undefined) {\n this.removeQuery(identifier);\n }\n }\n }\n\n subscribe(listener: () => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n getLocalResults(\n queries: RequestForQueries,\n ): Record<\n Identifier,\n Value | undefined | Error | PaginatedQueryResult<Value>\n > {\n const result: Record<\n Identifier,\n Value | Error | undefined | PaginatedQueryResult<Value>\n > = {};\n for (const identifier of Object.keys(queries)) {\n const { query, args } = queries[identifier];\n const paginationOptions = queries[identifier].paginationOptions;\n\n // Might throw\n getFunctionName(query);\n\n // Note: We're not gonna watch, we could save some allocations\n // by getting a reference to the client directly instead.\n const watch = this.createWatch(\n query,\n args,\n paginationOptions ? { paginationOptions } : {},\n );\n\n let value: Value | undefined | Error | PaginatedQueryResult<Value>;\n try {\n value = watch.localQueryResult();\n } catch (e) {\n // Only collect instances of `Error` because thats how callers\n // will distinguish errors from normal results.\n if (e instanceof Error) {\n value = e;\n } else {\n throw e;\n }\n }\n result[identifier] = value;\n }\n return result;\n }\n\n setCreateWatch(createWatch: CreateWatch) {\n this.createWatch = createWatch;\n // If we have a new watch, we might be using a new Convex client.\n // Recreate all the watches being careful to preserve the journals.\n for (const identifier of Object.keys(this.queries)) {\n const { query, args, watch, paginationOptions } =\n this.queries[identifier];\n const journal = \"journal\" in watch ? watch.journal() : undefined;\n this.removeQuery(identifier);\n this.addQuery(identifier, query, args, {\n ...(journal ? { journal } : []),\n ...(paginationOptions ? { paginationOptions } : {}),\n });\n }\n }\n\n destroy() {\n for (const identifier of Object.keys(this.queries)) {\n this.removeQuery(identifier);\n }\n this.listeners = new Set();\n }\n\n private addQuery(\n identifier: Identifier,\n query: FunctionReference<\"query\">,\n args: Record<string, Value>,\n {\n paginationOptions,\n journal,\n }: {\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n journal?: QueryJournal;\n },\n ) {\n if (this.queries[identifier] !== undefined) {\n throw new Error(\n `Tried to add a new query with identifier ${identifier} when it already exists.`,\n );\n }\n const watch = this.createWatch(query, args, {\n ...(journal ? { journal } : []),\n ...(paginationOptions ? { paginationOptions } : {}),\n });\n const unsubscribe = watch.onUpdate(() => this.notifyListeners());\n this.queries[identifier] = {\n query,\n args,\n watch,\n unsubscribe,\n ...(paginationOptions ? { paginationOptions } : {}),\n };\n }\n\n private removeQuery(identifier: Identifier) {\n const info = this.queries[identifier];\n if (info === undefined) {\n throw new Error(`No query found with identifier ${identifier}.`);\n }\n info.unsubscribe();\n delete this.queries[identifier];\n }\n\n private notifyListeners(): void {\n for (const listener of this.listeners) {\n listener();\n }\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAGpC,iBAAmD;AAgC5C,MAAM,gBAAgB;AAAA,EAK3B,YAAY,aAA0B;AAJtC,wBAAO;AACP,wBAAQ;AACR,wBAAQ;AAGN,SAAK,cAAc;AACnB,SAAK,UAAU,CAAC;AAChB,SAAK,YAAY,oBAAI,IAAI;AAAA,EAC3B;AAAA,EAEA,WACE,YAQA;AAGA,eAAW,cAAc,OAAO,KAAK,UAAU,GAAG;AAChD,YAAM,EAAE,OAAO,MAAM,kBAAkB,IAAI,WAAW,UAAU;AAEhE,sCAAgB,KAAK;AAErB,UAAI,KAAK,QAAQ,UAAU,MAAM,QAAW;AAE1C,aAAK;AAAA,UACH;AAAA,UACA;AAAA,UACA;AAAA,UACA,oBAAoB,EAAE,kBAAkB,IAAI,CAAC;AAAA,QAC/C;AAAA,MACF,OAAO;AACL,cAAM,eAAe,KAAK,QAAQ,UAAU;AAE5C,gBACE,4BAAgB,KAAK,UAAM,4BAAgB,aAAa,KAAK,KAC7D,KAAK,cAAU,4BAAa,IAAI,CAAC,MAC/B,KAAK,cAAU,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F;AACF;",
4
+ "sourcesContent": ["import { convexToJson, Value } from \"../values/index.js\";\nimport { PaginatedWatch, Watch } from \"./client.js\";\nimport { QueryJournal } from \"../browser/sync/protocol.js\";\nimport {\n getFunctionName,\n FunctionReference,\n FunctionReference_future,\n} from \"../server/api.js\";\nimport { PaginatedQueryResult } from \"../browser/sync/pagination.js\";\nimport { SubscribeToPaginatedQueryOptions } from \"../browser/sync/paginated_query_client.js\";\n\ntype Identifier = string;\n\ntype RequestForQueriesCompat = Record<\n Identifier,\n {\n query: FunctionReference<\"query\"> | FunctionReference_future<\"query\">;\n args: Record<string, Value>;\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n }\n>;\n\ntype QueryInfo = {\n query: FunctionReference<\"query\"> | FunctionReference_future<\"query\">;\n args: Record<string, Value>;\n watch: Watch<Value> | PaginatedWatch<Value>;\n unsubscribe: () => void;\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n};\n\nexport interface CreateWatch {\n (\n query: FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n args: Record<string, Value>,\n options: {\n journal?: QueryJournal;\n // Just the existence of this option makes this a paginated query\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n },\n ): Watch<Value> | PaginatedWatch<Value>;\n}\n\n/**\n * A class for observing the results of multiple queries at the same time.\n *\n * Any time the result of a query changes, the listeners are notified.\n */\nexport class QueriesObserver {\n public createWatch: CreateWatch;\n private queries: Record<Identifier, QueryInfo>;\n private listeners: Set<() => void>;\n\n constructor(createWatch: CreateWatch) {\n this.createWatch = createWatch;\n this.queries = {};\n this.listeners = new Set();\n }\n\n setQueries(newQueries: RequestForQueriesCompat) {\n // Add the new queries before unsubscribing from the old ones so that\n // the deduping in the `ConvexReactClient` can help if there are duplicates.\n for (const identifier of Object.keys(newQueries)) {\n const { query, args, paginationOptions } = newQueries[identifier];\n // Might throw\n getFunctionName(query);\n\n if (this.queries[identifier] === undefined) {\n // No existing query => add it.\n this.addQuery(\n identifier,\n query,\n args,\n paginationOptions ? { paginationOptions } : {},\n );\n } else {\n const existingInfo = this.queries[identifier];\n\n if (\n getFunctionName(query) !== getFunctionName(existingInfo.query) ||\n JSON.stringify(convexToJson(args)) !==\n JSON.stringify(convexToJson(existingInfo.args)) ||\n JSON.stringify(paginationOptions) !==\n JSON.stringify(existingInfo.paginationOptions)\n ) {\n // Existing query that doesn't match => remove the old and add the new.\n this.removeQuery(identifier);\n this.addQuery(\n identifier,\n query,\n args,\n paginationOptions ? { paginationOptions } : {},\n );\n }\n }\n }\n\n // Prune all the existing queries that we no longer need.\n for (const identifier of Object.keys(this.queries)) {\n if (newQueries[identifier] === undefined) {\n this.removeQuery(identifier);\n }\n }\n }\n\n subscribe(listener: () => void): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n getLocalResults(\n queries: RequestForQueriesCompat,\n ): Record<\n Identifier,\n Value | undefined | Error | PaginatedQueryResult<Value>\n > {\n const result: Record<\n Identifier,\n Value | Error | undefined | PaginatedQueryResult<Value>\n > = {};\n for (const identifier of Object.keys(queries)) {\n const { query, args } = queries[identifier];\n const paginationOptions = queries[identifier].paginationOptions;\n\n // Might throw\n getFunctionName(query);\n\n // Note: We're not gonna watch, we could save some allocations\n // by getting a reference to the client directly instead.\n const watch = this.createWatch(\n query,\n args,\n paginationOptions ? { paginationOptions } : {},\n );\n\n let value: Value | undefined | Error | PaginatedQueryResult<Value>;\n try {\n value = watch.localQueryResult();\n } catch (e) {\n // Only collect instances of `Error` because thats how callers\n // will distinguish errors from normal results.\n if (e instanceof Error) {\n value = e;\n } else {\n throw e;\n }\n }\n result[identifier] = value;\n }\n return result;\n }\n\n setCreateWatch(createWatch: CreateWatch) {\n this.createWatch = createWatch;\n // If we have a new watch, we might be using a new Convex client.\n // Recreate all the watches being careful to preserve the journals.\n for (const identifier of Object.keys(this.queries)) {\n const { query, args, watch, paginationOptions } =\n this.queries[identifier];\n const journal = \"journal\" in watch ? watch.journal() : undefined;\n this.removeQuery(identifier);\n this.addQuery(identifier, query, args, {\n ...(journal ? { journal } : []),\n ...(paginationOptions ? { paginationOptions } : {}),\n });\n }\n }\n\n destroy() {\n for (const identifier of Object.keys(this.queries)) {\n this.removeQuery(identifier);\n }\n this.listeners = new Set();\n }\n\n private addQuery(\n identifier: Identifier,\n query: FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n args: Record<string, Value>,\n {\n paginationOptions,\n journal,\n }: {\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n journal?: QueryJournal;\n },\n ) {\n if (this.queries[identifier] !== undefined) {\n throw new Error(\n `Tried to add a new query with identifier ${identifier} when it already exists.`,\n );\n }\n const watch = this.createWatch(query, args, {\n ...(journal ? { journal } : []),\n ...(paginationOptions ? { paginationOptions } : {}),\n });\n const unsubscribe = watch.onUpdate(() => this.notifyListeners());\n this.queries[identifier] = {\n query,\n args,\n watch,\n unsubscribe,\n ...(paginationOptions ? { paginationOptions } : {}),\n };\n }\n\n private removeQuery(identifier: Identifier) {\n const info = this.queries[identifier];\n if (info === undefined) {\n throw new Error(`No query found with identifier ${identifier}.`);\n }\n info.unsubscribe();\n delete this.queries[identifier];\n }\n\n private notifyListeners(): void {\n for (const listener of this.listeners) {\n listener();\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoC;AAGpC,iBAIO;AAwCA,MAAM,gBAAgB;AAAA,EAK3B,YAAY,aAA0B;AAJtC,wBAAO;AACP,wBAAQ;AACR,wBAAQ;AAGN,SAAK,cAAc;AACnB,SAAK,UAAU,CAAC;AAChB,SAAK,YAAY,oBAAI,IAAI;AAAA,EAC3B;AAAA,EAEA,WAAW,YAAqC;AAG9C,eAAW,cAAc,OAAO,KAAK,UAAU,GAAG;AAChD,YAAM,EAAE,OAAO,MAAM,kBAAkB,IAAI,WAAW,UAAU;AAEhE,sCAAgB,KAAK;AAErB,UAAI,KAAK,QAAQ,UAAU,MAAM,QAAW;AA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wB;AAC1C,UAAM,OAAO,KAAK,QAAQ,UAAU;AACpC,QAAI,SAAS,QAAW;AACtB,YAAM,IAAI,MAAM,kCAAkC,UAAU,GAAG;AAAA,IACjE;AACA,SAAK,YAAY;AACjB,WAAO,KAAK,QAAQ,UAAU;AAAA,EAChC;AAAA,EAEQ,kBAAwB;AAC9B,eAAW,YAAY,KAAK,WAAW;AACrC,eAAS;AAAA,IACX;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/react/use_paginated_query2.ts"],
4
- "sourcesContent": ["import { useState } from \"react\";\n\nimport { FunctionReference, getFunctionName } from \"../server/api.js\";\nimport {\n PaginatedQueryReference,\n PaginatedQueryArgs,\n PaginatedQueryItem,\n UsePaginatedQueryReturnType,\n} from \"./use_paginated_query.js\";\nimport { convexToJson, Value } from \"../values/value.js\";\nimport { useQueries } from \"./use_queries.js\";\nimport { PaginatedQueryResult } from \"../browser/sync/pagination.js\";\nimport { SubscribeToPaginatedQueryOptions } from \"../browser/sync/paginated_query_client.js\";\nimport { ConvexError } from \"../values/errors.js\";\nimport { useConvex } from \"./client.js\";\n\n/**\n * Options for object-form {@link usePaginatedQuery_experimental}.\n *\n * @public\n */\nexport type UsePaginatedQueryOptions<\n Query extends PaginatedQueryReference,\n ThrowOnError extends boolean = false,\n> = {\n query: Query;\n args: PaginatedQueryArgs<Query> | \"skip\";\n initialNumItems: number;\n /**\n * When `true` (default for positional form), errors are thrown and caught\n * by an error boundary. When `false` (default for object form), errors are\n * returned as `{ status: \"Error\", error: Error }` instead of being thrown.\n */\n throwOnError?: ThrowOnError;\n};\n\n/**\n * Return type of the object-form {@link usePaginatedQuery_experimental} overload.\n *\n * Uses lowercase query status (`\"pending\" | \"success\" | \"error\"`) and a\n * `canLoadMore` boolean instead of the TitleCase pagination status strings\n * used by the positional form.\n *\n * @public\n */\nexport type UsePaginatedQueryObjectReturnType<\n Query extends PaginatedQueryReference,\n ThrowOnError extends boolean = false,\n> =\n | {\n data: PaginatedQueryItem<Query>[] | undefined;\n status: \"pending\";\n canLoadMore: false;\n isLoading: true;\n error: undefined;\n loadMore: (numItems: number) => void;\n }\n | {\n data: PaginatedQueryItem<Query>[];\n status: \"success\";\n canLoadMore: boolean;\n isLoading: false;\n error: undefined;\n loadMore: (numItems: number) => void;\n }\n | (ThrowOnError extends true\n ? never\n : {\n data: PaginatedQueryItem<Query>[];\n status: \"error\";\n canLoadMore: false;\n isLoading: false;\n error: Error;\n loadMore: (numItems: number) => void;\n });\n\ntype UsePaginatedQueryState = {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n id: number;\n queries: {\n paginatedQuery?: {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n paginationOptions: SubscribeToPaginatedQueryOptions;\n };\n };\n skip: boolean;\n};\n\n/**\n * Experimental new usePaginatedQuery implementation that will replace the current one\n * in the future.\n *\n * Load data reactively from a paginated query to a create a growing list.\n *\n * This is an alternate implementation that relies on new client pagination logic.\n *\n * This can be used to power \"infinite scroll\" UIs.\n *\n * This hook must be used with public query references that match\n * {@link PaginatedQueryReference}.\n *\n * `usePaginatedQuery` concatenates all the pages of results into a single list\n * and manages the continuation cursors when requesting more items.\n *\n * Example usage:\n * ```typescript\n * const { results, status, isLoading, loadMore } = usePaginatedQuery(\n * api.messages.list,\n * { channel: \"#general\" },\n * { initialNumItems: 5 }\n * );\n * ```\n *\n * If the query reference or arguments change, the pagination state will be reset\n * to the first page. Similarly, if any of the pages result in an InvalidCursor\n * error or an error associated with too much data, the pagination state will also\n * reset to the first page.\n *\n * To learn more about pagination, see [Paginated Queries](https://docs.convex.dev/database/pagination).\n *\n * @param query - A FunctionReference to the public query function to run.\n * @param args - The arguments object for the query function, excluding\n * the `paginationOpts` property. That property is injected by this hook.\n * @param options - An object specifying the `initialNumItems` to be loaded in\n * the first page.\n * @returns A {@link UsePaginatedQueryResult} that includes the currently loaded\n * items, the status of the pagination, and a `loadMore` function.\n *\n * @public\n */\nexport function usePaginatedQuery_experimental<\n Query extends PaginatedQueryReference,\n>(\n query: Query,\n args: PaginatedQueryArgs<Query> | \"skip\",\n // Future options this hook might accept:\n // - maximumRowsRead\n // - maximumBytesRead\n // - a cursor for where to start? although probably no endCursor\n options: { initialNumItems: number },\n): UsePaginatedQueryReturnType<Query>;\n\n/**\n * Experimental new usePaginatedQuery implementation that accepts an options object\n * rather than positional arguments.\n *\n * @param options - A {@link UsePaginatedQueryOptions} object including `query` and `args`.\n * @returns A {@link UsePaginatedQueryObjectReturnType} object with `data`, `status`,\n * `canLoadMore`, `isLoading`, `error`, and `loadMore`. `status` is `\"pending\"` while\n * loading, `\"success\"` when data is available, or `\"error\"` if the query threw.\n * When `throwOnError` is `true`, the `\"error\"` status is excluded from the return\n * type since errors will be thrown instead.\n * `canLoadMore` is `true` only when idle and more pages exist.\n *\n * @public\n */\nexport function usePaginatedQuery_experimental<\n Query extends PaginatedQueryReference,\n ThrowOnError extends boolean = false,\n>(\n options: UsePaginatedQueryOptions<Query, ThrowOnError>,\n): UsePaginatedQueryObjectReturnType<Query, ThrowOnError>;\n\nexport function usePaginatedQuery_experimental<\n Query extends PaginatedQueryReference,\n>(\n queryOrOptions: Query | UsePaginatedQueryOptions<Query>,\n args?: PaginatedQueryArgs<Query> | \"skip\",\n // Future options this hook might accept:\n // - maximumRowsRead\n // - maximumBytesRead\n // - a cursor for where to start? although probably no endCursor\n options?: { initialNumItems: number },\n):\n | UsePaginatedQueryReturnType<Query>\n | UsePaginatedQueryObjectReturnType<Query> {\n const isObjectOptions =\n typeof queryOrOptions === \"object\" &&\n queryOrOptions !== null &&\n \"query\" in queryOrOptions;\n\n const query = isObjectOptions ? queryOrOptions.query : queryOrOptions;\n const queryArgs = isObjectOptions ? queryOrOptions.args : args;\n const throwOnError = isObjectOptions\n ? (queryOrOptions.throwOnError ?? false)\n : true;\n const initialOptions = isObjectOptions\n ? { initialNumItems: queryOrOptions.initialNumItems }\n : options;\n\n if (\n typeof initialOptions?.initialNumItems !== \"number\" ||\n initialOptions.initialNumItems < 0\n ) {\n throw new Error(\n `\\`options.initialNumItems\\` must be a positive number. Received \\`${initialOptions?.initialNumItems}\\`.`,\n );\n }\n const skip = queryArgs === \"skip\";\n const argsObject = skip ? {} : queryArgs;\n\n const convexClient = useConvex();\n const logger = convexClient.logger;\n\n // The identity of createInitialState changes each time!\n const createInitialState: () => UsePaginatedQueryState = () => {\n const id = nextPaginationId();\n return {\n query,\n args: argsObject as Record<string, Value>,\n id,\n // Queries will contain zero or one queries forever.\n queries: skip\n ? ({} as UsePaginatedQueryState[\"queries\"])\n : {\n paginatedQuery: {\n query,\n args: {\n ...argsObject,\n },\n paginationOptions: {\n initialNumItems: initialOptions.initialNumItems,\n id,\n },\n },\n },\n skip,\n };\n };\n\n const [state, setState] =\n useState<UsePaginatedQueryState>(createInitialState);\n\n // `currState` is the state that we'll render based on.\n let currState = state;\n // New function, args, or skip? New paginated query!\n if (\n getFunctionName(query) !== getFunctionName(state.query) ||\n JSON.stringify(convexToJson(argsObject as Value)) !==\n JSON.stringify(convexToJson(state.args)) ||\n skip !== state.skip\n ) {\n currState = createInitialState();\n setState(currState);\n }\n // currState.queries is just a single query; we use useQueries\n // because it's the lower-level ook sthat supports pagination options.\n const resultsObject = useQueries(currState.queries);\n\n // skip\n if (!(\"paginatedQuery\" in resultsObject)) {\n if (!skip) {\n throw new Error(\"Why is it missing?\");\n }\n const internalResult = {\n results: [] as Query[\"_returnType\"][\"page\"],\n status: \"LoadingFirstPage\" as const,\n isLoading: true as const,\n loadMore: function skipNOP(_numItems: number) {\n return false;\n },\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n }\n const result = resultsObject.paginatedQuery as\n | PaginatedQueryResult<Query[\"_returnType\"][\"page\"][number]>\n | Error;\n\n // TODO this is a weird mix of responsibilities:\n // - is it the hook's job to render the initial loading state?\n // - or is it the paginated query's job to render the approproate loading state?\n // It comes back to why we'd ever get undefined when asking about a query; have we not yet called subscribe for it?\n if (result === undefined) {\n const internalResult = {\n results: [] as Query[\"_returnType\"][\"page\"],\n loadMore: () => false,\n isLoading: true as const,\n status: \"LoadingFirstPage\" as const,\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n }\n\n if (result instanceof Error) {\n if (\n result.message.includes(\"InvalidCursor\") ||\n (result instanceof ConvexError &&\n typeof result.data === \"object\" &&\n result.data?.isConvexSystemError === true &&\n result.data?.paginationError === \"InvalidCursor\")\n ) {\n // - InvalidCursor: If the cursor is invalid, probably the paginated\n // database query was data-dependent and changed underneath us. The\n // cursor in the params or journal no longer matches the current\n // database query.\n\n // In all cases, we want to restart pagination to throw away all our\n // existing cursors.\n logger.warn(\n \"usePaginatedQuery hit error, resetting pagination state: \" +\n result.message,\n );\n setState(createInitialState);\n const internalResult = {\n results: [] as Query[\"_returnType\"][\"page\"],\n loadMore: () => false,\n isLoading: true as const,\n status: \"LoadingFirstPage\" as const,\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n } else {\n if (throwOnError) {\n throw result;\n }\n const internalResult = {\n results: [] as Query[\"_returnType\"][\"page\"],\n loadMore: () => false,\n isLoading: false as const,\n status: \"Error\" as const,\n error: result,\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n }\n }\n\n const internalResult = {\n ...result,\n loadMore: (num: number) => {\n return result.loadMore(num);\n },\n isLoading:\n result.status === \"LoadingFirstPage\"\n ? (true as const)\n : result.status === \"LoadingMore\"\n ? (true as const)\n : (false as const),\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n}\n\n/**\n * Reshape the internal TitleCase pagination result into the object-form\n * return type with lowercase `status`, `canLoadMore`, and `data`.\n */\nfunction reshapeToObjectForm2<Item>(internal: {\n results: Item[];\n status: string;\n isLoading: boolean;\n loadMore: (...args: any[]) => any;\n error?: Error;\n}) {\n const { results, loadMore } = internal;\n if (internal.status === \"Error\" && \"error\" in internal) {\n return {\n data: results,\n status: \"error\" as const,\n canLoadMore: false as const,\n isLoading: false as const,\n error: internal.error,\n loadMore,\n };\n }\n if (\n internal.status === \"LoadingFirstPage\" ||\n internal.status === \"LoadingMore\"\n ) {\n return {\n data: internal.status === \"LoadingFirstPage\" ? undefined : results,\n status: \"pending\" as const,\n canLoadMore: false as const,\n isLoading: true as const,\n error: undefined,\n loadMore,\n };\n }\n // CanLoadMore or Exhausted\n return {\n data: results,\n status: \"success\" as const,\n canLoadMore: internal.status === \"CanLoadMore\",\n isLoading: false as const,\n error: undefined,\n loadMore,\n };\n}\n\nlet paginationId = 0;\n/**\n * See ./use_paginated_query for the purpose, but we may be able to get rid of this soon.\n *\n * @returns The pagination ID.\n */\nfunction nextPaginationId(): number {\n paginationId++;\n return paginationId;\n}\n\n/**\n * Reset pagination id for tests only, so tests know what it is.\n */\nexport function resetPaginationId() {\n paginationId = 0;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyB;AAEzB,iBAAmD;AAOnD,mBAAoC;AACpC,yBAA2B;AAG3B,oBAA4B;AAC5B,oBAA0B;AAuJnB,SAAS,+BAGd,gBACA,MAKA,SAG2C;AAC3C,QAAM,kBACJ,OAAO,mBAAmB,YAC1B,mBAAmB,QACnB,WAAW;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AAU,CAAC,QAAgB;AACzB,aAAO,OAAO,SAAS,GAAG;AAAA,IAC5B;AAAA,IACA,WACE,OAAO,WAAW,qBACb,OACD,OAAO,WAAW,gBACf,OACA;AAAA,EACX;AACA,MAAI,iBAAiB;AACnB,WAAO;AAAA,MACL;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAMA,SAAS,qBAA2B,UAMjC;AACD,QAAM,EAAE,SAAS,SAAS,IAAI;AAC9B,MAAI,SAAS,WAAW,WAAW,WAAW,UAAU;AACtD,WAAO;AAAA,MACL,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,WAAW;AAAA,MACX,OAAO,SAAS;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACA,MACE,SAAS,WAAW,sBACpB,SAAS,WAAW,eACpB;AACA,WAAO;AAAA,MACL,MAAM,SAAS,WAAW,qBAAqB,SAAY;AAAA,MAC3D,QAAQ;AAAA,MACR,aAAa;AAAA,MACb,WAAW;AAAA,MACX,OAAO;AAAA,MACP;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,aAAa,SAAS,WAAW;AAAA,IACjC,WAAW;AAAA,IACX,OAAO;AAAA,IACP;AAAA,EACF;AACF;AAEA,IAAI,eAAe;AAMnB,SAAS,mBAA2B;AAClC;AACA,SAAO;AACT;AAKO,SAAS,oBAAoB;AAClC,iBAAe;AACjB;",
4
+ "sourcesContent": ["import { useState } from \"react\";\n\nimport {\n FunctionReference,\n FunctionReturnType,\n getFunctionName,\n} from \"../server/api.js\";\nimport {\n PaginatedQueryReference,\n PaginatedQueryArgs,\n PaginatedQueryItem,\n UsePaginatedQueryReturnType,\n} from \"./use_paginated_query.js\";\nimport { convexToJson, Value } from \"../values/value.js\";\nimport { useQueries } from \"./use_queries.js\";\nimport { PaginatedQueryResult } from \"../browser/sync/pagination.js\";\nimport { SubscribeToPaginatedQueryOptions } from \"../browser/sync/paginated_query_client.js\";\nimport { ConvexError } from \"../values/errors.js\";\nimport { useConvex } from \"./client.js\";\n\n/**\n * Options for object-form {@link usePaginatedQuery_experimental}.\n *\n * @public\n */\nexport type UsePaginatedQueryOptions<\n Query extends PaginatedQueryReference,\n ThrowOnError extends boolean = false,\n> = {\n query: Query;\n args: PaginatedQueryArgs<Query> | \"skip\";\n initialNumItems: number;\n /**\n * When `true` (default for positional form), errors are thrown and caught\n * by an error boundary. When `false` (default for object form), errors are\n * returned as `{ status: \"Error\", error: Error }` instead of being thrown.\n */\n throwOnError?: ThrowOnError;\n};\n\n/**\n * Return type of the object-form {@link usePaginatedQuery_experimental} overload.\n *\n * Uses lowercase query status (`\"pending\" | \"success\" | \"error\"`) and a\n * `canLoadMore` boolean instead of the TitleCase pagination status strings\n * used by the positional form.\n *\n * @public\n */\nexport type UsePaginatedQueryObjectReturnType<\n Query extends PaginatedQueryReference,\n ThrowOnError extends boolean = false,\n> =\n | {\n data: PaginatedQueryItem<Query>[] | undefined;\n status: \"pending\";\n canLoadMore: false;\n isLoading: true;\n error: undefined;\n loadMore: (numItems: number) => void;\n }\n | {\n data: PaginatedQueryItem<Query>[];\n status: \"success\";\n canLoadMore: boolean;\n isLoading: false;\n error: undefined;\n loadMore: (numItems: number) => void;\n }\n | (ThrowOnError extends true\n ? never\n : {\n data: PaginatedQueryItem<Query>[];\n status: \"error\";\n canLoadMore: false;\n isLoading: false;\n error: Error;\n loadMore: (numItems: number) => void;\n });\n\ntype UsePaginatedQueryState = {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n id: number;\n queries: {\n paginatedQuery?: {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n paginationOptions: SubscribeToPaginatedQueryOptions;\n };\n };\n skip: boolean;\n};\n\n/**\n * Experimental new usePaginatedQuery implementation that will replace the current one\n * in the future.\n *\n * Load data reactively from a paginated query to a create a growing list.\n *\n * This is an alternate implementation that relies on new client pagination logic.\n *\n * This can be used to power \"infinite scroll\" UIs.\n *\n * This hook must be used with public query references that match\n * {@link PaginatedQueryReference}.\n *\n * `usePaginatedQuery` concatenates all the pages of results into a single list\n * and manages the continuation cursors when requesting more items.\n *\n * Example usage:\n * ```typescript\n * const { results, status, isLoading, loadMore } = usePaginatedQuery(\n * api.messages.list,\n * { channel: \"#general\" },\n * { initialNumItems: 5 }\n * );\n * ```\n *\n * If the query reference or arguments change, the pagination state will be reset\n * to the first page. Similarly, if any of the pages result in an InvalidCursor\n * error or an error associated with too much data, the pagination state will also\n * reset to the first page.\n *\n * To learn more about pagination, see [Paginated Queries](https://docs.convex.dev/database/pagination).\n *\n * @param query - A FunctionReference to the public query function to run.\n * @param args - The arguments object for the query function, excluding\n * the `paginationOpts` property. That property is injected by this hook.\n * @param options - An object specifying the `initialNumItems` to be loaded in\n * the first page.\n * @returns A {@link UsePaginatedQueryResult} that includes the currently loaded\n * items, the status of the pagination, and a `loadMore` function.\n *\n * @public\n */\nexport function usePaginatedQuery_experimental<\n Query extends PaginatedQueryReference,\n>(\n query: Query,\n args: PaginatedQueryArgs<Query> | \"skip\",\n // Future options this hook might accept:\n // - maximumRowsRead\n // - maximumBytesRead\n // - a cursor for where to start? although probably no endCursor\n options: { initialNumItems: number },\n): UsePaginatedQueryReturnType<Query>;\n\n/**\n * Experimental new usePaginatedQuery implementation that accepts an options object\n * rather than positional arguments.\n *\n * @param options - A {@link UsePaginatedQueryOptions} object including `query` and `args`.\n * @returns A {@link UsePaginatedQueryObjectReturnType} object with `data`, `status`,\n * `canLoadMore`, `isLoading`, `error`, and `loadMore`. `status` is `\"pending\"` while\n * loading, `\"success\"` when data is available, or `\"error\"` if the query threw.\n * When `throwOnError` is `true`, the `\"error\"` status is excluded from the return\n * type since errors will be thrown instead.\n * `canLoadMore` is `true` only when idle and more pages exist.\n *\n * @public\n */\nexport function usePaginatedQuery_experimental<\n Query extends PaginatedQueryReference,\n ThrowOnError extends boolean = false,\n>(\n options: UsePaginatedQueryOptions<Query, ThrowOnError>,\n): UsePaginatedQueryObjectReturnType<Query, ThrowOnError>;\n\nexport function usePaginatedQuery_experimental<\n Query extends PaginatedQueryReference,\n>(\n queryOrOptions: Query | UsePaginatedQueryOptions<Query>,\n args?: PaginatedQueryArgs<Query> | \"skip\",\n // Future options this hook might accept:\n // - maximumRowsRead\n // - maximumBytesRead\n // - a cursor for where to start? although probably no endCursor\n options?: { initialNumItems: number },\n):\n | UsePaginatedQueryReturnType<Query>\n | UsePaginatedQueryObjectReturnType<Query> {\n const isObjectOptions =\n typeof queryOrOptions === \"object\" &&\n queryOrOptions !== null &&\n \"query\" in queryOrOptions;\n\n const query = isObjectOptions ? queryOrOptions.query : queryOrOptions;\n const queryArgs = isObjectOptions ? queryOrOptions.args : args;\n const throwOnError = isObjectOptions\n ? (queryOrOptions.throwOnError ?? false)\n : true;\n const initialOptions = isObjectOptions\n ? { initialNumItems: queryOrOptions.initialNumItems }\n : options;\n\n if (\n typeof initialOptions?.initialNumItems !== \"number\" ||\n initialOptions.initialNumItems < 0\n ) {\n throw new Error(\n `\\`options.initialNumItems\\` must be a positive number. Received \\`${initialOptions?.initialNumItems}\\`.`,\n );\n }\n const skip = queryArgs === \"skip\";\n const argsObject = skip ? {} : queryArgs;\n\n const convexClient = useConvex();\n const logger = convexClient.logger;\n\n // The identity of createInitialState changes each time!\n const createInitialState: () => UsePaginatedQueryState = () => {\n const id = nextPaginationId();\n return {\n query,\n args: argsObject as Record<string, Value>,\n id,\n // Queries will contain zero or one queries forever.\n queries: skip\n ? ({} as UsePaginatedQueryState[\"queries\"])\n : {\n paginatedQuery: {\n query,\n args: {\n ...argsObject,\n },\n paginationOptions: {\n initialNumItems: initialOptions.initialNumItems,\n id,\n },\n },\n },\n skip,\n };\n };\n\n const [state, setState] =\n useState<UsePaginatedQueryState>(createInitialState);\n\n // `currState` is the state that we'll render based on.\n let currState = state;\n // New function, args, or skip? New paginated query!\n if (\n getFunctionName(query) !== getFunctionName(state.query) ||\n JSON.stringify(convexToJson(argsObject as Value)) !==\n JSON.stringify(convexToJson(state.args)) ||\n skip !== state.skip\n ) {\n currState = createInitialState();\n setState(currState);\n }\n // currState.queries is just a single query; we use useQueries\n // because it's the lower-level ook sthat supports pagination options.\n const resultsObject = useQueries(currState.queries);\n\n // skip\n if (!(\"paginatedQuery\" in resultsObject)) {\n if (!skip) {\n throw new Error(\"Why is it missing?\");\n }\n const internalResult = {\n results: [] as FunctionReturnType<Query>[\"page\"],\n status: \"LoadingFirstPage\" as const,\n isLoading: true as const,\n loadMore: function skipNOP(_numItems: number) {\n return false;\n },\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n }\n const result = resultsObject.paginatedQuery as\n | PaginatedQueryResult<FunctionReturnType<Query>[\"page\"][number]>\n | Error;\n\n // TODO this is a weird mix of responsibilities:\n // - is it the hook's job to render the initial loading state?\n // - or is it the paginated query's job to render the approproate loading state?\n // It comes back to why we'd ever get undefined when asking about a query; have we not yet called subscribe for it?\n if (result === undefined) {\n const internalResult = {\n results: [] as FunctionReturnType<Query>[\"page\"],\n loadMore: () => false,\n isLoading: true as const,\n status: \"LoadingFirstPage\" as const,\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n }\n\n if (result instanceof Error) {\n if (\n result.message.includes(\"InvalidCursor\") ||\n (result instanceof ConvexError &&\n typeof result.data === \"object\" &&\n result.data?.isConvexSystemError === true &&\n result.data?.paginationError === \"InvalidCursor\")\n ) {\n // - InvalidCursor: If the cursor is invalid, probably the paginated\n // database query was data-dependent and changed underneath us. The\n // cursor in the params or journal no longer matches the current\n // database query.\n\n // In all cases, we want to restart pagination to throw away all our\n // existing cursors.\n logger.warn(\n \"usePaginatedQuery hit error, resetting pagination state: \" +\n result.message,\n );\n setState(createInitialState);\n const internalResult = {\n results: [] as FunctionReturnType<Query>[\"page\"],\n loadMore: () => false,\n isLoading: true as const,\n status: \"LoadingFirstPage\" as const,\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n } else {\n if (throwOnError) {\n throw result;\n }\n const internalResult = {\n results: [] as FunctionReturnType<Query>[\"page\"],\n loadMore: () => false,\n isLoading: false as const,\n status: \"Error\" as const,\n error: result,\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n }\n }\n\n const internalResult = {\n ...result,\n loadMore: (num: number) => {\n return result.loadMore(num);\n },\n isLoading:\n result.status === \"LoadingFirstPage\"\n ? (true as const)\n : result.status === \"LoadingMore\"\n ? (true as const)\n : (false as const),\n };\n if (isObjectOptions) {\n return reshapeToObjectForm2(\n internalResult,\n ) as unknown as UsePaginatedQueryObjectReturnType<Query>;\n }\n return internalResult as unknown as UsePaginatedQueryReturnType<Query>;\n}\n\n/**\n * Reshape the internal TitleCase pagination result into the object-form\n * return type with lowercase `status`, `canLoadMore`, and `data`.\n */\nfunction reshapeToObjectForm2<Item>(internal: {\n results: Item[];\n status: string;\n isLoading: boolean;\n loadMore: (...args: any[]) => any;\n error?: Error;\n}) {\n const { results, loadMore } = internal;\n if (internal.status === \"Error\" && \"error\" in internal) {\n return {\n data: results,\n status: \"error\" as const,\n canLoadMore: false as const,\n isLoading: false as const,\n error: internal.error,\n loadMore,\n };\n }\n if (\n internal.status === \"LoadingFirstPage\" ||\n internal.status === \"LoadingMore\"\n ) {\n return {\n data: internal.status === \"LoadingFirstPage\" ? undefined : results,\n status: \"pending\" as const,\n canLoadMore: false as const,\n isLoading: true as const,\n error: undefined,\n loadMore,\n };\n }\n // CanLoadMore or Exhausted\n return {\n data: results,\n status: \"success\" as const,\n canLoadMore: internal.status === \"CanLoadMore\",\n isLoading: false as const,\n error: undefined,\n loadMore,\n };\n}\n\nlet paginationId = 0;\n/**\n * See ./use_paginated_query for the purpose, but we may be able to get rid of this soon.\n *\n * @returns The pagination ID.\n */\nfunction nextPaginationId(): number {\n paginationId++;\n return paginationId;\n}\n\n/**\n * Reset pagination id for tests only, so tests know what it is.\n */\nexport function resetPaginationId() {\n paginationId = 0;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyB;AAEzB,iBAIO;AAOP,mBAAoC;AACpC,yBAA2B;AAG3B,oBAA4B;AAC5B,oBAA0B;AAuJnB,SAAS,+BAGd,gBACA,MAKA,SAG2C;AAC3C,QAAM,kBACJ,OAAO,mBAAmB,YAC1B,mBAAmB,QACnB,WAAW;AAEb,QAAM,QAAQ,kBAAkB,eAAe,QAAQ;AACvD,QAAM,YAAY,kBAAkB,eAAe,OAAO;AAC1D,QAAM,eAAe,kBAChB,eAAe,gBAAgB,QAChC;AACJ,QAAM,iBAAiB,kBACnB,EAAE,iBAAiB,eAAe,gBAAgB,IAClD;AAEJ,MACE,OAAO,gBAAgB,oBAAoB,YAC3C,eAAe,kBAAkB,GACjC;AACA,UAAM,IAAI;AAAA,MACR,qEAAqE,gBAAgB,eAAe;AAAA,IACtG;AAAA,EACF;AACA,QAAM,OAAO,cAAc;AAC3B,QAAM,aAAa,OAAO,CAAC,IAAI;AAE/B,QAAM,mBAAe,yBAAU;AAC/B,QAAM,SAAS,aAAa;AAG5B,QAAM,qBAAmD,MAAM;AAC7D,UAAM,KAAK,iBAAiB;AAC5B,WAAO;AAAA,MACL;AAAA,MACA,MAAM;AAAA,MACN;AAAA;AAAA,MAEA,SAAS,OACJ,CAAC,IACF;AAAA,QACE,gBAAgB;AAAA,UACd;AAAA,UACA,MAAM;AAAA,YACJ,GAAG;AAAA,UACL;AAAA,UACA,mBAAmB;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L,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,aAAa,SAAS,WAAW;AAAA,IACjC,WAAW;AAAA,IACX,OAAO;AAAA,IACP;AAAA,EACF;AACF;AAEA,IAAI,eAAe;AAMnB,SAAS,mBAA2B;AAClC;AACA,SAAO;AACT;AAKO,SAAS,oBAAoB;AAClC,iBAAe;AACjB;",
6
6
  "names": ["internalResult"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/react/use_queries.ts"],
4
- "sourcesContent": ["import { Value } from \"../values/index.js\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useConvex } from \"./client.js\";\nimport { CreateWatch, QueriesObserver } from \"./queries_observer.js\";\nimport { useSubscription } from \"./use_subscription.js\";\nimport { QueryJournal } from \"../browser/index.js\";\nimport { FunctionReference } from \"../server/api.js\";\nimport { SubscribeToPaginatedQueryOptions } from \"../browser/sync/paginated_query_client.js\";\n\n/**\n * Load a variable number of reactive Convex queries.\n *\n * `useQueries` is similar to {@link useQuery} but it allows\n * loading multiple queries which can be useful for loading a dynamic number\n * of queries without violating the rules of React hooks.\n *\n * This hook accepts an object whose keys are identifiers for each query and the\n * values are objects of `{ query: FunctionReference, args: Record<string, Value> }`. The\n * `query` is a FunctionReference for the Convex query function to load, and the `args` are\n * the arguments to that function.\n *\n * The hook returns an object that maps each identifier to the result of the query,\n * `undefined` if the query is still loading, or an instance of `Error` if the query\n * threw an exception.\n *\n * For example if you loaded a query like:\n * ```typescript\n * const results = useQueries({\n * messagesInGeneral: {\n * query: \"listMessages\",\n * args: { channel: \"#general\" }\n * }\n * });\n * ```\n * then the result would look like:\n * ```typescript\n * {\n * messagesInGeneral: [{\n * channel: \"#general\",\n * body: \"hello\"\n * _id: ...,\n * _creationTime: ...\n * }]\n * }\n * ```\n *\n * This React hook contains internal state that will cause a rerender\n * whenever any of the query results change.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @param queries - An object mapping identifiers to objects of\n * `{query: string, args: Record<string, Value> }` describing which query\n * functions to fetch.\n * @returns An object with the same keys as the input. The values are the result\n * of the query function, `undefined` if it's still loading, or an `Error` if\n * it threw an exception.\n *\n * @public\n */\nexport function useQueries(\n queries: RequestForQueries,\n): Record<string, any | undefined | Error> {\n const convex = useConvex();\n if (convex === undefined) {\n // Error message includes `useQuery` because this hook is called by `useQuery`\n // more often than it's called directly.\n throw new Error(\n \"Could not find Convex client! `useQuery` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n const createWatch = useMemo(() => {\n return (\n query: FunctionReference<\"query\">,\n args: Record<string, Value>,\n {\n journal,\n paginationOptions,\n }: {\n journal?: QueryJournal;\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n },\n ) => {\n if (paginationOptions) {\n return convex.watchPaginatedQuery(query, args, paginationOptions);\n } else {\n return convex.watchQuery(query, args, journal ? { journal } : {});\n }\n };\n }, [convex]);\n return useQueriesHelper(queries, createWatch);\n}\n\n/**\n * Internal version of `useQueries` that is exported for testing.\n */\nexport function useQueriesHelper(\n queries: RequestForQueries,\n createWatch: CreateWatch,\n): Record<string, any | undefined | Error> {\n const [observer] = useState(() => new QueriesObserver(createWatch));\n\n if (observer.createWatch !== createWatch) {\n observer.setCreateWatch(createWatch);\n }\n\n // Unsubscribe from all queries on unmount.\n useEffect(() => () => observer.destroy(), [observer]);\n\n const subscription = useMemo(\n () => ({\n getCurrentValue: () => {\n return observer.getLocalResults(queries);\n },\n subscribe: (callback: () => void) => {\n observer.setQueries(queries);\n return observer.subscribe(callback);\n },\n }),\n [observer, queries],\n );\n\n return useSubscription(subscription);\n}\n\n/**\n * An object representing a request to load multiple queries.\n *\n * The keys of this object are identifiers and the values are objects containing\n * the query function and the arguments to pass to it.\n *\n * This is used as an argument to {@link useQueries}.\n * @public\n */\nexport type RequestForQueries = Record<\n string,\n {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n /** @internal */\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n }\n>;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA6C;AAC7C,oBAA0B;AAC1B,8BAA6C;AAC7C,8BAAgC;AAwDzB,SAAS,WACd,SACyC;AACzC,QAAM,aAAS,yBAAU;AACzB,MAAI,WAAW,QAAW;AAGxB,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AACA,QAAM,kBAAc,sBAAQ,MAAM;AAChC,WAAO,CACL,OACA,MACA;AAAA,MACE;AAAA,MACA;AAAA,IACF,MAIG;AACH,UAAI,mBAAmB;AACrB,eAAO,OAAO,oBAAoB,OAAO,MAAM,iBAAiB;AAAA,MAClE,OAAO;AACL,eAAO,OAAO,WAAW,OAAO,MAAM,UAAU,EAAE,QAAQ,IAAI,CAAC,CAAC;AAAA,MAClE;AAAA,IACF;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AACX,SAAO,iBAAiB,SAAS,WAAW;AAC9C;AAKO,SAAS,iBACd,SACA,aACyC;AACzC,QAAM,CAAC,QAAQ,QAAI,uBAAS,MAAM,IAAI,wCAAgB,WAAW,CAAC;AAElE,MAAI,SAAS,gBAAgB,aAAa;AACxC,aAAS,eAAe,WAAW;AAAA,EACrC;AAGA,8BAAU,MAAM,MAAM,SAAS,QAAQ,GAAG,CAAC,QAAQ,CAAC;AAEpD,QAAM,mBAAe;AAAA,IACnB,OAAO;AAAA,MACL,iBAAiB,MAAM;AACrB,eAAO,SAAS,gBAAgB,OAAO;AAAA,MACzC;AAAA,MACA,WAAW,CAAC,aAAyB;AACnC,iBAAS,WAAW,OAAO;AAC3B,eAAO,SAAS,UAAU,QAAQ;AAAA,MACpC;AAAA,IACF;AAAA,IACA,CAAC,UAAU,OAAO;AAAA,EACpB;AAEA,aAAO,yCAAgB,YAAY;AACrC;",
4
+ "sourcesContent": ["import { Value } from \"../values/index.js\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useConvex } from \"./client.js\";\nimport { CreateWatch, QueriesObserver } from \"./queries_observer.js\";\nimport { useSubscription } from \"./use_subscription.js\";\nimport { QueryJournal } from \"../browser/index.js\";\nimport { FunctionReference, FunctionReference_future } from \"../server/api.js\";\nimport { SubscribeToPaginatedQueryOptions } from \"../browser/sync/paginated_query_client.js\";\n\n/**\n * Load a variable number of reactive Convex queries.\n *\n * `useQueries` is similar to {@link useQuery} but it allows\n * loading multiple queries which can be useful for loading a dynamic number\n * of queries without violating the rules of React hooks.\n *\n * This hook accepts an object whose keys are identifiers for each query and the\n * values are objects of\n * `{ query: FunctionReference | FunctionReference_future, args: Record<string, Value> }`.\n * The `query` is a reference to the Convex query function to load, and the\n * `args` are the arguments to that function.\n *\n * The hook returns an object that maps each identifier to the result of the query,\n * `undefined` if the query is still loading, or an instance of `Error` if the query\n * threw an exception.\n *\n * For example if you loaded a query like:\n * ```typescript\n * const results = useQueries({\n * messagesInGeneral: {\n * query: \"listMessages\",\n * args: { channel: \"#general\" }\n * }\n * });\n * ```\n * then the result would look like:\n * ```typescript\n * {\n * messagesInGeneral: [{\n * channel: \"#general\",\n * body: \"hello\"\n * _id: ...,\n * _creationTime: ...\n * }]\n * }\n * ```\n *\n * This React hook contains internal state that will cause a rerender\n * whenever any of the query results change.\n *\n * Throws an error if not used under {@link ConvexProvider}.\n *\n * @param queries - An object mapping identifiers to objects of\n * `{query: string, args: Record<string, Value> }` describing which query\n * functions to fetch.\n * @returns An object with the same keys as the input. The values are the result\n * of the query function, `undefined` if it's still loading, or an `Error` if\n * it threw an exception.\n *\n * @public\n */\nexport function useQueries(\n queries: RequestForQueriesCompat,\n): Record<string, any | undefined | Error> {\n const convex = useConvex();\n if (convex === undefined) {\n // Error message includes `useQuery` because this hook is called by `useQuery`\n // more often than it's called directly.\n throw new Error(\n \"Could not find Convex client! `useQuery` must be used in the React component \" +\n \"tree under `ConvexProvider`. Did you forget it? \" +\n \"See https://docs.convex.dev/quick-start#set-up-convex-in-your-react-app\",\n );\n }\n const createWatch = useMemo(() => {\n return (\n query: FunctionReference<\"query\"> | FunctionReference_future<\"query\">,\n args: Record<string, Value>,\n {\n journal,\n paginationOptions,\n }: {\n journal?: QueryJournal;\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n },\n ) => {\n if (paginationOptions) {\n return convex.watchPaginatedQuery(query, args, paginationOptions);\n } else {\n return convex.watchQuery(query, args, journal ? { journal } : {});\n }\n };\n }, [convex]);\n return useQueriesHelper(queries, createWatch);\n}\n\n/**\n * Internal version of `useQueries` that is exported for testing.\n */\nexport function useQueriesHelper(\n queries: RequestForQueriesCompat,\n createWatch: CreateWatch,\n): Record<string, any | undefined | Error> {\n const [observer] = useState(() => new QueriesObserver(createWatch));\n\n if (observer.createWatch !== createWatch) {\n observer.setCreateWatch(createWatch);\n }\n\n // Unsubscribe from all queries on unmount.\n useEffect(() => () => observer.destroy(), [observer]);\n\n const subscription = useMemo(\n () => ({\n getCurrentValue: () => {\n return observer.getLocalResults(queries);\n },\n subscribe: (callback: () => void) => {\n observer.setQueries(queries);\n return observer.subscribe(callback);\n },\n }),\n [observer, queries],\n );\n\n return useSubscription(subscription);\n}\n\n/**\n * An object representing a request to load multiple queries.\n *\n * The keys of this object are identifiers and the values are objects containing\n * the query function and the arguments to pass to it.\n *\n * This is used as an argument to {@link useQueries}.\n * @public\n */\nexport type RequestForQueries = Record<\n string,\n {\n query: FunctionReference<\"query\">;\n args: Record<string, Value>;\n /** @internal */\n paginationOptions?: SubscribeToPaginatedQueryOptions;\n }\n>;\n\n// The `queries` parameter of `useQueries`: `RequestForQueries` with `query`\n// also accepting a `FunctionReference_future`. The exported type stays a plain\n// reference so that code reading a `query` out of one gets a\n// `FunctionReference` it can forward anywhere. Module-local so that a\n// consumer's declaration file inlines it rather than importing it from a path\n// outside the package's public entry points.\ntype RequestForQueriesCompat = Record<\n string,\n {\n query: FunctionReference<\"query\"> | FunctionReference_future<\"query\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1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/server/api.ts"],
4
- "sourcesContent": ["import {\n EmptyObject,\n DefaultFunctionArgs,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"./registration.js\";\nimport { Expand, UnionToIntersection } from \"../type_utils.js\";\nimport { PaginationOptions, PaginationResult } from \"./pagination.js\";\nimport { functionName } from \"./functionName.js\";\nimport { getFunctionAddress } from \"./components/paths.js\";\n\n/**\n * The type of a Convex function.\n *\n * @public\n */\nexport type FunctionType = \"query\" | \"mutation\" | \"action\";\n\n/**\n * A reference to a registered Convex function.\n *\n * You can create a {@link FunctionReference} using the generated `api` utility:\n * ```js\n * import { api } from \"../convex/_generated/api\";\n *\n * const reference = api.myModule.myFunction;\n * ```\n *\n * If you aren't using code generation, you can create references using\n * {@link anyApi}:\n * ```js\n * import { anyApi } from \"convex/server\";\n *\n * const reference = anyApi.myModule.myFunction;\n * ```\n *\n * Function references can be used to invoke functions from the client. For\n * example, in React you can pass references to the {@link react.useQuery} hook:\n * ```js\n * const result = useQuery(api.myModule.myFunction);\n * ```\n *\n * @typeParam Type - The type of the function (\"query\", \"mutation\", or \"action\").\n * @typeParam Visibility - The visibility of the function (\"public\" or \"internal\").\n * @typeParam Args - The arguments to this function. This is an object mapping\n * argument names to their types.\n * @typeParam ReturnType - The return type of this function.\n * @public\n */\nexport type FunctionReference<\n Type extends FunctionType,\n Visibility extends FunctionVisibility = \"public\",\n Args extends DefaultFunctionArgs = any,\n ReturnType = any,\n ComponentPath = string | undefined,\n> = {\n _type: Type;\n _visibility: Visibility;\n _args: Args;\n _returnType: ReturnType;\n _componentPath: ComponentPath;\n};\n\n/**\n * Get the name of a function from a {@link FunctionReference}.\n *\n * The name is a string like \"myDir/myModule:myFunction\". If the exported name\n * of the function is `\"default\"`, the function name is omitted\n * (e.g. \"myDir/myModule\").\n *\n * @param functionReference - A {@link FunctionReference} to get the name of.\n * @returns A string of the function's name.\n *\n * @public\n */\nexport function getFunctionName(\n functionReference: AnyFunctionReference,\n): string {\n const address = getFunctionAddress(functionReference);\n\n if (address.name === undefined) {\n if (address.functionHandle !== undefined) {\n throw new Error(\n `Expected function reference like \"api.file.func\" or \"internal.file.func\", but received function handle ${address.functionHandle}`,\n );\n } else if (address.reference !== undefined) {\n throw new Error(\n `Expected function reference in the current component like \"api.file.func\" or \"internal.file.func\", but received reference ${address.reference}`,\n );\n }\n throw new Error(\n `Expected function reference like \"api.file.func\" or \"internal.file.func\", but received ${JSON.stringify(address)}`,\n );\n }\n // Both a legacy thing and also a convenience for interactive use:\n // the types won't check but a string is always allowed at runtime.\n if (typeof functionReference === \"string\") return functionReference;\n\n // Two different runtime values for FunctionReference implement this\n // interface: api objects returned from `createApi()` and standalone\n // function reference objects returned from makeFunctionReference.\n const name = (functionReference as any)[functionName];\n if (!name) {\n throw new Error(`${functionReference as any} is not a functionReference`);\n }\n return name;\n}\n\n/**\n * FunctionReferences generally come from generated code, but in custom clients\n * it may be useful to be able to build one manually.\n *\n * Real function references are empty objects at runtime, but the same interface\n * can be implemented with an object for tests and clients which don't use\n * code generation.\n *\n * @param name - The identifier of the function. E.g. `path/to/file:functionName`\n * @public\n */\nexport function makeFunctionReference<\n type extends FunctionType,\n args extends DefaultFunctionArgs = any,\n ret = any,\n>(name: string): FunctionReference<type, \"public\", args, ret> {\n return { [functionName]: name } as unknown as FunctionReference<\n type,\n \"public\",\n args,\n ret\n >;\n}\n\n/**\n * Create a runtime API object that implements {@link AnyApi}.\n *\n * This allows accessing any path regardless of what directories, modules,\n * or functions are defined.\n *\n * @param pathParts - The path to the current node in the API.\n * @returns An {@link AnyApi}\n * @public\n */\nfunction createApi(pathParts: string[] = []): AnyApi {\n const handler: ProxyHandler<object> = {\n get(_, prop: string | symbol) {\n if (typeof prop === \"string\") {\n const newParts = [...pathParts, prop];\n return createApi(newParts);\n } else if (prop === functionName) {\n if (pathParts.length < 2) {\n const found = [\"api\", ...pathParts].join(\".\");\n throw new Error(\n `API path is expected to be of the form \\`api.moduleName.functionName\\`. Found: \\`${found}\\``,\n );\n }\n const path = pathParts.slice(0, -1).join(\"/\");\n const exportName = pathParts[pathParts.length - 1];\n if (exportName === \"default\") {\n return path;\n } else {\n return path + \":\" + exportName;\n }\n } else if (prop === Symbol.toStringTag) {\n return \"FunctionReference\";\n } else {\n return undefined;\n }\n },\n };\n\n return new Proxy({}, handler);\n}\n\n/**\n * Given an export from a module, convert it to a {@link FunctionReference}\n * if it is a Convex function.\n */\nexport type FunctionReferenceFromExport<Export> =\n Export extends RegisteredQuery<\n infer Visibility,\n infer Args,\n infer ReturnValue\n >\n ? FunctionReference<\n \"query\",\n Visibility,\n Args,\n ConvertReturnType<ReturnValue>\n >\n : Export extends RegisteredMutation<\n infer Visibility,\n infer Args,\n infer ReturnValue\n >\n ? FunctionReference<\n \"mutation\",\n Visibility,\n Args,\n ConvertReturnType<ReturnValue>\n >\n : Export extends RegisteredAction<\n infer Visibility,\n infer Args,\n infer ReturnValue\n >\n ? FunctionReference<\n \"action\",\n Visibility,\n Args,\n ConvertReturnType<ReturnValue>\n >\n : never;\n\n/**\n * Given a module, convert all the Convex functions into\n * {@link FunctionReference}s and remove the other exports.\n *\n * BE CAREFUL WHEN EDITING THIS!\n *\n * This is written carefully to preserve jumping to function definitions using\n * cmd+click. If you edit it, please test that cmd+click still works.\n */\ntype FunctionReferencesInModule<Module extends Record<string, any>> = {\n -readonly [ExportName in keyof Module as Module[ExportName][\"isConvexFunction\"] extends true\n ? ExportName\n : never]: FunctionReferenceFromExport<Module[ExportName]>;\n};\n\n/**\n * Given a path to a module and it's type, generate an API type for this module.\n *\n * This is a nested object according to the module's path.\n */\ntype ApiForModule<\n ModulePath extends string,\n Module extends object,\n> = ModulePath extends `${infer First}/${infer Second}`\n ? {\n [_ in First]: ApiForModule<Second, Module>;\n }\n : { [_ in ModulePath]: FunctionReferencesInModule<Module> };\n\n/**\n * Given the types of all modules in the `convex/` directory, construct the type\n * of `api`.\n *\n * `api` is a utility for constructing {@link FunctionReference}s.\n *\n * @typeParam AllModules - A type mapping module paths (like `\"dir/myModule\"`) to\n * the types of the modules.\n * @public\n */\nexport type ApiFromModules<AllModules extends Record<string, object>> =\n FilterApi<\n ApiFromModulesAllowEmptyNodes<AllModules>,\n FunctionReference<any, any, any, any>\n >;\n\ntype ApiFromModulesAllowEmptyNodes<AllModules extends Record<string, object>> =\n ExpandModulesAndDirs<\n UnionToIntersection<\n {\n [ModulePath in keyof AllModules]: ApiForModule<\n ModulePath & string,\n AllModules[ModulePath]\n >;\n }[keyof AllModules]\n >\n >;\n\ntype FilterKeysInApi<key, API, Predicate> = API extends Predicate\n ? key\n : API extends FunctionReference<any, any, any, any>\n ? never\n : FilterApi<API, Predicate> extends Record<string, never>\n ? never\n : key;\n\n/**\n * @public\n *\n * Filter a Convex deployment api object for functions which meet criteria,\n * for example all public queries.\n */\nexport type FilterApi<API, Predicate> = Expand<{\n [mod in keyof API as FilterKeysInApi<\n mod,\n API[mod],\n Predicate\n >]: API[mod] extends Predicate ? API[mod] : FilterApi<API[mod], Predicate>;\n}>;\n\n/**\n * Given an api of type API and a FunctionReference subtype, return an api object\n * containing only the function references that match.\n *\n * ```ts\n * const q = filterApi<typeof api, FunctionReference<\"query\">>(api)\n * ```\n *\n * @public\n */\nexport function filterApi<API, Predicate>(api: API): FilterApi<API, Predicate> {\n return api as any;\n}\n\n// These just* API filter helpers require no type parameters so are useable from JavaScript.\n/** @public */\nexport function justInternal<API>(\n api: API,\n): FilterApi<API, FunctionReference<any, \"internal\", any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justPublic<API>(\n api: API,\n): FilterApi<API, FunctionReference<any, \"public\", any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justQueries<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"query\", any, any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justMutations<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"mutation\", any, any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justActions<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"action\", any, any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justPaginatedQueries<API>(\n api: API,\n): FilterApi<\n API,\n FunctionReference<\n \"query\",\n any,\n { paginationOpts: PaginationOptions },\n PaginationResult<any>\n >\n> {\n return api as any;\n}\n\n/** @public */\nexport function justSchedulable<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"mutation\" | \"action\", any, any, any>> {\n return api as any;\n}\n\n/**\n * Like {@link Expand}, this simplifies how TypeScript displays object types.\n * The differences are:\n * 1. This version is recursive.\n * 2. This stops recursing when it hits a {@link FunctionReference}.\n */\ntype ExpandModulesAndDirs<ObjectType> = ObjectType extends AnyFunctionReference\n ? ObjectType\n : {\n [Key in keyof ObjectType]: ExpandModulesAndDirs<ObjectType[Key]>;\n };\n\n/**\n * A {@link FunctionReference} of any type and any visibility with any\n * arguments and any return type.\n *\n * @public\n */\nexport type AnyFunctionReference = FunctionReference<any, any>;\n\ntype AnyModuleDirOrFunc = {\n [key: string]: AnyModuleDirOrFunc;\n} & AnyFunctionReference;\n\n/**\n * The type that Convex api objects extend. If you were writing an api from\n * scratch it should extend this type.\n *\n * @public\n */\nexport type AnyApi = Record<string, Record<string, AnyModuleDirOrFunc>>;\n\n/**\n * Recursive partial API, useful for defining a subset of an API when mocking\n * or building custom api objects.\n *\n * @public\n */\nexport type PartialApi<API> = {\n [mod in keyof API]?: API[mod] extends FunctionReference<any, any, any, any>\n ? API[mod]\n : PartialApi<API[mod]>;\n};\n\n/**\n * A utility for constructing {@link FunctionReference}s in projects that\n * are not using code generation.\n *\n * You can create a reference to a function like:\n * ```js\n * const reference = anyApi.myModule.myFunction;\n * ```\n *\n * This supports accessing any path regardless of what directories and modules\n * are in your project. All function references are typed as\n * {@link AnyFunctionReference}.\n *\n *\n * If you're using code generation, use `api` from `convex/_generated/api`\n * instead. It will be more type-safe and produce better auto-complete\n * in your editor.\n *\n * @public\n */\nexport const anyApi: AnyApi = createApi() as any;\n\n/**\n * Given a {@link FunctionReference}, get the return type of the function.\n *\n * This is represented as an object mapping argument names to values.\n * @public\n */\nexport type FunctionArgs<FuncRef extends AnyFunctionReference> =\n FuncRef[\"_args\"];\n\n/**\n * A tuple type of the (maybe optional) arguments to `FuncRef`.\n *\n * This type is used to make methods involving arguments type safe while allowing\n * skipping the arguments for functions that don't require arguments.\n *\n * @public\n */\nexport type OptionalRestArgs<FuncRef extends AnyFunctionReference> =\n FuncRef[\"_args\"] extends EmptyObject\n ? [args?: EmptyObject]\n : [args: FuncRef[\"_args\"]];\n\n/**\n * A tuple type of the (maybe optional) arguments to `FuncRef`, followed by an options\n * object of type `Options`.\n *\n * This type is used to make methods like `useQuery` type-safe while allowing\n * 1. Skipping arguments for functions that don't require arguments.\n * 2. Skipping the options object.\n * @public\n */\nexport type ArgsAndOptions<\n FuncRef extends AnyFunctionReference,\n Options,\n> = FuncRef[\"_args\"] extends EmptyObject\n ? [args?: EmptyObject, options?: Options]\n : [args: FuncRef[\"_args\"], options?: Options];\n\n/**\n * Given a {@link FunctionReference}, get the return type of the function.\n *\n * @public\n */\nexport type FunctionReturnType<FuncRef extends AnyFunctionReference> =\n FuncRef[\"_returnType\"];\n\ntype UndefinedToNull<T> = T extends void ? null : T;\n\ntype NullToUndefinedOrNull<T> = T extends null ? T | undefined | void : T;\n\n/**\n * Convert the return type of a function to it's client-facing format.\n *\n * This means:\n * - Converting `undefined` and `void` to `null`\n * - Removing all `Promise` wrappers\n */\nexport type ConvertReturnType<T> = UndefinedToNull<Awaited<T>>;\n\nexport type ValidatorTypeToReturnType<T> =\n | Promise<NullToUndefinedOrNull<T>>\n | NullToUndefinedOrNull<T>;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,0BAA6B;AAC7B,mBAAmC;AAkE5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AO,aAAa;AACtC,eAAO;AAAA,MACT,OAAO;AACL,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO,IAAI,MAAM,CAAC,GAAG,OAAO;AAC9B;AAmIO,SAAS,UAA0B,KAAqC;AAC7E,SAAO;AACT;AAIO,SAAS,aACd,KAC8D;AAC9D,SAAO;AACT;AAGO,SAAS,WACd,KAC4D;AAC5D,SAAO;AACT;AAGO,SAAS,YACd,KAC2D;AAC3D,SAAO;AACT;AAGO,SAAS,cACd,KAC8D;AAC9D,SAAO;AACT;AAGO,SAAS,YACd,KAC4D;AAC5D,SAAO;AACT;AAGO,SAAS,qBACd,KASA;AACA,SAAO;AACT;AAGO,SAAS,gBACd,KACyE;AACzE,SAAO;AACT;AAkEO,MAAM,SAAiB,UAAU;",
4
+ "sourcesContent": ["import {\n EmptyObject,\n DefaultFunctionArgs,\n FunctionVisibility,\n RegisteredAction,\n RegisteredMutation,\n RegisteredQuery,\n} from \"./registration.js\";\nimport { Expand, UnionToIntersection } from \"../type_utils.js\";\nimport { PaginationOptions, PaginationResult } from \"./pagination.js\";\nimport { functionName } from \"./functionName.js\";\nimport { getFunctionAddress } from \"./components/paths.js\";\n\n/**\n * The type of a Convex function.\n *\n * @public\n */\nexport type FunctionType = \"query\" | \"mutation\" | \"action\";\n\n/**\n * A reference to a registered Convex function.\n *\n * You can create a {@link FunctionReference} using the generated `api` utility:\n * ```js\n * import { api } from \"../convex/_generated/api\";\n *\n * const reference = api.myModule.myFunction;\n * ```\n *\n * If you aren't using code generation, you can create references using\n * {@link anyApi}:\n * ```js\n * import { anyApi } from \"convex/server\";\n *\n * const reference = anyApi.myModule.myFunction;\n * ```\n *\n * Function references can be used to invoke functions from the client. For\n * example, in React you can pass references to the {@link react.useQuery} hook:\n * ```js\n * const result = useQuery(api.myModule.myFunction);\n * ```\n *\n * If you want to accept a `FunctionReference` as a callback argument, prefer\n * typing the callback parameter as {@link FunctionReference_future}.\n *\n * @typeParam Type - The type of the function (\"query\", \"mutation\", or \"action\").\n * @typeParam Visibility - The visibility of the function (\"public\" or \"internal\").\n * @typeParam Args - The arguments to this function. This is an object mapping\n * argument names to their types.\n * @typeParam ReturnType - The return type of this function.\n * @public\n */\nexport type FunctionReference<\n Type extends FunctionType,\n Visibility extends FunctionVisibility = \"public\",\n Args extends DefaultFunctionArgs = any,\n ReturnType = any,\n ComponentPath = string | undefined,\n> = {\n _type: Type;\n _visibility: Visibility;\n /**\n * To read the arguments for a `FunctionReference`, prefer\n * {@link FunctionArgs}.\n *\n * This slot will be removed in a future version.\n *\n * @deprecated\n */\n _args: Args;\n /**\n * To read the return type of a `FunctionReference`, prefer\n * {@link FunctionReturnType}.\n *\n * This slot will be removed in a future version.\n *\n * @deprecated\n */\n _returnType: ReturnType;\n _componentPath: ComponentPath;\n /**\n * To read the arguments or return type of a `FunctionReference`, prefer\n * {@link FunctionArgs} and {@link FunctionReturnType}.\n */\n // This phantom slot exists so that a `FunctionReference` can be checked\n // against a `FunctionReference_future`. It changes nothing about how two\n // `FunctionReference`s compare with each other.\n //\n // The slot models the function itself: it puts `Args` in a contravariant\n // position and `ReturnType` in a covariant one, so the slot alone is enough\n // to compare a reference the way TypeScript compares two functions.\n //\n // In that comparison the `keys` parameter has an important role. It carries\n // the keys of `Args`, so that checking a `FunctionReference` against a\n // `FunctionReference_future` also checks that every key the consumer passes\n // is a key the function declares. TypeScript treats a surplus property as\n // harmless, but a Convex argument validator rejects it, so this is what\n // makes the comparison match the runtime. See `FunctionReferenceArgKeys`.\n _fn?(args: Args, keys: FunctionReferenceArgKeys<Args>): ReturnType;\n};\n\n/**\n * The keys of a reference's arguments.\n *\n * `0 extends 1 & Args` holds only when `Args` is `any`. That maps to `any`\n * rather than `keyof any` so that an untyped reference neither imposes nor\n * fails the key check in either direction. Arguments with an index signature,\n * such as `EmptyObject` and `DefaultFunctionArgs`, map to `string`, which\n * accepts every key and leaves the decision to the first parameter.\n */\ntype ArgKeys<Args> = 0 extends 1 & Args ? any : keyof Args;\n\n/**\n * The second parameter of `FunctionReference._fn`.\n *\n * Wrapping the keys in a function of a function puts them two parameters deep,\n * so comparing this parameter contravariantly checks that every key the\n * consumer passes is one the function declares. That is the check a Convex\n * argument validator performs and an ordinary function-type comparison skips.\n *\n * The union with {@link UncheckedArgKeys} is what keeps two\n * `FunctionReference`s comparing as they did before this slot existed. Every\n * `FunctionReferenceArgKeys` is assignable to `UncheckedArgKeys`, so between\n * two `FunctionReference`s the keys always relate and only `_args` decides.\n * {@link FunctionReference_futureArgKeys} is not assignable to it, so a\n * `FunctionReference` compared against a `FunctionReference_future` has to\n * satisfy the real check.\n */\ntype FunctionReferenceArgKeys<Args> = 0 extends 1 & Args\n ? any\n : ((keys: (key: ArgKeys<Args>) => void) => void) | UncheckedArgKeys;\n\n/**\n * A keys parameter that every {@link FunctionReferenceArgKeys} is assignable\n * to, and that no {@link FunctionReference_futureArgKeys} is: `unknown` for\n * the second parameter accepts the former's missing parameter and rejects the\n * latter's `never`.\n */\ntype UncheckedArgKeys = (keys: never, unchecked?: unknown) => void;\n\n/**\n * The second parameter of `FunctionReference_future._fn`. The same shape as\n * {@link FunctionReferenceArgKeys} plus a `guard` parameter that keeps it out\n * of {@link UncheckedArgKeys}.\n */\ntype FunctionReference_futureArgKeys<Args> = 0 extends 1 & Args\n ? any\n : (keys: (key: ArgKeys<Args>) => void, guard?: never) => void;\n\n/**\n * A reference to a Convex function whose arguments are checked closer to the\n * way Convex checks them at runtime.\n *\n * Use this instead of {@link FunctionReference} when you accept someone else's\n * Convex function as a callback and know which arguments you will pass it.\n *\n * A plain `FunctionReference` gets a couple things backwards: it accepts a\n * function requiring arguments you never pass, and rejects a function\n * accepting broader values than you pass. An ordinary TypeScript function type\n * doesn't map perfectly either: it treats a surplus argument as harmless,\n * where a Convex validator rejects it.\n *\n * This type melds regular TypeScript function reference behavior with top\n * level checking of arguments to prevent surplus arguments from hitting\n * runtime validation errors. The caveat: a surplus key inside a nested object,\n * an array element, or one arm of a union passes the type check and fails the\n * validator at runtime.\n *\n * ```ts\n * import { FunctionReference_future } from \"convex/server\";\n *\n * declare function onComplete(\n * fn: FunctionReference_future<\n * \"mutation\",\n * \"internal\",\n * { taskId: string; force: boolean },\n * null\n * >,\n * ): void;\n *\n * // Takes exactly `{ taskId: string; force: boolean }`.\n * onComplete(internal.tasks.finish);\n * // Takes `{ taskId: string | number; force?: boolean }`: calling it is safe.\n * onComplete(internal.tasks.finishLoosely);\n * // Requires a `reason` argument that `onComplete` never passes.\n * onComplete(internal.tasks.finishWithReason);\n * // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rejected\n * // Takes only `{ taskId: string }`: its validator would reject `force`.\n * onComplete(internal.tasks.finishById);\n * // ~~~~~~~~~~~~~~~~~~~~~~~~ rejected\n * ```\n *\n * A value of this type is usable with `ctx.runMutation`,\n * `ctx.scheduler.runAfter`, `createFunctionHandle`, and everything else in\n * this package that takes a reference, all of which accept either kind.\n *\n * It is *not* assignable to a plain `FunctionReference`. Code that wants to\n * accept both kinds should take\n * `FunctionReference<...> | FunctionReference_future<...>` and read arguments\n * and return types through {@link FunctionArgs} and {@link FunctionReturnType}.\n *\n * Argument checking here relies on `strictFunctionTypes` (implied by `strict`)\n * and is skipped for projects that disable it. Everything else about the\n * reference is compared exactly as `FunctionReference` compares it.\n *\n * @typeParam Type - The type of the function (\"query\", \"mutation\", or \"action\").\n * @typeParam Visibility - The visibility of the function (\"public\" or \"internal\").\n * @typeParam Args - The arguments the consumer of the reference will pass.\n * @typeParam ReturnType - The return type of this function.\n * @public\n */\nexport type FunctionReference_future<\n Type extends FunctionType,\n Visibility extends FunctionVisibility = \"public\",\n Args extends DefaultFunctionArgs = any,\n ReturnType = any,\n ComponentPath = string | undefined,\n> = {\n _type: Type;\n _visibility: Visibility;\n _componentPath: ComponentPath;\n // Declared as a *property* rather than a method: TypeScript compares method\n // parameters bivariantly and would not check anything. The explicit\n // `| undefined` is needed because an optional method on the source side\n // (`FunctionReference._fn`) carries a real `undefined` in its type, which\n // `exactOptionalPropertyTypes` would otherwise reject.\n //\n // Both parameters are compared contravariantly: the first checks that the\n // consumer's arguments satisfy the function's, the second that the consumer\n // passes no key the function does not declare. See\n // `FunctionReference_futureArgKeys`.\n _fn?:\n | ((args: Args, keys: FunctionReference_futureArgKeys<Args>) => ReturnType)\n | undefined;\n};\n\n/**\n * Get the name of a function from a {@link FunctionReference}.\n *\n * The name is a string like \"myDir/myModule:myFunction\". If the exported name\n * of the function is `\"default\"`, the function name is omitted\n * (e.g. \"myDir/myModule\").\n *\n * @param functionReference - A {@link FunctionReference} to get the name of.\n * @returns A string of the function's name.\n *\n * @public\n */\nexport function getFunctionName(\n functionReference:\n | FunctionReference<any, any>\n | FunctionReference_future<any, any>,\n): string {\n const address = getFunctionAddress(functionReference);\n\n if (address.name === undefined) {\n if (address.functionHandle !== undefined) {\n throw new Error(\n `Expected function reference like \"api.file.func\" or \"internal.file.func\", but received function handle ${address.functionHandle}`,\n );\n } else if (address.reference !== undefined) {\n throw new Error(\n `Expected function reference in the current component like \"api.file.func\" or \"internal.file.func\", but received reference ${address.reference}`,\n );\n }\n throw new Error(\n `Expected function reference like \"api.file.func\" or \"internal.file.func\", but received ${JSON.stringify(address)}`,\n );\n }\n // Both a legacy thing and also a convenience for interactive use:\n // the types won't check but a string is always allowed at runtime.\n if (typeof functionReference === \"string\") return functionReference;\n\n // Two different runtime values for FunctionReference implement this\n // interface: api objects returned from `createApi()` and standalone\n // function reference objects returned from makeFunctionReference.\n const name = (functionReference as any)[functionName];\n if (!name) {\n throw new Error(`${functionReference as any} is not a functionReference`);\n }\n return name;\n}\n\n/**\n * FunctionReferences generally come from generated code, but in custom clients\n * it may be useful to be able to build one manually.\n *\n * Real function references are empty objects at runtime, but the same interface\n * can be implemented with an object for tests and clients which don't use\n * code generation.\n *\n * @param name - The identifier of the function. E.g. `path/to/file:functionName`\n * @public\n */\nexport function makeFunctionReference<\n type extends FunctionType,\n args extends DefaultFunctionArgs = any,\n ret = any,\n>(name: string): FunctionReference<type, \"public\", args, ret> {\n return { [functionName]: name } as unknown as FunctionReference<\n type,\n \"public\",\n args,\n ret\n >;\n}\n\n/**\n * Create a runtime API object that implements {@link AnyApi}.\n *\n * This allows accessing any path regardless of what directories, modules,\n * or functions are defined.\n *\n * @param pathParts - The path to the current node in the API.\n * @returns An {@link AnyApi}\n * @public\n */\nfunction createApi(pathParts: string[] = []): AnyApi {\n const handler: ProxyHandler<object> = {\n get(_, prop: string | symbol) {\n if (typeof prop === \"string\") {\n const newParts = [...pathParts, prop];\n return createApi(newParts);\n } else if (prop === functionName) {\n if (pathParts.length < 2) {\n const found = [\"api\", ...pathParts].join(\".\");\n throw new Error(\n `API path is expected to be of the form \\`api.moduleName.functionName\\`. Found: \\`${found}\\``,\n );\n }\n const path = pathParts.slice(0, -1).join(\"/\");\n const exportName = pathParts[pathParts.length - 1];\n if (exportName === \"default\") {\n return path;\n } else {\n return path + \":\" + exportName;\n }\n } else if (prop === Symbol.toStringTag) {\n return \"FunctionReference\";\n } else {\n return undefined;\n }\n },\n };\n\n return new Proxy({}, handler);\n}\n\n/**\n * Given an export from a module, convert it to a {@link FunctionReference}\n * if it is a Convex function.\n */\nexport type FunctionReferenceFromExport<Export> =\n Export extends RegisteredQuery<\n infer Visibility,\n infer Args,\n infer ReturnValue\n >\n ? FunctionReference<\n \"query\",\n Visibility,\n Args,\n ConvertReturnType<ReturnValue>\n >\n : Export extends RegisteredMutation<\n infer Visibility,\n infer Args,\n infer ReturnValue\n >\n ? FunctionReference<\n \"mutation\",\n Visibility,\n Args,\n ConvertReturnType<ReturnValue>\n >\n : Export extends RegisteredAction<\n infer Visibility,\n infer Args,\n infer ReturnValue\n >\n ? FunctionReference<\n \"action\",\n Visibility,\n Args,\n ConvertReturnType<ReturnValue>\n >\n : never;\n\n/**\n * Given a module, convert all the Convex functions into\n * {@link FunctionReference}s and remove the other exports.\n *\n * BE CAREFUL WHEN EDITING THIS!\n *\n * This is written carefully to preserve jumping to function definitions using\n * cmd+click. If you edit it, please test that cmd+click still works.\n */\ntype FunctionReferencesInModule<Module extends Record<string, any>> = {\n -readonly [ExportName in keyof Module as Module[ExportName][\"isConvexFunction\"] extends true\n ? ExportName\n : never]: FunctionReferenceFromExport<Module[ExportName]>;\n};\n\n/**\n * Given a path to a module and it's type, generate an API type for this module.\n *\n * This is a nested object according to the module's path.\n */\ntype ApiForModule<\n ModulePath extends string,\n Module extends object,\n> = ModulePath extends `${infer First}/${infer Second}`\n ? {\n [_ in First]: ApiForModule<Second, Module>;\n }\n : { [_ in ModulePath]: FunctionReferencesInModule<Module> };\n\n/**\n * Given the types of all modules in the `convex/` directory, construct the type\n * of `api`.\n *\n * `api` is a utility for constructing {@link FunctionReference}s.\n *\n * @typeParam AllModules - A type mapping module paths (like `\"dir/myModule\"`) to\n * the types of the modules.\n * @public\n */\nexport type ApiFromModules<AllModules extends Record<string, object>> =\n FilterApi<\n ApiFromModulesAllowEmptyNodes<AllModules>,\n FunctionReference<any, any, any, any>\n >;\n\ntype ApiFromModulesAllowEmptyNodes<AllModules extends Record<string, object>> =\n ExpandModulesAndDirs<\n UnionToIntersection<\n {\n [ModulePath in keyof AllModules]: ApiForModule<\n ModulePath & string,\n AllModules[ModulePath]\n >;\n }[keyof AllModules]\n >\n >;\n\ntype FilterKeysInApi<key, API, Predicate> = API extends Predicate\n ? key\n : API extends FunctionReference<any, any, any, any>\n ? never\n : FilterApi<API, Predicate> extends Record<string, never>\n ? never\n : key;\n\n/**\n * @public\n *\n * Filter a Convex deployment api object for functions which meet criteria,\n * for example all public queries.\n */\nexport type FilterApi<API, Predicate> = Expand<{\n [mod in keyof API as FilterKeysInApi<\n mod,\n API[mod],\n Predicate\n >]: API[mod] extends Predicate ? API[mod] : FilterApi<API[mod], Predicate>;\n}>;\n\n/**\n * Given an api of type API and a FunctionReference subtype, return an api object\n * containing only the function references that match.\n *\n * ```ts\n * const q = filterApi<typeof api, FunctionReference<\"query\">>(api)\n * ```\n *\n * @public\n */\nexport function filterApi<API, Predicate>(api: API): FilterApi<API, Predicate> {\n return api as any;\n}\n\n// These just* API filter helpers require no type parameters so are useable from JavaScript.\n/** @public */\nexport function justInternal<API>(\n api: API,\n): FilterApi<API, FunctionReference<any, \"internal\", any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justPublic<API>(\n api: API,\n): FilterApi<API, FunctionReference<any, \"public\", any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justQueries<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"query\", any, any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justMutations<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"mutation\", any, any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justActions<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"action\", any, any, any>> {\n return api as any;\n}\n\n/** @public */\nexport function justPaginatedQueries<API>(\n api: API,\n): FilterApi<\n API,\n FunctionReference<\n \"query\",\n any,\n { paginationOpts: PaginationOptions },\n PaginationResult<any>\n >\n> {\n return api as any;\n}\n\n/** @public */\nexport function justSchedulable<API>(\n api: API,\n): FilterApi<API, FunctionReference<\"mutation\" | \"action\", any, any, any>> {\n return api as any;\n}\n\n/**\n * Like {@link Expand}, this simplifies how TypeScript displays object types.\n * The differences are:\n * 1. This version is recursive.\n * 2. This stops recursing when it hits a {@link FunctionReference}.\n */\ntype ExpandModulesAndDirs<ObjectType> = ObjectType extends AnyFunctionReference\n ? ObjectType\n : {\n [Key in keyof ObjectType]: ExpandModulesAndDirs<ObjectType[Key]>;\n };\n\n/**\n * A {@link FunctionReference} of any type and any visibility with any\n * arguments and any return type.\n *\n * @public\n */\nexport type AnyFunctionReference = FunctionReference<any, any>;\n\ntype AnyModuleDirOrFunc = {\n [key: string]: AnyModuleDirOrFunc;\n} & AnyFunctionReference;\n\n/**\n * The type that Convex api objects extend. If you were writing an api from\n * scratch it should extend this type.\n *\n * @public\n */\nexport type AnyApi = Record<string, Record<string, AnyModuleDirOrFunc>>;\n\n/**\n * Recursive partial API, useful for defining a subset of an API when mocking\n * or building custom api objects.\n *\n * @public\n */\nexport type PartialApi<API> = {\n [mod in keyof API]?: API[mod] extends FunctionReference<any, any, any, any>\n ? API[mod]\n : PartialApi<API[mod]>;\n};\n\n/**\n * A utility for constructing {@link FunctionReference}s in projects that\n * are not using code generation.\n *\n * You can create a reference to a function like:\n * ```js\n * const reference = anyApi.myModule.myFunction;\n * ```\n *\n * This supports accessing any path regardless of what directories and modules\n * are in your project. All function references are typed as\n * {@link AnyFunctionReference}.\n *\n *\n * If you're using code generation, use `api` from `convex/_generated/api`\n * instead. It will be more type-safe and produce better auto-complete\n * in your editor.\n *\n * @public\n */\nexport const anyApi: AnyApi = createApi() as any;\n\n/**\n * Given a {@link FunctionReference} or {@link FunctionReference_future}, get\n * the arguments of the function.\n *\n * This is represented as an object mapping argument names to values.\n *\n * @public\n */\nexport type FunctionArgs<\n FuncRef extends\n | FunctionReference<any, any>\n | FunctionReference_future<any, any>,\n> = ExtractSignature<FuncRef>[\"args\"];\n\n// The arguments and return type a reference declares. A `FunctionReference`\n// declares them in `_args` and `_returnType`, a `FunctionReference_future`\n// only in its `_fn` slot. Reading the named slots first also covers a\n// reference typed by an older copy of this package, which has no `_fn`.\ntype ExtractSignature<FuncRef> = FuncRef extends {\n _args: infer Args;\n _returnType: infer R;\n}\n ? { args: Args; returnType: R }\n : FuncRef extends {\n _fn?: ((args: infer Args, keys: never) => infer R) | undefined;\n }\n ? { args: Args; returnType: R }\n : { args: any; returnType: any };\n\n/**\n * A tuple type of the (maybe optional) arguments to `FuncRef`.\n *\n * This type is used to make methods involving arguments type safe while allowing\n * skipping the arguments for functions that don't require arguments.\n *\n * @public\n */\nexport type OptionalRestArgs<\n FuncRef extends\n | FunctionReference<any, any>\n | FunctionReference_future<any, any>,\n> =\n FunctionArgs<FuncRef> extends EmptyObject\n ? [args?: EmptyObject]\n : [args: FunctionArgs<FuncRef>];\n\n/**\n * A tuple type of the (maybe optional) arguments to `FuncRef`, followed by an options\n * object of type `Options`.\n *\n * This type is used to make methods like `useQuery` type-safe while allowing\n * 1. Skipping arguments for functions that don't require arguments.\n * 2. Skipping the options object.\n * @public\n */\nexport type ArgsAndOptions<\n FuncRef extends\n | FunctionReference<any, any>\n | FunctionReference_future<any, any>,\n Options,\n> =\n FunctionArgs<FuncRef> extends EmptyObject\n ? [args?: EmptyObject, options?: Options]\n : [args: FunctionArgs<FuncRef>, options?: Options];\n\n/**\n * Given a {@link FunctionReference} or {@link FunctionReference_future}, get\n * the return type of the function.\n *\n * @public\n */\nexport type FunctionReturnType<\n FuncRef extends\n | FunctionReference<any, any>\n | FunctionReference_future<any, any>,\n> = ExtractSignature<FuncRef>[\"returnType\"];\n\ntype UndefinedToNull<T> = T extends void ? null : T;\n\ntype NullToUndefinedOrNull<T> = T extends null ? T | undefined | void : T;\n\n/**\n * Convert the return type of a function to it's client-facing format.\n *\n * This means:\n * - Converting `undefined` and `void` to `null`\n * - Removing all `Promise` wrappers\n */\nexport type ConvertReturnType<T> = UndefinedToNull<Awaited<T>>;\n\nexport type ValidatorTypeToReturnType<T> =\n | Promise<NullToUndefinedOrNull<T>>\n | NullToUndefinedOrNull<T>;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,0BAA6B;AAC7B,mBAAmC;AA+O5B,SAAS,gBACd,mBAGQ;AACR,QAAM,cAAU,iCAAmB,iBAAiB;AAEpD,MAAI,QAAQ,SAAS,QAAW;AAC9B,QAAI,QAAQ,mBAAmB,QAAW;AACxC,YAAM,IAAI;AAAA,QACR,0GAA0G,QAAQ,cAAc;AAAA,MAClI;AAAA,IACF,WAAW,QAAQ,cAAc,QAAW;AAC1C,YAAM,IAAI;AAAA,QACR,6HAA6H,QAAQ,SAAS;AAAA,MAChJ;AAAA,IACF;AACA,UAAM,IAAI;AAAA,MACR,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