cvx-kit 0.2.0 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/README.md +556 -99
  2. package/dist/agent-tools.d.mts +39 -26
  3. package/dist/agent-tools.mjs +1 -1
  4. package/dist/agent-tools.mjs.map +1 -1
  5. package/dist/auth.d.mts +120 -308
  6. package/dist/auth.mjs +1 -1
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/components/approvals/_generated/api.d.mts +7 -9
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -1
  10. package/dist/components/approvals/_generated/component.d.mts +1 -4
  11. package/dist/components/approvals/_generated/dataModel.d.mts +5 -8
  12. package/dist/components/approvals/_generated/server.d.mts +12 -15
  13. package/dist/components/approvals/_generated/server.mjs.map +1 -1
  14. package/dist/components/approvals/audit.d.mts +8 -9
  15. package/dist/components/approvals/audit.mjs +1 -1
  16. package/dist/components/approvals/audit.mjs.map +1 -1
  17. package/dist/components/approvals/client.d.mts +11 -12
  18. package/dist/components/approvals/client.mjs +1 -1
  19. package/dist/components/approvals/client.mjs.map +1 -1
  20. package/dist/components/approvals/constants.d.mts +30 -31
  21. package/dist/components/approvals/constants.mjs.map +1 -1
  22. package/dist/components/approvals/convex.config.d.mts +0 -2
  23. package/dist/components/approvals/convex.config.mjs.map +1 -1
  24. package/dist/components/approvals/decisions.d.mts +13 -17
  25. package/dist/components/approvals/decisions.mjs +1 -1
  26. package/dist/components/approvals/decisions.mjs.map +1 -1
  27. package/dist/components/approvals/functions.d.mts +3 -4
  28. package/dist/components/approvals/functions.mjs +1 -1
  29. package/dist/components/approvals/functions.mjs.map +1 -1
  30. package/dist/components/approvals/health.d.mts +2 -3
  31. package/dist/components/approvals/health.mjs.map +1 -1
  32. package/dist/components/approvals/requests.d.mts +114 -131
  33. package/dist/components/approvals/requests.mjs +1 -1
  34. package/dist/components/approvals/requests.mjs.map +1 -1
  35. package/dist/components/approvals/schema.d.ts +106 -315
  36. package/dist/components/approvals/schema.js +1 -1
  37. package/dist/components/approvals/validators.d.mts +323 -395
  38. package/dist/components/approvals/validators.mjs +1 -1
  39. package/dist/components/approvals/validators.mjs.map +1 -1
  40. package/dist/components/approvals/workflow.d.mts +4 -5
  41. package/dist/components/approvals/workflow.mjs +1 -1
  42. package/dist/components/approvals/workflow.mjs.map +1 -1
  43. package/dist/components/approvals/workflow_steps.d.mts +16 -17
  44. package/dist/components/approvals/workflow_steps.mjs +1 -1
  45. package/dist/components/approvals/workflow_steps.mjs.map +1 -1
  46. package/dist/components/foundation/_generated/api.d.mts +6 -8
  47. package/dist/components/foundation/_generated/api.mjs.map +1 -1
  48. package/dist/components/foundation/_generated/component.d.mts +1 -4
  49. package/dist/components/foundation/_generated/dataModel.d.mts +5 -8
  50. package/dist/components/foundation/_generated/server.d.mts +12 -15
  51. package/dist/components/foundation/_generated/server.mjs.map +1 -1
  52. package/dist/components/foundation/client.d.mts +45 -38
  53. package/dist/components/foundation/client.mjs +1 -1
  54. package/dist/components/foundation/client.mjs.map +1 -1
  55. package/dist/components/foundation/convex.config.d.mts +0 -2
  56. package/dist/components/foundation/convex.config.mjs.map +1 -1
  57. package/dist/components/foundation/functions.d.mts +2 -3
  58. package/dist/components/foundation/functions.mjs.map +1 -1
  59. package/dist/components/foundation/modules/command/command.d.mts +65 -17
  60. package/dist/components/foundation/modules/command/command.mjs +1 -1
  61. package/dist/components/foundation/modules/command/command.mjs.map +1 -1
  62. package/dist/components/foundation/modules/command/lifecycle.d.mts +78 -0
  63. package/dist/components/foundation/modules/command/lifecycle.mjs +2 -0
  64. package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -0
  65. package/dist/components/foundation/modules/observability/observability.d.mts +13 -6
  66. package/dist/components/foundation/modules/observability/observability.mjs +1 -1
  67. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
  68. package/dist/components/foundation/modules/query/query.d.mts +11 -12
  69. package/dist/components/foundation/modules/query/query.mjs +1 -1
  70. package/dist/components/foundation/modules/query/query.mjs.map +1 -1
  71. package/dist/components/foundation/operation.d.mts +72 -0
  72. package/dist/components/foundation/operation.mjs +2 -0
  73. package/dist/components/foundation/operation.mjs.map +1 -0
  74. package/dist/components/foundation/result.d.mts +7 -8
  75. package/dist/components/foundation/result.mjs.map +1 -1
  76. package/dist/components/foundation/schema.d.ts +0 -2
  77. package/dist/components/foundation/telemetry.d.mts +2 -3
  78. package/dist/components/foundation/telemetry.mjs +1 -1
  79. package/dist/components/foundation/telemetry.mjs.map +1 -1
  80. package/dist/contracts.d.mts +5 -0
  81. package/dist/contracts.mjs +1 -0
  82. package/dist/crud.d.mts +185 -27
  83. package/dist/crud.mjs +1 -1
  84. package/dist/crud.mjs.map +1 -1
  85. package/dist/effect.d.mts +16 -0
  86. package/dist/effect.mjs +1 -0
  87. package/dist/errors.d.mts +6 -6
  88. package/dist/errors.mjs +1 -1
  89. package/dist/errors.mjs.map +1 -1
  90. package/dist/filters.d.mts +4 -0
  91. package/dist/filters.mjs +1 -0
  92. package/dist/idempotency.d.mts +2 -0
  93. package/dist/idempotency.mjs +1 -0
  94. package/dist/index.d.mts +14 -7
  95. package/dist/index.mjs +1 -1
  96. package/dist/json-schema.d.mts +40 -0
  97. package/dist/json-schema.mjs +2 -0
  98. package/dist/json-schema.mjs.map +1 -0
  99. package/dist/k/compile.d.mts +17 -0
  100. package/dist/k/compile.mjs +2 -0
  101. package/dist/k/compile.mjs.map +1 -0
  102. package/dist/k/dates.d.mts +23 -0
  103. package/dist/k/dates.mjs +2 -0
  104. package/dist/k/dates.mjs.map +1 -0
  105. package/dist/k/formats.d.mts +24 -0
  106. package/dist/k/formats.mjs +2 -0
  107. package/dist/k/formats.mjs.map +1 -0
  108. package/dist/k/index.d.mts +32 -0
  109. package/dist/k/index.mjs +2 -0
  110. package/dist/k/index.mjs.map +1 -0
  111. package/dist/k/issues.d.mts +31 -0
  112. package/dist/k/issues.mjs +2 -0
  113. package/dist/k/issues.mjs.map +1 -0
  114. package/dist/k/kinds.d.mts +81 -0
  115. package/dist/k/kinds.mjs +2 -0
  116. package/dist/k/kinds.mjs.map +1 -0
  117. package/dist/k/object.d.mts +43 -0
  118. package/dist/k/object.mjs +2 -0
  119. package/dist/k/object.mjs.map +1 -0
  120. package/dist/k/parse.d.mts +29 -0
  121. package/dist/k/parse.mjs +2 -0
  122. package/dist/k/parse.mjs.map +1 -0
  123. package/dist/k/schema.d.mts +100 -0
  124. package/dist/k/schema.mjs +2 -0
  125. package/dist/k/schema.mjs.map +1 -0
  126. package/dist/k/standard.d.mts +8 -0
  127. package/dist/k/standard.mjs +2 -0
  128. package/dist/k/standard.mjs.map +1 -0
  129. package/dist/k/types.d.mts +64 -0
  130. package/dist/k/types.mjs +1 -0
  131. package/dist/k.d.mts +8 -0
  132. package/dist/k.mjs +1 -0
  133. package/dist/middleware.d.mts +8 -11
  134. package/dist/middleware.mjs +1 -1
  135. package/dist/middleware.mjs.map +1 -1
  136. package/dist/modules/contracts/binding.d.mts +23 -0
  137. package/dist/modules/contracts/binding.mjs +2 -0
  138. package/dist/modules/contracts/binding.mjs.map +1 -0
  139. package/dist/modules/contracts/contract.d.mts +67 -0
  140. package/dist/modules/contracts/contract.mjs +2 -0
  141. package/dist/modules/contracts/contract.mjs.map +1 -0
  142. package/dist/modules/contracts/convex.d.mts +18 -0
  143. package/dist/modules/contracts/convex.mjs +2 -0
  144. package/dist/modules/contracts/convex.mjs.map +1 -0
  145. package/dist/modules/contracts/domain.d.mts +62 -0
  146. package/dist/modules/contracts/domain.mjs +2 -0
  147. package/dist/modules/contracts/domain.mjs.map +1 -0
  148. package/dist/modules/contracts/errors.d.mts +737 -0
  149. package/dist/modules/contracts/errors.mjs +2 -0
  150. package/dist/modules/contracts/errors.mjs.map +1 -0
  151. package/dist/modules/contracts/exposure.d.mts +103 -0
  152. package/dist/modules/contracts/exposure.mjs +2 -0
  153. package/dist/modules/contracts/exposure.mjs.map +1 -0
  154. package/dist/modules/contracts/idempotency.d.mts +85 -0
  155. package/dist/modules/contracts/idempotency.mjs +2 -0
  156. package/dist/modules/contracts/idempotency.mjs.map +1 -0
  157. package/dist/modules/contracts/lazy.d.mts +6 -0
  158. package/dist/modules/contracts/lazy.mjs +2 -0
  159. package/dist/modules/contracts/lazy.mjs.map +1 -0
  160. package/dist/modules/contracts/standard.d.mts +17 -0
  161. package/dist/modules/contracts/standard.mjs +2 -0
  162. package/dist/modules/contracts/standard.mjs.map +1 -0
  163. package/dist/modules/contracts/workflow.d.mts +165 -0
  164. package/dist/modules/contracts/workflow.mjs +2 -0
  165. package/dist/modules/contracts/workflow.mjs.map +1 -0
  166. package/dist/modules/effect/action.d.mts +63 -0
  167. package/dist/modules/effect/action.mjs +2 -0
  168. package/dist/modules/effect/action.mjs.map +1 -0
  169. package/dist/modules/effect/agent-tools.d.mts +2 -0
  170. package/dist/modules/effect/agent-tools.mjs +1 -0
  171. package/dist/modules/effect/api-runtime.d.mts +36 -0
  172. package/dist/modules/effect/api-runtime.mjs +2 -0
  173. package/dist/modules/effect/api-runtime.mjs.map +1 -0
  174. package/dist/modules/effect/api.d.mts +46 -0
  175. package/dist/modules/effect/api.mjs +2 -0
  176. package/dist/modules/effect/api.mjs.map +1 -0
  177. package/dist/modules/effect/auth.d.mts +46 -0
  178. package/dist/modules/effect/auth.mjs +2 -0
  179. package/dist/modules/effect/auth.mjs.map +1 -0
  180. package/dist/modules/effect/client.d.mts +15 -0
  181. package/dist/modules/effect/client.mjs +1 -0
  182. package/dist/modules/effect/command.d.mts +108 -0
  183. package/dist/modules/effect/command.mjs +2 -0
  184. package/dist/modules/effect/command.mjs.map +1 -0
  185. package/dist/modules/effect/crud.d.mts +885 -0
  186. package/dist/modules/effect/crud.mjs +2 -0
  187. package/dist/modules/effect/crud.mjs.map +1 -0
  188. package/dist/modules/effect/domain.d.mts +82 -0
  189. package/dist/modules/effect/domain.mjs +2 -0
  190. package/dist/modules/effect/domain.mjs.map +1 -0
  191. package/dist/modules/effect/errors.d.mts +13 -0
  192. package/dist/modules/effect/errors.mjs +2 -0
  193. package/dist/modules/effect/errors.mjs.map +1 -0
  194. package/dist/modules/effect/failure-audit.d.mts +48 -0
  195. package/dist/modules/effect/failure-audit.mjs +2 -0
  196. package/dist/modules/effect/failure-audit.mjs.map +1 -0
  197. package/dist/modules/effect/failures.d.mts +21 -0
  198. package/dist/modules/effect/failures.mjs +2 -0
  199. package/dist/modules/effect/failures.mjs.map +1 -0
  200. package/dist/modules/effect/foundation.d.mts +23 -0
  201. package/dist/modules/effect/foundation.mjs +2 -0
  202. package/dist/modules/effect/foundation.mjs.map +1 -0
  203. package/dist/modules/effect/idempotency.d.mts +29 -0
  204. package/dist/modules/effect/idempotency.mjs +2 -0
  205. package/dist/modules/effect/idempotency.mjs.map +1 -0
  206. package/dist/modules/effect/input.d.mts +10 -0
  207. package/dist/modules/effect/input.mjs +2 -0
  208. package/dist/modules/effect/input.mjs.map +1 -0
  209. package/dist/modules/effect/normalize.d.mts +7 -0
  210. package/dist/modules/effect/normalize.mjs +2 -0
  211. package/dist/modules/effect/normalize.mjs.map +1 -0
  212. package/dist/modules/effect/operation.d.mts +148 -0
  213. package/dist/modules/effect/operation.mjs +2 -0
  214. package/dist/modules/effect/operation.mjs.map +1 -0
  215. package/dist/modules/effect/query.d.mts +90 -0
  216. package/dist/modules/effect/query.mjs +2 -0
  217. package/dist/modules/effect/query.mjs.map +1 -0
  218. package/dist/modules/effect/schema.d.mts +30 -0
  219. package/dist/modules/effect/schema.mjs +2 -0
  220. package/dist/modules/effect/schema.mjs.map +1 -0
  221. package/dist/modules/effect/scope.d.mts +25 -0
  222. package/dist/modules/effect/scope.mjs +2 -0
  223. package/dist/modules/effect/scope.mjs.map +1 -0
  224. package/dist/modules/effect/workflow.d.mts +75 -0
  225. package/dist/modules/effect/workflow.mjs +2 -0
  226. package/dist/modules/effect/workflow.mjs.map +1 -0
  227. package/dist/modules/foundation/foundation.d.mts +108 -0
  228. package/dist/modules/foundation/foundation.mjs +2 -0
  229. package/dist/modules/foundation/foundation.mjs.map +1 -0
  230. package/dist/modules/foundation/operation.d.mts +139 -0
  231. package/dist/modules/foundation/operation.mjs +2 -0
  232. package/dist/modules/foundation/operation.mjs.map +1 -0
  233. package/dist/namespace.d.mts +104 -0
  234. package/dist/namespace.mjs +2 -0
  235. package/dist/namespace.mjs.map +1 -0
  236. package/dist/oxlint/architecture.d.mts +23 -0
  237. package/dist/oxlint/architecture.mjs +2 -0
  238. package/dist/oxlint/architecture.mjs.map +1 -0
  239. package/dist/oxlint/ast.d.mts +51 -0
  240. package/dist/oxlint/ast.mjs +2 -0
  241. package/dist/oxlint/ast.mjs.map +1 -0
  242. package/dist/oxlint/components.d.mts +4 -0
  243. package/dist/oxlint/components.mjs +2 -0
  244. package/dist/oxlint/components.mjs.map +1 -0
  245. package/dist/oxlint/ownership.d.mts +59 -0
  246. package/dist/oxlint/ownership.mjs +2 -0
  247. package/dist/oxlint/ownership.mjs.map +1 -0
  248. package/dist/oxlint/reserved-files.d.mts +4 -0
  249. package/dist/oxlint/reserved-files.mjs +2 -0
  250. package/dist/oxlint/reserved-files.mjs.map +1 -0
  251. package/dist/oxlint.d.mts +9 -0
  252. package/dist/oxlint.mjs +2 -0
  253. package/dist/oxlint.mjs.map +1 -0
  254. package/dist/querying/cursors.d.mts +94 -0
  255. package/dist/querying/cursors.mjs +2 -0
  256. package/dist/querying/cursors.mjs.map +1 -0
  257. package/dist/querying/execution.d.mts +40 -0
  258. package/dist/querying/execution.mjs +2 -0
  259. package/dist/querying/execution.mjs.map +1 -0
  260. package/dist/querying/failures.d.mts +11 -0
  261. package/dist/querying/failures.mjs +2 -0
  262. package/dist/querying/failures.mjs.map +1 -0
  263. package/dist/querying/filter-boundary.d.mts +25 -0
  264. package/dist/querying/filter-boundary.mjs +2 -0
  265. package/dist/querying/filter-boundary.mjs.map +1 -0
  266. package/dist/querying/filters.d.mts +180 -0
  267. package/dist/querying/filters.mjs +2 -0
  268. package/dist/querying/filters.mjs.map +1 -0
  269. package/dist/querying/planner.d.mts +61 -0
  270. package/dist/querying/planner.mjs +2 -0
  271. package/dist/querying/planner.mjs.map +1 -0
  272. package/dist/querying/relationships.d.mts +58 -0
  273. package/dist/querying/relationships.mjs +2 -0
  274. package/dist/querying/relationships.mjs.map +1 -0
  275. package/dist/querying/search.d.mts +69 -0
  276. package/dist/querying/search.mjs +2 -0
  277. package/dist/querying/search.mjs.map +1 -0
  278. package/dist/querying/security.d.mts +123 -0
  279. package/dist/querying/security.mjs +2 -0
  280. package/dist/querying/security.mjs.map +1 -0
  281. package/dist/querying/shared/ast.d.mts +26 -0
  282. package/dist/querying/shared/ast.mjs +2 -0
  283. package/dist/querying/shared/ast.mjs.map +1 -0
  284. package/dist/querying/shared/contract.d.mts +98 -0
  285. package/dist/querying/shared/contract.mjs +2 -0
  286. package/dist/querying/shared/contract.mjs.map +1 -0
  287. package/dist/querying/shared/evaluate.d.mts +5 -0
  288. package/dist/querying/shared/evaluate.mjs +2 -0
  289. package/dist/querying/shared/evaluate.mjs.map +1 -0
  290. package/dist/querying/shared/filters.d.mts +65 -0
  291. package/dist/querying/shared/filters.mjs +2 -0
  292. package/dist/querying/shared/filters.mjs.map +1 -0
  293. package/dist/querying/shared/native-json.d.mts +7 -0
  294. package/dist/querying/shared/native-json.mjs +2 -0
  295. package/dist/querying/shared/native-json.mjs.map +1 -0
  296. package/dist/querying/shared/page.d.mts +20 -0
  297. package/dist/querying/shared/page.mjs +2 -0
  298. package/dist/querying/shared/page.mjs.map +1 -0
  299. package/dist/querying.d.mts +82 -0
  300. package/dist/querying.mjs +2 -0
  301. package/dist/querying.mjs.map +1 -0
  302. package/dist/react/failures.d.mts +24 -0
  303. package/dist/react/failures.mjs +2 -0
  304. package/dist/react/failures.mjs.map +1 -0
  305. package/dist/react/optimistic.d.mts +46 -0
  306. package/dist/react/optimistic.mjs +2 -0
  307. package/dist/react/optimistic.mjs.map +1 -0
  308. package/dist/react/pagination-state.d.mts +39 -0
  309. package/dist/react/pagination-state.mjs +2 -0
  310. package/dist/react/pagination-state.mjs.map +1 -0
  311. package/dist/react/use-command.d.mts +22 -0
  312. package/dist/react/use-command.mjs +2 -0
  313. package/dist/react/use-command.mjs.map +1 -0
  314. package/dist/react/use-paginated-list.d.mts +34 -0
  315. package/dist/react/use-paginated-list.mjs +2 -0
  316. package/dist/react/use-paginated-list.mjs.map +1 -0
  317. package/dist/react.d.mts +6 -0
  318. package/dist/react.mjs +1 -0
  319. package/dist/registration.d.mts +65 -0
  320. package/dist/registration.mjs +2 -0
  321. package/dist/registration.mjs.map +1 -0
  322. package/dist/relations-public.d.mts +2 -0
  323. package/dist/relations-public.mjs +1 -0
  324. package/dist/relations.d.mts +274 -0
  325. package/dist/relations.mjs +2 -0
  326. package/dist/relations.mjs.map +1 -0
  327. package/dist/state-machine.d.mts +1 -4
  328. package/dist/state-machine.mjs.map +1 -1
  329. package/dist/table.d.mts +222 -0
  330. package/dist/table.mjs +2 -0
  331. package/dist/table.mjs.map +1 -0
  332. package/dist/tenancy.d.mts +6 -8
  333. package/dist/tenancy.mjs +1 -1
  334. package/dist/tenancy.mjs.map +1 -1
  335. package/dist/triggers.d.mts +12 -10
  336. package/dist/triggers.mjs +1 -1
  337. package/dist/triggers.mjs.map +1 -1
  338. package/dist/webhooks.d.mts +22 -112
  339. package/dist/webhooks.mjs +1 -1
  340. package/dist/webhooks.mjs.map +1 -1
  341. package/dist/workflow.d.mts +2 -0
  342. package/dist/workflow.mjs +1 -0
  343. package/dist/zod.d.mts +30 -0
  344. package/dist/zod.mjs +2 -0
  345. package/dist/zod.mjs.map +1 -0
  346. package/package.json +145 -33
  347. package/src/test.ts +9 -17
  348. package/CHANGELOG.md +0 -145
  349. package/ROADMAP.md +0 -126
  350. package/dist/zod-table.d.mts +0 -175
  351. package/dist/zod-table.mjs +0 -2
  352. package/dist/zod-table.mjs.map +0 -1
  353. package/docs/agent-tools.md +0 -41
  354. package/docs/approvals.md +0 -200
  355. package/docs/architecture.md +0 -124
  356. package/docs/auth.md +0 -218
  357. package/docs/commands.md +0 -278
  358. package/docs/conventions.md +0 -291
  359. package/docs/crud.md +0 -62
  360. package/docs/llms.md +0 -220
  361. package/docs/maintainability.md +0 -124
  362. package/docs/migration.md +0 -351
  363. package/docs/plans/2026-08-14-001-feat-v0.1.0-feature-set-plan.md +0 -461
  364. package/docs/plans/2026-08-21-0930-feat-resolve-organization-hook-plan.md +0 -178
  365. package/docs/tenancy.md +0 -179
  366. package/docs/triggers.md +0 -75
  367. package/docs/upgrading.md +0 -175
  368. package/docs/webhooks.md +0 -58
  369. package/docs/zod-table.md +0 -173
  370. package/scripts/convex-config-bridge.mjs +0 -55
  371. package/scripts/extract-changelog.mjs +0 -29
  372. package/scripts/smoke-packed-components.mjs +0 -374
@@ -1,32 +1,31 @@
1
- import { CommandExecution, CommandInput, CommandRegistry, CommandResult, Parseable } from "./modules/command/command.mjs";
1
+ import { CommandArgument, CommandExecution, CommandHandlerResult, CommandInput, CommandRegistry, CommandResult, CommandSchema, Parseable, SchemaInput, SchemaOutput } from "./modules/command/command.mjs";
2
2
  import { CommandObservation, Observability, ObservabilityOptions } from "./modules/observability/observability.mjs";
3
3
  import { AnyQueryMiddleware, Query, QueryExecution, QueryMiddleware } from "./modules/query/query.mjs";
4
4
  import { Result, ResultBoundary, TransactionMetricsContext, executeResultBoundary, projectResult } from "./result.mjs";
5
5
  import { emitSemanticEvent } from "./telemetry.mjs";
6
+ import { CommandPreparation, OperationExtension, OperationHostContext, TypedOperation, operationFactory } from "./operation.mjs";
7
+ import "./client.mjs";
8
+ import { Value } from "convex/values";
6
9
  declare namespace client_d_exports {
7
- export { AnyCommandMiddleware, AnyQueryMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandConstructor, CommandDefaults, CommandExecution, CommandInput, CommandMiddleware, CommandObservation, CommandRegistry, CommandResult, Foundation, FoundationOptions, ObservabilityOptions, Parseable, PermissionChecker, QueryExecution, QueryMiddleware, Result, ResultBoundary, TransactionMetricsContext };
10
+ export { AnyCommandMiddleware, AnyQueryMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandArgument, CommandConstructor, CommandDefaults, CommandExecution, CommandHandlerResult, CommandInput, CommandMiddleware, CommandObservation, CommandPreparation, CommandRegistry, CommandResult, Foundation, FoundationOptions, ObservabilityOptions, Parseable, PermissionChecker, QueryExecution, QueryMiddleware, Result, ResultBoundary, SchemaOutput, TransactionMetricsContext, TypedOperation };
8
11
  }
9
12
  /** Shape handed to the injected audit writer; classification comes from the operation. */
10
- type AuditEntryInput = {
13
+ export type AuditEntryInput = {
11
14
  operation: string;
12
15
  actorId: string;
13
16
  aggregate: {
14
17
  type: string;
15
18
  id: string;
16
19
  };
17
- metadata?: Record<string, unknown>;
20
+ metadata?: Record<string, Value>;
18
21
  classification: string;
19
22
  };
20
- type AuditWriter = (context: never, entry: AuditEntryInput) => Promise<unknown> | unknown;
23
+ export type AuditWriter<Result = unknown> = (context: never, entry: AuditEntryInput) => MaybePromise<Result>;
21
24
  type MaybePromise<Value> = Value | Promise<Value>;
22
25
  type OperationKey<Operations extends CommandRegistry> = Extract<keyof Operations, string>;
23
- type AuditedOperation = Readonly<{
24
- command: Readonly<{
25
- parse: (value: unknown) => unknown;
26
- }>;
27
- result: Readonly<{
28
- parse: (value: unknown) => unknown;
29
- }>;
26
+ export type AuditedOperation = Readonly<{
27
+ command: CommandSchema;
28
+ result: CommandSchema;
30
29
  classification: string;
31
30
  /**
32
31
  * Permission slug required to execute this operation. Checked through the
@@ -34,6 +33,8 @@ type AuditedOperation = Readonly<{
34
33
  * declaring a permission without injecting a checker fails closed.
35
34
  */
36
35
  permission?: string;
36
+ prepare?: (context: never, command: never) => MaybePromise<CommandPreparation<never>>;
37
+ replayResult?: CommandSchema;
37
38
  /**
38
39
  * Per-operation precondition, after the permission check and the registry
39
40
  * default guard, before the handler. Throw to deny — nothing has run yet.
@@ -60,38 +61,39 @@ type AuditedOperation = Readonly<{
60
61
  * transform results, but can never skip authorization, return an invalid
61
62
  * result, or desynchronize audit from effects.
62
63
  */
63
- type CommandMiddleware<Context = never, Extension extends Record<string, unknown> = Record<string, unknown>> = (input: {
64
+ export type CommandMiddleware<Context = never, Extension extends object = object, Input = unknown, Result = unknown> = (input: {
64
65
  operation: string;
65
- command: unknown;
66
+ command: Input;
66
67
  context: Context;
67
68
  next: (options?: {
68
69
  /** Merged into the context handed to inner middleware, guards, handler. */
69
70
  context?: Extension;
70
- }) => Promise<unknown>;
71
- }) => Promise<unknown>;
71
+ }) => Promise<Result>;
72
+ }) => Promise<Result>;
72
73
  /** Any-context middleware — what registries and operations accept. */
73
- type AnyCommandMiddleware = (input: {
74
+ export type AnyCommandMiddleware<Input = never, Result = unknown, NextResult = never> = (input: {
74
75
  operation: string;
75
- command: unknown;
76
+ definition?: AuditedOperation;
77
+ command: Input;
76
78
  context: never;
77
79
  next: (options?: {
78
- context?: unknown;
79
- }) => Promise<unknown>;
80
- }) => Promise<unknown>;
80
+ context?: object;
81
+ }) => Promise<NextResult>;
82
+ }) => Promise<Result>;
81
83
  /** Registry-wide defaults applied to every operation of one Command. */
82
- type CommandDefaults = Readonly<{
84
+ export type CommandDefaults = Readonly<{
83
85
  /** Runs before every operation's own guard. Throw to deny. */
84
86
  guard?: (context: never) => MaybePromise<void>;
85
87
  /** Outermost middleware, in array order, around every operation. */
86
88
  middleware?: readonly AnyCommandMiddleware[];
87
89
  }>;
88
90
  /** Injected permission policy: throw to deny. Host semantics, kit ordering. */
89
- type PermissionChecker = (context: never, input: Readonly<{
91
+ export type PermissionChecker = (context: never, input: Readonly<{
90
92
  permission: string;
91
93
  operation: string;
92
94
  }>) => MaybePromise<void>;
93
- type AuditedRegistry = Readonly<Record<string, AuditedOperation>>;
94
- type FoundationOptions = Readonly<{
95
+ export type AuditedRegistry = Readonly<Record<string, AuditedOperation>>;
96
+ export type FoundationOptions = Readonly<{
95
97
  observability: ObservabilityOptions & Readonly<{
96
98
  /**
97
99
  * In-transaction audit writer used by Command. Operations that
@@ -119,6 +121,7 @@ type FoundationComponentApi = Readonly<{
119
121
  */
120
122
  declare class BoundCommand<Context, const Operations extends AuditedRegistry> {
121
123
  #private;
124
+ static withContext: typeof operationFactory;
122
125
  /** Declared aggregate types per operation — introspectable for tests. */
123
126
  readonly aggregates: Readonly<{ [Key in OperationKey<Operations>]: Operations[Key]['aggregates']; }>;
124
127
  static operation<const Definition extends AuditedOperation>(definition: Definition): Definition;
@@ -126,31 +129,35 @@ declare class BoundCommand<Context, const Operations extends AuditedRegistry> {
126
129
  * Identity helper that types a middleware against its context and the
127
130
  * context extension it passes downstream via next({ context }).
128
131
  */
129
- static middleware<Context = never, const Extension extends Record<string, unknown> = Record<string, unknown>>(middleware: CommandMiddleware<Context, Extension>): CommandMiddleware<Context, Extension>;
132
+ static middleware<Context = never, const Extension extends object = object, Input = unknown, Result = unknown>(middleware: CommandMiddleware<Context, Extension, Input, Result>): CommandMiddleware<Context, Extension, Input, Result>;
130
133
  constructor(operations: Operations, deps: {
131
134
  observability: Observability;
132
135
  writeAudit: AuditWriter;
133
136
  checkPermission?: PermissionChecker;
134
137
  defaults?: CommandDefaults;
135
138
  });
139
+ /**
140
+ * @deprecated Declare handlers inside command({...}) using createEffectFoundation
141
+ * from cvx-kit/effect, then call exec(operation, input, host).
142
+ */
136
143
  exec<const Key extends OperationKey<Operations>>(executor: {
137
144
  operation: Key;
138
- handler: (context: Context, command: CommandInput<Operations, Key>) => MaybePromise<CommandResult<Operations, Key>>;
139
- }): (context: Context, command: Operations[Key]["command"] extends (infer T) ? T extends Operations[Key]["command"] ? T extends Readonly<{
140
- parse: (value: unknown) => infer Output;
141
- }> ? Output : never : never : never) => Promise<Operations[Key]["result"] extends (infer T_1) ? T_1 extends Operations[Key]["result"] ? T_1 extends Readonly<{
142
- parse: (value: unknown) => infer Output;
143
- }> ? Output : never : never : never>;
145
+ handler: (context: Context & OperationExtension<Operations[Key]>, command: CommandInput<Operations, Key>) => MaybePromise<CommandHandlerResult<Operations, Key>>;
146
+ }): (context: Context, command: SchemaInput<Operations[Key]["command"]>) => Promise<SchemaOutput<Operations[Key]["result"]>>;
144
147
  }
145
- type ApplicationCommand<Context, Operations extends AuditedRegistry> = BoundCommand<Context, Operations>;
148
+ /** @deprecated Use the registry returned by createEffectFoundation(...).Command from cvx-kit/effect. */
149
+ export type ApplicationCommand<Context, Operations extends AuditedRegistry> = BoundCommand<Context, Operations>;
146
150
  /**
147
151
  * The constructor shape a Foundation instance exposes as `Command`.
148
152
  * Exported as a TYPE ONLY so factories (e.g. cvx-kit/crud) can accept the
149
153
  * destructured facade class as input without importing any runtime kernel.
154
+ * @deprecated Use createEffectFoundation from cvx-kit/effect and declare handlers inside command({...}).
150
155
  */
151
- type CommandConstructor = {
152
- new <Context, const Operations extends AuditedRegistry>(operations: Operations, defaults?: CommandDefaults): BoundCommand<Context, Operations>;
156
+ export type CommandConstructor = {
157
+ /** @deprecated Use createEffectFoundation(...).Command({ context, operations }) from cvx-kit/effect. */
158
+ new <Context, const Operations extends AuditedRegistry>(operations: Operations & { readonly [Key in keyof Operations]: OperationHostContext<Context>; }, defaults?: CommandDefaults): BoundCommand<Context, Operations>;
153
159
  operation: (typeof BoundCommand)['operation'];
160
+ withContext: (typeof BoundCommand)['withContext'];
154
161
  middleware: (typeof BoundCommand)['middleware'];
155
162
  };
156
163
  /**
@@ -158,8 +165,9 @@ type CommandConstructor = {
158
165
  * Declared once; the sole source of the command protocol, query kernel, and
159
166
  * observability: `const { Command, Query, observability } = new Foundation(...)`.
160
167
  */
161
- declare class Foundation<Component extends FoundationComponentApi = FoundationComponentApi> {
168
+ export declare class Foundation<Component extends FoundationComponentApi = FoundationComponentApi> {
162
169
  readonly status: Component['functions']['status'];
170
+ /** @deprecated Use createEffectFoundation(...).Command from cvx-kit/effect. */
163
171
  readonly Command: CommandConstructor;
164
172
  readonly Query: typeof Query;
165
173
  readonly observability: Observability;
@@ -169,6 +177,5 @@ declare class Foundation<Component extends FoundationComponentApi = FoundationCo
169
177
  readonly emitSemanticEvent: typeof emitSemanticEvent;
170
178
  constructor(component: Component, options: FoundationOptions);
171
179
  }
172
- //#endregion
173
- export { AnyCommandMiddleware, type AnyQueryMiddleware, ApplicationCommand, AuditEntryInput, AuditWriter, AuditedOperation, AuditedRegistry, CommandConstructor, CommandDefaults, type CommandExecution, type CommandInput, CommandMiddleware, type CommandObservation, type CommandRegistry, type CommandResult, Foundation, FoundationOptions, type ObservabilityOptions, type Parseable, PermissionChecker, type QueryExecution, type QueryMiddleware, type Result, type ResultBoundary, type TransactionMetricsContext, client_d_exports };
180
+ export { type AnyQueryMiddleware, type CommandArgument, type CommandExecution, type CommandHandlerResult, type CommandInput, type CommandObservation, type CommandPreparation, type CommandRegistry, type CommandResult, type ObservabilityOptions, type Parseable, type QueryExecution, type QueryMiddleware, type Result, type ResultBoundary, type SchemaOutput, type TransactionMetricsContext, type TypedOperation, client_d_exports };
174
181
  //# sourceMappingURL=client.d.mts.map
@@ -1,2 +1,2 @@
1
- import{Command as e}from"./modules/command/command.mjs";import{Observability as t}from"./modules/observability/observability.mjs";import{Query as n}from"./modules/query/query.mjs";import{executeResultBoundary as r,projectResult as i}from"./result.mjs";import{emitSemanticEvent as a}from"./telemetry.mjs";var o=class{#e;#t;#n;#r;#i;aggregates;static operation(e){return e}static middleware(e){return e}constructor(t,n){this.#t=n.observability,this.#n=n.writeAudit,this.#r=n.checkPermission,this.#i=n.defaults??{},this.aggregates=Object.freeze(Object.fromEntries(Object.entries(t).map(([e,t])=>[e,t.aggregates]))),this.#e=new e({operations:t,execute:e=>this.#a(e)})}exec(e){return this.#e.exec(e)}async#a(e){return this.#t.observe({operation:e.operation,classification:e.definition.classification},async()=>{let t=e.definition.permission;if(t!==void 0){if(!this.#r)throw new l(e.operation);await this.#r(e.context,{permission:t,operation:e.operation})}let n=[...this.#i.middleware??[],...e.definition.middleware??[]],r=async t=>(await this.#i.guard?.(t),await e.definition.guard?.(t,e.command),e.run(t)),i=-1,a=async(t,o)=>{if(t<=i)throw new s(e.operation);i=t;let c=n[t];return c?c({operation:e.operation,command:e.command,context:o,next:e=>a(t+1,e?.context?{...o,...e.context}:o)}):r(o)},o=e.parseResult(await a(0,e.context)),u=await e.definition.audit({command:e.command,result:o},e.context);if(u){let t=e.definition.aggregates;if(t&&!t.includes(u.aggregate.type))throw new c(e.operation,u.aggregate.type);await this.#n(e.context,{...u,classification:e.definition.classification})}return o})}},s=class extends Error{code=`COMMAND_MIDDLEWARE_NEXT_REUSED`;name=`CommandMiddlewareError`;constructor(e){super(`A middleware for operation "${e}" called next() more than once`)}},c=class extends Error{code=`COMMAND_AGGREGATE_NOT_DECLARED`;name=`CommandAggregateError`;constructor(e,t){super(`Operation "${e}" audited aggregate type "${t}" outside its declared aggregates`)}},l=class extends Error{code=`COMMAND_PERMISSION_NOT_CONFIGURED`;name=`CommandPermissionError`;constructor(e){super(`Operation "${e}" declares a permission but the Foundation has no checkPermission`)}},u=class{status;Command;Query=n;observability;executeResultBoundary=r;projectResult=i;emitSemanticEvent=a;constructor(e,n){this.status=e.functions.status;let r=new t(n.observability);this.observability=r;let i=n.observability.writeAudit??(()=>void 0),a=n.checkPermission;this.Command=class extends o{constructor(e,t){super(e,{observability:r,writeAudit:i,checkPermission:a,defaults:t})}}}};export{u as Foundation};
1
+ import{Command as e,decodeCommandSchema as t,parseCommandSchema as n}from"./modules/command/command.mjs";import{Observability as r}from"./modules/observability/observability.mjs";import{Query as i}from"./modules/query/query.mjs";import{CommandPermissionError as a,executeCommandLifecycle as o,promiseLifecycle as s}from"./modules/command/lifecycle.mjs";import{executeResultBoundary as c,projectResult as l}from"./result.mjs";import{emitSemanticEvent as u}from"./telemetry.mjs";import{operationFactory as d}from"./operation.mjs";var f=class{static withContext=d;#e;#t;#n;#r;#i;aggregates;static operation(e){return e}static middleware(e){return e}constructor(t,n){this.#t=n.observability,this.#n=n.writeAudit,this.#r=n.checkPermission,this.#i=n.defaults??{},this.aggregates=Object.freeze(Object.fromEntries(Object.entries(t).map(([e,t])=>[e,t.aggregates]))),this.#e=new e({operations:t,execute:e=>this.#a(e)})}exec(e){return this.#e.exec({operation:e.operation,handler:(t,n)=>e.handler(t,n)})}async#a(e){let r=e.definition;return this.#t.observe({operation:e.operation,classification:r.classification},()=>o(s,{operation:e.operation,classification:r.classification,context:e.context,command:e.command,permission:r.permission===void 0?void 0:async()=>{if(!this.#r)throw new a(e.operation);await this.#r(e.context,{permission:r.permission,operation:e.operation})},prepare:async()=>{let t=await r.prepare?.(e.context,e.command);return t?.kind===`execute`?{kind:`execute`,complete:t.complete?async e=>{await t.complete(e)}:void 0}:t},parseReplay:t=>r.replayResult?n(r.replayResult,t):e.parseResult(t),decodeReplay:async n=>{if(!r.replayResult)return e.decodeResult?e.decodeResult(n):e.parseResult(n);let i=r.replayResult;return await t(i,n)},middleware:[...this.#i.middleware??[],...r.middleware??[]].map(e=>async t=>e({...t,definition:r,command:t.command,context:t.context,next:t.next})),defaultGuard:async e=>{await this.#i.guard?.(e)},guard:async t=>{await r.guard?.(t,e.command)},run:t=>e.runUnparsed(t),parseResult:e.parseResult,decodeResult:e.decodeResult,audit:async t=>r.audit({command:e.command,result:t},e.context),aggregates:r.aggregates,writeAudit:async t=>this.#n(e.context,t)}))}},p=class{status;Command;Query=i;observability;executeResultBoundary=c;projectResult=l;emitSemanticEvent=u;constructor(e,t){this.status=e.functions.status;let n=new r(t.observability);this.observability=n;let i=t.observability.writeAudit??(()=>void 0),a=t.checkPermission;class o extends f{constructor(e,t){super(e,{observability:n,writeAudit:i,checkPermission:a,defaults:t})}}this.Command=o}};export{p as Foundation};
2
2
  //# sourceMappingURL=client.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.mjs","names":["#kernel","#observability","#writeAudit","#checkPermission","#defaults","CommandKernelClass","#execute"],"sources":["../../../src/components/foundation/client.ts"],"sourcesContent":["import {\n\tCommand as CommandKernelClass,\n\ttype CommandExecution,\n\ttype CommandInput,\n\ttype CommandRegistry,\n\ttype CommandResult,\n} from './modules/command/command'\nimport {\n\tObservability,\n\ttype ObservabilityOptions,\n} from './modules/observability/observability'\nimport { Query } from './modules/query/query'\nimport { executeResultBoundary, projectResult } from './result'\nimport { emitSemanticEvent } from './telemetry'\n\n/** Shape handed to the injected audit writer; classification comes from the operation. */\nexport type AuditEntryInput = {\n\toperation: string\n\tactorId: string\n\taggregate: { type: string; id: string }\n\tmetadata?: Record<string, unknown>\n\tclassification: string\n}\n\nexport type AuditWriter = (\n\tcontext: never,\n\tentry: AuditEntryInput,\n) => Promise<unknown> | unknown\n\ntype MaybePromise<Value> = Value | Promise<Value>\ntype OperationKey<Operations extends CommandRegistry> = Extract<\n\tkeyof Operations,\n\tstring\n>\n\nexport type AuditedOperation = Readonly<{\n\tcommand: Readonly<{ parse: (value: unknown) => unknown }>\n\tresult: Readonly<{ parse: (value: unknown) => unknown }>\n\tclassification: string\n\t/**\n\t * Permission slug required to execute this operation. Checked through the\n\t * Foundation's injected checkPermission BEFORE guards and the handler;\n\t * declaring a permission without injecting a checker fails closed.\n\t */\n\tpermission?: string\n\t/**\n\t * Per-operation precondition, after the permission check and the registry\n\t * default guard, before the handler. Throw to deny — nothing has run yet.\n\t */\n\tguard?: (context: never, command: never) => MaybePromise<void>\n\t/**\n\t * Allowlist of aggregate types this operation's audit may reference. When\n\t * declared, an audit entry whose aggregate.type is not listed throws —\n\t * the audit vocabulary is enforced, not advisory.\n\t */\n\taggregates?: readonly string[]\n\t/** Per-operation middleware, inside the registry-wide chain. */\n\tmiddleware?: readonly AnyCommandMiddleware[]\n\taudit: (\n\t\tresolution: Readonly<{ command: never; result: never }>,\n\t\tcontext: never,\n\t) => MaybePromise<Omit<AuditEntryInput, 'classification'> | null>\n}>\n\n/**\n * Composable, next()-based middleware wrapping [guards → handler]. Runs\n * INSIDE the pipeline's invariants: after the permission check, before the\n * result-schema parse, aggregate allowlist, and audit — so middleware can\n * time, trace, enrich context (`next({ context })`), short-circuit, or\n * transform results, but can never skip authorization, return an invalid\n * result, or desynchronize audit from effects.\n */\nexport type CommandMiddleware<\n\tContext = never,\n\tExtension extends Record<string, unknown> = Record<string, unknown>,\n> = (input: {\n\toperation: string\n\tcommand: unknown\n\tcontext: Context\n\tnext: (options?: {\n\t\t/** Merged into the context handed to inner middleware, guards, handler. */\n\t\tcontext?: Extension\n\t}) => Promise<unknown>\n}) => Promise<unknown>\n\n/** Any-context middleware — what registries and operations accept. */\n// Contravariant seam: the supertype every typed CommandMiddleware<C, E>\n// assigns to (context contra-narrows to never; next's options widen to\n// unknown). Definition sites stay typed via Command.middleware.\nexport type AnyCommandMiddleware = (input: {\n\toperation: string\n\tcommand: unknown\n\tcontext: never\n\tnext: (options?: { context?: unknown }) => Promise<unknown>\n}) => Promise<unknown>\n\n/** Registry-wide defaults applied to every operation of one Command. */\nexport type CommandDefaults = Readonly<{\n\t/** Runs before every operation's own guard. Throw to deny. */\n\tguard?: (context: never) => MaybePromise<void>\n\t/** Outermost middleware, in array order, around every operation. */\n\tmiddleware?: readonly AnyCommandMiddleware[]\n}>\n\n/** Injected permission policy: throw to deny. Host semantics, kit ordering. */\nexport type PermissionChecker = (\n\tcontext: never,\n\tinput: Readonly<{ permission: string; operation: string }>,\n) => MaybePromise<void>\n\nexport type AuditedRegistry = Readonly<Record<string, AuditedOperation>>\n\nexport type FoundationOptions = Readonly<{\n\tobservability: ObservabilityOptions &\n\t\tReadonly<{\n\t\t\t/**\n\t\t\t * In-transaction audit writer used by Command. Operations that\n\t\t\t * return an audit record get it written here automatically.\n\t\t\t */\n\t\t\twriteAudit?: AuditWriter\n\t\t}>\n\t/**\n\t * Permission policy for operations that declare a `permission`. Runs\n\t * before guards and the handler; throw to deny. An operation with a\n\t * permission but no injected checker fails closed.\n\t */\n\tcheckPermission?: PermissionChecker\n}>\n\ntype FoundationComponentApi = Readonly<{\n\tfunctions: Readonly<{ status: unknown }>\n}>\n\n/**\n * Application command protocol bound to a Foundation instance:\n * validate, observe, execute, and audit. `classification` and `audit()`\n * are mandatory per operation — auditing is type-enforced, not opt-in.\n * Obtain it by destructuring the Foundation: `const { Command } = new Foundation(...)`.\n */\nclass BoundCommand<Context, const Operations extends AuditedRegistry> {\n\treadonly #kernel: CommandKernelClass<Context, Operations>\n\treadonly #observability: Observability\n\treadonly #writeAudit: AuditWriter\n\treadonly #checkPermission: PermissionChecker | undefined\n\treadonly #defaults: CommandDefaults\n\n\t/** Declared aggregate types per operation — introspectable for tests. */\n\treadonly aggregates: Readonly<{\n\t\t[Key in OperationKey<Operations>]: Operations[Key]['aggregates']\n\t}>\n\n\tstatic operation<const Definition extends AuditedOperation>(\n\t\tdefinition: Definition,\n\t): Definition {\n\t\treturn definition\n\t}\n\n\t/**\n\t * Identity helper that types a middleware against its context and the\n\t * context extension it passes downstream via next({ context }).\n\t */\n\tstatic middleware<\n\t\tContext = never,\n\t\tconst Extension extends Record<string, unknown> = Record<\n\t\t\tstring,\n\t\t\tunknown\n\t\t>,\n\t>(\n\t\tmiddleware: CommandMiddleware<Context, Extension>,\n\t): CommandMiddleware<Context, Extension> {\n\t\treturn middleware\n\t}\n\n\tconstructor(\n\t\toperations: Operations,\n\t\tdeps: {\n\t\t\tobservability: Observability\n\t\t\twriteAudit: AuditWriter\n\t\t\tcheckPermission?: PermissionChecker\n\t\t\tdefaults?: CommandDefaults\n\t\t},\n\t) {\n\t\tthis.#observability = deps.observability\n\t\tthis.#writeAudit = deps.writeAudit\n\t\tthis.#checkPermission = deps.checkPermission\n\t\tthis.#defaults = deps.defaults ?? {}\n\t\tthis.aggregates = Object.freeze(\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries(operations).map(([operation, definition]) => [\n\t\t\t\t\toperation,\n\t\t\t\t\tdefinition.aggregates,\n\t\t\t\t]),\n\t\t\t),\n\t\t) as this['aggregates']\n\t\tthis.#kernel = new CommandKernelClass<Context, Operations>({\n\t\t\toperations,\n\t\t\texecute: (execution) => this.#execute(execution),\n\t\t})\n\t}\n\n\texec<const Key extends OperationKey<Operations>>(executor: {\n\t\toperation: Key\n\t\thandler: (\n\t\t\tcontext: Context,\n\t\t\tcommand: CommandInput<Operations, Key>,\n\t\t) => MaybePromise<CommandResult<Operations, Key>>\n\t}) {\n\t\treturn this.#kernel.exec(executor)\n\t}\n\n\tasync #execute<Key extends OperationKey<Operations>>(\n\t\texecution: CommandExecution<Context, Operations, Key>,\n\t): Promise<CommandResult<Operations, Key>> {\n\t\treturn this.#observability.observe(\n\t\t\t{\n\t\t\t\toperation: execution.operation,\n\t\t\t\tclassification: execution.definition.classification,\n\t\t\t},\n\t\t\tasync () => {\n\t\t\t\t// Guards run before the handler: permission → default → operation.\n\t\t\t\tconst permission = execution.definition.permission\n\t\t\t\tif (permission !== undefined) {\n\t\t\t\t\tif (!this.#checkPermission) {\n\t\t\t\t\t\tthrow new CommandPermissionError(execution.operation)\n\t\t\t\t\t}\n\t\t\t\t\tawait this.#checkPermission(execution.context as never, {\n\t\t\t\t\t\tpermission,\n\t\t\t\t\t\toperation: execution.operation,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tconst middleware = [\n\t\t\t\t\t...(this.#defaults.middleware ?? []),\n\t\t\t\t\t...(execution.definition.middleware ?? []),\n\t\t\t\t]\n\t\t\t\tconst terminal = async (context: unknown) => {\n\t\t\t\t\tawait this.#defaults.guard?.(context as never)\n\t\t\t\t\tawait execution.definition.guard?.(\n\t\t\t\t\t\tcontext as never,\n\t\t\t\t\t\texecution.command as never,\n\t\t\t\t\t)\n\t\t\t\t\treturn execution.run(context as never)\n\t\t\t\t}\n\t\t\t\tlet deepest = -1\n\t\t\t\tconst dispatch = async (\n\t\t\t\t\tindex: number,\n\t\t\t\t\tcontext: unknown,\n\t\t\t\t): Promise<unknown> => {\n\t\t\t\t\tif (index <= deepest) {\n\t\t\t\t\t\tthrow new CommandMiddlewareError(execution.operation)\n\t\t\t\t\t}\n\t\t\t\t\tdeepest = index\n\t\t\t\t\tconst layer = middleware[index]\n\t\t\t\t\tif (!layer) return terminal(context)\n\t\t\t\t\treturn layer({\n\t\t\t\t\t\toperation: execution.operation,\n\t\t\t\t\t\tcommand: execution.command,\n\t\t\t\t\t\tcontext: context as never,\n\t\t\t\t\t\tnext: (options) =>\n\t\t\t\t\t\t\tdispatch(\n\t\t\t\t\t\t\t\tindex + 1,\n\t\t\t\t\t\t\t\toptions?.context\n\t\t\t\t\t\t\t\t\t? { ...(context as object), ...(options.context as object) }\n\t\t\t\t\t\t\t\t\t: context,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\t// Middleware may transform the return value, so the strict\n\t\t\t\t// result schema re-parses whatever leaves the chain.\n\t\t\t\tconst result = execution.parseResult(\n\t\t\t\t\tawait dispatch(0, execution.context),\n\t\t\t\t)\n\t\t\t\tconst audit = await execution.definition.audit(\n\t\t\t\t\t{ command: execution.command, result } as never,\n\t\t\t\t\texecution.context as never,\n\t\t\t\t)\n\t\t\t\tif (audit) {\n\t\t\t\t\tconst allowed = execution.definition.aggregates\n\t\t\t\t\tif (allowed && !allowed.includes(audit.aggregate.type)) {\n\t\t\t\t\t\tthrow new CommandAggregateError(\n\t\t\t\t\t\t\texecution.operation,\n\t\t\t\t\t\t\taudit.aggregate.type,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tawait this.#writeAudit(execution.context as never, {\n\t\t\t\t\t\t...audit,\n\t\t\t\t\t\tclassification: execution.definition.classification,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\treturn result\n\t\t\t},\n\t\t)\n\t}\n}\n\n/** A middleware called next() more than once. */\nclass CommandMiddlewareError extends Error {\n\treadonly code = 'COMMAND_MIDDLEWARE_NEXT_REUSED'\n\treadonly name = 'CommandMiddlewareError'\n\n\tconstructor(operation: string) {\n\t\tsuper(\n\t\t\t`A middleware for operation \"${operation}\" called next() more than once`,\n\t\t)\n\t}\n}\n\n/** The audit referenced an aggregate type outside the operation's allowlist. */\nclass CommandAggregateError extends Error {\n\treadonly code = 'COMMAND_AGGREGATE_NOT_DECLARED'\n\treadonly name = 'CommandAggregateError'\n\n\tconstructor(operation: string, aggregateType: string) {\n\t\tsuper(\n\t\t\t`Operation \"${operation}\" audited aggregate type \"${aggregateType}\" outside its declared aggregates`,\n\t\t)\n\t}\n}\n\n/** Fails closed: an operation declared a permission but no checker exists. */\nclass CommandPermissionError extends Error {\n\treadonly code = 'COMMAND_PERMISSION_NOT_CONFIGURED'\n\treadonly name = 'CommandPermissionError'\n\n\tconstructor(operation: string) {\n\t\tsuper(\n\t\t\t`Operation \"${operation}\" declares a permission but the Foundation has no checkPermission`,\n\t\t)\n\t}\n}\n\nexport type ApplicationCommand<\n\tContext,\n\tOperations extends AuditedRegistry,\n> = BoundCommand<Context, Operations>\n\n/**\n * The constructor shape a Foundation instance exposes as `Command`.\n * Exported as a TYPE ONLY so factories (e.g. cvx-kit/crud) can accept the\n * destructured facade class as input without importing any runtime kernel.\n */\nexport type CommandConstructor = {\n\tnew <Context, const Operations extends AuditedRegistry>(\n\t\toperations: Operations,\n\t\tdefaults?: CommandDefaults,\n\t): BoundCommand<Context, Operations>\n\toperation: (typeof BoundCommand)['operation']\n\tmiddleware: (typeof BoundCommand)['middleware']\n}\n\n/**\n * Host facade for a component that owns no application execution capability.\n * Declared once; the sole source of the command protocol, query kernel, and\n * observability: `const { Command, Query, observability } = new Foundation(...)`.\n */\nexport class Foundation<\n\tComponent extends FoundationComponentApi = FoundationComponentApi,\n> {\n\treadonly status: Component['functions']['status']\n\treadonly Command: CommandConstructor\n\treadonly Query = Query\n\treadonly observability: Observability\n\t/** Typed-failure boundary — see result.ts. Facade-bound like the kernels. */\n\treadonly executeResultBoundary = executeResultBoundary\n\treadonly projectResult = projectResult\n\treadonly emitSemanticEvent = emitSemanticEvent\n\n\tconstructor(component: Component, options: FoundationOptions) {\n\t\tthis.status = component.functions.status\n\t\tconst observability = new Observability(options.observability)\n\t\tthis.observability = observability\n\t\tconst writeAudit = options.observability.writeAudit ?? (() => undefined)\n\t\tconst checkPermission = options.checkPermission\n\t\tthis.Command = class <\n\t\t\tContext,\n\t\t\tconst Operations extends AuditedRegistry,\n\t\t> extends BoundCommand<Context, Operations> {\n\t\t\tconstructor(operations: Operations, defaults?: CommandDefaults) {\n\t\t\t\tsuper(operations, {\n\t\t\t\t\tobservability,\n\t\t\t\t\twriteAudit,\n\t\t\t\t\tcheckPermission,\n\t\t\t\t\tdefaults,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n}\n\n// Kernel CLASSES are deliberately NOT exported: Command, Query, and\n// Observability exist only as capabilities of a Foundation instance —\n// `const { Command, Query, observability } = new Foundation(...)`. A loose\n// import would construct kernels without the injected observability, audit\n// writer, and permission checker. Types stay exported for signatures.\nexport type {\n\tCommandExecution,\n\tCommandInput,\n\tCommandRegistry,\n\tCommandResult,\n\tParseable,\n} from './modules/command/command'\nexport type {\n\tCommandObservation,\n\tObservabilityOptions,\n} from './modules/observability/observability'\nexport type {\n\tAnyQueryMiddleware,\n\tQueryExecution,\n\tQueryMiddleware,\n} from './modules/query/query'\nexport type {\n\tResult,\n\tResultBoundary,\n\tTransactionMetricsContext,\n} from './result'\n\n// The component definition is deliberately NOT re-exported here: Convex's\n// CLI only discovers a component whose resolved file is convex.config.js,\n// so hosts must mount via the dedicated subpath:\n// import foundation from 'cvx-kit/components/foundation/convex.config'\n"],"mappings":"gTA2IA,IAAM,EAAN,KAAsE,CACrE,GACA,GACA,GACA,GACA,GAGA,WAIA,OAAO,UACN,EACa,CACb,OAAO,CACR,CAMA,OAAO,WAON,EACwC,CACxC,OAAO,CACR,CAEA,YACC,EACA,EAMC,CACD,KAAKC,GAAiB,EAAK,cAC3B,KAAKC,GAAc,EAAK,WACxB,KAAKC,GAAmB,EAAK,gBAC7B,KAAKC,GAAY,EAAK,UAAY,CAAC,EACnC,KAAK,WAAa,OAAO,OACxB,OAAO,YACN,OAAO,QAAQ,CAAU,CAAC,CAAC,KAAK,CAAC,EAAW,KAAgB,CAC3D,EACA,EAAW,UACZ,CAAC,CACF,CACD,EACA,KAAKJ,GAAU,IAAIK,EAAwC,CAC1D,aACA,QAAU,GAAc,KAAKC,GAAS,CAAS,CAChD,CAAC,CACF,CAEA,KAAiD,EAM9C,CACF,OAAO,KAAKN,GAAQ,KAAK,CAAQ,CAClC,CAEA,KAAMM,GACL,EAC0C,CAC1C,OAAO,KAAKL,GAAe,QAC1B,CACC,UAAW,EAAU,UACrB,eAAgB,EAAU,WAAW,cACtC,EACA,SAAY,CAEX,IAAM,EAAa,EAAU,WAAW,WACxC,GAAI,IAAe,IAAA,GAAW,CAC7B,GAAI,CAAC,KAAKE,GACT,MAAM,IAAI,EAAuB,EAAU,SAAS,EAErD,MAAM,KAAKA,GAAiB,EAAU,QAAkB,CACvD,aACA,UAAW,EAAU,SACtB,CAAC,CACF,CACA,IAAM,EAAa,CAClB,GAAI,KAAKC,GAAU,YAAc,CAAC,EAClC,GAAI,EAAU,WAAW,YAAc,CAAC,CACzC,EACM,EAAW,KAAO,KACvB,MAAM,KAAKA,GAAU,QAAQ,CAAgB,EAC7C,MAAM,EAAU,WAAW,QAC1B,EACA,EAAU,OACX,EACO,EAAU,IAAI,CAAgB,GAElC,EAAU,GACR,EAAW,MAChB,EACA,IACsB,CACtB,GAAI,GAAS,EACZ,MAAM,IAAI,EAAuB,EAAU,SAAS,EAErD,EAAU,EACV,IAAM,EAAQ,EAAW,GAEzB,OADK,EACE,EAAM,CACZ,UAAW,EAAU,UACrB,QAAS,EAAU,QACV,UACT,KAAO,GACN,EACC,EAAQ,EACR,GAAS,QACN,CAAE,GAAI,EAAoB,GAAI,EAAQ,OAAmB,EACzD,CACJ,CACF,CAAC,EAZkB,EAAS,CAAO,CAapC,EAGM,EAAS,EAAU,YACxB,MAAM,EAAS,EAAG,EAAU,OAAO,CACpC,EACM,EAAQ,MAAM,EAAU,WAAW,MACxC,CAAE,QAAS,EAAU,QAAS,QAAO,EACrC,EAAU,OACX,EACA,GAAI,EAAO,CACV,IAAM,EAAU,EAAU,WAAW,WACrC,GAAI,GAAW,CAAC,EAAQ,SAAS,EAAM,UAAU,IAAI,EACpD,MAAM,IAAI,EACT,EAAU,UACV,EAAM,UAAU,IACjB,EAED,MAAM,KAAKF,GAAY,EAAU,QAAkB,CAClD,GAAG,EACH,eAAgB,EAAU,WAAW,cACtC,CAAC,CACF,CACA,OAAO,CACR,CACD,CACD,CACD,EAGM,EAAN,cAAqC,KAAM,CAC1C,KAAgB,iCAChB,KAAgB,yBAEhB,YAAY,EAAmB,CAC9B,MACC,+BAA+B,EAAU,+BAC1C,CACD,CACD,EAGM,EAAN,cAAoC,KAAM,CACzC,KAAgB,iCAChB,KAAgB,wBAEhB,YAAY,EAAmB,EAAuB,CACrD,MACC,cAAc,EAAU,4BAA4B,EAAc,kCACnE,CACD,CACD,EAGM,EAAN,cAAqC,KAAM,CAC1C,KAAgB,oCAChB,KAAgB,yBAEhB,YAAY,EAAmB,CAC9B,MACC,cAAc,EAAU,kEACzB,CACD,CACD,EA0Ba,EAAb,KAEE,CACD,OACA,QACA,MAAiB,EACjB,cAEA,sBAAiC,EACjC,cAAyB,EACzB,kBAA6B,EAE7B,YAAY,EAAsB,EAA4B,CAC7D,KAAK,OAAS,EAAU,UAAU,OAClC,IAAM,EAAgB,IAAI,EAAc,EAAQ,aAAa,EAC7D,KAAK,cAAgB,EACrB,IAAM,EAAa,EAAQ,cAAc,iBAAqB,IAAA,IACxD,EAAkB,EAAQ,gBAChC,KAAK,QAAU,cAGL,CAAkC,CAC3C,YAAY,EAAwB,EAA4B,CAC/D,MAAM,EAAY,CACjB,gBACA,aACA,kBACA,UACD,CAAC,CACF,CACD,CACD,CACD"}
1
+ {"version":3,"file":"client.mjs","names":["CommandKernelClass","BoundCommand","operationFactory","definition","middleware","#observability","deps","#writeAudit","#checkPermission","#defaults","operations","operation","#kernel","Command","#execute","execution","executor","context","command","executeCommandLifecycle","promiseLifecycle","CommandPermissionError","preparation","result","parseCommandSchema","value","replay","decodeCommandSchema","layer","input","entry","Foundation","Query","executeResultBoundary","projectResult","emitSemanticEvent","component","observability","Observability","options","writeAudit","checkPermission","HostCommand"],"sources":["../../../src/components/foundation/client.ts"],"sourcesContent":["import type { Value } from 'convex/values'\nimport {\n\tCommand as CommandKernelClass,\n\ttype CommandExecution,\n\ttype CommandHandlerResult,\n\ttype CommandInput,\n\ttype CommandRegistry,\n\ttype CommandResult,\n\ttype CommandSchema,\n\tdecodeCommandSchema,\n\tparseCommandSchema,\n} from './modules/command/command'\nimport { Observability, type ObservabilityOptions } from './modules/observability/observability'\nimport { Query } from './modules/query/query'\nimport {\n\texecuteCommandLifecycle,\n\tpromiseLifecycle,\n\tCommandPermissionError,\n\ttype PromiseExecution,\n} from './modules/command/lifecycle'\nimport { executeResultBoundary, projectResult } from './result'\nimport { emitSemanticEvent } from './telemetry'\nimport {\n\toperationFactory,\n\ttype CommandPreparation,\n\ttype OperationExtension,\n\ttype OperationHostContext,\n} from './operation'\n\n/** Shape handed to the injected audit writer; classification comes from the operation. */\nexport type AuditEntryInput = {\n\toperation: string\n\tactorId: string\n\taggregate: { type: string; id: string }\n\tmetadata?: Record<string, Value>\n\tclassification: string\n}\n\nexport type AuditWriter<Result = unknown> = (\n\tcontext: never,\n\tentry: AuditEntryInput,\n) => MaybePromise<Result>\n\ntype MaybePromise<Value> = Value | Promise<Value>\ntype OperationKey<Operations extends CommandRegistry> = Extract<keyof Operations, string>\n\nexport type AuditedOperation = Readonly<{\n\tcommand: CommandSchema\n\tresult: CommandSchema\n\tclassification: string\n\t/**\n\t * Permission slug required to execute this operation. Checked through the\n\t * Foundation's injected checkPermission BEFORE guards and the handler;\n\t * declaring a permission without injecting a checker fails closed.\n\t */\n\tpermission?: string\n\tprepare?: (context: never, command: never) => MaybePromise<CommandPreparation<never>>\n\treplayResult?: CommandSchema\n\t/**\n\t * Per-operation precondition, after the permission check and the registry\n\t * default guard, before the handler. Throw to deny — nothing has run yet.\n\t */\n\tguard?: (context: never, command: never) => MaybePromise<void>\n\t/**\n\t * Allowlist of aggregate types this operation's audit may reference. When\n\t * declared, an audit entry whose aggregate.type is not listed throws —\n\t * the audit vocabulary is enforced, not advisory.\n\t */\n\taggregates?: readonly string[]\n\t/** Per-operation middleware, inside the registry-wide chain. */\n\tmiddleware?: readonly AnyCommandMiddleware[]\n\taudit: (\n\t\tresolution: Readonly<{ command: never; result: never }>,\n\t\tcontext: never,\n\t) => MaybePromise<Omit<AuditEntryInput, 'classification'> | null>\n}>\n\n/**\n * Composable, next()-based middleware wrapping [guards → handler]. Runs\n * INSIDE the pipeline's invariants: after the permission check, before the\n * result-schema parse, aggregate allowlist, and audit — so middleware can\n * time, trace, enrich context (`next({ context })`), short-circuit, or\n * transform results, but can never skip authorization, return an invalid\n * result, or desynchronize audit from effects.\n */\nexport type CommandMiddleware<\n\tContext = never,\n\tExtension extends object = object,\n\tInput = unknown,\n\tResult = unknown,\n> = (input: {\n\toperation: string\n\tcommand: Input\n\tcontext: Context\n\tnext: (options?: {\n\t\t/** Merged into the context handed to inner middleware, guards, handler. */\n\t\tcontext?: Extension\n\t}) => Promise<Result>\n}) => Promise<Result>\n\n/** Any-context middleware — what registries and operations accept. */\n// Contravariant seam: the supertype every typed CommandMiddleware<C, E>\n// assigns to. Context, command, and next are contravariant storage slots;\n// dispatch restores the selected operation's types before invocation.\nexport type AnyCommandMiddleware<Input = never, Result = unknown, NextResult = never> = (input: {\n\toperation: string\n\tdefinition?: AuditedOperation\n\tcommand: Input\n\tcontext: never\n\tnext: (options?: { context?: object }) => Promise<NextResult>\n}) => Promise<Result>\n\n/** Registry-wide defaults applied to every operation of one Command. */\nexport type CommandDefaults = Readonly<{\n\t/** Runs before every operation's own guard. Throw to deny. */\n\tguard?: (context: never) => MaybePromise<void>\n\t/** Outermost middleware, in array order, around every operation. */\n\tmiddleware?: readonly AnyCommandMiddleware[]\n}>\n\n/** Injected permission policy: throw to deny. Host semantics, kit ordering. */\nexport type PermissionChecker = (\n\tcontext: never,\n\tinput: Readonly<{ permission: string; operation: string }>,\n) => MaybePromise<void>\n\nexport type AuditedRegistry = Readonly<Record<string, AuditedOperation>>\n\nexport type FoundationOptions = Readonly<{\n\tobservability: ObservabilityOptions &\n\t\tReadonly<{\n\t\t\t/**\n\t\t\t * In-transaction audit writer used by Command. Operations that\n\t\t\t * return an audit record get it written here automatically.\n\t\t\t */\n\t\t\twriteAudit?: AuditWriter\n\t\t}>\n\t/**\n\t * Permission policy for operations that declare a `permission`. Runs\n\t * before guards and the handler; throw to deny. An operation with a\n\t * permission but no injected checker fails closed.\n\t */\n\tcheckPermission?: PermissionChecker\n}>\n\ntype FoundationComponentApi = Readonly<{\n\tfunctions: Readonly<{ status: unknown }>\n}>\n\n/**\n * Application command protocol bound to a Foundation instance:\n * validate, observe, execute, and audit. `classification` and `audit()`\n * are mandatory per operation — auditing is type-enforced, not opt-in.\n * Obtain it by destructuring the Foundation: `const { Command } = new Foundation(...)`.\n */\nclass BoundCommand<Context, const Operations extends AuditedRegistry> {\n\tstatic withContext = operationFactory\n\treadonly #kernel: CommandKernelClass<Context, Operations>\n\treadonly #observability: Observability\n\treadonly #writeAudit: AuditWriter\n\treadonly #checkPermission: PermissionChecker | undefined\n\treadonly #defaults: CommandDefaults\n\n\t/** Declared aggregate types per operation — introspectable for tests. */\n\treadonly aggregates: Readonly<{\n\t\t[Key in OperationKey<Operations>]: Operations[Key]['aggregates']\n\t}>\n\n\tstatic operation<const Definition extends AuditedOperation>(definition: Definition): Definition {\n\t\treturn definition\n\t}\n\n\t/**\n\t * Identity helper that types a middleware against its context and the\n\t * context extension it passes downstream via next({ context }).\n\t */\n\tstatic middleware<\n\t\tContext = never,\n\t\tconst Extension extends object = object,\n\t\tInput = unknown,\n\t\tResult = unknown,\n\t>(\n\t\tmiddleware: CommandMiddleware<Context, Extension, Input, Result>,\n\t): CommandMiddleware<Context, Extension, Input, Result> {\n\t\treturn middleware\n\t}\n\n\tconstructor(\n\t\toperations: Operations,\n\t\tdeps: {\n\t\t\tobservability: Observability\n\t\t\twriteAudit: AuditWriter\n\t\t\tcheckPermission?: PermissionChecker\n\t\t\tdefaults?: CommandDefaults\n\t\t},\n\t) {\n\t\tthis.#observability = deps.observability\n\t\tthis.#writeAudit = deps.writeAudit\n\t\tthis.#checkPermission = deps.checkPermission\n\t\tthis.#defaults = deps.defaults ?? {}\n\t\t// SAFETY: this map preserves every operations key and selects its aggregates property.\n\t\tthis.aggregates = Object.freeze(\n\t\t\tObject.fromEntries(\n\t\t\t\tObject.entries(operations).map(([operation, definition]) => [\n\t\t\t\t\toperation,\n\t\t\t\t\tdefinition.aggregates,\n\t\t\t\t]),\n\t\t\t),\n\t\t) as this['aggregates']\n\t\tthis.#kernel = new CommandKernelClass<Context, Operations>({\n\t\t\toperations,\n\t\t\texecute: (execution) => this.#execute(execution),\n\t\t})\n\t}\n\n\t/**\n\t * @deprecated Declare handlers inside command({...}) using createEffectFoundation\n\t * from cvx-kit/effect, then call exec(operation, input, host).\n\t */\n\texec<const Key extends OperationKey<Operations>>(executor: {\n\t\toperation: Key\n\t\thandler: (\n\t\t\tcontext: Context & OperationExtension<Operations[Key]>,\n\t\t\tcommand: CommandInput<Operations, Key>,\n\t\t) => MaybePromise<CommandHandlerResult<Operations, Key>>\n\t}) {\n\t\treturn this.#kernel.exec({\n\t\t\toperation: executor.operation,\n\t\t\thandler: (context, command) =>\n\t\t\t\texecutor.handler(\n\t\t\t\t\t// SAFETY: operationFactory requires enrichment middleware before this handler.\n\t\t\t\t\tcontext as Context & OperationExtension<Operations[Key]>,\n\t\t\t\t\tcommand,\n\t\t\t\t),\n\t\t})\n\t}\n\n\tasync #execute<Key extends OperationKey<Operations>>(\n\t\texecution: CommandExecution<Context, Operations, Key>,\n\t): Promise<CommandResult<Operations, Key>> {\n\t\tconst definition = execution.definition\n\t\treturn this.#observability.observe(\n\t\t\t{ operation: execution.operation, classification: definition.classification },\n\t\t\t() =>\n\t\t\t\texecuteCommandLifecycle<\n\t\t\t\t\tPromiseExecution,\n\t\t\t\t\tContext,\n\t\t\t\t\tCommandInput<Operations, Key>,\n\t\t\t\t\tCommandHandlerResult<Operations, Key>,\n\t\t\t\t\tCommandResult<Operations, Key>\n\t\t\t\t>(promiseLifecycle, {\n\t\t\t\t\toperation: execution.operation,\n\t\t\t\t\tclassification: definition.classification,\n\t\t\t\t\tcontext: execution.context,\n\t\t\t\t\tcommand: execution.command,\n\t\t\t\t\tpermission:\n\t\t\t\t\t\tdefinition.permission === undefined\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: async () => {\n\t\t\t\t\t\t\t\t\tif (!this.#checkPermission) throw new CommandPermissionError(execution.operation)\n\t\t\t\t\t\t\t\t\t// SAFETY: injected policy consumes this invocation's original host context.\n\t\t\t\t\t\t\t\t\tawait this.#checkPermission(execution.context as never, {\n\t\t\t\t\t\t\t\t\t\tpermission: definition.permission!,\n\t\t\t\t\t\t\t\t\t\toperation: execution.operation,\n\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\tprepare: async () => {\n\t\t\t\t\t\t// SAFETY: selected definition and parsed input are paired by the kernel.\n\t\t\t\t\t\tconst preparation = await definition.prepare?.(\n\t\t\t\t\t\t\texecution.context as never,\n\t\t\t\t\t\t\texecution.command as never,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (preparation?.kind !== 'execute') return preparation\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tkind: 'execute' as const,\n\t\t\t\t\t\t\tcomplete: preparation.complete\n\t\t\t\t\t\t\t\t? async (result: CommandResult<Operations, Key>) => {\n\t\t\t\t\t\t\t\t\t\t// SAFETY: completion belongs to this operation's validated final result.\n\t\t\t\t\t\t\t\t\t\tawait preparation.complete!(result as never)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tparseReplay: (value) => {\n\t\t\t\t\t\tif (!definition.replayResult) return execution.parseResult(value)\n\t\t\t\t\t\t// SAFETY: selected replay schema validates this operation's stored output.\n\t\t\t\t\t\treturn parseCommandSchema(definition.replayResult, value) as CommandResult<\n\t\t\t\t\t\t\tOperations,\n\t\t\t\t\t\t\tKey\n\t\t\t\t\t\t>\n\t\t\t\t\t},\n\t\t\t\t\tdecodeReplay: async (value) => {\n\t\t\t\t\t\tif (!definition.replayResult) {\n\t\t\t\t\t\t\treturn execution.decodeResult\n\t\t\t\t\t\t\t\t? execution.decodeResult(value)\n\t\t\t\t\t\t\t\t: execution.parseResult(value)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst replay = definition.replayResult\n\t\t\t\t\t\t// SAFETY: selected replay decoder owns the final output representation.\n\t\t\t\t\t\treturn (await decodeCommandSchema(replay, value)) as CommandResult<Operations, Key>\n\t\t\t\t\t},\n\t\t\t\t\tmiddleware: [...(this.#defaults.middleware ?? []), ...(definition.middleware ?? [])].map(\n\t\t\t\t\t\t(layer) => async (input) => {\n\t\t\t\t\t\t\t// SAFETY: selected definition owns this heterogeneous middleware's pre-validation output.\n\t\t\t\t\t\t\treturn layer({\n\t\t\t\t\t\t\t\t...input,\n\t\t\t\t\t\t\t\tdefinition,\n\t\t\t\t\t\t\t\t// SAFETY: selected command schema owns this heterogeneous storage value.\n\t\t\t\t\t\t\t\tcommand: input.command as never,\n\t\t\t\t\t\t\t\t// SAFETY: only heterogeneous storage erases the selected middleware context.\n\t\t\t\t\t\t\t\tcontext: input.context as never,\n\t\t\t\t\t\t\t\t// SAFETY: selected operation pairs downstream output with its final schema.\n\t\t\t\t\t\t\t\tnext: input.next as (options?: { context?: object }) => Promise<never>,\n\t\t\t\t\t\t\t}) as Promise<CommandHandlerResult<Operations, Key>>\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t\tdefaultGuard: async (context) => {\n\t\t\t\t\t\t// SAFETY: default guards consume the downstream middleware context.\n\t\t\t\t\t\tawait this.#defaults.guard?.(context as never)\n\t\t\t\t\t},\n\t\t\t\t\tguard: async (context) => {\n\t\t\t\t\t\t// SAFETY: selected guard consumes its parsed input and enriched context.\n\t\t\t\t\t\tawait definition.guard?.(context as never, execution.command as never)\n\t\t\t\t\t},\n\t\t\t\t\trun: (context) => execution.runUnparsed(context),\n\t\t\t\t\tparseResult: execution.parseResult,\n\t\t\t\t\tdecodeResult: execution.decodeResult,\n\t\t\t\t\taudit: async (result) => {\n\t\t\t\t\t\t// SAFETY: audit receives this selected parsed command/result and original context.\n\t\t\t\t\t\treturn definition.audit(\n\t\t\t\t\t\t\t{ command: execution.command, result } as never,\n\t\t\t\t\t\t\texecution.context as never,\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t\taggregates: definition.aggregates,\n\t\t\t\t\twriteAudit: async (entry) => {\n\t\t\t\t\t\t// SAFETY: host supplied writer for this invocation's original context.\n\t\t\t\t\t\treturn this.#writeAudit(execution.context as never, entry)\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t)\n\t}\n}\n\n/** @deprecated Use the registry returned by createEffectFoundation(...).Command from cvx-kit/effect. */\nexport type ApplicationCommand<Context, Operations extends AuditedRegistry> = BoundCommand<\n\tContext,\n\tOperations\n>\n\n/**\n * The constructor shape a Foundation instance exposes as `Command`.\n * Exported as a TYPE ONLY so factories (e.g. cvx-kit/crud) can accept the\n * destructured facade class as input without importing any runtime kernel.\n * @deprecated Use createEffectFoundation from cvx-kit/effect and declare handlers inside command({...}).\n */\nexport type CommandConstructor = {\n\t/** @deprecated Use createEffectFoundation(...).Command({ context, operations }) from cvx-kit/effect. */\n\tnew <Context, const Operations extends AuditedRegistry>(\n\t\toperations: Operations & {\n\t\t\treadonly [Key in keyof Operations]: OperationHostContext<Context>\n\t\t},\n\t\tdefaults?: CommandDefaults,\n\t): BoundCommand<Context, Operations>\n\toperation: (typeof BoundCommand)['operation']\n\twithContext: (typeof BoundCommand)['withContext']\n\tmiddleware: (typeof BoundCommand)['middleware']\n}\n\n/**\n * Host facade for a component that owns no application execution capability.\n * Declared once; the sole source of the command protocol, query kernel, and\n * observability: `const { Command, Query, observability } = new Foundation(...)`.\n */\nexport class Foundation<Component extends FoundationComponentApi = FoundationComponentApi> {\n\treadonly status: Component['functions']['status']\n\t/** @deprecated Use createEffectFoundation(...).Command from cvx-kit/effect. */\n\treadonly Command: CommandConstructor\n\treadonly Query = Query\n\treadonly observability: Observability\n\t/** Typed-failure boundary — see result.ts. Facade-bound like the kernels. */\n\treadonly executeResultBoundary = executeResultBoundary\n\treadonly projectResult = projectResult\n\treadonly emitSemanticEvent = emitSemanticEvent\n\n\tconstructor(component: Component, options: FoundationOptions) {\n\t\tthis.status = component.functions.status\n\t\tconst observability = new Observability(options.observability)\n\t\tthis.observability = observability\n\t\tconst writeAudit = options.observability.writeAudit ?? (() => undefined)\n\t\tconst checkPermission = options.checkPermission\n\t\tclass HostCommand<Context, const Operations extends AuditedRegistry> extends BoundCommand<\n\t\t\tContext,\n\t\t\tOperations\n\t\t> {\n\t\t\tconstructor(operations: Operations, defaults?: CommandDefaults) {\n\t\t\t\tsuper(operations, {\n\t\t\t\t\tobservability,\n\t\t\t\t\twriteAudit,\n\t\t\t\t\tcheckPermission,\n\t\t\t\t\tdefaults,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tthis.Command = HostCommand\n\t}\n}\n\n// Kernel CLASSES are deliberately NOT exported: Command, Query, and\n// Observability exist only as capabilities of a Foundation instance —\n// `const { Command, Query, observability } = new Foundation(...)`. A loose\n// import would construct kernels without the injected observability, audit\n// writer, and permission checker. Types stay exported for signatures.\nexport type { CommandPreparation, TypedOperation } from './operation'\nexport type {\n\tCommandArgument,\n\tCommandExecution,\n\tCommandHandlerResult,\n\tCommandInput,\n\tCommandRegistry,\n\tCommandResult,\n\tSchemaOutput,\n\tParseable,\n} from './modules/command/command'\nexport type {\n\tCommandObservation,\n\tObservabilityOptions,\n} from './modules/observability/observability'\nexport type { AnyQueryMiddleware, QueryExecution, QueryMiddleware } from './modules/query/query'\nexport type { Result, ResultBoundary, TransactionMetricsContext } from './result'\n\n// The component definition is deliberately NOT re-exported here: Convex's\n// CLI only discovers a component whose resolved file is convex.config.js,\n// so hosts must mount via the dedicated subpath:\n// import foundation from 'cvx-kit/components/foundation/convex.config'\n"],"mappings":"A,ghBA2JA,IAAMC,EAAN,KAAsE,CACrE,OAAO,YAAcC,EACrB,GACA,GACA,GACA,GACA,GAGA,WAIA,OAAO,UAAqD,EAAoC,CAC/F,OAAOC,CACR,CAMA,OAAO,WAMN,EACuD,CACvD,OAAOC,CACR,CAEA,YACC,EACA,EAMC,CACD,KAAKC,GAAiBC,EAAK,cAC3B,KAAKC,GAAcD,EAAK,WACxB,KAAKE,GAAmBF,EAAK,gBAC7B,KAAKG,GAAYH,EAAK,UAAY,CAAC,EAEnC,KAAK,WAAa,OAAO,OACxB,OAAO,YACN,OAAO,QAAQI,CAAU,CAAC,CAAC,KAAK,CAACC,EAAWR,KAAgB,CAC3DQ,EACAR,EAAW,UACZ,CAAC,CACF,CACD,EACA,KAAKS,GAAU,IAAIZ,EAAwC,CAC1D,aACA,QAAU,GAAc,KAAKc,GAASC,CAAS,CAChD,CAAC,CACF,CAMA,KAAiD,EAM9C,CACF,OAAO,KAAKH,GAAQ,KAAK,CACxB,UAAWI,EAAS,UACpB,SAAU,EAAS,IAClBA,EAAS,QAERC,EACAC,CACD,CACF,CAAC,CACF,CAEA,KAAMJ,GACL,EAC0C,CAC1C,IAAMX,EAAaY,EAAU,WAC7B,OAAO,KAAKV,GAAe,QAC1B,CAAE,UAAWU,EAAU,UAAW,eAAgBZ,EAAW,cAAe,MAE3EgB,EAMEC,EAAkB,CACnB,UAAWL,EAAU,UACrB,eAAgBZ,EAAW,eAC3B,QAASY,EAAU,QACnB,QAASA,EAAU,QACnB,WACCZ,EAAW,aAAe,IAAA,GACvB,IAAA,GACA,SAAY,CACZ,GAAI,CAAC,KAAKK,GAAkB,MAAM,IAAIa,EAAuBN,EAAU,SAAS,EAEhF,MAAM,KAAKP,GAAiBO,EAAU,QAAkB,CACvD,WAAYZ,EAAW,WACvB,UAAWY,EAAU,SACtB,CAAC,CACF,EACH,QAAS,SAAY,CAEpB,IAAMO,EAAc,MAAMnB,EAAW,UACpCY,EAAU,QACVA,EAAU,OACX,EAEA,OADIO,GAAa,OAAS,UACnB,CACN,KAAM,UACN,SAAUA,EAAY,SACnB,KAAO,IAA2C,CAElD,MAAMA,EAAY,SAAUC,CAAe,CAC5C,EACC,IAAA,EACJ,EAT4CD,CAU7C,EACA,YAAc,GACRnB,EAAW,aAETqB,EAAmBrB,EAAW,aAAcsB,CAAK,EAFnBV,EAAU,YAAYU,CAAK,EAOjE,aAAc,KAAO,IAAU,CAC9B,GAAI,CAACtB,EAAW,aACf,OAAOY,EAAU,aACdA,EAAU,aAAaU,CAAK,EAC5BV,EAAU,YAAYU,CAAK,EAE/B,IAAMC,EAASvB,EAAW,aAE1B,OAAQ,MAAMwB,EAAoBD,EAAQD,CAAK,CAChD,EACA,WAAY,CAAC,GAAI,KAAKhB,GAAU,YAAc,CAAC,EAAI,GAAIN,EAAW,YAAc,CAAC,CAAE,CAAC,CAAC,IACnF,GAAU,KAAO,IAEVyB,EAAM,CACZ,GAAGC,EACH,aAEA,QAASA,EAAM,QAEf,QAASA,EAAM,QAEf,KAAMA,EAAM,IACb,CAAC,CAEH,EACA,aAAc,KAAO,IAAY,CAEhC,MAAM,KAAKpB,GAAU,QAAQQ,CAAgB,CAC9C,EACA,MAAO,KAAO,IAAY,CAEzB,MAAMd,EAAW,QAAQc,EAAkBF,EAAU,OAAgB,CACtE,EACA,IAAM,GAAYA,EAAU,YAAYE,CAAO,EAC/C,YAAaF,EAAU,YACvB,aAAcA,EAAU,aACxB,MAAO,KAAO,IAENZ,EAAW,MACjB,CAAE,QAASY,EAAU,QAAS,QAAO,EACrCA,EAAU,OACX,EAED,WAAYZ,EAAW,WACvB,WAAY,KAAO,IAEX,KAAKI,GAAYQ,EAAU,QAAkBe,CAAK,CAE3D,CAAC,CACH,CACD,CACD,EAgCaC,EAAb,KAA2F,CAC1F,OAEA,QACA,MAAiBC,EACjB,cAEA,sBAAiCC,EACjC,cAAyBC,EACzB,kBAA6BC,EAE7B,YAAY,EAAsB,EAA4B,CAC7D,KAAK,OAASC,EAAU,UAAU,OAClC,IAAMC,EAAgB,IAAIC,EAAcC,EAAQ,aAAa,EAC7D,KAAK,cAAgBF,EACrB,IAAMG,EAAaD,EAAQ,cAAc,iBAAqB,IAAA,IACxDE,EAAkBF,EAAQ,gBAChC,MAAMG,UAAuEzC,CAG3E,CACD,YAAY,EAAwB,EAA4B,CAC/D,MAAMS,EAAY,CACjB,gBACA,aACA,kBACA,UACD,CAAC,CACF,CACD,CACA,KAAK,QAAUgC,CAChB,CACD,E"}
@@ -1,5 +1,3 @@
1
- //#region src/components/foundation/convex.config.d.ts
2
1
  declare const _default: import("convex/server").ComponentDefinition<any, {}>;
3
- //#endregion
4
2
  export { _default as default };
5
3
  //# sourceMappingURL=convex.config.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convex.config.mjs","names":[],"sources":["../../../src/components/foundation/convex.config.ts"],"sourcesContent":["import { defineComponent } from 'convex/server'\n\nexport default defineComponent('foundation')\n"],"mappings":"gDAEA,IAAA,EAAe,EAAgB,YAAY"}
1
+ {"version":3,"file":"convex.config.mjs","names":["convex_config_default","defineComponent"],"sources":["../../../src/components/foundation/convex.config.ts"],"sourcesContent":["import { defineComponent } from 'convex/server'\n\nexport default defineComponent('foundation')\n"],"mappings":"A,gDAEA,IAAAA,EAAeC,EAAgB,YAAY,E"}
@@ -2,7 +2,6 @@ declare namespace functions_d_exports {
2
2
  export { status };
3
3
  }
4
4
  /** Minimal health signal exposed only through the configured host facade. */
5
- declare const status: import("convex/server").RegisteredQuery<"public", {}, Promise<"ready">>;
6
- //#endregion
7
- export { functions_d_exports, status };
5
+ export declare const status: import("convex/server").RegisteredQuery<"public", {}, Promise<"ready">>;
6
+ export { functions_d_exports };
8
7
  //# sourceMappingURL=functions.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"functions.mjs","names":[],"sources":["../../../src/components/foundation/functions.ts"],"sourcesContent":["import { v } from 'convex/values'\n\nimport { query } from './_generated/server'\n\n/** Minimal health signal exposed only through the configured host facade. */\nexport const status = query({\n\targs: {},\n\treturns: v.literal('ready'),\n\thandler: async () => 'ready' as const,\n})\n"],"mappings":"kFAKA,MAAa,EAAS,EAAM,CAC3B,KAAM,CAAC,EACP,QAAS,EAAE,QAAQ,OAAO,EAC1B,QAAS,SAAY,OACtB,CAAC"}
1
+ {"version":3,"file":"functions.mjs","names":["status","query","v"],"sources":["../../../src/components/foundation/functions.ts"],"sourcesContent":["import { v } from 'convex/values'\n\nimport { query } from './_generated/server'\n\n/** Minimal health signal exposed only through the configured host facade. */\nexport const status = query({\n\targs: {},\n\treturns: v.literal('ready'),\n\thandler: async () => 'ready' as const,\n})\n"],"mappings":"A,kFAKA,MAAaA,EAASC,EAAM,CAC3B,KAAM,CAAC,EACP,QAASC,EAAE,QAAQ,OAAO,EAC1B,QAAS,SAAY,OACtB,CAAC,E"}
@@ -1,48 +1,96 @@
1
1
  declare namespace command_d_exports {
2
- export { Command, CommandExecution, CommandInput, CommandRegistry, CommandResult, Parseable };
2
+ export { Command, CommandArgument, CommandExecution, CommandHandlerResult, CommandInput, CommandRegistry, CommandResult, CommandSchema, Parseable, SchemaInput, SchemaOutput, decodeCommandSchema, parseCommandSchema };
3
3
  }
4
- type Parseable<Output> = Readonly<{
5
- parse: (value: unknown) => Output;
4
+ export type Parseable<Output> = Readonly<{
5
+ parse: <Input>(value: Input) => Output;
6
+ parseAsync?: <Input>(value: Input) => Promise<Output>;
6
7
  }>;
7
- type CommandRegistry = Readonly<Record<string, CommandDefinition>>;
8
- type CommandInput<Registry extends CommandRegistry, Key extends Operation<Registry>> = Parsed<Registry[Key]['command']>;
9
- type CommandResult<Registry extends CommandRegistry, Key extends Operation<Registry>> = Parsed<Registry[Key]['result']>;
10
- type CommandExecution<Context, Registry extends CommandRegistry, Key extends Operation<Registry>> = Readonly<{
8
+ /** Structural mirror of portable neutral contracts: components cannot import host modules. */
9
+ interface ValidationIssue {
10
+ readonly message: string;
11
+ readonly path?: readonly (PropertyKey | {
12
+ readonly key: PropertyKey;
13
+ })[];
14
+ }
15
+ type ValidationResult<Output> = {
16
+ readonly value: Output;
17
+ readonly issues?: undefined;
18
+ } | {
19
+ readonly issues: readonly ValidationIssue[];
20
+ };
21
+ interface StandardSchema<Input = unknown, Output = unknown> {
22
+ readonly '~standard': {
23
+ readonly version: 1;
24
+ readonly vendor: string;
25
+ readonly types?: {
26
+ readonly input: Input;
27
+ readonly output: Output;
28
+ };
29
+ readonly validate: (value: unknown) => ValidationResult<Output> | Promise<ValidationResult<Output>>;
30
+ };
31
+ }
32
+ interface NeutralDecoder<Input = unknown, Output = unknown, Execution = unknown> {
33
+ readonly kind: 'contract';
34
+ readonly types?: {
35
+ readonly input: Input;
36
+ readonly output: Output;
37
+ };
38
+ readonly decode: (value: unknown) => Execution;
39
+ }
40
+ export type CommandSchema<Output = unknown> = Parseable<Output> | StandardSchema<unknown, Output> | NeutralDecoder<unknown, Output, ValidationResult<Output> | Promise<ValidationResult<Output>>>;
41
+ /** Raw values accepted before decoding, including transform inputs. */
42
+ export type SchemaInput<Schema extends CommandSchema> = Schema extends NeutralDecoder<infer Input, unknown, unknown> ? Input : Schema extends {
43
+ _input: infer Input;
44
+ } ? Input : Schema extends StandardSchema<infer Input, unknown> ? Input : SchemaOutput<Schema>;
45
+ export type SchemaOutput<Schema extends CommandSchema> = Schema extends Parseable<unknown> ? ReturnType<Schema['parse']> : Schema extends NeutralDecoder<unknown, infer Output, unknown> ? Output : Schema extends StandardSchema<unknown, infer Output> ? Output : never;
46
+ export type CommandHandlerResult<Registry extends CommandRegistry, Key extends Operation<Registry>> = SchemaInput<Registry[Key]['result']>;
47
+ export type CommandRegistry = Readonly<Record<string, CommandDefinition>>;
48
+ /** Values accepted from callers before the command schema parses them. */
49
+ export type CommandArgument<Registry extends CommandRegistry, Key extends Operation<Registry>> = SchemaInput<Registry[Key]['command']>;
50
+ export type CommandInput<Registry extends CommandRegistry, Key extends Operation<Registry>> = SchemaOutput<Registry[Key]['command']>;
51
+ export type CommandResult<Registry extends CommandRegistry, Key extends Operation<Registry>> = SchemaOutput<Registry[Key]['result']>;
52
+ export type CommandExecution<Context, Registry extends CommandRegistry, Key extends Operation<Registry>> = Readonly<{
11
53
  context: Context;
12
54
  operation: Key;
13
55
  definition: Registry[Key];
14
56
  command: CommandInput<Registry, Key>;
15
- parseResult: (value: unknown) => CommandResult<Registry, Key>;
57
+ parseResult: <Input>(value: Input) => CommandResult<Registry, Key>;
58
+ /** Interpreter-owned asynchronous result decoding, preserving the legacy parser. */
59
+ decodeResult?: <Input>(value: Input) => Promise<CommandResult<Registry, Key>>;
16
60
  /** Runs the handler (result-parsed). Accepts a middleware-enriched context. */
17
61
  run: (context?: Context) => Promise<CommandResult<Registry, Key>>;
62
+ /** Runs without parsing for owners that validate after their middleware chain. */
63
+ runUnparsed: (context?: Context) => Promise<CommandHandlerResult<Registry, Key>>;
18
64
  }>;
19
65
  type CommandDefinition = Readonly<{
20
- command: Parseable<unknown>;
21
- result: Parseable<unknown>;
66
+ command: CommandSchema;
67
+ result: CommandSchema;
22
68
  }>;
23
69
  type Operation<Registry extends CommandRegistry> = Extract<keyof Registry, string>;
24
- type Parsed<Schema> = Schema extends Parseable<infer Output> ? Output : never;
25
70
  type MaybePromise<Value> = Value | Promise<Value>;
26
71
  type Execute<Context, Registry extends CommandRegistry> = <Key extends Operation<Registry>>(execution: CommandExecution<Context, Registry, Key>) => Promise<CommandResult<Registry, Key>>;
27
72
  type FixedExecutor<Context, Registry extends CommandRegistry, Key extends Operation<Registry>> = Readonly<{
28
73
  operation: Key;
29
- handler: (context: Context, command: CommandInput<Registry, Key>) => MaybePromise<CommandResult<Registry, Key>>;
74
+ handler: (context: Context, command: CommandInput<Registry, Key>) => MaybePromise<CommandHandlerResult<Registry, Key>>;
30
75
  }>;
31
76
  type DynamicExecutor<Context, Registry extends CommandRegistry, Dispatcher, Key extends Operation<Registry>> = Readonly<{
32
77
  dispatcher: Parseable<Dispatcher>;
33
78
  select: (dispatcher: Dispatcher) => Key;
34
- handler: (context: Context, command: CommandInput<Registry, Key>) => MaybePromise<CommandResult<Registry, Key>>;
79
+ handler: (context: Context, command: CommandInput<Registry, Key>) => MaybePromise<CommandHandlerResult<Registry, Key>>;
35
80
  }>;
36
81
  /** Generic command kernel. Host policy is injected by the owning domain. */
37
- declare class Command<Context, const Registry extends CommandRegistry> {
82
+ export declare class Command<Context, const Registry extends CommandRegistry> {
38
83
  #private;
39
84
  constructor(configuration: {
40
85
  readonly operations: Registry;
41
86
  readonly execute: Execute<Context, Registry>;
42
87
  });
43
- exec<const Key extends Operation<Registry>>(executor: FixedExecutor<Context, Registry, Key>): (context: Context, command: CommandInput<Registry, Key>) => Promise<CommandResult<Registry, Key>>;
88
+ exec<const Key extends Operation<Registry>>(executor: FixedExecutor<Context, Registry, Key>): (context: Context, command: CommandArgument<Registry, Key>) => Promise<CommandResult<Registry, Key>>;
44
89
  exec<Dispatcher, const Key extends Operation<Registry>>(executor: DynamicExecutor<Context, Registry, Dispatcher, Key>): (context: Context, command: Dispatcher) => Promise<CommandResult<Registry, Key>>;
45
90
  }
46
- //#endregion
47
- export { Command, CommandExecution, CommandInput, CommandRegistry, CommandResult, Parseable, command_d_exports };
91
+ /** Legacy synchronous parsing remains available to existing kernel interpreters. */
92
+ export declare function parseCommandSchema<S extends CommandSchema>(schema: S, value: unknown): SchemaOutput<S>;
93
+ /** Interpreter-owned decoding awaits validation and leaves thrown/rejected defects intact. */
94
+ export declare function decodeCommandSchema<S extends CommandSchema>(schema: S, value: unknown): Promise<SchemaOutput<S>>;
95
+ export { command_d_exports };
48
96
  //# sourceMappingURL=command.d.mts.map
@@ -1,2 +1,2 @@
1
- var e=class extends Error{code=`COMMAND_OPERATION_NOT_CONFIGURED`;name=`CommandConfigurationError`;constructor(){super(`The selected command operation is not configured`)}},t=class{#e;#t;constructor(e){this.#e=e.operations,this.#t=e.execute}exec(t){return async(n,r)=>{let i=`operation`in t?{operation:t.operation,value:r}:(()=>{let e=t.dispatcher.parse(r);return{operation:t.select(e),value:e}})();if(!Object.prototype.hasOwnProperty.call(this.#e,i.operation))throw new e;let a=i.operation,o=this.#e[a],s=o.command.parse(i.value),c=e=>o.result.parse(e),l=t.handler;return this.#t({context:n,operation:a,definition:o,command:s,parseResult:c,run:async e=>c(await l(e??n,s))})}}};export{t as Command};
1
+ var e=class extends Error{code=`COMMAND_OPERATION_NOT_CONFIGURED`;name=`CommandConfigurationError`;constructor(){super(`The selected command operation is not configured`)}},t=class{#e;#t;constructor(e){this.#e=e.operations,this.#t=e.execute}exec(t){return async(i,a)=>{let o=`operation`in t?{operation:t.operation,value:a}:await(async()=>{let e=await r(t.dispatcher,a);return{operation:t.select(e),value:e}})();if(!Object.prototype.hasOwnProperty.call(this.#e,o.operation))throw new e;let s=o.operation,c=this.#e[s],l=await r(c.command,o.value),u=e=>n(c.result,e),d=async e=>await r(c.result,e),f=t.handler;return this.#t({context:i,operation:s,definition:c,command:l,parseResult:u,decodeResult:d,runUnparsed:async e=>f(e??i,l),run:async e=>d(await f(e??i,l))})}}};function n(e,t){if(!(`parse`in e))throw TypeError(`This command schema requires asynchronous decoding`);return e.parse(t)}async function r(e,t){if(`parse`in e)return await(e.parseAsync?e.parseAsync(t):e.parse(t));let n=await(`kind`in e?e.decode(t):e[`~standard`].validate(t));if(n.issues!==void 0)throw new i(n.issues);return n.value}var i=class extends Error{issues;name=`CommandValidationError`;constructor(e){super(`Command contract validation failed`),this.issues=e}};export{t as Command,r as decodeCommandSchema,n as parseCommandSchema};
2
2
  //# sourceMappingURL=command.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"command.mjs","names":["#operations","#execute"],"sources":["../../../../../src/components/foundation/modules/command/command.ts"],"sourcesContent":["export type Parseable<Output> = Readonly<{ parse: (value: unknown) => Output }>\n\nexport type CommandRegistry = Readonly<Record<string, CommandDefinition>>\n\nexport type CommandInput<\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = Parsed<Registry[Key]['command']>\n\nexport type CommandResult<\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = Parsed<Registry[Key]['result']>\n\nexport type CommandExecution<\n\tContext,\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = Readonly<{\n\tcontext: Context\n\toperation: Key\n\tdefinition: Registry[Key]\n\tcommand: CommandInput<Registry, Key>\n\tparseResult: (value: unknown) => CommandResult<Registry, Key>\n\t/** Runs the handler (result-parsed). Accepts a middleware-enriched context. */\n\trun: (context?: Context) => Promise<CommandResult<Registry, Key>>\n}>\n\ntype CommandDefinition = Readonly<{\n\tcommand: Parseable<unknown>\n\tresult: Parseable<unknown>\n}>\n\ntype Operation<Registry extends CommandRegistry> = Extract<\n\tkeyof Registry,\n\tstring\n>\ntype Parsed<Schema> = Schema extends Parseable<infer Output> ? Output : never\ntype MaybePromise<Value> = Value | Promise<Value>\ntype Execute<Context, Registry extends CommandRegistry> = <\n\tKey extends Operation<Registry>,\n>(\n\texecution: CommandExecution<Context, Registry, Key>,\n) => Promise<CommandResult<Registry, Key>>\n\ntype FixedExecutor<\n\tContext,\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = Readonly<{\n\toperation: Key\n\thandler: (\n\t\tcontext: Context,\n\t\tcommand: CommandInput<Registry, Key>,\n\t) => MaybePromise<CommandResult<Registry, Key>>\n}>\n\ntype DynamicExecutor<\n\tContext,\n\tRegistry extends CommandRegistry,\n\tDispatcher,\n\tKey extends Operation<Registry>,\n> = Readonly<{\n\tdispatcher: Parseable<Dispatcher>\n\tselect: (dispatcher: Dispatcher) => Key\n\thandler: (\n\t\tcontext: Context,\n\t\tcommand: CommandInput<Registry, Key>,\n\t) => MaybePromise<CommandResult<Registry, Key>>\n}>\n\nclass CommandConfigurationError extends Error {\n\treadonly code = 'COMMAND_OPERATION_NOT_CONFIGURED'\n\treadonly name = 'CommandConfigurationError'\n\n\tconstructor() {\n\t\tsuper('The selected command operation is not configured')\n\t}\n}\n\n/** Generic command kernel. Host policy is injected by the owning domain. */\nexport class Command<Context, const Registry extends CommandRegistry> {\n\treadonly #operations: Registry\n\treadonly #execute: Execute<Context, Registry>\n\n\tconstructor(configuration: {\n\t\treadonly operations: Registry\n\t\treadonly execute: Execute<Context, Registry>\n\t}) {\n\t\tthis.#operations = configuration.operations\n\t\tthis.#execute = configuration.execute\n\t}\n\n\texec<const Key extends Operation<Registry>>(\n\t\texecutor: FixedExecutor<Context, Registry, Key>,\n\t): (\n\t\tcontext: Context,\n\t\tcommand: CommandInput<Registry, Key>,\n\t) => Promise<CommandResult<Registry, Key>>\n\texec<Dispatcher, const Key extends Operation<Registry>>(\n\t\texecutor: DynamicExecutor<Context, Registry, Dispatcher, Key>,\n\t): (\n\t\tcontext: Context,\n\t\tcommand: Dispatcher,\n\t) => Promise<CommandResult<Registry, Key>>\n\texec(\n\t\texecutor:\n\t\t\t| FixedExecutor<Context, Registry, Operation<Registry>>\n\t\t\t| DynamicExecutor<Context, Registry, unknown, Operation<Registry>>,\n\t) {\n\t\treturn async (context: Context, value: unknown) => {\n\t\t\tconst selected =\n\t\t\t\t'operation' in executor\n\t\t\t\t\t? { operation: executor.operation, value }\n\t\t\t\t\t: (() => {\n\t\t\t\t\t\t\tconst dispatcher = executor.dispatcher.parse(value)\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\toperation: executor.select(dispatcher),\n\t\t\t\t\t\t\t\tvalue: dispatcher,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})()\n\t\t\tif (\n\t\t\t\t!Object.prototype.hasOwnProperty.call(\n\t\t\t\t\tthis.#operations,\n\t\t\t\t\tselected.operation,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new CommandConfigurationError()\n\t\t\t}\n\t\t\tconst operation = selected.operation as Operation<Registry>\n\t\t\tconst definition = this.#operations[operation]\n\t\t\tconst command = definition.command.parse(selected.value) as CommandInput<\n\t\t\t\tRegistry,\n\t\t\t\tOperation<Registry>\n\t\t\t>\n\t\t\tconst parseResult = (result: unknown) =>\n\t\t\t\tdefinition.result.parse(result) as CommandResult<\n\t\t\t\t\tRegistry,\n\t\t\t\t\tOperation<Registry>\n\t\t\t\t>\n\t\t\tconst handler = executor.handler as (\n\t\t\t\tcontext: Context,\n\t\t\t\tcommand: CommandInput<Registry, Operation<Registry>>,\n\t\t\t) => MaybePromise<CommandResult<Registry, Operation<Registry>>>\n\t\t\treturn this.#execute({\n\t\t\t\tcontext,\n\t\t\t\toperation,\n\t\t\t\tdefinition,\n\t\t\t\tcommand,\n\t\t\t\tparseResult,\n\t\t\t\trun: async (contextOverride?: Context) =>\n\t\t\t\t\tparseResult(await handler(contextOverride ?? context, command)),\n\t\t\t})\n\t\t}\n\t}\n}\n"],"mappings":"AAuEA,IAAM,EAAN,cAAwC,KAAM,CAC7C,KAAgB,mCAChB,KAAgB,4BAEhB,aAAc,CACb,MAAM,kDAAkD,CACzD,CACD,EAGa,EAAb,KAAsE,CACrE,GACA,GAEA,YAAY,EAGT,CACF,KAAKA,GAAc,EAAc,WACjC,KAAKC,GAAW,EAAc,OAC/B,CAcA,KACC,EAGC,CACD,OAAO,MAAO,EAAkB,IAAmB,CAClD,IAAM,EACL,cAAe,EACZ,CAAE,UAAW,EAAS,UAAW,OAAM,OAChC,CACP,IAAM,EAAa,EAAS,WAAW,MAAM,CAAK,EAClD,MAAO,CACN,UAAW,EAAS,OAAO,CAAU,EACrC,MAAO,CACR,CACD,EAAA,CAAG,EACN,GACC,CAAC,OAAO,UAAU,eAAe,KAChC,KAAKD,GACL,EAAS,SACV,EAEA,MAAM,IAAI,EAEX,IAAM,EAAY,EAAS,UACrB,EAAa,KAAKA,GAAY,GAC9B,EAAU,EAAW,QAAQ,MAAM,EAAS,KAAK,EAIjD,EAAe,GACpB,EAAW,OAAO,MAAM,CAAM,EAIzB,EAAU,EAAS,QAIzB,OAAO,KAAKC,GAAS,CACpB,UACA,YACA,aACA,UACA,cACA,IAAK,KAAO,IACX,EAAY,MAAM,EAAQ,GAAmB,EAAS,CAAO,CAAC,CAChE,CAAC,CACF,CACD,CACD"}
1
+ {"version":3,"file":"command.mjs","names":["CommandConfigurationError","Command","#operations","configuration","#execute","selected","executor","dispatcher","decodeCommandSchema","value","operation","definition","command","parseResult","parseCommandSchema","result","decodeResult","handler","contextOverride","context","schema","CommandValidationError","issues"],"sources":["../../../../../src/components/foundation/modules/command/command.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-parameters -- Schema validators and interpreter decoders own these untrusted input boundaries and validate before domain callbacks. */\nexport type Parseable<Output> = Readonly<{\n\tparse: <Input>(value: Input) => Output\n\tparseAsync?: <Input>(value: Input) => Promise<Output>\n}>\n\n/** Structural mirror of portable neutral contracts: components cannot import host modules. */\ninterface ValidationIssue {\n\treadonly message: string\n\treadonly path?: readonly (PropertyKey | { readonly key: PropertyKey })[]\n}\ntype ValidationResult<Output> =\n\t| { readonly value: Output; readonly issues?: undefined }\n\t| { readonly issues: readonly ValidationIssue[] }\ninterface StandardSchema<Input = unknown, Output = unknown> {\n\treadonly '~standard': {\n\t\treadonly version: 1\n\t\treadonly vendor: string\n\t\treadonly types?: { readonly input: Input; readonly output: Output }\n\t\treadonly validate: (\n\t\t\tvalue: unknown,\n\t\t) => ValidationResult<Output> | Promise<ValidationResult<Output>>\n\t}\n}\ninterface NeutralDecoder<Input = unknown, Output = unknown, Execution = unknown> {\n\treadonly kind: 'contract'\n\treadonly types?: { readonly input: Input; readonly output: Output }\n\treadonly decode: (value: unknown) => Execution\n}\nexport type CommandSchema<Output = unknown> =\n\t| Parseable<Output>\n\t| StandardSchema<unknown, Output>\n\t| NeutralDecoder<unknown, Output, ValidationResult<Output> | Promise<ValidationResult<Output>>>\n\n/** Raw values accepted before decoding, including transform inputs. */\nexport type SchemaInput<Schema extends CommandSchema> =\n\tSchema extends NeutralDecoder<infer Input, unknown, unknown>\n\t\t? Input\n\t\t: Schema extends { _input: infer Input }\n\t\t\t? Input\n\t\t\t: Schema extends StandardSchema<infer Input, unknown>\n\t\t\t\t? Input\n\t\t\t\t: SchemaOutput<Schema>\nexport type SchemaOutput<Schema extends CommandSchema> =\n\tSchema extends Parseable<unknown>\n\t\t? ReturnType<Schema['parse']>\n\t\t: Schema extends NeutralDecoder<unknown, infer Output, unknown>\n\t\t\t? Output\n\t\t\t: Schema extends StandardSchema<unknown, infer Output>\n\t\t\t\t? Output\n\t\t\t\t: never\nexport type CommandHandlerResult<\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = SchemaInput<Registry[Key]['result']>\n\nexport type CommandRegistry = Readonly<Record<string, CommandDefinition>>\n\n/** Values accepted from callers before the command schema parses them. */\nexport type CommandArgument<\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = SchemaInput<Registry[Key]['command']>\n\nexport type CommandInput<\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = SchemaOutput<Registry[Key]['command']>\n\nexport type CommandResult<\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = SchemaOutput<Registry[Key]['result']>\n\nexport type CommandExecution<\n\tContext,\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = Readonly<{\n\tcontext: Context\n\toperation: Key\n\tdefinition: Registry[Key]\n\tcommand: CommandInput<Registry, Key>\n\tparseResult: <Input>(value: Input) => CommandResult<Registry, Key>\n\t/** Interpreter-owned asynchronous result decoding, preserving the legacy parser. */\n\tdecodeResult?: <Input>(value: Input) => Promise<CommandResult<Registry, Key>>\n\t/** Runs the handler (result-parsed). Accepts a middleware-enriched context. */\n\trun: (context?: Context) => Promise<CommandResult<Registry, Key>>\n\t/** Runs without parsing for owners that validate after their middleware chain. */\n\trunUnparsed: (context?: Context) => Promise<CommandHandlerResult<Registry, Key>>\n}>\n\ntype CommandDefinition = Readonly<{\n\tcommand: CommandSchema\n\tresult: CommandSchema\n}>\n\ntype Operation<Registry extends CommandRegistry> = Extract<keyof Registry, string>\ntype MaybePromise<Value> = Value | Promise<Value>\ntype Execute<Context, Registry extends CommandRegistry> = <Key extends Operation<Registry>>(\n\texecution: CommandExecution<Context, Registry, Key>,\n) => Promise<CommandResult<Registry, Key>>\n\ntype FixedExecutor<\n\tContext,\n\tRegistry extends CommandRegistry,\n\tKey extends Operation<Registry>,\n> = Readonly<{\n\toperation: Key\n\thandler: (\n\t\tcontext: Context,\n\t\tcommand: CommandInput<Registry, Key>,\n\t) => MaybePromise<CommandHandlerResult<Registry, Key>>\n}>\n\ntype DynamicExecutor<\n\tContext,\n\tRegistry extends CommandRegistry,\n\tDispatcher,\n\tKey extends Operation<Registry>,\n> = Readonly<{\n\tdispatcher: Parseable<Dispatcher>\n\tselect: (dispatcher: Dispatcher) => Key\n\thandler: (\n\t\tcontext: Context,\n\t\tcommand: CommandInput<Registry, Key>,\n\t) => MaybePromise<CommandHandlerResult<Registry, Key>>\n}>\n\nclass CommandConfigurationError extends Error {\n\treadonly code = 'COMMAND_OPERATION_NOT_CONFIGURED'\n\treadonly name = 'CommandConfigurationError'\n\n\tconstructor() {\n\t\tsuper('The selected command operation is not configured')\n\t}\n}\n\n/** Generic command kernel. Host policy is injected by the owning domain. */\nexport class Command<Context, const Registry extends CommandRegistry> {\n\treadonly #operations: Registry\n\treadonly #execute: Execute<Context, Registry>\n\n\tconstructor(configuration: {\n\t\treadonly operations: Registry\n\t\treadonly execute: Execute<Context, Registry>\n\t}) {\n\t\tthis.#operations = configuration.operations\n\t\tthis.#execute = configuration.execute\n\t}\n\n\texec<const Key extends Operation<Registry>>(\n\t\texecutor: FixedExecutor<Context, Registry, Key>,\n\t): (\n\t\tcontext: Context,\n\t\tcommand: CommandArgument<Registry, Key>,\n\t) => Promise<CommandResult<Registry, Key>>\n\texec<Dispatcher, const Key extends Operation<Registry>>(\n\t\texecutor: DynamicExecutor<Context, Registry, Dispatcher, Key>,\n\t): (context: Context, command: Dispatcher) => Promise<CommandResult<Registry, Key>>\n\texec<Dispatcher>(\n\t\texecutor:\n\t\t\t| FixedExecutor<Context, Registry, Operation<Registry>>\n\t\t\t| DynamicExecutor<Context, Registry, Dispatcher, Operation<Registry>>,\n\t) {\n\t\treturn async (\n\t\t\tcontext: Context,\n\t\t\tvalue: Dispatcher | CommandArgument<Registry, Operation<Registry>>,\n\t\t) => {\n\t\t\tconst selected =\n\t\t\t\t'operation' in executor\n\t\t\t\t\t? { operation: executor.operation, value }\n\t\t\t\t\t: await (async () => {\n\t\t\t\t\t\t\tconst dispatcher = await decodeCommandSchema(executor.dispatcher, value)\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\toperation: executor.select(dispatcher),\n\t\t\t\t\t\t\t\tvalue: dispatcher,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})()\n\t\t\tif (!Object.prototype.hasOwnProperty.call(this.#operations, selected.operation)) {\n\t\t\t\tthrow new CommandConfigurationError()\n\t\t\t}\n\t\t\tconst operation = selected.operation\n\t\t\tconst definition = this.#operations[operation]\n\t\t\t// SAFETY: the selected registry entry owns this command schema and its output.\n\t\t\tconst command = (await decodeCommandSchema(\n\t\t\t\tdefinition.command,\n\t\t\t\tselected.value,\n\t\t\t)) as CommandInput<Registry, Operation<Registry>>\n\t\t\t// SAFETY: the selected entry also owns the result schema, including transforms.\n\t\t\tconst parseResult = <Input>(result: Input) =>\n\t\t\t\tparseCommandSchema(definition.result, result) as CommandResult<\n\t\t\t\t\tRegistry,\n\t\t\t\t\tOperation<Registry>\n\t\t\t\t>\n\t\t\t// SAFETY: selected result schema owns the decoded output, including async transforms.\n\t\t\tconst decodeResult = async <Input>(result: Input) =>\n\t\t\t\t(await decodeCommandSchema(definition.result, result)) as CommandResult<\n\t\t\t\t\tRegistry,\n\t\t\t\t\tOperation<Registry>\n\t\t\t\t>\n\t\t\tconst handler = executor.handler\n\t\t\treturn this.#execute({\n\t\t\t\tcontext,\n\t\t\t\toperation,\n\t\t\t\tdefinition,\n\t\t\t\tcommand,\n\t\t\t\tparseResult,\n\t\t\t\tdecodeResult,\n\t\t\t\trunUnparsed: async (contextOverride?: Context) =>\n\t\t\t\t\thandler(contextOverride ?? context, command),\n\t\t\t\trun: async (contextOverride?: Context) =>\n\t\t\t\t\tdecodeResult(await handler(contextOverride ?? context, command)),\n\t\t\t})\n\t\t}\n\t}\n}\n\n/** Legacy synchronous parsing remains available to existing kernel interpreters. */\nexport function parseCommandSchema<S extends CommandSchema>(\n\tschema: S,\n\tvalue: unknown,\n): SchemaOutput<S> {\n\tif (!('parse' in schema))\n\t\tthrow new TypeError('This command schema requires asynchronous decoding')\n\t// SAFETY: this legacy parser belongs to the selected schema.\n\treturn schema.parse(value) as SchemaOutput<S>\n}\n\n/** Interpreter-owned decoding awaits validation and leaves thrown/rejected defects intact. */\nexport async function decodeCommandSchema<S extends CommandSchema>(\n\tschema: S,\n\tvalue: unknown,\n): Promise<SchemaOutput<S>> {\n\tif ('parse' in schema) {\n\t\t// SAFETY: parseAsync and parse share the selected legacy schema's output.\n\t\treturn (await (schema.parseAsync\n\t\t\t? schema.parseAsync(value)\n\t\t\t: schema.parse(value))) as SchemaOutput<S>\n\t}\n\tconst result = await ('kind' in schema\n\t\t? schema.decode(value)\n\t\t: schema['~standard'].validate(value))\n\tif (result.issues !== undefined) throw new CommandValidationError(result.issues)\n\t// SAFETY: this decoder owns the selected schema's output.\n\treturn result.value as SchemaOutput<S>\n}\n\nclass CommandValidationError extends Error {\n\treadonly name = 'CommandValidationError'\n\tconstructor(readonly issues: readonly ValidationIssue[]) {\n\t\tsuper('Command contract validation failed')\n\t}\n}\n"],"mappings":"AAiIA,IAAMA,EAAN,cAAwC,KAAM,CAC7C,KAAgB,mCAChB,KAAgB,4BAEhB,aAAc,CACb,MAAM,kDAAkD,CACzD,CACD,EAGaC,EAAb,KAAsE,CACrE,GACA,GAEA,YAAY,EAGT,CACF,KAAKC,GAAcC,EAAc,WACjC,KAAKC,GAAWD,EAAc,OAC/B,CAWA,KACC,EAGC,CACD,OAAO,MACN,EACA,IACI,CACJ,IAAME,EACL,cAAeC,EACZ,CAAE,UAAWA,EAAS,UAAW,OAAM,EACvC,MAAO,SAAY,CACnB,IAAMC,EAAa,MAAMC,EAAoBF,EAAS,WAAYG,CAAK,EACvE,MAAO,CACN,UAAWH,EAAS,OAAOC,CAAU,EACrC,MAAOA,CACR,CACD,EAAA,CAAG,EACN,GAAI,CAAC,OAAO,UAAU,eAAe,KAAK,KAAKL,GAAaG,EAAS,SAAS,EAC7E,MAAM,IAAIL,EAEX,IAAMU,EAAYL,EAAS,UACrBM,EAAa,KAAKT,GAAYQ,GAE9BE,EAAW,MAAMJ,EACtBG,EAAW,QACXN,EAAS,KACV,EAEMQ,EAAsB,GAC3BC,EAAmBH,EAAW,OAAQI,CAAM,EAKvCC,EAAe,KAAc,IACjC,MAAMR,EAAoBG,EAAW,OAAQI,CAAM,EAI/CE,EAAUX,EAAS,QACzB,OAAO,KAAKF,GAAS,CACpB,UACA,YACA,aACA,UACA,cACA,eACA,YAAa,KAAO,IACnBa,EAAQC,GAAmBC,EAASP,CAAO,EAC5C,IAAK,KAAO,IACXI,EAAa,MAAMC,EAAQC,GAAmBC,EAASP,CAAO,CAAC,CACjE,CAAC,CACF,CACD,CACD,EAGA,SAAgBE,EACf,EACA,EACkB,CAClB,GAAI,EAAE,UAAWM,GAChB,MAAU,UAAU,oDAAoD,EAEzE,OAAOA,EAAO,MAAMX,CAAK,CAC1B,CAGA,eAAsBD,EACrB,EACA,EAC2B,CAC3B,GAAI,UAAWY,EAEd,OAAQ,MAAOA,EAAO,WACnBA,EAAO,WAAWX,CAAK,EACvBW,EAAO,MAAMX,CAAK,GAEtB,IAAMM,EAAS,MAAO,SAAUK,EAC7BA,EAAO,OAAOX,CAAK,EACnBW,EAAO,YAAY,CAAC,SAASX,CAAK,GACrC,GAAIM,EAAO,SAAW,IAAA,GAAW,MAAM,IAAIM,EAAuBN,EAAO,MAAM,EAE/E,OAAOA,EAAO,KACf,CAEA,IAAMM,EAAN,cAAqC,KAAM,CAErB,OADrB,KAAgB,yBAChB,YAAY,EAA6C,CACxD,MAAM,oCAAoC,EADtB,KAAA,OAAAC,CAErB,CACD,E"}
@@ -0,0 +1,78 @@
1
+ import { AuditEntryInput } from "../../client.mjs";
2
+ /** Internal sequencing only: interpreters own callback normalization and observation. */
3
+ export interface ExecutionKind {
4
+ readonly value: unknown;
5
+ readonly type: unknown;
6
+ }
7
+ export type ExecutionValue<Kind extends ExecutionKind, Value> = (Kind & {
8
+ readonly value: Value;
9
+ })['type'];
10
+ export interface LifecycleAlgebra<Kind extends ExecutionKind> {
11
+ succeed<Value>(value: Value): ExecutionValue<Kind, Value>;
12
+ suspend<Value>(execute: () => ExecutionValue<Kind, Value>): ExecutionValue<Kind, Value>;
13
+ flatMap<Input, Output>(execution: ExecutionValue<Kind, Input>, next: (input: Input) => ExecutionValue<Kind, Output>): ExecutionValue<Kind, Output>;
14
+ }
15
+ export interface PromiseExecution extends ExecutionKind {
16
+ readonly type: Promise<this['value']>;
17
+ }
18
+ export declare const promiseLifecycle: LifecycleAlgebra<PromiseExecution>;
19
+ export type LifecyclePreparation<Kind extends ExecutionKind, Result> = {
20
+ kind: 'replay';
21
+ result: unknown;
22
+ } | {
23
+ kind: 'execute';
24
+ complete?: (result: Result) => ExecutionValue<Kind, void>;
25
+ };
26
+ export type LifecycleMiddleware<Kind extends ExecutionKind, Context, Input, Raw> = (input: {
27
+ operation: string;
28
+ context: Context;
29
+ command: Input;
30
+ next: (options?: {
31
+ context?: object;
32
+ }) => ExecutionValue<Kind, Raw>;
33
+ }) => ExecutionValue<Kind, Raw>;
34
+ export type LifecycleExecution<Kind extends ExecutionKind, Context, Input, Raw, Result> = {
35
+ operation: string;
36
+ classification: string;
37
+ context: Context;
38
+ command: Input;
39
+ permission?: () => ExecutionValue<Kind, void>;
40
+ prepare: () => ExecutionValue<Kind, LifecyclePreparation<Kind, Result> | undefined>;
41
+ middleware: readonly LifecycleMiddleware<Kind, Context, Input, Raw>[];
42
+ defaultGuard: (context: Context) => ExecutionValue<Kind, void>;
43
+ guard: (context: Context) => ExecutionValue<Kind, void>;
44
+ run: (context: Context) => ExecutionValue<Kind, Raw>;
45
+ audit: (result: Result) => ExecutionValue<Kind, Omit<AuditEntryInput, 'classification'> | null>;
46
+ aggregates?: readonly string[];
47
+ writeAudit: (entry: AuditEntryInput) => ExecutionValue<Kind, unknown>;
48
+ } & ({
49
+ parseReplay: <Value>(value: Value) => Result;
50
+ decodeReplay?: (value: unknown) => ExecutionValue<Kind, Result>;
51
+ } | {
52
+ parseReplay?: never;
53
+ decodeReplay: (value: unknown) => ExecutionValue<Kind, Result>;
54
+ }) & ({
55
+ parseResult: (value: Raw) => Result;
56
+ decodeResult?: (value: Raw) => ExecutionValue<Kind, Result>;
57
+ } | {
58
+ parseResult?: never;
59
+ decodeResult: (value: Raw) => ExecutionValue<Kind, Result>;
60
+ });
61
+ /** One owner for the command protocol; every interpretation allocates fresh dispatch state. */
62
+ export declare function executeCommandLifecycle<Kind extends ExecutionKind, Context, Input, Raw, Result>(algebra: LifecycleAlgebra<Kind>, execution: LifecycleExecution<Kind, Context, Input, Raw, Result>): ExecutionValue<Kind, Result>;
63
+ export declare class CommandMiddlewareError extends Error {
64
+ readonly code = "COMMAND_MIDDLEWARE_NEXT_REUSED";
65
+ readonly name = "CommandMiddlewareError";
66
+ constructor(operation: string);
67
+ }
68
+ export declare class CommandAggregateError extends Error {
69
+ readonly code = "COMMAND_AGGREGATE_NOT_DECLARED";
70
+ readonly name = "CommandAggregateError";
71
+ constructor(operation: string, aggregateType: string);
72
+ }
73
+ export declare class CommandPermissionError extends Error {
74
+ readonly code = "COMMAND_PERMISSION_NOT_CONFIGURED";
75
+ readonly name = "CommandPermissionError";
76
+ constructor(operation: string);
77
+ }
78
+ //# sourceMappingURL=lifecycle.d.mts.map
@@ -0,0 +1,2 @@
1
+ const e={succeed:e=>Promise.resolve(e),suspend:e=>Promise.resolve().then(e),flatMap:(e,t)=>e.then(t)};function t(e,t){return e.suspend(()=>{let i=-1,a=n=>e.flatMap(t.defaultGuard(n),()=>e.flatMap(t.guard(n),()=>t.run(n))),o=(r,s)=>e.suspend(()=>{if(r<=i)throw new n(t.operation);i=r;let e=t.middleware[r];return e?e({operation:t.operation,command:t.command,context:s,next:e=>o(r+1,e?.context?{...s,...e.context}:s)}):a(s)});return e.flatMap(t.permission?.()??e.succeed(void 0),()=>e.flatMap(t.prepare(),n=>n?.kind===`replay`?e.suspend(()=>t.decodeReplay?t.decodeReplay(n.result):e.succeed(t.parseReplay(n.result))):e.flatMap(o(0,t.context),i=>e.flatMap(t.decodeResult?t.decodeResult(i):e.succeed(t.parseResult(i)),i=>e.flatMap(t.audit(i),a=>{if(a&&t.aggregates&&!t.aggregates.includes(a.aggregate.type))throw new r(t.operation,a.aggregate.type);return e.flatMap(a?t.writeAudit({...a,classification:t.classification}):e.succeed(void 0),()=>e.flatMap(n?.complete?.(i)??e.succeed(void 0),()=>e.succeed(i)))})))))})}var n=class extends Error{code=`COMMAND_MIDDLEWARE_NEXT_REUSED`;name=`CommandMiddlewareError`;constructor(e){super(`A middleware for operation "${e}" called next() more than once`)}},r=class extends Error{code=`COMMAND_AGGREGATE_NOT_DECLARED`;name=`CommandAggregateError`;constructor(e,t){super(`Operation "${e}" audited aggregate type "${t}" outside its declared aggregates`)}},i=class extends Error{code=`COMMAND_PERMISSION_NOT_CONFIGURED`;name=`CommandPermissionError`;constructor(e){super(`Operation "${e}" declares a permission but the Foundation has no checkPermission`)}};export{r as CommandAggregateError,n as CommandMiddlewareError,i as CommandPermissionError,t as executeCommandLifecycle,e as promiseLifecycle};
2
+ //# sourceMappingURL=lifecycle.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.mjs","names":["promiseLifecycle","value","execute","execution","next","executeCommandLifecycle","algebra","deepest","terminal","context","dispatch","index","CommandMiddlewareError","layer","options","preparation","raw","result","audit","CommandAggregateError","operation","aggregateType","CommandPermissionError"],"sources":["../../../../../src/components/foundation/modules/command/lifecycle.ts"],"sourcesContent":["import type { AuditEntryInput } from '../../client'\n\n/** Internal sequencing only: interpreters own callback normalization and observation. */\nexport interface ExecutionKind {\n\treadonly value: unknown\n\treadonly type: unknown\n}\nexport type ExecutionValue<Kind extends ExecutionKind, Value> = (Kind & {\n\treadonly value: Value\n})['type']\nexport interface LifecycleAlgebra<Kind extends ExecutionKind> {\n\tsucceed<Value>(value: Value): ExecutionValue<Kind, Value>\n\tsuspend<Value>(execute: () => ExecutionValue<Kind, Value>): ExecutionValue<Kind, Value>\n\tflatMap<Input, Output>(\n\t\texecution: ExecutionValue<Kind, Input>,\n\t\tnext: (input: Input) => ExecutionValue<Kind, Output>,\n\t): ExecutionValue<Kind, Output>\n}\nexport interface PromiseExecution extends ExecutionKind {\n\treadonly type: Promise<this['value']>\n}\nexport const promiseLifecycle: LifecycleAlgebra<PromiseExecution> = {\n\tsucceed: (value) => Promise.resolve(value),\n\tsuspend: (execute) => Promise.resolve().then(execute),\n\tflatMap: (execution, next) => execution.then(next),\n}\nexport type LifecyclePreparation<Kind extends ExecutionKind, Result> =\n\t| { kind: 'replay'; result: unknown }\n\t| { kind: 'execute'; complete?: (result: Result) => ExecutionValue<Kind, void> }\nexport type LifecycleMiddleware<Kind extends ExecutionKind, Context, Input, Raw> = (input: {\n\toperation: string\n\tcontext: Context\n\tcommand: Input\n\tnext: (options?: { context?: object }) => ExecutionValue<Kind, Raw>\n}) => ExecutionValue<Kind, Raw>\nexport type LifecycleExecution<Kind extends ExecutionKind, Context, Input, Raw, Result> = {\n\toperation: string\n\tclassification: string\n\tcontext: Context\n\tcommand: Input\n\tpermission?: () => ExecutionValue<Kind, void>\n\tprepare: () => ExecutionValue<Kind, LifecyclePreparation<Kind, Result> | undefined>\n\tmiddleware: readonly LifecycleMiddleware<Kind, Context, Input, Raw>[]\n\tdefaultGuard: (context: Context) => ExecutionValue<Kind, void>\n\tguard: (context: Context) => ExecutionValue<Kind, void>\n\trun: (context: Context) => ExecutionValue<Kind, Raw>\n\taudit: (result: Result) => ExecutionValue<Kind, Omit<AuditEntryInput, 'classification'> | null>\n\taggregates?: readonly string[]\n\twriteAudit: (entry: AuditEntryInput) => ExecutionValue<Kind, unknown>\n} & (\n\t| {\n\t\t\tparseReplay: <Value>(value: Value) => Result\n\t\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Replay decoding validates untrusted stored output at the interpreter boundary.\n\t\t\tdecodeReplay?: (value: unknown) => ExecutionValue<Kind, Result>\n\t }\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Replay decoding validates untrusted stored output at the interpreter boundary.\n\t| { parseReplay?: never; decodeReplay: (value: unknown) => ExecutionValue<Kind, Result> }\n) &\n\t(\n\t\t| {\n\t\t\t\tparseResult: (value: Raw) => Result\n\t\t\t\tdecodeResult?: (value: Raw) => ExecutionValue<Kind, Result>\n\t\t }\n\t\t| { parseResult?: never; decodeResult: (value: Raw) => ExecutionValue<Kind, Result> }\n\t)\n\n/** One owner for the command protocol; every interpretation allocates fresh dispatch state. */\nexport function executeCommandLifecycle<Kind extends ExecutionKind, Context, Input, Raw, Result>(\n\talgebra: LifecycleAlgebra<Kind>,\n\texecution: LifecycleExecution<Kind, Context, Input, Raw, Result>,\n): ExecutionValue<Kind, Result> {\n\treturn algebra.suspend(() => {\n\t\tlet deepest = -1\n\t\tconst terminal = (context: Context): ExecutionValue<Kind, Raw> =>\n\t\t\talgebra.flatMap(execution.defaultGuard(context), () =>\n\t\t\t\talgebra.flatMap(execution.guard(context), () => execution.run(context)),\n\t\t\t)\n\t\tconst dispatch = (index: number, context: Context): ExecutionValue<Kind, Raw> =>\n\t\t\talgebra.suspend(() => {\n\t\t\t\tif (index <= deepest) throw new CommandMiddlewareError(execution.operation)\n\t\t\t\tdeepest = index\n\t\t\t\tconst layer = execution.middleware[index]\n\t\t\t\tif (!layer) return terminal(context)\n\t\t\t\treturn layer({\n\t\t\t\t\toperation: execution.operation,\n\t\t\t\t\tcommand: execution.command,\n\t\t\t\t\tcontext,\n\t\t\t\t\tnext: (options) =>\n\t\t\t\t\t\tdispatch(index + 1, options?.context ? { ...context, ...options.context } : context),\n\t\t\t\t})\n\t\t\t})\n\t\treturn algebra.flatMap(execution.permission?.() ?? algebra.succeed(undefined), () =>\n\t\t\talgebra.flatMap(execution.prepare(), (preparation) => {\n\t\t\t\tif (preparation?.kind === 'replay') {\n\t\t\t\t\treturn algebra.suspend(() =>\n\t\t\t\t\t\texecution.decodeReplay\n\t\t\t\t\t\t\t? execution.decodeReplay(preparation.result)\n\t\t\t\t\t\t\t: algebra.succeed(execution.parseReplay!(preparation.result)),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn algebra.flatMap(dispatch(0, execution.context), (raw) => {\n\t\t\t\t\treturn algebra.flatMap(\n\t\t\t\t\t\texecution.decodeResult\n\t\t\t\t\t\t\t? execution.decodeResult(raw)\n\t\t\t\t\t\t\t: algebra.succeed(execution.parseResult!(raw)),\n\t\t\t\t\t\t(result) =>\n\t\t\t\t\t\t\talgebra.flatMap(execution.audit(result), (audit) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\taudit &&\n\t\t\t\t\t\t\t\t\texecution.aggregates &&\n\t\t\t\t\t\t\t\t\t!execution.aggregates.includes(audit.aggregate.type)\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tthrow new CommandAggregateError(execution.operation, audit.aggregate.type)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn algebra.flatMap(\n\t\t\t\t\t\t\t\t\taudit\n\t\t\t\t\t\t\t\t\t\t? execution.writeAudit({ ...audit, classification: execution.classification })\n\t\t\t\t\t\t\t\t\t\t: algebra.succeed(undefined),\n\t\t\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\t\t\talgebra.flatMap(\n\t\t\t\t\t\t\t\t\t\t\tpreparation?.complete?.(result) ?? algebra.succeed(undefined),\n\t\t\t\t\t\t\t\t\t\t\t() => algebra.succeed(result),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t}),\n\t\t)\n\t})\n}\n\nexport class CommandMiddlewareError extends Error {\n\treadonly code = 'COMMAND_MIDDLEWARE_NEXT_REUSED'\n\treadonly name = 'CommandMiddlewareError'\n\tconstructor(operation: string) {\n\t\tsuper(`A middleware for operation \"${operation}\" called next() more than once`)\n\t}\n}\nexport class CommandAggregateError extends Error {\n\treadonly code = 'COMMAND_AGGREGATE_NOT_DECLARED'\n\treadonly name = 'CommandAggregateError'\n\tconstructor(operation: string, aggregateType: string) {\n\t\tsuper(\n\t\t\t`Operation \"${operation}\" audited aggregate type \"${aggregateType}\" outside its declared aggregates`,\n\t\t)\n\t}\n}\nexport class CommandPermissionError extends Error {\n\treadonly code = 'COMMAND_PERMISSION_NOT_CONFIGURED'\n\treadonly name = 'CommandPermissionError'\n\tconstructor(operation: string) {\n\t\tsuper(\n\t\t\t`Operation \"${operation}\" declares a permission but the Foundation has no checkPermission`,\n\t\t)\n\t}\n}\n"],"mappings":"AAqBA,MAAaA,EAAuD,CACnE,QAAU,GAAU,QAAQ,QAAQC,CAAK,EACzC,QAAU,GAAY,QAAQ,QAAQ,CAAC,CAAC,KAAKC,CAAO,EACpD,SAAU,EAAW,IAASC,EAAU,KAAKC,CAAI,CAClD,EA0CA,SAAgBC,EACf,EACA,EAC+B,CAC/B,OAAOC,EAAQ,YAAc,CAC5B,IAAIC,EAAU,GACRC,EAAY,GACjBF,EAAQ,QAAQH,EAAU,aAAaM,CAAO,MAC7CH,EAAQ,QAAQH,EAAU,MAAMM,CAAO,MAASN,EAAU,IAAIM,CAAO,CAAC,CACvE,EACKC,GAAY,EAAe,IAChCJ,EAAQ,YAAc,CACrB,GAAIK,GAASJ,EAAS,MAAM,IAAIK,EAAuBT,EAAU,SAAS,EAC1E,EAAUQ,EACV,IAAME,EAAQV,EAAU,WAAWQ,GAEnC,OADKE,EACEA,EAAM,CACZ,UAAWV,EAAU,UACrB,QAASA,EAAU,QACnB,UACA,KAAO,GACNO,EAASC,EAAQ,EAAGG,GAAS,QAAU,CAAE,GAAGL,EAAS,GAAGK,EAAQ,OAAQ,EAAIL,CAAO,CACrF,CAAC,EAPkBD,EAASC,CAAO,CAQpC,CAAC,EACF,OAAOH,EAAQ,QAAQH,EAAU,aAAa,GAAKG,EAAQ,QAAQ,IAAA,EAAS,MAC3EA,EAAQ,QAAQH,EAAU,QAAQ,EAAI,GACjCY,GAAa,OAAS,SAClBT,EAAQ,YACdH,EAAU,aACPA,EAAU,aAAaY,EAAY,MAAM,EACzCT,EAAQ,QAAQH,EAAU,YAAaY,EAAY,MAAM,CAAC,CAC9D,EAEMT,EAAQ,QAAQI,EAAS,EAAGP,EAAU,OAAO,EAAI,GAChDG,EAAQ,QACdH,EAAU,aACPA,EAAU,aAAaa,CAAG,EAC1BV,EAAQ,QAAQH,EAAU,YAAaa,CAAG,CAAC,EAC7C,GACAV,EAAQ,QAAQH,EAAU,MAAMc,CAAM,EAAI,GAAU,CACnD,GACCC,GACAf,EAAU,YACV,CAACA,EAAU,WAAW,SAASe,EAAM,UAAU,IAAI,EAEnD,MAAM,IAAIC,EAAsBhB,EAAU,UAAWe,EAAM,UAAU,IAAI,EAE1E,OAAOZ,EAAQ,QACdY,EACGf,EAAU,WAAW,CAAE,GAAGe,EAAO,eAAgBf,EAAU,cAAe,CAAC,EAC3EG,EAAQ,QAAQ,IAAA,EAAS,MAE3BA,EAAQ,QACPS,GAAa,WAAWE,CAAM,GAAKX,EAAQ,QAAQ,IAAA,EAAS,MACtDA,EAAQ,QAAQW,CAAM,CAC7B,CACF,CACD,CAAC,CACH,CACA,CACD,CACF,CACD,CAAC,CACF,CAEA,IAAaL,EAAb,cAA4C,KAAM,CACjD,KAAgB,iCAChB,KAAgB,yBAChB,YAAY,EAAmB,CAC9B,MAAM,+BAA+BQ,EAAU,+BAA+B,CAC/E,CACD,EACaD,EAAb,cAA2C,KAAM,CAChD,KAAgB,iCAChB,KAAgB,wBAChB,YAAY,EAAmB,EAAuB,CACrD,MACC,cAAcC,EAAU,4BAA4BC,EAAc,kCACnE,CACD,CACD,EACaC,EAAb,cAA4C,KAAM,CACjD,KAAgB,oCAChB,KAAgB,yBAChB,YAAY,EAAmB,CAC9B,MACC,cAAcF,EAAU,kEACzB,CACD,CACD,E"}