cvx-kit 0.1.35 → 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 (327) hide show
  1. package/README.md +92 -49
  2. package/dist/agent-tools.d.mts +21 -25
  3. package/dist/agent-tools.mjs +1 -1
  4. package/dist/agent-tools.mjs.map +1 -1
  5. package/dist/auth.d.mts +20 -14
  6. package/dist/auth.mjs +1 -1
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/components/approvals/_generated/api.d.mts +4 -5
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -1
  10. package/dist/components/approvals/_generated/component.d.mts +0 -2
  11. package/dist/components/approvals/_generated/dataModel.d.mts +1 -3
  12. package/dist/components/approvals/_generated/server.d.mts +0 -2
  13. package/dist/components/approvals/_generated/server.mjs.map +1 -1
  14. package/dist/components/approvals/audit.d.mts +0 -1
  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 +0 -1
  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 +0 -1
  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 +1 -4
  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 +0 -1
  28. package/dist/components/approvals/functions.mjs.map +1 -1
  29. package/dist/components/approvals/health.d.mts +0 -1
  30. package/dist/components/approvals/health.mjs.map +1 -1
  31. package/dist/components/approvals/requests.d.mts +106 -123
  32. package/dist/components/approvals/requests.mjs +1 -1
  33. package/dist/components/approvals/requests.mjs.map +1 -1
  34. package/dist/components/approvals/schema.d.ts +106 -315
  35. package/dist/components/approvals/schema.js +1 -1
  36. package/dist/components/approvals/validators.d.mts +321 -393
  37. package/dist/components/approvals/validators.mjs +1 -1
  38. package/dist/components/approvals/validators.mjs.map +1 -1
  39. package/dist/components/approvals/workflow.d.mts +0 -1
  40. package/dist/components/approvals/workflow.mjs +1 -1
  41. package/dist/components/approvals/workflow.mjs.map +1 -1
  42. package/dist/components/approvals/workflow_steps.d.mts +1 -2
  43. package/dist/components/approvals/workflow_steps.mjs.map +1 -1
  44. package/dist/components/foundation/_generated/api.d.mts +3 -4
  45. package/dist/components/foundation/_generated/api.mjs.map +1 -1
  46. package/dist/components/foundation/_generated/component.d.mts +0 -2
  47. package/dist/components/foundation/_generated/dataModel.d.mts +1 -3
  48. package/dist/components/foundation/_generated/server.d.mts +0 -2
  49. package/dist/components/foundation/_generated/server.mjs.map +1 -1
  50. package/dist/components/foundation/client.d.mts +0 -1
  51. package/dist/components/foundation/client.mjs +1 -1
  52. package/dist/components/foundation/client.mjs.map +1 -1
  53. package/dist/components/foundation/convex.config.d.mts +0 -2
  54. package/dist/components/foundation/convex.config.mjs.map +1 -1
  55. package/dist/components/foundation/functions.d.mts +0 -1
  56. package/dist/components/foundation/functions.mjs.map +1 -1
  57. package/dist/components/foundation/modules/command/command.d.mts +0 -1
  58. package/dist/components/foundation/modules/command/command.mjs.map +1 -1
  59. package/dist/components/foundation/modules/command/lifecycle.d.mts +0 -2
  60. package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -1
  61. package/dist/components/foundation/modules/observability/observability.d.mts +0 -1
  62. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
  63. package/dist/components/foundation/modules/query/query.d.mts +0 -1
  64. package/dist/components/foundation/modules/query/query.mjs.map +1 -1
  65. package/dist/components/foundation/operation.d.mts +2 -3
  66. package/dist/components/foundation/operation.mjs.map +1 -1
  67. package/dist/components/foundation/result.d.mts +0 -1
  68. package/dist/components/foundation/result.mjs.map +1 -1
  69. package/dist/components/foundation/schema.d.ts +0 -2
  70. package/dist/components/foundation/telemetry.d.mts +0 -1
  71. package/dist/components/foundation/telemetry.mjs +1 -1
  72. package/dist/components/foundation/telemetry.mjs.map +1 -1
  73. package/dist/contracts.d.mts +2 -2
  74. package/dist/contracts.mjs +1 -1
  75. package/dist/crud.d.mts +93 -97
  76. package/dist/crud.mjs +1 -1
  77. package/dist/crud.mjs.map +1 -1
  78. package/dist/effect.d.mts +2 -3
  79. package/dist/effect.mjs +1 -1
  80. package/dist/errors.d.mts +2 -4
  81. package/dist/errors.mjs +1 -1
  82. package/dist/errors.mjs.map +1 -1
  83. package/dist/filters.d.mts +1 -1
  84. package/dist/filters.mjs +1 -1
  85. package/dist/idempotency.mjs +1 -1
  86. package/dist/index.d.mts +10 -7
  87. package/dist/index.mjs +1 -1
  88. package/dist/json-schema.d.mts +40 -0
  89. package/dist/json-schema.mjs +2 -0
  90. package/dist/json-schema.mjs.map +1 -0
  91. package/dist/k/compile.d.mts +17 -0
  92. package/dist/k/compile.mjs +2 -0
  93. package/dist/k/compile.mjs.map +1 -0
  94. package/dist/k/dates.d.mts +23 -0
  95. package/dist/k/dates.mjs +2 -0
  96. package/dist/k/dates.mjs.map +1 -0
  97. package/dist/k/formats.d.mts +24 -0
  98. package/dist/k/formats.mjs +2 -0
  99. package/dist/k/formats.mjs.map +1 -0
  100. package/dist/k/index.d.mts +32 -0
  101. package/dist/k/index.mjs +2 -0
  102. package/dist/k/index.mjs.map +1 -0
  103. package/dist/k/issues.d.mts +31 -0
  104. package/dist/k/issues.mjs +2 -0
  105. package/dist/k/issues.mjs.map +1 -0
  106. package/dist/k/kinds.d.mts +81 -0
  107. package/dist/k/kinds.mjs +2 -0
  108. package/dist/k/kinds.mjs.map +1 -0
  109. package/dist/k/object.d.mts +43 -0
  110. package/dist/k/object.mjs +2 -0
  111. package/dist/k/object.mjs.map +1 -0
  112. package/dist/k/parse.d.mts +29 -0
  113. package/dist/k/parse.mjs +2 -0
  114. package/dist/k/parse.mjs.map +1 -0
  115. package/dist/k/schema.d.mts +100 -0
  116. package/dist/k/schema.mjs +2 -0
  117. package/dist/k/schema.mjs.map +1 -0
  118. package/dist/k/standard.d.mts +8 -0
  119. package/dist/k/standard.mjs +2 -0
  120. package/dist/k/standard.mjs.map +1 -0
  121. package/dist/k/types.d.mts +64 -0
  122. package/dist/k/types.mjs +1 -0
  123. package/dist/k.d.mts +8 -0
  124. package/dist/k.mjs +1 -0
  125. package/dist/middleware.d.mts +0 -2
  126. package/dist/middleware.mjs +1 -1
  127. package/dist/middleware.mjs.map +1 -1
  128. package/dist/modules/contracts/binding.d.mts +1 -2
  129. package/dist/modules/contracts/binding.mjs.map +1 -1
  130. package/dist/modules/contracts/contract.d.mts +0 -2
  131. package/dist/modules/contracts/contract.mjs.map +1 -1
  132. package/dist/modules/contracts/convex.d.mts +1 -3
  133. package/dist/modules/contracts/convex.mjs.map +1 -1
  134. package/dist/modules/contracts/domain.d.mts +1 -2
  135. package/dist/modules/contracts/domain.mjs.map +1 -1
  136. package/dist/modules/contracts/errors.d.mts +161 -2
  137. package/dist/modules/contracts/errors.mjs +1 -1
  138. package/dist/modules/contracts/errors.mjs.map +1 -1
  139. package/dist/modules/contracts/exposure.d.mts +1 -2
  140. package/dist/modules/contracts/exposure.mjs.map +1 -1
  141. package/dist/modules/contracts/idempotency.d.mts +1 -2
  142. package/dist/modules/contracts/idempotency.mjs +1 -1
  143. package/dist/modules/contracts/idempotency.mjs.map +1 -1
  144. package/dist/modules/contracts/lazy.d.mts +0 -2
  145. package/dist/modules/contracts/lazy.mjs.map +1 -1
  146. package/dist/modules/contracts/standard.d.mts +7 -5
  147. package/dist/modules/contracts/standard.mjs +1 -1
  148. package/dist/modules/contracts/standard.mjs.map +1 -1
  149. package/dist/modules/contracts/workflow.d.mts +1 -2
  150. package/dist/modules/contracts/workflow.mjs.map +1 -1
  151. package/dist/modules/effect/action.d.mts +6 -7
  152. package/dist/modules/effect/action.mjs +1 -1
  153. package/dist/modules/effect/action.mjs.map +1 -1
  154. package/dist/modules/effect/agent-tools.mjs +1 -1
  155. package/dist/modules/effect/api-runtime.d.mts +1 -2
  156. package/dist/modules/effect/api-runtime.mjs +1 -1
  157. package/dist/modules/effect/api-runtime.mjs.map +1 -1
  158. package/dist/modules/effect/api.d.mts +41 -15
  159. package/dist/modules/effect/api.mjs +1 -1
  160. package/dist/modules/effect/api.mjs.map +1 -1
  161. package/dist/modules/effect/auth.d.mts +5 -6
  162. package/dist/modules/effect/auth.mjs +1 -1
  163. package/dist/modules/effect/auth.mjs.map +1 -1
  164. package/dist/modules/effect/client.d.mts +7 -8
  165. package/dist/modules/effect/client.mjs +1 -1
  166. package/dist/modules/effect/command.d.mts +7 -5
  167. package/dist/modules/effect/command.mjs +1 -1
  168. package/dist/modules/effect/command.mjs.map +1 -1
  169. package/dist/modules/effect/crud.d.mts +272 -206
  170. package/dist/modules/effect/crud.mjs +1 -1
  171. package/dist/modules/effect/crud.mjs.map +1 -1
  172. package/dist/modules/effect/domain.d.mts +5 -6
  173. package/dist/modules/effect/domain.mjs.map +1 -1
  174. package/dist/modules/effect/errors.d.mts +4 -2
  175. package/dist/modules/effect/errors.mjs +1 -1
  176. package/dist/modules/effect/errors.mjs.map +1 -1
  177. package/dist/modules/effect/failure-audit.d.mts +2 -2
  178. package/dist/modules/effect/failure-audit.mjs +1 -1
  179. package/dist/modules/effect/failure-audit.mjs.map +1 -1
  180. package/dist/modules/effect/failures.d.mts +1 -2
  181. package/dist/modules/effect/failures.mjs.map +1 -1
  182. package/dist/modules/effect/foundation.d.mts +0 -2
  183. package/dist/modules/effect/foundation.mjs.map +1 -1
  184. package/dist/modules/effect/idempotency.d.mts +2 -3
  185. package/dist/modules/effect/idempotency.mjs +1 -1
  186. package/dist/modules/effect/idempotency.mjs.map +1 -1
  187. package/dist/modules/effect/input.d.mts +10 -0
  188. package/dist/modules/effect/input.mjs +2 -0
  189. package/dist/modules/effect/input.mjs.map +1 -0
  190. package/dist/modules/effect/normalize.d.mts +0 -2
  191. package/dist/modules/effect/normalize.mjs.map +1 -1
  192. package/dist/modules/effect/operation.d.mts +2 -3
  193. package/dist/modules/effect/operation.mjs.map +1 -1
  194. package/dist/modules/effect/query.d.mts +6 -4
  195. package/dist/modules/effect/query.mjs +1 -1
  196. package/dist/modules/effect/query.mjs.map +1 -1
  197. package/dist/modules/effect/schema.d.mts +0 -2
  198. package/dist/modules/effect/schema.mjs.map +1 -1
  199. package/dist/modules/effect/scope.d.mts +0 -2
  200. package/dist/modules/effect/scope.mjs.map +1 -1
  201. package/dist/modules/effect/workflow.d.mts +4 -5
  202. package/dist/modules/effect/workflow.mjs +1 -1
  203. package/dist/modules/effect/workflow.mjs.map +1 -1
  204. package/dist/modules/foundation/foundation.d.mts +4 -5
  205. package/dist/modules/foundation/foundation.mjs +1 -1
  206. package/dist/modules/foundation/foundation.mjs.map +1 -1
  207. package/dist/modules/foundation/operation.d.mts +2 -3
  208. package/dist/modules/foundation/operation.mjs.map +1 -1
  209. package/dist/namespace.d.mts +104 -0
  210. package/dist/namespace.mjs +2 -0
  211. package/dist/namespace.mjs.map +1 -0
  212. package/dist/oxlint/architecture.d.mts +0 -2
  213. package/dist/oxlint/architecture.mjs +1 -1
  214. package/dist/oxlint/architecture.mjs.map +1 -1
  215. package/dist/oxlint/ast.d.mts +16 -8
  216. package/dist/oxlint/ast.mjs +1 -1
  217. package/dist/oxlint/ast.mjs.map +1 -1
  218. package/dist/oxlint/components.d.mts +0 -2
  219. package/dist/oxlint/components.mjs.map +1 -1
  220. package/dist/oxlint/ownership.d.mts +0 -2
  221. package/dist/oxlint/ownership.mjs +1 -1
  222. package/dist/oxlint/ownership.mjs.map +1 -1
  223. package/dist/oxlint/reserved-files.d.mts +0 -2
  224. package/dist/oxlint/reserved-files.mjs +1 -1
  225. package/dist/oxlint/reserved-files.mjs.map +1 -1
  226. package/dist/oxlint.d.mts +0 -2
  227. package/dist/oxlint.mjs +1 -1
  228. package/dist/oxlint.mjs.map +1 -1
  229. package/dist/querying/cursors.d.mts +27 -9
  230. package/dist/querying/cursors.mjs +1 -1
  231. package/dist/querying/cursors.mjs.map +1 -1
  232. package/dist/querying/execution.d.mts +6 -7
  233. package/dist/querying/execution.mjs +1 -1
  234. package/dist/querying/execution.mjs.map +1 -1
  235. package/dist/querying/failures.d.mts +0 -2
  236. package/dist/querying/failures.mjs +1 -1
  237. package/dist/querying/failures.mjs.map +1 -1
  238. package/dist/querying/filter-boundary.d.mts +18 -9
  239. package/dist/querying/filter-boundary.mjs +1 -1
  240. package/dist/querying/filter-boundary.mjs.map +1 -1
  241. package/dist/querying/filters.d.mts +71 -35
  242. package/dist/querying/filters.mjs +1 -1
  243. package/dist/querying/filters.mjs.map +1 -1
  244. package/dist/querying/planner.d.mts +16 -20
  245. package/dist/querying/planner.mjs +1 -1
  246. package/dist/querying/planner.mjs.map +1 -1
  247. package/dist/querying/relationships.d.mts +6 -6
  248. package/dist/querying/relationships.mjs +1 -1
  249. package/dist/querying/relationships.mjs.map +1 -1
  250. package/dist/querying/search.d.mts +12 -12
  251. package/dist/querying/search.mjs +1 -1
  252. package/dist/querying/search.mjs.map +1 -1
  253. package/dist/querying/security.d.mts +2 -3
  254. package/dist/querying/security.mjs.map +1 -1
  255. package/dist/querying/shared/ast.d.mts +0 -2
  256. package/dist/querying/shared/ast.mjs.map +1 -1
  257. package/dist/querying/shared/contract.d.mts +17 -23
  258. package/dist/querying/shared/contract.mjs +1 -1
  259. package/dist/querying/shared/contract.mjs.map +1 -1
  260. package/dist/querying/shared/evaluate.d.mts +0 -2
  261. package/dist/querying/shared/evaluate.mjs.map +1 -1
  262. package/dist/querying/shared/filters.d.mts +47 -29
  263. package/dist/querying/shared/filters.mjs +1 -1
  264. package/dist/querying/shared/filters.mjs.map +1 -1
  265. package/dist/querying/shared/native-json.d.mts +7 -0
  266. package/dist/querying/shared/native-json.mjs +2 -0
  267. package/dist/querying/shared/native-json.mjs.map +1 -0
  268. package/dist/querying/shared/page.d.mts +19 -22
  269. package/dist/querying/shared/page.mjs +1 -1
  270. package/dist/querying/shared/page.mjs.map +1 -1
  271. package/dist/querying.d.mts +6 -9
  272. package/dist/querying.mjs +1 -1
  273. package/dist/querying.mjs.map +1 -1
  274. package/dist/react/failures.d.mts +0 -2
  275. package/dist/react/failures.mjs.map +1 -1
  276. package/dist/react/optimistic.d.mts +2 -3
  277. package/dist/react/optimistic.mjs.map +1 -1
  278. package/dist/react/pagination-state.d.mts +1 -2
  279. package/dist/react/pagination-state.mjs.map +1 -1
  280. package/dist/react/use-command.d.mts +0 -2
  281. package/dist/react/use-command.mjs.map +1 -1
  282. package/dist/react/use-paginated-list.d.mts +1 -3
  283. package/dist/react/use-paginated-list.mjs +1 -1
  284. package/dist/react/use-paginated-list.mjs.map +1 -1
  285. package/dist/react.d.mts +1 -1
  286. package/dist/react.mjs +1 -1
  287. package/dist/registration.d.mts +65 -0
  288. package/dist/registration.mjs +2 -0
  289. package/dist/registration.mjs.map +1 -0
  290. package/dist/relations-public.d.mts +2 -2
  291. package/dist/relations-public.mjs +1 -1
  292. package/dist/relations.d.mts +55 -46
  293. package/dist/relations.mjs +1 -1
  294. package/dist/relations.mjs.map +1 -1
  295. package/dist/state-machine.d.mts +0 -2
  296. package/dist/state-machine.mjs.map +1 -1
  297. package/dist/table.d.mts +222 -0
  298. package/dist/table.mjs +2 -0
  299. package/dist/table.mjs.map +1 -0
  300. package/dist/tenancy.d.mts +0 -2
  301. package/dist/tenancy.mjs.map +1 -1
  302. package/dist/triggers.d.mts +2 -4
  303. package/dist/triggers.mjs +1 -1
  304. package/dist/triggers.mjs.map +1 -1
  305. package/dist/webhooks.d.mts +9 -9
  306. package/dist/webhooks.mjs +1 -1
  307. package/dist/webhooks.mjs.map +1 -1
  308. package/dist/workflow.mjs +1 -1
  309. package/dist/zod.d.mts +30 -0
  310. package/dist/zod.mjs +2 -0
  311. package/dist/zod.mjs.map +1 -0
  312. package/package.json +51 -29
  313. package/dist/modules/effect/api-zod.d.mts +0 -34
  314. package/dist/modules/effect/api-zod.mjs +0 -2
  315. package/dist/modules/effect/api-zod.mjs.map +0 -1
  316. package/dist/querying/schema-snapshot.d.mts +0 -49
  317. package/dist/querying/schema-snapshot.mjs +0 -2
  318. package/dist/querying/schema-snapshot.mjs.map +0 -1
  319. package/dist/zod-convex.d.mts +0 -10
  320. package/dist/zod-convex.mjs +0 -2
  321. package/dist/zod-convex.mjs.map +0 -1
  322. package/dist/zod-registration.d.mts +0 -15
  323. package/dist/zod-registration.mjs +0 -2
  324. package/dist/zod-registration.mjs.map +0 -1
  325. package/dist/zod-table.d.mts +0 -351
  326. package/dist/zod-table.mjs +0 -2
  327. package/dist/zod-table.mjs.map +0 -1
package/dist/crud.d.mts CHANGED
@@ -1,18 +1,28 @@
1
- import { ErrorFactory } from "./errors.mjs";
2
- import { SchemaInput, SchemaOutput } from "./components/foundation/modules/command/command.mjs";
1
+ import { KFields, KType } from "./k/types.mjs";
2
+ import { KOptional } from "./k/schema.mjs";
3
+ import { KId, KLiteral } from "./k/kinds.mjs";
4
+ import { KObject } from "./k/object.mjs";
5
+ import { k } from "./k/index.mjs";
6
+ import "./k.mjs";
7
+ import { Parseable, SchemaInput, SchemaOutput } from "./components/foundation/modules/command/command.mjs";
3
8
  import { AnyCommandMiddleware, ApplicationCommand, AuditedOperation, CommandConstructor } from "./components/foundation/client.mjs";
4
- import { GenericDataModel, GenericMutationCtx } from "convex/server";
5
- import { z } from "zod";
9
+ import { ErrorFactory } from "./errors.mjs";
6
10
  import { Value } from "convex/values";
7
- //#region src/crud.d.ts
11
+ import { GenericDataModel, GenericMutationCtx } from "convex/server";
8
12
  /**
9
- * The zodTable surface the factory consumes — structural, so any zodTable /
10
- * tenantTable return satisfies it.
13
+ * The table surface the factory consumes — structural, so any kTable / createTable / tenantTable
14
+ * boundary satisfies it.
11
15
  */
12
16
  type CrudTable = {
13
- tableName: string;
14
- commandInput: z.ZodObject<Record<string, z.ZodType<Value | undefined>>>;
15
- storage: z.ZodObject<Record<string, z.ZodType<Value | undefined>>>;
17
+ readonly tableName: string;
18
+ readonly commandInput: KType & Parseable<CommandRow>;
19
+ readonly storage: KType & {
20
+ readonly shape: KFields;
21
+ };
22
+ };
23
+ /** A parsed command: the commandFields' values. */
24
+ type CommandRow = {
25
+ readonly [field: string]: Value | undefined;
16
26
  };
17
27
  type CrudContext = {
18
28
  db: Pick<GenericMutationCtx<GenericDataModel>['db'], 'insert' | 'patch'>;
@@ -33,7 +43,7 @@ export type CrudConfig<Context extends CrudContext, Table extends CrudTable = Cr
33
43
  * REQUIRED when the table is a tenantTable — forgetting it would insert
34
44
  * untenanted rows; the factory fails fast at construction instead.
35
45
  */
36
- enrich?: (context: Context, command: SchemaOutput<Table['commandInput']>) => MaybePromise<Partial<z.input<Table['storage']>>>;
46
+ enrich?: (context: Context, command: SchemaOutput<Table['commandInput']>) => MaybePromise<Partial<k.input<Table['storage']>>>;
37
47
  /** Per-operation preconditions; run before the handlers. */
38
48
  guards?: {
39
49
  create?: (context: Context, command: never) => MaybePromise<void>;
@@ -45,7 +55,7 @@ export type CrudConfig<Context extends CrudContext, Table extends CrudTable = Cr
45
55
  errors?: ErrorFactory;
46
56
  };
47
57
  /**
48
- * Generates the standard create/update/archive operations from one zodTable
58
+ * Generates the standard create/update/archive operations from one kTable
49
59
  * declaration, fully inside the audited command pipeline: strict command
50
60
  * inputs from `commandFields`, mandatory audit with the declared aggregate
51
61
  * type, soft delete only (archive sets `archivedAt` — no hard-delete
@@ -59,183 +69,169 @@ export type CrudCommands<Context extends CrudContext, Table extends CrudTable =
59
69
  export declare function createCrudCommands<Context extends CrudContext, Table extends CrudTable = CrudTable>(config: CrudConfig<Context, Table>): {
60
70
  commands: ApplicationCommand<Context, NamedOperation<`${string}.create`, {
61
71
  command: Table["commandInput"];
62
- result: z.ZodObject<{
63
- id: import("convex-helpers/server/zod4").Zid<string>;
64
- }, z.core.$strict>;
72
+ result: KObject<{
73
+ id: KId<string>;
74
+ }>;
65
75
  classification: string;
66
76
  aggregates: string[];
67
77
  middleware: readonly AnyCommandMiddleware[] | undefined;
68
78
  guard: ((context: Context, command: never) => MaybePromise<void>) | undefined;
69
79
  audit: (resolution: {
70
- result: z.output<z.ZodObject<{
71
- id: import("convex-helpers/server/zod4").Zid<string>;
72
- }, z.core.$strict>>;
80
+ result: k.infer<KObject<{
81
+ id: KId<string>;
82
+ }>>;
73
83
  }, context: Context) => {
74
84
  operation: `${string}.create`;
75
85
  actorId: string;
76
86
  aggregate: {
77
87
  type: string;
78
- id: string & {
79
- __tableName: string;
80
- };
88
+ id: import("convex/values").GenericId<string>;
81
89
  };
82
90
  };
83
91
  }> & NamedOperation<`${string}.update`, {
84
- command: z.ZodObject<{
85
- id: import("convex-helpers/server/zod4").Zid<string>;
86
- data: z.ZodObject<{
87
- [x: string]: z.ZodOptional<z.ZodType<Value | undefined, unknown, z.core.$ZodTypeInternals<Value | undefined, unknown>>>;
88
- }, z.core.$strict>;
89
- }, z.core.$strict>;
90
- result: z.ZodObject<{
91
- ok: z.ZodLiteral<true>;
92
- }, z.core.$strict>;
92
+ command: KObject<{
93
+ id: KId<string>;
94
+ data: KObject<{
95
+ readonly [x: string]: KOptional<KType>;
96
+ }>;
97
+ }>;
98
+ result: KObject<{
99
+ ok: KLiteral<true>;
100
+ }>;
93
101
  classification: string;
94
102
  aggregates: string[];
95
103
  middleware: readonly AnyCommandMiddleware[] | undefined;
96
104
  guard: ((context: Context, command: never) => MaybePromise<void>) | undefined;
97
105
  audit: (resolution: {
98
- command: z.output<z.ZodObject<{
99
- id: import("convex-helpers/server/zod4").Zid<string>;
100
- data: z.ZodObject<{
101
- [x: string]: z.ZodOptional<z.ZodType<Value | undefined, unknown, z.core.$ZodTypeInternals<Value | undefined, unknown>>>;
102
- }, z.core.$strict>;
103
- }, z.core.$strict>>;
106
+ command: k.infer<KObject<{
107
+ id: KId<string>;
108
+ data: KObject<{
109
+ readonly [x: string]: KOptional<KType>;
110
+ }>;
111
+ }>>;
104
112
  }, context: Context) => {
105
113
  operation: `${string}.update`;
106
114
  actorId: string;
107
115
  aggregate: {
108
116
  type: string;
109
- id: string & {
110
- __tableName: string;
111
- };
117
+ id: import("convex/values").GenericId<string>;
112
118
  };
113
119
  };
114
120
  }> & NamedOperation<`${string}.archive`, {
115
- command: z.ZodObject<{
116
- id: import("convex-helpers/server/zod4").Zid<string>;
117
- }, z.core.$strict>;
118
- result: z.ZodObject<{
119
- ok: z.ZodLiteral<true>;
120
- }, z.core.$strict>;
121
+ command: KObject<{
122
+ id: KId<string>;
123
+ }>;
124
+ result: KObject<{
125
+ ok: KLiteral<true>;
126
+ }>;
121
127
  classification: string;
122
128
  aggregates: string[];
123
129
  middleware: readonly AnyCommandMiddleware[] | undefined;
124
130
  guard: ((context: Context, command: never) => MaybePromise<void>) | undefined;
125
131
  audit: (resolution: {
126
- command: z.output<z.ZodObject<{
127
- id: import("convex-helpers/server/zod4").Zid<string>;
128
- }, z.core.$strict>>;
132
+ command: k.infer<KObject<{
133
+ id: KId<string>;
134
+ }>>;
129
135
  }, context: Context) => {
130
136
  operation: `${string}.archive`;
131
137
  actorId: string;
132
138
  aggregate: {
133
139
  type: string;
134
- id: string & {
135
- __tableName: string;
136
- };
140
+ id: import("convex/values").GenericId<string>;
137
141
  };
138
142
  };
139
143
  }>>;
140
144
  operations: NamedOperation<`${string}.create`, {
141
145
  command: Table["commandInput"];
142
- result: z.ZodObject<{
143
- id: import("convex-helpers/server/zod4").Zid<string>;
144
- }, z.core.$strict>;
146
+ result: KObject<{
147
+ id: KId<string>;
148
+ }>;
145
149
  classification: string;
146
150
  aggregates: string[];
147
151
  middleware: readonly AnyCommandMiddleware[] | undefined;
148
152
  guard: ((context: Context, command: never) => MaybePromise<void>) | undefined;
149
153
  audit: (resolution: {
150
- result: z.output<z.ZodObject<{
151
- id: import("convex-helpers/server/zod4").Zid<string>;
152
- }, z.core.$strict>>;
154
+ result: k.infer<KObject<{
155
+ id: KId<string>;
156
+ }>>;
153
157
  }, context: Context) => {
154
158
  operation: `${string}.create`;
155
159
  actorId: string;
156
160
  aggregate: {
157
161
  type: string;
158
- id: string & {
159
- __tableName: string;
160
- };
162
+ id: import("convex/values").GenericId<string>;
161
163
  };
162
164
  };
163
165
  }> & NamedOperation<`${string}.update`, {
164
- command: z.ZodObject<{
165
- id: import("convex-helpers/server/zod4").Zid<string>;
166
- data: z.ZodObject<{
167
- [x: string]: z.ZodOptional<z.ZodType<Value | undefined, unknown, z.core.$ZodTypeInternals<Value | undefined, unknown>>>;
168
- }, z.core.$strict>;
169
- }, z.core.$strict>;
170
- result: z.ZodObject<{
171
- ok: z.ZodLiteral<true>;
172
- }, z.core.$strict>;
166
+ command: KObject<{
167
+ id: KId<string>;
168
+ data: KObject<{
169
+ readonly [x: string]: KOptional<KType>;
170
+ }>;
171
+ }>;
172
+ result: KObject<{
173
+ ok: KLiteral<true>;
174
+ }>;
173
175
  classification: string;
174
176
  aggregates: string[];
175
177
  middleware: readonly AnyCommandMiddleware[] | undefined;
176
178
  guard: ((context: Context, command: never) => MaybePromise<void>) | undefined;
177
179
  audit: (resolution: {
178
- command: z.output<z.ZodObject<{
179
- id: import("convex-helpers/server/zod4").Zid<string>;
180
- data: z.ZodObject<{
181
- [x: string]: z.ZodOptional<z.ZodType<Value | undefined, unknown, z.core.$ZodTypeInternals<Value | undefined, unknown>>>;
182
- }, z.core.$strict>;
183
- }, z.core.$strict>>;
180
+ command: k.infer<KObject<{
181
+ id: KId<string>;
182
+ data: KObject<{
183
+ readonly [x: string]: KOptional<KType>;
184
+ }>;
185
+ }>>;
184
186
  }, context: Context) => {
185
187
  operation: `${string}.update`;
186
188
  actorId: string;
187
189
  aggregate: {
188
190
  type: string;
189
- id: string & {
190
- __tableName: string;
191
- };
191
+ id: import("convex/values").GenericId<string>;
192
192
  };
193
193
  };
194
194
  }> & NamedOperation<`${string}.archive`, {
195
- command: z.ZodObject<{
196
- id: import("convex-helpers/server/zod4").Zid<string>;
197
- }, z.core.$strict>;
198
- result: z.ZodObject<{
199
- ok: z.ZodLiteral<true>;
200
- }, z.core.$strict>;
195
+ command: KObject<{
196
+ id: KId<string>;
197
+ }>;
198
+ result: KObject<{
199
+ ok: KLiteral<true>;
200
+ }>;
201
201
  classification: string;
202
202
  aggregates: string[];
203
203
  middleware: readonly AnyCommandMiddleware[] | undefined;
204
204
  guard: ((context: Context, command: never) => MaybePromise<void>) | undefined;
205
205
  audit: (resolution: {
206
- command: z.output<z.ZodObject<{
207
- id: import("convex-helpers/server/zod4").Zid<string>;
208
- }, z.core.$strict>>;
206
+ command: k.infer<KObject<{
207
+ id: KId<string>;
208
+ }>>;
209
209
  }, context: Context) => {
210
210
  operation: `${string}.archive`;
211
211
  actorId: string;
212
212
  aggregate: {
213
213
  type: string;
214
- id: string & {
215
- __tableName: string;
216
- };
214
+ id: import("convex/values").GenericId<string>;
217
215
  };
218
216
  };
219
217
  }>;
220
218
  executeCreate: (context: Context, command: SchemaInput<Table["commandInput"]>) => Promise<{
221
- id: string & {
222
- __tableName: string;
223
- };
219
+ id: import("convex/values").GenericId<string>;
224
220
  }>;
225
221
  executeUpdate: (context: Context, command: {
226
- id: string;
227
222
  data: {
228
- [x: string]: unknown;
223
+ [x: string]: any;
229
224
  };
225
+ id: import("convex/values").GenericId<string>;
230
226
  }) => Promise<{
231
227
  ok: true;
232
228
  }>;
233
229
  executeArchive: (context: Context, command: {
234
- id: string;
230
+ id: import("convex/values").GenericId<string>;
235
231
  }) => Promise<{
236
232
  ok: true;
237
233
  }>;
238
234
  };
239
235
  type NamedOperation<Name extends string, Definition extends AuditedOperation> = { [Key in Name]: Definition; };
240
- //#endregion
236
+ export {};
241
237
  //# sourceMappingURL=crud.d.mts.map
package/dist/crud.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{defaultErrors as e}from"./errors.mjs";import{zid as t}from"convex-helpers/server/zod4";import{z as n}from"zod";function r(r){let a=r.errors??e,o=r.table.tableName,s=r.classification??`business`;if(`tenant`in r.table.storage.shape&&!r.enrich)return a.throw({code:`CRUD_ENRICH_REQUIRED`,message:`Table "${o}" is a tenantTable: createCrudCommands requires an enrich callback that stamps ctx.tenant`});let c=r.table.commandInput,l=t(o),u=n.object({id:l}).strict(),d=n.object({ok:n.literal(!0)}).strict(),f=n.object({id:l,data:c.partial().strict()}).strict(),p=n.object({id:l}).strict(),m=`${o}.create`,h=`${o}.update`,g=`${o}.archive`,_=Object.assign({},i(m,{command:c,result:u,classification:s,aggregates:[r.aggregateType],middleware:r.middleware,guard:r.guards?.create,audit:(e,t)=>({operation:m,actorId:r.actor(t),aggregate:{type:r.aggregateType,id:e.result.id}})}),i(h,{command:f,result:d,classification:s,aggregates:[r.aggregateType],middleware:r.middleware,guard:r.guards?.update,audit:(e,t)=>({operation:h,actorId:r.actor(t),aggregate:{type:r.aggregateType,id:e.command.id}})}),i(g,{command:p,result:d,classification:s,aggregates:[r.aggregateType],middleware:r.middleware,guard:r.guards?.archive,audit:(e,t)=>({operation:g,actorId:r.actor(t),aggregate:{type:r.aggregateType,id:e.command.id}})})),v=new r.Command(_);return{commands:v,operations:_,executeCreate:v.exec({operation:m,handler:async(e,t)=>{let n=r.enrich?await r.enrich(e,t):{},i={};for(let[e,r]of Object.entries({...t,...n}))r!==void 0&&(i[e]=r);return{id:await e.db.insert(o,i)}}}),executeUpdate:v.exec({operation:h,handler:async(e,t)=>(await e.db.patch(t.id,t.data),{ok:!0})}),executeArchive:v.exec({operation:g,handler:async(e,t)=>(await e.db.patch(t.id,{archivedAt:Date.now()}),{ok:!0})})}}function i(e,t){return{[e]:t}}export{r as createCrudCommands};
1
+ import{defaultErrors as e}from"./errors.mjs";import{k as t}from"./k/index.mjs";function n(n){let a=n.errors??e,o=n.table.tableName,s=n.classification??`business`;if(`tenant`in n.table.storage.shape&&!n.enrich)return a.throw({code:`CRUD_ENRICH_REQUIRED`,message:`Table "${o}" is a tenantTable: createCrudCommands requires an enrich callback that stamps ctx.tenant`});let c=n.table.commandInput,l=t.id(o),u=t.object({id:l}),d=t.object({ok:t.literal(!0)}),f=t.object({id:l,data:r(c).partial()}),p=t.object({id:l}),m=`${o}.create`,h=`${o}.update`,g=`${o}.archive`,_=Object.assign({},i(m,{command:c,result:u,classification:s,aggregates:[n.aggregateType],middleware:n.middleware,guard:n.guards?.create,audit:(e,t)=>({operation:m,actorId:n.actor(t),aggregate:{type:n.aggregateType,id:e.result.id}})}),i(h,{command:f,result:d,classification:s,aggregates:[n.aggregateType],middleware:n.middleware,guard:n.guards?.update,audit:(e,t)=>({operation:h,actorId:n.actor(t),aggregate:{type:n.aggregateType,id:e.command.id}})}),i(g,{command:p,result:d,classification:s,aggregates:[n.aggregateType],middleware:n.middleware,guard:n.guards?.archive,audit:(e,t)=>({operation:g,actorId:n.actor(t),aggregate:{type:n.aggregateType,id:e.command.id}})})),v=new n.Command(_);return{commands:v,operations:_,executeCreate:v.exec({operation:m,handler:async(e,t)=>{let r=n.enrich?await n.enrich(e,t):{},i=t,a=r,s={};for(let[e,t]of Object.entries({...i,...a}))t!==void 0&&(s[e]=t);return{id:await e.db.insert(o,s)}}}),executeUpdate:v.exec({operation:h,handler:async(e,t)=>(await e.db.patch(t.id,t.data),{ok:!0})}),executeArchive:v.exec({operation:g,handler:async(e,t)=>(await e.db.patch(t.id,{archivedAt:Date.now()}),{ok:!0})})}}function r(e){return e}function i(e,t){return{[e]:t}}export{n as createCrudCommands};
2
2
  //# sourceMappingURL=crud.mjs.map
package/dist/crud.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"crud.mjs","names":["createCrudCommands","errors","config","defaultErrors","name","classification","commandSchema","id","zid","createResult","z","okResult","updateInput","archiveInput","createName","updateName","archiveName","operations","namedOperation","context","resolution","commands","enrichment","command","values","field","value","definition"],"sources":["../src/crud.ts"],"sourcesContent":["import { zid } from 'convex-helpers/server/zod4'\nimport { z } from 'zod'\nimport type { Value } from 'convex/values'\nimport type { GenericDataModel, GenericMutationCtx } from 'convex/server'\nimport type {\n\tAnyCommandMiddleware,\n\tApplicationCommand,\n\tAuditedOperation,\n\tCommandConstructor,\n\tSchemaOutput,\n} from './components/foundation/client'\nimport { defaultErrors, type ErrorFactory } from './errors'\n\n/**\n * The zodTable surface the factory consumes — structural, so any zodTable /\n * tenantTable return satisfies it.\n */\ntype CrudTable = {\n\ttableName: string\n\tcommandInput: z.ZodObject<Record<string, z.ZodType<Value | undefined>>>\n\tstorage: z.ZodObject<Record<string, z.ZodType<Value | undefined>>>\n}\n\ntype CrudContext = { db: Pick<GenericMutationCtx<GenericDataModel>['db'], 'insert' | 'patch'> }\n\ntype MaybePromise<Value> = Value | Promise<Value>\n\nexport type CrudConfig<Context extends CrudContext, Table extends CrudTable = CrudTable> = {\n\t/** The Foundation-bound Command class (destructured from the facade). */\n\tCommand: CommandConstructor\n\ttable: Table\n\t/** Audit aggregate type; enforced by the aggregates allowlist. */\n\taggregateType: string\n\t/** Observability/audit classification. Default 'business'. */\n\tclassification?: string\n\t/** Derives the audited actor id from the ctx (usually ctx.actor.userId). */\n\tactor: (context: Context) => string\n\t/**\n\t * Stamps server-owned fields onto creates (tenant, denormalized ids...).\n\t * REQUIRED when the table is a tenantTable — forgetting it would insert\n\t * untenanted rows; the factory fails fast at construction instead.\n\t */\n\tenrich?: (\n\t\tcontext: Context,\n\t\tcommand: SchemaOutput<Table['commandInput']>,\n\t) => MaybePromise<Partial<z.input<Table['storage']>>>\n\t/** Per-operation preconditions; run before the handlers. */\n\tguards?: {\n\t\tcreate?: (context: Context, command: never) => MaybePromise<void>\n\t\tupdate?: (context: Context, command: never) => MaybePromise<void>\n\t\tarchive?: (context: Context, command: never) => MaybePromise<void>\n\t}\n\t/** Per-operation middleware applied to all three generated operations. */\n\tmiddleware?: readonly AnyCommandMiddleware[]\n\terrors?: ErrorFactory\n}\n\n/**\n * Generates the standard create/update/archive operations from one zodTable\n * declaration, fully inside the audited command pipeline: strict command\n * inputs from `commandFields`, mandatory audit with the declared aggregate\n * type, soft delete only (archive sets `archivedAt` — no hard-delete\n * operation is generated, per kit doctrine).\n *\n * convex-helpers ships a same-named `crud` helper; it was deliberately not\n * used — it bypasses the command pipeline (no audits, no guards, and hard\n * deletes). See docs/crud.md.\n */\nexport type CrudCommands<\n\tContext extends CrudContext,\n\tTable extends CrudTable = CrudTable,\n> = ReturnType<typeof createCrudCommands<Context, Table>>\n\nexport function createCrudCommands<\n\tContext extends CrudContext,\n\tTable extends CrudTable = CrudTable,\n>(config: CrudConfig<Context, Table>) {\n\tconst errors = config.errors ?? defaultErrors\n\tconst name = config.table.tableName\n\tconst classification = config.classification ?? 'business'\n\tconst isTenantTable = 'tenant' in config.table.storage.shape\n\tif (isTenantTable && !config.enrich) {\n\t\treturn errors.throw({\n\t\t\tcode: 'CRUD_ENRICH_REQUIRED',\n\t\t\tmessage: `Table \"${name}\" is a tenantTable: createCrudCommands requires an enrich callback that stamps ctx.tenant`,\n\t\t})\n\t}\n\n\tconst commandSchema: Table['commandInput'] = config.table.commandInput\n\tconst id = zid(name)\n\tconst createResult = z.object({ id }).strict()\n\tconst okResult = z.object({ ok: z.literal(true) }).strict()\n\tconst updateInput = z.object({ id, data: commandSchema.partial().strict() }).strict()\n\tconst archiveInput = z.object({ id }).strict()\n\n\tconst createName = `${name}.create` as const\n\tconst updateName = `${name}.update` as const\n\tconst archiveName = `${name}.archive` as const\n\tconst operations = Object.assign(\n\t\t{},\n\t\tnamedOperation(createName, {\n\t\t\tcommand: commandSchema,\n\t\t\tresult: createResult,\n\t\t\tclassification,\n\t\t\taggregates: [config.aggregateType],\n\t\t\tmiddleware: config.middleware,\n\t\t\tguard: config.guards?.create,\n\t\t\taudit: (resolution: { result: z.output<typeof createResult> }, context: Context) => ({\n\t\t\t\toperation: createName,\n\t\t\t\tactorId: config.actor(context),\n\t\t\t\taggregate: { type: config.aggregateType, id: resolution.result.id },\n\t\t\t}),\n\t\t}),\n\t\tnamedOperation(updateName, {\n\t\t\tcommand: updateInput,\n\t\t\tresult: okResult,\n\t\t\tclassification,\n\t\t\taggregates: [config.aggregateType],\n\t\t\tmiddleware: config.middleware,\n\t\t\tguard: config.guards?.update,\n\t\t\taudit: (resolution: { command: z.output<typeof updateInput> }, context: Context) => ({\n\t\t\t\toperation: updateName,\n\t\t\t\tactorId: config.actor(context),\n\t\t\t\taggregate: { type: config.aggregateType, id: resolution.command.id },\n\t\t\t}),\n\t\t}),\n\t\tnamedOperation(archiveName, {\n\t\t\tcommand: archiveInput,\n\t\t\tresult: okResult,\n\t\t\tclassification,\n\t\t\taggregates: [config.aggregateType],\n\t\t\tmiddleware: config.middleware,\n\t\t\tguard: config.guards?.archive,\n\t\t\taudit: (resolution: { command: z.output<typeof archiveInput> }, context: Context) => ({\n\t\t\t\toperation: archiveName,\n\t\t\t\tactorId: config.actor(context),\n\t\t\t\taggregate: { type: config.aggregateType, id: resolution.command.id },\n\t\t\t}),\n\t\t}),\n\t)\n\tconst commands: ApplicationCommand<Context, typeof operations> = new config.Command<\n\t\tContext,\n\t\ttypeof operations\n\t>(operations)\n\tconst executeCreate = commands.exec({\n\t\toperation: createName,\n\t\thandler: async (context, command) => {\n\t\t\tconst enrichment = config.enrich ? await config.enrich(context, command) : {}\n\t\t\tconst values: Record<string, Value> = {}\n\t\t\tfor (const [field, value] of Object.entries({ ...command, ...enrichment })) {\n\t\t\t\tif (value !== undefined) values[field] = value\n\t\t\t}\n\t\t\tconst inserted = await context.db.insert(name, values)\n\t\t\treturn { id: inserted }\n\t\t},\n\t})\n\tconst executeUpdate = commands.exec({\n\t\toperation: updateName,\n\t\thandler: async (context, command) => {\n\t\t\tawait context.db.patch(command.id, command.data)\n\t\t\treturn { ok: true }\n\t\t},\n\t})\n\tconst executeArchive = commands.exec({\n\t\toperation: archiveName,\n\t\thandler: async (context, command) => {\n\t\t\tawait context.db.patch(command.id, { archivedAt: Date.now() })\n\t\t\treturn { ok: true }\n\t\t},\n\t})\n\n\treturn {\n\t\tcommands,\n\t\toperations,\n\t\texecuteCreate,\n\t\texecuteUpdate,\n\t\texecuteArchive,\n\t}\n}\n\nfunction namedOperation<Name extends string, Definition extends AuditedOperation>(\n\tname: Name,\n\tdefinition: Definition,\n) {\n\t// SAFETY: this object contains exactly the computed name and its corresponding definition.\n\treturn { [name]: definition } as NamedOperation<Name, Definition>\n}\n\ntype NamedOperation<Name extends string, Definition extends AuditedOperation> = {\n\t[Key in Name]: Definition\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"crud.mjs","names":["createCrudCommands","errors","config","defaultErrors","name","classification","commandSchema","id","k","createResult","okResult","updateInput","commandObject","archiveInput","createName","updateName","archiveName","operations","namedOperation","context","resolution","commands","enrichment","command","row","stamped","values","field","value","schema","definition"],"sources":["../src/crud.ts"],"sourcesContent":["import type { Value } from 'convex/values'\nimport type { GenericDataModel, GenericMutationCtx } from 'convex/server'\nimport type {\n\tAnyCommandMiddleware,\n\tApplicationCommand,\n\tAuditedOperation,\n\tCommandConstructor,\n\tParseable,\n\tSchemaOutput,\n} from './components/foundation/client'\nimport { defaultErrors, type ErrorFactory } from './errors'\nimport { k, type KFields, type KObject, type KType } from './k'\n\n/**\n * The table surface the factory consumes — structural, so any kTable / createTable / tenantTable\n * boundary satisfies it.\n */\ntype CrudTable = {\n\treadonly tableName: string\n\treadonly commandInput: KType & Parseable<CommandRow>\n\t// oxlint-disable-next-line anti-slop/no-shape-in-symbol-names -- `.shape` is the k object field map the table boundary exposes.\n\treadonly storage: KType & { readonly shape: KFields }\n}\n\n/** A parsed command: the commandFields' values. */\ntype CommandRow = { readonly [field: string]: Value | undefined }\n\ntype CrudContext = { db: Pick<GenericMutationCtx<GenericDataModel>['db'], 'insert' | 'patch'> }\n\ntype MaybePromise<Value> = Value | Promise<Value>\n\nexport type CrudConfig<Context extends CrudContext, Table extends CrudTable = CrudTable> = {\n\t/** The Foundation-bound Command class (destructured from the facade). */\n\tCommand: CommandConstructor\n\ttable: Table\n\t/** Audit aggregate type; enforced by the aggregates allowlist. */\n\taggregateType: string\n\t/** Observability/audit classification. Default 'business'. */\n\tclassification?: string\n\t/** Derives the audited actor id from the ctx (usually ctx.actor.userId). */\n\tactor: (context: Context) => string\n\t/**\n\t * Stamps server-owned fields onto creates (tenant, denormalized ids...).\n\t * REQUIRED when the table is a tenantTable — forgetting it would insert\n\t * untenanted rows; the factory fails fast at construction instead.\n\t */\n\tenrich?: (\n\t\tcontext: Context,\n\t\tcommand: SchemaOutput<Table['commandInput']>,\n\t) => MaybePromise<Partial<k.input<Table['storage']>>>\n\t/** Per-operation preconditions; run before the handlers. */\n\tguards?: {\n\t\tcreate?: (context: Context, command: never) => MaybePromise<void>\n\t\tupdate?: (context: Context, command: never) => MaybePromise<void>\n\t\tarchive?: (context: Context, command: never) => MaybePromise<void>\n\t}\n\t/** Per-operation middleware applied to all three generated operations. */\n\tmiddleware?: readonly AnyCommandMiddleware[]\n\terrors?: ErrorFactory\n}\n\n/**\n * Generates the standard create/update/archive operations from one kTable\n * declaration, fully inside the audited command pipeline: strict command\n * inputs from `commandFields`, mandatory audit with the declared aggregate\n * type, soft delete only (archive sets `archivedAt` — no hard-delete\n * operation is generated, per kit doctrine).\n *\n * convex-helpers ships a same-named `crud` helper; it was deliberately not\n * used — it bypasses the command pipeline (no audits, no guards, and hard\n * deletes). See docs/crud.md.\n */\nexport type CrudCommands<\n\tContext extends CrudContext,\n\tTable extends CrudTable = CrudTable,\n> = ReturnType<typeof createCrudCommands<Context, Table>>\n\nexport function createCrudCommands<\n\tContext extends CrudContext,\n\tTable extends CrudTable = CrudTable,\n>(config: CrudConfig<Context, Table>) {\n\tconst errors = config.errors ?? defaultErrors\n\tconst name = config.table.tableName\n\tconst classification = config.classification ?? 'business'\n\tconst isTenantTable = 'tenant' in config.table.storage.shape\n\tif (isTenantTable && !config.enrich) {\n\t\treturn errors.throw({\n\t\t\tcode: 'CRUD_ENRICH_REQUIRED',\n\t\t\tmessage: `Table \"${name}\" is a tenantTable: createCrudCommands requires an enrich callback that stamps ctx.tenant`,\n\t\t})\n\t}\n\n\tconst commandSchema: Table['commandInput'] = config.table.commandInput\n\t// k objects are strict: an update naming a field outside commandFields fails with VALIDATION.\n\tconst id = k.id(name)\n\tconst createResult = k.object({ id })\n\tconst okResult = k.object({ ok: k.literal(true) })\n\tconst updateInput = k.object({ id, data: commandObject(commandSchema).partial() })\n\tconst archiveInput = k.object({ id })\n\n\tconst createName = `${name}.create` as const\n\tconst updateName = `${name}.update` as const\n\tconst archiveName = `${name}.archive` as const\n\tconst operations = Object.assign(\n\t\t{},\n\t\tnamedOperation(createName, {\n\t\t\tcommand: commandSchema,\n\t\t\tresult: createResult,\n\t\t\tclassification,\n\t\t\taggregates: [config.aggregateType],\n\t\t\tmiddleware: config.middleware,\n\t\t\tguard: config.guards?.create,\n\t\t\taudit: (resolution: { result: k.infer<typeof createResult> }, context: Context) => ({\n\t\t\t\toperation: createName,\n\t\t\t\tactorId: config.actor(context),\n\t\t\t\taggregate: { type: config.aggregateType, id: resolution.result.id },\n\t\t\t}),\n\t\t}),\n\t\tnamedOperation(updateName, {\n\t\t\tcommand: updateInput,\n\t\t\tresult: okResult,\n\t\t\tclassification,\n\t\t\taggregates: [config.aggregateType],\n\t\t\tmiddleware: config.middleware,\n\t\t\tguard: config.guards?.update,\n\t\t\taudit: (resolution: { command: k.infer<typeof updateInput> }, context: Context) => ({\n\t\t\t\toperation: updateName,\n\t\t\t\tactorId: config.actor(context),\n\t\t\t\taggregate: { type: config.aggregateType, id: resolution.command.id },\n\t\t\t}),\n\t\t}),\n\t\tnamedOperation(archiveName, {\n\t\t\tcommand: archiveInput,\n\t\t\tresult: okResult,\n\t\t\tclassification,\n\t\t\taggregates: [config.aggregateType],\n\t\t\tmiddleware: config.middleware,\n\t\t\tguard: config.guards?.archive,\n\t\t\taudit: (resolution: { command: k.infer<typeof archiveInput> }, context: Context) => ({\n\t\t\t\toperation: archiveName,\n\t\t\t\tactorId: config.actor(context),\n\t\t\t\taggregate: { type: config.aggregateType, id: resolution.command.id },\n\t\t\t}),\n\t\t}),\n\t)\n\tconst commands: ApplicationCommand<Context, typeof operations> = new config.Command<\n\t\tContext,\n\t\ttypeof operations\n\t>(operations)\n\tconst executeCreate = commands.exec({\n\t\toperation: createName,\n\t\thandler: async (context, command) => {\n\t\t\tconst enrichment = config.enrich ? await config.enrich(context, command) : {}\n\t\t\tconst row: CommandRow = command\n\t\t\tconst stamped: CommandRow = enrichment\n\t\t\tconst values: Record<string, Value> = {}\n\t\t\tfor (const [field, value] of Object.entries({ ...row, ...stamped })) {\n\t\t\t\tif (value !== undefined) values[field] = value\n\t\t\t}\n\t\t\tconst inserted = await context.db.insert(name, values)\n\t\t\treturn { id: inserted }\n\t\t},\n\t})\n\tconst executeUpdate = commands.exec({\n\t\toperation: updateName,\n\t\thandler: async (context, command) => {\n\t\t\tawait context.db.patch(command.id, command.data)\n\t\t\treturn { ok: true }\n\t\t},\n\t})\n\tconst executeArchive = commands.exec({\n\t\toperation: archiveName,\n\t\thandler: async (context, command) => {\n\t\t\tawait context.db.patch(command.id, { archivedAt: Date.now() })\n\t\t\treturn { ok: true }\n\t\t},\n\t})\n\n\treturn {\n\t\tcommands,\n\t\toperations,\n\t\texecuteCreate,\n\t\texecuteUpdate,\n\t\texecuteArchive,\n\t}\n}\n\n/** The command input as an object schema, for its `partial()` patch shape. */\nfunction commandObject(schema: KType): KObject<KFields> {\n\t// SAFETY: every table boundary's commandInput is a k.object (kTable picks the commandFields into one).\n\treturn schema as KObject<KFields>\n}\n\nfunction namedOperation<Name extends string, Definition extends AuditedOperation>(\n\tname: Name,\n\tdefinition: Definition,\n) {\n\t// SAFETY: this object contains exactly the computed name and its corresponding definition.\n\treturn { [name]: definition } as NamedOperation<Name, Definition>\n}\n\ntype NamedOperation<Name extends string, Definition extends AuditedOperation> = {\n\t[Key in Name]: Definition\n}\n"],"mappings":"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"}
package/dist/effect.d.mts CHANGED
@@ -2,7 +2,7 @@ import { OperationExecutor, OperationPublicResult, OperationTool, OperationToolC
2
2
  import { ContractDecoderError, ContractDecoderRequirements, ContractValidationError, EffectDecoder, decodeEffectContract, effectContract, effectSchema, effectStandardSchema } from "./modules/effect/schema.mjs";
3
3
  import { NestedAuditMode, RequestScope } from "./modules/effect/scope.mjs";
4
4
  import { CallbackError, CallbackRequirements, EffectMiddlewareInput, EffectOperationArgument, EffectOperationError, EffectOperationHandlerResult, EffectOperationInput, EffectOperationRequirements, EffectOperationResult, EffectPreparation, EffectValue, effectOperationFactory } from "./modules/effect/operation.mjs";
5
- import { EffectZodApiBuilder, effectZodApiBuilder } from "./modules/effect/api-zod.mjs";
5
+ import { EffectApiBuilder, effectApiBuilder } from "./modules/effect/api.mjs";
6
6
  import { EffectAuthFunctions, createEffectAuthFunctions } from "./modules/effect/auth.mjs";
7
7
  import { FailureAuditEntry, FailureAuditOptions } from "./modules/effect/failure-audit.mjs";
8
8
  import { EffectErrors, effectErrors } from "./modules/effect/failures.mjs";
@@ -10,8 +10,7 @@ import { ActionAuditWriterError, EffectActionDependencies, EffectActionRegistry
10
10
  import { EffectFoundationOptions, createEffectFoundation } from "./modules/effect/foundation.mjs";
11
11
  import { EffectIdempotencyPreparation, effectTransactionalIdempotency } from "./modules/effect/idempotency.mjs";
12
12
  import { EffectCrudConfig, EffectCrudContext, EffectCrudPage, EffectCrudPagination, EffectCrudRepository, EffectCrudTable, createEffectCrud } from "./modules/effect/crud.mjs";
13
- import { EffectApiBuilder, effectApiBuilder } from "./modules/effect/api.mjs";
14
13
  import { projectErrorCause } from "./modules/effect/errors.mjs";
15
14
  import { EffectReceiptProtectedWorkflowMutation, effectReceiptWorkflowMutation, effectTerminalWorkflowAttempt, effectWorkflowAttempt, effectWorkflowStatusBindings } from "./modules/effect/workflow.mjs";
16
15
  import "./modules/effect/client.mjs";
17
- export { ActionAuditWriterError, type CallbackError, type CallbackRequirements, type ContractDecoderError, type ContractDecoderRequirements, ContractValidationError, type EffectActionDependencies, type EffectActionRegistry, type EffectApiBuilder, type EffectAuthFunctions, type EffectCrudConfig, type EffectCrudContext, type EffectCrudPage, type EffectCrudPagination, type EffectCrudRepository, type EffectCrudTable, type EffectDecoder, type EffectErrors, type EffectFoundationOptions, type EffectIdempotencyPreparation, type EffectMiddlewareInput, type EffectOperationArgument, type EffectOperationError, type EffectOperationHandlerResult, type EffectOperationInput, type EffectOperationRequirements, type EffectOperationResult, type EffectPreparation, type EffectReceiptProtectedWorkflowMutation, type EffectValue, type EffectZodApiBuilder, type FailureAuditEntry, type FailureAuditOptions, type NestedAuditMode, type OperationExecutor, type OperationPublicResult, type OperationTool, type OperationToolConverter, type OperationToolDefinition, type OperationToolJsonSchema, type OperationToolOutcome, type RequestScope, type SelectedOperation, bindOperationExecutor, createEffectAuthFunctions, createEffectCrud, createEffectFoundation, createOperationTools, decodeEffectContract, effectApiBuilder, effectContract, effectErrors, effectOperationFactory, effectReceiptWorkflowMutation, effectSchema, effectStandardSchema, effectTerminalWorkflowAttempt, effectTransactionalIdempotency, effectWorkflowAttempt, effectWorkflowStatusBindings, effectZodApiBuilder, operationToolDialect, projectErrorCause, selectOperation };
16
+ export { ActionAuditWriterError, type CallbackError, type CallbackRequirements, type ContractDecoderError, type ContractDecoderRequirements, ContractValidationError, type EffectActionDependencies, type EffectActionRegistry, type EffectApiBuilder, type EffectAuthFunctions, type EffectCrudConfig, type EffectCrudContext, type EffectCrudPage, type EffectCrudPagination, type EffectCrudRepository, type EffectCrudTable, type EffectDecoder, type EffectErrors, type EffectFoundationOptions, type EffectIdempotencyPreparation, type EffectMiddlewareInput, type EffectOperationArgument, type EffectOperationError, type EffectOperationHandlerResult, type EffectOperationInput, type EffectOperationRequirements, type EffectOperationResult, type EffectPreparation, type EffectReceiptProtectedWorkflowMutation, type EffectValue, type FailureAuditEntry, type FailureAuditOptions, type NestedAuditMode, type OperationExecutor, type OperationPublicResult, type OperationTool, type OperationToolConverter, type OperationToolDefinition, type OperationToolJsonSchema, type OperationToolOutcome, type RequestScope, type SelectedOperation, bindOperationExecutor, createEffectAuthFunctions, createEffectCrud, createEffectFoundation, createOperationTools, decodeEffectContract, effectApiBuilder, effectContract, effectErrors, effectOperationFactory, effectReceiptWorkflowMutation, effectSchema, effectStandardSchema, effectTerminalWorkflowAttempt, effectTransactionalIdempotency, effectWorkflowAttempt, effectWorkflowStatusBindings, operationToolDialect, projectErrorCause, selectOperation };
package/dist/effect.mjs CHANGED
@@ -1 +1 @@
1
- import{bindOperationExecutor as e,createOperationTools as t,operationToolDialect as n,selectOperation as r}from"./modules/contracts/exposure.mjs";import{projectErrorCause as i}from"./modules/effect/errors.mjs";import{effectZodApiBuilder as a}from"./modules/effect/api-zod.mjs";import{createEffectAuthFunctions as o}from"./modules/effect/auth.mjs";import{effectOperationFactory as s}from"./modules/effect/operation.mjs";import{ContractValidationError as c,decodeEffectContract as l,effectContract as u,effectSchema as d,effectStandardSchema as f}from"./modules/effect/schema.mjs";import{effectErrors as p}from"./modules/effect/failures.mjs";import{ActionAuditWriterError as m}from"./modules/effect/action.mjs";import{createEffectFoundation as h}from"./modules/effect/foundation.mjs";import{effectTransactionalIdempotency as g}from"./modules/effect/idempotency.mjs";import{createEffectCrud as _}from"./modules/effect/crud.mjs";import{effectApiBuilder as v}from"./modules/effect/api.mjs";import{effectReceiptWorkflowMutation as y,effectTerminalWorkflowAttempt as b,effectWorkflowAttempt as x,effectWorkflowStatusBindings as S}from"./modules/effect/workflow.mjs";export{m as ActionAuditWriterError,c as ContractValidationError,e as bindOperationExecutor,o as createEffectAuthFunctions,_ as createEffectCrud,h as createEffectFoundation,t as createOperationTools,l as decodeEffectContract,v as effectApiBuilder,u as effectContract,p as effectErrors,s as effectOperationFactory,y as effectReceiptWorkflowMutation,d as effectSchema,f as effectStandardSchema,b as effectTerminalWorkflowAttempt,g as effectTransactionalIdempotency,x as effectWorkflowAttempt,S as effectWorkflowStatusBindings,a as effectZodApiBuilder,n as operationToolDialect,i as projectErrorCause,r as selectOperation};
1
+ import{createEffectAuthFunctions as e}from"./modules/effect/auth.mjs";import{bindOperationExecutor as t,createOperationTools as n,operationToolDialect as r,selectOperation as i}from"./modules/contracts/exposure.mjs";import{effectOperationFactory as a}from"./modules/effect/operation.mjs";import{createEffectFoundation as o}from"./modules/effect/foundation.mjs";import{ActionAuditWriterError as s}from"./modules/effect/action.mjs";import{effectErrors as c}from"./modules/effect/failures.mjs";import{effectTransactionalIdempotency as l}from"./modules/effect/idempotency.mjs";import{createEffectCrud as u}from"./modules/effect/crud.mjs";import{effectApiBuilder as d}from"./modules/effect/api.mjs";import{projectErrorCause as f}from"./modules/effect/errors.mjs";import{ContractValidationError as p,decodeEffectContract as m,effectContract as h,effectSchema as g,effectStandardSchema as _}from"./modules/effect/schema.mjs";import{effectReceiptWorkflowMutation as v,effectTerminalWorkflowAttempt as y,effectWorkflowAttempt as b,effectWorkflowStatusBindings as x}from"./modules/effect/workflow.mjs";export{s as ActionAuditWriterError,p as ContractValidationError,t as bindOperationExecutor,e as createEffectAuthFunctions,u as createEffectCrud,o as createEffectFoundation,n as createOperationTools,m as decodeEffectContract,d as effectApiBuilder,h as effectContract,c as effectErrors,a as effectOperationFactory,v as effectReceiptWorkflowMutation,g as effectSchema,_ as effectStandardSchema,y as effectTerminalWorkflowAttempt,l as effectTransactionalIdempotency,b as effectWorkflowAttempt,x as effectWorkflowStatusBindings,r as operationToolDialect,f as projectErrorCause,i as selectOperation};
package/dist/errors.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { DeclaredError, DeclaredFailure, DecodedFailure, ErrorContract, ErrorDefinitions, ErrorDetailParser, UnknownFailure, combineErrorContracts, decodeFailure, defineErrorContract, queryErrors } from "./modules/contracts/errors.mjs";
1
+ import { ARGUMENT_ISSUE_LIMITS, ArgumentFailure, ArgumentFailurePolicy, ArgumentIssue, DeclaredError, DeclaredFailure, DecodedFailure, ErrorContract, ErrorDefinitions, ErrorDetailParser, UnknownFailure, argumentErrors, combineErrorContracts, decodeFailure, defineErrorContract, queryErrors, sanitizeArgumentIssues } from "./modules/contracts/errors.mjs";
2
2
  import { FailureHandlers, failureOf, isFailure, matchFailure } from "./react/failures.mjs";
3
- //#region src/errors.d.ts
4
3
  /** Structured application error carried across Convex function boundaries. */
5
4
  export declare class KitError extends Error {
6
5
  readonly code: string;
@@ -21,6 +20,5 @@ export type ErrorFactory = {
21
20
  }): never;
22
21
  };
23
22
  export declare const defaultErrors: ErrorFactory;
24
- //#endregion
25
- export { type DeclaredError, type DeclaredFailure, type DecodedFailure, type ErrorContract, type ErrorDefinitions, type ErrorDetailParser, type FailureHandlers, type UnknownFailure, combineErrorContracts, decodeFailure, defineErrorContract, failureOf, isFailure, matchFailure, queryErrors };
23
+ export { ARGUMENT_ISSUE_LIMITS, type ArgumentFailure, type ArgumentFailurePolicy, type ArgumentIssue, type DeclaredError, type DeclaredFailure, type DecodedFailure, type ErrorContract, type ErrorDefinitions, type ErrorDetailParser, type FailureHandlers, type UnknownFailure, argumentErrors, combineErrorContracts, decodeFailure, defineErrorContract, failureOf, isFailure, matchFailure, queryErrors, sanitizeArgumentIssues };
26
24
  //# sourceMappingURL=errors.d.mts.map
package/dist/errors.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{combineErrorContracts as e,decodeFailure as t,defineErrorContract as n,queryErrors as r}from"./modules/contracts/errors.mjs";import{failureOf as i,isFailure as a,matchFailure as o}from"./react/failures.mjs";var s=class extends Error{code;constructor(e){super(e.message??e.code),this.name=`KitError`,this.code=e.code}};const c={throw(e){throw new s(e)}};export{s as KitError,e as combineErrorContracts,t as decodeFailure,c as defaultErrors,n as defineErrorContract,i as failureOf,a as isFailure,o as matchFailure,r as queryErrors};
1
+ import{ARGUMENT_ISSUE_LIMITS as e,argumentErrors as t,combineErrorContracts as n,decodeFailure as r,defineErrorContract as i,queryErrors as a,sanitizeArgumentIssues as o}from"./modules/contracts/errors.mjs";import{failureOf as s,isFailure as c,matchFailure as l}from"./react/failures.mjs";var u=class extends Error{code;constructor(e){super(e.message??e.code),this.name=`KitError`,this.code=e.code}};const d={throw(e){throw new u(e)}};export{e as ARGUMENT_ISSUE_LIMITS,u as KitError,t as argumentErrors,n as combineErrorContracts,r as decodeFailure,d as defaultErrors,i as defineErrorContract,s as failureOf,c as isFailure,l as matchFailure,a as queryErrors,o as sanitizeArgumentIssues};
2
2
  //# sourceMappingURL=errors.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.mjs","names":["KitError","input","defaultErrors","combineErrorContracts","decodeFailure","defineErrorContract","failureOf","isFailure","matchFailure","queryErrors"],"sources":["../src/errors.ts"],"sourcesContent":["/** Structured application error carried across Convex function boundaries. */\nexport class KitError extends Error {\n\treadonly code: string\n\n\tconstructor(input: { code: string; message?: string }) {\n\t\tsuper(input.message ?? input.code)\n\t\tthis.name = 'KitError'\n\t\tthis.code = input.code\n\t}\n}\n\nexport {\n\tdefineErrorContract,\n\tqueryErrors,\n\tcombineErrorContracts,\n\ttype ErrorContract,\n\ttype ErrorDefinitions,\n\ttype ErrorDetailParser,\n\ttype DeclaredError,\n\ttype DeclaredFailure,\n\ttype DecodedFailure,\n\ttype UnknownFailure,\n} from './modules/contracts/errors'\n\n/**\n * Injection seam for host error policy. Hosts with their own error taxonomy\n * (e.g. an App.errors singleton) adapt it to this shape; everyone else uses\n * the default factory below.\n */\nexport type ErrorFactory = {\n\tthrow(input: { code: string; message?: string }): never\n}\n\nexport const defaultErrors: ErrorFactory = {\n\tthrow(input) {\n\t\tthrow new KitError(input)\n\t},\n}\n\n// Pure helpers do not import React or server query-engine modules.\nexport {\n\tdecodeFailure,\n\tmatchFailure,\n\tfailureOf,\n\tisFailure,\n\ttype FailureHandlers,\n} from './react/failures'\n"],"mappings":"sNACA,IAAaA,EAAb,cAA8B,KAAM,CACnC,KAEA,YAAY,EAA2C,CACtD,MAAMC,EAAM,SAAWA,EAAM,IAAI,EACjC,KAAK,KAAO,WACZ,KAAK,KAAOA,EAAM,IACnB,CACD,EAwBA,MAAaC,EAA8B,CAC1C,MAAM,EAAO,CACZ,MAAM,IAAIF,EAASC,CAAK,CACzB,CACD"}
1
+ {"version":3,"file":"errors.mjs","names":["KitError","input","defaultErrors","ARGUMENT_ISSUE_LIMITS","argumentErrors","combineErrorContracts","decodeFailure","defineErrorContract","failureOf","isFailure","matchFailure","queryErrors","sanitizeArgumentIssues"],"sources":["../src/errors.ts"],"sourcesContent":["/** Structured application error carried across Convex function boundaries. */\nexport class KitError extends Error {\n\treadonly code: string\n\n\tconstructor(input: { code: string; message?: string }) {\n\t\tsuper(input.message ?? input.code)\n\t\tthis.name = 'KitError'\n\t\tthis.code = input.code\n\t}\n}\n\nexport {\n\tdefineErrorContract,\n\tqueryErrors,\n\targumentErrors,\n\tsanitizeArgumentIssues,\n\tARGUMENT_ISSUE_LIMITS,\n\tcombineErrorContracts,\n\ttype ArgumentIssue,\n\ttype ArgumentFailure,\n\ttype ArgumentFailurePolicy,\n\ttype ErrorContract,\n\ttype ErrorDefinitions,\n\ttype ErrorDetailParser,\n\ttype DeclaredError,\n\ttype DeclaredFailure,\n\ttype DecodedFailure,\n\ttype UnknownFailure,\n} from './modules/contracts/errors'\n\n/**\n * Injection seam for host error policy. Hosts with their own error taxonomy\n * (e.g. an App.errors singleton) adapt it to this shape; everyone else uses\n * the default factory below.\n */\nexport type ErrorFactory = {\n\tthrow(input: { code: string; message?: string }): never\n}\n\nexport const defaultErrors: ErrorFactory = {\n\tthrow(input) {\n\t\tthrow new KitError(input)\n\t},\n}\n\n// Pure helpers do not import React or server query-engine modules.\nexport {\n\tdecodeFailure,\n\tmatchFailure,\n\tfailureOf,\n\tisFailure,\n\ttype FailureHandlers,\n} from './react/failures'\n"],"mappings":"A,iSACA,IAAaA,EAAb,cAA8B,KAAM,CACnC,KAEA,YAAY,EAA2C,CACtD,MAAMC,EAAM,SAAWA,EAAM,IAAI,EACjC,KAAK,KAAO,WACZ,KAAK,KAAOA,EAAM,IACnB,CACD,EA8BA,MAAaC,EAA8B,CAC1C,MAAM,EAAO,CACZ,MAAM,IAAIF,EAASC,CAAK,CACzB,CACD,E"}
@@ -1,4 +1,4 @@
1
1
  import { FilterContract, FilterDescriptor, SharedField, SharedFilters, defineFilterContract } from "./querying/shared/contract.mjs";
2
- import { FilterAst, FilterOperator, FilterScalar } from "./querying/shared/ast.mjs";
3
2
  import { evaluateFilter } from "./querying/shared/evaluate.mjs";
3
+ import { FilterAst, FilterOperator, FilterScalar } from "./querying/shared/ast.mjs";
4
4
  export { type FilterAst, type FilterContract, type FilterDescriptor, type FilterOperator, type FilterScalar, type SharedField, type SharedFilters, defineFilterContract, evaluateFilter };
package/dist/filters.mjs CHANGED
@@ -1 +1 @@
1
- import{evaluateFilter as e}from"./querying/shared/evaluate.mjs";import{defineFilterContract as t}from"./querying/shared/contract.mjs";export{t as defineFilterContract,e as evaluateFilter};
1
+ import{defineFilterContract as e}from"./querying/shared/contract.mjs";import{evaluateFilter as t}from"./querying/shared/evaluate.mjs";export{e as defineFilterContract,t as evaluateFilter};
@@ -1 +1 @@
1
- import{IdempotencyError as e,canonicalConvexBytes as t,captureIdempotencyInvocation as n,transactionalIdempotency as r}from"./modules/contracts/idempotency.mjs";export{e as IdempotencyError,t as canonicalConvexBytes,n as captureIdempotencyInvocation,r as transactionalIdempotency};
1
+ export{IdempotencyError,canonicalConvexBytes,captureIdempotencyInvocation,transactionalIdempotency}from"./modules/contracts/idempotency.mjs";
package/dist/index.d.mts CHANGED
@@ -1,17 +1,20 @@
1
- import { AgentToolHandlers, AgentToolRecord, createAgentTools } from "./agent-tools.mjs";
1
+ import { k } from "./k/index.mjs";
2
2
  import { ErrorFactory, KitError, defaultErrors } from "./errors.mjs";
3
- import { ScalarFilters, ScalarSelection, ServerFilter } from "./querying/filters.mjs";
4
- import { DtoOptions, TIMESTAMP_FIELDS, TableBoundaryOptions, createModule, createTable, jsonSafeZid, paginated, tenantTable, zodTable, zodVariantTable } from "./zod-table.mjs";
5
- import { FieldReference, RelationBuilder, RelationDeclarations, RelationEdge, RelationFilterSelection, RelationFilters, RelationRegistry, RelationRegistryIdentity, RelationRow, RelationSelection, RelationTable, RelationTableHelpers, RelationTables, ThroughReference, defineRelations } from "./relations.mjs";
3
+ import { EnginePaginationResult, KDtoOptions, KTableBoundary, KTableOptions, KVariantOptions, KVariantTableBoundary, PageCompleteness, TIMESTAMP_FIELDS, createTable, kTable, kVariantTable, paginated, tenantTable } from "./table.mjs";
6
4
  import { RLSConfig, Rules, TENANT_FIELD, assertTenantOwned, composeRules, createTenantRules, requireTenantReference } from "./tenancy.mjs";
7
5
  import { Actor, AuthBundle, AuthFunctions, AuthFunctionsConfig, DefaultRole, Include, IncludedQuery, SecurityBundle, SecurityConfig, ServiceMutation, ServicePrincipal, ServiceQuery, createAuthFunctions, createInclude, defaultRoleMap } from "./auth.mjs";
8
- import { AnyQueryMiddleware, QueryMiddleware } from "./components/foundation/modules/query/query.mjs";
9
- import { AnyCommandMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandConstructor, CommandDefaults, CommandMiddleware, Foundation, FoundationOptions, PermissionChecker } from "./components/foundation/client.mjs";
6
+ import { Namespace, NamespaceTag, createModule, memberName, namespace, namespaceIndex, namespaceName, namespacePrefix, tablesOf } from "./namespace.mjs";
7
+ import { AgentToolHandlers, AgentToolRecord, createAgentTools } from "./agent-tools.mjs";
10
8
  import { CrudConfig, createCrudCommands } from "./crud.mjs";
11
9
  import { RateLimiterLike, rateLimit } from "./middleware.mjs";
12
10
  import { WebhookBoundaryConfig, createWebhookBoundary, recordWebhookEvent, webhookEventsTable } from "./webhooks.mjs";
11
+ import { AnyQueryMiddleware, QueryMiddleware } from "./components/foundation/modules/query/query.mjs";
13
12
  import { createStateMachine } from "./state-machine.mjs";
14
13
  import { Change, Trigger, Triggers, appendOnly, createTriggers, noDelete, tenantOwnership, timestamps, triggerContext } from "./triggers.mjs";
14
+ import { AnyCommandMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandConstructor, CommandDefaults, CommandMiddleware, Foundation, FoundationOptions, PermissionChecker } from "./components/foundation/client.mjs";
15
15
  import { FoundationRegistry, FoundationRegistryOptions, createFoundation } from "./modules/foundation/foundation.mjs";
16
+ import { FieldReference, RelationBuilder, RelationDeclarations, RelationEdge, RelationFilterSelection, RelationFilters, RelationRegistry, RelationRegistryIdentity, RelationRow, RelationSelection, RelationTable, RelationTableHelpers, RelationTables, ThroughReference, defineRelations } from "./relations.mjs";
17
+ import { ScalarFilters, ScalarSelection, ServerFilter } from "./querying/filters.mjs";
16
18
  import { QueryEngineConfig, createQueryEngine } from "./querying.mjs";
17
- export { type Actor, type AgentToolHandlers, type AgentToolRecord, type AnyCommandMiddleware, type AnyQueryMiddleware, type ApplicationCommand, type AuditEntryInput, type AuditWriter, type AuditedOperation, type AuditedRegistry, type AuthBundle, type AuthFunctions, type AuthFunctionsConfig, type Change, type CommandConstructor, type CommandDefaults, type CommandMiddleware, type CrudConfig, type DefaultRole, type DtoOptions, type ErrorFactory, type FieldReference, Foundation, type FoundationOptions, type FoundationRegistry, type FoundationRegistryOptions, type Include, type IncludedQuery, KitError, type PermissionChecker, type QueryEngineConfig, type QueryMiddleware, type RLSConfig, type RateLimiterLike, type RelationBuilder, type RelationDeclarations, type RelationEdge, type RelationFilterSelection, type RelationFilters, type RelationRegistry, type RelationRegistryIdentity, type RelationRow, type RelationSelection, type RelationTable, type RelationTableHelpers, type RelationTables, type Rules, type ScalarFilters, type ScalarSelection, type SecurityBundle, type SecurityConfig, type ServerFilter, type ServiceMutation, type ServicePrincipal, type ServiceQuery, TENANT_FIELD, TIMESTAMP_FIELDS, type TableBoundaryOptions, type ThroughReference, type Trigger, Triggers, type WebhookBoundaryConfig, appendOnly, assertTenantOwned, composeRules, createAgentTools, createAuthFunctions, createCrudCommands, createFoundation, createInclude, createModule, createQueryEngine, createStateMachine, createTable, createTenantRules, createTriggers, createWebhookBoundary, defaultErrors, defaultRoleMap, defineRelations, jsonSafeZid, noDelete, paginated, rateLimit, recordWebhookEvent, requireTenantReference, tenantOwnership, tenantTable, timestamps, triggerContext, webhookEventsTable, zodTable, zodVariantTable };
19
+ import "./k.mjs";
20
+ export { type Actor, type AgentToolHandlers, type AgentToolRecord, type AnyCommandMiddleware, type AnyQueryMiddleware, type ApplicationCommand, type AuditEntryInput, type AuditWriter, type AuditedOperation, type AuditedRegistry, type AuthBundle, type AuthFunctions, type AuthFunctionsConfig, type Change, type CommandConstructor, type CommandDefaults, type CommandMiddleware, type CrudConfig, type DefaultRole, type KDtoOptions as DtoOptions, type EnginePaginationResult, type ErrorFactory, type FieldReference, Foundation, type FoundationOptions, type FoundationRegistry, type FoundationRegistryOptions, type Include, type IncludedQuery, type KDtoOptions, type KTableBoundary, type KTableOptions, type KVariantOptions, type KVariantTableBoundary, KitError, type Namespace, type NamespaceTag, type PageCompleteness, type PermissionChecker, type QueryEngineConfig, type QueryMiddleware, type RLSConfig, type RateLimiterLike, type RelationBuilder, type RelationDeclarations, type RelationEdge, type RelationFilterSelection, type RelationFilters, type RelationRegistry, type RelationRegistryIdentity, type RelationRow, type RelationSelection, type RelationTable, type RelationTableHelpers, type RelationTables, type Rules, type ScalarFilters, type ScalarSelection, type SecurityBundle, type SecurityConfig, type ServerFilter, type ServiceMutation, type ServicePrincipal, type ServiceQuery, TENANT_FIELD, TIMESTAMP_FIELDS, type KTableOptions as TableBoundaryOptions, type ThroughReference, type Trigger, Triggers, type WebhookBoundaryConfig, appendOnly, assertTenantOwned, composeRules, createAgentTools, createAuthFunctions, createCrudCommands, createFoundation, createInclude, createModule, createQueryEngine, createStateMachine, createTable, createTenantRules, createTriggers, createWebhookBoundary, defaultErrors, defaultRoleMap, defineRelations, k, kTable, kVariantTable, memberName, namespace, namespaceIndex, namespaceName, namespacePrefix, noDelete, paginated, rateLimit, recordWebhookEvent, requireTenantReference, tablesOf, tenantOwnership, tenantTable, timestamps, triggerContext, webhookEventsTable };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{createAgentTools as e}from"./agent-tools.mjs";import{KitError as t,defaultErrors as n}from"./errors.mjs";import{TENANT_FIELD as r,assertTenantOwned as i,composeRules as a,createTenantRules as o,requireTenantReference as s}from"./tenancy.mjs";import{createAuthFunctions as c,createInclude as l,defaultRoleMap as u}from"./auth.mjs";import{createCrudCommands as d}from"./crud.mjs";import{TIMESTAMP_FIELDS as f,createModule as p,createTable as m,jsonSafeZid as h,paginated as g,tenantTable as _,zodTable as v,zodVariantTable as y}from"./zod-table.mjs";import{rateLimit as b}from"./middleware.mjs";import{createWebhookBoundary as x,recordWebhookEvent as S,webhookEventsTable as C}from"./webhooks.mjs";import{createStateMachine as w}from"./state-machine.mjs";import{Triggers as T,appendOnly as E,createTriggers as D,noDelete as O,tenantOwnership as k,timestamps as A,triggerContext as j}from"./triggers.mjs";import{Foundation as M}from"./components/foundation/client.mjs";import{createFoundation as N}from"./modules/foundation/foundation.mjs";import{defineRelations as P}from"./relations.mjs";import{createQueryEngine as F}from"./querying.mjs";export{M as Foundation,t as KitError,r as TENANT_FIELD,f as TIMESTAMP_FIELDS,T as Triggers,E as appendOnly,i as assertTenantOwned,a as composeRules,e as createAgentTools,c as createAuthFunctions,d as createCrudCommands,N as createFoundation,l as createInclude,p as createModule,F as createQueryEngine,w as createStateMachine,m as createTable,o as createTenantRules,D as createTriggers,x as createWebhookBoundary,n as defaultErrors,u as defaultRoleMap,P as defineRelations,h as jsonSafeZid,O as noDelete,g as paginated,b as rateLimit,S as recordWebhookEvent,s as requireTenantReference,k as tenantOwnership,_ as tenantTable,A as timestamps,j as triggerContext,C as webhookEventsTable,v as zodTable,y as zodVariantTable};
1
+ import{KitError as e,defaultErrors as t}from"./errors.mjs";import{TIMESTAMP_FIELDS as n,createTable as r,kTable as i,kVariantTable as a,paginated as o,tenantTable as s}from"./table.mjs";import{TENANT_FIELD as c,assertTenantOwned as l,composeRules as u,createTenantRules as d,requireTenantReference as f}from"./tenancy.mjs";import{createAuthFunctions as p,createInclude as m,defaultRoleMap as h}from"./auth.mjs";import{createAgentTools as g}from"./agent-tools.mjs";import{createCrudCommands as _}from"./crud.mjs";import{createModule as v,memberName as y,namespace as b,namespaceIndex as x,namespaceName as S,namespacePrefix as C,tablesOf as w}from"./namespace.mjs";import{rateLimit as T}from"./middleware.mjs";import{createWebhookBoundary as E,recordWebhookEvent as D,webhookEventsTable as O}from"./webhooks.mjs";import{createStateMachine as k}from"./state-machine.mjs";import{Triggers as A,appendOnly as j,createTriggers as M,noDelete as N,tenantOwnership as P,timestamps as F,triggerContext as I}from"./triggers.mjs";import{Foundation as L}from"./components/foundation/client.mjs";import{createFoundation as R}from"./modules/foundation/foundation.mjs";import{defineRelations as z}from"./relations.mjs";import{createQueryEngine as B}from"./querying.mjs";import{k as V}from"./k/index.mjs";export{L as Foundation,e as KitError,c as TENANT_FIELD,n as TIMESTAMP_FIELDS,A as Triggers,j as appendOnly,l as assertTenantOwned,u as composeRules,g as createAgentTools,p as createAuthFunctions,_ as createCrudCommands,R as createFoundation,m as createInclude,v as createModule,B as createQueryEngine,k as createStateMachine,r as createTable,d as createTenantRules,M as createTriggers,E as createWebhookBoundary,t as defaultErrors,h as defaultRoleMap,z as defineRelations,V as k,i as kTable,a as kVariantTable,y as memberName,b as namespace,x as namespaceIndex,S as namespaceName,C as namespacePrefix,N as noDelete,o as paginated,T as rateLimit,D as recordWebhookEvent,f as requireTenantReference,w as tablesOf,P as tenantOwnership,s as tenantTable,F as timestamps,I as triggerContext,O as webhookEventsTable};
@@ -0,0 +1,40 @@
1
+ import { KType } from "./k/types.mjs";
2
+ import { JSONValue } from "convex/values";
3
+ /** The JSON Schema (draft 2020-12) subset `toJsonSchema` emits. */
4
+ export interface JsonSchema {
5
+ $schema?: string;
6
+ type?: 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'array' | 'object';
7
+ format?: 'date' | 'date-time';
8
+ contentEncoding?: 'base64';
9
+ description?: string;
10
+ const?: JSONValue;
11
+ enum?: string[];
12
+ default?: JSONValue;
13
+ minLength?: number;
14
+ maxLength?: number;
15
+ pattern?: string;
16
+ minimum?: number;
17
+ maximum?: number;
18
+ minItems?: number;
19
+ maxItems?: number;
20
+ items?: JsonSchema;
21
+ properties?: Record<string, JsonSchema>;
22
+ required?: string[];
23
+ additionalProperties?: boolean | JsonSchema;
24
+ propertyNames?: JsonSchema;
25
+ anyOf?: JsonSchema[];
26
+ oneOf?: JsonSchema[];
27
+ allOf?: JsonSchema[];
28
+ }
29
+ export type JsonSchemaOptions = {
30
+ /** Add `$schema: "https://json-schema.org/draft/2020-12/schema"` to the root. */
31
+ readonly $schema?: boolean;
32
+ };
33
+ /**
34
+ * The input-side JSON Schema of a `k` schema, for agent tool inputs and forms: optional and defaulted
35
+ * fields are not required (a JSON-compatible default is emitted), ids are strings, transforms and pipes
36
+ * emit their input schema, and descriptions come from `.describe()`. Custom refinements are not
37
+ * expressible and are omitted.
38
+ */
39
+ export declare function toJsonSchema(schema: KType, options?: JsonSchemaOptions): JsonSchema;
40
+ //# sourceMappingURL=json-schema.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{membersOf as e}from"./k/compile.mjs";import{maxTimestamp as t}from"./k/formats.mjs";function n(e,t){let n=r(e);return t?.$schema===!0?{$schema:`https://json-schema.org/draft/2020-12/schema`,...n}:n}function r(e){let t=[];for(let n=e;n!==null;n=n.prev)t.push(n);let n=i(t.pop()),r=!1,a=!1,o,c;for(let e=t.length-1;e>=0;e--){let i=t[e];switch(i.op){case`transform`:case`pipe`:r=!0;break;case`describe`:o=h(i);break;case`nullable`:a=!0;break;case`default`:r||(c=u(f(i)));break;case`min`:case`max`:case`length`:case`regex`:case`int`:r||s(n,i)}}let l=a?{anyOf:[n,{type:`null`}]}:n;return o!==void 0&&(l.description=o),c!==void 0&&(l.default=c),l}function i(n){switch(n.op){case`string`:case`id`:return{type:`string`};case`isoDate`:return{type:`string`,format:`date`};case`isoDateTime`:return{type:`string`,format:`date-time`};case`number`:return{type:`number`};case`int`:case`int64`:return{type:`integer`};case`timestamp`:return{type:`integer`,minimum:0,maximum:t};case`boolean`:return{type:`boolean`};case`null`:return{type:`null`};case`bytes`:return{type:`string`,contentEncoding:`base64`};case`any`:case`json`:return{};case`literal`:return l(m(n));case`enum`:return{type:`string`,enum:[...n.arg]};case`array`:return{type:`array`,items:r(d(n.arg))};case`object`:return a(p(n));case`record`:{let[e,t]=n.arg;return{type:`object`,propertyNames:r(e),additionalProperties:r(t)}}case`union`:return{anyOf:e(n).map(r)};case`discriminatedUnion`:{let{options:e}=n.arg;return{oneOf:e.map(r)}}default:throw Error(`toJsonSchema: '${n.op}' is not a root operation`)}}function a(e){let t={},n=[];for(let i in e)t[i]=r(e[i]),o(e[i])&&n.push(i);let i={type:`object`,properties:t,additionalProperties:!1};return n.length>0&&(i.required=n),i}function o(e){for(let t=e;t!==null;t=t.prev)if(t.op===`optional`||t.op===`partial`||t.op==="default")return!1;return!0}function s(e,t){if(t.op===`int`){e.type=`integer`;return}if(t.op===`regex`){let n=t.arg.source;e.pattern===void 0?e.pattern=n:(e.allOf??=[]).push({pattern:n});return}let n=t.arg,r=t.op===`min`||t.op===`length`,i=t.op===`max`||t.op===`length`;e.type===`string`?(r&&(e.minLength=c(e.minLength,n,Math.max)),i&&(e.maxLength=c(e.maxLength,n,Math.min))):e.type===`array`?(r&&(e.minItems=c(e.minItems,n,Math.max)),i&&(e.maxItems=c(e.maxItems,n,Math.min))):(r&&(e.minimum=c(e.minimum,n,Math.max)),i&&(e.maximum=c(e.maximum,n,Math.min)))}function c(e,t,n){return e===void 0?t:n(e,t)}function l(e){switch(typeof e){case`string`:return{type:`string`,const:e};case`boolean`:return{type:`boolean`,const:e};case`bigint`:return{type:`integer`,const:Number(e)};default:return{type:`number`,const:e}}}function u(e){if(e===null)return null;switch(typeof e){case`string`:case`boolean`:return e;case`number`:return Number.isFinite(e)?e:void 0;case`bigint`:return}if(e instanceof ArrayBuffer)return;if(Array.isArray(e)){let t=[];for(let n of e){let e=u(n);if(e===void 0)return;t.push(e)}return t}let t={};for(let[n,r]of Object.entries(e)){if(r===void 0)continue;let e=u(r);if(e===void 0)return;t[n]=e}return t}function d(e){return e}function f(e){return e.arg}function p(e){return e.arg}function m(e){return e.arg}function h(e){return e.arg}export{n as toJsonSchema};
2
+ //# sourceMappingURL=json-schema.mjs.map