convex 1.45.0-alpha.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 (333) hide show
  1. package/CHANGELOG.md +55 -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/indexes.js +1 -1
  34. package/dist/cjs/cli/lib/indexes.js.map +1 -1
  35. package/dist/cjs/cli/lib/localDeployment/run.js +30 -1
  36. package/dist/cjs/cli/lib/localDeployment/run.js.map +2 -2
  37. package/dist/cjs/cli/lib/localDeployment/upgrade.js +6 -5
  38. package/dist/cjs/cli/lib/localDeployment/upgrade.js.map +2 -2
  39. package/dist/cjs/cli/lib/localDeployment/utils.js +5 -1
  40. package/dist/cjs/cli/lib/localDeployment/utils.js.map +2 -2
  41. package/dist/cjs/cli/lib/run.js +1 -0
  42. package/dist/cjs/cli/lib/run.js.map +2 -2
  43. package/dist/cjs/cli/lib/utils/utils.js +36 -29
  44. package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
  45. package/dist/cjs/cli/mcp.js +16 -6
  46. package/dist/cjs/cli/mcp.js.map +2 -2
  47. package/dist/cjs/index.js +1 -1
  48. package/dist/cjs/index.js.map +1 -1
  49. package/dist/cjs/nextjs/index.js.map +2 -2
  50. package/dist/cjs/react/client.js.map +2 -2
  51. package/dist/cjs/react/hydration.js.map +2 -2
  52. package/dist/cjs/react/queries_observer.js.map +2 -2
  53. package/dist/cjs/react/use_paginated_query2.js.map +2 -2
  54. package/dist/cjs/react/use_queries.js.map +2 -2
  55. package/dist/cjs/server/api.js.map +2 -2
  56. package/dist/cjs/server/components/index.js.map +2 -2
  57. package/dist/cjs/server/cron.js +10 -10
  58. package/dist/cjs/server/cron.js.map +2 -2
  59. package/dist/cjs/server/impl/actions_impl.js.map +2 -2
  60. package/dist/cjs/server/impl/meta_impl.js +8 -2
  61. package/dist/cjs/server/impl/meta_impl.js.map +2 -2
  62. package/dist/cjs/server/impl/scheduler_impl.js.map +2 -2
  63. package/dist/cjs/server/index.js.map +2 -2
  64. package/dist/cjs/server/meta.js.map +1 -1
  65. package/dist/cjs/server/registration.js.map +1 -1
  66. package/dist/cjs/server/scheduler.js.map +1 -1
  67. package/dist/cjs/server/schema.js +50 -3
  68. package/dist/cjs/server/schema.js.map +2 -2
  69. package/dist/cjs/values/validator.js +1 -1
  70. package/dist/cjs/values/validator.js.map +2 -2
  71. package/dist/cjs/values/validators.js +81 -25
  72. package/dist/cjs/values/validators.js.map +2 -2
  73. package/dist/cjs-types/browser/http_client.d.ts +5 -5
  74. package/dist/cjs-types/browser/http_client.d.ts.map +1 -1
  75. package/dist/cjs-types/browser/query_options.d.ts +2 -2
  76. package/dist/cjs-types/browser/query_options.d.ts.map +1 -1
  77. package/dist/cjs-types/browser/simple_client.d.ts +6 -6
  78. package/dist/cjs-types/browser/simple_client.d.ts.map +1 -1
  79. package/dist/cjs-types/browser/sync/optimistic_updates.d.ts +4 -4
  80. package/dist/cjs-types/browser/sync/optimistic_updates.d.ts.map +1 -1
  81. package/dist/cjs-types/browser/sync/optimistic_updates_impl.d.ts.map +1 -1
  82. package/dist/cjs-types/cli/codegen.d.ts.map +1 -1
  83. package/dist/cjs-types/cli/docs.d.ts.map +1 -1
  84. package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts +26 -5
  85. package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
  86. package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts +14 -0
  87. package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -0
  88. package/dist/cjs-types/cli/lib/codegen.d.ts +1 -0
  89. package/dist/cjs-types/cli/lib/codegen.d.ts.map +1 -1
  90. package/dist/cjs-types/cli/lib/components.d.ts +1 -0
  91. package/dist/cjs-types/cli/lib/components.d.ts.map +1 -1
  92. package/dist/cjs-types/cli/lib/deploy2.d.ts +6 -0
  93. package/dist/cjs-types/cli/lib/deploy2.d.ts.map +1 -1
  94. package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts +453 -0
  95. package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -0
  96. package/dist/cjs-types/cli/lib/deployApi/finishPush.d.ts +1 -2
  97. package/dist/cjs-types/cli/lib/deployApi/finishPush.d.ts.map +1 -1
  98. package/dist/cjs-types/cli/lib/dev.d.ts.map +1 -1
  99. package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts +2 -0
  100. package/dist/cjs-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
  101. package/dist/cjs-types/cli/lib/localDeployment/run.d.ts +2 -0
  102. package/dist/cjs-types/cli/lib/localDeployment/run.d.ts.map +1 -1
  103. package/dist/cjs-types/cli/lib/localDeployment/upgrade.d.ts.map +1 -1
  104. package/dist/cjs-types/cli/lib/localDeployment/utils.d.ts +1 -0
  105. package/dist/cjs-types/cli/lib/localDeployment/utils.d.ts.map +1 -1
  106. package/dist/cjs-types/cli/lib/run.d.ts.map +1 -1
  107. package/dist/cjs-types/cli/lib/utils/utils.d.ts +5 -5
  108. package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
  109. package/dist/cjs-types/cli/mcp.d.ts.map +1 -1
  110. package/dist/cjs-types/index.d.ts +1 -1
  111. package/dist/cjs-types/index.d.ts.map +1 -1
  112. package/dist/cjs-types/nextjs/index.d.ts +6 -6
  113. package/dist/cjs-types/nextjs/index.d.ts.map +1 -1
  114. package/dist/cjs-types/react/client.d.ts +15 -15
  115. package/dist/cjs-types/react/client.d.ts.map +1 -1
  116. package/dist/cjs-types/react/hydration.d.ts +3 -3
  117. package/dist/cjs-types/react/hydration.d.ts.map +1 -1
  118. package/dist/cjs-types/react/queries_observer.d.ts +9 -9
  119. package/dist/cjs-types/react/queries_observer.d.ts.map +1 -1
  120. package/dist/cjs-types/react/use_paginated_query2.d.ts.map +1 -1
  121. package/dist/cjs-types/react/use_queries.d.ts +14 -6
  122. package/dist/cjs-types/react/use_queries.d.ts.map +1 -1
  123. package/dist/cjs-types/server/api.d.ts +157 -7
  124. package/dist/cjs-types/server/api.d.ts.map +1 -1
  125. package/dist/cjs-types/server/components/index.d.ts +2 -2
  126. package/dist/cjs-types/server/components/index.d.ts.map +1 -1
  127. package/dist/cjs-types/server/cron.d.ts +21 -20
  128. package/dist/cjs-types/server/cron.d.ts.map +1 -1
  129. package/dist/cjs-types/server/impl/actions_impl.d.ts +18 -4
  130. package/dist/cjs-types/server/impl/actions_impl.d.ts.map +1 -1
  131. package/dist/cjs-types/server/impl/meta_impl.d.ts.map +1 -1
  132. package/dist/cjs-types/server/impl/scheduler_impl.d.ts.map +1 -1
  133. package/dist/cjs-types/server/index.d.ts +2 -1
  134. package/dist/cjs-types/server/index.d.ts.map +1 -1
  135. package/dist/cjs-types/server/meta.d.ts.map +1 -1
  136. package/dist/cjs-types/server/registration.d.ts +7 -7
  137. package/dist/cjs-types/server/registration.d.ts.map +1 -1
  138. package/dist/cjs-types/server/scheduler.d.ts +9 -7
  139. package/dist/cjs-types/server/scheduler.d.ts.map +1 -1
  140. package/dist/cjs-types/server/schema.d.ts +1 -0
  141. package/dist/cjs-types/server/schema.d.ts.map +1 -1
  142. package/dist/cjs-types/values/validator.d.ts.map +1 -1
  143. package/dist/cjs-types/values/validators.d.ts +30 -0
  144. package/dist/cjs-types/values/validators.d.ts.map +1 -1
  145. package/dist/cli.bundle.cjs +1753 -140
  146. package/dist/cli.bundle.cjs.map +4 -4
  147. package/dist/esm/browser/http_client.js.map +2 -2
  148. package/dist/esm/browser/query_options.js.map +2 -2
  149. package/dist/esm/browser/simple_client.js.map +2 -2
  150. package/dist/esm/browser/sync/optimistic_updates_impl.js.map +2 -2
  151. package/dist/esm/cli/codegen.js +2 -0
  152. package/dist/esm/cli/codegen.js.map +2 -2
  153. package/dist/esm/cli/deploy.js +1 -0
  154. package/dist/esm/cli/deploy.js.map +2 -2
  155. package/dist/esm/cli/docs.js +3 -43
  156. package/dist/esm/cli/docs.js.map +2 -2
  157. package/dist/esm/cli/lib/checkForLargeIndexDeletion.js +100 -60
  158. package/dist/esm/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
  159. package/dist/esm/cli/lib/checkForSlowSchemaValidation.js +85 -0
  160. package/dist/esm/cli/lib/checkForSlowSchemaValidation.js.map +7 -0
  161. package/dist/esm/cli/lib/codegen.js.map +2 -2
  162. package/dist/esm/cli/lib/components.js +12 -0
  163. package/dist/esm/cli/lib/components.js.map +2 -2
  164. package/dist/esm/cli/lib/deploy2.js +30 -2
  165. package/dist/esm/cli/lib/deploy2.js.map +2 -2
  166. package/dist/esm/cli/lib/deployApi/evaluateSchema.js +46 -0
  167. package/dist/esm/cli/lib/deployApi/evaluateSchema.js.map +7 -0
  168. package/dist/esm/cli/lib/deployApi/finishPush.js +1 -1
  169. package/dist/esm/cli/lib/deployApi/finishPush.js.map +2 -2
  170. package/dist/esm/cli/lib/deployApi/startPush.js +1 -1
  171. package/dist/esm/cli/lib/deployApi/startPush.js.map +2 -2
  172. package/dist/esm/cli/lib/dev.js +1 -0
  173. package/dist/esm/cli/lib/dev.js.map +2 -2
  174. package/dist/esm/cli/lib/indexes.js +1 -1
  175. package/dist/esm/cli/lib/indexes.js.map +1 -1
  176. package/dist/esm/cli/lib/localDeployment/run.js +30 -2
  177. package/dist/esm/cli/lib/localDeployment/run.js.map +2 -2
  178. package/dist/esm/cli/lib/localDeployment/upgrade.js +4 -3
  179. package/dist/esm/cli/lib/localDeployment/upgrade.js.map +2 -2
  180. package/dist/esm/cli/lib/localDeployment/utils.js +3 -0
  181. package/dist/esm/cli/lib/localDeployment/utils.js.map +2 -2
  182. package/dist/esm/cli/lib/run.js +1 -0
  183. package/dist/esm/cli/lib/run.js.map +2 -2
  184. package/dist/esm/cli/lib/utils/utils.js +36 -30
  185. package/dist/esm/cli/lib/utils/utils.js.map +2 -2
  186. package/dist/esm/cli/mcp.js +17 -7
  187. package/dist/esm/cli/mcp.js.map +2 -2
  188. package/dist/esm/index.js +1 -1
  189. package/dist/esm/index.js.map +1 -1
  190. package/dist/esm/nextjs/index.js.map +2 -2
  191. package/dist/esm/react/client.js.map +2 -2
  192. package/dist/esm/react/hydration.js +3 -1
  193. package/dist/esm/react/hydration.js.map +2 -2
  194. package/dist/esm/react/queries_observer.js +3 -1
  195. package/dist/esm/react/queries_observer.js.map +2 -2
  196. package/dist/esm/react/use_paginated_query2.js +3 -1
  197. package/dist/esm/react/use_paginated_query2.js.map +2 -2
  198. package/dist/esm/react/use_queries.js.map +2 -2
  199. package/dist/esm/server/api.js.map +2 -2
  200. package/dist/esm/server/components/index.js.map +2 -2
  201. package/dist/esm/server/cron.js +13 -11
  202. package/dist/esm/server/cron.js.map +2 -2
  203. package/dist/esm/server/impl/actions_impl.js.map +2 -2
  204. package/dist/esm/server/impl/meta_impl.js +9 -3
  205. package/dist/esm/server/impl/meta_impl.js.map +2 -2
  206. package/dist/esm/server/impl/scheduler_impl.js.map +2 -2
  207. package/dist/esm/server/index.js.map +2 -2
  208. package/dist/esm/server/schema.js +50 -3
  209. package/dist/esm/server/schema.js.map +2 -2
  210. package/dist/esm/values/validator.js +1 -1
  211. package/dist/esm/values/validator.js.map +2 -2
  212. package/dist/esm/values/validators.js +81 -25
  213. package/dist/esm/values/validators.js.map +2 -2
  214. package/dist/esm-types/browser/http_client.d.ts +5 -5
  215. package/dist/esm-types/browser/http_client.d.ts.map +1 -1
  216. package/dist/esm-types/browser/query_options.d.ts +2 -2
  217. package/dist/esm-types/browser/query_options.d.ts.map +1 -1
  218. package/dist/esm-types/browser/simple_client.d.ts +6 -6
  219. package/dist/esm-types/browser/simple_client.d.ts.map +1 -1
  220. package/dist/esm-types/browser/sync/optimistic_updates.d.ts +4 -4
  221. package/dist/esm-types/browser/sync/optimistic_updates.d.ts.map +1 -1
  222. package/dist/esm-types/browser/sync/optimistic_updates_impl.d.ts.map +1 -1
  223. package/dist/esm-types/cli/codegen.d.ts.map +1 -1
  224. package/dist/esm-types/cli/docs.d.ts.map +1 -1
  225. package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts +26 -5
  226. package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
  227. package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts +14 -0
  228. package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -0
  229. package/dist/esm-types/cli/lib/codegen.d.ts +1 -0
  230. package/dist/esm-types/cli/lib/codegen.d.ts.map +1 -1
  231. package/dist/esm-types/cli/lib/components.d.ts +1 -0
  232. package/dist/esm-types/cli/lib/components.d.ts.map +1 -1
  233. package/dist/esm-types/cli/lib/deploy2.d.ts +6 -0
  234. package/dist/esm-types/cli/lib/deploy2.d.ts.map +1 -1
  235. package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts +453 -0
  236. package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -0
  237. package/dist/esm-types/cli/lib/deployApi/finishPush.d.ts +1 -2
  238. package/dist/esm-types/cli/lib/deployApi/finishPush.d.ts.map +1 -1
  239. package/dist/esm-types/cli/lib/dev.d.ts.map +1 -1
  240. package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts +2 -0
  241. package/dist/esm-types/cli/lib/generatedFunctionLogsApi.d.ts.map +1 -1
  242. package/dist/esm-types/cli/lib/localDeployment/run.d.ts +2 -0
  243. package/dist/esm-types/cli/lib/localDeployment/run.d.ts.map +1 -1
  244. package/dist/esm-types/cli/lib/localDeployment/upgrade.d.ts.map +1 -1
  245. package/dist/esm-types/cli/lib/localDeployment/utils.d.ts +1 -0
  246. package/dist/esm-types/cli/lib/localDeployment/utils.d.ts.map +1 -1
  247. package/dist/esm-types/cli/lib/run.d.ts.map +1 -1
  248. package/dist/esm-types/cli/lib/utils/utils.d.ts +5 -5
  249. package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
  250. package/dist/esm-types/cli/mcp.d.ts.map +1 -1
  251. package/dist/esm-types/index.d.ts +1 -1
  252. package/dist/esm-types/index.d.ts.map +1 -1
  253. package/dist/esm-types/nextjs/index.d.ts +6 -6
  254. package/dist/esm-types/nextjs/index.d.ts.map +1 -1
  255. package/dist/esm-types/react/client.d.ts +15 -15
  256. package/dist/esm-types/react/client.d.ts.map +1 -1
  257. package/dist/esm-types/react/hydration.d.ts +3 -3
  258. package/dist/esm-types/react/hydration.d.ts.map +1 -1
  259. package/dist/esm-types/react/queries_observer.d.ts +9 -9
  260. package/dist/esm-types/react/queries_observer.d.ts.map +1 -1
  261. package/dist/esm-types/react/use_paginated_query2.d.ts.map +1 -1
  262. package/dist/esm-types/react/use_queries.d.ts +14 -6
  263. package/dist/esm-types/react/use_queries.d.ts.map +1 -1
  264. package/dist/esm-types/server/api.d.ts +157 -7
  265. package/dist/esm-types/server/api.d.ts.map +1 -1
  266. package/dist/esm-types/server/components/index.d.ts +2 -2
  267. package/dist/esm-types/server/components/index.d.ts.map +1 -1
  268. package/dist/esm-types/server/cron.d.ts +21 -20
  269. package/dist/esm-types/server/cron.d.ts.map +1 -1
  270. package/dist/esm-types/server/impl/actions_impl.d.ts +18 -4
  271. package/dist/esm-types/server/impl/actions_impl.d.ts.map +1 -1
  272. package/dist/esm-types/server/impl/meta_impl.d.ts.map +1 -1
  273. package/dist/esm-types/server/impl/scheduler_impl.d.ts.map +1 -1
  274. package/dist/esm-types/server/index.d.ts +2 -1
  275. package/dist/esm-types/server/index.d.ts.map +1 -1
  276. package/dist/esm-types/server/meta.d.ts.map +1 -1
  277. package/dist/esm-types/server/registration.d.ts +7 -7
  278. package/dist/esm-types/server/registration.d.ts.map +1 -1
  279. package/dist/esm-types/server/scheduler.d.ts +9 -7
  280. package/dist/esm-types/server/scheduler.d.ts.map +1 -1
  281. package/dist/esm-types/server/schema.d.ts +1 -0
  282. package/dist/esm-types/server/schema.d.ts.map +1 -1
  283. package/dist/esm-types/values/validator.d.ts.map +1 -1
  284. package/dist/esm-types/values/validators.d.ts +30 -0
  285. package/dist/esm-types/values/validators.d.ts.map +1 -1
  286. package/dist/react.bundle.js +1 -1
  287. package/dist/react.bundle.js.map +2 -2
  288. package/package.json +5 -5
  289. package/src/browser/http_client.ts +43 -10
  290. package/src/browser/query_options.ts +11 -5
  291. package/src/browser/simple_client.ts +35 -14
  292. package/src/browser/sync/optimistic_updates.ts +17 -4
  293. package/src/browser/sync/optimistic_updates_impl.ts +17 -4
  294. package/src/cli/codegen.ts +1 -0
  295. package/src/cli/deploy.ts +1 -0
  296. package/src/cli/docs.ts +3 -44
  297. package/src/cli/lib/checkForLargeIndexDeletion.ts +154 -82
  298. package/src/cli/lib/checkForSlowSchemaValidation.ts +130 -0
  299. package/src/cli/lib/codegen.ts +1 -0
  300. package/src/cli/lib/components.ts +17 -0
  301. package/src/cli/lib/deploy2.ts +56 -1
  302. package/src/cli/lib/deployApi/evaluateSchema.ts +62 -0
  303. package/src/cli/lib/deployApi/finishPush.ts +1 -1
  304. package/src/cli/lib/deployApi/startPush.ts +1 -1
  305. package/src/cli/lib/dev.ts +1 -0
  306. package/src/cli/lib/generatedFunctionLogsApi.ts +2 -0
  307. package/src/cli/lib/indexes.ts +1 -1
  308. package/src/cli/lib/localDeployment/run.ts +44 -2
  309. package/src/cli/lib/localDeployment/upgrade.ts +4 -6
  310. package/src/cli/lib/localDeployment/utils.ts +6 -0
  311. package/src/cli/lib/run.ts +1 -0
  312. package/src/cli/lib/utils/utils.ts +63 -35
  313. package/src/cli/mcp.ts +29 -7
  314. package/src/index.ts +1 -1
  315. package/src/nextjs/index.ts +19 -8
  316. package/src/react/client.ts +73 -30
  317. package/src/react/hydration.tsx +14 -6
  318. package/src/react/queries_observer.ts +19 -16
  319. package/src/react/use_paginated_query2.ts +10 -6
  320. package/src/react/use_queries.ts +23 -7
  321. package/src/server/api.ts +220 -14
  322. package/src/server/components/index.ts +4 -6
  323. package/src/server/cron.ts +34 -24
  324. package/src/server/impl/actions_impl.ts +16 -5
  325. package/src/server/impl/meta_impl.ts +8 -1
  326. package/src/server/impl/scheduler_impl.ts +13 -6
  327. package/src/server/index.ts +1 -3
  328. package/src/server/meta.ts +25 -0
  329. package/src/server/registration.ts +28 -7
  330. package/src/server/scheduler.ts +22 -7
  331. package/src/server/schema.ts +55 -0
  332. package/src/values/validator.ts +3 -1
  333. package/src/values/validators.ts +84 -26
@@ -1,9 +1,19 @@
1
- import { getFunctionName, OptionalRestArgs } from "../server/api.js";
1
+ import {
2
+ FunctionReference_future,
3
+ getFunctionName,
4
+ OptionalRestArgs,
5
+ } from "../server/api.js";
2
6
  import { parseArgs } from "../common/index.js";
3
7
  import { convexToJson, JSONValue, Value } from "../values/index.js";
4
8
  import { getFunctionAddress } from "./components/paths.js";
5
9
  import { SchedulableFunctionReference } from "./scheduler.js";
6
10
 
11
+ // Mirrors the constraint on `Scheduler.runAfter` and `Scheduler.runAt`, which
12
+ // is module-local to `scheduler.ts`.
13
+ type SchedulableFunctionReferenceCompat =
14
+ | SchedulableFunctionReference
15
+ | FunctionReference_future<"mutation" | "action", "public" | "internal">;
16
+
7
17
  type CronSchedule = {
8
18
  type: "cron";
9
19
  cron: string;
@@ -238,8 +248,8 @@ function validatedOptionalMinuteOfHour(n: number | undefined) {
238
248
  // call shapes apart by whether the second argument resolves to a function
239
249
  // reference (the way the scheduler syscalls do) rather than a schedule object.
240
250
  function isSchedulableFunctionReference(
241
- arg: Hourly | SchedulableFunctionReference,
242
- ): arg is SchedulableFunctionReference {
251
+ arg: Hourly | SchedulableFunctionReferenceCompat,
252
+ ): arg is SchedulableFunctionReferenceCompat {
243
253
  try {
244
254
  getFunctionAddress(arg);
245
255
  return true;
@@ -280,7 +290,7 @@ export class Crons {
280
290
  schedule(
281
291
  cronIdentifier: string,
282
292
  schedule: Schedule,
283
- functionReference: SchedulableFunctionReference,
293
+ functionReference: SchedulableFunctionReferenceCompat,
284
294
  args?: Record<string, Value>,
285
295
  ) {
286
296
  const cronArgs = parseArgs(args);
@@ -304,11 +314,11 @@ export class Crons {
304
314
  *
305
315
  * @param identifier - A unique name for this scheduled job.
306
316
  * @param schedule - The time between runs for this scheduled job.
307
- * @param functionReference - A {@link FunctionReference} for the function
308
- * to schedule.
317
+ * @param functionReference - A {@link FunctionReference} or
318
+ * {@link FunctionReference_future} for the function to schedule.
309
319
  * @param args - The arguments to the function.
310
320
  */
311
- interval<FuncRef extends SchedulableFunctionReference>(
321
+ interval<FuncRef extends SchedulableFunctionReferenceCompat>(
312
322
  cronIdentifier: string,
313
323
  schedule: Interval,
314
324
  functionReference: FuncRef,
@@ -353,22 +363,22 @@ export class Crons {
353
363
  * @param cronIdentifier - A unique name for this scheduled job.
354
364
  * @param schedule - What minute (UTC) of each hour to run this function. May
355
365
  * be omitted to let Convex pick a minute and spread runs across the hour.
356
- * @param functionReference - A {@link FunctionReference} for the function
357
- * to schedule.
366
+ * @param functionReference - A {@link FunctionReference} or
367
+ * {@link FunctionReference_future} for the function to schedule.
358
368
  * @param args - The arguments to the function.
359
369
  */
360
- hourly<FuncRef extends SchedulableFunctionReference>(
370
+ hourly<FuncRef extends SchedulableFunctionReferenceCompat>(
361
371
  cronIdentifier: string,
362
372
  functionReference: FuncRef,
363
373
  ...args: OptionalRestArgs<FuncRef>
364
374
  ): void;
365
- hourly<FuncRef extends SchedulableFunctionReference>(
375
+ hourly<FuncRef extends SchedulableFunctionReferenceCompat>(
366
376
  cronIdentifier: string,
367
377
  schedule: Hourly,
368
378
  functionReference: FuncRef,
369
379
  ...args: OptionalRestArgs<FuncRef>
370
380
  ): void;
371
- hourly<FuncRef extends SchedulableFunctionReference>(
381
+ hourly<FuncRef extends SchedulableFunctionReferenceCompat>(
372
382
  cronIdentifier: string,
373
383
  scheduleOrFunctionReference: Hourly | FuncRef,
374
384
  functionReferenceOrArg?: FuncRef | Record<string, Value>,
@@ -414,11 +424,11 @@ export class Crons {
414
424
  *
415
425
  * @param cronIdentifier - A unique name for this scheduled job.
416
426
  * @param schedule - What time (UTC) each day to run this function.
417
- * @param functionReference - A {@link FunctionReference} for the function
418
- * to schedule.
427
+ * @param functionReference - A {@link FunctionReference} or
428
+ * {@link FunctionReference_future} for the function to schedule.
419
429
  * @param args - The arguments to the function.
420
430
  */
421
- daily<FuncRef extends SchedulableFunctionReference>(
431
+ daily<FuncRef extends SchedulableFunctionReferenceCompat>(
422
432
  cronIdentifier: string,
423
433
  schedule: Daily,
424
434
  functionReference: FuncRef,
@@ -453,10 +463,10 @@ export class Crons {
453
463
  *
454
464
  * @param cronIdentifier - A unique name for this scheduled job.
455
465
  * @param schedule - What day and time (UTC) each week to run this function.
456
- * @param functionReference - A {@link FunctionReference} for the function
457
- * to schedule.
466
+ * @param functionReference - A {@link FunctionReference} or
467
+ * {@link FunctionReference_future} for the function to schedule.
458
468
  */
459
- weekly<FuncRef extends SchedulableFunctionReference>(
469
+ weekly<FuncRef extends SchedulableFunctionReferenceCompat>(
460
470
  cronIdentifier: string,
461
471
  schedule: Weekly,
462
472
  functionReference: FuncRef,
@@ -495,11 +505,11 @@ export class Crons {
495
505
  *
496
506
  * @param cronIdentifier - A unique name for this scheduled job.
497
507
  * @param schedule - What day and time (UTC) each month to run this function.
498
- * @param functionReference - A {@link FunctionReference} for the function
499
- * to schedule.
508
+ * @param functionReference - A {@link FunctionReference} or
509
+ * {@link FunctionReference_future} for the function to schedule.
500
510
  * @param args - The arguments to the function.
501
511
  */
502
- monthly<FuncRef extends SchedulableFunctionReference>(
512
+ monthly<FuncRef extends SchedulableFunctionReferenceCompat>(
503
513
  cronIdentifier: string,
504
514
  schedule: Monthly,
505
515
  functionReference: FuncRef,
@@ -534,11 +544,11 @@ export class Crons {
534
544
  *
535
545
  * @param cronIdentifier - A unique name for this scheduled job.
536
546
  * @param cron - Cron string like `"15 7 * * *"` (Every day at 7:15 UTC)
537
- * @param functionReference - A {@link FunctionReference} for the function
538
- * to schedule.
547
+ * @param functionReference - A {@link FunctionReference} or
548
+ * {@link FunctionReference_future} for the function to schedule.
539
549
  * @param args - The arguments to the function.
540
550
  */
541
- cron<FuncRef extends SchedulableFunctionReference>(
551
+ cron<FuncRef extends SchedulableFunctionReferenceCompat>(
542
552
  cronIdentifier: string,
543
553
  cron: CronString,
544
554
  functionReference: FuncRef,
@@ -2,7 +2,10 @@ import { convexToJson, jsonToConvex, Value } from "../../values/index.js";
2
2
  import { version } from "../../index.js";
3
3
  import { performAsyncSyscall } from "./syscall.js";
4
4
  import { parseArgs } from "../../common/index.js";
5
- import { FunctionReference } from "../../server/api.js";
5
+ import {
6
+ FunctionReference,
7
+ FunctionReference_future,
8
+ } from "../../server/api.js";
6
9
  import { getFunctionAddress } from "../components/paths.js";
7
10
  import { validateArg } from "./validate.js";
8
11
 
@@ -23,7 +26,9 @@ function syscallArgs(
23
26
  export function setupActionCalls(requestId: string) {
24
27
  return {
25
28
  runQuery: async (
26
- query: FunctionReference<"query", "public" | "internal">,
29
+ query:
30
+ | FunctionReference<"query", "public" | "internal">
31
+ | FunctionReference_future<"query", "public" | "internal">,
27
32
  args?: Record<string, Value>,
28
33
  ): Promise<any> => {
29
34
  const result = await performAsyncSyscall(
@@ -33,7 +38,9 @@ export function setupActionCalls(requestId: string) {
33
38
  return jsonToConvex(result);
34
39
  },
35
40
  runMutation: async (
36
- mutation: FunctionReference<"mutation", "public" | "internal">,
41
+ mutation:
42
+ | FunctionReference<"mutation", "public" | "internal">
43
+ | FunctionReference_future<"mutation", "public" | "internal">,
37
44
  args?: Record<string, Value>,
38
45
  ): Promise<any> => {
39
46
  const result = await performAsyncSyscall(
@@ -43,7 +50,9 @@ export function setupActionCalls(requestId: string) {
43
50
  return jsonToConvex(result);
44
51
  },
45
52
  runAction: async (
46
- action: FunctionReference<"action", "public" | "internal">,
53
+ action:
54
+ | FunctionReference<"action", "public" | "internal">
55
+ | FunctionReference_future<"action", "public" | "internal">,
47
56
  args?: Record<string, Value>,
48
57
  ): Promise<any> => {
49
58
  const result = await performAsyncSyscall(
@@ -64,7 +73,9 @@ export function setupActionCalls(requestId: string) {
64
73
  * cached, so a later call retries.
65
74
  *
66
75
  * @param service - The service the credential may access.
67
- * @internal
76
+ * @returns A JWT to send as `Authorization: Bearer <token>`. Keep it inside
77
+ * the action: don't return it to clients or store it in environment
78
+ * variables.
68
79
  */
69
80
  export async function getServiceToken(service: "ai-gateway"): Promise<string> {
70
81
  validateArg(service, 1, "getServiceToken", "service");
@@ -8,7 +8,7 @@ import {
8
8
  TransactionMetrics,
9
9
  DeploymentMetadata,
10
10
  } from "../meta.js";
11
- import { performAsyncSyscall } from "./syscall.js";
11
+ import { performAsyncSyscall, performSyscall } from "./syscall.js";
12
12
 
13
13
  async function getTransactionMetrics(): Promise<TransactionMetrics> {
14
14
  let syscallJSON;
@@ -53,6 +53,11 @@ async function getDeploymentMetadata(): Promise<DeploymentMetadata> {
53
53
  };
54
54
  }
55
55
 
56
+ function getSnapshotTs(): bigint {
57
+ const syscallJSON = performSyscall("1.0/getSnapshotTs", {});
58
+ return jsonToConvex(syscallJSON) as bigint;
59
+ }
60
+
56
61
  async function getRequestMetadata(): Promise<RequestMetadata> {
57
62
  const { ip, userAgent, requestId, scheduledFunctionId, authToken } =
58
63
  await performAsyncSyscall("1.0/getRequestMetadata", {});
@@ -70,6 +75,7 @@ export function setupQueryMeta(
70
75
  }),
71
76
  getTransactionMetrics,
72
77
  getDeploymentMetadata,
78
+ getSnapshotTs,
73
79
  };
74
80
  }
75
81
 
@@ -85,6 +91,7 @@ export function setupMutationMeta(
85
91
  getTransactionMetrics,
86
92
  getDeploymentMetadata,
87
93
  getRequestMetadata,
94
+ getSnapshotTs,
88
95
  };
89
96
  }
90
97
 
@@ -3,15 +3,22 @@ import { version } from "../../index.js";
3
3
  import { performAsyncSyscall } from "./syscall.js";
4
4
  import { parseArgs } from "../../common/index.js";
5
5
  import { SchedulableFunctionReference, Scheduler } from "../scheduler.js";
6
+ import { FunctionReference_future } from "../api.js";
6
7
  import { Id } from "../../values/value.js";
7
8
  import { validateArg } from "./validate.js";
8
9
  import { getFunctionAddress } from "../components/paths.js";
9
10
 
11
+ // Mirrors the constraint on `Scheduler.runAfter` and `Scheduler.runAt`, which
12
+ // is module-local to `scheduler.ts`.
13
+ type SchedulableFunctionReferenceCompat =
14
+ | SchedulableFunctionReference
15
+ | FunctionReference_future<"mutation" | "action", "public" | "internal">;
16
+
10
17
  export function setupMutationScheduler(): Scheduler {
11
18
  return {
12
19
  runAfter: async (
13
20
  delayMs: number,
14
- functionReference: SchedulableFunctionReference,
21
+ functionReference: SchedulableFunctionReferenceCompat,
15
22
  args?: Record<string, Value>,
16
23
  ) => {
17
24
  const syscallArgs = runAfterSyscallArgs(delayMs, functionReference, args);
@@ -19,7 +26,7 @@ export function setupMutationScheduler(): Scheduler {
19
26
  },
20
27
  runAt: async (
21
28
  ms_since_epoch_or_date: number | Date,
22
- functionReference: SchedulableFunctionReference,
29
+ functionReference: SchedulableFunctionReferenceCompat,
23
30
  args?: Record<string, Value>,
24
31
  ) => {
25
32
  const syscallArgs = runAtSyscallArgs(
@@ -41,7 +48,7 @@ export function setupActionScheduler(requestId: string): Scheduler {
41
48
  return {
42
49
  runAfter: async (
43
50
  delayMs: number,
44
- functionReference: SchedulableFunctionReference,
51
+ functionReference: SchedulableFunctionReferenceCompat,
45
52
  args?: Record<string, Value>,
46
53
  ) => {
47
54
  const syscallArgs = {
@@ -52,7 +59,7 @@ export function setupActionScheduler(requestId: string): Scheduler {
52
59
  },
53
60
  runAt: async (
54
61
  ms_since_epoch_or_date: number | Date,
55
- functionReference: SchedulableFunctionReference,
62
+ functionReference: SchedulableFunctionReferenceCompat,
56
63
  args?: Record<string, Value>,
57
64
  ) => {
58
65
  const syscallArgs = {
@@ -74,7 +81,7 @@ export function setupActionScheduler(requestId: string): Scheduler {
74
81
 
75
82
  function runAfterSyscallArgs(
76
83
  delayMs: number,
77
- functionReference: SchedulableFunctionReference,
84
+ functionReference: SchedulableFunctionReferenceCompat,
78
85
  args?: Record<string, Value>,
79
86
  ) {
80
87
  if (typeof delayMs !== "number") {
@@ -100,7 +107,7 @@ function runAfterSyscallArgs(
100
107
 
101
108
  function runAtSyscallArgs(
102
109
  ms_since_epoch_or_date: number | Date,
103
- functionReference: SchedulableFunctionReference,
110
+ functionReference: SchedulableFunctionReferenceCompat,
104
111
  args?: Record<string, Value>,
105
112
  ) {
106
113
  let ts;
@@ -103,9 +103,6 @@ export {
103
103
  internalMutationGeneric,
104
104
  internalQueryGeneric,
105
105
  } from "./impl/registration_impl.js";
106
- /**
107
- * @internal
108
- */
109
106
  export { getServiceToken } from "./impl/actions_impl.js";
110
107
  export type {
111
108
  TransactionMetric,
@@ -177,6 +174,7 @@ export {
177
174
  export type {
178
175
  ApiFromModules,
179
176
  AnyApi,
177
+ FunctionReference_future,
180
178
  FilterApi,
181
179
  FunctionType,
182
180
  FunctionReference,
@@ -133,6 +133,31 @@ export interface QueryMeta {
133
133
  getFunctionMetadata(): Promise<FunctionMetadata>;
134
134
  getTransactionMetrics(): Promise<TransactionMetrics>;
135
135
  getDeploymentMetadata(): Promise<DeploymentMetadata>;
136
+ /**
137
+ * @internal
138
+ * Returns the timestamp of the database snapshot this transaction reads
139
+ * from, in nanoseconds.
140
+ *
141
+ * All commits at or before this timestamp are observable within the
142
+ * transaction, and no later commits are. The value is fixed for the
143
+ * lifetime of the transaction and shared with all nested `runMutation` and
144
+ * `runQuery` calls.
145
+ *
146
+ * It is on the same clock as `db.vars.commitTs`: documents observable in
147
+ * this transaction have `commitTs` values at or before this timestamp, and
148
+ * no new documents will be written with a `commitTs` at or below this,
149
+ * including from the current transaction. When reading documents with an
150
+ * index in commitTs order, you can use this as an upper bound to prevent
151
+ * conflicting with racing inserts.
152
+ *
153
+ * Since the timestamp differs on every execution, calling this in a query
154
+ * limits caching of the query's result the same way `Date.now()` does.
155
+ *
156
+ * Note: this should not be compared to `_creationTime` or `Date.now()`, as
157
+ * those are based on wall-clock time rather than the database clock, and
158
+ * aren't guaranteed to follow commit order.
159
+ */
160
+ getSnapshotTs(): bigint;
136
161
  }
137
162
 
138
163
  /**
@@ -16,10 +16,11 @@ import {
16
16
  } from "./meta.js";
17
17
  import {
18
18
  ArgsAndOptions,
19
- FunctionReference,
20
19
  FunctionReturnType,
21
20
  OptionalRestArgs,
22
21
  ValidatorTypeToReturnType,
22
+ FunctionReference,
23
+ FunctionReference_future,
23
24
  } from "../server/api.js";
24
25
  import {
25
26
  GenericValidator,
@@ -133,7 +134,11 @@ export interface GenericMutationCtx<DataModel extends GenericDataModel> {
133
134
  * const user = await ctx.runQuery(internal.users.getUser, { userId });
134
135
  * ```
135
136
  */
136
- runQuery: <Query extends FunctionReference<"query", "public" | "internal">>(
137
+ runQuery: <
138
+ Query extends
139
+ | FunctionReference<"query", "public" | "internal">
140
+ | FunctionReference_future<"query", "public" | "internal">,
141
+ >(
137
142
  query: Query,
138
143
  ...args: ArgsAndOptions<Query, AdvancedRunQueryOptions>
139
144
  ) => Promise<FunctionReturnType<Query>>;
@@ -149,7 +154,9 @@ export interface GenericMutationCtx<DataModel extends GenericDataModel> {
149
154
  * validation, and creating a new isolated JS context.
150
155
  */
151
156
  runMutation: <
152
- Mutation extends FunctionReference<"mutation", "public" | "internal">,
157
+ Mutation extends
158
+ | FunctionReference<"mutation", "public" | "internal">
159
+ | FunctionReference_future<"mutation", "public" | "internal">,
153
160
  >(
154
161
  mutation: Mutation,
155
162
  ...args: ArgsAndOptions<Mutation, { transactionLimits?: TransactionLimits }>
@@ -243,7 +250,11 @@ export interface GenericQueryCtx<DataModel extends GenericDataModel> {
243
250
  * `runQuery` incurs overhead of running argument and return value validation,
244
251
  * and creating a new isolated JS context.
245
252
  */
246
- runQuery: <Query extends FunctionReference<"query", "public" | "internal">>(
253
+ runQuery: <
254
+ Query extends
255
+ | FunctionReference<"query", "public" | "internal">
256
+ | FunctionReference_future<"query", "public" | "internal">,
257
+ >(
247
258
  query: Query,
248
259
  ...args: ArgsAndOptions<Query, { transactionLimits?: TransactionLimits }>
249
260
  ) => Promise<FunctionReturnType<Query>>;
@@ -326,7 +337,11 @@ export interface GenericActionCtx<DataModel extends GenericDataModel> {
326
337
  * @param args - The arguments to the query function.
327
338
  * @returns A promise of the query's result.
328
339
  */
329
- runQuery<Query extends FunctionReference<"query", "public" | "internal">>(
340
+ runQuery<
341
+ Query extends
342
+ | FunctionReference<"query", "public" | "internal">
343
+ | FunctionReference_future<"query", "public" | "internal">,
344
+ >(
330
345
  query: Query,
331
346
  ...args: OptionalRestArgs<Query>
332
347
  ): Promise<FunctionReturnType<Query>>;
@@ -347,7 +362,9 @@ export interface GenericActionCtx<DataModel extends GenericDataModel> {
347
362
  * @returns A promise of the mutation's result.
348
363
  */
349
364
  runMutation<
350
- Mutation extends FunctionReference<"mutation", "public" | "internal">,
365
+ Mutation extends
366
+ | FunctionReference<"mutation", "public" | "internal">
367
+ | FunctionReference_future<"mutation", "public" | "internal">,
351
368
  >(
352
369
  mutation: Mutation,
353
370
  ...args: OptionalRestArgs<Mutation>
@@ -369,7 +386,11 @@ export interface GenericActionCtx<DataModel extends GenericDataModel> {
369
386
  * @param args - The arguments to the action function.
370
387
  * @returns A promise of the action's result.
371
388
  */
372
- runAction<Action extends FunctionReference<"action", "public" | "internal">>(
389
+ runAction<
390
+ Action extends
391
+ | FunctionReference<"action", "public" | "internal">
392
+ | FunctionReference_future<"action", "public" | "internal">,
393
+ >(
373
394
  action: Action,
374
395
  ...args: OptionalRestArgs<Action>
375
396
  ): Promise<FunctionReturnType<Action>>;
@@ -1,4 +1,8 @@
1
- import { FunctionReference, OptionalRestArgs } from "../server/api.js";
1
+ import {
2
+ FunctionReference,
3
+ FunctionReference_future,
4
+ OptionalRestArgs,
5
+ } from "../server/api.js";
2
6
  import { Id } from "../values/value.js";
3
7
 
4
8
  /**
@@ -13,6 +17,17 @@ export type SchedulableFunctionReference = FunctionReference<
13
17
  "public" | "internal"
14
18
  >;
15
19
 
20
+ // What the scheduling methods accept. This is kept separate from the exported
21
+ // `SchedulableFunctionReference` so that alias keeps describing a plain
22
+ // reference. Existing code depending on it can still forward it to anything
23
+ // typed with `FunctionReference` or read its `_args`. This alias is
24
+ // module-local so that a consumer's declaration file inlines it instead of
25
+ // importing it from a path that is not part of the package's public entry
26
+ // points.
27
+ type SchedulableFunctionReferenceCompat =
28
+ | SchedulableFunctionReference
29
+ | FunctionReference_future<"mutation" | "action", "public" | "internal">;
30
+
16
31
  /**
17
32
  * An interface to schedule Convex functions to run in the future.
18
33
  *
@@ -78,13 +93,13 @@ export interface Scheduler {
78
93
  * @param delayMs - Delay in milliseconds. Must be non-negative. If the delay
79
94
  * is zero, the scheduled function will be due to execute immediately after the
80
95
  * scheduling one completes.
81
- * @param functionReference - A {@link FunctionReference} for the function
82
- * to schedule.
96
+ * @param functionReference - A {@link FunctionReference} or
97
+ * {@link FunctionReference_future} for the function to schedule.
83
98
  * @param args - Arguments to call the scheduled functions with.
84
99
  * @returns The ID of the scheduled function in the `_scheduled_functions`
85
100
  * system table. Use this to cancel it later if needed.
86
101
  **/
87
- runAfter<FuncRef extends SchedulableFunctionReference>(
102
+ runAfter<FuncRef extends SchedulableFunctionReferenceCompat>(
88
103
  delayMs: number,
89
104
  functionReference: FuncRef,
90
105
  ...args: OptionalRestArgs<FuncRef>
@@ -110,13 +125,13 @@ export interface Scheduler {
110
125
  * If the timestamp is in the past, the scheduled function will be due to
111
126
  * execute immediately after the scheduling one completes. The timestamp can't
112
127
  * be more than five years in the past or more than five years in the future.
113
- * @param functionReference - A {@link FunctionReference} for the function
114
- * to schedule.
128
+ * @param functionReference - A {@link FunctionReference} or
129
+ * {@link FunctionReference_future} for the function to schedule.
115
130
  * @param args - Arguments to call the scheduled functions with.
116
131
  * @returns The ID of the scheduled function in the `_scheduled_functions`
117
132
  * system table.
118
133
  **/
119
- runAt<FuncRef extends SchedulableFunctionReference>(
134
+ runAt<FuncRef extends SchedulableFunctionReferenceCompat>(
120
135
  timestamp: number | Date,
121
136
  functionReference: FuncRef,
122
137
  ...args: OptionalRestArgs<FuncRef>
@@ -204,6 +204,9 @@ export class TableDefinition<
204
204
  private stagedVectorIndexes: VectorIndex[];
205
205
  // The type of documents stored in this table.
206
206
  validator: DocumentType;
207
+ // The proposed next validator for this table, validated against existing
208
+ // documents in the background while `validator` remains enforced.
209
+ private stagedValidator: Validator<any, any, any> | undefined;
207
210
 
208
211
  /**
209
212
  * @internal
@@ -557,6 +560,45 @@ export class TableDefinition<
557
560
  return this;
558
561
  }
559
562
 
563
+ /**
564
+ * Stage a new document validator for this table.
565
+ *
566
+ * Convex validates the staged validator against the table's existing
567
+ * documents in the background, while the validator passed to
568
+ * {@link defineTable} remains the one enforced on reads and writes. Once
569
+ * the background validation succeeds, make the staged validator the
570
+ * table's validator and remove `.staged()`.
571
+ *
572
+ * ```ts
573
+ * defineTable({
574
+ * author: v.string(),
575
+ * }).staged({
576
+ * author: v.array(v.string()),
577
+ * })
578
+ * ```
579
+ *
580
+ * TODO: link a worked staged-schema example from the docs once one exists.
581
+ *
582
+ * @param documentSchema - The proposed next type of documents stored in
583
+ * this table, as an object of field validators or a schema validator.
584
+ * @returns A {@link TableDefinition} with the staged validator attached.
585
+ *
586
+ * @internal
587
+ */
588
+ staged(
589
+ documentSchema:
590
+ | Validator<Record<string, any>, "required", any>
591
+ | Record<string, GenericValidator>,
592
+ ): TableDefinition<DocumentType, Indexes, SearchIndexes, VectorIndexes> {
593
+ if (this.stagedValidator !== undefined) {
594
+ throw new Error("Table cannot have more than one staged validator.");
595
+ }
596
+ this.stagedValidator = isValidator(documentSchema)
597
+ ? documentSchema
598
+ : v.object(documentSchema);
599
+ return this.self();
600
+ }
601
+
560
602
  /**
561
603
  * Work around for https://github.com/microsoft/TypeScript/issues/57035
562
604
  */
@@ -582,6 +624,16 @@ export class TableDefinition<
582
624
  );
583
625
  }
584
626
 
627
+ let stagedDocumentType = undefined;
628
+ if (this.stagedValidator !== undefined) {
629
+ stagedDocumentType = this.stagedValidator.json;
630
+ if (typeof stagedDocumentType !== "object") {
631
+ throw new Error(
632
+ "Invalid staged validator: please make sure that the parameter of `.staged()` is valid (see https://docs.convex.dev/database/schemas)",
633
+ );
634
+ }
635
+ }
636
+
585
637
  return {
586
638
  indexes: this.indexes,
587
639
  stagedDbIndexes: this.stagedDbIndexes,
@@ -590,6 +642,7 @@ export class TableDefinition<
590
642
  vectorIndexes: this.vectorIndexes,
591
643
  stagedVectorIndexes: this.stagedVectorIndexes,
592
644
  documentType,
645
+ stagedDocumentType,
593
646
  };
594
647
  }
595
648
  }
@@ -884,6 +937,7 @@ export class SchemaDefinition<
884
937
  vectorIndexes,
885
938
  stagedVectorIndexes,
886
939
  documentType,
940
+ stagedDocumentType,
887
941
  } = definition.export();
888
942
  return {
889
943
  tableName,
@@ -894,6 +948,7 @@ export class SchemaDefinition<
894
948
  vectorIndexes,
895
949
  stagedVectorIndexes,
896
950
  documentType,
951
+ stagedDocumentType,
897
952
  };
898
953
  }),
899
954
  schemaValidation: this.schemaValidation,
@@ -28,7 +28,9 @@ import {
28
28
  export type GenericValidator = Validator<any, any, any>;
29
29
 
30
30
  export function isValidator(v: any): v is GenericValidator {
31
- return !!v.isConvexValidator;
31
+ // Check for the literal `true` marker: a field map can contain a field
32
+ // *named* `isConvexValidator` whose value is a (truthy) validator object.
33
+ return v?.isConvexValidator === true;
32
34
  }
33
35
 
34
36
  /**