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
package/docs/llms.md DELETED
@@ -1,220 +0,0 @@
1
- # cvx-kit — condensed reference for LLMs and coding agents
2
-
3
- > Paste this file (installed at `node_modules/cvx-kit/docs/`) into an agent's
4
- > context when it works on a cvx-kit application. Detailed docs:
5
- > `architecture.md`, `conventions.md`, `zod-table.md`, `auth.md`,
6
- > `commands.md`, `triggers.md`, `approvals.md`, `maintainability.md`,
7
- > `migration.md` (same directory).
8
- > Structure, file anatomy, and naming rules → `conventions.md` is
9
- > authoritative. Restructuring an existing raw project → `migration.md`.
10
- > Upgrading from 0.0.x → `upgrading.md`. New 0.1.0 helpers: `crud.md`,
11
- > `webhooks.md`, `agent-tools.md`; pagination in `zod-table.md`/`auth.md`.
12
-
13
- > **Placeholders.** Names like `documents`, `users`, `history`, `title`,
14
- > `ownerId`, and `documentPublish` in the examples below are illustrative
15
- > only — replace them with the application's own entities and fields. No
16
- > specific table, entity, field, or workflow is required by the kit. Names in
17
- > `<angle brackets>` are always placeholders.
18
-
19
- cvx-kit is a reusable Convex application kit: zod table boundaries, auth-aware
20
- function constructors, a trigger registry, an audited command protocol
21
- (Foundation component), and a declarative approvals component. Peer deps:
22
- `convex ^1.43`, `zod ^4`.
23
-
24
- ## Non-negotiable rules
25
-
26
- 1. **One `zodTable` per entity**, in `domain/<entity>/schema.ts`. Never write
27
- `defineTable` inline or a second zod object for the same entity.
28
- 2. **Raw `query`/`mutation`/`action`/`internal*` builders appear only in
29
- `convex/functions.ts`** (the `createAuthFunctions` call). All other
30
- functions use `authQuery/authMutation/authAction`, `roleQuery/...`,
31
- `adminQuery/...` (public) or `systemQuery/systemMutation/systemAction` (internal).
32
- This is what guarantees auth, triggers, and bounded reads.
33
- 3. **Every public query returns DTOs** via `<table>.toPublicDto(row)` —
34
- runtime redaction, not just types.
35
- 4. **Every read is bounded**: `ctx.include(ctx.db.query('t')).matching(...)
36
- .execute(limit)` with `1 ≤ limit ≤ 100`. `.resolve()` falls back to a full
37
- table scan — avoid it.
38
- 5. **State changes are commands**: an operations registry with mandatory
39
- `classification` and `audit()` per operation, executed via
40
- `commands.exec({ operation, handler })`. Audit writes happen in the same
41
- transaction. Optional per-operation `permission` (checked via the
42
- Foundation's injected `checkPermission`) and `guard(ctx, command)`
43
- preconditions run BEFORE the handler, plus a registry-wide default guard
44
- (`new Command(operations, { guard })`). Composable middleware
45
- (`Command.middleware(async ({ context, next }) => ...)`) wraps
46
- [guards → handler] via registry `middleware: [...]` and per-operation
47
- `middleware: [...]` — `next({ context })` enriches downstream ctx, and
48
- the chain's output is re-parsed by the result schema. Query takes the
49
- same shape (`Query.middleware`, kernel + per-executor arrays). Order:
50
- permission → registry middleware → operation middleware → default guard
51
- → operation guard → handler → result parse → aggregates → audit.
52
- 6. **Never write timestamps by hand.** `createdAt`/`updatedAt` are maintained
53
- by the `timestamps` trigger; `archivedAt` is the app-controlled soft-delete
54
- marker.
55
- 7. **Vocabularies are named readonly tuples in `constants.ts`** —
56
- `z.enum([...])` with an inline literal is banned in kit-style codebases.
57
- 8. **Components are consumed only through their client facades**
58
- (`Foundation`, `Approvals`) — no deep imports, no touching component
59
- tables, no reaching private children (`components.approvals.workflow`).
60
- 9. **Operation names are `domain.verb` lowercase-dotted; error codes are
61
- UPPER_SNAKE** — otherwise observability silently drops the events.
62
- 10. **Row-level security is configured, not hand-rolled**: the optional
63
- `security` config on `createAuthFunctions` takes role-level `rules`
64
- (works standalone) and/or `tenancy` (a table registry; adds
65
- `ctx.tenant`, deny-default isolation, and pairs with `tenantTable` +
66
- `tenantOwnership`). Multi-tenant apps stamp inserts with
67
- `tenant: ctx.tenant` and re-verify client ids with
68
- `requireTenantReference`. See `tenancy.md`.
69
-
70
- ## Exports map
71
-
72
- | Import | Provides |
73
- |---|---|
74
- | `cvx-kit` | everything below re-exported (except components' defaults) |
75
- | `cvx-kit/zod-table` | `zodTable`, `tenantTable`, `createModule`, `paginated`, `zodVariantTable`, `jsonSafeZid`, `TIMESTAMP_FIELDS` |
76
- | `cvx-kit/auth` | `createAuthFunctions` (incl. optional `security` RLS config), `createInclude`, `defaultRoleMap` |
77
- | `cvx-kit/tenancy` | `createTenantRules`, `composeRules`, `requireTenantReference`, `assertTenantOwned`, `TENANT_FIELD` |
78
- | `cvx-kit/crud` | `createCrudCommands` — create/update/archive from a zodTable, inside the command pipeline; `enrich` REQUIRED for tenantTables |
79
- | `cvx-kit/state-machine` | `createStateMachine` — typed transitions from constants tuples; `assert` drops into command guards |
80
- | `cvx-kit/middleware` | `rateLimit` — packaged middleware over an injected rate-limiter instance; keyed by `ctx.tenant`, missing key = config error |
81
- | `cvx-kit/webhooks` | `createWebhookBoundary`, `recordWebhookEvent`, `webhookEventsTable` — raw-body verify, natural-key dedup in the mutation |
82
- | `cvx-kit/agent-tools` | `createAgentTools` — tool records from table masks; mutation handlers route through command executors |
83
- | `cvx-kit/triggers` | `createTriggers`, `timestamps`, `appendOnly`, `noDelete`, `tenantOwnership`, `Triggers` |
84
- | `cvx-kit/errors` | `KitError`, `defaultErrors`, `ErrorFactory` |
85
- | `cvx-kit/components/foundation` | `Foundation` — the ONLY runtime export besides the default component config for `app.use`. Everything (`Command`, `Query`, `observability`, `executeResultBoundary`, `projectResult`, `emitSemanticEvent`) destructures from the instance; nothing is importable loose. |
86
- | `cvx-kit/components/approvals` | `Approvals` client; default export = component config for `app.use` |
87
- | `cvx-kit/test` | `registerFoundation(t)`, `registerApprovals(t)` for convex-test |
88
-
89
- ## Minimal app wiring (the five root files)
90
-
91
- ```ts
92
- // convex/convex.config.ts
93
- import { defineApp } from 'convex/server'
94
- import foundation from 'cvx-kit/components/foundation/convex.config'
95
- import approvals from 'cvx-kit/components/approvals/convex.config'
96
- const app = defineApp()
97
- app.use(foundation)
98
- app.use(approvals)
99
- export default app
100
-
101
- // convex/triggers.ts
102
- import { createTriggers, timestamps, appendOnly } from 'cvx-kit/triggers'
103
- export const triggers = createTriggers<DataModel>()
104
- timestamps(triggers, 'documents')
105
- appendOnly(triggers, 'history')
106
-
107
- // convex/functions.ts
108
- export const { authQuery, authMutation, authAction, adminQuery, adminMutation,
109
- adminAction, roleQuery, roleMutation, roleAction, systemQuery, systemMutation,
110
- systemAction, include } = createAuthFunctions<DataModel>({
111
- query, mutation, action, internalQuery, internalMutation, internalAction, // from ./_generated/server
112
- getAuthUser: (ctx) => authKit.getAuthUser(ctx),
113
- mapRole: defaultRoleMap, // 'member'→'writer'; reader|writer|admin pass
114
- adminRoles: ['admin'],
115
- triggers,
116
- verifyMembership: async ({ userId, organizationId }) => { /* live check; actions only */ },
117
- resolveOrganization: async ({ ctx, identity, user }) => { /* org+role from app tables; overrides claims; null/throw ⇒ FORBIDDEN */ },
118
- })
119
-
120
- // convex/foundation.ts
121
- export const { Command, Query, observability } = new Foundation(
122
- components.foundation,
123
- { observability: {
124
- enabled: () => process.env.OBS === 'true',
125
- classifyError, // → { outcome: 'denied'|'failed', errorCode }
126
- writeAudit: (ctx, entry) => writeAuditEntry(ctx, entry),
127
- } },
128
- )
129
-
130
- // convex/approvals.ts
131
- export const approvals = new Approvals(components.approvals)
132
- ```
133
-
134
- ## Entity pattern
135
-
136
- ```ts
137
- // domain/documents/schema.ts
138
- export const documents = zodTable('documents', (id) => ({
139
- title: z.string(), ownerId: id('users'), secretNote: z.string(),
140
- }), {
141
- commandFields: ['title'], // what a command may say
142
- publicFields: ['title', 'ownerId'], // the DTO allowlist
143
- })
144
-
145
- // convex/schema.ts (via domain/table.ts)
146
- defineSchema({ documents: documents.table.index('by_owner', ['ownerId']) })
147
-
148
- // domain/documents/commands.ts
149
- const operations = {
150
- 'documents.rename': Command.operation({
151
- command: documents.commandInput.extend({ id: zid('documents'), actorId: z.string() }),
152
- result: z.object({ ok: z.literal(true) }).strict(),
153
- classification: 'business',
154
- audit: ({ command }) => ({ operation: 'documents.rename', actorId: command.actorId,
155
- aggregate: { type: 'document', id: command.id } }),
156
- }),
157
- } as const
158
- const commands = new Command<MutationCtx, typeof operations>(operations)
159
- export const executeRename = commands.exec({ operation: 'documents.rename',
160
- handler: async (ctx, cmd) => { await ctx.db.patch(cmd.id, { title: cmd.title }); return { ok: true } } })
161
-
162
- // api/documents.ts — thin public adapter
163
- export const rename = authMutation({
164
- args: documents.commandInput.extend({ id: zid('documents') }),
165
- returns: z.object({ ok: z.literal(true) }).strict(),
166
- handler: (ctx, args) => executeRename(ctx, { ...args, actorId: ctx.actor.userId }),
167
- })
168
- export const list = authQuery({
169
- args: { limit: z.number() },
170
- returns: z.array(documents.publicDto),
171
- handler: (ctx, { limit }) =>
172
- ctx.include(ctx.db.query('documents'))
173
- .matching('by_owner', (ix) => ix.eq('ownerId', ctx.actor.userId))
174
- .execute(limit, (rows) => rows.map(documents.toPublicDto)),
175
- })
176
- ```
177
-
178
- ## Auth ctx contents
179
-
180
- Authenticated handlers receive frozen `ctx.identity` (JWT), `ctx.user.id`,
181
- `ctx.org = { organizationId, role }`, `ctx.role`, `ctx.actor = { userId,
182
- organizationId, role }`, and `ctx.include`. Queries/mutations trust the JWT;
183
- **actions live-verify membership and fail closed**. Use `ctx.actor` as the
184
- canonical actor for audits/approvals.
185
-
186
- ## Approvals in one block
187
-
188
- ```ts
189
- export const publishApproval = approvals.define({ name: 'documentPublish', steps: [
190
- approvals.decision('managerDecision', { decisions: ['approved','rejected'],
191
- quorum: { kind: 'count', approvals: 1 }, makerChecker: true, expiresAfterMs: 604_800_000 }),
192
- approvals.branch('applyDecision', { approvedStepKey: 'publish', rejectedStepKey: 'notify' }),
193
- approvals.mutation('publish', { handler: internal.domain.documents.approval_functions.applyDecision }),
194
- approvals.notify('notify', { handler: internal.domain.documents.approval_functions.notifyRejected }),
195
- ]})
196
- // start(ctx, { scopeRef, resourceType, resourceRef, requester: ctx.actor, metadata? })
197
- // decide(ctx, { runId, decision, reason? }, ctx.actor) · status/evidence/list/cancel/restart
198
- ```
199
-
200
- Callback handlers are `systemMutation`/`systemAction`, receive opaque strings,
201
- and must `normalizeId` + re-check `resourceType` + verify the resource still
202
- points at `runId`.
203
-
204
- ## Footguns (top 8)
205
-
206
- 1. `t.run(ctx => ctx.db...)` in convex-test and raw builders bypass ALL
207
- triggers — seeding only.
208
- 2. `executeResultBoundary` returns a typed failure **only when the
209
- transaction has no effects yet**; after any write/schedule it rethrows for
210
- rollback. Handled-vs-thrown is decided by transaction state.
211
- 3. Observability drops events on identifier-regex mismatch — see rule 9.
212
- 4. Mis-declared `serverFields` silently make server-owned fields
213
- client-writable; masks are the security boundary.
214
- 5. `include(...).resolve()` silently falls back to `fullTableScan()`.
215
- 6. Audit callback ctx is untyped (`never`) — commands must run in mutations;
216
- wiring a query ctx fails at runtime.
217
- 7. Changing approval steps without bumping `compatibilityKey` lets old runs
218
- be driven by an incompatible shape.
219
- 8. When composing ctx manually, spread `wrapDB(ctx)` first — later spreads
220
- carrying `db` restore the unwrapped database.
@@ -1,124 +0,0 @@
1
- # Maintaining a Convex application built on cvx-kit
2
-
3
- Practices that keep a cvx-kit backend maintainable over years, taken from the
4
- origin application. The theme throughout: make every rule either *structural*
5
- (the code can't be written any other way) or *executable* (a test fails when
6
- it's violated). Conventions that live only in documentation decay.
7
-
8
- ## Schema and indexes
9
-
10
- - `convex/schema.ts` stays at ~4 lines: `defineSchema(domainTables)`.
11
- Per-domain `table.ts` files attach indexes to `<zodTable>.table` and
12
- `domain/table.ts` merges the maps. Shapes (zod) and topology (indexes) are
13
- deliberately separate files.
14
- - **Index naming**: `by_<field>_and_<field>...`, camelCase field names in
15
- declaration order, nested paths flattened with `_`
16
- (`by_assignedToUserId_and_state_status` for `['assignedToUserId',
17
- 'state.status']`). A reader should reconstruct the index definition from its
18
- name.
19
- - Every read goes through `ctx.include(...)` with an explicit limit ≤ 100.
20
- If a query can't be served by an index, that's a schema problem, not a
21
- reason to `fullTableScan`.
22
-
23
- ## Schema evolution without downtime
24
-
25
- Convex validates the whole table against the schema on push, so evolution is
26
- additive:
27
-
28
- 1. **New fields arrive `.optional()`** with a comment explaining the epoch:
29
- `// Optional only for documents created before priority was frozen.`
30
- 2. Deploy code that writes the new field on every new write and tolerates its
31
- absence on reads.
32
- 3. Backfill if needed (a `systemMutation` batch or `@convex-dev/migrations`),
33
- then — and only then — consider tightening the schema.
34
- 4. Never rename in place: add the new field, dual-write, backfill, drop the
35
- old one release(s) later.
36
-
37
- zod-table makes step 1 cheap: change the shape once and every boundary mask
38
- updates together, with `tsc` pointing at every consumer that must adapt.
39
-
40
- ## Function hygiene
41
-
42
- - Raw `query`/`mutation`/`action` builders appear **only** in `functions.ts`.
43
- Everything public is `auth*`/`role*`/`admin*`; everything
44
- internal/scheduled is `system*`. This is what makes triggers, auth, and
45
- bounded reads impossible to forget.
46
- - Public functions in `api/` are thin: parse args (zod-table masks), call the
47
- domain executor with `ctx.actor`, project through `toPublicDto`. Business
48
- logic that lives in an adapter can't be reused by workflows or callbacks —
49
- keep it in the domain.
50
- - Vocabularies (states, kinds, decisions) are single-owner readonly tuples in
51
- `constants.ts`. Grep for the tuple name to find every consumer.
52
-
53
- ## Audit and observability as maintenance tools
54
-
55
- - Every state change is a command with a mandatory classification and audit
56
- derivation — so "what happened to this record" is a query over the audit
57
- log, not archaeology. Keep operation names stable (`domain.verb`); they are
58
- your telemetry and audit vocabulary.
59
- - Observability is payload-free by construction — you can leave it on in
60
- production and grep durable one-line JSON events
61
- (`event: 'command.execution'`) without PII review.
62
- - Set retention deliberately: audit entries carry the classification as their
63
- retention category; the approvals component ships `cleanupAudit` for its own
64
- trail.
65
-
66
- ## Testing strategy
67
-
68
- Three test layers, all in-memory via `convex-test` on `edge-runtime`:
69
-
70
- 1. **Behavioral tests** — drive functions through the real constructors
71
- (`t.withIdentity(...)`), assert DTO shapes and trigger effects. Remember:
72
- `t.run(ctx => ctx.db...)` bypasses triggers — use it for seeding, not for
73
- asserting write behavior.
74
- 2. **Architecture tests** — glob the source and assert the conventions
75
- (no inline tables/enums, no deep imports, no sibling-domain imports, one
76
- `app.use` per component, no raw builders outside `functions.ts`). Prove
77
- each rule against a synthetic violating fixture first.
78
- 3. **Boundary/copyability tests** — components contain no host imports and no
79
- vendor/env references; optionally `cp -r` the component to a tmpdir and
80
- run `tsc` to prove copy-portability.
81
-
82
- Consumers register the kit's components on their test instance:
83
-
84
- ```ts
85
- import { convexTest } from 'convex-test'
86
- import { registerApprovals, registerFoundation } from 'cvx-kit/test'
87
-
88
- const t = convexTest(schema, modules)
89
- registerFoundation(t)
90
- registerApprovals(t)
91
- ```
92
-
93
- (`cvx-kit/test` ships as source and needs a vitest-compatible runner —
94
- `import.meta.glob`.) Nested components used by approvals register their own
95
- test modules the same way (`@convex-dev/workflow/test`,
96
- `convex-audit-log/test`). Stub required env vars (declared on
97
- `defineApp({ env })`) in test setup.
98
-
99
- ## Operational habits
100
-
101
- - **Env flags over redeploys**: observability is toggled by an env var read
102
- at call time (`enabled: () => env.OBS === 'true'`).
103
- - **Fail closed**: membership verification errors reject; unknown roles
104
- reject; unreadable transaction metrics rethrow. Preserve this bias in app
105
- code.
106
- - **Soft deletes** (`archivedAt` + `noDelete`) for anything a human might ask
107
- about later; `appendOnly` for evidence tables. Hard deletes are a data-loss
108
- bug you opt into per table.
109
- - **Component upgrades**: components own their tables; upgrade them like
110
- services — read the component's migration notes, bump, run codegen, run the
111
- suite. Never write to a component's tables from the host.
112
-
113
- ## Checklist for a new entity
114
-
115
- 1. `domain/<entity>/schema.ts` — `zodTable` with the three masks thought
116
- through (`serverFields`, `commandFields`, `publicFields`).
117
- 2. `domain/<entity>/table.ts` — indexes, named `by_...`.
118
- 3. Register in `domain/table.ts`; add `timestamps(triggers, '<table>')` and
119
- any `appendOnly`/`noDelete` discipline.
120
- 4. `constants.ts` — vocabularies as readonly tuples.
121
- 5. `commands.ts` — operation registry (`domain.verb`, classification, audit)
122
- + executors.
123
- 6. `api/<entity>.ts` — thin `auth*` adapters, DTO projection.
124
- 7. Tests: behavior + add the entity to the architecture globs.