cvx-kit 0.1.35 → 2.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/README.md +92 -49
  2. package/dist/agent-tools.d.mts +21 -25
  3. package/dist/agent-tools.mjs +1 -1
  4. package/dist/agent-tools.mjs.map +1 -1
  5. package/dist/auth.d.mts +20 -14
  6. package/dist/auth.mjs +1 -1
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/components/approvals/_generated/api.d.mts +4 -5
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -1
  10. package/dist/components/approvals/_generated/component.d.mts +0 -2
  11. package/dist/components/approvals/_generated/dataModel.d.mts +1 -3
  12. package/dist/components/approvals/_generated/server.d.mts +0 -2
  13. package/dist/components/approvals/_generated/server.mjs.map +1 -1
  14. package/dist/components/approvals/audit.d.mts +0 -1
  15. package/dist/components/approvals/audit.mjs +1 -1
  16. package/dist/components/approvals/audit.mjs.map +1 -1
  17. package/dist/components/approvals/client.d.mts +0 -1
  18. package/dist/components/approvals/client.mjs +1 -1
  19. package/dist/components/approvals/client.mjs.map +1 -1
  20. package/dist/components/approvals/constants.d.mts +0 -1
  21. package/dist/components/approvals/constants.mjs.map +1 -1
  22. package/dist/components/approvals/convex.config.d.mts +0 -2
  23. package/dist/components/approvals/convex.config.mjs.map +1 -1
  24. package/dist/components/approvals/decisions.d.mts +1 -4
  25. package/dist/components/approvals/decisions.mjs +1 -1
  26. package/dist/components/approvals/decisions.mjs.map +1 -1
  27. package/dist/components/approvals/functions.d.mts +0 -1
  28. package/dist/components/approvals/functions.mjs.map +1 -1
  29. package/dist/components/approvals/health.d.mts +0 -1
  30. package/dist/components/approvals/health.mjs.map +1 -1
  31. package/dist/components/approvals/requests.d.mts +106 -123
  32. package/dist/components/approvals/requests.mjs +1 -1
  33. package/dist/components/approvals/requests.mjs.map +1 -1
  34. package/dist/components/approvals/schema.d.ts +106 -315
  35. package/dist/components/approvals/schema.js +1 -1
  36. package/dist/components/approvals/validators.d.mts +321 -393
  37. package/dist/components/approvals/validators.mjs +1 -1
  38. package/dist/components/approvals/validators.mjs.map +1 -1
  39. package/dist/components/approvals/workflow.d.mts +0 -1
  40. package/dist/components/approvals/workflow.mjs +1 -1
  41. package/dist/components/approvals/workflow.mjs.map +1 -1
  42. package/dist/components/approvals/workflow_steps.d.mts +1 -2
  43. package/dist/components/approvals/workflow_steps.mjs.map +1 -1
  44. package/dist/components/foundation/_generated/api.d.mts +3 -4
  45. package/dist/components/foundation/_generated/api.mjs.map +1 -1
  46. package/dist/components/foundation/_generated/component.d.mts +0 -2
  47. package/dist/components/foundation/_generated/dataModel.d.mts +1 -3
  48. package/dist/components/foundation/_generated/server.d.mts +0 -2
  49. package/dist/components/foundation/_generated/server.mjs.map +1 -1
  50. package/dist/components/foundation/client.d.mts +0 -1
  51. package/dist/components/foundation/client.mjs +1 -1
  52. package/dist/components/foundation/client.mjs.map +1 -1
  53. package/dist/components/foundation/convex.config.d.mts +0 -2
  54. package/dist/components/foundation/convex.config.mjs.map +1 -1
  55. package/dist/components/foundation/functions.d.mts +0 -1
  56. package/dist/components/foundation/functions.mjs.map +1 -1
  57. package/dist/components/foundation/modules/command/command.d.mts +0 -1
  58. package/dist/components/foundation/modules/command/command.mjs.map +1 -1
  59. package/dist/components/foundation/modules/command/lifecycle.d.mts +0 -2
  60. package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -1
  61. package/dist/components/foundation/modules/observability/observability.d.mts +0 -1
  62. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
  63. package/dist/components/foundation/modules/query/query.d.mts +0 -1
  64. package/dist/components/foundation/modules/query/query.mjs.map +1 -1
  65. package/dist/components/foundation/operation.d.mts +2 -3
  66. package/dist/components/foundation/operation.mjs.map +1 -1
  67. package/dist/components/foundation/result.d.mts +0 -1
  68. package/dist/components/foundation/result.mjs.map +1 -1
  69. package/dist/components/foundation/schema.d.ts +0 -2
  70. package/dist/components/foundation/telemetry.d.mts +0 -1
  71. package/dist/components/foundation/telemetry.mjs +1 -1
  72. package/dist/components/foundation/telemetry.mjs.map +1 -1
  73. package/dist/contracts.d.mts +2 -2
  74. package/dist/contracts.mjs +1 -1
  75. package/dist/crud.d.mts +93 -97
  76. package/dist/crud.mjs +1 -1
  77. package/dist/crud.mjs.map +1 -1
  78. package/dist/effect.d.mts +2 -3
  79. package/dist/effect.mjs +1 -1
  80. package/dist/errors.d.mts +2 -4
  81. package/dist/errors.mjs +1 -1
  82. package/dist/errors.mjs.map +1 -1
  83. package/dist/filters.d.mts +1 -1
  84. package/dist/filters.mjs +1 -1
  85. package/dist/idempotency.mjs +1 -1
  86. package/dist/index.d.mts +10 -7
  87. package/dist/index.mjs +1 -1
  88. package/dist/json-schema.d.mts +40 -0
  89. package/dist/json-schema.mjs +2 -0
  90. package/dist/json-schema.mjs.map +1 -0
  91. package/dist/k/compile.d.mts +17 -0
  92. package/dist/k/compile.mjs +2 -0
  93. package/dist/k/compile.mjs.map +1 -0
  94. package/dist/k/dates.d.mts +23 -0
  95. package/dist/k/dates.mjs +2 -0
  96. package/dist/k/dates.mjs.map +1 -0
  97. package/dist/k/formats.d.mts +24 -0
  98. package/dist/k/formats.mjs +2 -0
  99. package/dist/k/formats.mjs.map +1 -0
  100. package/dist/k/index.d.mts +32 -0
  101. package/dist/k/index.mjs +2 -0
  102. package/dist/k/index.mjs.map +1 -0
  103. package/dist/k/issues.d.mts +31 -0
  104. package/dist/k/issues.mjs +2 -0
  105. package/dist/k/issues.mjs.map +1 -0
  106. package/dist/k/kinds.d.mts +81 -0
  107. package/dist/k/kinds.mjs +2 -0
  108. package/dist/k/kinds.mjs.map +1 -0
  109. package/dist/k/object.d.mts +43 -0
  110. package/dist/k/object.mjs +2 -0
  111. package/dist/k/object.mjs.map +1 -0
  112. package/dist/k/parse.d.mts +29 -0
  113. package/dist/k/parse.mjs +2 -0
  114. package/dist/k/parse.mjs.map +1 -0
  115. package/dist/k/schema.d.mts +100 -0
  116. package/dist/k/schema.mjs +2 -0
  117. package/dist/k/schema.mjs.map +1 -0
  118. package/dist/k/standard.d.mts +8 -0
  119. package/dist/k/standard.mjs +2 -0
  120. package/dist/k/standard.mjs.map +1 -0
  121. package/dist/k/types.d.mts +64 -0
  122. package/dist/k/types.mjs +1 -0
  123. package/dist/k.d.mts +8 -0
  124. package/dist/k.mjs +1 -0
  125. package/dist/middleware.d.mts +0 -2
  126. package/dist/middleware.mjs +1 -1
  127. package/dist/middleware.mjs.map +1 -1
  128. package/dist/modules/contracts/binding.d.mts +1 -2
  129. package/dist/modules/contracts/binding.mjs.map +1 -1
  130. package/dist/modules/contracts/contract.d.mts +0 -2
  131. package/dist/modules/contracts/contract.mjs.map +1 -1
  132. package/dist/modules/contracts/convex.d.mts +1 -3
  133. package/dist/modules/contracts/convex.mjs.map +1 -1
  134. package/dist/modules/contracts/domain.d.mts +1 -2
  135. package/dist/modules/contracts/domain.mjs.map +1 -1
  136. package/dist/modules/contracts/errors.d.mts +161 -2
  137. package/dist/modules/contracts/errors.mjs +1 -1
  138. package/dist/modules/contracts/errors.mjs.map +1 -1
  139. package/dist/modules/contracts/exposure.d.mts +1 -2
  140. package/dist/modules/contracts/exposure.mjs.map +1 -1
  141. package/dist/modules/contracts/idempotency.d.mts +1 -2
  142. package/dist/modules/contracts/idempotency.mjs +1 -1
  143. package/dist/modules/contracts/idempotency.mjs.map +1 -1
  144. package/dist/modules/contracts/lazy.d.mts +0 -2
  145. package/dist/modules/contracts/lazy.mjs.map +1 -1
  146. package/dist/modules/contracts/standard.d.mts +7 -5
  147. package/dist/modules/contracts/standard.mjs +1 -1
  148. package/dist/modules/contracts/standard.mjs.map +1 -1
  149. package/dist/modules/contracts/workflow.d.mts +1 -2
  150. package/dist/modules/contracts/workflow.mjs.map +1 -1
  151. package/dist/modules/effect/action.d.mts +6 -7
  152. package/dist/modules/effect/action.mjs +1 -1
  153. package/dist/modules/effect/action.mjs.map +1 -1
  154. package/dist/modules/effect/agent-tools.mjs +1 -1
  155. package/dist/modules/effect/api-runtime.d.mts +1 -2
  156. package/dist/modules/effect/api-runtime.mjs +1 -1
  157. package/dist/modules/effect/api-runtime.mjs.map +1 -1
  158. package/dist/modules/effect/api.d.mts +41 -15
  159. package/dist/modules/effect/api.mjs +1 -1
  160. package/dist/modules/effect/api.mjs.map +1 -1
  161. package/dist/modules/effect/auth.d.mts +5 -6
  162. package/dist/modules/effect/auth.mjs +1 -1
  163. package/dist/modules/effect/auth.mjs.map +1 -1
  164. package/dist/modules/effect/client.d.mts +7 -8
  165. package/dist/modules/effect/client.mjs +1 -1
  166. package/dist/modules/effect/command.d.mts +7 -5
  167. package/dist/modules/effect/command.mjs +1 -1
  168. package/dist/modules/effect/command.mjs.map +1 -1
  169. package/dist/modules/effect/crud.d.mts +272 -206
  170. package/dist/modules/effect/crud.mjs +1 -1
  171. package/dist/modules/effect/crud.mjs.map +1 -1
  172. package/dist/modules/effect/domain.d.mts +5 -6
  173. package/dist/modules/effect/domain.mjs.map +1 -1
  174. package/dist/modules/effect/errors.d.mts +4 -2
  175. package/dist/modules/effect/errors.mjs +1 -1
  176. package/dist/modules/effect/errors.mjs.map +1 -1
  177. package/dist/modules/effect/failure-audit.d.mts +2 -2
  178. package/dist/modules/effect/failure-audit.mjs +1 -1
  179. package/dist/modules/effect/failure-audit.mjs.map +1 -1
  180. package/dist/modules/effect/failures.d.mts +1 -2
  181. package/dist/modules/effect/failures.mjs.map +1 -1
  182. package/dist/modules/effect/foundation.d.mts +0 -2
  183. package/dist/modules/effect/foundation.mjs.map +1 -1
  184. package/dist/modules/effect/idempotency.d.mts +2 -3
  185. package/dist/modules/effect/idempotency.mjs +1 -1
  186. package/dist/modules/effect/idempotency.mjs.map +1 -1
  187. package/dist/modules/effect/input.d.mts +10 -0
  188. package/dist/modules/effect/input.mjs +2 -0
  189. package/dist/modules/effect/input.mjs.map +1 -0
  190. package/dist/modules/effect/normalize.d.mts +0 -2
  191. package/dist/modules/effect/normalize.mjs.map +1 -1
  192. package/dist/modules/effect/operation.d.mts +2 -3
  193. package/dist/modules/effect/operation.mjs.map +1 -1
  194. package/dist/modules/effect/query.d.mts +6 -4
  195. package/dist/modules/effect/query.mjs +1 -1
  196. package/dist/modules/effect/query.mjs.map +1 -1
  197. package/dist/modules/effect/schema.d.mts +0 -2
  198. package/dist/modules/effect/schema.mjs.map +1 -1
  199. package/dist/modules/effect/scope.d.mts +0 -2
  200. package/dist/modules/effect/scope.mjs.map +1 -1
  201. package/dist/modules/effect/workflow.d.mts +4 -5
  202. package/dist/modules/effect/workflow.mjs +1 -1
  203. package/dist/modules/effect/workflow.mjs.map +1 -1
  204. package/dist/modules/foundation/foundation.d.mts +4 -5
  205. package/dist/modules/foundation/foundation.mjs +1 -1
  206. package/dist/modules/foundation/foundation.mjs.map +1 -1
  207. package/dist/modules/foundation/operation.d.mts +2 -3
  208. package/dist/modules/foundation/operation.mjs.map +1 -1
  209. package/dist/namespace.d.mts +104 -0
  210. package/dist/namespace.mjs +2 -0
  211. package/dist/namespace.mjs.map +1 -0
  212. package/dist/oxlint/architecture.d.mts +0 -2
  213. package/dist/oxlint/architecture.mjs +1 -1
  214. package/dist/oxlint/architecture.mjs.map +1 -1
  215. package/dist/oxlint/ast.d.mts +16 -8
  216. package/dist/oxlint/ast.mjs +1 -1
  217. package/dist/oxlint/ast.mjs.map +1 -1
  218. package/dist/oxlint/components.d.mts +0 -2
  219. package/dist/oxlint/components.mjs.map +1 -1
  220. package/dist/oxlint/ownership.d.mts +0 -2
  221. package/dist/oxlint/ownership.mjs +1 -1
  222. package/dist/oxlint/ownership.mjs.map +1 -1
  223. package/dist/oxlint/reserved-files.d.mts +0 -2
  224. package/dist/oxlint/reserved-files.mjs +1 -1
  225. package/dist/oxlint/reserved-files.mjs.map +1 -1
  226. package/dist/oxlint.d.mts +0 -2
  227. package/dist/oxlint.mjs +1 -1
  228. package/dist/oxlint.mjs.map +1 -1
  229. package/dist/querying/cursors.d.mts +27 -9
  230. package/dist/querying/cursors.mjs +1 -1
  231. package/dist/querying/cursors.mjs.map +1 -1
  232. package/dist/querying/execution.d.mts +6 -7
  233. package/dist/querying/execution.mjs +1 -1
  234. package/dist/querying/execution.mjs.map +1 -1
  235. package/dist/querying/failures.d.mts +0 -2
  236. package/dist/querying/failures.mjs +1 -1
  237. package/dist/querying/failures.mjs.map +1 -1
  238. package/dist/querying/filter-boundary.d.mts +18 -9
  239. package/dist/querying/filter-boundary.mjs +1 -1
  240. package/dist/querying/filter-boundary.mjs.map +1 -1
  241. package/dist/querying/filters.d.mts +71 -35
  242. package/dist/querying/filters.mjs +1 -1
  243. package/dist/querying/filters.mjs.map +1 -1
  244. package/dist/querying/planner.d.mts +16 -20
  245. package/dist/querying/planner.mjs +1 -1
  246. package/dist/querying/planner.mjs.map +1 -1
  247. package/dist/querying/relationships.d.mts +6 -6
  248. package/dist/querying/relationships.mjs +1 -1
  249. package/dist/querying/relationships.mjs.map +1 -1
  250. package/dist/querying/search.d.mts +12 -12
  251. package/dist/querying/search.mjs +1 -1
  252. package/dist/querying/search.mjs.map +1 -1
  253. package/dist/querying/security.d.mts +2 -3
  254. package/dist/querying/security.mjs.map +1 -1
  255. package/dist/querying/shared/ast.d.mts +0 -2
  256. package/dist/querying/shared/ast.mjs.map +1 -1
  257. package/dist/querying/shared/contract.d.mts +17 -23
  258. package/dist/querying/shared/contract.mjs +1 -1
  259. package/dist/querying/shared/contract.mjs.map +1 -1
  260. package/dist/querying/shared/evaluate.d.mts +0 -2
  261. package/dist/querying/shared/evaluate.mjs.map +1 -1
  262. package/dist/querying/shared/filters.d.mts +47 -29
  263. package/dist/querying/shared/filters.mjs +1 -1
  264. package/dist/querying/shared/filters.mjs.map +1 -1
  265. package/dist/querying/shared/native-json.d.mts +7 -0
  266. package/dist/querying/shared/native-json.mjs +2 -0
  267. package/dist/querying/shared/native-json.mjs.map +1 -0
  268. package/dist/querying/shared/page.d.mts +19 -22
  269. package/dist/querying/shared/page.mjs +1 -1
  270. package/dist/querying/shared/page.mjs.map +1 -1
  271. package/dist/querying.d.mts +6 -9
  272. package/dist/querying.mjs +1 -1
  273. package/dist/querying.mjs.map +1 -1
  274. package/dist/react/failures.d.mts +0 -2
  275. package/dist/react/failures.mjs.map +1 -1
  276. package/dist/react/optimistic.d.mts +2 -3
  277. package/dist/react/optimistic.mjs.map +1 -1
  278. package/dist/react/pagination-state.d.mts +1 -2
  279. package/dist/react/pagination-state.mjs.map +1 -1
  280. package/dist/react/use-command.d.mts +0 -2
  281. package/dist/react/use-command.mjs.map +1 -1
  282. package/dist/react/use-paginated-list.d.mts +1 -3
  283. package/dist/react/use-paginated-list.mjs +1 -1
  284. package/dist/react/use-paginated-list.mjs.map +1 -1
  285. package/dist/react.d.mts +1 -1
  286. package/dist/react.mjs +1 -1
  287. package/dist/registration.d.mts +65 -0
  288. package/dist/registration.mjs +2 -0
  289. package/dist/registration.mjs.map +1 -0
  290. package/dist/relations-public.d.mts +2 -2
  291. package/dist/relations-public.mjs +1 -1
  292. package/dist/relations.d.mts +55 -46
  293. package/dist/relations.mjs +1 -1
  294. package/dist/relations.mjs.map +1 -1
  295. package/dist/state-machine.d.mts +0 -2
  296. package/dist/state-machine.mjs.map +1 -1
  297. package/dist/table.d.mts +222 -0
  298. package/dist/table.mjs +2 -0
  299. package/dist/table.mjs.map +1 -0
  300. package/dist/tenancy.d.mts +0 -2
  301. package/dist/tenancy.mjs.map +1 -1
  302. package/dist/triggers.d.mts +2 -4
  303. package/dist/triggers.mjs +1 -1
  304. package/dist/triggers.mjs.map +1 -1
  305. package/dist/webhooks.d.mts +9 -9
  306. package/dist/webhooks.mjs +1 -1
  307. package/dist/webhooks.mjs.map +1 -1
  308. package/dist/workflow.mjs +1 -1
  309. package/dist/zod.d.mts +30 -0
  310. package/dist/zod.mjs +2 -0
  311. package/dist/zod.mjs.map +1 -0
  312. package/package.json +51 -29
  313. package/dist/modules/effect/api-zod.d.mts +0 -34
  314. package/dist/modules/effect/api-zod.mjs +0 -2
  315. package/dist/modules/effect/api-zod.mjs.map +0 -1
  316. package/dist/querying/schema-snapshot.d.mts +0 -49
  317. package/dist/querying/schema-snapshot.mjs +0 -2
  318. package/dist/querying/schema-snapshot.mjs.map +0 -1
  319. package/dist/zod-convex.d.mts +0 -10
  320. package/dist/zod-convex.mjs +0 -2
  321. package/dist/zod-convex.mjs.map +0 -1
  322. package/dist/zod-registration.d.mts +0 -15
  323. package/dist/zod-registration.mjs +0 -2
  324. package/dist/zod-registration.mjs.map +0 -1
  325. package/dist/zod-table.d.mts +0 -351
  326. package/dist/zod-table.mjs +0 -2
  327. package/dist/zod-table.mjs.map +0 -1
@@ -1,8 +1,6 @@
1
- //#region src/modules/contracts/lazy.d.ts
2
1
  /** Retain both successful builds and configuration failures; never repeat declaration effects. */
3
2
  export declare function memoize<Value>(build: () => Value): () => Value;
4
3
  /** Internal bridge lets the architecture test path validate explicitly supplied registries. */
5
4
  export declare function registerLazyRegistry<Registry extends object>(registry: Registry, build: () => object): Registry;
6
5
  export declare function forceRegistry<Registry extends object>(registry: Registry): void;
7
- //#endregion
8
6
  //# sourceMappingURL=lazy.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"lazy.mjs","names":["memoize","state","value","failure","build","cause","registryBuilders","registerLazyRegistry","registry","forceRegistry"],"sources":["../../../src/modules/contracts/lazy.ts"],"sourcesContent":["/** Retain both successful builds and configuration failures; never repeat declaration effects. */\nexport function memoize<Value>(build: () => Value): () => Value {\n\tlet state: 'pending' | 'building' | 'ready' | 'failed' = 'pending'\n\tlet value: Value\n\tlet failure: unknown\n\treturn () => {\n\t\tif (state === 'ready') return value\n\t\tif (state === 'failed') throw failure\n\t\tif (state === 'building') throw new Error('Recursive lazy declaration')\n\t\tstate = 'building'\n\t\ttry {\n\t\t\tvalue = build()\n\t\t\tstate = 'ready'\n\t\t\treturn value\n\t\t} catch (cause) {\n\t\t\tfailure = cause\n\t\t\tstate = 'failed'\n\t\t\tthrow cause\n\t\t}\n\t}\n}\n\nconst registryBuilders = new WeakMap<object, () => object>()\n\n/** Internal bridge lets the architecture test path validate explicitly supplied registries. */\nexport function registerLazyRegistry<Registry extends object>(\n\tregistry: Registry,\n\tbuild: () => object,\n): Registry {\n\tregistryBuilders.set(registry, build)\n\treturn registry\n}\n\nexport function forceRegistry<Registry extends object>(registry: Registry): void {\n\tconst build = registryBuilders.get(registry)\n\tif (!build) throw new Error('Expected a kit Effect registry')\n\t// Getter-declared operations bind on first access; reading every value validates them here too.\n\tvoid Object.values(build())\n}\n"],"mappings":"AACA,SAAgBA,EAAe,EAAiC,CAC/D,IAAIC,EAAqD,UACrDC,EACAC,EACJ,UAAa,CACZ,GAAIF,IAAU,QAAS,OAAOC,EAC9B,GAAID,IAAU,SAAU,MAAME,EAC9B,GAAIF,IAAU,WAAY,MAAU,MAAM,4BAA4B,EACtE,EAAQ,WACR,GAAI,CAGH,MAFA,GAAQG,EAAM,EACd,EAAQ,QACDF,CACR,OAASG,EAAO,CAGf,KAFA,GAAUA,EACV,EAAQ,SACFA,CACP,CACD,CACD,CAEA,MAAMC,kBAAmB,IAAI,QAG7B,SAAgBC,EACf,EACA,EACW,CAEX,OADAD,EAAiB,IAAIE,EAAUJ,CAAK,EAC7BI,CACR,CAEA,SAAgBC,EAAuC,EAA0B,CAChF,IAAML,EAAQE,EAAiB,IAAIE,CAAQ,EAC3C,GAAI,CAACJ,EAAO,MAAU,MAAM,gCAAgC,EAE5D,OAAY,OAAOA,EAAM,CAAC,CAC3B"}
1
+ {"version":3,"file":"lazy.mjs","names":["memoize","state","value","failure","build","cause","registryBuilders","registerLazyRegistry","registry","forceRegistry"],"sources":["../../../src/modules/contracts/lazy.ts"],"sourcesContent":["/** Retain both successful builds and configuration failures; never repeat declaration effects. */\nexport function memoize<Value>(build: () => Value): () => Value {\n\tlet state: 'pending' | 'building' | 'ready' | 'failed' = 'pending'\n\tlet value: Value\n\tlet failure: unknown\n\treturn () => {\n\t\tif (state === 'ready') return value\n\t\tif (state === 'failed') throw failure\n\t\tif (state === 'building') throw new Error('Recursive lazy declaration')\n\t\tstate = 'building'\n\t\ttry {\n\t\t\tvalue = build()\n\t\t\tstate = 'ready'\n\t\t\treturn value\n\t\t} catch (cause) {\n\t\t\tfailure = cause\n\t\t\tstate = 'failed'\n\t\t\tthrow cause\n\t\t}\n\t}\n}\n\nconst registryBuilders = new WeakMap<object, () => object>()\n\n/** Internal bridge lets the architecture test path validate explicitly supplied registries. */\nexport function registerLazyRegistry<Registry extends object>(\n\tregistry: Registry,\n\tbuild: () => object,\n): Registry {\n\tregistryBuilders.set(registry, build)\n\treturn registry\n}\n\nexport function forceRegistry<Registry extends object>(registry: Registry): void {\n\tconst build = registryBuilders.get(registry)\n\tif (!build) throw new Error('Expected a kit Effect registry')\n\t// Getter-declared operations bind on first access; reading every value validates them here too.\n\tvoid Object.values(build())\n}\n"],"mappings":"AACA,SAAgBA,EAAe,EAAiC,CAC/D,IAAIC,EAAqD,UACrDC,EACAC,EACJ,UAAa,CACZ,GAAIF,IAAU,QAAS,OAAOC,EAC9B,GAAID,IAAU,SAAU,MAAME,EAC9B,GAAIF,IAAU,WAAY,MAAU,MAAM,4BAA4B,EACtE,EAAQ,WACR,GAAI,CAGH,MAFA,GAAQG,EAAM,EACd,EAAQ,QACDF,CACR,OAASG,EAAO,CAGf,KAFA,GAAUA,EACV,EAAQ,SACFA,CACP,CACD,CACD,CAEA,MAAMC,kBAAmB,IAAI,QAG7B,SAAgBC,EACf,EACA,EACW,CAEX,OADAD,EAAiB,IAAIE,EAAUJ,CAAK,EAC7BI,CACR,CAEA,SAAgBC,EAAuC,EAA0B,CAChF,IAAML,EAAQE,EAAiB,IAAIE,CAAQ,EAC3C,GAAI,CAACJ,EAAO,MAAU,MAAM,gCAAgC,EAE5D,OAAY,OAAOA,EAAM,CAAC,CAC3B,C"}
@@ -1,15 +1,17 @@
1
1
  import { ContractInput, ContractOutput, Decoder, StandardSchema, ValidationResult } from "./contract.mjs";
2
- import { z } from "zod";
3
- //#region src/modules/contracts/standard.d.ts
2
+ import { KType } from "../../k/types.mjs";
4
3
  /** Standard Schema validation executes exactly the validator supplied by its author. */
5
4
  export declare function standardContract<const S extends StandardSchema<unknown, unknown>>(schema: S): Decoder<ContractInput<S>, ContractOutput<S>, ValidationResult<ContractOutput<S>> | Promise<ValidationResult<ContractOutput<S>>>> & {
6
5
  readonly kind: 'contract';
7
6
  readonly schema: S;
8
7
  };
9
- /** Zod's Standard bridge probes sync first; safeParseAsync executes transforms once. */
10
- export declare function zodContract<const S extends z.ZodType>(schema: S): Decoder<z.input<S>, z.output<S>, Promise<ValidationResult<z.output<S>>>> & {
8
+ /**
9
+ * A `k` schema as a contract: callers supply its input type (`k.input`, defaults optional, before any
10
+ * transform) and the handler receives its output (`k.infer`). Decoding is synchronous; a failure is a
11
+ * validation result whose issues carry the KTD6 `path`, `code` and `message`.
12
+ */
13
+ export declare function kContract<const S extends KType>(schema: S): Decoder<S['validator']['type'], S['_output'], ValidationResult<S['_output']>> & {
11
14
  readonly kind: 'contract';
12
15
  readonly schema: S;
13
16
  };
14
- //#endregion
15
17
  //# sourceMappingURL=standard.d.mts.map
@@ -1,2 +1,2 @@
1
- function e(e){return{kind:`contract`,schema:e,decode:t=>e[`~standard`].validate(t)}}function t(e){return{kind:`contract`,schema:e,decode:async t=>{let n=await e.safeParseAsync(t);return n.success?{value:n.data}:{issues:n.error.issues}}}}export{e as standardContract,t as zodContract};
1
+ function e(e){return{kind:`contract`,schema:e,decode:t=>e[`~standard`].validate(t)}}function t(e){let t=e;return{kind:`contract`,schema:e,decode:e=>{let n=t.safeParse(e);return n.success?{value:n.data}:{issues:n.issues}}}}export{t as kContract,e as standardContract};
2
2
  //# sourceMappingURL=standard.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"standard.mjs","names":["standardContract","schema","value","zodContract","result"],"sources":["../../../src/modules/contracts/standard.ts"],"sourcesContent":["import type {\n\tContractInput,\n\tContractOutput,\n\tDecoder,\n\tStandardSchema,\n\tValidationResult,\n} from './contract'\nimport type { z } from 'zod'\n\n/** Standard Schema validation executes exactly the validator supplied by its author. */\nexport function standardContract<const S extends StandardSchema<unknown, unknown>>(\n\tschema: S,\n): Decoder<\n\tContractInput<S>,\n\tContractOutput<S>,\n\tValidationResult<ContractOutput<S>> | Promise<ValidationResult<ContractOutput<S>>>\n> & { readonly kind: 'contract'; readonly schema: S } {\n\treturn {\n\t\tkind: 'contract',\n\t\tschema,\n\t\t// SAFETY: structural Standard Schema inference associates validate's output with S.\n\t\tdecode: (value) =>\n\t\t\tschema['~standard'].validate(value) as\n\t\t\t\t| ValidationResult<ContractOutput<S>>\n\t\t\t\t| Promise<ValidationResult<ContractOutput<S>>>,\n\t}\n}\n\n/** Zod's Standard bridge probes sync first; safeParseAsync executes transforms once. */\nexport function zodContract<const S extends z.ZodType>(\n\tschema: S,\n): Decoder<z.input<S>, z.output<S>, Promise<ValidationResult<z.output<S>>>> & {\n\treadonly kind: 'contract'\n\treadonly schema: S\n} {\n\treturn {\n\t\tkind: 'contract',\n\t\tschema,\n\t\tdecode: async (value) => {\n\t\t\tconst result = await schema.safeParseAsync(value)\n\t\t\treturn result.success ? { value: result.data } : { issues: result.error.issues }\n\t\t},\n\t}\n}\n"],"mappings":"AAUA,SAAgBA,EACf,EAKqD,CACrD,MAAO,CACN,KAAM,WACN,SAEA,OAAS,GACRC,EAAO,YAAY,CAAC,SAASC,CAAK,CAGpC,CACD,CAGA,SAAgBC,EACf,EAIC,CACD,MAAO,CACN,KAAM,WACN,SACA,OAAQ,KAAO,IAAU,CACxB,IAAMC,EAAS,MAAMH,EAAO,eAAeC,CAAK,EAChD,OAAOE,EAAO,QAAU,CAAE,MAAOA,EAAO,IAAK,EAAI,CAAE,OAAQA,EAAO,MAAM,MAAO,CAChF,CACD,CACD"}
1
+ {"version":3,"file":"standard.mjs","names":["standardContract","schema","value","kContract","parser","result"],"sources":["../../../src/modules/contracts/standard.ts"],"sourcesContent":["import type {\n\tContractInput,\n\tContractOutput,\n\tDecoder,\n\tStandardSchema,\n\tValidationResult,\n} from './contract'\nimport type { KSafeParseResult } from '../../k/issues'\nimport type { KType } from '../../k/types'\n\n/** Standard Schema validation executes exactly the validator supplied by its author. */\nexport function standardContract<const S extends StandardSchema<unknown, unknown>>(\n\tschema: S,\n): Decoder<\n\tContractInput<S>,\n\tContractOutput<S>,\n\tValidationResult<ContractOutput<S>> | Promise<ValidationResult<ContractOutput<S>>>\n> & { readonly kind: 'contract'; readonly schema: S } {\n\treturn {\n\t\tkind: 'contract',\n\t\tschema,\n\t\t// SAFETY: structural Standard Schema inference associates validate's output with S.\n\t\tdecode: (value) =>\n\t\t\tschema['~standard'].validate(value) as\n\t\t\t\t| ValidationResult<ContractOutput<S>>\n\t\t\t\t| Promise<ValidationResult<ContractOutput<S>>>,\n\t}\n}\n\n/**\n * A `k` schema as a contract: callers supply its input type (`k.input`, defaults optional, before any\n * transform) and the handler receives its output (`k.infer`). Decoding is synchronous; a failure is a\n * validation result whose issues carry the KTD6 `path`, `code` and `message`.\n */\nexport function kContract<const S extends KType>(\n\tschema: S,\n): Decoder<S['validator']['type'], S['_output'], ValidationResult<S['_output']>> & {\n\treadonly kind: 'contract'\n\treadonly schema: S\n} {\n\t// SAFETY: every KType at runtime is a KSchema record, which carries safeParse.\n\tconst parser = schema as S & {\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Contracts decode undecoded transport input.\n\t\tsafeParse: (value: unknown) => KSafeParseResult<S['_output']>\n\t}\n\treturn {\n\t\tkind: 'contract',\n\t\tschema,\n\t\tdecode: (value) => {\n\t\t\tconst result = parser.safeParse(value)\n\t\t\treturn result.success ? { value: result.data } : { issues: result.issues }\n\t\t},\n\t}\n}\n"],"mappings":"AAWA,SAAgBA,EACf,EAKqD,CACrD,MAAO,CACN,KAAM,WACN,SAEA,OAAS,GACRC,EAAO,YAAY,CAAC,SAASC,CAAK,CAGpC,CACD,CAOA,SAAgBC,EACf,EAIC,CAED,IAAMC,EAASH,EAIf,MAAO,CACN,KAAM,WACN,SACA,OAAS,GAAU,CAClB,IAAMI,EAASD,EAAO,UAAUF,CAAK,EACrC,OAAOG,EAAO,QAAU,CAAE,MAAOA,EAAO,IAAK,EAAI,CAAE,OAAQA,EAAO,MAAO,CAC1E,CACD,CACD,C"}
@@ -2,7 +2,6 @@ import { ContractInput, ContractOutput, NeutralSchema } from "./contract.mjs";
2
2
  import { CanonicalConvexBounds, IdempotencyInvocation, IdempotencyPreparation } from "./idempotency.mjs";
3
3
  import { FunctionReference, FunctionType, FunctionVisibility } from "convex/server";
4
4
  import { WorkflowCtx } from "@convex-dev/workflow";
5
- //#region src/modules/contracts/workflow.d.ts
6
5
  export declare class WorkflowBindingError extends Error {
7
6
  readonly _tag = "WorkflowBindingError";
8
7
  constructor(message: string);
@@ -162,5 +161,5 @@ export declare function workflowStatusBindings<Result, Failure>(configuration: {
162
161
  state: WorkflowHostState<Result, Failure>;
163
162
  }>;
164
163
  };
165
- //#endregion
164
+ export {};
166
165
  //# sourceMappingURL=workflow.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.mjs","names":["WorkflowBindingError","message","fields","descriptorBounds","workflowExecution","value","field","descriptor","canonicalConvexBytes","workflowBinding","compatibleVersions","binding","version","snapshot","runWorkflowStep","runner","step","execution","input","versions","nativeOptions","options","output","workflowDecode","decoded","decodeContract","schema","workflowAttempt","authority","configuration","receiptWorkflowMutation","adapter","preparation","workflowReceiptInvocation","captureIdempotencyInvocation","terminalWorkflowAttempt","error","terminal","safeFailure","workflowTransition","generation","current","update","nativeStatus","outcome","status","state","workflowCancel","expectedGeneration","workflowRestart","workflowStatusBindings","apply","transition"],"sources":["../../../src/modules/contracts/workflow.ts"],"sourcesContent":["import type { FunctionReference, FunctionVisibility, FunctionType } from 'convex/server'\nimport type { WorkflowCtx } from '@convex-dev/workflow'\nimport {\n\tdecodeContract,\n\ttype ContractInput,\n\ttype ContractOutput,\n\ttype NeutralSchema,\n} from './contract'\nimport {\n\tcanonicalConvexBytes,\n\tcaptureIdempotencyInvocation,\n\ttype CanonicalConvexBounds,\n\ttype IdempotencyInvocation,\n\ttype IdempotencyPreparation,\n} from './idempotency'\n\nexport class WorkflowBindingError extends Error {\n\treadonly _tag = 'WorkflowBindingError'\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'WorkflowBindingError'\n\t}\n}\nexport interface WorkflowExecution<Args = unknown> {\n\treadonly version: 1\n\treadonly operation: string\n\treadonly operationVersion: string\n\treadonly contractVersion: string\n\treadonly bindingVersion: string\n\t/** Host-issued business-run identity. Recovery preserves it. */\n\treadonly run: string\n\t/** Opaque host capability; never caller-supplied principal or tenant authority. */\n\treadonly capability: string\n\t/** Logical occurrence, distinct for each repeated loop step. */\n\treadonly occurrence: string\n\treadonly args: Args\n}\nexport type WorkflowStepArguments<Args> = { execution: WorkflowExecution<Args> }\nconst fields = [\n\t'version',\n\t'operation',\n\t'operationVersion',\n\t'contractVersion',\n\t'bindingVersion',\n\t'run',\n\t'capability',\n\t'occurrence',\n\t'args',\n] as const\nconst descriptorBounds = {\n\tmaxDepth: 64,\n\tmaxNodes: 100000,\n\tmaxBytes: 1000000,\n\tmaxArrayLength: 100000,\n\tmaxObjectFields: 100000,\n}\n/** Strict plain, versioned transport. Validity does not confer authority; the host resolves capability anew. */\n/* oxlint-disable anti-slop/no-unknown-parameters, anti-slop/no-runtime-typeof -- This decoder validates an untrusted execution descriptor before it enters the native workflow boundary. */\nexport function workflowExecution<Args>(value: WorkflowExecution<Args>): WorkflowExecution<Args>\nexport function workflowExecution(value: unknown): WorkflowExecution\nexport function workflowExecution(value: unknown): WorkflowExecution {\n\tif (\n\t\t!value ||\n\t\ttypeof value !== 'object' ||\n\t\tObject.getPrototypeOf(value) !== Object.prototype ||\n\t\tReflect.ownKeys(value).length !== fields.length ||\n\t\tfields.some((field) => !Object.hasOwn(value, field))\n\t)\n\t\tthrow new WorkflowBindingError('Execution requires exact plain descriptor fields')\n\t// SAFETY: the exact field set is checked above; values and accessors are checked before use below.\n\tconst descriptor = value as WorkflowExecution\n\tfor (const field of fields)\n\t\tif (!('value' in Object.getOwnPropertyDescriptor(value, field)!))\n\t\t\tthrow new WorkflowBindingError('Execution cannot contain accessors')\n\tif (\n\t\tdescriptor.version !== 1 ||\n\t\tfields\n\t\t\t.filter((field) => field !== 'version' && field !== 'args')\n\t\t\t.some((field) => typeof descriptor[field] !== 'string' || descriptor[field].length === 0)\n\t)\n\t\tthrow new WorkflowBindingError('Invalid execution descriptor version or identity')\n\ttry {\n\t\tcanonicalConvexBytes(descriptor.args, descriptorBounds)\n\t} catch {\n\t\tthrow new WorkflowBindingError('Execution args require plain Convex data')\n\t}\n\treturn descriptor\n}\n/* oxlint-enable anti-slop/no-unknown-parameters, anti-slop/no-runtime-typeof */\nexport interface WorkflowBinding<\n\tKind extends FunctionType,\n\tArgs extends NeutralSchema,\n\tResult extends NeutralSchema,\n> {\n\treadonly kind: Kind\n\treadonly operation: string\n\treadonly operationVersion: string\n\treadonly contractVersion: string\n\treadonly bindingVersion: string\n\treadonly args: Args\n\treadonly result: Result\n\treadonly reference: FunctionReference<\n\t\tNoInfer<Kind>,\n\t\tFunctionVisibility,\n\t\tWorkflowStepArguments<NoInfer<ContractInput<Args>>>,\n\t\tNoInfer<ContractInput<Result>>\n\t>\n\t/** Host explicitly lists deployed descriptor versions whose semantics remain compatible. */\n\treadonly compatibleVersions?: readonly {\n\t\toperationVersion: string\n\t\tcontractVersion: string\n\t\tbindingVersion: string\n\t}[]\n}\n/** Both phantom reference args and results must match the explicit wire contracts. */\nexport function workflowBinding<\n\tKind extends FunctionType,\n\tconst Args extends NeutralSchema,\n\tconst Result extends NeutralSchema,\n>(binding: WorkflowBinding<Kind, Args, Result>): WorkflowBinding<Kind, Args, Result> {\n\tconst compatibleVersions = binding.compatibleVersions?.map((version) =>\n\t\tObject.freeze({ ...version }),\n\t)\n\tconst snapshot = { ...binding }\n\tif (compatibleVersions !== undefined)\n\t\tsnapshot.compatibleVersions = Object.freeze(compatibleVersions)\n\treturn Object.freeze(snapshot)\n}\nexport type WorkflowStepOptions = {\n\tname?: string\n\tretry?: NonNullable<Parameters<WorkflowCtx['withOptions']>[0]['retry']>\n} & (\n\t| { inline?: false; runAt?: number; runAfter?: number }\n\t| { inline: true; runAt?: never; runAfter?: never }\n)\n/** A structural seam allows invocation-scoped native WorkflowCtx without creating another durability runtime. */\nexport interface WorkflowStepRunner {\n\t/* oxlint-disable anti-slop/no-unknown-returns -- Native runner results stay opaque here; runWorkflowStep correlates them with the binding's raw result contract without replay decoding. */\n\trunQuery?: (\n\t\treference: FunctionReference<'query', FunctionVisibility>,\n\t\targs: WorkflowStepArguments<unknown>,\n\t\toptions?: WorkflowStepOptions,\n\t) => Promise<unknown>\n\trunMutation?: (\n\t\treference: FunctionReference<'mutation', FunctionVisibility>,\n\t\targs: WorkflowStepArguments<unknown>,\n\t\toptions?: WorkflowStepOptions,\n\t) => Promise<unknown>\n\trunAction?: (\n\t\treference: FunctionReference<'action', FunctionVisibility>,\n\t\targs: WorkflowStepArguments<unknown>,\n\t\toptions?: WorkflowStepOptions,\n\t) => Promise<unknown>\n\t/* oxlint-enable anti-slop/no-unknown-returns */\n}\nexport async function runWorkflowStep<\n\tKind extends FunctionType,\n\tArgs extends NeutralSchema,\n\tResult extends NeutralSchema,\n>(\n\tstep: WorkflowCtx | WorkflowStepRunner,\n\tbinding: WorkflowBinding<Kind, Args, Result>,\n\tinput: WorkflowExecution<ContractInput<Args>>,\n\toptions: WorkflowStepOptions = {},\n): Promise<ContractInput<Result>> {\n\t// SAFETY: each binding has nonempty, checked generated args. Native ArgsAndOptions' empty-args overload is never selected.\n\tconst runner = step as WorkflowStepRunner\n\tconst execution = workflowExecution(input)\n\tconst versions = [binding, ...(binding.compatibleVersions ?? [])]\n\tif (\n\t\texecution.operation !== binding.operation ||\n\t\t!versions.some(\n\t\t\t(version) =>\n\t\t\t\tversion.operationVersion === execution.operationVersion &&\n\t\t\t\tversion.contractVersion === execution.contractVersion &&\n\t\t\t\tversion.bindingVersion === execution.bindingVersion,\n\t\t)\n\t)\n\t\tthrow new WorkflowBindingError('Incompatible workflow operation version')\n\tconst nativeOptions = {\n\t\t...options,\n\t\tname: options.name ?? `${execution.operation}:${execution.occurrence}`,\n\t}\n\tlet output: unknown\n\tswitch (binding.kind) {\n\t\tcase 'query':\n\t\t\tif (!runner.runQuery) throw new WorkflowBindingError('Native query runner missing')\n\t\t\t// SAFETY: the checked binding kind selects this exact native reference kind.\n\t\t\toutput = await runner.runQuery(\n\t\t\t\tbinding.reference as FunctionReference<'query', FunctionVisibility>,\n\t\t\t\t{ execution },\n\t\t\t\tnativeOptions,\n\t\t\t)\n\t\t\tbreak\n\t\tcase 'mutation':\n\t\t\tif (!runner.runMutation) throw new WorkflowBindingError('Native mutation runner missing')\n\t\t\t// SAFETY: the checked binding kind selects this exact native reference kind.\n\t\t\toutput = await runner.runMutation(\n\t\t\t\tbinding.reference as FunctionReference<'mutation', FunctionVisibility>,\n\t\t\t\t{ execution },\n\t\t\t\tnativeOptions,\n\t\t\t)\n\t\t\tbreak\n\t\tcase 'action':\n\t\t\tif (!runner.runAction) throw new WorkflowBindingError('Native action runner missing')\n\t\t\tif (options.inline) throw new WorkflowBindingError('Actions cannot execute inline')\n\t\t\t// SAFETY: the checked binding kind selects this exact native reference kind.\n\t\t\toutput = await runner.runAction(\n\t\t\t\tbinding.reference as FunctionReference<'action', FunctionVisibility>,\n\t\t\t\t{ execution },\n\t\t\t\t{ ...nativeOptions, retry: options.retry ?? false },\n\t\t\t)\n\t\t\tbreak\n\t}\n\t// Native validators own wire validation. Replaying workflow code must not rerun transforms.\n\t// SAFETY: the binding correlates the generated reference's result with this raw wire contract.\n\treturn output as ContractInput<Result>\n}\nexport async function workflowDecode<S extends NeutralSchema>(\n\tschema: S,\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- The schema parses retained or native transport values at this boundary.\n\tvalue: unknown,\n): Promise<ContractOutput<S>> {\n\tconst decoded = await decodeContract(schema, value)\n\tif (decoded.issues) throw new WorkflowBindingError('Workflow contract validation failed')\n\treturn decoded.value\n}\ntype Ordinary<A> = A | PromiseLike<A>\n/** This helper belongs inside a registered native function, never in the replaying workflow handler. */\nexport function workflowAttempt<Args, Authority, Result>(configuration: {\n\tauthorize: (execution: WorkflowExecution<Args>) => Ordinary<Authority>\n\texecute: (execution: WorkflowExecution<Args>, authority: Authority) => Ordinary<Result>\n}) {\n\treturn async (input: WorkflowExecution<Args>): Promise<Result> => {\n\t\tconst execution = workflowExecution(input)\n\t\tconst authority = await configuration.authorize(execution)\n\t\treturn configuration.execute(execution, authority)\n\t}\n}\nexport type WorkflowOutcome<Result = unknown, Failure = unknown> =\n\t| { readonly version: 1; readonly kind: 'succeeded'; readonly value: Result }\n\t| { readonly version: 1; readonly kind: 'failed'; readonly error: Failure }\ndeclare const protectedMutation: unique symbol\nexport interface ReceiptProtectedWorkflowMutation<Args, Result> {\n\treadonly [protectedMutation]: { args: Args; result: Result }\n\treadonly handler: (execution: WorkflowExecution<Args>) => Promise<Result>\n}\nexport interface WorkflowReceiptAdapter<S extends NeutralSchema> {\n\treadonly replayResult: S\n\treadonly prepare: (\n\t\tinvocation: IdempotencyInvocation,\n\t) => Promise<IdempotencyPreparation<ContractOutput<S>>>\n}\n/** Host registers this handler as the inner native mutation. All callbacks share its transaction. */\nexport function receiptWorkflowMutation<\n\tArgs,\n\tAuthority,\n\tconst Replay extends NeutralSchema,\n>(configuration: {\n\tauthorize: (execution: WorkflowExecution<Args>) => Ordinary<Authority>\n\treceipt: (authority: Authority) => WorkflowReceiptAdapter<Replay>\n\tinvocation: (execution: WorkflowExecution<Args>, authority: Authority) => IdempotencyInvocation\n\texecute: (\n\t\texecution: WorkflowExecution<Args>,\n\t\tauthority: Authority,\n\t) => Ordinary<ContractOutput<Replay>>\n}): ReceiptProtectedWorkflowMutation<Args, ContractOutput<Replay>> {\n\tconst handler = workflowAttempt({\n\t\tauthorize: configuration.authorize,\n\t\texecute: async (execution: WorkflowExecution<Args>, authority: Authority) => {\n\t\t\tconst adapter = configuration.receipt(authority)\n\t\t\tconst preparation = await adapter.prepare(configuration.invocation(execution, authority))\n\t\t\tif (preparation.kind === 'replay')\n\t\t\t\treturn workflowDecode(adapter.replayResult, preparation.result)\n\t\t\tconst value = await configuration.execute(execution, authority)\n\t\t\tawait preparation.complete(value)\n\t\t\treturn value\n\t\t},\n\t})\n\t// SAFETY: the private type evidence can only be issued by this receipt-protected helper.\n\treturn { handler } as ReceiptProtectedWorkflowMutation<Args, ContractOutput<Replay>>\n}\nexport function workflowReceiptInvocation(\n\texecution: WorkflowExecution,\n\toptions: { scope: string; fingerprintPolicy: string; bounds: CanonicalConvexBounds },\n): IdempotencyInvocation {\n\tconst descriptor = workflowExecution(execution)\n\treturn captureIdempotencyInvocation({\n\t\tbinding: { kind: 'mutation', atomicity: 'same-mutation' },\n\t\tidentity: {\n\t\t\toperation: descriptor.operation,\n\t\t\tscope: options.scope,\n\t\t\tkey: JSON.stringify([descriptor.run, descriptor.occurrence]),\n\t\t},\n\t\tversions: {\n\t\t\toperation: descriptor.operationVersion,\n\t\t\tcontract: descriptor.contractVersion,\n\t\t\tbinding: descriptor.bindingVersion,\n\t\t\tfingerprintPolicy: options.fingerprintPolicy,\n\t\t},\n\t\trawInput: descriptor.args,\n\t\tcanonical: { bounds: options.bounds },\n\t})\n}\ntype TerminalMode<Args> =\n\t| {\n\t\t\tkind: 'mutation'\n\t\t\t/** Assertion supplied only after host native rollback/journaling acceptance. */ atomicJournalProof: 'host-verified'\n\t }\n\t| { kind: 'action'; protectedMutation: ReceiptProtectedWorkflowMutation<Args, unknown> }\n/** The native inner mutation rejection must cross its transaction boundary before terminal mapping. */\nexport function terminalWorkflowAttempt<\n\tArgs,\n\tAuthority,\n\tconst Result extends NeutralSchema,\n\tconst Failure extends NeutralSchema,\n>(\n\tconfiguration: TerminalMode<Args> & {\n\t\tauthorize: (execution: WorkflowExecution<Args>) => Ordinary<Authority>\n\t\tinvokeMutation: (\n\t\t\texecution: WorkflowExecution<Args>,\n\t\t\tauthority: Authority,\n\t\t) => Promise<ContractInput<Result>>\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Native thrown values are classified by the host before validating the terminal failure contract.\n\t\tterminal: (error: unknown) => Ordinary<ContractInput<Failure> | undefined>\n\t\tresult: Result\n\t\tfailure: Failure\n\t},\n) {\n\treturn workflowAttempt({\n\t\tauthorize: configuration.authorize,\n\t\texecute: async (\n\t\t\texecution: WorkflowExecution<Args>,\n\t\t\tauthority: Authority,\n\t\t): Promise<WorkflowOutcome<ContractInput<Result>, ContractOutput<Failure>>> => {\n\t\t\tlet value: ContractInput<Result>\n\t\t\ttry {\n\t\t\t\tvalue = await configuration.invokeMutation(execution, authority)\n\t\t\t} catch (error) {\n\t\t\t\tconst terminal = await configuration.terminal(error)\n\t\t\t\tif (terminal === undefined) throw error\n\t\t\t\tconst safeFailure = await workflowDecode(configuration.failure, terminal)\n\t\t\t\tcanonicalConvexBytes(safeFailure, descriptorBounds)\n\t\t\t\treturn { version: 1, kind: 'failed', error: safeFailure }\n\t\t\t}\n\t\t\tawait workflowDecode(configuration.result, value)\n\t\t\tcanonicalConvexBytes(value, descriptorBounds)\n\t\t\treturn { version: 1, kind: 'succeeded', value }\n\t\t},\n\t})\n}\nexport type WorkflowNativeStatus = 'running' | 'succeeded' | 'failed' | 'canceled'\nexport interface WorkflowHostState<Result = unknown, Failure = unknown> {\n\treadonly generation: number\n\treadonly status: WorkflowNativeStatus\n\treadonly nativeStatus: WorkflowNativeStatus\n\treadonly outcome?: WorkflowOutcome<Result, Failure>\n}\nexport interface WorkflowHostUpdate<Result = unknown, Failure = unknown> {\n\treadonly generation: number\n\treadonly nativeStatus: WorkflowNativeStatus\n\treadonly outcome?: WorkflowOutcome<Result, Failure>\n}\nexport type WorkflowTransition<Result = unknown, Failure = unknown> = {\n\treadonly kind: 'applied' | 'ignored'\n\treadonly state: WorkflowHostState<Result, Failure>\n}\n/** Call within a host transaction or compare-and-set. A late operation failure refines host success; cancellation and terminal native status stay fenced. */\nexport function workflowTransition<Result, Failure>(\n\tcurrent: WorkflowHostState<Result, Failure>,\n\tupdate: WorkflowHostUpdate<Result, Failure>,\n): WorkflowTransition<Result, Failure> {\n\tgeneration(current.generation)\n\tgeneration(update.generation)\n\tif (current.generation !== update.generation) return { kind: 'ignored', state: current }\n\tconst nativeStatus =\n\t\tcurrent.nativeStatus !== 'running' ? current.nativeStatus : update.nativeStatus\n\tconst outcome = current.outcome ?? update.outcome\n\tconst status =\n\t\t(current.status === 'running' || current.status === 'succeeded') &&\n\t\tnativeStatus === 'succeeded' &&\n\t\toutcome?.kind === 'failed'\n\t\t\t? 'failed'\n\t\t\t: current.status !== 'running'\n\t\t\t\t? current.status\n\t\t\t\t: nativeStatus\n\tconst state = { generation: current.generation, status, nativeStatus }\n\treturn { kind: 'applied', state: outcome === undefined ? state : { ...state, outcome } }\n}\nexport function workflowCancel<Result, Failure>(\n\tcurrent: WorkflowHostState<Result, Failure>,\n\texpectedGeneration: number,\n): WorkflowTransition<Result, Failure> {\n\tgeneration(expectedGeneration)\n\tif (current.generation !== expectedGeneration) return { kind: 'ignored', state: current }\n\treturn {\n\t\tkind: 'applied',\n\t\tstate: { ...current, status: current.status === 'running' ? 'canceled' : current.status },\n\t}\n}\n/** Host calls after an authorized native restart. Receipt identity remains run plus occurrence. */\nexport function workflowRestart<Result, Failure>(\n\tcurrent: WorkflowHostState<Result, Failure>,\n): WorkflowHostState<Result, Failure> {\n\tgeneration(current.generation)\n\tgeneration(current.generation + 1)\n\tconst state = {\n\t\tgeneration: current.generation + 1,\n\t\tstatus: 'running' as const,\n\t\tnativeStatus: 'running' as const,\n\t}\n\treturn current.outcome?.kind === 'succeeded' ? { ...state, outcome: current.outcome } : state\n}\n/** Host closures capture the trusted run, secured storage and manager. `write` must enforce expected generation atomically. */\nexport function workflowStatusBindings<Result, Failure>(configuration: {\n\tauthorize: () => Ordinary<void>\n\tread: () => Ordinary<WorkflowHostState<Result, Failure>>\n\twrite: (expectedGeneration: number, state: WorkflowHostState<Result, Failure>) => Ordinary<void>\n\tnativeStatus: () => Ordinary<WorkflowNativeStatus>\n\treceiptOutcome: () => Ordinary<WorkflowOutcome<Result, Failure> | undefined>\n\t/** Host calls the manager in the same transaction as its guarded state write. */\n\tcancelNative: () => Ordinary<void>\n\trestartNative: () => Ordinary<void>\n}) {\n\tasync function apply(\n\t\texpectedGeneration: number,\n\t\tnativeStatus: WorkflowNativeStatus,\n\t\toutcome?: WorkflowOutcome<Result, Failure>,\n\t) {\n\t\tconst update = { generation: expectedGeneration, nativeStatus }\n\t\tconst transition = workflowTransition(\n\t\t\tawait configuration.read(),\n\t\t\toutcome === undefined ? update : { ...update, outcome },\n\t\t)\n\t\tif (transition.kind === 'applied')\n\t\t\tawait configuration.write(expectedGeneration, transition.state)\n\t\treturn transition\n\t}\n\treturn {\n\t\tasync callback(\n\t\t\texpectedGeneration: number,\n\t\t\tnativeStatus: WorkflowNativeStatus,\n\t\t\toutcome?: WorkflowOutcome<Result, Failure>,\n\t\t) {\n\t\t\tawait configuration.authorize()\n\t\t\treturn apply(expectedGeneration, nativeStatus, outcome)\n\t\t},\n\t\tasync reconcile(expectedGeneration: number) {\n\t\t\tawait configuration.authorize()\n\t\t\treturn apply(\n\t\t\t\texpectedGeneration,\n\t\t\t\tawait configuration.nativeStatus(),\n\t\t\t\tawait configuration.receiptOutcome(),\n\t\t\t)\n\t\t},\n\t\tasync cancel(expectedGeneration: number) {\n\t\t\tawait configuration.authorize()\n\t\t\tconst current = await configuration.read()\n\t\t\tconst transition = workflowCancel(current, expectedGeneration)\n\t\t\tif (transition.kind === 'applied' && current.status === 'running') {\n\t\t\t\tawait configuration.cancelNative()\n\t\t\t\tawait configuration.write(expectedGeneration, transition.state)\n\t\t\t}\n\t\t\treturn transition\n\t\t},\n\t\tasync restart(expectedGeneration: number) {\n\t\t\tawait configuration.authorize()\n\t\t\tconst current = await configuration.read()\n\t\t\tif (current.generation !== expectedGeneration)\n\t\t\t\treturn { kind: 'ignored' as const, state: current }\n\t\t\tconst state = workflowRestart(current)\n\t\t\tawait configuration.restartNative()\n\t\t\tawait configuration.write(expectedGeneration, state)\n\t\t\treturn { kind: 'applied' as const, state }\n\t\t},\n\t}\n}\nfunction generation(value: number): void {\n\tif (!Number.isSafeInteger(value) || value < 0)\n\t\tthrow new WorkflowBindingError('Invalid host execution generation')\n}\n"],"mappings":"2IAgBA,IAAaA,EAAb,cAA0C,KAAM,CAC/C,KAAgB,uBAChB,YAAY,EAAiB,CAC5B,MAAMC,CAAO,EACb,KAAK,KAAO,sBACb,CACD,EAgBA,MAAMC,EAAS,CACd,UACA,YACA,mBACA,kBACA,iBACA,MACA,aACA,aACA,MACD,EACMC,EAAmB,CACxB,SAAU,GACV,SAAU,IACV,SAAU,IACV,eAAgB,IAChB,gBAAiB,GAClB,EAKA,SAAgBC,EAAkB,EAAmC,CACpE,GACC,CAACC,GACD,OAAOA,GAAU,UACjB,OAAO,eAAeA,CAAK,IAAM,OAAO,WACxC,QAAQ,QAAQA,CAAK,CAAC,CAAC,SAAWH,EAAO,QACzCA,EAAO,KAAM,GAAU,CAAC,OAAO,OAAOG,EAAOC,CAAK,CAAC,EAEnD,MAAM,IAAIN,EAAqB,kDAAkD,EAElF,IAAMO,EAAaF,EACnB,IAAK,IAAMC,KAASJ,EACnB,GAAI,EAAE,UAAW,OAAO,yBAAyBG,EAAOC,CAAK,GAC5D,MAAM,IAAIN,EAAqB,oCAAoC,EACrE,GACCO,EAAW,UAAY,GACvBL,EACE,OAAQ,GAAUI,IAAU,WAAaA,IAAU,MAAM,CAAC,CAC1D,KAAM,GAAU,OAAOC,EAAWD,IAAW,UAAYC,EAAWD,EAAM,CAAC,SAAW,CAAC,EAEzF,MAAM,IAAIN,EAAqB,kDAAkD,EAClF,GAAI,CACHQ,EAAqBD,EAAW,KAAMJ,CAAgB,CACvD,MAAQ,CACP,MAAM,IAAIH,EAAqB,0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AAM,QAAQ,EAA4B,CACzC,MAAMvB,EAAc,UAAU,EAC9B,IAAMY,EAAU,MAAMZ,EAAc,KAAK,EACzC,GAAIY,EAAQ,aAAeO,EAC1B,MAAO,CAAE,KAAM,UAAoB,MAAOP,CAAQ,EACnD,IAAMK,EAAQG,EAAgBR,CAAO,EAGrC,OAFA,MAAMZ,EAAc,cAAc,EAClC,MAAMA,EAAc,MAAMmB,EAAoBF,CAAK,EAC5C,CAAE,KAAM,UAAoB,OAAM,CAC1C,CACD,CACD,CACA,SAASN,EAAW,EAAqB,CACxC,GAAI,CAAC,OAAO,cAAcnC,CAAK,GAAKA,EAAQ,EAC3C,MAAM,IAAIL,EAAqB,mCAAmC,CACpE"}
1
+ {"version":3,"file":"workflow.mjs","names":["WorkflowBindingError","message","fields","descriptorBounds","workflowExecution","value","field","descriptor","canonicalConvexBytes","workflowBinding","compatibleVersions","binding","version","snapshot","runWorkflowStep","runner","step","execution","input","versions","nativeOptions","options","output","workflowDecode","decoded","decodeContract","schema","workflowAttempt","authority","configuration","receiptWorkflowMutation","adapter","preparation","workflowReceiptInvocation","captureIdempotencyInvocation","terminalWorkflowAttempt","error","terminal","safeFailure","workflowTransition","generation","current","update","nativeStatus","outcome","status","state","workflowCancel","expectedGeneration","workflowRestart","workflowStatusBindings","apply","transition"],"sources":["../../../src/modules/contracts/workflow.ts"],"sourcesContent":["import type { FunctionReference, FunctionVisibility, FunctionType } from 'convex/server'\nimport type { WorkflowCtx } from '@convex-dev/workflow'\nimport {\n\tdecodeContract,\n\ttype ContractInput,\n\ttype ContractOutput,\n\ttype NeutralSchema,\n} from './contract'\nimport {\n\tcanonicalConvexBytes,\n\tcaptureIdempotencyInvocation,\n\ttype CanonicalConvexBounds,\n\ttype IdempotencyInvocation,\n\ttype IdempotencyPreparation,\n} from './idempotency'\n\nexport class WorkflowBindingError extends Error {\n\treadonly _tag = 'WorkflowBindingError'\n\tconstructor(message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'WorkflowBindingError'\n\t}\n}\nexport interface WorkflowExecution<Args = unknown> {\n\treadonly version: 1\n\treadonly operation: string\n\treadonly operationVersion: string\n\treadonly contractVersion: string\n\treadonly bindingVersion: string\n\t/** Host-issued business-run identity. Recovery preserves it. */\n\treadonly run: string\n\t/** Opaque host capability; never caller-supplied principal or tenant authority. */\n\treadonly capability: string\n\t/** Logical occurrence, distinct for each repeated loop step. */\n\treadonly occurrence: string\n\treadonly args: Args\n}\nexport type WorkflowStepArguments<Args> = { execution: WorkflowExecution<Args> }\nconst fields = [\n\t'version',\n\t'operation',\n\t'operationVersion',\n\t'contractVersion',\n\t'bindingVersion',\n\t'run',\n\t'capability',\n\t'occurrence',\n\t'args',\n] as const\nconst descriptorBounds = {\n\tmaxDepth: 64,\n\tmaxNodes: 100000,\n\tmaxBytes: 1000000,\n\tmaxArrayLength: 100000,\n\tmaxObjectFields: 100000,\n}\n/** Strict plain, versioned transport. Validity does not confer authority; the host resolves capability anew. */\n/* oxlint-disable anti-slop/no-unknown-parameters, anti-slop/no-runtime-typeof -- This decoder validates an untrusted execution descriptor before it enters the native workflow boundary. */\nexport function workflowExecution<Args>(value: WorkflowExecution<Args>): WorkflowExecution<Args>\nexport function workflowExecution(value: unknown): WorkflowExecution\nexport function workflowExecution(value: unknown): WorkflowExecution {\n\tif (\n\t\t!value ||\n\t\ttypeof value !== 'object' ||\n\t\tObject.getPrototypeOf(value) !== Object.prototype ||\n\t\tReflect.ownKeys(value).length !== fields.length ||\n\t\tfields.some((field) => !Object.hasOwn(value, field))\n\t)\n\t\tthrow new WorkflowBindingError('Execution requires exact plain descriptor fields')\n\t// SAFETY: the exact field set is checked above; values and accessors are checked before use below.\n\tconst descriptor = value as WorkflowExecution\n\tfor (const field of fields)\n\t\tif (!('value' in Object.getOwnPropertyDescriptor(value, field)!))\n\t\t\tthrow new WorkflowBindingError('Execution cannot contain accessors')\n\tif (\n\t\tdescriptor.version !== 1 ||\n\t\tfields\n\t\t\t.filter((field) => field !== 'version' && field !== 'args')\n\t\t\t.some((field) => typeof descriptor[field] !== 'string' || descriptor[field].length === 0)\n\t)\n\t\tthrow new WorkflowBindingError('Invalid execution descriptor version or identity')\n\ttry {\n\t\tcanonicalConvexBytes(descriptor.args, descriptorBounds)\n\t} catch {\n\t\tthrow new WorkflowBindingError('Execution args require plain Convex data')\n\t}\n\treturn descriptor\n}\n/* oxlint-enable anti-slop/no-unknown-parameters, anti-slop/no-runtime-typeof */\nexport interface WorkflowBinding<\n\tKind extends FunctionType,\n\tArgs extends NeutralSchema,\n\tResult extends NeutralSchema,\n> {\n\treadonly kind: Kind\n\treadonly operation: string\n\treadonly operationVersion: string\n\treadonly contractVersion: string\n\treadonly bindingVersion: string\n\treadonly args: Args\n\treadonly result: Result\n\treadonly reference: FunctionReference<\n\t\tNoInfer<Kind>,\n\t\tFunctionVisibility,\n\t\tWorkflowStepArguments<NoInfer<ContractInput<Args>>>,\n\t\tNoInfer<ContractInput<Result>>\n\t>\n\t/** Host explicitly lists deployed descriptor versions whose semantics remain compatible. */\n\treadonly compatibleVersions?: readonly {\n\t\toperationVersion: string\n\t\tcontractVersion: string\n\t\tbindingVersion: string\n\t}[]\n}\n/** Both phantom reference args and results must match the explicit wire contracts. */\nexport function workflowBinding<\n\tKind extends FunctionType,\n\tconst Args extends NeutralSchema,\n\tconst Result extends NeutralSchema,\n>(binding: WorkflowBinding<Kind, Args, Result>): WorkflowBinding<Kind, Args, Result> {\n\tconst compatibleVersions = binding.compatibleVersions?.map((version) =>\n\t\tObject.freeze({ ...version }),\n\t)\n\tconst snapshot = { ...binding }\n\tif (compatibleVersions !== undefined)\n\t\tsnapshot.compatibleVersions = Object.freeze(compatibleVersions)\n\treturn Object.freeze(snapshot)\n}\nexport type WorkflowStepOptions = {\n\tname?: string\n\tretry?: NonNullable<Parameters<WorkflowCtx['withOptions']>[0]['retry']>\n} & (\n\t| { inline?: false; runAt?: number; runAfter?: number }\n\t| { inline: true; runAt?: never; runAfter?: never }\n)\n/** A structural seam allows invocation-scoped native WorkflowCtx without creating another durability runtime. */\nexport interface WorkflowStepRunner {\n\t/* oxlint-disable anti-slop/no-unknown-returns -- Native runner results stay opaque here; runWorkflowStep correlates them with the binding's raw result contract without replay decoding. */\n\trunQuery?: (\n\t\treference: FunctionReference<'query', FunctionVisibility>,\n\t\targs: WorkflowStepArguments<unknown>,\n\t\toptions?: WorkflowStepOptions,\n\t) => Promise<unknown>\n\trunMutation?: (\n\t\treference: FunctionReference<'mutation', FunctionVisibility>,\n\t\targs: WorkflowStepArguments<unknown>,\n\t\toptions?: WorkflowStepOptions,\n\t) => Promise<unknown>\n\trunAction?: (\n\t\treference: FunctionReference<'action', FunctionVisibility>,\n\t\targs: WorkflowStepArguments<unknown>,\n\t\toptions?: WorkflowStepOptions,\n\t) => Promise<unknown>\n\t/* oxlint-enable anti-slop/no-unknown-returns */\n}\nexport async function runWorkflowStep<\n\tKind extends FunctionType,\n\tArgs extends NeutralSchema,\n\tResult extends NeutralSchema,\n>(\n\tstep: WorkflowCtx | WorkflowStepRunner,\n\tbinding: WorkflowBinding<Kind, Args, Result>,\n\tinput: WorkflowExecution<ContractInput<Args>>,\n\toptions: WorkflowStepOptions = {},\n): Promise<ContractInput<Result>> {\n\t// SAFETY: each binding has nonempty, checked generated args. Native ArgsAndOptions' empty-args overload is never selected.\n\tconst runner = step as WorkflowStepRunner\n\tconst execution = workflowExecution(input)\n\tconst versions = [binding, ...(binding.compatibleVersions ?? [])]\n\tif (\n\t\texecution.operation !== binding.operation ||\n\t\t!versions.some(\n\t\t\t(version) =>\n\t\t\t\tversion.operationVersion === execution.operationVersion &&\n\t\t\t\tversion.contractVersion === execution.contractVersion &&\n\t\t\t\tversion.bindingVersion === execution.bindingVersion,\n\t\t)\n\t)\n\t\tthrow new WorkflowBindingError('Incompatible workflow operation version')\n\tconst nativeOptions = {\n\t\t...options,\n\t\tname: options.name ?? `${execution.operation}:${execution.occurrence}`,\n\t}\n\tlet output: unknown\n\tswitch (binding.kind) {\n\t\tcase 'query':\n\t\t\tif (!runner.runQuery) throw new WorkflowBindingError('Native query runner missing')\n\t\t\t// SAFETY: the checked binding kind selects this exact native reference kind.\n\t\t\toutput = await runner.runQuery(\n\t\t\t\tbinding.reference as FunctionReference<'query', FunctionVisibility>,\n\t\t\t\t{ execution },\n\t\t\t\tnativeOptions,\n\t\t\t)\n\t\t\tbreak\n\t\tcase 'mutation':\n\t\t\tif (!runner.runMutation) throw new WorkflowBindingError('Native mutation runner missing')\n\t\t\t// SAFETY: the checked binding kind selects this exact native reference kind.\n\t\t\toutput = await runner.runMutation(\n\t\t\t\tbinding.reference as FunctionReference<'mutation', FunctionVisibility>,\n\t\t\t\t{ execution },\n\t\t\t\tnativeOptions,\n\t\t\t)\n\t\t\tbreak\n\t\tcase 'action':\n\t\t\tif (!runner.runAction) throw new WorkflowBindingError('Native action runner missing')\n\t\t\tif (options.inline) throw new WorkflowBindingError('Actions cannot execute inline')\n\t\t\t// SAFETY: the checked binding kind selects this exact native reference kind.\n\t\t\toutput = await runner.runAction(\n\t\t\t\tbinding.reference as FunctionReference<'action', FunctionVisibility>,\n\t\t\t\t{ execution },\n\t\t\t\t{ ...nativeOptions, retry: options.retry ?? false },\n\t\t\t)\n\t\t\tbreak\n\t}\n\t// Native validators own wire validation. Replaying workflow code must not rerun transforms.\n\t// SAFETY: the binding correlates the generated reference's result with this raw wire contract.\n\treturn output as ContractInput<Result>\n}\nexport async function workflowDecode<S extends NeutralSchema>(\n\tschema: S,\n\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- The schema parses retained or native transport values at this boundary.\n\tvalue: unknown,\n): Promise<ContractOutput<S>> {\n\tconst decoded = await decodeContract(schema, value)\n\tif (decoded.issues) throw new WorkflowBindingError('Workflow contract validation failed')\n\treturn decoded.value\n}\ntype Ordinary<A> = A | PromiseLike<A>\n/** This helper belongs inside a registered native function, never in the replaying workflow handler. */\nexport function workflowAttempt<Args, Authority, Result>(configuration: {\n\tauthorize: (execution: WorkflowExecution<Args>) => Ordinary<Authority>\n\texecute: (execution: WorkflowExecution<Args>, authority: Authority) => Ordinary<Result>\n}) {\n\treturn async (input: WorkflowExecution<Args>): Promise<Result> => {\n\t\tconst execution = workflowExecution(input)\n\t\tconst authority = await configuration.authorize(execution)\n\t\treturn configuration.execute(execution, authority)\n\t}\n}\nexport type WorkflowOutcome<Result = unknown, Failure = unknown> =\n\t| { readonly version: 1; readonly kind: 'succeeded'; readonly value: Result }\n\t| { readonly version: 1; readonly kind: 'failed'; readonly error: Failure }\ndeclare const protectedMutation: unique symbol\nexport interface ReceiptProtectedWorkflowMutation<Args, Result> {\n\treadonly [protectedMutation]: { args: Args; result: Result }\n\treadonly handler: (execution: WorkflowExecution<Args>) => Promise<Result>\n}\nexport interface WorkflowReceiptAdapter<S extends NeutralSchema> {\n\treadonly replayResult: S\n\treadonly prepare: (\n\t\tinvocation: IdempotencyInvocation,\n\t) => Promise<IdempotencyPreparation<ContractOutput<S>>>\n}\n/** Host registers this handler as the inner native mutation. All callbacks share its transaction. */\nexport function receiptWorkflowMutation<\n\tArgs,\n\tAuthority,\n\tconst Replay extends NeutralSchema,\n>(configuration: {\n\tauthorize: (execution: WorkflowExecution<Args>) => Ordinary<Authority>\n\treceipt: (authority: Authority) => WorkflowReceiptAdapter<Replay>\n\tinvocation: (execution: WorkflowExecution<Args>, authority: Authority) => IdempotencyInvocation\n\texecute: (\n\t\texecution: WorkflowExecution<Args>,\n\t\tauthority: Authority,\n\t) => Ordinary<ContractOutput<Replay>>\n}): ReceiptProtectedWorkflowMutation<Args, ContractOutput<Replay>> {\n\tconst handler = workflowAttempt({\n\t\tauthorize: configuration.authorize,\n\t\texecute: async (execution: WorkflowExecution<Args>, authority: Authority) => {\n\t\t\tconst adapter = configuration.receipt(authority)\n\t\t\tconst preparation = await adapter.prepare(configuration.invocation(execution, authority))\n\t\t\tif (preparation.kind === 'replay')\n\t\t\t\treturn workflowDecode(adapter.replayResult, preparation.result)\n\t\t\tconst value = await configuration.execute(execution, authority)\n\t\t\tawait preparation.complete(value)\n\t\t\treturn value\n\t\t},\n\t})\n\t// SAFETY: the private type evidence can only be issued by this receipt-protected helper.\n\treturn { handler } as ReceiptProtectedWorkflowMutation<Args, ContractOutput<Replay>>\n}\nexport function workflowReceiptInvocation(\n\texecution: WorkflowExecution,\n\toptions: { scope: string; fingerprintPolicy: string; bounds: CanonicalConvexBounds },\n): IdempotencyInvocation {\n\tconst descriptor = workflowExecution(execution)\n\treturn captureIdempotencyInvocation({\n\t\tbinding: { kind: 'mutation', atomicity: 'same-mutation' },\n\t\tidentity: {\n\t\t\toperation: descriptor.operation,\n\t\t\tscope: options.scope,\n\t\t\tkey: JSON.stringify([descriptor.run, descriptor.occurrence]),\n\t\t},\n\t\tversions: {\n\t\t\toperation: descriptor.operationVersion,\n\t\t\tcontract: descriptor.contractVersion,\n\t\t\tbinding: descriptor.bindingVersion,\n\t\t\tfingerprintPolicy: options.fingerprintPolicy,\n\t\t},\n\t\trawInput: descriptor.args,\n\t\tcanonical: { bounds: options.bounds },\n\t})\n}\ntype TerminalMode<Args> =\n\t| {\n\t\t\tkind: 'mutation'\n\t\t\t/** Assertion supplied only after host native rollback/journaling acceptance. */ atomicJournalProof: 'host-verified'\n\t }\n\t| { kind: 'action'; protectedMutation: ReceiptProtectedWorkflowMutation<Args, unknown> }\n/** The native inner mutation rejection must cross its transaction boundary before terminal mapping. */\nexport function terminalWorkflowAttempt<\n\tArgs,\n\tAuthority,\n\tconst Result extends NeutralSchema,\n\tconst Failure extends NeutralSchema,\n>(\n\tconfiguration: TerminalMode<Args> & {\n\t\tauthorize: (execution: WorkflowExecution<Args>) => Ordinary<Authority>\n\t\tinvokeMutation: (\n\t\t\texecution: WorkflowExecution<Args>,\n\t\t\tauthority: Authority,\n\t\t) => Promise<ContractInput<Result>>\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Native thrown values are classified by the host before validating the terminal failure contract.\n\t\tterminal: (error: unknown) => Ordinary<ContractInput<Failure> | undefined>\n\t\tresult: Result\n\t\tfailure: Failure\n\t},\n) {\n\treturn workflowAttempt({\n\t\tauthorize: configuration.authorize,\n\t\texecute: async (\n\t\t\texecution: WorkflowExecution<Args>,\n\t\t\tauthority: Authority,\n\t\t): Promise<WorkflowOutcome<ContractInput<Result>, ContractOutput<Failure>>> => {\n\t\t\tlet value: ContractInput<Result>\n\t\t\ttry {\n\t\t\t\tvalue = await configuration.invokeMutation(execution, authority)\n\t\t\t} catch (error) {\n\t\t\t\tconst terminal = await configuration.terminal(error)\n\t\t\t\tif (terminal === undefined) throw error\n\t\t\t\tconst safeFailure = await workflowDecode(configuration.failure, terminal)\n\t\t\t\tcanonicalConvexBytes(safeFailure, descriptorBounds)\n\t\t\t\treturn { version: 1, kind: 'failed', error: safeFailure }\n\t\t\t}\n\t\t\tawait workflowDecode(configuration.result, value)\n\t\t\tcanonicalConvexBytes(value, descriptorBounds)\n\t\t\treturn { version: 1, kind: 'succeeded', value }\n\t\t},\n\t})\n}\nexport type WorkflowNativeStatus = 'running' | 'succeeded' | 'failed' | 'canceled'\nexport interface WorkflowHostState<Result = unknown, Failure = unknown> {\n\treadonly generation: number\n\treadonly status: WorkflowNativeStatus\n\treadonly nativeStatus: WorkflowNativeStatus\n\treadonly outcome?: WorkflowOutcome<Result, Failure>\n}\nexport interface WorkflowHostUpdate<Result = unknown, Failure = unknown> {\n\treadonly generation: number\n\treadonly nativeStatus: WorkflowNativeStatus\n\treadonly outcome?: WorkflowOutcome<Result, Failure>\n}\nexport type WorkflowTransition<Result = unknown, Failure = unknown> = {\n\treadonly kind: 'applied' | 'ignored'\n\treadonly state: WorkflowHostState<Result, Failure>\n}\n/** Call within a host transaction or compare-and-set. A late operation failure refines host success; cancellation and terminal native status stay fenced. */\nexport function workflowTransition<Result, Failure>(\n\tcurrent: WorkflowHostState<Result, Failure>,\n\tupdate: WorkflowHostUpdate<Result, Failure>,\n): WorkflowTransition<Result, Failure> {\n\tgeneration(current.generation)\n\tgeneration(update.generation)\n\tif (current.generation !== update.generation) return { kind: 'ignored', state: current }\n\tconst nativeStatus =\n\t\tcurrent.nativeStatus !== 'running' ? current.nativeStatus : update.nativeStatus\n\tconst outcome = current.outcome ?? update.outcome\n\tconst status =\n\t\t(current.status === 'running' || current.status === 'succeeded') &&\n\t\tnativeStatus === 'succeeded' &&\n\t\toutcome?.kind === 'failed'\n\t\t\t? 'failed'\n\t\t\t: current.status !== 'running'\n\t\t\t\t? current.status\n\t\t\t\t: nativeStatus\n\tconst state = { generation: current.generation, status, nativeStatus }\n\treturn { kind: 'applied', state: outcome === undefined ? state : { ...state, outcome } }\n}\nexport function workflowCancel<Result, Failure>(\n\tcurrent: WorkflowHostState<Result, Failure>,\n\texpectedGeneration: number,\n): WorkflowTransition<Result, Failure> {\n\tgeneration(expectedGeneration)\n\tif (current.generation !== expectedGeneration) return { kind: 'ignored', state: current }\n\treturn {\n\t\tkind: 'applied',\n\t\tstate: { ...current, status: current.status === 'running' ? 'canceled' : current.status },\n\t}\n}\n/** Host calls after an authorized native restart. Receipt identity remains run plus occurrence. */\nexport function workflowRestart<Result, Failure>(\n\tcurrent: WorkflowHostState<Result, Failure>,\n): WorkflowHostState<Result, Failure> {\n\tgeneration(current.generation)\n\tgeneration(current.generation + 1)\n\tconst state = {\n\t\tgeneration: current.generation + 1,\n\t\tstatus: 'running' as const,\n\t\tnativeStatus: 'running' as const,\n\t}\n\treturn current.outcome?.kind === 'succeeded' ? { ...state, outcome: current.outcome } : state\n}\n/** Host closures capture the trusted run, secured storage and manager. `write` must enforce expected generation atomically. */\nexport function workflowStatusBindings<Result, Failure>(configuration: {\n\tauthorize: () => Ordinary<void>\n\tread: () => Ordinary<WorkflowHostState<Result, Failure>>\n\twrite: (expectedGeneration: number, state: WorkflowHostState<Result, Failure>) => Ordinary<void>\n\tnativeStatus: () => Ordinary<WorkflowNativeStatus>\n\treceiptOutcome: () => Ordinary<WorkflowOutcome<Result, Failure> | undefined>\n\t/** Host calls the manager in the same transaction as its guarded state write. */\n\tcancelNative: () => Ordinary<void>\n\trestartNative: () => Ordinary<void>\n}) {\n\tasync function apply(\n\t\texpectedGeneration: number,\n\t\tnativeStatus: WorkflowNativeStatus,\n\t\toutcome?: WorkflowOutcome<Result, Failure>,\n\t) {\n\t\tconst update = { generation: expectedGeneration, nativeStatus }\n\t\tconst transition = workflowTransition(\n\t\t\tawait configuration.read(),\n\t\t\toutcome === undefined ? update : { ...update, outcome },\n\t\t)\n\t\tif (transition.kind === 'applied')\n\t\t\tawait configuration.write(expectedGeneration, transition.state)\n\t\treturn transition\n\t}\n\treturn {\n\t\tasync callback(\n\t\t\texpectedGeneration: number,\n\t\t\tnativeStatus: WorkflowNativeStatus,\n\t\t\toutcome?: WorkflowOutcome<Result, Failure>,\n\t\t) {\n\t\t\tawait configuration.authorize()\n\t\t\treturn apply(expectedGeneration, nativeStatus, outcome)\n\t\t},\n\t\tasync reconcile(expectedGeneration: number) {\n\t\t\tawait configuration.authorize()\n\t\t\treturn apply(\n\t\t\t\texpectedGeneration,\n\t\t\t\tawait configuration.nativeStatus(),\n\t\t\t\tawait configuration.receiptOutcome(),\n\t\t\t)\n\t\t},\n\t\tasync cancel(expectedGeneration: number) {\n\t\t\tawait configuration.authorize()\n\t\t\tconst current = await configuration.read()\n\t\t\tconst transition = workflowCancel(current, expectedGeneration)\n\t\t\tif (transition.kind === 'applied' && current.status === 'running') {\n\t\t\t\tawait configuration.cancelNative()\n\t\t\t\tawait configuration.write(expectedGeneration, transition.state)\n\t\t\t}\n\t\t\treturn transition\n\t\t},\n\t\tasync restart(expectedGeneration: number) {\n\t\t\tawait configuration.authorize()\n\t\t\tconst current = await configuration.read()\n\t\t\tif (current.generation !== expectedGeneration)\n\t\t\t\treturn { kind: 'ignored' as const, state: current }\n\t\t\tconst state = workflowRestart(current)\n\t\t\tawait configuration.restartNative()\n\t\t\tawait configuration.write(expectedGeneration, state)\n\t\t\treturn { kind: 'applied' as const, state }\n\t\t},\n\t}\n}\nfunction generation(value: number): void {\n\tif (!Number.isSafeInteger(value) || value < 0)\n\t\tthrow new WorkflowBindingError('Invalid host execution generation')\n}\n"],"mappings":"A,2IAgBA,IAAaA,EAAb,cAA0C,KAAM,CAC/C,KAAgB,uBAChB,YAAY,EAAiB,CAC5B,MAAMC,CAAO,EACb,KAAK,KAAO,sBACb,CACD,EAgBA,MAAMC,EAAS,CACd,UACA,YACA,mBACA,kBACA,iBACA,MACA,aACA,aACA,MACD,EACMC,EAAmB,CACxB,SAAU,GACV,SAAU,IACV,SAAU,IACV,eAAgB,IAChB,gBAAiB,GAClB,EAKA,SAAgBC,EAAkB,EAAmC,CACpE,GACC,CAACC,GACD,OAAOA,GAAU,UACjB,OAAO,eAAeA,CAAK,IAAM,OAAO,WACxC,QAAQ,QAAQA,CAAK,CAAC,CAAC,SAAWH,EAAO,QACzCA,EAAO,KAAM,GAAU,CAAC,OAAO,OAAOG,EAAOC,CAAK,CAAC,EAEnD,MAAM,IAAIN,EAAqB,kDAAkD,EAElF,IAAMO,EAAaF,EACnB,IAAK,IAAMC,KAASJ,EACnB,GAAI,EAAE,UAAW,OAAO,yBAAyBG,EAAOC,CAAK,GAC5D,MAAM,IAAIN,EAAqB,oCAAoC,EACrE,GACCO,EAAW,UAAY,GACvBL,EACE,OAAQ,GAAUI,IAAU,WAAaA,IAAU,MAAM,CAAC,CAC1D,KAAM,GAAU,OAAOC,EAAWD,IAAW,UAAYC,EAAWD,EAAM,CAAC,SAAW,CAAC,EAEzF,MAAM,IAAIN,EAAqB,kDAAkD,EAClF,GAAI,CACHQ,EAAqBD,EAAW,KAAMJ,CAAgB,CACvD,MAAQ,CACP,MAAM,IAAIH,EAAqB,0CAA0C,CAC1E,CACA,OAAOO,CACR,CA4BA,SAAgBE,EAId,EAAmF,CACpF,IAAMC,EAAqBC,EAAQ,oBAAoB,IAAK,GAC3D,OAAO,OAAO,CAAE,GAAGC,CAAQ,CAAC,CAC7B,EACMC,EAAW,CAAE,GAAGF,CAAQ,EAG9B,OAFID,IAAuB,IA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AAMZ,EAAc,cAAc,EAClC,MAAMA,EAAc,MAAMmB,EAAoBF,CAAK,EAC5C,CAAE,KAAM,UAAoB,OAAM,CAC1C,CACD,CACD,CACA,SAASN,EAAW,EAAqB,CACxC,GAAI,CAAC,OAAO,cAAcnC,CAAK,GAAKA,EAAQ,EAC3C,MAAM,IAAIL,EAAqB,mCAAmC,CACpE,C"}
@@ -1,14 +1,13 @@
1
- import { Observability } from "../../components/foundation/modules/observability/observability.mjs";
2
1
  import { AuditEntryInput } from "../../components/foundation/client.mjs";
2
+ import { Observability } from "../../components/foundation/modules/observability/observability.mjs";
3
3
  import { DomainActionContract, DomainAuditInput, DomainContract } from "../contracts/domain.mjs";
4
- import { NestedAuditMode, RequestScope } from "./scope.mjs";
5
- import { CallbackError, CallbackRequirements, ValidatedEffectOperations, effectActionFactory } from "./operation.mjs";
6
- import { FailureAuditOptions } from "./failure-audit.mjs";
7
4
  import { BoundOperations } from "../contracts/binding.mjs";
8
- import { AuditValue, AuditedOperations, DomainEffectFactory, DomainEffectImplementations, ExactDomainOperations } from "./domain.mjs";
9
5
  import { DomainOf, HostOf, HostParameter, Registry, Resolver, createEffectCommand } from "./command.mjs";
6
+ import { AuditValue, AuditedOperations, DomainEffectFactory, DomainEffectImplementations, ExactDomainOperations } from "./domain.mjs";
7
+ import { FailureAuditOptions } from "./failure-audit.mjs";
8
+ import { CallbackError, CallbackRequirements, ValidatedEffectOperations, effectActionFactory } from "./operation.mjs";
9
+ import { NestedAuditMode, RequestScope } from "./scope.mjs";
10
10
  import { Effect } from "effect";
11
- //#region src/modules/effect/action.d.ts
12
11
  type Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>;
13
12
  /** Host policies an Action registry uses; actions have no mutation-side permission host. */
14
13
  export type EffectActionDependencies = {
@@ -60,5 +59,5 @@ export declare function bindEffectAction<const Dependencies extends EffectAction
60
59
  };
61
60
  } & ActionCompatible<Resolve, Dependencies>): EffectActionRegistry<Resolve, [Returned] extends [never] ? Operations : AuditedOperations<Operations, (resolution: never, context: never) => Returned>, Dependencies, Guard>;
62
61
  };
63
- //#endregion
62
+ export {};
64
63
  //# sourceMappingURL=action.d.mts.map
@@ -1,2 +1,2 @@
1
- import{memoize as e,registerLazyRegistry as t}from"../contracts/lazy.mjs";import{effectActionFactory as n}from"./operation.mjs";import{snapshotOperations as r}from"../contracts/binding.mjs";import{domainEffectFactory as i}from"./domain.mjs";import{createEffectCommand as a}from"./command.mjs";var o=class extends Error{code=`ACTION_AUDIT_WRITER_MISSING`;name=`ActionAuditWriterError`;constructor(e){super(`Action "${e}" declares an audit but the Foundation has no writeActionAudit`)}};function s(s){function c(c){let l=e(()=>{let e=r(c.operations(c.contract?i(c.contract.actions??{},`action`,c.contract.errors):n()),c.contract,`actions`,c.audit);if(!s.writeActionAudit){for(let[t,n]of Object.entries(e))if(`audit`in n&&n.audit!==void 0)throw new o(t)}return e}),u=a({...c,observability:s.observability,auditFailure:s.auditFailure,nestedAudit:s.nestedAudit,writeAudit:s.writeActionAudit??(()=>void 0),operations:l,mode:`action`});return t({exec:u.exec,withContext:u.withContext},l)}return c}export{o as ActionAuditWriterError,s as bindEffectAction};
1
+ import{snapshotOperations as e}from"../contracts/binding.mjs";import{memoize as t,registerLazyRegistry as n}from"../contracts/lazy.mjs";import{createEffectCommand as r}from"./command.mjs";import{domainEffectFactory as i}from"./domain.mjs";import{effectActionFactory as a}from"./operation.mjs";var o=class extends Error{code=`ACTION_AUDIT_WRITER_MISSING`;name=`ActionAuditWriterError`;constructor(e){super(`Action "${e}" declares an audit but the Foundation has no writeActionAudit`)}};function s(s){function c(c){let l=t(()=>{let t=e(c.operations(c.contract?i(c.contract.actions??{},`action`,c.contract.errors):a()),c.contract,`actions`,c.audit);if(!s.writeActionAudit){for(let[e,n]of Object.entries(t))if(`audit`in n&&n.audit!==void 0)throw new o(e)}return t}),u=r({...c,observability:s.observability,auditFailure:s.auditFailure,nestedAudit:s.nestedAudit,writeAudit:s.writeActionAudit??(()=>void 0),operations:l,mode:`action`});return n({exec:u.exec,withContext:u.withContext},l)}return c}export{o as ActionAuditWriterError,s as bindEffectAction};
2
2
  //# sourceMappingURL=action.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"action.mjs","names":["ActionAuditWriterError","operation","bindEffectAction","action","getOperations","memoize","operations","snapshotOperations","configuration","domainEffectFactory","effectActionFactory","dependencies","definition","kernel","createEffectCommand","registerLazyRegistry"],"sources":["../../../src/modules/effect/action.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- Overload implementation storage is erased; public signatures retain concrete values, errors and services. */\nimport type { Effect } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation observability without entering the Convex component deployment graph.\nimport type { Observability } from '../../components/foundation/modules/observability/observability'\nimport type { DomainActionContract, DomainAuditInput, DomainContract } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport { memoize, registerLazyRegistry } from '../contracts/lazy'\nimport {\n\tcreateEffectCommand,\n\ttype DomainOf,\n\ttype HostOf,\n\ttype HostParameter,\n\ttype Registry,\n\ttype Resolver,\n} from './command'\nimport {\n\tdomainEffectFactory,\n\ttype AuditedOperations,\n\ttype AuditValue,\n\ttype DomainEffectFactory,\n\ttype DomainEffectImplementations,\n\ttype ExactDomainOperations,\n} from './domain'\nimport type { FailureAuditOptions } from './failure-audit'\nimport {\n\teffectActionFactory,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype ValidatedEffectOperations,\n} from './operation'\nimport type { NestedAuditMode, RequestScope } from './scope'\n\ntype Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>\n\n/** Host policies an Action registry uses; actions have no mutation-side permission host. */\nexport type EffectActionDependencies = {\n\tobservability: Observability\n\t/** Writes action audit entries, typically through `ctx.runMutation`; required once any action audits. */\n\twriteActionAudit?: (host: never, entry: AuditEntryInput) => Supported<unknown>\n\tauditFailure?: FailureAuditOptions\n\tnestedAudit?: NestedAuditMode\n}\ntype ActionWriter<Dependencies extends EffectActionDependencies> = [\n\tExclude<Dependencies['writeActionAudit'], undefined>,\n] extends [never]\n\t? (host: never, entry: AuditEntryInput) => void\n\t: Exclude<Dependencies['writeActionAudit'], undefined>\n/** The command kernel runs actions with the action writer in its audit-writer slot. */\ntype KernelDependencies<Dependencies extends EffectActionDependencies> = {\n\tobservability: Observability\n\twriteAudit: ActionWriter<Dependencies>\n\tauditFailure?: FailureAuditOptions\n\tnestedAudit?: NestedAuditMode\n}\ntype ActionCompatible<Resolve extends Resolver, Dependencies extends EffectActionDependencies> = [\n\tHostOf<Resolve>,\n] extends [HostParameter<Dependencies['writeActionAudit']>]\n\t? unknown\n\t: { context: never }\ntype ActionFactory<Resolve extends Resolver, Guard> = ReturnType<\n\ttypeof effectActionFactory<\n\t\tDomainOf<Resolve>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>\n\t>\n>\ntype Kernel<\n\tResolve extends Resolver,\n\tOperations extends Registry<DomainOf<Resolve>>,\n\tDependencies extends EffectActionDependencies,\n\tGuard,\n> = ReturnType<\n\ttypeof createEffectCommand<Resolve, Operations, KernelDependencies<Dependencies>, Guard>\n>\n/** Actions are executed by their own Convex action functions; they are never exposed as mutations. */\nexport type EffectActionRegistry<\n\tResolve extends Resolver,\n\tOperations extends Registry<DomainOf<Resolve>>,\n\tDependencies extends EffectActionDependencies,\n\tGuard,\n> = Pick<Kernel<Resolve, Operations, Dependencies, Guard>, 'exec' | 'withContext'>\n\nexport class ActionAuditWriterError extends Error {\n\treadonly code = 'ACTION_AUDIT_WRITER_MISSING'\n\treadonly name = 'ActionAuditWriterError'\n\tconstructor(operation: string) {\n\t\tsuper(`Action \"${operation}\" declares an audit but the Foundation has no writeActionAudit`)\n\t}\n}\n\n/** Bind trusted application policies once; each registry resolves its own invocation context. */\nexport function bindEffectAction<const Dependencies extends EffectActionDependencies>(\n\tdependencies: Dependencies,\n) {\n\tfunction action<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tactions: Readonly<Record<string, DomainActionContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<DomainOf<Resolve>, Contract['actions']>,\n\t\tReturned extends AuditValue = never,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['actions']> &\n\t\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit?: (\n\t\t\t\tresolution: DomainAuditInput<Contract['actions']>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t\tscope: RequestScope | undefined,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: DomainEffectFactory<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tContract['actions'],\n\t\t\t\t\t'action',\n\t\t\t\t\tnever,\n\t\t\t\t\tNoInfer<CallbackError<Guard>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\t\t\t\tContract['errors']\n\t\t\t\t>,\n\t\t\t) => Operations\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & ActionCompatible<Resolve, Dependencies>,\n\t): EffectActionRegistry<\n\t\tResolve,\n\t\t[Returned] extends [never]\n\t\t\t? BoundOperations<Operations, Contract['actions']>\n\t\t\t: AuditedOperations<\n\t\t\t\t\tBoundOperations<Operations, Contract['actions']>,\n\t\t\t\t\t(resolution: never, context: never) => Returned\n\t\t\t\t>,\n\t\tDependencies,\n\t\tGuard\n\t>\n\tfunction action<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends Registry<DomainOf<Resolve>>,\n\t\tReturned extends AuditValue = never,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontext: Resolve\n\t\t\taudit?: (\n\t\t\t\tresolution: DomainAuditInput<Operations>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t\tscope: RequestScope | undefined,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: ActionFactory<Resolve, Guard>,\n\t\t\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & ActionCompatible<Resolve, Dependencies>,\n\t): EffectActionRegistry<\n\t\tResolve,\n\t\t[Returned] extends [never]\n\t\t\t? Operations\n\t\t\t: AuditedOperations<Operations, (resolution: never, context: never) => Returned>,\n\t\tDependencies,\n\t\tGuard\n\t>\n\tfunction action(configuration: {\n\t\tcontext: Resolver\n\t\tcontract?: DomainContract\n\t\taudit?: (resolution: never, context: never, scope: never) => AuditValue\n\t\toperations: (define: never) => Readonly<Record<string, object>>\n\t\tdefaults?: { guard?: (context: never) => unknown }\n\t}): unknown {\n\t\tconst buildOperations = () => {\n\t\t\tconst operations = snapshotOperations(\n\t\t\t\tconfiguration.operations(\n\t\t\t\t\t// SAFETY: each overload checks callbacks against this exact inline or contracted helper factory.\n\t\t\t\t\t(configuration.contract\n\t\t\t\t\t\t? domainEffectFactory(\n\t\t\t\t\t\t\t\tconfiguration.contract.actions ?? {},\n\t\t\t\t\t\t\t\t'action',\n\t\t\t\t\t\t\t\tconfiguration.contract.errors,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: effectActionFactory()) as never,\n\t\t\t\t),\n\t\t\t\tconfiguration.contract,\n\t\t\t\t'actions',\n\t\t\t\tconfiguration.audit,\n\t\t\t)\n\t\t\tif (!dependencies.writeActionAudit) {\n\t\t\t\tfor (const [operation, definition] of Object.entries(operations))\n\t\t\t\t\tif ('audit' in definition && definition.audit !== undefined)\n\t\t\t\t\t\tthrow new ActionAuditWriterError(operation)\n\t\t\t}\n\t\t\treturn operations\n\t\t}\n\t\tconst getOperations = memoize(buildOperations)\n\t\t// SAFETY: overloads check callbacks and schemas; binding validates exact keys and snapshots runtime records.\n\t\tconst kernel = createEffectCommand({\n\t\t\t...configuration,\n\t\t\tobservability: dependencies.observability,\n\t\t\tauditFailure: dependencies.auditFailure,\n\t\t\tnestedAudit: dependencies.nestedAudit,\n\t\t\twriteAudit: dependencies.writeActionAudit ?? (() => undefined),\n\t\t\toperations: getOperations,\n\t\t\tmode: 'action',\n\t\t} as never)\n\t\treturn registerLazyRegistry(\n\t\t\t{ exec: kernel.exec, withContext: kernel.withContext },\n\t\t\tgetOperations,\n\t\t)\n\t}\n\treturn action\n}\n"],"mappings":"qSAmFA,IAAaA,EAAb,cAA4C,KAAM,CACjD,KAAgB,8BAChB,KAAgB,yBAChB,YAAY,EAAmB,CAC9B,MAAM,WAAWC,EAAU,+DAA+D,CAC3F,CACD,EAGA,SAAgBC,EACf,EACC,CA0ED,SAASC,EAAO,EAMJ,CAwBX,IAAMC,EAAgBC,MAvBQ,CAC7B,IAAMC,EAAaC,EAClBC,EAAc,WAEZA,EAAc,SACZC,EACAD,EAAc,SAAS,SAAW,CAAC,EACnC,SACAA,EAAc,SAAS,MACxB,EACCE,EAAoB,CACxB,EACAF,EAAc,SACd,UACAA,EAAc,KACf,EACA,GAAI,CAACG,EAAa,iBACZ,KAAA,GAAM,CAACV,EAAWW,KAAe,OAAO,QAAQN,CAAU,EAC9D,GAAI,UAAWM,GAAcA,EAAW,QAAU,IAAA,GACjD,MAAM,IAAIZ,EAAuBC,CAAS,CAAA,CAE7C,OAAOK,CACR,CAC6C,EAEvCO,EAASC,EAAoB,CAClC,GAAGN,EACH,cAAeG,EAAa,cAC5B,aAAcA,EAAa,aAC3B,YAAaA,EAAa,YAC1B,WAAYA,EAAa,uBAA2B,IAAA,IACpD,WAAYP,EACZ,KAAM,QACP,CAAU,EACV,OAAOW,EACN,CAAE,KAAMF,EAAO,KAAM,YAAaA,EAAO,WAAY,EACrDT,CACD,CACD,CACA,OAAOD,CACR"}
1
+ {"version":3,"file":"action.mjs","names":["ActionAuditWriterError","operation","bindEffectAction","action","getOperations","memoize","operations","snapshotOperations","configuration","domainEffectFactory","effectActionFactory","dependencies","definition","kernel","createEffectCommand","registerLazyRegistry"],"sources":["../../../src/modules/effect/action.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- Overload implementation storage is erased; public signatures retain concrete values, errors and services. */\nimport type { Effect } from 'effect'\nimport type { AuditEntryInput } from '../../components/foundation/client'\n// oxlint-disable-next-line cvx/component-boundaries -- SAFETY: Internal optional adapter shares the Effect-free Foundation observability without entering the Convex component deployment graph.\nimport type { Observability } from '../../components/foundation/modules/observability/observability'\nimport type { DomainActionContract, DomainAuditInput, DomainContract } from '../contracts/domain'\nimport { snapshotOperations, type BoundOperations } from '../contracts/binding'\nimport { memoize, registerLazyRegistry } from '../contracts/lazy'\nimport {\n\tcreateEffectCommand,\n\ttype DomainOf,\n\ttype HostOf,\n\ttype HostParameter,\n\ttype Registry,\n\ttype Resolver,\n} from './command'\nimport {\n\tdomainEffectFactory,\n\ttype AuditedOperations,\n\ttype AuditValue,\n\ttype DomainEffectFactory,\n\ttype DomainEffectImplementations,\n\ttype ExactDomainOperations,\n} from './domain'\nimport type { FailureAuditOptions } from './failure-audit'\nimport {\n\teffectActionFactory,\n\ttype CallbackError,\n\ttype CallbackRequirements,\n\ttype ValidatedEffectOperations,\n} from './operation'\nimport type { NestedAuditMode, RequestScope } from './scope'\n\ntype Supported<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>\n\n/** Host policies an Action registry uses; actions have no mutation-side permission host. */\nexport type EffectActionDependencies = {\n\tobservability: Observability\n\t/** Writes action audit entries, typically through `ctx.runMutation`; required once any action audits. */\n\twriteActionAudit?: (host: never, entry: AuditEntryInput) => Supported<unknown>\n\tauditFailure?: FailureAuditOptions\n\tnestedAudit?: NestedAuditMode\n}\ntype ActionWriter<Dependencies extends EffectActionDependencies> = [\n\tExclude<Dependencies['writeActionAudit'], undefined>,\n] extends [never]\n\t? (host: never, entry: AuditEntryInput) => void\n\t: Exclude<Dependencies['writeActionAudit'], undefined>\n/** The command kernel runs actions with the action writer in its audit-writer slot. */\ntype KernelDependencies<Dependencies extends EffectActionDependencies> = {\n\tobservability: Observability\n\twriteAudit: ActionWriter<Dependencies>\n\tauditFailure?: FailureAuditOptions\n\tnestedAudit?: NestedAuditMode\n}\ntype ActionCompatible<Resolve extends Resolver, Dependencies extends EffectActionDependencies> = [\n\tHostOf<Resolve>,\n] extends [HostParameter<Dependencies['writeActionAudit']>]\n\t? unknown\n\t: { context: never }\ntype ActionFactory<Resolve extends Resolver, Guard> = ReturnType<\n\ttypeof effectActionFactory<\n\t\tDomainOf<Resolve>,\n\t\tNoInfer<CallbackError<Guard>>,\n\t\tNoInfer<CallbackRequirements<Guard>>\n\t>\n>\ntype Kernel<\n\tResolve extends Resolver,\n\tOperations extends Registry<DomainOf<Resolve>>,\n\tDependencies extends EffectActionDependencies,\n\tGuard,\n> = ReturnType<\n\ttypeof createEffectCommand<Resolve, Operations, KernelDependencies<Dependencies>, Guard>\n>\n/** Actions are executed by their own Convex action functions; they are never exposed as mutations. */\nexport type EffectActionRegistry<\n\tResolve extends Resolver,\n\tOperations extends Registry<DomainOf<Resolve>>,\n\tDependencies extends EffectActionDependencies,\n\tGuard,\n> = Pick<Kernel<Resolve, Operations, Dependencies, Guard>, 'exec' | 'withContext'>\n\nexport class ActionAuditWriterError extends Error {\n\treadonly code = 'ACTION_AUDIT_WRITER_MISSING'\n\treadonly name = 'ActionAuditWriterError'\n\tconstructor(operation: string) {\n\t\tsuper(`Action \"${operation}\" declares an audit but the Foundation has no writeActionAudit`)\n\t}\n}\n\n/** Bind trusted application policies once; each registry resolves its own invocation context. */\nexport function bindEffectAction<const Dependencies extends EffectActionDependencies>(\n\tdependencies: Dependencies,\n) {\n\tfunction action<\n\t\tResolve extends Resolver,\n\t\tconst Contract extends DomainContract & {\n\t\t\tactions: Readonly<Record<string, DomainActionContract>>\n\t\t},\n\t\tconst Operations extends DomainEffectImplementations<DomainOf<Resolve>, Contract['actions']>,\n\t\tReturned extends AuditValue = never,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontract: Contract &\n\t\t\t\tNoInfer<\n\t\t\t\t\tOperations extends ExactDomainOperations<Operations, Contract['actions']> &\n\t\t\t\t\t\tValidatedEffectOperations<Operations>\n\t\t\t\t\t\t? unknown\n\t\t\t\t\t\t: never\n\t\t\t\t>\n\t\t\tcontext: Resolve\n\t\t\taudit?: (\n\t\t\t\tresolution: DomainAuditInput<Contract['actions']>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t\tscope: RequestScope | undefined,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: DomainEffectFactory<\n\t\t\t\t\tDomainOf<Resolve>,\n\t\t\t\t\tContract['actions'],\n\t\t\t\t\t'action',\n\t\t\t\t\tnever,\n\t\t\t\t\tNoInfer<CallbackError<Guard>>,\n\t\t\t\t\tNoInfer<CallbackRequirements<Guard>>,\n\t\t\t\t\tContract['errors']\n\t\t\t\t>,\n\t\t\t) => Operations\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & ActionCompatible<Resolve, Dependencies>,\n\t): EffectActionRegistry<\n\t\tResolve,\n\t\t[Returned] extends [never]\n\t\t\t? BoundOperations<Operations, Contract['actions']>\n\t\t\t: AuditedOperations<\n\t\t\t\t\tBoundOperations<Operations, Contract['actions']>,\n\t\t\t\t\t(resolution: never, context: never) => Returned\n\t\t\t\t>,\n\t\tDependencies,\n\t\tGuard\n\t>\n\tfunction action<\n\t\tResolve extends Resolver,\n\t\tconst Operations extends Registry<DomainOf<Resolve>>,\n\t\tReturned extends AuditValue = never,\n\t\tGuard = never,\n\t>(\n\t\tconfiguration: {\n\t\t\tcontext: Resolve\n\t\t\taudit?: (\n\t\t\t\tresolution: DomainAuditInput<Operations>,\n\t\t\t\tcontext: DomainOf<Resolve>,\n\t\t\t\tscope: RequestScope | undefined,\n\t\t\t) => Returned\n\t\t\toperations: (\n\t\t\t\tdefine: ActionFactory<Resolve, Guard>,\n\t\t\t) => Operations & NoInfer<ValidatedEffectOperations<Operations>>\n\t\t\tdefaults?: { guard?: (context: DomainOf<Resolve>) => Guard }\n\t\t} & ActionCompatible<Resolve, Dependencies>,\n\t): EffectActionRegistry<\n\t\tResolve,\n\t\t[Returned] extends [never]\n\t\t\t? Operations\n\t\t\t: AuditedOperations<Operations, (resolution: never, context: never) => Returned>,\n\t\tDependencies,\n\t\tGuard\n\t>\n\tfunction action(configuration: {\n\t\tcontext: Resolver\n\t\tcontract?: DomainContract\n\t\taudit?: (resolution: never, context: never, scope: never) => AuditValue\n\t\toperations: (define: never) => Readonly<Record<string, object>>\n\t\tdefaults?: { guard?: (context: never) => unknown }\n\t}): unknown {\n\t\tconst buildOperations = () => {\n\t\t\tconst operations = snapshotOperations(\n\t\t\t\tconfiguration.operations(\n\t\t\t\t\t// SAFETY: each overload checks callbacks against this exact inline or contracted helper factory.\n\t\t\t\t\t(configuration.contract\n\t\t\t\t\t\t? domainEffectFactory(\n\t\t\t\t\t\t\t\tconfiguration.contract.actions ?? {},\n\t\t\t\t\t\t\t\t'action',\n\t\t\t\t\t\t\t\tconfiguration.contract.errors,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: effectActionFactory()) as never,\n\t\t\t\t),\n\t\t\t\tconfiguration.contract,\n\t\t\t\t'actions',\n\t\t\t\tconfiguration.audit,\n\t\t\t)\n\t\t\tif (!dependencies.writeActionAudit) {\n\t\t\t\tfor (const [operation, definition] of Object.entries(operations))\n\t\t\t\t\tif ('audit' in definition && definition.audit !== undefined)\n\t\t\t\t\t\tthrow new ActionAuditWriterError(operation)\n\t\t\t}\n\t\t\treturn operations\n\t\t}\n\t\tconst getOperations = memoize(buildOperations)\n\t\t// SAFETY: overloads check callbacks and schemas; binding validates exact keys and snapshots runtime records.\n\t\tconst kernel = createEffectCommand({\n\t\t\t...configuration,\n\t\t\tobservability: dependencies.observability,\n\t\t\tauditFailure: dependencies.auditFailure,\n\t\t\tnestedAudit: dependencies.nestedAudit,\n\t\t\twriteAudit: dependencies.writeActionAudit ?? (() => undefined),\n\t\t\toperations: getOperations,\n\t\t\tmode: 'action',\n\t\t} as never)\n\t\treturn registerLazyRegistry(\n\t\t\t{ exec: kernel.exec, withContext: kernel.withContext },\n\t\t\tgetOperations,\n\t\t)\n\t}\n\treturn action\n}\n"],"mappings":"A,qSAmFA,IAAaA,EAAb,cAA4C,KAAM,CACjD,KAAgB,8BAChB,KAAgB,yBAChB,YAAY,EAAmB,CAC9B,MAAM,WAAWC,EAAU,+DAA+D,CAC3F,CACD,EAGA,SAAgBC,EACf,EACC,CA0ED,SAASC,EAAO,EAMJ,CAwBX,IAAMC,EAAgBC,MAvBQ,CAC7B,IAAMC,EAAaC,EAClBC,EAAc,WAEZA,EAAc,SACZC,EACAD,EAAc,SAAS,SAAW,CAAC,EACnC,SACAA,EAAc,SAAS,MACxB,EACCE,EAAoB,CACxB,EACAF,EAAc,SACd,UACAA,EAAc,KACf,EACA,GAAI,CAACG,EAAa,iBACZ,KAAA,GAAM,CAACV,EAAWW,KAAe,OAAO,QAAQN,CAAU,EAC9D,GAAI,UAAWM,GAAcA,EAAW,QAAU,IAAA,GACjD,MAAM,IAAIZ,EAAuBC,CAAS,CAAA,CAE7C,OAAOK,CACR,CAC6C,EAEvCO,EAASC,EAAoB,CAClC,GAAGN,EACH,cAAeG,EAAa,cAC5B,aAAcA,EAAa,aAC3B,YAAaA,EAAa,YAC1B,WAAYA,EAAa,uBAA2B,IAAA,IACpD,WAAYP,EACZ,KAAM,QACP,CAAU,EACV,OAAOW,EACN,CAAE,KAAMF,EAAO,KAAM,YAAaA,EAAO,WAAY,EACrDT,CACD,CACD,CACA,OAAOD,CACR,C"}
@@ -1 +1 @@
1
- import{bindOperationExecutor as e,createOperationTools as t,operationToolDialect as n,selectOperation as r}from"../contracts/exposure.mjs";export{e as bindOperationExecutor,t as createOperationTools,n as operationToolDialect,r as selectOperation};
1
+ export{bindOperationExecutor,createOperationTools,operationToolDialect,selectOperation}from"../contracts/exposure.mjs";
@@ -1,7 +1,6 @@
1
1
  import { ErrorContract, ErrorDefinitions } from "../contracts/errors.mjs";
2
2
  import { CallbackRequirements, EffectValue } from "./operation.mjs";
3
3
  import { Context, Effect, Scope } from "effect";
4
- //#region src/modules/effect/api-runtime.d.ts
5
4
  export type EffectApiErrorProjection = (error: unknown) => unknown;
6
5
  export type EffectApiErrorContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>;
7
6
  export type EffectApiHandlerValue<Value> = Value | PromiseLike<Value> | Effect.Effect<Value, unknown, unknown>;
@@ -33,5 +32,5 @@ export declare function wrapEffectBuilder(builder: Function, options: {
33
32
  mapError?: EffectApiErrorProjection;
34
33
  errors?: EffectApiErrorContract;
35
34
  }): Function;
36
- //#endregion
35
+ export {};
37
36
  //# sourceMappingURL=api-runtime.d.mts.map
@@ -1,2 +1,2 @@
1
- import{memoize as e}from"../contracts/lazy.mjs";import{projectErrorCause as t}from"./errors.mjs";import{normalizeEffect as n}from"./normalize.mjs";import{ConvexError as r}from"convex/values";import{Cause as i,Context as a,Effect as o,Exit as s}from"effect";function c(e,c){return u=>{let d=typeof u==`function`?u:u.handler,f=async(e,...l)=>{let u=n(()=>c.services?c.services(e):a.empty()).pipe(o.flatMap(t=>n(()=>c.context?c.context(e):{}).pipe(o.flatMap(t=>o.sync(()=>{if(typeof t!=`object`||!t)throw Error(`Effect API context must be an object`);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n!==null)throw Error(`Effect API context additions must be a plain record`);let r=e;for(let e of Reflect.ownKeys(t))if(e in r)throw Error(`Effect API context cannot replace ${String(e)}`);return c.context?Object.create(Object.getPrototypeOf(r),{...Object.getOwnPropertyDescriptors(r),...Object.getOwnPropertyDescriptors(t)}):e})),o.flatMap(e=>n(()=>d(e,...l))),o.provideContext(t)))),f=await o.runPromiseExit(o.scoped(u));if(s.isSuccess(f))return f.value;if(c.errors)throw new r(t(c.errors,f.cause));let p=f.cause.reasons.length===1?f.cause.reasons[0]:void 0;throw p&&i.isFailReason(p)?c.mapError?c.mapError(p.error):p.error:p&&i.isDieReason(p)?p.defect:Error(`Effect API execution failed`,{cause:f.cause})};return e(typeof u==`function`?f:l(u,f))}}function l(t,n){let r={handler:n};for(let n of Reflect.ownKeys(t)){let i=Object.getOwnPropertyDescriptor(t,n);n!==`handler`&&i?.enumerable&&Object.defineProperty(r,n,{configurable:!0,enumerable:!0,...i.get?{get:e(()=>i.get.call(t))}:{value:i.value,writable:!0}})}return r}export{c as wrapEffectBuilder};
1
+ import{memoize as e}from"../contracts/lazy.mjs";import{getArgumentRejection as t,projectErrorCause as n}from"./errors.mjs";import{normalizeEffect as r}from"./normalize.mjs";import{ConvexError as i}from"convex/values";import{Cause as a,Context as o,Effect as s,Exit as c}from"effect";function l(e,l){return d=>{let f=typeof d==`function`?d:d.handler,p=async(e,...u)=>{let d=r(()=>l.services?l.services(e):o.empty()).pipe(s.flatMap(t=>r(()=>l.context?l.context(e):{}).pipe(s.flatMap(t=>s.sync(()=>{if(typeof t!=`object`||!t)throw Error(`Effect API context must be an object`);let n=Object.getPrototypeOf(t);if(n!==Object.prototype&&n!==null)throw Error(`Effect API context additions must be a plain record`);let r=e;for(let e of Reflect.ownKeys(t))if(e in r)throw Error(`Effect API context cannot replace ${String(e)}`);return l.context?Object.create(Object.getPrototypeOf(r),{...Object.getOwnPropertyDescriptors(r),...Object.getOwnPropertyDescriptors(t)}):e})),s.flatMap(e=>r(()=>f(e,...u))),s.provideContext(t)))),p=await s.runPromiseExit(s.scoped(d));if(c.isSuccess(p))return p.value;let m=p.cause.reasons.length===1?p.cause.reasons[0]:void 0;throw m&&a.isDieReason(m)&&t(p.cause)?m.defect:l.errors?new i(n(l.errors,p.cause)):m&&a.isFailReason(m)?l.mapError?l.mapError(m.error):m.error:m&&a.isDieReason(m)?m.defect:Error(`Effect API execution failed`,{cause:p.cause})};return e(typeof d==`function`?p:u(d,p))}}function u(t,n){let r={handler:n};for(let n of Reflect.ownKeys(t)){let i=Object.getOwnPropertyDescriptor(t,n);n!==`handler`&&i?.enumerable&&Object.defineProperty(r,n,{configurable:!0,enumerable:!0,...i.get?{get:e(()=>i.get.call(t))}:{value:i.value,writable:!0}})}return r}export{l as wrapEffectBuilder};
2
2
  //# sourceMappingURL=api-runtime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-runtime.mjs","names":["wrapEffectBuilder","original","definition","handler","args","program","normalizeEffect","options","ctx","Context","Effect","added","additionsPrototype","originalContext","key","context","services","exit","Exit","ConvexError","projectErrorCause","reason","Cause","builder","withHandler","copy","descriptor","memoize"],"sources":["../../../src/modules/effect/api-runtime.ts"],"sourcesContent":["import { Cause, Context, Effect, Exit } from 'effect'\nimport type { Scope } from 'effect'\nimport { ConvexError, type Value } from 'convex/values'\nimport type { ErrorContract, ErrorDefinitions } from '../contracts/errors'\nimport { memoize } from '../contracts/lazy'\nimport { projectErrorCause } from './errors'\nimport { normalizeEffect } from './normalize'\nimport type { CallbackRequirements, EffectValue } from './operation'\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns -- Projection receives any expected failure and its result is always thrown, never returned as public data.\nexport type EffectApiErrorProjection = (error: unknown) => unknown\nexport type EffectApiErrorContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>\n\nexport type EffectApiHandlerValue<Value> =\n\t| Value\n\t| PromiseLike<Value>\n\t| Effect.Effect<Value, unknown, unknown>\n\nexport type EffectApiServices =\n\t| Context.Context<never>\n\t| PromiseLike<Context.Context<never>>\n\t| Effect.Effect<Context.Context<never>, unknown, Scope.Scope>\nexport type ProvidedServices<Provider> =\n\tEffectValue<Provider> extends Context.Context<infer Services> ? Services : never\n// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- This inference constraint requires record-shaped additions; each adapter preserves its concrete inferred fields and runtime checks the record boundary.\nexport type EffectApiContext = EffectApiHandlerValue<Record<string, unknown>>\ntype KeysOfUnion<Value> = Value extends object ? keyof Value : never\nexport type CheckedContext<Ctx, Added> =\n\tExtract<KeysOfUnion<EffectValue<Added>>, keyof Ctx> extends never ? unknown : never\nexport type EffectApiOptions<Ctx, Provider extends EffectApiServices, Added = {}> = (\n\t[ProvidedServices<Provider>] extends [never]\n\t\t? { services?: (ctx: Ctx) => Provider }\n\t\t: { services: (ctx: Ctx) => Provider }\n) & (\n\t[KeysOfUnion<EffectValue<Added>>] extends [never]\n\t\t? { context?: (ctx: Ctx) => Added & CheckedContext<Ctx, Added> }\n\t\t: { context: (ctx: Ctx) => Added & CheckedContext<Ctx, Added> }\n) & (\n\t| { errors: EffectApiErrorContract; mapError?: never }\n\t| { errors?: never; mapError?: EffectApiErrorProjection }\n)\nexport type CheckedApiRequirements<Returned, Provider> = [\n\tExclude<CallbackRequirements<NoInfer<Returned>>, ProvidedServices<Provider> | Scope.Scope>,\n] extends [never]\n\t? unknown\n\t: never\n\n/** Internal erasure is limited to the registration boundary; public adapters check A/E/R. */\nexport function wrapEffectBuilder(\n\tbuilder: Function,\n\toptions: {\n\t\tservices?: Function\n\t\tcontext?: Function\n\t\tmapError?: EffectApiErrorProjection\n\t\terrors?: EffectApiErrorContract\n\t},\n): Function {\n\treturn (definition: Function | { handler: Function }) => {\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Native registration explicitly accepts a callable or an object with a handler.\n\t\tconst original = typeof definition === 'function' ? definition : definition.handler\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Private erased callback receives the context already constructed by the checked native/custom builder.\n\t\tconst handler = async (ctx: unknown, ...args: unknown[]) => {\n\t\t\tconst program = normalizeEffect(() =>\n\t\t\t\toptions.services ? options.services(ctx) : Context.empty(),\n\t\t\t).pipe(\n\t\t\t\tEffect.flatMap((services) =>\n\t\t\t\t\tnormalizeEffect(() => (options.context ? options.context(ctx) : {})).pipe(\n\t\t\t\t\t\tEffect.flatMap((added) =>\n\t\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Validate erased context additions before enumerating or merging their fields.\n\t\t\t\t\t\t\t\tif (added === null || typeof added !== 'object')\n\t\t\t\t\t\t\t\t\tthrow Error('Effect API context must be an object')\n\t\t\t\t\t\t\t\tconst additionsPrototype = Object.getPrototypeOf(added)\n\t\t\t\t\t\t\t\tif (additionsPrototype !== Object.prototype && additionsPrototype !== null)\n\t\t\t\t\t\t\t\t\tthrow Error('Effect API context additions must be a plain record')\n\t\t\t\t\t\t\t\t// SAFETY: native and custom builders construct an object context before invoking this private handler.\n\t\t\t\t\t\t\t\tconst originalContext = ctx as object\n\t\t\t\t\t\t\t\tfor (const key of Reflect.ownKeys(added)) {\n\t\t\t\t\t\t\t\t\tif (key in originalContext)\n\t\t\t\t\t\t\t\t\t\tthrow Error(`Effect API context cannot replace ${String(key)}`)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn options.context\n\t\t\t\t\t\t\t\t\t? Object.create(Object.getPrototypeOf(originalContext), {\n\t\t\t\t\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptors(originalContext),\n\t\t\t\t\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptors(added),\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t: ctx\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.flatMap((context) => normalizeEffect(() => original(context, ...args))),\n\t\t\t\t\t\tEffect.provideContext(services),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t\t// SAFETY: checked public signatures prohibit unprovided handler requirements and\n\t\t\t// permit only Scope in providers; services are constructed within this same scope.\n\t\t\tconst exit = await Effect.runPromiseExit(\n\t\t\t\tEffect.scoped(program) as Effect.Effect<unknown, unknown>,\n\t\t\t)\n\t\t\tif (Exit.isSuccess(exit)) return exit.value\n\t\t\tif (options.errors) {\n\t\t\t\t// SAFETY: declared projection copies validated JSON-safe fields; all other Causes have a fixed safe envelope.\n\t\t\t\tthrow new ConvexError(projectErrorCause(options.errors, exit.cause) as Value)\n\t\t\t}\n\t\t\tconst reason = exit.cause.reasons.length === 1 ? exit.cause.reasons[0] : undefined\n\t\t\tif (reason && Cause.isFailReason(reason)) {\n\t\t\t\tthrow options.mapError ? options.mapError(reason.error) : reason.error\n\t\t\t}\n\t\t\tif (reason && Cause.isDieReason(reason)) throw reason.defect\n\t\t\tthrow new Error('Effect API execution failed', { cause: exit.cause })\n\t\t}\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Preserve the original native callable or object registration form.\n\t\treturn builder(typeof definition === 'function' ? handler : withHandler(definition, handler))\n\t}\n}\n\n/**\n * Object-spread equivalent that forwards accessors instead of reading them, so\n * getter-declared args and returns stay unread until the builder needs them.\n */\nfunction withHandler(definition: { handler: Function }, handler: Function) {\n\tconst copy = { handler }\n\tfor (const key of Reflect.ownKeys(definition)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(definition, key)\n\t\tif (key === 'handler' || !descriptor?.enumerable) continue\n\t\tObject.defineProperty(copy, key, {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t\t...(descriptor.get\n\t\t\t\t? { get: memoize(() => descriptor.get!.call(definition)) }\n\t\t\t\t: { value: descriptor.value, writable: true }),\n\t\t})\n\t}\n\treturn copy\n}\n"],"mappings":"iQAgDA,SAAgBA,EACf,EACA,EAMW,CACX,MAAQ,IAAiD,CAExD,IAAMC,EAAW,OAAOC,GAAe,WAAaA,EAAaA,EAAW,QAEtEC,EAAU,MAAO,EAAc,GAAGC,IAAoB,CAC3D,IAAMC,EAAUC,MACfC,EAAQ,SAAWA,EAAQ,SAASC,CAAG,EAAIC,EAAQ,MAA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E,EAEA,OAAOM,EAAQ,OAAOrB,GAAe,WAAaC,EAAUqB,EAAYtB,EAAYC,CAAO,CAAC,CAC7F,CACD,CAMA,SAASqB,EAAY,EAAmC,EAAmB,CAC1E,IAAMC,EAAO,CAAE,SAAQ,EACvB,IAAK,IAAMX,KAAO,QAAQ,QAAQZ,CAAU,EAAG,CAC9C,IAAMwB,EAAa,OAAO,yBAAyBxB,EAAYY,CAAG,EAC9DA,IAAQ,WAAcY,GAAY,YACtC,OAAO,eAAeD,EAAMX,EAAK,CAChC,aAAc,GACd,WAAY,GACZ,GAAIY,EAAW,IACZ,CAAE,IAAKC,MAAcD,EAAW,IAAK,KAAKxB,CAAU,CAAC,CAAE,EACvD,CAAE,MAAOwB,EAAW,MAAO,SAAU,EAAK,CAC9C,CAAC,CACF,CACA,OAAOD,CACR"}
1
+ {"version":3,"file":"api-runtime.mjs","names":["wrapEffectBuilder","original","definition","handler","args","program","normalizeEffect","options","ctx","Context","Effect","added","additionsPrototype","originalContext","key","context","services","exit","Exit","reason","Cause","getArgumentRejection","ConvexError","projectErrorCause","builder","withHandler","copy","descriptor","memoize"],"sources":["../../../src/modules/effect/api-runtime.ts"],"sourcesContent":["import { Cause, Context, Effect, Exit } from 'effect'\nimport type { Scope } from 'effect'\nimport { ConvexError, type Value } from 'convex/values'\nimport type { ErrorContract, ErrorDefinitions } from '../contracts/errors'\nimport { memoize } from '../contracts/lazy'\nimport { getArgumentRejection, projectErrorCause } from './errors'\nimport { normalizeEffect } from './normalize'\nimport type { CallbackRequirements, EffectValue } from './operation'\n\n// oxlint-disable-next-line anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns -- Projection receives any expected failure and its result is always thrown, never returned as public data.\nexport type EffectApiErrorProjection = (error: unknown) => unknown\nexport type EffectApiErrorContract = Pick<ErrorContract<ErrorDefinitions>, 'project'>\n\nexport type EffectApiHandlerValue<Value> =\n\t| Value\n\t| PromiseLike<Value>\n\t| Effect.Effect<Value, unknown, unknown>\n\nexport type EffectApiServices =\n\t| Context.Context<never>\n\t| PromiseLike<Context.Context<never>>\n\t| Effect.Effect<Context.Context<never>, unknown, Scope.Scope>\nexport type ProvidedServices<Provider> =\n\tEffectValue<Provider> extends Context.Context<infer Services> ? Services : never\n// oxlint-disable-next-line anti-slop/no-unsafe-dictionary-type -- This inference constraint requires record-shaped additions; each adapter preserves its concrete inferred fields and runtime checks the record boundary.\nexport type EffectApiContext = EffectApiHandlerValue<Record<string, unknown>>\ntype KeysOfUnion<Value> = Value extends object ? keyof Value : never\nexport type CheckedContext<Ctx, Added> =\n\tExtract<KeysOfUnion<EffectValue<Added>>, keyof Ctx> extends never ? unknown : never\nexport type EffectApiOptions<Ctx, Provider extends EffectApiServices, Added = {}> = (\n\t[ProvidedServices<Provider>] extends [never]\n\t\t? { services?: (ctx: Ctx) => Provider }\n\t\t: { services: (ctx: Ctx) => Provider }\n) & (\n\t[KeysOfUnion<EffectValue<Added>>] extends [never]\n\t\t? { context?: (ctx: Ctx) => Added & CheckedContext<Ctx, Added> }\n\t\t: { context: (ctx: Ctx) => Added & CheckedContext<Ctx, Added> }\n) & (\n\t| { errors: EffectApiErrorContract; mapError?: never }\n\t| { errors?: never; mapError?: EffectApiErrorProjection }\n)\nexport type CheckedApiRequirements<Returned, Provider> = [\n\tExclude<CallbackRequirements<NoInfer<Returned>>, ProvidedServices<Provider> | Scope.Scope>,\n] extends [never]\n\t? unknown\n\t: never\n\n/** Internal erasure is limited to the registration boundary; public adapters check A/E/R. */\nexport function wrapEffectBuilder(\n\tbuilder: Function,\n\toptions: {\n\t\tservices?: Function\n\t\tcontext?: Function\n\t\tmapError?: EffectApiErrorProjection\n\t\terrors?: EffectApiErrorContract\n\t},\n): Function {\n\treturn (definition: Function | { handler: Function }) => {\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Native registration explicitly accepts a callable or an object with a handler.\n\t\tconst original = typeof definition === 'function' ? definition : definition.handler\n\t\t// oxlint-disable-next-line anti-slop/no-unknown-parameters -- Private erased callback receives the context already constructed by the checked native/custom builder.\n\t\tconst handler = async (ctx: unknown, ...args: unknown[]) => {\n\t\t\tconst program = normalizeEffect(() =>\n\t\t\t\toptions.services ? options.services(ctx) : Context.empty(),\n\t\t\t).pipe(\n\t\t\t\tEffect.flatMap((services) =>\n\t\t\t\t\tnormalizeEffect(() => (options.context ? options.context(ctx) : {})).pipe(\n\t\t\t\t\t\tEffect.flatMap((added) =>\n\t\t\t\t\t\t\tEffect.sync(() => {\n\t\t\t\t\t\t\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Validate erased context additions before enumerating or merging their fields.\n\t\t\t\t\t\t\t\tif (added === null || typeof added !== 'object')\n\t\t\t\t\t\t\t\t\tthrow Error('Effect API context must be an object')\n\t\t\t\t\t\t\t\tconst additionsPrototype = Object.getPrototypeOf(added)\n\t\t\t\t\t\t\t\tif (additionsPrototype !== Object.prototype && additionsPrototype !== null)\n\t\t\t\t\t\t\t\t\tthrow Error('Effect API context additions must be a plain record')\n\t\t\t\t\t\t\t\t// SAFETY: native and custom builders construct an object context before invoking this private handler.\n\t\t\t\t\t\t\t\tconst originalContext = ctx as object\n\t\t\t\t\t\t\t\tfor (const key of Reflect.ownKeys(added)) {\n\t\t\t\t\t\t\t\t\tif (key in originalContext)\n\t\t\t\t\t\t\t\t\t\tthrow Error(`Effect API context cannot replace ${String(key)}`)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn options.context\n\t\t\t\t\t\t\t\t\t? Object.create(Object.getPrototypeOf(originalContext), {\n\t\t\t\t\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptors(originalContext),\n\t\t\t\t\t\t\t\t\t\t\t...Object.getOwnPropertyDescriptors(added),\n\t\t\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t\t: ctx\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t\t\tEffect.flatMap((context) => normalizeEffect(() => original(context, ...args))),\n\t\t\t\t\t\tEffect.provideContext(services),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t)\n\t\t\t// SAFETY: checked public signatures prohibit unprovided handler requirements and\n\t\t\t// permit only Scope in providers; services are constructed within this same scope.\n\t\t\tconst exit = await Effect.runPromiseExit(\n\t\t\t\tEffect.scoped(program) as Effect.Effect<unknown, unknown>,\n\t\t\t)\n\t\t\tif (Exit.isSuccess(exit)) return exit.value\n\t\t\tconst reason = exit.cause.reasons.length === 1 ? exit.cause.reasons[0] : undefined\n\t\t\tif (reason && Cause.isDieReason(reason) && getArgumentRejection(exit.cause))\n\t\t\t\tthrow reason.defect\n\t\t\tif (options.errors) {\n\t\t\t\t// SAFETY: declared projection copies validated JSON-safe fields; all other Causes have a fixed safe envelope.\n\t\t\t\tthrow new ConvexError(projectErrorCause(options.errors, exit.cause) as Value)\n\t\t\t}\n\t\t\tif (reason && Cause.isFailReason(reason)) {\n\t\t\t\tthrow options.mapError ? options.mapError(reason.error) : reason.error\n\t\t\t}\n\t\t\tif (reason && Cause.isDieReason(reason)) throw reason.defect\n\t\t\tthrow new Error('Effect API execution failed', { cause: exit.cause })\n\t\t}\n\t\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- Preserve the original native callable or object registration form.\n\t\treturn builder(typeof definition === 'function' ? handler : withHandler(definition, handler))\n\t}\n}\n\n/**\n * Object-spread equivalent that forwards accessors instead of reading them, so\n * getter-declared args and returns stay unread until the builder needs them.\n */\nfunction withHandler(definition: { handler: Function }, handler: Function) {\n\tconst copy = { handler }\n\tfor (const key of Reflect.ownKeys(definition)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(definition, key)\n\t\tif (key === 'handler' || !descriptor?.enumerable) continue\n\t\tObject.defineProperty(copy, key, {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t\t...(descriptor.get\n\t\t\t\t? { get: memoize(() => descriptor.get!.call(definition)) }\n\t\t\t\t: { value: descriptor.value, writable: true }),\n\t\t})\n\t}\n\treturn copy\n}\n"],"m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KAAK,EACnEE,EAAO,OACVZ,EAAQ,OAEL,IAAIe,EAAYC,EAAkBhB,EAAQ,OAAQU,EAAK,KAAK,CAAU,EAEzEE,GAAUC,EAAM,aAAaD,CAAM,EAChCZ,EAAQ,SAAWA,EAAQ,SAASY,EAAO,KAAK,EAAIA,EAAO,MAE9DA,GAAUC,EAAM,YAAYD,CAAM,EAASA,EAAO,OAC5C,MAAM,8BAA+B,CAAE,MAAOF,EAAK,KAAM,CAAC,CACrE,EAEA,OAAOO,EAAQ,OAAOtB,GAAe,WAAaC,EAAUsB,EAAYvB,EAAYC,CAAO,CAAC,CAC7F,CACD,CAMA,SAASsB,EAAY,EAAmC,EAAmB,CAC1E,IAAMC,EAAO,CAAE,SAAQ,EACvB,IAAK,IAAMZ,KAAO,QAAQ,QAAQZ,CAAU,EAAG,CAC9C,IAAMyB,EAAa,OAAO,yBAAyBzB,EAAYY,CAAG,EAC9DA,IAAQ,WAAca,GAAY,YACtC,OAAO,eAAeD,EAAMZ,EAAK,CAChC,aAAc,GACd,WAAY,GACZ,GAAIa,EAAW,IACZ,CAAE,IAAKC,MAAcD,EAAW,IAAK,KAAKzB,CAAU,CAAC,CAAE,EACvD,CAAE,MAAOyB,EAAW,MAAO,SAAU,EAAK,CAC9C,CAAC,CACF,CACA,OAAOD,CACR,C"}
@@ -1,20 +1,46 @@
1
- import { EffectValue } from "./operation.mjs";
2
- import { CheckedApiRequirements, EffectApiContext, EffectApiHandlerValue, EffectApiOptions, EffectApiServices } from "./api-runtime.mjs";
3
- import { ActionBuilder, ArgsArrayForOptionalValidator, ArgsArrayToObject, DefaultArgsForOptionalValidator, FunctionVisibility, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx, MutationBuilder, QueryBuilder, RegisteredAction, RegisteredMutation, RegisteredQuery, ReturnValueForOptionalValidator } from "convex/server";
4
- import { PropertyValidators, Validator } from "convex/values";
5
- //#region src/modules/effect/api.d.ts
6
- type ApiValidator = PropertyValidators | Validator<unknown, 'required', string> | void;
7
- type ApiOutput<Returns extends ApiValidator> = [Returns] extends [void] ? unknown : ReturnValueForOptionalValidator<Returns>;
8
- export type EffectApiBuilder<Ctx, Visibility extends FunctionVisibility, Kind extends 'query' | 'mutation' | 'action', Provider, Initialized = {}> = {
9
- <Args extends ApiValidator, Returns extends ApiValidator = void, Returned extends EffectApiHandlerValue<ApiOutput<Returns>> = EffectApiHandlerValue<ApiOutput<Returns>>, OneOrZeroArgs extends ArgsArrayForOptionalValidator<Args> = DefaultArgsForOptionalValidator<Args>>(definition: ({
1
+ import { KType } from "../../k/types.mjs";
2
+ import { KArgs, KArgsInput, KArgsOutput, KCustomBuilder, KReturns } from "../../registration.mjs";
3
+ import { EffectApiContext, EffectApiHandlerValue, EffectApiOptions, EffectApiServices, ProvidedServices } from "./api-runtime.mjs";
4
+ import { CallbackRequirements, EffectValue } from "./operation.mjs";
5
+ import { GenericValidator, Infer, ObjectType, PropertyValidators } from "convex/values";
6
+ import { ActionBuilder, ArgsArrayToObject, DefaultFunctionArgs, FunctionVisibility, GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx, MutationBuilder, QueryBuilder } from "convex/server";
7
+ import { Registration } from "convex-helpers/server/customFunctions";
8
+ import { Scope } from "effect";
9
+ type Expand<Value> = { [Key in keyof Value]: Value[Key]; };
10
+ type Overwrite<Input, Custom> = keyof Custom extends never ? Input : Omit<Input, keyof Custom> & Custom;
11
+ type HandlerArgs<Args, Made> = [Args] extends [void] ? Made extends Record<string, never> ? [DefaultFunctionArgs] : [Expand<DefaultFunctionArgs & Made>] : Made extends Record<string, never> ? [KArgsOutput<Args>] : [Expand<KArgsOutput<Args> & Made>];
12
+ /** A handler without declared args may still annotate its own (Convex's native rule). */
13
+ type HandlerArgsBound<Args, Made> = HandlerArgs<Args, Made> | ([Args] extends [void] ? (Made extends Record<string, never> ? [] : never) : never);
14
+ type RawArgs<Args, Custom extends PropertyValidators, OneOrZeroArgs extends [] | [DefaultFunctionArgs]> = [Args] extends [void] ? Custom extends Record<string, never> ? ArgsArrayToObject<OneOrZeroArgs> : Expand<DefaultFunctionArgs & ObjectType<Custom>> : Custom extends Record<string, never> ? KArgsInput<Args> : Expand<KArgsInput<Args> & ObjectType<Custom>>;
15
+ /** The value a handler must produce: the output side of a `k` schema, which Convex validates. */
16
+ type ResultValue<Returns> = [Returns] extends [KType] ? Returns['_output'] : [Returns] extends [GenericValidator] ? Infer<Returns> : unknown;
17
+ /**
18
+ * The registered result: what the handler returns when that already satisfies `returns` (so a
19
+ * narrower handler value, such as a search page's required `paginationMode`, reaches callers, as
20
+ * the `k` custom builders do), and the `returns` output otherwise.
21
+ */
22
+ type ResultOutput<Returns, Returned> = [Returns] extends [void] ? EffectValue<Returned> : [EffectValue<Returned>] extends [ResultValue<Returns>] ? EffectValue<Returned> : ResultValue<Returns>;
23
+ type CheckedRequirements<Returned, Services> = [Exclude<CallbackRequirements<NoInfer<Returned>>, Services | Scope.Scope>] extends [never] ? unknown : never;
24
+ type Reserved = 'args' | 'returns' | 'handler' | 'skipConvexValidation';
25
+ /**
26
+ * One Effect builder over a native Convex builder or a `k` custom builder (`kCustomQuery`, the auth
27
+ * constructors): `args` and `returns` accept `k` schemas and native validators, and the customization's
28
+ * context, made args and extra options are retained.
29
+ */
30
+ export type EffectApiBuilder<Kind extends 'query' | 'mutation' | 'action', CustomArgs extends PropertyValidators, CustomCtx extends object, CustomMadeArgs extends Record<string, unknown>, InputCtx, Visibility extends FunctionVisibility, ExtraArgs extends Record<string, unknown>, Services, Added = {}, Initialized = {}> = {
31
+ <Args extends KArgs | void = void, Returns extends KReturns | void = void, Returned extends EffectApiHandlerValue<ResultValue<Returns> | (null extends ResultValue<Returns> ? undefined | void : never)> = EffectApiHandlerValue<ResultValue<Returns> | (null extends ResultValue<Returns> ? undefined | void : never)>, OneOrZeroArgs extends HandlerArgsBound<Args, CustomMadeArgs> = HandlerArgs<Args, CustomMadeArgs>>(definition: (({
10
32
  args?: Args;
11
33
  returns?: Returns;
12
- handler: (ctx: Ctx, ...args: OneOrZeroArgs) => Returned;
13
- } | ((ctx: Ctx, ...args: OneOrZeroArgs) => Returned)) & CheckedApiRequirements<Returned, Provider> & CheckedApiRequirements<Initialized, Provider>): Kind extends 'query' ? RegisteredQuery<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>> : Kind extends 'mutation' ? RegisteredMutation<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>> : RegisteredAction<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>>;
34
+ /** Export no validators to Convex; the kit then parses args fully itself (KTD3). */
35
+ skipConvexValidation?: boolean;
36
+ handler: (ctx: Overwrite<InputCtx, CustomCtx> & Added, ...args: OneOrZeroArgs) => Returned;
37
+ } & Omit<ExtraArgs, Reserved>) | ((ctx: Overwrite<InputCtx, CustomCtx> & Added, ...args: OneOrZeroArgs) => Returned)) & CheckedRequirements<Returned, Services> & CheckedRequirements<Initialized, Services>): Registration<Kind, Visibility, RawArgs<Args, CustomArgs, Extract<OneOrZeroArgs, [] | [DefaultFunctionArgs]>>, ResultOutput<Returns, Returned>>;
14
38
  };
39
+ type Adapter<Kind extends 'query' | 'mutation' | 'action', Ctx, Visibility extends FunctionVisibility, Provider, Added> = EffectApiBuilder<Kind, {}, {}, {}, Ctx, Visibility, {}, ProvidedServices<Provider>, EffectValue<Added>, Added>;
15
40
  /** Provision request services after the supplied builder has constructed its trusted context. */
16
- export declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: QueryBuilder<DM, V>, options: EffectApiOptions<GenericQueryCtx<DM>, Provider, Added>): EffectApiBuilder<GenericQueryCtx<DM> & EffectValue<Added>, V, 'query', Provider, Added>;
17
- export declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: MutationBuilder<DM, V>, options: EffectApiOptions<GenericMutationCtx<DM>, Provider, Added>): EffectApiBuilder<GenericMutationCtx<DM> & EffectValue<Added>, V, 'mutation', Provider, Added>;
18
- export declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: ActionBuilder<DM, V>, options: EffectApiOptions<GenericActionCtx<DM>, Provider, Added>): EffectApiBuilder<GenericActionCtx<DM> & EffectValue<Added>, V, 'action', Provider, Added>;
19
- //#endregion
41
+ export declare function effectApiBuilder<Kind extends 'query' | 'mutation' | 'action', CustomArgs extends PropertyValidators, CustomCtx extends Record<string, any>, CustomMadeArgs extends Record<string, any>, InputCtx, Visibility extends FunctionVisibility, ExtraArgs extends Record<string, any>, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: KCustomBuilder<Kind, CustomArgs, CustomCtx, CustomMadeArgs, InputCtx, Visibility, ExtraArgs>, options: EffectApiOptions<Overwrite<InputCtx, CustomCtx>, Provider, Added>): EffectApiBuilder<Kind, CustomArgs, CustomCtx, CustomMadeArgs, InputCtx, Visibility, ExtraArgs, ProvidedServices<Provider>, EffectValue<Added>, Added>;
42
+ export declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: QueryBuilder<DM, V>, options: EffectApiOptions<GenericQueryCtx<DM>, Provider, Added>): Adapter<'query', GenericQueryCtx<DM>, V, Provider, Added>;
43
+ export declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: MutationBuilder<DM, V>, options: EffectApiOptions<GenericMutationCtx<DM>, Provider, Added>): Adapter<'mutation', GenericMutationCtx<DM>, V, Provider, Added>;
44
+ export declare function effectApiBuilder<DM extends GenericDataModel, V extends FunctionVisibility, Provider extends EffectApiServices = import('effect').Context.Context<never>, Added extends EffectApiContext = {}>(builder: ActionBuilder<DM, V>, options: EffectApiOptions<GenericActionCtx<DM>, Provider, Added>): Adapter<'action', GenericActionCtx<DM>, V, Provider, Added>;
45
+ export {};
20
46
  //# sourceMappingURL=api.d.mts.map
@@ -1,2 +1,2 @@
1
- import{wrapEffectBuilder as e}from"./api-runtime.mjs";function t(t,n){return e(t,n)}export{t as effectApiBuilder};
1
+ import{kCustomQuery as e}from"../../registration.mjs";import{wrapEffectBuilder as t}from"./api-runtime.mjs";import{actionGeneric as n,internalActionGeneric as r,internalMutationGeneric as i,internalQueryGeneric as a,mutationGeneric as o,queryGeneric as s}from"convex/server";import{NoOp as c}from"convex-helpers/server/customFunctions";function l(e,n){return t(u.has(e)?d(e):e,n)}const u=/* @__PURE__ */ new Set([s,o,n,a,i,r]);function d(t){return e(t,c)}export{l as effectApiBuilder};
2
2
  //# sourceMappingURL=api.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"api.mjs","names":["effectApiBuilder","wrapEffectBuilder","builder","options"],"sources":["../../../src/modules/effect/api.ts"],"sourcesContent":["import type {\n\tActionBuilder,\n\tArgsArrayForOptionalValidator,\n\tArgsArrayToObject,\n\tDefaultArgsForOptionalValidator,\n\tFunctionVisibility,\n\tGenericActionCtx,\n\tGenericDataModel,\n\tGenericMutationCtx,\n\tGenericQueryCtx,\n\tMutationBuilder,\n\tQueryBuilder,\n\tRegisteredAction,\n\tRegisteredMutation,\n\tRegisteredQuery,\n\tReturnValueForOptionalValidator,\n} from 'convex/server'\nimport type { PropertyValidators, Validator } from 'convex/values'\nimport type { EffectValue } from './operation'\nimport {\n\twrapEffectBuilder,\n\ttype CheckedApiRequirements,\n\ttype EffectApiOptions,\n\ttype EffectApiErrorProjection,\n\ttype EffectApiErrorContract,\n\ttype EffectApiServices,\n\ttype EffectApiHandlerValue,\n\ttype EffectApiContext,\n} from './api-runtime'\n\n// Convex's optional-validator grammar, restricted to unknown instead of public any.\ntype ApiValidator = PropertyValidators | Validator<unknown, 'required', string> | void\ntype ApiOutput<Returns extends ApiValidator> = [Returns] extends [void]\n\t? unknown\n\t: ReturnValueForOptionalValidator<Returns>\nexport type EffectApiBuilder<\n\tCtx,\n\tVisibility extends FunctionVisibility,\n\tKind extends 'query' | 'mutation' | 'action',\n\tProvider,\n\tInitialized = {},\n> = {\n\t<\n\t\tArgs extends ApiValidator,\n\t\tReturns extends ApiValidator = void,\n\t\tReturned extends EffectApiHandlerValue<ApiOutput<Returns>> = EffectApiHandlerValue<\n\t\t\tApiOutput<Returns>\n\t\t>,\n\t\tOneOrZeroArgs extends ArgsArrayForOptionalValidator<Args> =\n\t\t\tDefaultArgsForOptionalValidator<Args>,\n\t>(\n\t\tdefinition: (\n\t\t\t| { args?: Args; returns?: Returns; handler: (ctx: Ctx, ...args: OneOrZeroArgs) => Returned }\n\t\t\t| ((ctx: Ctx, ...args: OneOrZeroArgs) => Returned)\n\t\t) &\n\t\t\tCheckedApiRequirements<Returned, Provider> &\n\t\t\tCheckedApiRequirements<Initialized, Provider>,\n\t): Kind extends 'query'\n\t\t? RegisteredQuery<Visibility, ArgsArrayToObject<OneOrZeroArgs>, Promise<EffectValue<Returned>>>\n\t\t: Kind extends 'mutation'\n\t\t\t? RegisteredMutation<\n\t\t\t\t\tVisibility,\n\t\t\t\t\tArgsArrayToObject<OneOrZeroArgs>,\n\t\t\t\t\tPromise<EffectValue<Returned>>\n\t\t\t\t>\n\t\t\t: RegisteredAction<\n\t\t\t\t\tVisibility,\n\t\t\t\t\tArgsArrayToObject<OneOrZeroArgs>,\n\t\t\t\t\tPromise<EffectValue<Returned>>\n\t\t\t\t>\n}\n\n/** Provision request services after the supplied builder has constructed its trusted context. */\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: QueryBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericQueryCtx<DM>, Provider, Added>,\n): EffectApiBuilder<GenericQueryCtx<DM> & EffectValue<Added>, V, 'query', Provider, Added>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: MutationBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericMutationCtx<DM>, Provider, Added>,\n): EffectApiBuilder<GenericMutationCtx<DM> & EffectValue<Added>, V, 'mutation', Provider, Added>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: ActionBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericActionCtx<DM>, Provider, Added>,\n): EffectApiBuilder<GenericActionCtx<DM> & EffectValue<Added>, V, 'action', Provider, Added>\nexport function effectApiBuilder(\n\tbuilder: Function,\n\toptions: {\n\t\tservices?: Function\n\t\tcontext?: Function\n\t\tmapError?: EffectApiErrorProjection\n\t\terrors?: EffectApiErrorContract\n\t},\n): Function {\n\treturn wrapEffectBuilder(builder, options)\n}\n"],"mappings":"sDAoGA,SAAgBA,EACf,EACA,EAMW,CACX,OAAOC,EAAkBC,EAASC,CAAO,CAC1C"}
1
+ {"version":3,"file":"api.mjs","names":["effectApiBuilder","wrapEffectBuilder","nativeBuilders","builder","kBuilder","options","queryGeneric","mutationGeneric","actionGeneric","internalQueryGeneric","internalMutationGeneric","internalActionGeneric","kCustomQuery","NoOp"],"sources":["../../../src/modules/effect/api.ts"],"sourcesContent":["import {\n\tactionGeneric,\n\tinternalActionGeneric,\n\tinternalMutationGeneric,\n\tinternalQueryGeneric,\n\tmutationGeneric,\n\tqueryGeneric,\n\ttype ActionBuilder,\n\ttype ArgsArrayToObject,\n\ttype DefaultFunctionArgs,\n\ttype FunctionVisibility,\n\ttype GenericActionCtx,\n\ttype GenericDataModel,\n\ttype GenericMutationCtx,\n\ttype GenericQueryCtx,\n\ttype MutationBuilder,\n\ttype QueryBuilder,\n} from 'convex/server'\nimport type { GenericValidator, Infer, ObjectType, PropertyValidators } from 'convex/values'\nimport { NoOp, type Registration } from 'convex-helpers/server/customFunctions'\nimport type { Scope } from 'effect'\nimport type { KType } from '../../k/types'\nimport {\n\tkCustomQuery,\n\ttype KArgs,\n\ttype KArgsInput,\n\ttype KArgsOutput,\n\ttype KCustomBuilder,\n\ttype KReturns,\n} from '../../registration'\nimport {\n\twrapEffectBuilder,\n\ttype EffectApiOptions,\n\ttype EffectApiErrorProjection,\n\ttype EffectApiErrorContract,\n\ttype EffectApiServices,\n\ttype EffectApiHandlerValue,\n\ttype EffectApiContext,\n\ttype ProvidedServices,\n} from './api-runtime'\nimport type { CallbackRequirements, EffectValue } from './operation'\n\n// The argument and result grammar of src/registration.ts: `k` schemas, native validators, or both.\ntype Expand<Value> = { [Key in keyof Value]: Value[Key] }\ntype Overwrite<Input, Custom> = keyof Custom extends never\n\t? Input\n\t: Omit<Input, keyof Custom> & Custom\ntype HandlerArgs<Args, Made> = [Args] extends [void]\n\t? Made extends Record<string, never>\n\t\t? [DefaultFunctionArgs]\n\t\t: [Expand<DefaultFunctionArgs & Made>]\n\t: Made extends Record<string, never>\n\t\t? [KArgsOutput<Args>]\n\t\t: [Expand<KArgsOutput<Args> & Made>]\n/** A handler without declared args may still annotate its own (Convex's native rule). */\ntype HandlerArgsBound<Args, Made> =\n\t| HandlerArgs<Args, Made>\n\t| ([Args] extends [void] ? (Made extends Record<string, never> ? [] : never) : never)\ntype RawArgs<\n\tArgs,\n\tCustom extends PropertyValidators,\n\tOneOrZeroArgs extends [] | [DefaultFunctionArgs],\n> = [Args] extends [void]\n\t? Custom extends Record<string, never>\n\t\t? ArgsArrayToObject<OneOrZeroArgs>\n\t\t: Expand<DefaultFunctionArgs & ObjectType<Custom>>\n\t: Custom extends Record<string, never>\n\t\t? KArgsInput<Args>\n\t\t: Expand<KArgsInput<Args> & ObjectType<Custom>>\n/** The value a handler must produce: the output side of a `k` schema, which Convex validates. */\ntype ResultValue<Returns> = [Returns] extends [KType]\n\t? Returns['_output']\n\t: [Returns] extends [GenericValidator]\n\t\t? Infer<Returns>\n\t\t: unknown\n/**\n * The registered result: what the handler returns when that already satisfies `returns` (so a\n * narrower handler value, such as a search page's required `paginationMode`, reaches callers, as\n * the `k` custom builders do), and the `returns` output otherwise.\n */\ntype ResultOutput<Returns, Returned> = [Returns] extends [void]\n\t? EffectValue<Returned>\n\t: [EffectValue<Returned>] extends [ResultValue<Returns>]\n\t\t? EffectValue<Returned>\n\t\t: ResultValue<Returns>\ntype CheckedRequirements<Returned, Services> = [\n\tExclude<CallbackRequirements<NoInfer<Returned>>, Services | Scope.Scope>,\n] extends [never]\n\t? unknown\n\t: never\ntype Reserved = 'args' | 'returns' | 'handler' | 'skipConvexValidation'\n\n/**\n * One Effect builder over a native Convex builder or a `k` custom builder (`kCustomQuery`, the auth\n * constructors): `args` and `returns` accept `k` schemas and native validators, and the customization's\n * context, made args and extra options are retained.\n */\nexport type EffectApiBuilder<\n\tKind extends 'query' | 'mutation' | 'action',\n\tCustomArgs extends PropertyValidators,\n\t// Native Convex context interfaces do not declare a string index signature.\n\tCustomCtx extends object,\n\tCustomMadeArgs extends Record<string, unknown>,\n\tInputCtx,\n\tVisibility extends FunctionVisibility,\n\tExtraArgs extends Record<string, unknown>,\n\tServices,\n\tAdded = {},\n\tInitialized = {},\n> = {\n\t<\n\t\tArgs extends KArgs | void = void,\n\t\tReturns extends KReturns | void = void,\n\t\tReturned extends EffectApiHandlerValue<\n\t\t\tResultValue<Returns> | (null extends ResultValue<Returns> ? undefined | void : never)\n\t\t> = EffectApiHandlerValue<\n\t\t\tResultValue<Returns> | (null extends ResultValue<Returns> ? undefined | void : never)\n\t\t>,\n\t\tOneOrZeroArgs extends HandlerArgsBound<Args, CustomMadeArgs> = HandlerArgs<\n\t\t\tArgs,\n\t\t\tCustomMadeArgs\n\t\t>,\n\t>(\n\t\tdefinition: (\n\t\t\t| ({\n\t\t\t\t\targs?: Args\n\t\t\t\t\treturns?: Returns\n\t\t\t\t\t/** Export no validators to Convex; the kit then parses args fully itself (KTD3). */\n\t\t\t\t\tskipConvexValidation?: boolean\n\t\t\t\t\thandler: (ctx: Overwrite<InputCtx, CustomCtx> & Added, ...args: OneOrZeroArgs) => Returned\n\t\t\t } & Omit<ExtraArgs, Reserved>)\n\t\t\t| ((ctx: Overwrite<InputCtx, CustomCtx> & Added, ...args: OneOrZeroArgs) => Returned)\n\t\t) &\n\t\t\tCheckedRequirements<Returned, Services> &\n\t\t\tCheckedRequirements<Initialized, Services>,\n\t): Registration<\n\t\tKind,\n\t\tVisibility,\n\t\tRawArgs<Args, CustomArgs, Extract<OneOrZeroArgs, [] | [DefaultFunctionArgs]>>,\n\t\tResultOutput<Returns, Returned>\n\t>\n}\n\ntype Adapter<\n\tKind extends 'query' | 'mutation' | 'action',\n\tCtx,\n\tVisibility extends FunctionVisibility,\n\tProvider,\n\tAdded,\n> = EffectApiBuilder<\n\tKind,\n\t{},\n\t{},\n\t{},\n\tCtx,\n\tVisibility,\n\t{},\n\tProvidedServices<Provider>,\n\tEffectValue<Added>,\n\tAdded\n>\n\n/** Provision request services after the supplied builder has constructed its trusted context. */\nexport function effectApiBuilder<\n\tKind extends 'query' | 'mutation' | 'action',\n\tCustomArgs extends PropertyValidators,\n\tCustomCtx extends Record<string, any>,\n\tCustomMadeArgs extends Record<string, any>,\n\tInputCtx,\n\tVisibility extends FunctionVisibility,\n\tExtraArgs extends Record<string, any>,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: KCustomBuilder<\n\t\tKind,\n\t\tCustomArgs,\n\t\tCustomCtx,\n\t\tCustomMadeArgs,\n\t\tInputCtx,\n\t\tVisibility,\n\t\tExtraArgs\n\t>,\n\toptions: EffectApiOptions<Overwrite<InputCtx, CustomCtx>, Provider, Added>,\n): EffectApiBuilder<\n\tKind,\n\tCustomArgs,\n\tCustomCtx,\n\tCustomMadeArgs,\n\tInputCtx,\n\tVisibility,\n\tExtraArgs,\n\tProvidedServices<Provider>,\n\tEffectValue<Added>,\n\tAdded\n>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: QueryBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericQueryCtx<DM>, Provider, Added>,\n): Adapter<'query', GenericQueryCtx<DM>, V, Provider, Added>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: MutationBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericMutationCtx<DM>, Provider, Added>,\n): Adapter<'mutation', GenericMutationCtx<DM>, V, Provider, Added>\nexport function effectApiBuilder<\n\tDM extends GenericDataModel,\n\tV extends FunctionVisibility,\n\tProvider extends EffectApiServices = import('effect').Context.Context<never>,\n\tAdded extends EffectApiContext = {},\n>(\n\tbuilder: ActionBuilder<DM, V>,\n\toptions: EffectApiOptions<GenericActionCtx<DM>, Provider, Added>,\n): Adapter<'action', GenericActionCtx<DM>, V, Provider, Added>\nexport function effectApiBuilder(\n\tbuilder: Function,\n\toptions: {\n\t\tservices?: Function\n\t\tcontext?: Function\n\t\tmapError?: EffectApiErrorProjection\n\t\terrors?: EffectApiErrorContract\n\t},\n): Function {\n\treturn wrapEffectBuilder(nativeBuilders.has(builder) ? kBuilder(builder) : builder, options)\n}\n\n/**\n * Convex's own registration functions; every generated `query`/`mutation`/`action` is one of them.\n * Any other builder is a `k` custom builder, which already accepts `k` schemas and must not be\n * wrapped twice (its made args would reach the outer parse).\n */\nconst nativeBuilders = new Set<Function>([\n\tqueryGeneric,\n\tmutationGeneric,\n\tactionGeneric,\n\tinternalQueryGeneric,\n\tinternalMutationGeneric,\n\tinternalActionGeneric,\n])\n\n/** A native builder behind src/registration.ts with no customization, so it accepts `k` schemas. */\nfunction kBuilder(builder: Function): Function {\n\t// SAFETY: kCustomQuery, kCustomMutation and kCustomAction share one kind-agnostic runtime; the kind\n\t// is a type-level label only, and the public overloads above carry the native builder's own kind.\n\treturn kCustomQuery(builder as QueryBuilder<GenericDataModel, FunctionVisibility>, NoOp)\n}\n"],"mappings":"A,gVA+NA,SAAgBA,EACf,EACA,EAMW,CACX,OAAOC,EAAkBC,EAAe,IAAIC,CAAO,EAAIC,EAASD,CAAO,EAAIA,EAASE,CAAO,CAC5F,CAOA,MAAMH,kBAAiB,IAAI,IAAc,CACxCI,EACAC,EACAC,EACAC,EACAC,EACAC,CACD,CAAC,EAGD,SAASP,EAAS,EAA6B,CAG9C,OAAOQ,EAAaT,EAA+DU,CAAI,CACxF,C"}
@@ -1,12 +1,11 @@
1
1
  import { AuthBundle, AuthFunctions, AuthFunctionsConfig, DefaultRole, Include, ServiceMutation, ServicePrincipal, ServiceQuery } from "../../auth.mjs";
2
- import { EffectValue } from "./operation.mjs";
2
+ import { KCustomBuilder } from "../../registration.mjs";
3
+ import { EffectApiBuilder } from "./api.mjs";
3
4
  import { EffectApiContext, EffectApiOptions, EffectApiServices, ProvidedServices } from "./api-runtime.mjs";
4
- import { EffectZodApiBuilder } from "./api-zod.mjs";
5
- import { CustomBuilder } from "convex-helpers/server/zod4";
5
+ import { EffectValue } from "./operation.mjs";
6
6
  import { GenericActionCtx, GenericDataModel, GenericMutationCtx, GenericQueryCtx } from "convex/server";
7
7
  import { Context } from "effect";
8
- //#region src/modules/effect/auth.d.ts
9
- type Adapted<Builder, Services, Added> = Builder extends CustomBuilder<infer Kind, infer Args, infer Ctx, infer Made, infer Input, infer Visibility, infer Extra> ? EffectZodApiBuilder<Kind, Args, Ctx, Made, Input, Visibility, Extra, ProvidedServices<Services>, EffectValue<Added>, Added> : never;
8
+ type Adapted<Builder, Services, Added> = Builder extends KCustomBuilder<infer Kind, infer Args, infer Ctx, infer Made, infer Input, infer Visibility, infer Extra> ? EffectApiBuilder<Kind, Args, Ctx, Made, Input, Visibility, Extra, ProvidedServices<Services>, EffectValue<Added>, Added> : never;
10
9
  /** Shared post-auth composition; internal/system policies are configured separately. */
11
10
  export type EffectAuthFunctions<DataModel extends GenericDataModel, Role extends string = DefaultRole, QueryServices extends EffectApiServices = Context.Context<never>, QueryAdded extends EffectApiContext = {}, MutationServices extends EffectApiServices = Context.Context<never>, MutationAdded extends EffectApiContext = {}, ActionServices extends EffectApiServices = Context.Context<never>, ActionAdded extends EffectApiContext = {}, SystemQueryServices extends EffectApiServices = Context.Context<never>, SystemQueryAdded extends EffectApiContext = {}, SystemMutationServices extends EffectApiServices = Context.Context<never>, SystemMutationAdded extends EffectApiContext = {}, SystemActionServices extends EffectApiServices = Context.Context<never>, SystemActionAdded extends EffectApiContext = {}> = Pick<AuthFunctions<DataModel, Role>, 'include' | 'authenticatedUser'> & {
12
11
  authQuery: Adapted<AuthFunctions<DataModel, Role>['authQuery'], QueryServices, QueryAdded>;
@@ -43,5 +42,5 @@ export declare function createEffectAuthFunctions<DataModel extends GenericDataM
43
42
  }, SystemMutationServices, SystemMutationAdded>;
44
43
  systemAction: EffectApiOptions<GenericActionCtx<DataModel>, SystemActionServices, SystemActionAdded>;
45
44
  }): EffectAuthFunctions<DataModel, Role, QueryServices, QueryAdded, MutationServices, MutationAdded, ActionServices, ActionAdded, SystemQueryServices, SystemQueryAdded, SystemMutationServices, SystemMutationAdded, SystemActionServices, SystemActionAdded>;
46
- //#endregion
45
+ export {};
47
46
  //# sourceMappingURL=auth.d.mts.map
@@ -1,2 +1,2 @@
1
- import{createAuthFunctions as e}from"../../auth.mjs";import{wrapEffectBuilder as t}from"./api-runtime.mjs";import{effectZodApiBuilder as n}from"./api-zod.mjs";function r(t,r){let a=e(t);return{include:a.include,authenticatedUser:a.authenticatedUser,authQuery:n(a.authQuery,r.query),roleQuery:(...e)=>n(a.roleQuery(...e),r.query),adminQuery:n(a.adminQuery,r.query),authMutation:n(a.authMutation,r.mutation),roleMutation:(...e)=>n(a.roleMutation(...e),r.mutation),adminMutation:n(a.adminMutation,r.mutation),authAction:n(a.authAction,r.action),roleAction:(...e)=>n(a.roleAction(...e),r.action),adminAction:n(a.adminAction,r.action),serviceQuery:e=>i(a.serviceQuery(e),r.query),serviceMutation:e=>i(a.serviceMutation(e),r.mutation),systemQuery:n(a.systemQuery,r.systemQuery),systemMutation:n(a.systemMutation,r.systemMutation),systemAction:n(a.systemAction,r.systemAction)}}function i(e,n){return t(e,n)}export{r as createEffectAuthFunctions};
1
+ import{createAuthFunctions as e}from"../../auth.mjs";import{effectApiBuilder as t}from"./api.mjs";import{wrapEffectBuilder as n}from"./api-runtime.mjs";function r(n,r){let a=e(n);return{include:a.include,authenticatedUser:a.authenticatedUser,authQuery:t(a.authQuery,r.query),roleQuery:(...e)=>t(a.roleQuery(...e),r.query),adminQuery:t(a.adminQuery,r.query),authMutation:t(a.authMutation,r.mutation),roleMutation:(...e)=>t(a.roleMutation(...e),r.mutation),adminMutation:t(a.adminMutation,r.mutation),authAction:t(a.authAction,r.action),roleAction:(...e)=>t(a.roleAction(...e),r.action),adminAction:t(a.adminAction,r.action),serviceQuery:e=>i(a.serviceQuery(e),r.query),serviceMutation:e=>i(a.serviceMutation(e),r.mutation),systemQuery:t(a.systemQuery,r.systemQuery),systemMutation:t(a.systemMutation,r.systemMutation),systemAction:t(a.systemAction,r.systemAction)}}function i(e,t){return n(e,t)}export{r as createEffectAuthFunctions};
2
2
  //# sourceMappingURL=auth.mjs.map