cvx-kit 0.2.0 → 2.0.0-beta.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 (372) hide show
  1. package/README.md +556 -99
  2. package/dist/agent-tools.d.mts +39 -26
  3. package/dist/agent-tools.mjs +1 -1
  4. package/dist/agent-tools.mjs.map +1 -1
  5. package/dist/auth.d.mts +120 -308
  6. package/dist/auth.mjs +1 -1
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/components/approvals/_generated/api.d.mts +7 -9
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -1
  10. package/dist/components/approvals/_generated/component.d.mts +1 -4
  11. package/dist/components/approvals/_generated/dataModel.d.mts +5 -8
  12. package/dist/components/approvals/_generated/server.d.mts +12 -15
  13. package/dist/components/approvals/_generated/server.mjs.map +1 -1
  14. package/dist/components/approvals/audit.d.mts +8 -9
  15. package/dist/components/approvals/audit.mjs +1 -1
  16. package/dist/components/approvals/audit.mjs.map +1 -1
  17. package/dist/components/approvals/client.d.mts +11 -12
  18. package/dist/components/approvals/client.mjs +1 -1
  19. package/dist/components/approvals/client.mjs.map +1 -1
  20. package/dist/components/approvals/constants.d.mts +30 -31
  21. package/dist/components/approvals/constants.mjs.map +1 -1
  22. package/dist/components/approvals/convex.config.d.mts +0 -2
  23. package/dist/components/approvals/convex.config.mjs.map +1 -1
  24. package/dist/components/approvals/decisions.d.mts +13 -17
  25. package/dist/components/approvals/decisions.mjs +1 -1
  26. package/dist/components/approvals/decisions.mjs.map +1 -1
  27. package/dist/components/approvals/functions.d.mts +3 -4
  28. package/dist/components/approvals/functions.mjs +1 -1
  29. package/dist/components/approvals/functions.mjs.map +1 -1
  30. package/dist/components/approvals/health.d.mts +2 -3
  31. package/dist/components/approvals/health.mjs.map +1 -1
  32. package/dist/components/approvals/requests.d.mts +114 -131
  33. package/dist/components/approvals/requests.mjs +1 -1
  34. package/dist/components/approvals/requests.mjs.map +1 -1
  35. package/dist/components/approvals/schema.d.ts +106 -315
  36. package/dist/components/approvals/schema.js +1 -1
  37. package/dist/components/approvals/validators.d.mts +323 -395
  38. package/dist/components/approvals/validators.mjs +1 -1
  39. package/dist/components/approvals/validators.mjs.map +1 -1
  40. package/dist/components/approvals/workflow.d.mts +4 -5
  41. package/dist/components/approvals/workflow.mjs +1 -1
  42. package/dist/components/approvals/workflow.mjs.map +1 -1
  43. package/dist/components/approvals/workflow_steps.d.mts +16 -17
  44. package/dist/components/approvals/workflow_steps.mjs +1 -1
  45. package/dist/components/approvals/workflow_steps.mjs.map +1 -1
  46. package/dist/components/foundation/_generated/api.d.mts +6 -8
  47. package/dist/components/foundation/_generated/api.mjs.map +1 -1
  48. package/dist/components/foundation/_generated/component.d.mts +1 -4
  49. package/dist/components/foundation/_generated/dataModel.d.mts +5 -8
  50. package/dist/components/foundation/_generated/server.d.mts +12 -15
  51. package/dist/components/foundation/_generated/server.mjs.map +1 -1
  52. package/dist/components/foundation/client.d.mts +45 -38
  53. package/dist/components/foundation/client.mjs +1 -1
  54. package/dist/components/foundation/client.mjs.map +1 -1
  55. package/dist/components/foundation/convex.config.d.mts +0 -2
  56. package/dist/components/foundation/convex.config.mjs.map +1 -1
  57. package/dist/components/foundation/functions.d.mts +2 -3
  58. package/dist/components/foundation/functions.mjs.map +1 -1
  59. package/dist/components/foundation/modules/command/command.d.mts +65 -17
  60. package/dist/components/foundation/modules/command/command.mjs +1 -1
  61. package/dist/components/foundation/modules/command/command.mjs.map +1 -1
  62. package/dist/components/foundation/modules/command/lifecycle.d.mts +78 -0
  63. package/dist/components/foundation/modules/command/lifecycle.mjs +2 -0
  64. package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -0
  65. package/dist/components/foundation/modules/observability/observability.d.mts +13 -6
  66. package/dist/components/foundation/modules/observability/observability.mjs +1 -1
  67. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
  68. package/dist/components/foundation/modules/query/query.d.mts +11 -12
  69. package/dist/components/foundation/modules/query/query.mjs +1 -1
  70. package/dist/components/foundation/modules/query/query.mjs.map +1 -1
  71. package/dist/components/foundation/operation.d.mts +72 -0
  72. package/dist/components/foundation/operation.mjs +2 -0
  73. package/dist/components/foundation/operation.mjs.map +1 -0
  74. package/dist/components/foundation/result.d.mts +7 -8
  75. package/dist/components/foundation/result.mjs.map +1 -1
  76. package/dist/components/foundation/schema.d.ts +0 -2
  77. package/dist/components/foundation/telemetry.d.mts +2 -3
  78. package/dist/components/foundation/telemetry.mjs +1 -1
  79. package/dist/components/foundation/telemetry.mjs.map +1 -1
  80. package/dist/contracts.d.mts +5 -0
  81. package/dist/contracts.mjs +1 -0
  82. package/dist/crud.d.mts +185 -27
  83. package/dist/crud.mjs +1 -1
  84. package/dist/crud.mjs.map +1 -1
  85. package/dist/effect.d.mts +16 -0
  86. package/dist/effect.mjs +1 -0
  87. package/dist/errors.d.mts +6 -6
  88. package/dist/errors.mjs +1 -1
  89. package/dist/errors.mjs.map +1 -1
  90. package/dist/filters.d.mts +4 -0
  91. package/dist/filters.mjs +1 -0
  92. package/dist/idempotency.d.mts +2 -0
  93. package/dist/idempotency.mjs +1 -0
  94. package/dist/index.d.mts +14 -7
  95. package/dist/index.mjs +1 -1
  96. package/dist/json-schema.d.mts +40 -0
  97. package/dist/json-schema.mjs +2 -0
  98. package/dist/json-schema.mjs.map +1 -0
  99. package/dist/k/compile.d.mts +17 -0
  100. package/dist/k/compile.mjs +2 -0
  101. package/dist/k/compile.mjs.map +1 -0
  102. package/dist/k/dates.d.mts +23 -0
  103. package/dist/k/dates.mjs +2 -0
  104. package/dist/k/dates.mjs.map +1 -0
  105. package/dist/k/formats.d.mts +24 -0
  106. package/dist/k/formats.mjs +2 -0
  107. package/dist/k/formats.mjs.map +1 -0
  108. package/dist/k/index.d.mts +32 -0
  109. package/dist/k/index.mjs +2 -0
  110. package/dist/k/index.mjs.map +1 -0
  111. package/dist/k/issues.d.mts +31 -0
  112. package/dist/k/issues.mjs +2 -0
  113. package/dist/k/issues.mjs.map +1 -0
  114. package/dist/k/kinds.d.mts +81 -0
  115. package/dist/k/kinds.mjs +2 -0
  116. package/dist/k/kinds.mjs.map +1 -0
  117. package/dist/k/object.d.mts +43 -0
  118. package/dist/k/object.mjs +2 -0
  119. package/dist/k/object.mjs.map +1 -0
  120. package/dist/k/parse.d.mts +29 -0
  121. package/dist/k/parse.mjs +2 -0
  122. package/dist/k/parse.mjs.map +1 -0
  123. package/dist/k/schema.d.mts +100 -0
  124. package/dist/k/schema.mjs +2 -0
  125. package/dist/k/schema.mjs.map +1 -0
  126. package/dist/k/standard.d.mts +8 -0
  127. package/dist/k/standard.mjs +2 -0
  128. package/dist/k/standard.mjs.map +1 -0
  129. package/dist/k/types.d.mts +64 -0
  130. package/dist/k/types.mjs +1 -0
  131. package/dist/k.d.mts +8 -0
  132. package/dist/k.mjs +1 -0
  133. package/dist/middleware.d.mts +8 -11
  134. package/dist/middleware.mjs +1 -1
  135. package/dist/middleware.mjs.map +1 -1
  136. package/dist/modules/contracts/binding.d.mts +23 -0
  137. package/dist/modules/contracts/binding.mjs +2 -0
  138. package/dist/modules/contracts/binding.mjs.map +1 -0
  139. package/dist/modules/contracts/contract.d.mts +67 -0
  140. package/dist/modules/contracts/contract.mjs +2 -0
  141. package/dist/modules/contracts/contract.mjs.map +1 -0
  142. package/dist/modules/contracts/convex.d.mts +18 -0
  143. package/dist/modules/contracts/convex.mjs +2 -0
  144. package/dist/modules/contracts/convex.mjs.map +1 -0
  145. package/dist/modules/contracts/domain.d.mts +62 -0
  146. package/dist/modules/contracts/domain.mjs +2 -0
  147. package/dist/modules/contracts/domain.mjs.map +1 -0
  148. package/dist/modules/contracts/errors.d.mts +737 -0
  149. package/dist/modules/contracts/errors.mjs +2 -0
  150. package/dist/modules/contracts/errors.mjs.map +1 -0
  151. package/dist/modules/contracts/exposure.d.mts +103 -0
  152. package/dist/modules/contracts/exposure.mjs +2 -0
  153. package/dist/modules/contracts/exposure.mjs.map +1 -0
  154. package/dist/modules/contracts/idempotency.d.mts +85 -0
  155. package/dist/modules/contracts/idempotency.mjs +2 -0
  156. package/dist/modules/contracts/idempotency.mjs.map +1 -0
  157. package/dist/modules/contracts/lazy.d.mts +6 -0
  158. package/dist/modules/contracts/lazy.mjs +2 -0
  159. package/dist/modules/contracts/lazy.mjs.map +1 -0
  160. package/dist/modules/contracts/standard.d.mts +17 -0
  161. package/dist/modules/contracts/standard.mjs +2 -0
  162. package/dist/modules/contracts/standard.mjs.map +1 -0
  163. package/dist/modules/contracts/workflow.d.mts +165 -0
  164. package/dist/modules/contracts/workflow.mjs +2 -0
  165. package/dist/modules/contracts/workflow.mjs.map +1 -0
  166. package/dist/modules/effect/action.d.mts +63 -0
  167. package/dist/modules/effect/action.mjs +2 -0
  168. package/dist/modules/effect/action.mjs.map +1 -0
  169. package/dist/modules/effect/agent-tools.d.mts +2 -0
  170. package/dist/modules/effect/agent-tools.mjs +1 -0
  171. package/dist/modules/effect/api-runtime.d.mts +36 -0
  172. package/dist/modules/effect/api-runtime.mjs +2 -0
  173. package/dist/modules/effect/api-runtime.mjs.map +1 -0
  174. package/dist/modules/effect/api.d.mts +46 -0
  175. package/dist/modules/effect/api.mjs +2 -0
  176. package/dist/modules/effect/api.mjs.map +1 -0
  177. package/dist/modules/effect/auth.d.mts +46 -0
  178. package/dist/modules/effect/auth.mjs +2 -0
  179. package/dist/modules/effect/auth.mjs.map +1 -0
  180. package/dist/modules/effect/client.d.mts +15 -0
  181. package/dist/modules/effect/client.mjs +1 -0
  182. package/dist/modules/effect/command.d.mts +108 -0
  183. package/dist/modules/effect/command.mjs +2 -0
  184. package/dist/modules/effect/command.mjs.map +1 -0
  185. package/dist/modules/effect/crud.d.mts +885 -0
  186. package/dist/modules/effect/crud.mjs +2 -0
  187. package/dist/modules/effect/crud.mjs.map +1 -0
  188. package/dist/modules/effect/domain.d.mts +82 -0
  189. package/dist/modules/effect/domain.mjs +2 -0
  190. package/dist/modules/effect/domain.mjs.map +1 -0
  191. package/dist/modules/effect/errors.d.mts +13 -0
  192. package/dist/modules/effect/errors.mjs +2 -0
  193. package/dist/modules/effect/errors.mjs.map +1 -0
  194. package/dist/modules/effect/failure-audit.d.mts +48 -0
  195. package/dist/modules/effect/failure-audit.mjs +2 -0
  196. package/dist/modules/effect/failure-audit.mjs.map +1 -0
  197. package/dist/modules/effect/failures.d.mts +21 -0
  198. package/dist/modules/effect/failures.mjs +2 -0
  199. package/dist/modules/effect/failures.mjs.map +1 -0
  200. package/dist/modules/effect/foundation.d.mts +23 -0
  201. package/dist/modules/effect/foundation.mjs +2 -0
  202. package/dist/modules/effect/foundation.mjs.map +1 -0
  203. package/dist/modules/effect/idempotency.d.mts +29 -0
  204. package/dist/modules/effect/idempotency.mjs +2 -0
  205. package/dist/modules/effect/idempotency.mjs.map +1 -0
  206. package/dist/modules/effect/input.d.mts +10 -0
  207. package/dist/modules/effect/input.mjs +2 -0
  208. package/dist/modules/effect/input.mjs.map +1 -0
  209. package/dist/modules/effect/normalize.d.mts +7 -0
  210. package/dist/modules/effect/normalize.mjs +2 -0
  211. package/dist/modules/effect/normalize.mjs.map +1 -0
  212. package/dist/modules/effect/operation.d.mts +148 -0
  213. package/dist/modules/effect/operation.mjs +2 -0
  214. package/dist/modules/effect/operation.mjs.map +1 -0
  215. package/dist/modules/effect/query.d.mts +90 -0
  216. package/dist/modules/effect/query.mjs +2 -0
  217. package/dist/modules/effect/query.mjs.map +1 -0
  218. package/dist/modules/effect/schema.d.mts +30 -0
  219. package/dist/modules/effect/schema.mjs +2 -0
  220. package/dist/modules/effect/schema.mjs.map +1 -0
  221. package/dist/modules/effect/scope.d.mts +25 -0
  222. package/dist/modules/effect/scope.mjs +2 -0
  223. package/dist/modules/effect/scope.mjs.map +1 -0
  224. package/dist/modules/effect/workflow.d.mts +75 -0
  225. package/dist/modules/effect/workflow.mjs +2 -0
  226. package/dist/modules/effect/workflow.mjs.map +1 -0
  227. package/dist/modules/foundation/foundation.d.mts +108 -0
  228. package/dist/modules/foundation/foundation.mjs +2 -0
  229. package/dist/modules/foundation/foundation.mjs.map +1 -0
  230. package/dist/modules/foundation/operation.d.mts +139 -0
  231. package/dist/modules/foundation/operation.mjs +2 -0
  232. package/dist/modules/foundation/operation.mjs.map +1 -0
  233. package/dist/namespace.d.mts +104 -0
  234. package/dist/namespace.mjs +2 -0
  235. package/dist/namespace.mjs.map +1 -0
  236. package/dist/oxlint/architecture.d.mts +23 -0
  237. package/dist/oxlint/architecture.mjs +2 -0
  238. package/dist/oxlint/architecture.mjs.map +1 -0
  239. package/dist/oxlint/ast.d.mts +51 -0
  240. package/dist/oxlint/ast.mjs +2 -0
  241. package/dist/oxlint/ast.mjs.map +1 -0
  242. package/dist/oxlint/components.d.mts +4 -0
  243. package/dist/oxlint/components.mjs +2 -0
  244. package/dist/oxlint/components.mjs.map +1 -0
  245. package/dist/oxlint/ownership.d.mts +59 -0
  246. package/dist/oxlint/ownership.mjs +2 -0
  247. package/dist/oxlint/ownership.mjs.map +1 -0
  248. package/dist/oxlint/reserved-files.d.mts +4 -0
  249. package/dist/oxlint/reserved-files.mjs +2 -0
  250. package/dist/oxlint/reserved-files.mjs.map +1 -0
  251. package/dist/oxlint.d.mts +9 -0
  252. package/dist/oxlint.mjs +2 -0
  253. package/dist/oxlint.mjs.map +1 -0
  254. package/dist/querying/cursors.d.mts +94 -0
  255. package/dist/querying/cursors.mjs +2 -0
  256. package/dist/querying/cursors.mjs.map +1 -0
  257. package/dist/querying/execution.d.mts +40 -0
  258. package/dist/querying/execution.mjs +2 -0
  259. package/dist/querying/execution.mjs.map +1 -0
  260. package/dist/querying/failures.d.mts +11 -0
  261. package/dist/querying/failures.mjs +2 -0
  262. package/dist/querying/failures.mjs.map +1 -0
  263. package/dist/querying/filter-boundary.d.mts +25 -0
  264. package/dist/querying/filter-boundary.mjs +2 -0
  265. package/dist/querying/filter-boundary.mjs.map +1 -0
  266. package/dist/querying/filters.d.mts +180 -0
  267. package/dist/querying/filters.mjs +2 -0
  268. package/dist/querying/filters.mjs.map +1 -0
  269. package/dist/querying/planner.d.mts +61 -0
  270. package/dist/querying/planner.mjs +2 -0
  271. package/dist/querying/planner.mjs.map +1 -0
  272. package/dist/querying/relationships.d.mts +58 -0
  273. package/dist/querying/relationships.mjs +2 -0
  274. package/dist/querying/relationships.mjs.map +1 -0
  275. package/dist/querying/search.d.mts +69 -0
  276. package/dist/querying/search.mjs +2 -0
  277. package/dist/querying/search.mjs.map +1 -0
  278. package/dist/querying/security.d.mts +123 -0
  279. package/dist/querying/security.mjs +2 -0
  280. package/dist/querying/security.mjs.map +1 -0
  281. package/dist/querying/shared/ast.d.mts +26 -0
  282. package/dist/querying/shared/ast.mjs +2 -0
  283. package/dist/querying/shared/ast.mjs.map +1 -0
  284. package/dist/querying/shared/contract.d.mts +98 -0
  285. package/dist/querying/shared/contract.mjs +2 -0
  286. package/dist/querying/shared/contract.mjs.map +1 -0
  287. package/dist/querying/shared/evaluate.d.mts +5 -0
  288. package/dist/querying/shared/evaluate.mjs +2 -0
  289. package/dist/querying/shared/evaluate.mjs.map +1 -0
  290. package/dist/querying/shared/filters.d.mts +65 -0
  291. package/dist/querying/shared/filters.mjs +2 -0
  292. package/dist/querying/shared/filters.mjs.map +1 -0
  293. package/dist/querying/shared/native-json.d.mts +7 -0
  294. package/dist/querying/shared/native-json.mjs +2 -0
  295. package/dist/querying/shared/native-json.mjs.map +1 -0
  296. package/dist/querying/shared/page.d.mts +20 -0
  297. package/dist/querying/shared/page.mjs +2 -0
  298. package/dist/querying/shared/page.mjs.map +1 -0
  299. package/dist/querying.d.mts +82 -0
  300. package/dist/querying.mjs +2 -0
  301. package/dist/querying.mjs.map +1 -0
  302. package/dist/react/failures.d.mts +24 -0
  303. package/dist/react/failures.mjs +2 -0
  304. package/dist/react/failures.mjs.map +1 -0
  305. package/dist/react/optimistic.d.mts +46 -0
  306. package/dist/react/optimistic.mjs +2 -0
  307. package/dist/react/optimistic.mjs.map +1 -0
  308. package/dist/react/pagination-state.d.mts +39 -0
  309. package/dist/react/pagination-state.mjs +2 -0
  310. package/dist/react/pagination-state.mjs.map +1 -0
  311. package/dist/react/use-command.d.mts +22 -0
  312. package/dist/react/use-command.mjs +2 -0
  313. package/dist/react/use-command.mjs.map +1 -0
  314. package/dist/react/use-paginated-list.d.mts +34 -0
  315. package/dist/react/use-paginated-list.mjs +2 -0
  316. package/dist/react/use-paginated-list.mjs.map +1 -0
  317. package/dist/react.d.mts +6 -0
  318. package/dist/react.mjs +1 -0
  319. package/dist/registration.d.mts +65 -0
  320. package/dist/registration.mjs +2 -0
  321. package/dist/registration.mjs.map +1 -0
  322. package/dist/relations-public.d.mts +2 -0
  323. package/dist/relations-public.mjs +1 -0
  324. package/dist/relations.d.mts +274 -0
  325. package/dist/relations.mjs +2 -0
  326. package/dist/relations.mjs.map +1 -0
  327. package/dist/state-machine.d.mts +1 -4
  328. package/dist/state-machine.mjs.map +1 -1
  329. package/dist/table.d.mts +222 -0
  330. package/dist/table.mjs +2 -0
  331. package/dist/table.mjs.map +1 -0
  332. package/dist/tenancy.d.mts +6 -8
  333. package/dist/tenancy.mjs +1 -1
  334. package/dist/tenancy.mjs.map +1 -1
  335. package/dist/triggers.d.mts +12 -10
  336. package/dist/triggers.mjs +1 -1
  337. package/dist/triggers.mjs.map +1 -1
  338. package/dist/webhooks.d.mts +22 -112
  339. package/dist/webhooks.mjs +1 -1
  340. package/dist/webhooks.mjs.map +1 -1
  341. package/dist/workflow.d.mts +2 -0
  342. package/dist/workflow.mjs +1 -0
  343. package/dist/zod.d.mts +30 -0
  344. package/dist/zod.mjs +2 -0
  345. package/dist/zod.mjs.map +1 -0
  346. package/package.json +145 -33
  347. package/src/test.ts +9 -17
  348. package/CHANGELOG.md +0 -145
  349. package/ROADMAP.md +0 -126
  350. package/dist/zod-table.d.mts +0 -175
  351. package/dist/zod-table.mjs +0 -2
  352. package/dist/zod-table.mjs.map +0 -1
  353. package/docs/agent-tools.md +0 -41
  354. package/docs/approvals.md +0 -200
  355. package/docs/architecture.md +0 -124
  356. package/docs/auth.md +0 -218
  357. package/docs/commands.md +0 -278
  358. package/docs/conventions.md +0 -291
  359. package/docs/crud.md +0 -62
  360. package/docs/llms.md +0 -220
  361. package/docs/maintainability.md +0 -124
  362. package/docs/migration.md +0 -351
  363. package/docs/plans/2026-08-14-001-feat-v0.1.0-feature-set-plan.md +0 -461
  364. package/docs/plans/2026-08-21-0930-feat-resolve-organization-hook-plan.md +0 -178
  365. package/docs/tenancy.md +0 -179
  366. package/docs/triggers.md +0 -75
  367. package/docs/upgrading.md +0 -175
  368. package/docs/webhooks.md +0 -58
  369. package/docs/zod-table.md +0 -173
  370. package/scripts/convex-config-bridge.mjs +0 -55
  371. package/scripts/extract-changelog.mjs +0 -29
  372. package/scripts/smoke-packed-components.mjs +0 -374
@@ -1,156 +1,148 @@
1
1
  declare namespace requests_d_exports {
2
2
  export { cancel, getForWorkflow, list, recordExecutionTerminal, restart, start, status };
3
3
  }
4
- declare const start: import("convex/server").RegisteredMutation<"public", {
4
+ export declare const start: import("convex/server").RegisteredMutation<"public", {
5
5
  metadata?: Record<string, string> | undefined;
6
6
  requester: {
7
7
  actorRef: string;
8
8
  capabilities: string[];
9
- metadata?: {
10
- [x: string]: string;
11
- } | undefined;
9
+ metadata?: Record<string, string> | undefined;
12
10
  };
13
11
  resourceRef: string;
14
12
  resourceType: string;
15
13
  scopeRef: string;
16
14
  workflow: {
17
- schemaVersion: 1;
18
15
  compatibilityKey: string;
19
16
  name: string;
17
+ schemaVersion: 1;
20
18
  steps: ({
21
- kind: "mutation";
22
- key: string;
23
19
  callback: {
24
- kind: "mutation";
25
20
  handle: string;
21
+ kind: "mutation";
26
22
  retry: boolean;
27
23
  };
28
- } | {
29
- kind: "action";
30
24
  key: string;
25
+ kind: "mutation";
26
+ } | {
31
27
  callback: {
32
- kind: "action";
33
28
  handle: string;
29
+ kind: "action";
34
30
  retry: boolean;
35
31
  };
36
- } | {
37
- kind: "notify";
38
32
  key: string;
33
+ kind: "action";
34
+ } | {
39
35
  callback: {
40
- kind: "action";
41
36
  handle: string;
37
+ kind: "action";
42
38
  retry: boolean;
43
39
  };
44
- } | {
45
- kind: "decision";
46
40
  key: string;
41
+ kind: "notify";
42
+ } | {
47
43
  decisions: ("approved" | "rejected")[];
44
+ expiresAfterMs?: number | undefined;
45
+ key: string;
46
+ kind: "decision";
47
+ makerChecker: boolean;
48
48
  quorum: {
49
- kind: "count";
50
49
  approvals: number;
50
+ kind: "count";
51
51
  };
52
- makerChecker: boolean;
53
- expiresAfterMs?: number | undefined;
54
52
  } | {
55
- kind: "branch";
56
- key: string;
57
53
  approvedStepKey: string;
54
+ key: string;
55
+ kind: "branch";
58
56
  rejectedStepKey: string;
59
57
  })[];
60
58
  };
61
59
  }, Promise<{
62
60
  runId: import("convex/values").GenericId<"approvalRuns">;
63
61
  }>>;
64
- declare const cancel: import("convex/server").RegisteredMutation<"public", {
62
+ export declare const cancel: import("convex/server").RegisteredMutation<"public", {
65
63
  actor: {
66
64
  actorRef: string;
67
65
  capabilities: string[];
68
- metadata?: {
69
- [x: string]: string;
70
- } | undefined;
66
+ metadata?: Record<string, string> | undefined;
71
67
  };
72
68
  compatibilityKey: string;
73
69
  runId: import("convex/values").GenericId<"approvalRuns">;
74
70
  }, Promise<{
75
71
  state: 'canceled';
76
72
  }>>;
77
- declare const restart: import("convex/server").RegisteredMutation<"public", {
73
+ export declare const restart: import("convex/server").RegisteredMutation<"public", {
78
74
  compatibilityKey: string;
79
75
  runId: import("convex/values").GenericId<"approvalRuns">;
80
76
  }, Promise<null>>;
81
- declare const status: import("convex/server").RegisteredQuery<"public", {
77
+ export declare const status: import("convex/server").RegisteredQuery<"public", {
82
78
  compatibilityKey: string;
83
79
  runId: import("convex/values").GenericId<"approvalRuns">;
84
80
  }, Promise<{
85
81
  run: {
86
82
  _creationTime: number;
87
83
  _id: import("convex/values").GenericId<"approvalRuns">;
88
- scopeRef: string;
89
- resourceType: string;
90
- resourceRef: string;
84
+ createdAt: number;
85
+ currentStepKey?: string | undefined;
86
+ executionFailedStepKey?: string | undefined;
87
+ expiresAt?: number | undefined;
88
+ metadata?: Record<string, string> | undefined;
91
89
  requester: {
92
90
  actorRef: string;
93
91
  capabilities: string[];
94
- metadata?: {
95
- [x: string]: string;
96
- } | undefined;
92
+ metadata?: Record<string, string> | undefined;
97
93
  };
98
- metadata?: {
99
- [x: string]: string;
100
- } | undefined;
94
+ resourceRef: string;
95
+ resourceType: string;
96
+ scopeRef: string;
97
+ state: "approved" | "canceled" | "expired" | "pending" | "rejected";
98
+ terminalAt?: number | undefined;
99
+ updatedAt: number;
101
100
  workflow: {
102
- schemaVersion: 1;
103
101
  compatibilityKey: string;
104
102
  name: string;
103
+ schemaVersion: 1;
105
104
  steps: ({
106
- kind: "mutation";
107
- key: string;
108
105
  callback: {
109
- kind: "mutation";
110
106
  handle: string;
107
+ kind: "mutation";
111
108
  retry: boolean;
112
109
  };
113
- } | {
114
- kind: "action";
115
110
  key: string;
111
+ kind: "mutation";
112
+ } | {
116
113
  callback: {
117
- kind: "action";
118
114
  handle: string;
115
+ kind: "action";
119
116
  retry: boolean;
120
117
  };
121
- } | {
122
- kind: "notify";
123
118
  key: string;
119
+ kind: "action";
120
+ } | {
124
121
  callback: {
125
- kind: "action";
126
122
  handle: string;
123
+ kind: "action";
127
124
  retry: boolean;
128
125
  };
129
- } | {
130
- kind: "decision";
131
126
  key: string;
127
+ kind: "notify";
128
+ } | {
132
129
  decisions: ("approved" | "rejected")[];
130
+ expiresAfterMs?: number | undefined;
131
+ key: string;
132
+ kind: "decision";
133
+ makerChecker: boolean;
133
134
  quorum: {
134
- kind: "count";
135
135
  approvals: number;
136
+ kind: "count";
136
137
  };
137
- makerChecker: boolean;
138
- expiresAfterMs?: number | undefined;
139
138
  } | {
140
- kind: "branch";
141
- key: string;
142
139
  approvedStepKey: string;
140
+ key: string;
141
+ kind: "branch";
143
142
  rejectedStepKey: string;
144
143
  })[];
145
144
  };
146
- state: "approved" | "canceled" | "expired" | "pending" | "rejected";
147
- currentStepKey?: string | undefined;
148
- executionFailedStepKey?: string | undefined;
149
- expiresAt?: number | undefined;
150
145
  workflowId?: string | undefined;
151
- createdAt: number;
152
- updatedAt: number;
153
- terminalAt?: number | undefined;
154
146
  };
155
147
  execution: {
156
148
  type: 'failed';
@@ -160,7 +152,7 @@ declare const status: import("convex/server").RegisteredQuery<"public", {
160
152
  type: "canceled" | "completed" | "inProgress";
161
153
  } | null;
162
154
  } | null>>;
163
- declare const list: import("convex/server").RegisteredQuery<"public", {
155
+ export declare const list: import("convex/server").RegisteredQuery<"public", {
164
156
  paginationOpts: {
165
157
  id?: number;
166
158
  endCursor?: string | null;
@@ -174,150 +166,141 @@ declare const list: import("convex/server").RegisteredQuery<"public", {
174
166
  }, Promise<import("convex/server").PaginationResult<{
175
167
  _creationTime: number;
176
168
  _id: import("convex/values").GenericId<"approvalRuns">;
177
- scopeRef: string;
178
- resourceType: string;
179
- resourceRef: string;
169
+ createdAt: number;
170
+ currentStepKey?: string | undefined;
171
+ executionFailedStepKey?: string | undefined;
172
+ expiresAt?: number | undefined;
173
+ metadata?: Record<string, string> | undefined;
180
174
  requester: {
181
175
  actorRef: string;
182
176
  capabilities: string[];
183
- metadata?: {
184
- [x: string]: string;
185
- } | undefined;
177
+ metadata?: Record<string, string> | undefined;
186
178
  };
187
- metadata?: {
188
- [x: string]: string;
189
- } | undefined;
179
+ resourceRef: string;
180
+ resourceType: string;
181
+ scopeRef: string;
182
+ state: "approved" | "canceled" | "expired" | "pending" | "rejected";
183
+ terminalAt?: number | undefined;
184
+ updatedAt: number;
190
185
  workflow: {
191
- schemaVersion: 1;
192
186
  compatibilityKey: string;
193
187
  name: string;
188
+ schemaVersion: 1;
194
189
  steps: ({
195
- kind: "mutation";
196
- key: string;
197
190
  callback: {
198
- kind: "mutation";
199
191
  handle: string;
192
+ kind: "mutation";
200
193
  retry: boolean;
201
194
  };
202
- } | {
203
- kind: "action";
204
195
  key: string;
196
+ kind: "mutation";
197
+ } | {
205
198
  callback: {
206
- kind: "action";
207
199
  handle: string;
200
+ kind: "action";
208
201
  retry: boolean;
209
202
  };
210
- } | {
211
- kind: "notify";
212
203
  key: string;
204
+ kind: "action";
205
+ } | {
213
206
  callback: {
214
- kind: "action";
215
207
  handle: string;
208
+ kind: "action";
216
209
  retry: boolean;
217
210
  };
218
- } | {
219
- kind: "decision";
220
211
  key: string;
212
+ kind: "notify";
213
+ } | {
221
214
  decisions: ("approved" | "rejected")[];
215
+ expiresAfterMs?: number | undefined;
216
+ key: string;
217
+ kind: "decision";
218
+ makerChecker: boolean;
222
219
  quorum: {
223
- kind: "count";
224
220
  approvals: number;
221
+ kind: "count";
225
222
  };
226
- makerChecker: boolean;
227
- expiresAfterMs?: number | undefined;
228
223
  } | {
229
- kind: "branch";
230
- key: string;
231
224
  approvedStepKey: string;
225
+ key: string;
226
+ kind: "branch";
232
227
  rejectedStepKey: string;
233
228
  })[];
234
229
  };
235
- state: "approved" | "canceled" | "expired" | "pending" | "rejected";
236
- currentStepKey?: string | undefined;
237
- executionFailedStepKey?: string | undefined;
238
- expiresAt?: number | undefined;
239
230
  workflowId?: string | undefined;
240
- createdAt: number;
241
- updatedAt: number;
242
- terminalAt?: number | undefined;
243
231
  }>>>;
244
- declare const getForWorkflow: import("convex/server").RegisteredQuery<"internal", {
232
+ export declare const getForWorkflow: import("convex/server").RegisteredQuery<"internal", {
245
233
  runId: import("convex/values").GenericId<"approvalRuns">;
246
234
  }, Promise<{
247
235
  _creationTime: number;
248
236
  _id: import("convex/values").GenericId<"approvalRuns">;
249
- scopeRef: string;
250
- resourceType: string;
251
- resourceRef: string;
237
+ createdAt: number;
238
+ currentStepKey?: string | undefined;
239
+ executionFailedStepKey?: string | undefined;
240
+ expiresAt?: number | undefined;
241
+ metadata?: Record<string, string> | undefined;
252
242
  requester: {
253
243
  actorRef: string;
254
244
  capabilities: string[];
255
- metadata?: {
256
- [x: string]: string;
257
- } | undefined;
245
+ metadata?: Record<string, string> | undefined;
258
246
  };
259
- metadata?: {
260
- [x: string]: string;
261
- } | undefined;
247
+ resourceRef: string;
248
+ resourceType: string;
249
+ scopeRef: string;
250
+ state: "approved" | "canceled" | "expired" | "pending" | "rejected";
251
+ terminalAt?: number | undefined;
252
+ updatedAt: number;
262
253
  workflow: {
263
- schemaVersion: 1;
264
254
  compatibilityKey: string;
265
255
  name: string;
256
+ schemaVersion: 1;
266
257
  steps: ({
267
- kind: "mutation";
268
- key: string;
269
258
  callback: {
270
- kind: "mutation";
271
259
  handle: string;
260
+ kind: "mutation";
272
261
  retry: boolean;
273
262
  };
274
- } | {
275
- kind: "action";
276
263
  key: string;
264
+ kind: "mutation";
265
+ } | {
277
266
  callback: {
278
- kind: "action";
279
267
  handle: string;
268
+ kind: "action";
280
269
  retry: boolean;
281
270
  };
282
- } | {
283
- kind: "notify";
284
271
  key: string;
272
+ kind: "action";
273
+ } | {
285
274
  callback: {
286
- kind: "action";
287
275
  handle: string;
276
+ kind: "action";
288
277
  retry: boolean;
289
278
  };
290
- } | {
291
- kind: "decision";
292
279
  key: string;
280
+ kind: "notify";
281
+ } | {
293
282
  decisions: ("approved" | "rejected")[];
283
+ expiresAfterMs?: number | undefined;
284
+ key: string;
285
+ kind: "decision";
286
+ makerChecker: boolean;
294
287
  quorum: {
295
- kind: "count";
296
288
  approvals: number;
289
+ kind: "count";
297
290
  };
298
- makerChecker: boolean;
299
- expiresAfterMs?: number | undefined;
300
291
  } | {
301
- kind: "branch";
302
- key: string;
303
292
  approvedStepKey: string;
293
+ key: string;
294
+ kind: "branch";
304
295
  rejectedStepKey: string;
305
296
  })[];
306
297
  };
307
- state: "approved" | "canceled" | "expired" | "pending" | "rejected";
308
- currentStepKey?: string | undefined;
309
- executionFailedStepKey?: string | undefined;
310
- expiresAt?: number | undefined;
311
298
  workflowId?: string | undefined;
312
- createdAt: number;
313
- updatedAt: number;
314
- terminalAt?: number | undefined;
315
299
  } | null>>;
316
- declare const recordExecutionTerminal: import("convex/server").RegisteredMutation<"internal", {
300
+ export declare const recordExecutionTerminal: import("convex/server").RegisteredMutation<"internal", {
317
301
  failedStepKey?: string | undefined;
318
302
  outcome: "completed" | "failed";
319
303
  runId: import("convex/values").GenericId<"approvalRuns">;
320
304
  }, Promise<null>>;
321
- //#endregion
322
- export { cancel, getForWorkflow, list, recordExecutionTerminal, requests_d_exports, restart, start, status };
305
+ export { requests_d_exports };
323
306
  //# sourceMappingURL=requests.d.mts.map
@@ -1,2 +1,2 @@
1
- import{components as e,internal as t}from"./_generated/api.mjs";import{internalMutation as n,internalQuery as r,mutation as i,query as a}from"./_generated/server.mjs";import{APPROVAL_EXECUTION_STATES as o,APPROVAL_RUN_STATES as s}from"./constants.mjs";import{logApprovalTransition as c}from"./audit.mjs";import{approvalActor as l,approvalMetadata as u,approvalName as d,approvalReference as f,approvalRunDocument as p,approvalRunState as m,approvalWorkflowDescriptor as h}from"./validators.mjs";import{canTransitionApprovalRun as g}from"./functions.mjs";import _ from"./schema.js";import{zodToConvex as v}from"convex-helpers/server/zod4";import{paginationOptsValidator as y,paginationResultValidator as b}from"convex/server";import{v as x}from"convex/values";import{WorkflowManager as S}from"@convex-dev/workflow";import{paginator as C}from"convex-helpers/server/pagination";const w=i({args:{scopeRef:v(f),resourceType:v(f),resourceRef:v(f),requester:v(l),metadata:x.optional(v(u)),workflow:v(h)},returns:x.object({runId:x.id(`approvalRuns`)}),handler:async(e,n)=>{let r=Date.now(),i=await e.db.insert(`approvalRuns`,{...n,state:`pending`,createdAt:r,updatedAt:r}),a=await j.start(e,t.workflow.run,{runId:i},{startAsync:!0});return await e.db.patch(i,{workflowId:a,updatedAt:Date.now()}),await c(e,{action:`approval.requested`,actorRef:n.requester.actorRef,runId:i,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`requested`}),{runId:i}}}),T=i({args:{runId:x.id(`approvalRuns`),actor:v(l),compatibilityKey:x.string()},returns:x.object({state:x.literal(s[4])}),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);if(I(n.workflow.compatibilityKey,t.compatibilityKey),n.state!==`pending`){if(n.state===`canceled`)return{state:`canceled`};throw Error(`Approval request is already ${n.state}`)}if(!n.workflowId)throw Error(`Approval workflow is not linked`);if(await j.cancel(e,n.workflowId),!g(n.state,`canceled`))throw Error(`Approval request cannot transition from ${n.state}`);let r=Date.now();return await e.db.patch(n._id,{state:`canceled`,expiresAt:void 0,updatedAt:r,terminalAt:r}),await c(e,{action:`approval.canceled`,actorRef:t.actor.actorRef,runId:n._id,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`canceled`}),{state:`canceled`}}}),E=i({args:{runId:x.id(`approvalRuns`),compatibilityKey:x.string()},returns:x.null(),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);if(I(n.workflow.compatibilityKey,t.compatibilityKey),!n.workflowId)throw Error(`Approval workflow is not linked`);if(!n.executionFailedStepKey)throw Error(`Approval workflow has no failed step to restart`);return await j.restart(e,n.workflowId,{from:n.executionFailedStepKey,startAsync:!0}),null}}),D=a({args:{runId:x.id(`approvalRuns`),compatibilityKey:x.string()},returns:x.union(x.null(),F()),handler:async(e,t)=>{let n=await e.db.get(t.runId);return n?(I(n.workflow.compatibilityKey,t.compatibilityKey),{run:n,execution:M(n.workflowId?await j.status(e,n.workflowId):null)}):null}}),O=a({args:{scopeRef:v(f),state:x.optional(v(m)),paginationOpts:y},returns:b(N()),handler:(e,t)=>C(e.db,_).query(`approvalRuns`).withIndex(`by_scopeRef_and_state`,e=>t.state===void 0?e.eq(`scopeRef`,t.scopeRef):e.eq(`scopeRef`,t.scopeRef).eq(`state`,t.state)).order(`desc`).paginate(t.paginationOpts)}),k=r({args:{runId:x.id(`approvalRuns`)},returns:x.union(x.null(),N()),handler:(e,t)=>e.db.get(t.runId)}),A=n({args:{runId:x.id(`approvalRuns`),outcome:x.union(x.literal(o[1]),x.literal(o[3])),failedStepKey:x.optional(v(d))},returns:x.null(),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);return await e.db.patch(n._id,{executionFailedStepKey:t.outcome===`failed`?t.failedStepKey:void 0,updatedAt:Date.now()}),await c(e,{action:`approval.execution.${t.outcome}`,runId:n._id,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`execution:${t.outcome}`,severity:t.outcome===`failed`?`error`:`info`}),null}}),j=new S(e.workflow);function M(e){if(!e)return null;switch(e.type){case`failed`:return{type:`failed`,error:e.error};case`inProgress`:case`completed`:case`canceled`:return{type:e.type}}}function N(){return x.object({_id:x.id(`approvalRuns`),_creationTime:x.number(),...v(p).fields})}function P(){return x.union(x.object({type:x.literal(o[0])}),x.object({type:x.literal(o[1])}),x.object({type:x.literal(o[2])}),x.object({type:x.literal(o[3]),error:x.string()}))}function F(){return x.object({run:N(),execution:x.union(x.null(),P())})}function I(e,t){if(e!==t)throw Error(`Approval workflow compatibility mismatch: expected ${t}, received ${e}`)}export{T as cancel,k as getForWorkflow,O as list,A as recordExecutionTerminal,E as restart,w as start,D as status};
1
+ import{components as e,internal as t}from"./_generated/api.mjs";import{internalMutation as n,internalQuery as r,mutation as i,query as a}from"./_generated/server.mjs";import{logApprovalTransition as o}from"./audit.mjs";import s from"./schema.js";import{APPROVAL_EXECUTION_STATES as c,APPROVAL_RUN_STATES as l}from"./constants.mjs";import{canTransitionApprovalRun as u}from"./functions.mjs";import{approvalActor as d,approvalMetadata as f,approvalName as p,approvalReference as m,approvalRunDocument as h,approvalRunState as g,approvalWorkflowDescriptor as _}from"./validators.mjs";import{v}from"convex/values";import{paginationOptsValidator as y,paginationResultValidator as b}from"convex/server";import{WorkflowManager as x}from"@convex-dev/workflow";import{paginator as S}from"convex-helpers/server/pagination";const C=i({args:{scopeRef:m.validator,resourceType:m.validator,resourceRef:m.validator,requester:d.validator,metadata:v.optional(f.validator),workflow:_.validator},returns:v.object({runId:v.id(`approvalRuns`)}),handler:async(e,n)=>{let r=Date.now(),i=await e.db.insert(`approvalRuns`,{...n,state:`pending`,createdAt:r,updatedAt:r}),a=await A.start(e,t.workflow.run,{runId:i},{startAsync:!0});return await e.db.patch(i,{workflowId:a,updatedAt:Date.now()}),await o(e,{action:`approval.requested`,actorRef:n.requester.actorRef,runId:i,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`requested`}),{runId:i}}}),w=i({args:{runId:v.id(`approvalRuns`),actor:d.validator,compatibilityKey:v.string()},returns:v.object({state:v.literal(l[4])}),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);if(F(n.workflow.compatibilityKey,t.compatibilityKey),n.state!==`pending`){if(n.state===`canceled`)return{state:`canceled`};throw Error(`Approval request is already ${n.state}`)}if(!n.workflowId)throw Error(`Approval workflow is not linked`);if(await A.cancel(e,n.workflowId),!u(n.state,`canceled`))throw Error(`Approval request cannot transition from ${n.state}`);let r=Date.now();return await e.db.patch(n._id,{state:`canceled`,expiresAt:void 0,updatedAt:r,terminalAt:r}),await o(e,{action:`approval.canceled`,actorRef:t.actor.actorRef,runId:n._id,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`canceled`}),{state:`canceled`}}}),T=i({args:{runId:v.id(`approvalRuns`),compatibilityKey:v.string()},returns:v.null(),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);if(F(n.workflow.compatibilityKey,t.compatibilityKey),!n.workflowId)throw Error(`Approval workflow is not linked`);if(!n.executionFailedStepKey)throw Error(`Approval workflow has no failed step to restart`);return await A.restart(e,n.workflowId,{from:n.executionFailedStepKey,startAsync:!0}),null}}),E=a({args:{runId:v.id(`approvalRuns`),compatibilityKey:v.string()},returns:v.union(v.null(),P()),handler:async(e,t)=>{let n=await e.db.get(t.runId);return n?(F(n.workflow.compatibilityKey,t.compatibilityKey),{run:n,execution:j(n.workflowId?await A.status(e,n.workflowId):null)}):null}}),D=a({args:{scopeRef:m.validator,state:v.optional(g.validator),paginationOpts:y},returns:b(M()),handler:(e,t)=>S(e.db,s).query(`approvalRuns`).withIndex(`by_scopeRef_and_state`,e=>t.state===void 0?e.eq(`scopeRef`,t.scopeRef):e.eq(`scopeRef`,t.scopeRef).eq(`state`,t.state)).order(`desc`).paginate(t.paginationOpts)}),O=r({args:{runId:v.id(`approvalRuns`)},returns:v.union(v.null(),M()),handler:(e,t)=>e.db.get(t.runId)}),k=n({args:{runId:v.id(`approvalRuns`),outcome:v.union(v.literal(c[1]),v.literal(c[3])),failedStepKey:v.optional(p.validator)},returns:v.null(),handler:async(e,t)=>{let n=await e.db.get(t.runId);if(!n)throw Error(`Approval request not found`);return await e.db.patch(n._id,{executionFailedStepKey:t.outcome===`failed`?t.failedStepKey:void 0,updatedAt:Date.now()}),await o(e,{action:`approval.execution.${t.outcome}`,runId:n._id,resourceType:n.resourceType,resourceRef:n.resourceRef,transition:`execution:${t.outcome}`,severity:t.outcome===`failed`?`error`:`info`}),null}}),A=new x(e.workflow);function j(e){if(!e)return null;switch(e.type){case`failed`:return{type:`failed`,error:e.error};case`inProgress`:case`completed`:case`canceled`:return{type:e.type}}}function M(){return v.object({_id:v.id(`approvalRuns`),_creationTime:v.number(),...h.validator.fields})}function N(){return v.union(v.object({type:v.literal(c[0])}),v.object({type:v.literal(c[1])}),v.object({type:v.literal(c[2])}),v.object({type:v.literal(c[3]),error:v.string()}))}function P(){return v.object({run:M(),execution:v.union(v.null(),N())})}function F(e,t){if(e!==t)throw Error(`Approval workflow compatibility mismatch: expected ${t}, received ${e}`)}export{w as cancel,O as getForWorkflow,D as list,k as recordExecutionTerminal,T as restart,C as start,E as status};
2
2
  //# sourceMappingURL=requests.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"requests.mjs","names":["schema"],"sources":["../../../src/components/approvals/requests.ts"],"sourcesContent":["import { WorkflowManager, type WorkflowId } from '@convex-dev/workflow'\nimport { zodToConvex } from 'convex-helpers/server/zod4'\nimport { paginator } from 'convex-helpers/server/pagination'\nimport {\n\tpaginationOptsValidator,\n\tpaginationResultValidator,\n} from 'convex/server'\nimport { v } from 'convex/values'\n\nimport { components, internal } from './_generated/api'\nimport {\n\tinternalMutation,\n\tinternalQuery,\n\tmutation,\n\tquery,\n} from './_generated/server'\nimport { logApprovalTransition } from './audit'\nimport schema from './schema'\nimport { APPROVAL_EXECUTION_STATES, APPROVAL_RUN_STATES } from './constants'\nimport { canTransitionApprovalRun } from './functions'\nimport {\n\tapprovalActor,\n\tapprovalMetadata,\n\tapprovalName,\n\tapprovalReference,\n\tapprovalRunDocument,\n\tapprovalRunState,\n\tapprovalWorkflowDescriptor,\n} from './validators'\n\nexport const start = mutation({\n\targs: {\n\t\tscopeRef: zodToConvex(approvalReference),\n\t\tresourceType: zodToConvex(approvalReference),\n\t\tresourceRef: zodToConvex(approvalReference),\n\t\trequester: zodToConvex(approvalActor),\n\t\tmetadata: v.optional(zodToConvex(approvalMetadata)),\n\t\tworkflow: zodToConvex(approvalWorkflowDescriptor),\n\t},\n\treturns: v.object({ runId: v.id('approvalRuns') }),\n\thandler: async (ctx, input) => {\n\t\tconst now = Date.now()\n\t\tconst runId = await ctx.db.insert('approvalRuns', {\n\t\t\t...input,\n\t\t\tstate: 'pending',\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t})\n\t\tconst workflowId: WorkflowId = await approvalWorkflow.start(\n\t\t\tctx,\n\t\t\tinternal.workflow.run,\n\t\t\t{ runId },\n\t\t\t{ startAsync: true },\n\t\t)\n\t\tawait ctx.db.patch(runId, { workflowId, updatedAt: Date.now() })\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: 'approval.requested',\n\t\t\tactorRef: input.requester.actorRef,\n\t\t\trunId,\n\t\t\tresourceType: input.resourceType,\n\t\t\tresourceRef: input.resourceRef,\n\t\t\ttransition: 'requested',\n\t\t})\n\t\treturn { runId }\n\t},\n})\n\nexport const cancel = mutation({\n\targs: {\n\t\trunId: v.id('approvalRuns'),\n\t\tactor: zodToConvex(approvalActor),\n\t\tcompatibilityKey: v.string(),\n\t},\n\treturns: v.object({ state: v.literal(APPROVAL_RUN_STATES[4]) }),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tif (run.state !== 'pending') {\n\t\t\tif (run.state === 'canceled') return { state: 'canceled' as const }\n\t\t\tthrow new Error(`Approval request is already ${run.state}`)\n\t\t}\n\t\tif (!run.workflowId) throw new Error('Approval workflow is not linked')\n\t\tawait approvalWorkflow.cancel(ctx, run.workflowId as WorkflowId)\n\t\tif (!canTransitionApprovalRun(run.state, 'canceled'))\n\t\t\tthrow new Error(`Approval request cannot transition from ${run.state}`)\n\t\tconst now = Date.now()\n\t\tawait ctx.db.patch(run._id, {\n\t\t\tstate: 'canceled',\n\t\t\texpiresAt: undefined,\n\t\t\tupdatedAt: now,\n\t\t\tterminalAt: now,\n\t\t})\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: 'approval.canceled',\n\t\t\tactorRef: input.actor.actorRef,\n\t\t\trunId: run._id,\n\t\t\tresourceType: run.resourceType,\n\t\t\tresourceRef: run.resourceRef,\n\t\t\ttransition: 'canceled',\n\t\t})\n\t\treturn { state: 'canceled' as const }\n\t},\n})\n\nexport const restart = mutation({\n\targs: { runId: v.id('approvalRuns'), compatibilityKey: v.string() },\n\treturns: v.null(),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tif (!run.workflowId) throw new Error('Approval workflow is not linked')\n\t\tif (!run.executionFailedStepKey)\n\t\t\tthrow new Error('Approval workflow has no failed step to restart')\n\t\tawait approvalWorkflow.restart(ctx, run.workflowId as WorkflowId, {\n\t\t\tfrom: run.executionFailedStepKey,\n\t\t\tstartAsync: true,\n\t\t})\n\t\treturn null\n\t},\n})\n\nexport const status = query({\n\targs: { runId: v.id('approvalRuns'), compatibilityKey: v.string() },\n\treturns: v.union(v.null(), approvalStatusValidator()),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) return null\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tconst workflowStatus = run.workflowId\n\t\t\t? await approvalWorkflow.status(ctx, run.workflowId as WorkflowId)\n\t\t\t: null\n\t\tconst execution = normalizeWorkflowStatus(workflowStatus)\n\t\treturn { run, execution }\n\t},\n})\n\nexport const list = query({\n\targs: {\n\t\tscopeRef: zodToConvex(approvalReference),\n\t\tstate: v.optional(zodToConvex(approvalRunState)),\n\t\tpaginationOpts: paginationOptsValidator,\n\t},\n\treturns: paginationResultValidator(approvalRunValidator()),\n\thandler: (ctx, input) =>\n\t\tpaginator(ctx.db, schema)\n\t\t\t.query('approvalRuns')\n\t\t\t.withIndex('by_scopeRef_and_state', (query) =>\n\t\t\t\tinput.state === undefined\n\t\t\t\t\t? query.eq('scopeRef', input.scopeRef)\n\t\t\t\t\t: query.eq('scopeRef', input.scopeRef).eq('state', input.state),\n\t\t\t)\n\t\t\t.order('desc')\n\t\t\t.paginate(input.paginationOpts),\n})\n\nexport const getForWorkflow = internalQuery({\n\targs: { runId: v.id('approvalRuns') },\n\treturns: v.union(v.null(), approvalRunValidator()),\n\thandler: (ctx, input) => ctx.db.get(input.runId),\n})\n\nexport const recordExecutionTerminal = internalMutation({\n\targs: {\n\t\trunId: v.id('approvalRuns'),\n\t\toutcome: v.union(\n\t\t\tv.literal(APPROVAL_EXECUTION_STATES[1]),\n\t\t\tv.literal(APPROVAL_EXECUTION_STATES[3]),\n\t\t),\n\t\tfailedStepKey: v.optional(zodToConvex(approvalName)),\n\t},\n\treturns: v.null(),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tawait ctx.db.patch(run._id, {\n\t\t\texecutionFailedStepKey:\n\t\t\t\tinput.outcome === 'failed' ? input.failedStepKey : undefined,\n\t\t\tupdatedAt: Date.now(),\n\t\t})\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: `approval.execution.${input.outcome}`,\n\t\t\trunId: run._id,\n\t\t\tresourceType: run.resourceType,\n\t\t\tresourceRef: run.resourceRef,\n\t\t\ttransition: `execution:${input.outcome}`,\n\t\t\tseverity: input.outcome === 'failed' ? 'error' : 'info',\n\t\t})\n\t\treturn null\n\t},\n})\n\nconst approvalWorkflow = new WorkflowManager(components.workflow)\n\nfunction normalizeWorkflowStatus(\n\tstatus: Awaited<ReturnType<typeof approvalWorkflow.status>> | null,\n) {\n\tif (!status) return null\n\tswitch (status.type) {\n\t\tcase 'failed':\n\t\t\treturn { type: 'failed' as const, error: status.error }\n\t\tcase 'inProgress':\n\t\tcase 'completed':\n\t\tcase 'canceled':\n\t\t\treturn { type: status.type }\n\t}\n}\n\nfunction approvalRunValidator() {\n\treturn v.object({\n\t\t_id: v.id('approvalRuns'),\n\t\t_creationTime: v.number(),\n\t\t...zodToConvex(approvalRunDocument).fields,\n\t})\n}\n\nfunction workflowStatusValidator() {\n\treturn v.union(\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[0]) }),\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[1]) }),\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[2]) }),\n\t\tv.object({\n\t\t\ttype: v.literal(APPROVAL_EXECUTION_STATES[3]),\n\t\t\terror: v.string(),\n\t\t}),\n\t)\n}\n\nfunction approvalStatusValidator() {\n\treturn v.object({\n\t\trun: approvalRunValidator(),\n\t\texecution: v.union(v.null(), workflowStatusValidator()),\n\t})\n}\n\nfunction assertCompatible(actual: string, expected: string): void {\n\tif (actual !== expected)\n\t\tthrow new Error(\n\t\t\t`Approval workflow compatibility mismatch: expected ${expected}, received ${actual}`,\n\t\t)\n}\n"],"mappings":"42BA8BA,MAAa,EAAQ,EAAS,CAC7B,KAAM,CACL,SAAU,EAA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d,MAAU,MACT,sDAAsD,EAAS,aAAa,GAC7E,CACF"}
1
+ {"version":3,"file":"requests.mjs","names":["schema","schema_default","start","mutation","approvalReference","approvalActor","approvalMetadata","approvalWorkflowDescriptor","now","runId","ctx","input","workflowId","approvalWorkflow","internal","logApprovalTransition","cancel","APPROVAL_RUN_STATES","run","assertCompatible","canTransitionApprovalRun","restart","status","query","approvalStatusValidator","normalizeWorkflowStatus","list","approvalRunState","paginationOptsValidator","paginationResultValidator","approvalRunValidator","paginator","getForWorkflow","internalQuery","recordExecutionTerminal","internalMutation","APPROVAL_EXECUTION_STATES","approvalName","WorkflowManager","components","approvalRunDocument","workflowStatusValidator","actual","expected"],"sources":["../../../src/components/approvals/requests.ts"],"sourcesContent":["import { WorkflowManager, type WorkflowId } from '@convex-dev/workflow'\nimport { paginator } from 'convex-helpers/server/pagination'\nimport { paginationOptsValidator, paginationResultValidator } from 'convex/server'\nimport { v } from 'convex/values'\n\nimport { components, internal } from './_generated/api'\nimport { internalMutation, internalQuery, mutation, query } from './_generated/server'\nimport { logApprovalTransition } from './audit'\nimport schema from './schema'\nimport { APPROVAL_EXECUTION_STATES, APPROVAL_RUN_STATES } from './constants'\nimport { canTransitionApprovalRun } from './functions'\nimport {\n\tapprovalActor,\n\tapprovalMetadata,\n\tapprovalName,\n\tapprovalReference,\n\tapprovalRunDocument,\n\tapprovalRunState,\n\tapprovalWorkflowDescriptor,\n} from './validators'\n\nexport const start = mutation({\n\targs: {\n\t\tscopeRef: approvalReference.validator,\n\t\tresourceType: approvalReference.validator,\n\t\tresourceRef: approvalReference.validator,\n\t\trequester: approvalActor.validator,\n\t\tmetadata: v.optional(approvalMetadata.validator),\n\t\tworkflow: approvalWorkflowDescriptor.validator,\n\t},\n\treturns: v.object({ runId: v.id('approvalRuns') }),\n\thandler: async (ctx, input) => {\n\t\tconst now = Date.now()\n\t\tconst runId = await ctx.db.insert('approvalRuns', {\n\t\t\t...input,\n\t\t\tstate: 'pending',\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t})\n\t\tconst workflowId: WorkflowId = await approvalWorkflow.start(\n\t\t\tctx,\n\t\t\tinternal.workflow.run,\n\t\t\t{ runId },\n\t\t\t{ startAsync: true },\n\t\t)\n\t\tawait ctx.db.patch(runId, { workflowId, updatedAt: Date.now() })\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: 'approval.requested',\n\t\t\tactorRef: input.requester.actorRef,\n\t\t\trunId,\n\t\t\tresourceType: input.resourceType,\n\t\t\tresourceRef: input.resourceRef,\n\t\t\ttransition: 'requested',\n\t\t})\n\t\treturn { runId }\n\t},\n})\n\nexport const cancel = mutation({\n\targs: {\n\t\trunId: v.id('approvalRuns'),\n\t\tactor: approvalActor.validator,\n\t\tcompatibilityKey: v.string(),\n\t},\n\treturns: v.object({ state: v.literal(APPROVAL_RUN_STATES[4]) }),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tif (run.state !== 'pending') {\n\t\t\tif (run.state === 'canceled') return { state: 'canceled' as const }\n\t\t\tthrow new Error(`Approval request is already ${run.state}`)\n\t\t}\n\t\tif (!run.workflowId) throw new Error('Approval workflow is not linked')\n\t\t// SAFETY: this run stores the id returned by approvalWorkflow.start.\n\t\tawait approvalWorkflow.cancel(ctx, run.workflowId as WorkflowId)\n\t\tif (!canTransitionApprovalRun(run.state, 'canceled'))\n\t\t\tthrow new Error(`Approval request cannot transition from ${run.state}`)\n\t\tconst now = Date.now()\n\t\tawait ctx.db.patch(run._id, {\n\t\t\tstate: 'canceled',\n\t\t\texpiresAt: undefined,\n\t\t\tupdatedAt: now,\n\t\t\tterminalAt: now,\n\t\t})\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: 'approval.canceled',\n\t\t\tactorRef: input.actor.actorRef,\n\t\t\trunId: run._id,\n\t\t\tresourceType: run.resourceType,\n\t\t\tresourceRef: run.resourceRef,\n\t\t\ttransition: 'canceled',\n\t\t})\n\t\treturn { state: 'canceled' as const }\n\t},\n})\n\nexport const restart = mutation({\n\targs: { runId: v.id('approvalRuns'), compatibilityKey: v.string() },\n\treturns: v.null(),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\tif (!run.workflowId) throw new Error('Approval workflow is not linked')\n\t\tif (!run.executionFailedStepKey)\n\t\t\tthrow new Error('Approval workflow has no failed step to restart')\n\t\t// SAFETY: this run stores the id returned by approvalWorkflow.start.\n\t\tawait approvalWorkflow.restart(ctx, run.workflowId as WorkflowId, {\n\t\t\tfrom: run.executionFailedStepKey,\n\t\t\tstartAsync: true,\n\t\t})\n\t\treturn null\n\t},\n})\n\nexport const status = query({\n\targs: { runId: v.id('approvalRuns'), compatibilityKey: v.string() },\n\treturns: v.union(v.null(), approvalStatusValidator()),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) return null\n\t\tassertCompatible(run.workflow.compatibilityKey, input.compatibilityKey)\n\t\t// SAFETY: workflowId is the id persisted from approvalWorkflow.start for this run.\n\t\tconst workflowStatus = run.workflowId\n\t\t\t? await approvalWorkflow.status(ctx, run.workflowId as WorkflowId)\n\t\t\t: null\n\t\tconst execution = normalizeWorkflowStatus(workflowStatus)\n\t\treturn { run, execution }\n\t},\n})\n\nexport const list = query({\n\targs: {\n\t\tscopeRef: approvalReference.validator,\n\t\tstate: v.optional(approvalRunState.validator),\n\t\tpaginationOpts: paginationOptsValidator,\n\t},\n\treturns: paginationResultValidator(approvalRunValidator()),\n\thandler: (ctx, input) =>\n\t\tpaginator(ctx.db, schema)\n\t\t\t.query('approvalRuns')\n\t\t\t.withIndex('by_scopeRef_and_state', (query) =>\n\t\t\t\tinput.state === undefined\n\t\t\t\t\t? query.eq('scopeRef', input.scopeRef)\n\t\t\t\t\t: query.eq('scopeRef', input.scopeRef).eq('state', input.state),\n\t\t\t)\n\t\t\t.order('desc')\n\t\t\t.paginate(input.paginationOpts),\n})\n\nexport const getForWorkflow = internalQuery({\n\targs: { runId: v.id('approvalRuns') },\n\treturns: v.union(v.null(), approvalRunValidator()),\n\thandler: (ctx, input) => ctx.db.get(input.runId),\n})\n\nexport const recordExecutionTerminal = internalMutation({\n\targs: {\n\t\trunId: v.id('approvalRuns'),\n\t\toutcome: v.union(\n\t\t\tv.literal(APPROVAL_EXECUTION_STATES[1]),\n\t\t\tv.literal(APPROVAL_EXECUTION_STATES[3]),\n\t\t),\n\t\tfailedStepKey: v.optional(approvalName.validator),\n\t},\n\treturns: v.null(),\n\thandler: async (ctx, input) => {\n\t\tconst run = await ctx.db.get(input.runId)\n\t\tif (!run) throw new Error('Approval request not found')\n\t\tawait ctx.db.patch(run._id, {\n\t\t\texecutionFailedStepKey: input.outcome === 'failed' ? input.failedStepKey : undefined,\n\t\t\tupdatedAt: Date.now(),\n\t\t})\n\t\tawait logApprovalTransition(ctx, {\n\t\t\taction: `approval.execution.${input.outcome}`,\n\t\t\trunId: run._id,\n\t\t\tresourceType: run.resourceType,\n\t\t\tresourceRef: run.resourceRef,\n\t\t\ttransition: `execution:${input.outcome}`,\n\t\t\tseverity: input.outcome === 'failed' ? 'error' : 'info',\n\t\t})\n\t\treturn null\n\t},\n})\n\nconst approvalWorkflow = new WorkflowManager(components.workflow)\n\nfunction normalizeWorkflowStatus(\n\tstatus: Awaited<ReturnType<typeof approvalWorkflow.status>> | null,\n) {\n\tif (!status) return null\n\tswitch (status.type) {\n\t\tcase 'failed':\n\t\t\treturn { type: 'failed' as const, error: status.error }\n\t\tcase 'inProgress':\n\t\tcase 'completed':\n\t\tcase 'canceled':\n\t\t\treturn { type: status.type }\n\t}\n}\n\nfunction approvalRunValidator() {\n\treturn v.object({\n\t\t_id: v.id('approvalRuns'),\n\t\t_creationTime: v.number(),\n\t\t...approvalRunDocument.validator.fields,\n\t})\n}\n\nfunction workflowStatusValidator() {\n\treturn v.union(\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[0]) }),\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[1]) }),\n\t\tv.object({ type: v.literal(APPROVAL_EXECUTION_STATES[2]) }),\n\t\tv.object({\n\t\t\ttype: v.literal(APPROVAL_EXECUTION_STATES[3]),\n\t\t\terror: v.string(),\n\t\t}),\n\t)\n}\n\nfunction approvalStatusValidator() {\n\treturn v.object({\n\t\trun: approvalRunValidator(),\n\t\texecution: v.union(v.null(), workflowStatusValidator()),\n\t})\n}\n\nfunction assertCompatible(actual: string, expected: string): void {\n\tif (actual !== expected)\n\t\tthrow new Error(\n\t\t\t`Approval workflow compatibility mismatch: expected ${expected}, received ${actual}`,\n\t\t)\n}\n"],"mappings":"A,8yBAqBA,MAAaE,EAAQC,EAAS,CAC7B,KAAM,CACL,SAAUC,EAAkB,UAC5B,aAAcA,EAAkB,UAChC,YAAaA,EAAkB,UAC/B,UAAWC,EAAc,UACzB,SAAU,EAAE,SAASC,EAAiB,SAAS,EAC/C,SAAUC,EAA2B,SACtC,EACA,QAAS,EAAE,OAAO,CAAE,MAAO,EAAE,GAAG,cAAc,CAAE,CAAC,EACjD,QAAS,MAAO,EAAK,IAAU,CAC9B,IAAMC,EAAM,KAAK,IAAI,EACfC,EAAQ,MAAMC,EAAI,GAAG,OAAO,eAAgB,CACjD,GAAGC,EACH,MAAO,UACP,UAAWH,EACX,UAAWA,CACZ,CAAC,EACKI,EAAyB,MAAMC,EAAiB,MACrDH,EACAI,EAAS,SAAS,IAClB,CAAE,OAAM,EACR,CAAE,WAAY,EAAK,CACpB,EAUA,OATA,MAAMJ,EAAI,GAAG,MAAMD,EAAO,CAAE,aAAY,UAAW,KAAK,IAAI,CAAE,CAAC,EAC/D,MAAMM,EAAsBL,EAAK,CAChC,OAAQ,qBACR,SAAUC,EAAM,UAAU,SAC1B,QACA,a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