convex 1.46.0 → 1.48.0-alpha.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 (479) hide show
  1. package/CHANGELOG.md +58 -1
  2. package/dist/browser.bundle.js +7 -1
  3. package/dist/browser.bundle.js.map +2 -2
  4. package/dist/cjs/bundler/context.js +7 -5
  5. package/dist/cjs/bundler/context.js.map +2 -2
  6. package/dist/cjs/bundler/fs.js +47 -6
  7. package/dist/cjs/bundler/fs.js.map +2 -2
  8. package/dist/cjs/bundler/index.js +5 -4
  9. package/dist/cjs/bundler/index.js.map +2 -2
  10. package/dist/cjs/cli/account.js +237 -0
  11. package/dist/cjs/cli/account.js.map +7 -0
  12. package/dist/cjs/cli/codegen.js +0 -4
  13. package/dist/cjs/cli/codegen.js.map +2 -2
  14. package/dist/cjs/cli/configure.js +28 -6
  15. package/dist/cjs/cli/configure.js.map +2 -2
  16. package/dist/cjs/cli/deploy.js +27 -2
  17. package/dist/cjs/cli/deploy.js.map +2 -2
  18. package/dist/cjs/cli/deploymentSelect.js +2 -2
  19. package/dist/cjs/cli/deploymentSelect.js.map +2 -2
  20. package/dist/cjs/cli/dev.js +6 -0
  21. package/dist/cjs/cli/dev.js.map +2 -2
  22. package/dist/cjs/cli/env.js +10 -5
  23. package/dist/cjs/cli/env.js.map +2 -2
  24. package/dist/cjs/cli/envDefault.js +7 -2
  25. package/dist/cjs/cli/envDefault.js.map +2 -2
  26. package/dist/cjs/cli/generatedApi.js.map +1 -1
  27. package/dist/cjs/cli/lib/api.js +2 -0
  28. package/dist/cjs/cli/lib/api.js.map +2 -2
  29. package/dist/cjs/cli/lib/checkForLargeIndexBackfill.js +113 -0
  30. package/dist/cjs/cli/lib/checkForLargeIndexBackfill.js.map +7 -0
  31. package/dist/cjs/cli/lib/checkForLargeIndexDeletion.js +36 -47
  32. package/dist/cjs/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
  33. package/dist/cjs/cli/lib/checkForSlowSchemaValidation.js +58 -39
  34. package/dist/cjs/cli/lib/checkForSlowSchemaValidation.js.map +2 -2
  35. package/dist/cjs/cli/lib/checkForStagedValidatorDeletion.js +90 -0
  36. package/dist/cjs/cli/lib/checkForStagedValidatorDeletion.js.map +7 -0
  37. package/dist/cjs/cli/lib/codegen.js.map +2 -2
  38. package/dist/cjs/cli/lib/command.js +2 -1
  39. package/dist/cjs/cli/lib/command.js.map +2 -2
  40. package/dist/cjs/cli/lib/components/definition/bundle.js +37 -11
  41. package/dist/cjs/cli/lib/components/definition/bundle.js.map +2 -2
  42. package/dist/cjs/cli/lib/components.js +48 -5
  43. package/dist/cjs/cli/lib/components.js.map +2 -2
  44. package/dist/cjs/cli/lib/config.js +56 -17
  45. package/dist/cjs/cli/lib/config.js.map +2 -2
  46. package/dist/cjs/cli/lib/deploy2.js +3 -1
  47. package/dist/cjs/cli/lib/deploy2.js.map +2 -2
  48. package/dist/cjs/cli/lib/deployApi/evaluateSchema.js +30 -2
  49. package/dist/cjs/cli/lib/deployApi/evaluateSchema.js.map +2 -2
  50. package/dist/cjs/cli/lib/deployKeyWarning.js +43 -0
  51. package/dist/cjs/cli/lib/deployKeyWarning.js.map +7 -0
  52. package/dist/cjs/cli/lib/deployment.js +2 -0
  53. package/dist/cjs/cli/lib/deployment.js.map +2 -2
  54. package/dist/cjs/cli/lib/deploymentSelection.js +27 -18
  55. package/dist/cjs/cli/lib/deploymentSelection.js.map +2 -2
  56. package/dist/cjs/cli/lib/dev.js +5 -0
  57. package/dist/cjs/cli/lib/dev.js.map +2 -2
  58. package/dist/cjs/cli/lib/envvars.js +32 -0
  59. package/dist/cjs/cli/lib/envvars.js.map +2 -2
  60. package/dist/cjs/cli/lib/formatValidationProgress.js +47 -0
  61. package/dist/cjs/cli/lib/formatValidationProgress.js.map +7 -0
  62. package/dist/cjs/cli/lib/fsUtils.js +1 -1
  63. package/dist/cjs/cli/lib/fsUtils.js.map +2 -2
  64. package/dist/cjs/cli/lib/generateDocs.js +1 -1
  65. package/dist/cjs/cli/lib/generateDocs.js.map +1 -1
  66. package/dist/cjs/cli/lib/indexes.js.map +1 -1
  67. package/dist/cjs/cli/lib/login.js +28 -4
  68. package/dist/cjs/cli/lib/login.js.map +2 -2
  69. package/dist/cjs/cli/lib/mcp/requestContext.js +5 -1
  70. package/dist/cjs/cli/lib/mcp/requestContext.js.map +2 -2
  71. package/dist/cjs/cli/lib/mcp/tools/env.js +10 -3
  72. package/dist/cjs/cli/lib/mcp/tools/env.js.map +2 -2
  73. package/dist/cjs/cli/lib/profileManagement.js +196 -0
  74. package/dist/cjs/cli/lib/profileManagement.js.map +7 -0
  75. package/dist/cjs/cli/lib/profiles.js +333 -0
  76. package/dist/cjs/cli/lib/profiles.js.map +7 -0
  77. package/dist/cjs/cli/lib/run.js +4 -0
  78. package/dist/cjs/cli/lib/run.js.map +2 -2
  79. package/dist/cjs/cli/lib/schemaEvaluation.js +62 -0
  80. package/dist/cjs/cli/lib/schemaEvaluation.js.map +7 -0
  81. package/dist/cjs/cli/lib/usageLimits.js +4 -2
  82. package/dist/cjs/cli/lib/usageLimits.js.map +2 -2
  83. package/dist/cjs/cli/lib/utils/mutex.js +9 -24
  84. package/dist/cjs/cli/lib/utils/mutex.js.map +2 -2
  85. package/dist/cjs/cli/lib/utils/utils.js +66 -27
  86. package/dist/cjs/cli/lib/utils/utils.js.map +2 -2
  87. package/dist/cjs/cli/login.js +213 -114
  88. package/dist/cjs/cli/login.js.map +3 -3
  89. package/dist/cjs/cli/logout.js +113 -12
  90. package/dist/cjs/cli/logout.js.map +3 -3
  91. package/dist/cjs/cli/mcp.js +43 -10
  92. package/dist/cjs/cli/mcp.js.map +3 -3
  93. package/dist/cjs/cli/program.js +2 -1
  94. package/dist/cjs/cli/program.js.map +2 -2
  95. package/dist/cjs/cli/projectCreate.js +1 -1
  96. package/dist/cjs/cli/projectCreate.js.map +1 -1
  97. package/dist/cjs/index.js +1 -1
  98. package/dist/cjs/index.js.map +1 -1
  99. package/dist/cjs/server/impl/actions_impl.js +8 -3
  100. package/dist/cjs/server/impl/actions_impl.js.map +2 -2
  101. package/dist/cjs/server/impl/storage_impl.js +29 -0
  102. package/dist/cjs/server/impl/storage_impl.js.map +2 -2
  103. package/dist/cjs/server/index.js +1 -0
  104. package/dist/cjs/server/index.js.map +2 -2
  105. package/dist/cjs/server/meta.js.map +1 -1
  106. package/dist/cjs/server/registration.js.map +1 -1
  107. package/dist/cjs/server/schema.js +34 -12
  108. package/dist/cjs/server/schema.js.map +2 -2
  109. package/dist/cjs/server/storage.js.map +1 -1
  110. package/dist/cjs/values/validators.js +1 -1
  111. package/dist/cjs/values/validators.js.map +2 -2
  112. package/dist/cjs/values/value.js +6 -0
  113. package/dist/cjs/values/value.js.map +2 -2
  114. package/dist/cjs-types/bundler/context.d.ts +5 -0
  115. package/dist/cjs-types/bundler/context.d.ts.map +1 -1
  116. package/dist/cjs-types/bundler/fs.d.ts +7 -2
  117. package/dist/cjs-types/bundler/fs.d.ts.map +1 -1
  118. package/dist/cjs-types/bundler/index.d.ts +9 -2
  119. package/dist/cjs-types/bundler/index.d.ts.map +1 -1
  120. package/dist/cjs-types/cli/account.d.ts +6 -0
  121. package/dist/cjs-types/cli/account.d.ts.map +1 -0
  122. package/dist/cjs-types/cli/codegen.d.ts.map +1 -1
  123. package/dist/cjs-types/cli/configure.d.ts +6 -0
  124. package/dist/cjs-types/cli/configure.d.ts.map +1 -1
  125. package/dist/cjs-types/cli/deploy.d.ts +2 -0
  126. package/dist/cjs-types/cli/deploy.d.ts.map +1 -1
  127. package/dist/cjs-types/cli/deploymentCreate.d.ts +6 -6
  128. package/dist/cjs-types/cli/deploymentSelect.d.ts.map +1 -1
  129. package/dist/cjs-types/cli/dev.d.ts +1 -0
  130. package/dist/cjs-types/cli/dev.d.ts.map +1 -1
  131. package/dist/cjs-types/cli/env.d.ts.map +1 -1
  132. package/dist/cjs-types/cli/envDefault.d.ts.map +1 -1
  133. package/dist/cjs-types/cli/generatedApi.d.ts +1 -1
  134. package/dist/cjs-types/cli/generatedApi.d.ts.map +1 -1
  135. package/dist/cjs-types/cli/lib/api.d.ts.map +1 -1
  136. package/dist/cjs-types/cli/lib/checkForLargeIndexBackfill.d.ts +30 -0
  137. package/dist/cjs-types/cli/lib/checkForLargeIndexBackfill.d.ts.map +1 -0
  138. package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts +5 -7
  139. package/dist/cjs-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
  140. package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts +4 -10
  141. package/dist/cjs-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -1
  142. package/dist/cjs-types/cli/lib/checkForStagedValidatorDeletion.d.ts +17 -0
  143. package/dist/cjs-types/cli/lib/checkForStagedValidatorDeletion.d.ts.map +1 -0
  144. package/dist/cjs-types/cli/lib/codegen.d.ts +0 -3
  145. package/dist/cjs-types/cli/lib/codegen.d.ts.map +1 -1
  146. package/dist/cjs-types/cli/lib/command.d.ts +2 -0
  147. package/dist/cjs-types/cli/lib/command.d.ts.map +1 -1
  148. package/dist/cjs-types/cli/lib/components/definition/bundle.d.ts +13 -0
  149. package/dist/cjs-types/cli/lib/components/definition/bundle.d.ts.map +1 -1
  150. package/dist/cjs-types/cli/lib/components.d.ts +4 -0
  151. package/dist/cjs-types/cli/lib/components.d.ts.map +1 -1
  152. package/dist/cjs-types/cli/lib/config.d.ts +2 -1
  153. package/dist/cjs-types/cli/lib/config.d.ts.map +1 -1
  154. package/dist/cjs-types/cli/lib/deploy2.d.ts +2 -0
  155. package/dist/cjs-types/cli/lib/deploy2.d.ts.map +1 -1
  156. package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts +460 -16
  157. package/dist/cjs-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -1
  158. package/dist/cjs-types/cli/lib/deployKeyWarning.d.ts +3 -0
  159. package/dist/cjs-types/cli/lib/deployKeyWarning.d.ts.map +1 -0
  160. package/dist/cjs-types/cli/lib/deployment.d.ts +2 -0
  161. package/dist/cjs-types/cli/lib/deployment.d.ts.map +1 -1
  162. package/dist/cjs-types/cli/lib/deploymentSelection.d.ts +2 -1
  163. package/dist/cjs-types/cli/lib/deploymentSelection.d.ts.map +1 -1
  164. package/dist/cjs-types/cli/lib/dev.d.ts +1 -0
  165. package/dist/cjs-types/cli/lib/dev.d.ts.map +1 -1
  166. package/dist/cjs-types/cli/lib/envvars.d.ts +6 -0
  167. package/dist/cjs-types/cli/lib/envvars.d.ts.map +1 -1
  168. package/dist/cjs-types/cli/lib/formatValidationProgress.d.ts +8 -0
  169. package/dist/cjs-types/cli/lib/formatValidationProgress.d.ts.map +1 -0
  170. package/dist/cjs-types/cli/lib/fsUtils.d.ts +1 -0
  171. package/dist/cjs-types/cli/lib/fsUtils.d.ts.map +1 -1
  172. package/dist/cjs-types/cli/lib/login.d.ts +3 -1
  173. package/dist/cjs-types/cli/lib/login.d.ts.map +1 -1
  174. package/dist/cjs-types/cli/lib/mcp/requestContext.d.ts.map +1 -1
  175. package/dist/cjs-types/cli/lib/mcp/tools/env.d.ts +8 -5
  176. package/dist/cjs-types/cli/lib/mcp/tools/env.d.ts.map +1 -1
  177. package/dist/cjs-types/cli/lib/mcp/tools/insights.d.ts +2 -2
  178. package/dist/cjs-types/cli/lib/profileManagement.d.ts +10 -0
  179. package/dist/cjs-types/cli/lib/profileManagement.d.ts.map +1 -0
  180. package/dist/cjs-types/cli/lib/profiles.d.ts +59 -0
  181. package/dist/cjs-types/cli/lib/profiles.d.ts.map +1 -0
  182. package/dist/cjs-types/cli/lib/run.d.ts.map +1 -1
  183. package/dist/cjs-types/cli/lib/schemaEvaluation.d.ts +33 -0
  184. package/dist/cjs-types/cli/lib/schemaEvaluation.d.ts.map +1 -0
  185. package/dist/cjs-types/cli/lib/usageLimits.d.ts +1 -1
  186. package/dist/cjs-types/cli/lib/usageLimits.d.ts.map +1 -1
  187. package/dist/cjs-types/cli/lib/utils/mutex.d.ts +1 -3
  188. package/dist/cjs-types/cli/lib/utils/mutex.d.ts.map +1 -1
  189. package/dist/cjs-types/cli/lib/utils/utils.d.ts +15 -2
  190. package/dist/cjs-types/cli/lib/utils/utils.d.ts.map +1 -1
  191. package/dist/cjs-types/cli/login.d.ts +21 -0
  192. package/dist/cjs-types/cli/login.d.ts.map +1 -1
  193. package/dist/cjs-types/cli/logout.d.ts +8 -1
  194. package/dist/cjs-types/cli/logout.d.ts.map +1 -1
  195. package/dist/cjs-types/cli/mcp.d.ts.map +1 -1
  196. package/dist/cjs-types/cli/program.d.ts.map +1 -1
  197. package/dist/cjs-types/index.d.ts +1 -1
  198. package/dist/cjs-types/index.d.ts.map +1 -1
  199. package/dist/cjs-types/server/impl/actions_impl.d.ts +18 -3
  200. package/dist/cjs-types/server/impl/actions_impl.d.ts.map +1 -1
  201. package/dist/cjs-types/server/impl/storage_impl.d.ts.map +1 -1
  202. package/dist/cjs-types/server/index.d.ts +1 -1
  203. package/dist/cjs-types/server/index.d.ts.map +1 -1
  204. package/dist/cjs-types/server/meta.d.ts +63 -0
  205. package/dist/cjs-types/server/meta.d.ts.map +1 -1
  206. package/dist/cjs-types/server/registration.d.ts +10 -0
  207. package/dist/cjs-types/server/registration.d.ts.map +1 -1
  208. package/dist/cjs-types/server/schema.d.ts +33 -0
  209. package/dist/cjs-types/server/schema.d.ts.map +1 -1
  210. package/dist/cjs-types/server/storage.d.ts.map +1 -1
  211. package/dist/cjs-types/values/value.d.ts.map +1 -1
  212. package/dist/cli.bundle.cjs +4889 -2980
  213. package/dist/cli.bundle.cjs.map +4 -4
  214. package/dist/esm/bundler/context.js +7 -5
  215. package/dist/esm/bundler/context.js.map +2 -2
  216. package/dist/esm/bundler/fs.js +47 -6
  217. package/dist/esm/bundler/fs.js.map +2 -2
  218. package/dist/esm/bundler/index.js +5 -4
  219. package/dist/esm/bundler/index.js.map +2 -2
  220. package/dist/esm/cli/account.js +221 -0
  221. package/dist/esm/cli/account.js.map +7 -0
  222. package/dist/esm/cli/codegen.js +0 -4
  223. package/dist/esm/cli/codegen.js.map +2 -2
  224. package/dist/esm/cli/configure.js +27 -6
  225. package/dist/esm/cli/configure.js.map +2 -2
  226. package/dist/esm/cli/deploy.js +27 -2
  227. package/dist/esm/cli/deploy.js.map +2 -2
  228. package/dist/esm/cli/deploymentSelect.js +6 -3
  229. package/dist/esm/cli/deploymentSelect.js.map +2 -2
  230. package/dist/esm/cli/dev.js +6 -0
  231. package/dist/esm/cli/dev.js.map +2 -2
  232. package/dist/esm/cli/env.js +11 -6
  233. package/dist/esm/cli/env.js.map +2 -2
  234. package/dist/esm/cli/envDefault.js +7 -2
  235. package/dist/esm/cli/envDefault.js.map +2 -2
  236. package/dist/esm/cli/lib/api.js +2 -0
  237. package/dist/esm/cli/lib/api.js.map +2 -2
  238. package/dist/esm/cli/lib/checkForLargeIndexBackfill.js +95 -0
  239. package/dist/esm/cli/lib/checkForLargeIndexBackfill.js.map +7 -0
  240. package/dist/esm/cli/lib/checkForLargeIndexDeletion.js +37 -48
  241. package/dist/esm/cli/lib/checkForLargeIndexDeletion.js.map +2 -2
  242. package/dist/esm/cli/lib/checkForSlowSchemaValidation.js +63 -41
  243. package/dist/esm/cli/lib/checkForSlowSchemaValidation.js.map +2 -2
  244. package/dist/esm/cli/lib/checkForStagedValidatorDeletion.js +68 -0
  245. package/dist/esm/cli/lib/checkForStagedValidatorDeletion.js.map +7 -0
  246. package/dist/esm/cli/lib/codegen.js.map +2 -2
  247. package/dist/esm/cli/lib/command.js +2 -1
  248. package/dist/esm/cli/lib/command.js.map +2 -2
  249. package/dist/esm/cli/lib/components/definition/bundle.js +37 -11
  250. package/dist/esm/cli/lib/components/definition/bundle.js.map +2 -2
  251. package/dist/esm/cli/lib/components.js +55 -5
  252. package/dist/esm/cli/lib/components.js.map +2 -2
  253. package/dist/esm/cli/lib/config.js +55 -17
  254. package/dist/esm/cli/lib/config.js.map +2 -2
  255. package/dist/esm/cli/lib/deploy2.js +3 -1
  256. package/dist/esm/cli/lib/deploy2.js.map +2 -2
  257. package/dist/esm/cli/lib/deployApi/evaluateSchema.js +28 -2
  258. package/dist/esm/cli/lib/deployApi/evaluateSchema.js.map +2 -2
  259. package/dist/esm/cli/lib/deployKeyWarning.js +27 -0
  260. package/dist/esm/cli/lib/deployKeyWarning.js.map +7 -0
  261. package/dist/esm/cli/lib/deployment.js +2 -2
  262. package/dist/esm/cli/lib/deployment.js.map +2 -2
  263. package/dist/esm/cli/lib/deploymentSelection.js +35 -20
  264. package/dist/esm/cli/lib/deploymentSelection.js.map +2 -2
  265. package/dist/esm/cli/lib/dev.js +5 -0
  266. package/dist/esm/cli/lib/dev.js.map +2 -2
  267. package/dist/esm/cli/lib/envvars.js +35 -1
  268. package/dist/esm/cli/lib/envvars.js.map +2 -2
  269. package/dist/esm/cli/lib/formatValidationProgress.js +24 -0
  270. package/dist/esm/cli/lib/formatValidationProgress.js.map +7 -0
  271. package/dist/esm/cli/lib/fsUtils.js +1 -1
  272. package/dist/esm/cli/lib/fsUtils.js.map +2 -2
  273. package/dist/esm/cli/lib/generateDocs.js +1 -1
  274. package/dist/esm/cli/lib/generateDocs.js.map +1 -1
  275. package/dist/esm/cli/lib/indexes.js.map +1 -1
  276. package/dist/esm/cli/lib/login.js +36 -4
  277. package/dist/esm/cli/lib/login.js.map +2 -2
  278. package/dist/esm/cli/lib/mcp/requestContext.js +5 -1
  279. package/dist/esm/cli/lib/mcp/requestContext.js.map +2 -2
  280. package/dist/esm/cli/lib/mcp/tools/env.js +10 -3
  281. package/dist/esm/cli/lib/mcp/tools/env.js.map +2 -2
  282. package/dist/esm/cli/lib/profileManagement.js +179 -0
  283. package/dist/esm/cli/lib/profileManagement.js.map +7 -0
  284. package/dist/esm/cli/lib/profiles.js +288 -0
  285. package/dist/esm/cli/lib/profiles.js.map +7 -0
  286. package/dist/esm/cli/lib/run.js +4 -0
  287. package/dist/esm/cli/lib/run.js.map +2 -2
  288. package/dist/esm/cli/lib/schemaEvaluation.js +39 -0
  289. package/dist/esm/cli/lib/schemaEvaluation.js.map +7 -0
  290. package/dist/esm/cli/lib/usageLimits.js +4 -2
  291. package/dist/esm/cli/lib/usageLimits.js.map +2 -2
  292. package/dist/esm/cli/lib/utils/mutex.js +9 -24
  293. package/dist/esm/cli/lib/utils/mutex.js.map +2 -2
  294. package/dist/esm/cli/lib/utils/utils.js +63 -27
  295. package/dist/esm/cli/lib/utils/utils.js.map +2 -2
  296. package/dist/esm/cli/login.js +225 -112
  297. package/dist/esm/cli/login.js.map +3 -3
  298. package/dist/esm/cli/logout.js +110 -13
  299. package/dist/esm/cli/logout.js.map +2 -2
  300. package/dist/esm/cli/mcp.js +34 -10
  301. package/dist/esm/cli/mcp.js.map +2 -2
  302. package/dist/esm/cli/program.js +2 -1
  303. package/dist/esm/cli/program.js.map +2 -2
  304. package/dist/esm/cli/projectCreate.js +1 -1
  305. package/dist/esm/cli/projectCreate.js.map +1 -1
  306. package/dist/esm/index.js +1 -1
  307. package/dist/esm/index.js.map +1 -1
  308. package/dist/esm/server/impl/actions_impl.js +7 -3
  309. package/dist/esm/server/impl/actions_impl.js.map +2 -2
  310. package/dist/esm/server/impl/storage_impl.js +29 -0
  311. package/dist/esm/server/impl/storage_impl.js.map +2 -2
  312. package/dist/esm/server/index.js +4 -1
  313. package/dist/esm/server/index.js.map +2 -2
  314. package/dist/esm/server/schema.js +34 -12
  315. package/dist/esm/server/schema.js.map +2 -2
  316. package/dist/esm/values/validators.js +1 -1
  317. package/dist/esm/values/validators.js.map +2 -2
  318. package/dist/esm/values/value.js +6 -0
  319. package/dist/esm/values/value.js.map +2 -2
  320. package/dist/esm-types/bundler/context.d.ts +5 -0
  321. package/dist/esm-types/bundler/context.d.ts.map +1 -1
  322. package/dist/esm-types/bundler/fs.d.ts +7 -2
  323. package/dist/esm-types/bundler/fs.d.ts.map +1 -1
  324. package/dist/esm-types/bundler/index.d.ts +9 -2
  325. package/dist/esm-types/bundler/index.d.ts.map +1 -1
  326. package/dist/esm-types/cli/account.d.ts +6 -0
  327. package/dist/esm-types/cli/account.d.ts.map +1 -0
  328. package/dist/esm-types/cli/codegen.d.ts.map +1 -1
  329. package/dist/esm-types/cli/configure.d.ts +6 -0
  330. package/dist/esm-types/cli/configure.d.ts.map +1 -1
  331. package/dist/esm-types/cli/deploy.d.ts +2 -0
  332. package/dist/esm-types/cli/deploy.d.ts.map +1 -1
  333. package/dist/esm-types/cli/deploymentCreate.d.ts +6 -6
  334. package/dist/esm-types/cli/deploymentSelect.d.ts.map +1 -1
  335. package/dist/esm-types/cli/dev.d.ts +1 -0
  336. package/dist/esm-types/cli/dev.d.ts.map +1 -1
  337. package/dist/esm-types/cli/env.d.ts.map +1 -1
  338. package/dist/esm-types/cli/envDefault.d.ts.map +1 -1
  339. package/dist/esm-types/cli/generatedApi.d.ts +1 -1
  340. package/dist/esm-types/cli/generatedApi.d.ts.map +1 -1
  341. package/dist/esm-types/cli/lib/api.d.ts.map +1 -1
  342. package/dist/esm-types/cli/lib/checkForLargeIndexBackfill.d.ts +30 -0
  343. package/dist/esm-types/cli/lib/checkForLargeIndexBackfill.d.ts.map +1 -0
  344. package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts +5 -7
  345. package/dist/esm-types/cli/lib/checkForLargeIndexDeletion.d.ts.map +1 -1
  346. package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts +4 -10
  347. package/dist/esm-types/cli/lib/checkForSlowSchemaValidation.d.ts.map +1 -1
  348. package/dist/esm-types/cli/lib/checkForStagedValidatorDeletion.d.ts +17 -0
  349. package/dist/esm-types/cli/lib/checkForStagedValidatorDeletion.d.ts.map +1 -0
  350. package/dist/esm-types/cli/lib/codegen.d.ts +0 -3
  351. package/dist/esm-types/cli/lib/codegen.d.ts.map +1 -1
  352. package/dist/esm-types/cli/lib/command.d.ts +2 -0
  353. package/dist/esm-types/cli/lib/command.d.ts.map +1 -1
  354. package/dist/esm-types/cli/lib/components/definition/bundle.d.ts +13 -0
  355. package/dist/esm-types/cli/lib/components/definition/bundle.d.ts.map +1 -1
  356. package/dist/esm-types/cli/lib/components.d.ts +4 -0
  357. package/dist/esm-types/cli/lib/components.d.ts.map +1 -1
  358. package/dist/esm-types/cli/lib/config.d.ts +2 -1
  359. package/dist/esm-types/cli/lib/config.d.ts.map +1 -1
  360. package/dist/esm-types/cli/lib/deploy2.d.ts +2 -0
  361. package/dist/esm-types/cli/lib/deploy2.d.ts.map +1 -1
  362. package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts +460 -16
  363. package/dist/esm-types/cli/lib/deployApi/evaluateSchema.d.ts.map +1 -1
  364. package/dist/esm-types/cli/lib/deployKeyWarning.d.ts +3 -0
  365. package/dist/esm-types/cli/lib/deployKeyWarning.d.ts.map +1 -0
  366. package/dist/esm-types/cli/lib/deployment.d.ts +2 -0
  367. package/dist/esm-types/cli/lib/deployment.d.ts.map +1 -1
  368. package/dist/esm-types/cli/lib/deploymentSelection.d.ts +2 -1
  369. package/dist/esm-types/cli/lib/deploymentSelection.d.ts.map +1 -1
  370. package/dist/esm-types/cli/lib/dev.d.ts +1 -0
  371. package/dist/esm-types/cli/lib/dev.d.ts.map +1 -1
  372. package/dist/esm-types/cli/lib/envvars.d.ts +6 -0
  373. package/dist/esm-types/cli/lib/envvars.d.ts.map +1 -1
  374. package/dist/esm-types/cli/lib/formatValidationProgress.d.ts +8 -0
  375. package/dist/esm-types/cli/lib/formatValidationProgress.d.ts.map +1 -0
  376. package/dist/esm-types/cli/lib/fsUtils.d.ts +1 -0
  377. package/dist/esm-types/cli/lib/fsUtils.d.ts.map +1 -1
  378. package/dist/esm-types/cli/lib/login.d.ts +3 -1
  379. package/dist/esm-types/cli/lib/login.d.ts.map +1 -1
  380. package/dist/esm-types/cli/lib/mcp/requestContext.d.ts.map +1 -1
  381. package/dist/esm-types/cli/lib/mcp/tools/env.d.ts +8 -5
  382. package/dist/esm-types/cli/lib/mcp/tools/env.d.ts.map +1 -1
  383. package/dist/esm-types/cli/lib/mcp/tools/insights.d.ts +2 -2
  384. package/dist/esm-types/cli/lib/profileManagement.d.ts +10 -0
  385. package/dist/esm-types/cli/lib/profileManagement.d.ts.map +1 -0
  386. package/dist/esm-types/cli/lib/profiles.d.ts +59 -0
  387. package/dist/esm-types/cli/lib/profiles.d.ts.map +1 -0
  388. package/dist/esm-types/cli/lib/run.d.ts.map +1 -1
  389. package/dist/esm-types/cli/lib/schemaEvaluation.d.ts +33 -0
  390. package/dist/esm-types/cli/lib/schemaEvaluation.d.ts.map +1 -0
  391. package/dist/esm-types/cli/lib/usageLimits.d.ts +1 -1
  392. package/dist/esm-types/cli/lib/usageLimits.d.ts.map +1 -1
  393. package/dist/esm-types/cli/lib/utils/mutex.d.ts +1 -3
  394. package/dist/esm-types/cli/lib/utils/mutex.d.ts.map +1 -1
  395. package/dist/esm-types/cli/lib/utils/utils.d.ts +15 -2
  396. package/dist/esm-types/cli/lib/utils/utils.d.ts.map +1 -1
  397. package/dist/esm-types/cli/login.d.ts +21 -0
  398. package/dist/esm-types/cli/login.d.ts.map +1 -1
  399. package/dist/esm-types/cli/logout.d.ts +8 -1
  400. package/dist/esm-types/cli/logout.d.ts.map +1 -1
  401. package/dist/esm-types/cli/mcp.d.ts.map +1 -1
  402. package/dist/esm-types/cli/program.d.ts.map +1 -1
  403. package/dist/esm-types/index.d.ts +1 -1
  404. package/dist/esm-types/index.d.ts.map +1 -1
  405. package/dist/esm-types/server/impl/actions_impl.d.ts +18 -3
  406. package/dist/esm-types/server/impl/actions_impl.d.ts.map +1 -1
  407. package/dist/esm-types/server/impl/storage_impl.d.ts.map +1 -1
  408. package/dist/esm-types/server/index.d.ts +1 -1
  409. package/dist/esm-types/server/index.d.ts.map +1 -1
  410. package/dist/esm-types/server/meta.d.ts +63 -0
  411. package/dist/esm-types/server/meta.d.ts.map +1 -1
  412. package/dist/esm-types/server/registration.d.ts +10 -0
  413. package/dist/esm-types/server/registration.d.ts.map +1 -1
  414. package/dist/esm-types/server/schema.d.ts +33 -0
  415. package/dist/esm-types/server/schema.d.ts.map +1 -1
  416. package/dist/esm-types/server/storage.d.ts.map +1 -1
  417. package/dist/esm-types/values/value.d.ts.map +1 -1
  418. package/dist/react.bundle.js +7 -1
  419. package/dist/react.bundle.js.map +2 -2
  420. package/package.json +5 -5
  421. package/schemas/convex.schema.json +5 -5
  422. package/src/bundler/context.ts +9 -5
  423. package/src/bundler/fs.ts +54 -5
  424. package/src/bundler/index.ts +9 -4
  425. package/src/cli/account.ts +320 -0
  426. package/src/cli/codegen.ts +0 -2
  427. package/src/cli/configure.ts +45 -9
  428. package/src/cli/deploy.ts +36 -5
  429. package/src/cli/deploymentSelect.ts +7 -4
  430. package/src/cli/dev.ts +9 -0
  431. package/src/cli/env.ts +12 -6
  432. package/src/cli/envDefault.ts +8 -2
  433. package/src/cli/generatedApi.ts +1 -1
  434. package/src/cli/lib/api.ts +5 -1
  435. package/src/cli/lib/checkForLargeIndexBackfill.ts +173 -0
  436. package/src/cli/lib/checkForLargeIndexDeletion.ts +45 -58
  437. package/src/cli/lib/checkForSlowSchemaValidation.ts +76 -65
  438. package/src/cli/lib/checkForStagedValidatorDeletion.ts +104 -0
  439. package/src/cli/lib/codegen.ts +0 -3
  440. package/src/cli/lib/command.ts +3 -0
  441. package/src/cli/lib/components/definition/bundle.ts +68 -14
  442. package/src/cli/lib/components.ts +71 -4
  443. package/src/cli/lib/config.ts +85 -18
  444. package/src/cli/lib/deploy2.ts +10 -1
  445. package/src/cli/lib/deployApi/evaluateSchema.ts +35 -0
  446. package/src/cli/lib/deployKeyWarning.ts +43 -0
  447. package/src/cli/lib/deployment.ts +2 -2
  448. package/src/cli/lib/deploymentSelection.ts +37 -18
  449. package/src/cli/lib/dev.ts +14 -0
  450. package/src/cli/lib/envvars.ts +43 -1
  451. package/src/cli/lib/formatValidationProgress.ts +35 -0
  452. package/src/cli/lib/fsUtils.ts +5 -2
  453. package/src/cli/lib/generateDocs.ts +1 -1
  454. package/src/cli/lib/indexes.ts +1 -1
  455. package/src/cli/lib/login.ts +47 -3
  456. package/src/cli/lib/mcp/requestContext.ts +7 -1
  457. package/src/cli/lib/mcp/tools/env.ts +17 -3
  458. package/src/cli/lib/profileManagement.ts +262 -0
  459. package/src/cli/lib/profiles.ts +398 -0
  460. package/src/cli/lib/run.ts +2 -0
  461. package/src/cli/lib/schemaEvaluation.ts +88 -0
  462. package/src/cli/lib/usageLimits.ts +2 -0
  463. package/src/cli/lib/utils/mutex.ts +9 -27
  464. package/src/cli/lib/utils/utils.ts +83 -36
  465. package/src/cli/login.ts +293 -168
  466. package/src/cli/logout.ts +142 -17
  467. package/src/cli/mcp.ts +48 -11
  468. package/src/cli/program.ts +2 -0
  469. package/src/cli/projectCreate.ts +1 -1
  470. package/src/index.ts +1 -1
  471. package/src/server/impl/actions_impl.ts +26 -6
  472. package/src/server/impl/storage_impl.ts +30 -0
  473. package/src/server/index.ts +5 -1
  474. package/src/server/meta.ts +56 -2
  475. package/src/server/registration.ts +10 -0
  476. package/src/server/schema.ts +37 -15
  477. package/src/server/storage.ts +17 -0
  478. package/src/values/validators.ts +1 -1
  479. package/src/values/value.ts +9 -5
package/src/cli/logout.ts CHANGED
@@ -1,24 +1,149 @@
1
1
  import { Command } from "@commander-js/extra-typings";
2
2
  import { oneoffContext } from "../bundler/context.js";
3
- import { logFinishedStep } from "../bundler/log.js";
3
+ import { logFinishedStep, logMessage, logWarning } from "../bundler/log.js";
4
4
  import { recursivelyDelete } from "./lib/fsUtils.js";
5
5
  import { globalConfigPath } from "./lib/utils/globalConfig.js";
6
+ import {
7
+ getProfileSelection,
8
+ profileConfigPath,
9
+ readProfileToken,
10
+ readProfileSettings,
11
+ updateProfileSettings,
12
+ savedProfileNames,
13
+ } from "./lib/profiles.js";
14
+ import path from "path";
15
+ import { rootDirectory } from "./lib/utils/utils.js";
16
+ import { promptOptions } from "./lib/utils/prompts.js";
6
17
 
7
- export const logout = new Command("logout")
8
- .description("Log out of Convex on this machine")
9
- .allowExcessArguments(false)
10
- .action(async () => {
11
- const ctx = await oneoffContext({
12
- url: undefined,
13
- adminKey: undefined,
14
- envFile: undefined,
15
- });
18
+ export function createLogoutCommand() {
19
+ return new Command("logout")
20
+ .description(
21
+ "Log out of the selected account. Directory selections are preserved.",
22
+ )
23
+ .option("--account <name>", "Remove only this account's saved credentials")
24
+ .option(
25
+ "--all",
26
+ "Remove all saved account credentials, preserving account selections",
27
+ )
28
+ .allowExcessArguments(false)
29
+ .action(async (options, cmd) => {
30
+ if (options.all && options.account !== undefined)
31
+ cmd.error("Pass either --account or --all, not both.");
32
+ const ctx = await oneoffContext({
33
+ url: undefined,
34
+ adminKey: undefined,
35
+ envFile: undefined,
36
+ skipAuth: true,
37
+ });
38
+
39
+ let all = !!options.all;
40
+ let profile = all
41
+ ? null
42
+ : await getProfileSelection(ctx, { name: options.account });
43
+ if (
44
+ !all &&
45
+ options.account === undefined &&
46
+ process.stdin.isTTY &&
47
+ profile !== null
48
+ ) {
49
+ const token = readProfileToken(ctx, profile.name);
50
+ const settings = await readProfileSettings(ctx);
51
+ const selectedName = profile.name;
52
+ // A matching compatibility token is another copy of this account's login.
53
+ const hasOtherLogins =
54
+ savedProfileNames(ctx).some((name) => name !== selectedName) ||
55
+ (typeof settings.accessToken === "string" &&
56
+ settings.accessToken.length > 0 &&
57
+ settings.accessToken !== token);
58
+ if (hasOtherLogins) {
59
+ const scope = await promptOptions(ctx, {
60
+ message: "Which saved logins would you like to log out of?",
61
+ choices: [
62
+ { name: `Only account "${profile.name}"`, value: "profile" },
63
+ { name: "All saved logins on this device", value: "all" },
64
+ ],
65
+ default: "profile",
66
+ });
67
+ if (scope === "all") {
68
+ profile = null;
69
+ all = true;
70
+ }
71
+ }
72
+ }
16
73
 
17
- if (ctx.fs.exists(globalConfigPath())) {
18
- recursivelyDelete(ctx, globalConfigPath());
19
- }
74
+ let warnAboutLegacyCredentials = false;
75
+ if (profile !== null) {
76
+ const selectedName = profile.name;
77
+ await updateProfileSettings(
78
+ ctx,
79
+ (settings) => {
80
+ const token = readProfileToken(ctx, selectedName);
81
+ // A migrated account can share its token with old CLI versions.
82
+ if (token !== null && settings.accessToken === token) {
83
+ delete settings.accessToken;
84
+ } else if (
85
+ settings.defaultProfile === selectedName &&
86
+ typeof settings.accessToken === "string" &&
87
+ settings.accessToken.length > 0
88
+ ) {
89
+ // Editing the default or logging in with an older CLI can leave this
90
+ // token belonging to a different account.
91
+ warnAboutLegacyCredentials = true;
92
+ }
93
+ },
94
+ () => {
95
+ const configPath = profileConfigPath(selectedName);
96
+ recursivelyDelete(ctx, configPath, {
97
+ force: true,
98
+ followSymlinks: false,
99
+ });
100
+ },
101
+ );
102
+ } else {
103
+ await updateProfileSettings(
104
+ ctx,
105
+ async (settings) => {
106
+ if (
107
+ !all &&
108
+ savedProfileNames(ctx).length > 0 &&
109
+ settings.accessToken === undefined
110
+ ) {
111
+ return await ctx.crash({
112
+ exitCode: 1,
113
+ errorType: "fatal",
114
+ printedMessage:
115
+ "No account is selected. Use `npx convex logout --account <name>` or `npx convex logout --all`.",
116
+ });
117
+ }
118
+ delete settings.accessToken;
119
+ },
120
+ () => {
121
+ const profilesDir = path.join(rootDirectory(), "profiles");
122
+ if (all)
123
+ recursivelyDelete(ctx, profilesDir, {
124
+ force: true,
125
+ followSymlinks: false,
126
+ });
127
+ },
128
+ );
129
+ }
130
+
131
+ logFinishedStep(
132
+ profile !== null
133
+ ? `Removed credentials for account "${profile.name}".\n Run \`npx convex login --account ${profile.name}\` to log in.`
134
+ : `${all ? "Removed all saved Convex account credentials." : "Removed your saved Convex login credentials."}\n Run \`npx convex login\` to log in.`,
135
+ );
136
+ if (warnAboutLegacyCredentials) {
137
+ logWarning(
138
+ `Saved credentials remain in ${globalConfigPath()} for older CLI versions. To remove all saved account credentials, run \`npx convex logout --all\`.`,
139
+ );
140
+ }
141
+ if (process.env.CONVEX_OVERRIDE_ACCESS_TOKEN) {
142
+ logMessage(
143
+ "CONVEX_OVERRIDE_ACCESS_TOKEN still supplies credentials. Unset it to stop using that token.",
144
+ );
145
+ }
146
+ });
147
+ }
20
148
 
21
- logFinishedStep(
22
- "You have been logged out of Convex.\n Run `npx convex dev` to log in.",
23
- );
24
- });
149
+ export const logout = createLogoutCommand();
package/src/cli/mcp.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import path from "path";
1
2
  import { Command, Option } from "@commander-js/extra-typings";
2
3
  import { oneoffContext } from "../bundler/context.js";
3
4
  import { logError } from "../bundler/log.js";
@@ -6,6 +7,7 @@ import { serveStdio } from "@modelcontextprotocol/server/stdio";
6
7
  import { actionDescription } from "./lib/command.js";
7
8
  import { checkAuthorization } from "./lib/login.js";
8
9
  import {
10
+ encodeDeploymentSelector,
9
11
  McpOptions,
10
12
  RequestContext,
11
13
  RequestCrash,
@@ -115,6 +117,14 @@ function enabledTools(
115
117
  export function makeServer(options: McpOptions) {
116
118
  const enabledToolsByName = enabledTools(options);
117
119
  const mutex = new Mutex();
120
+ const serverDirectory = process.cwd();
121
+ options = {
122
+ ...options,
123
+ envFile:
124
+ options.envFile === undefined
125
+ ? undefined
126
+ : path.resolve(serverDirectory, options.envFile),
127
+ };
118
128
  const server = new Server(
119
129
  {
120
130
  name: "Convex MCP Server",
@@ -128,17 +138,7 @@ export function makeServer(options: McpOptions) {
128
138
  );
129
139
  server.setRequestHandler("tools/call", async (request: CallToolRequest) => {
130
140
  const ctx = new RequestContext(options);
131
- await initializeBigBrainAuth(ctx, options);
132
141
  try {
133
- const authorized = await checkAuthorization(ctx, false);
134
- if (!authorized) {
135
- await ctx.crash({
136
- exitCode: 1,
137
- errorType: "fatal",
138
- printedMessage:
139
- "Not Authorized: Run `npx convex dev` to login to your Convex project.",
140
- });
141
- }
142
142
  if (!request.params.arguments) {
143
143
  await ctx.crash({
144
144
  exitCode: 1,
@@ -158,7 +158,44 @@ export function makeServer(options: McpOptions) {
158
158
 
159
159
  // Serialize tool handlers since they're mutating the current working directory.
160
160
  const result = await mutex.runExclusive(async () => {
161
- return await convexTool.handler(ctx, input);
161
+ const projectDir =
162
+ "deploymentSelector" in input
163
+ ? ctx.decodeDeploymentSelectorUnchecked(input.deploymentSelector)
164
+ .projectDir
165
+ : (("projectDir" in input ? input.projectDir : undefined) ??
166
+ options.projectDir);
167
+ const previousDirectory = process.cwd();
168
+ try {
169
+ if (projectDir !== undefined)
170
+ process.chdir(path.resolve(serverDirectory, projectDir));
171
+ await initializeBigBrainAuth(ctx, options);
172
+ if (!(await checkAuthorization(ctx, false))) {
173
+ await ctx.crash({
174
+ exitCode: 1,
175
+ errorType: "fatal",
176
+ printedMessage:
177
+ "Not Authorized: Run `npx convex dev` to login to your Convex project.",
178
+ });
179
+ }
180
+ const absoluteDirectory = process.cwd();
181
+ const resolvedInput =
182
+ "deploymentSelector" in input
183
+ ? {
184
+ ...input,
185
+ deploymentSelector: encodeDeploymentSelector(
186
+ absoluteDirectory,
187
+ ctx.decodeDeploymentSelectorUnchecked(
188
+ input.deploymentSelector,
189
+ ).deployment,
190
+ ),
191
+ }
192
+ : projectDir === undefined
193
+ ? input
194
+ : { ...input, projectDir: absoluteDirectory };
195
+ return await convexTool.handler(ctx, resolvedInput);
196
+ } finally {
197
+ process.chdir(previousDirectory);
198
+ }
162
199
  });
163
200
  return {
164
201
  content: [
@@ -21,6 +21,7 @@ import { logout } from "./logout.js";
21
21
  import { logs } from "./logs.js";
22
22
  import { mcp } from "./mcp.js";
23
23
  import { networkTest } from "./network_test.js";
24
+ import { account } from "./account.js";
24
25
  import { project } from "./project.js";
25
26
  import { reinit } from "./reinit.js";
26
27
  import { run } from "./run.js";
@@ -56,6 +57,7 @@ export function buildProgram() {
56
57
  .addCommand(codegen)
57
58
  .addCommand(update)
58
59
  .addCommand(logout)
60
+ .addCommand(account)
59
61
  .addCommand(networkTest, { hidden: true })
60
62
  .addCommand(integration, { hidden: true })
61
63
  .addCommand(functionSpec)
@@ -64,7 +64,7 @@ async function runProjectCreate(
64
64
  logMessage(
65
65
  chalkStderr.gray(
66
66
  `Next, add a deployment with ` +
67
- `\`npx convex deployment create ${team.slug}:${projectSlug}:dev --type dev\` ` +
67
+ `\`npx convex deployment create ${team.slug}:${projectSlug}:dev/my-feature --type dev --select\` ` +
68
68
  `(pass \`--region us\` to choose a region).`,
69
69
  ),
70
70
  );
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export const version = "1.46.0";
1
+ export const version = "1.48.0-alpha.0";
@@ -64,26 +64,46 @@ export function setupActionCalls(requestId: string) {
64
64
  };
65
65
  }
66
66
 
67
+ /**
68
+ * A Convex-managed service. The backend decides which names it accepts; this
69
+ * type lists the ones the current release knows about.
70
+ */
71
+ export type ServiceName = "ai-gateway";
72
+
67
73
  /**
68
74
  * Get a short-lived credential for calling a Convex-managed service.
69
75
  *
70
76
  * This function can only be called while an action is running. The credential
71
77
  * is scoped to the current deployment and should be sent as a bearer token.
72
- * Repeated calls in the same action reuse one token; a failed mint is not
73
- * cached, so a later call retries.
78
+ * The action runtime caches and refreshes credentials as needed, so call
79
+ * this function whenever making a service request.
74
80
  *
75
81
  * @param service - The service the credential may access.
76
82
  * @returns A JWT to send as `Authorization: Bearer <token>`. Keep it inside
77
83
  * the action: don't return it to clients or store it in environment
78
84
  * variables.
79
85
  */
80
- export async function getServiceToken(service: "ai-gateway"): Promise<string> {
86
+ export async function getServiceToken(service: ServiceName): Promise<string> {
81
87
  validateArg(service, 1, "getServiceToken", "service");
82
- if (service !== "ai-gateway") {
83
- throw new Error(`Unsupported service "${String(service)}"`);
84
- }
85
88
  return await performAsyncSyscall("1.0/createServiceToken", {
86
89
  service,
87
90
  version,
88
91
  });
89
92
  }
93
+
94
+ /**
95
+ * Get the base URL of a Convex-managed service.
96
+ *
97
+ * This function can only be called while an action is running. Pair it with
98
+ * {@link getServiceToken} to reach the service.
99
+ *
100
+ * @param service - The service to address.
101
+ * @returns The service's origin, without a trailing slash.
102
+ */
103
+ export async function getServiceUrl(service: ServiceName): Promise<string> {
104
+ validateArg(service, 1, "getServiceUrl", "service");
105
+ return await performAsyncSyscall("1.0/getServiceUrl", {
106
+ service,
107
+ version,
108
+ });
109
+ }
@@ -6,6 +6,7 @@ import {
6
6
  StorageWriter,
7
7
  } from "../storage.js";
8
8
  import { version } from "../../index.js";
9
+ import { fromByteArray, toByteArray } from "../../values/base64.js";
9
10
  import { performAsyncSyscall, performJsSyscall } from "./syscall.js";
10
11
  import { validateArg } from "./validate.js";
11
12
 
@@ -45,6 +46,35 @@ export function setupStorageWriter(requestId: string): StorageWriter {
45
46
  storageId,
46
47
  });
47
48
  },
49
+ store: async (blob: Blob, options?: { sha256?: string }) => {
50
+ if (!(blob instanceof Blob)) {
51
+ throw new Error(
52
+ "store() expects a Blob. If you are trying to store a Request, `await request.blob()` will give you the correct input.",
53
+ );
54
+ }
55
+ const bytes = new Uint8Array(await blob.arrayBuffer());
56
+ return await performAsyncSyscall("1.0/storageStore", {
57
+ requestId,
58
+ version,
59
+ blob: fromByteArray(bytes),
60
+ contentType: blob.type,
61
+ sha256: options?.sha256,
62
+ });
63
+ },
64
+ get: async (storageId: FileStorageId) => {
65
+ const result: { blob: string; contentType: string | null } | null =
66
+ await performAsyncSyscall("1.0/storageGet", {
67
+ requestId,
68
+ version,
69
+ storageId,
70
+ });
71
+ if (result === null) {
72
+ return null;
73
+ }
74
+ return new Blob([toByteArray(result.blob)], {
75
+ type: result.contentType ?? "",
76
+ });
77
+ },
48
78
  getUrl: reader.getUrl,
49
79
  getMetadata: reader.getMetadata,
50
80
  };
@@ -103,7 +103,11 @@ export {
103
103
  internalMutationGeneric,
104
104
  internalQueryGeneric,
105
105
  } from "./impl/registration_impl.js";
106
- export { getServiceToken } from "./impl/actions_impl.js";
106
+ export {
107
+ getServiceToken,
108
+ getServiceUrl,
109
+ type ServiceName,
110
+ } from "./impl/actions_impl.js";
107
111
  export type {
108
112
  TransactionMetric,
109
113
  TransactionMetrics,
@@ -26,6 +26,14 @@ export type TransactionMetrics = {
26
26
  documentsWritten: TransactionMetric;
27
27
  functionsScheduled: TransactionMetric;
28
28
  scheduledFunctionArgsBytes: TransactionMetric;
29
+ /** @internal */
30
+ filesWritten: TransactionMetric;
31
+ /** @internal */
32
+ fileWriteBytes: TransactionMetric;
33
+ /** @internal */
34
+ filesRead: TransactionMetric;
35
+ /** @internal */
36
+ fileReadBytes: TransactionMetric;
29
37
  };
30
38
 
31
39
  /**
@@ -43,6 +51,14 @@ export interface TransactionLimits {
43
51
  documentsWritten?: number;
44
52
  functionsScheduled?: number;
45
53
  scheduledFunctionArgsBytes?: number;
54
+ /** @internal */
55
+ filesWritten?: number;
56
+ /** @internal */
57
+ fileWriteBytes?: number;
58
+ /** @internal */
59
+ filesRead?: number;
60
+ /** @internal */
61
+ fileReadBytes?: number;
46
62
  }
47
63
 
48
64
  /**
@@ -130,18 +146,30 @@ export type RequestMetadata = {
130
146
  * @public
131
147
  */
132
148
  export interface QueryMeta {
149
+ /**
150
+ * Metadata about the currently executing Convex function.
151
+ */
133
152
  getFunctionMetadata(): Promise<FunctionMetadata>;
153
+ /**
154
+ * The remaining headroom for a transaction before hitting limits.
155
+ *
156
+ * See https://docs.convex.dev/production/state/limits
157
+ */
134
158
  getTransactionMetrics(): Promise<TransactionMetrics>;
159
+ /**
160
+ * Metadata about the deployment this function is running on.
161
+ */
135
162
  getDeploymentMetadata(): Promise<DeploymentMetadata>;
136
163
  /**
137
- * @internal
138
164
  * Returns the timestamp of the database snapshot this transaction reads
139
165
  * from, in nanoseconds.
140
166
  *
141
167
  * All commits at or before this timestamp are observable within the
142
168
  * transaction, and no later commits are. The value is fixed for the
143
169
  * lifetime of the transaction and shared with all nested `runMutation` and
144
- * `runQuery` calls.
170
+ * non-stale `runQuery` calls. If a nested query is called with
171
+ * `useStaleSnapshot: true`, then the nested query may in a future backend
172
+ * version choose an older snapshotTs.
145
173
  *
146
174
  * It is on the same clock as `db.vars.commitTs`: documents observable in
147
175
  * this transaction have `commitTs` values at or before this timestamp, and
@@ -156,6 +184,8 @@ export interface QueryMeta {
156
184
  * Note: this should not be compared to `_creationTime` or `Date.now()`, as
157
185
  * those are based on wall-clock time rather than the database clock, and
158
186
  * aren't guaranteed to follow commit order.
187
+ *
188
+ * Docs: https://docs.convex.dev/database/advanced/commit-timestamp
159
189
  */
160
190
  getSnapshotTs(): bigint;
161
191
  }
@@ -166,6 +196,15 @@ export interface QueryMeta {
166
196
  * @public
167
197
  */
168
198
  export interface MutationMeta extends QueryMeta {
199
+ /**
200
+ * Metadata about the HTTP request that triggered the current function execution.
201
+ *
202
+ * `ip` and `userAgent` are `null` when the function was not triggered by an
203
+ * HTTP request (e.g. scheduled jobs or cron jobs).
204
+ *
205
+ * Functions called from within a function (i.e. using `runMutation`) will have
206
+ * the same request metadata as the parent function.
207
+ */
169
208
  getRequestMetadata(): Promise<RequestMetadata>;
170
209
  }
171
210
 
@@ -175,7 +214,22 @@ export interface MutationMeta extends QueryMeta {
175
214
  * @public
176
215
  */
177
216
  export interface ActionMeta {
217
+ /**
218
+ * Metadata about the currently executing Convex function.
219
+ */
178
220
  getFunctionMetadata(): Promise<FunctionMetadata>;
221
+ /**
222
+ * Metadata about the deployment this function is running on.
223
+ */
179
224
  getDeploymentMetadata(): Promise<DeploymentMetadata>;
225
+ /**
226
+ * Metadata about the HTTP request that triggered the current function execution.
227
+ *
228
+ * `ip` and `userAgent` are `null` when the function was not triggered by an
229
+ * HTTP request (e.g. scheduled jobs or cron jobs).
230
+ *
231
+ * Functions called from within a function (i.e. using `runMutation` or
232
+ * `runAction`) will have the same request metadata as the parent function.
233
+ */
180
234
  getRequestMetadata(): Promise<RequestMetadata>;
181
235
  }
@@ -1234,6 +1234,11 @@ export type HttpActionBuilder = (
1234
1234
  ) => PublicHttpAction;
1235
1235
 
1236
1236
  export interface AdvancedRunQueryOptions {
1237
+ /**
1238
+ * Custom limits for a nested transaction. Each field specifies the absolute
1239
+ * maximum allowed for the nested function call. Values are capped at the
1240
+ * global transaction limits, so they can only lower limits, never raise them.
1241
+ */
1237
1242
  transactionLimits?: TransactionLimits;
1238
1243
  /**
1239
1244
  * Run a query on a recent snapshot of the database that is not guaranteed
@@ -1244,6 +1249,11 @@ export interface AdvancedRunQueryOptions {
1244
1249
  * database read conflicts are expected, e.g. reading from an append-only
1245
1250
  * table with immutable records where the only read conflicts are from
1246
1251
  * concurrent appends.
1252
+ *
1253
+ * To determine the snapshot of the nested query, you can call
1254
+ * `ctx.meta.getSnapshotTs()` from within the stale snapshot query. To
1255
+ * compare to the parent mutation's snapshot timestamp, you can return that
1256
+ * value from the query and call `ctx.meta.getSnapshotTs()` from the parent.
1247
1257
  */
1248
1258
  useStaleSnapshot?: boolean;
1249
1259
  }
@@ -561,41 +561,63 @@ export class TableDefinition<
561
561
  }
562
562
 
563
563
  /**
564
- * Stage a new document validator for this table.
564
+ * Stage changes to this table's document validator.
565
565
  *
566
566
  * Convex validates the staged validator against the table's existing
567
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()`.
568
+ * {@link defineTable} remains the one enforced on writes. Once
569
+ * the background validation succeeds, apply the staged changes
570
+ * and remove `.staged()`.
571
+ *
572
+ * For an object validator, pass only the fields to add or replace. Fields
573
+ * omitted from the changes keep their enforced validators.
574
+ * Set a field to `undefined` to remove it from the staged validator.
575
+ * For nested objects, you must specify the full object validator.
571
576
  *
572
577
  * ```ts
573
578
  * defineTable({
574
- * author: v.string(),
579
+ * apple: v.string(),
580
+ * banana: v.number(),
581
+ * legacy: v.optional(v.string()),
575
582
  * }).staged({
576
- * author: v.array(v.string()),
583
+ * banana: v.union(v.string(), v.number()),
584
+ * legacy: undefined,
577
585
  * })
578
586
  * ```
579
587
  *
580
- * TODO: link a worked staged-schema example from the docs once one exists.
588
+ * See [Staged validators](https://docs.convex.dev/database/schemas#staged-validators).
581
589
  *
582
- * @param documentSchema - The proposed next type of documents stored in
583
- * this table, as an object of field validators or a schema validator.
590
+ * @param documentSchema - Field changes for a table defined as an object or
591
+ * `v.any()`, or a full schema validator specifying the proposed next document
592
+ * type. Use a full schema validator for a table defined as a union.
584
593
  * @returns A {@link TableDefinition} with the staged validator attached.
585
- *
586
- * @internal
587
594
  */
588
595
  staged(
589
596
  documentSchema:
590
597
  | Validator<Record<string, any>, "required", any>
591
- | Record<string, GenericValidator>,
598
+ | Record<string, GenericValidator | undefined>,
592
599
  ): TableDefinition<DocumentType, Indexes, SearchIndexes, VectorIndexes> {
593
600
  if (this.stagedValidator !== undefined) {
594
601
  throw new Error("Table cannot have more than one staged validator.");
595
602
  }
596
- this.stagedValidator = isValidator(documentSchema)
597
- ? documentSchema
598
- : v.object(documentSchema);
603
+ if (isValidator(documentSchema)) {
604
+ this.stagedValidator = documentSchema;
605
+ } else {
606
+ if (this.validator.kind !== "object" && this.validator.kind !== "any") {
607
+ throw new Error(
608
+ "Specifying top-level field changes is only supported for simple table definitions. For a table defined with a union or record validator, you must stage a fully defined object or union validator.",
609
+ );
610
+ }
611
+ const enforcedFields =
612
+ this.validator.kind === "object" ? this.validator.fields : {};
613
+ const fields: Record<string, GenericValidator> = Object.fromEntries(
614
+ Object.entries({ ...enforcedFields, ...documentSchema }).filter(
615
+ (entry): entry is [string, GenericValidator] =>
616
+ entry[1] !== undefined,
617
+ ),
618
+ );
619
+ this.stagedValidator = v.object(fields);
620
+ }
599
621
  return this.self();
600
622
  }
601
623
 
@@ -194,6 +194,23 @@ export interface StorageWriter extends StorageReader {
194
194
  delete<T extends StorageId>(
195
195
  storageId: T extends { __tableName: any } ? never : T,
196
196
  ): Promise<void>;
197
+
198
+ /**
199
+ * @internal
200
+ */
201
+ // TODO: move `store` from StorageActionWriter to StorageWriter when mutation
202
+ // file storage access is ready for release
203
+ store(
204
+ blob: Blob,
205
+ options?: { sha256?: string },
206
+ ): Promise<GenericId<"_storage">>;
207
+
208
+ /**
209
+ * @internal
210
+ */
211
+ // TODO: move `get` from StorageActionWriter to StorageWriter when mutation
212
+ // file storage access is ready for release
213
+ get(storageId: GenericId<"_storage">): Promise<Blob | null>;
197
214
  }
198
215
 
199
216
  /**
@@ -641,7 +641,7 @@ export class VRecord<
641
641
  throw new Error("Record validator cannot have optional values");
642
642
  }
643
643
  if (!key.isConvexValidator || !value.isConvexValidator) {
644
- throw new Error("Key and value of v.record() but be validators");
644
+ throw new Error("Key and value of v.record() must be validators");
645
645
  }
646
646
  this.key = key;
647
647
  this.value = value;
@@ -311,13 +311,17 @@ const MAX_VALUE_FOR_ERROR_LEN = 16384;
311
311
  export function stringifyValueForError(value: any) {
312
312
  const str = JSON.stringify(value, (_key, value) => {
313
313
  if (value === undefined) {
314
- // By default `JSON.stringify` converts undefined, functions, symbols,
315
- // Infinity, and NaN to null which produces a confusing error message.
316
- // We deal with `undefined` specifically because it's the most common.
317
- // Ideally we'd use a pretty-printing library that prints `undefined`
318
- // (no quotes), but it might not be worth the bundle size cost.
314
+ // JSON.stringify omits undefined object properties and converts undefined
315
+ // array elements to null. Preserve them in error messages.
319
316
  return "undefined";
320
317
  }
318
+ if (typeof value === "function") {
319
+ // A fixed placeholder also works for functions with custom string coercion.
320
+ return "[Function]";
321
+ }
322
+ if (typeof value === "symbol") {
323
+ return String(value);
324
+ }
321
325
  if (typeof value === "bigint") {
322
326
  // `JSON.stringify` throws on bigints by default.
323
327
  return `${value.toString()}n`;