@aventara/core 1.0.0-rc.0 → 1.0.0-rc.2

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 (267) hide show
  1. package/CHANGELOG.md +1434 -0
  2. package/ERRORS.md +142 -0
  3. package/README.md +247 -57
  4. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  5. package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
  6. package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
  7. package/dist/adapters/adapter-field.d.ts +25 -11
  8. package/dist/adapters/adapter-identifier.d.ts +6 -6
  9. package/dist/adapters/adapter-model.d.ts +18 -9
  10. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  11. package/dist/adapters/adapter-operation.d.ts +3 -3
  12. package/dist/adapters/adapter-resource.d.ts +18 -9
  13. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  14. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  15. package/dist/adapters/adapter.interface.d.ts +59 -29
  16. package/dist/avz/avz-check.factory.d.ts +83 -0
  17. package/dist/avz/avz-check.factory.js +116 -0
  18. package/dist/avz/avz-check.registry.d.ts +35 -0
  19. package/dist/avz/avz-check.registry.js +9 -0
  20. package/dist/avz/avz.d.ts +203 -0
  21. package/dist/{json → avz}/avz.js +150 -8
  22. package/dist/{json → avz}/index.d.ts +2 -1
  23. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  24. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  25. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  26. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  27. package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
  28. package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
  29. package/dist/compiler/contract.compiler.d.ts +18 -18
  30. package/dist/compiler/contract.compiler.js +637 -442
  31. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  32. package/dist/compiler/create-requirements.projector.js +423 -0
  33. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  34. package/dist/compiler/field-validator.compiler.js +238 -0
  35. package/dist/config/any-framework-config.d.ts +19 -12
  36. package/dist/config/computed-fields.d.ts +62 -0
  37. package/dist/config/computed-fields.js +80 -0
  38. package/dist/config/config-diagnostic.d.ts +11 -4
  39. package/dist/config/config-diagnostic.guidance.d.ts +6 -0
  40. package/dist/config/config-diagnostic.guidance.js +32 -0
  41. package/dist/config/config-layer.d.ts +15 -6
  42. package/dist/config/config.resolver.d.ts +74 -31
  43. package/dist/config/config.resolver.js +108 -44
  44. package/dist/config/config.validator.d.ts +7 -7
  45. package/dist/config/config.validator.js +581 -72
  46. package/dist/config/define-resource.d.ts +57 -0
  47. package/dist/config/define-resource.js +14 -0
  48. package/dist/config/effective-fields.d.ts +19 -23
  49. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  50. package/dist/config/exact-framework-config.d.ts +308 -0
  51. package/dist/config/field-compute.resolver.d.ts +21 -0
  52. package/dist/config/field-compute.resolver.js +123 -0
  53. package/dist/config/field-pipeline-config.d.ts +47 -0
  54. package/dist/config/forced-operation.validator.d.ts +10 -0
  55. package/dist/config/forced-operation.validator.js +66 -0
  56. package/dist/config/framework-config.d.ts +111 -39
  57. package/dist/config/framework-exemptions-config.d.ts +91 -0
  58. package/dist/config/framework-exemptions-config.js +1 -0
  59. package/dist/config/framework-field-definition.d.ts +78 -0
  60. package/dist/config/framework-field-definition.js +28 -0
  61. package/dist/config/framework-resources-config.d.ts +122 -0
  62. package/dist/config/framework-resources-config.js +1 -0
  63. package/dist/config/pipeline-config.d.ts +56 -20
  64. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  65. package/dist/config/pipeline-tree.resolver.js +220 -0
  66. package/dist/config/stage-type.eraser.d.ts +65 -0
  67. package/dist/config/stage-type.eraser.js +1 -0
  68. package/dist/contracts/capability.d.ts +21 -12
  69. package/dist/contracts/capability.js +2 -0
  70. package/dist/contracts/client-contract-structure.validator.d.ts +388 -63
  71. package/dist/contracts/client-contract-structure.validator.js +156 -10
  72. package/dist/contracts/contract-canonicalizer.d.ts +26 -3
  73. package/dist/contracts/contract-canonicalizer.js +156 -29
  74. package/dist/contracts/contract-hash.d.ts +12 -7
  75. package/dist/contracts/contract-hash.js +3 -2
  76. package/dist/contracts/contract-limits.d.ts +4 -1
  77. package/dist/contracts/contract-limits.js +1 -0
  78. package/dist/contracts/contract-lookup.d.ts +5 -5
  79. package/dist/contracts/contract-protocol.d.ts +4 -4
  80. package/dist/contracts/contract.d.ts +24 -16
  81. package/dist/contracts/create-requirements.d.ts +35 -0
  82. package/dist/contracts/create-requirements.js +1 -0
  83. package/dist/contracts/enum-definition.d.ts +1 -1
  84. package/dist/contracts/field-check.d.ts +101 -0
  85. package/dist/contracts/field-check.js +1 -0
  86. package/dist/contracts/field.d.ts +81 -42
  87. package/dist/contracts/identifier.d.ts +4 -4
  88. package/dist/contracts/json-shape.d.ts +12 -1
  89. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  90. package/dist/contracts/resource-operations.d.ts +28 -28
  91. package/dist/contracts/resource.d.ts +15 -9
  92. package/dist/contracts/scalar-value-type.d.ts +15 -15
  93. package/dist/contracts/scalar.d.ts +3 -3
  94. package/dist/contracts/transaction-capability.d.ts +1 -1
  95. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  96. package/dist/framework/contract-view.d.ts +213 -147
  97. package/dist/framework/framework-construction.error.d.ts +19 -10
  98. package/dist/framework/framework-construction.error.js +7 -3
  99. package/dist/framework/framework.d.ts +47 -23
  100. package/dist/framework/framework.factory.d.ts +8 -6
  101. package/dist/framework/framework.factory.js +49 -22
  102. package/dist/framework/operation-facade.d.ts +123 -52
  103. package/dist/framework/operation-facade.js +9 -1
  104. package/dist/index.d.ts +57 -50
  105. package/dist/index.js +7 -6
  106. package/dist/internal.d.ts +17 -10
  107. package/dist/internal.js +4 -1
  108. package/dist/operations/database-refusal.d.ts +51 -0
  109. package/dist/operations/database-refusal.js +45 -0
  110. package/dist/operations/operation-arguments.d.ts +343 -207
  111. package/dist/operations/operation-call.d.ts +27 -28
  112. package/dist/operations/operation-identity.d.ts +10 -10
  113. package/dist/operations/operation-result.d.ts +21 -21
  114. package/dist/operations/operation-validator-core.d.ts +6 -6
  115. package/dist/operations/operation-validator-core.js +99 -6
  116. package/dist/operations/operation-validator.d.ts +9 -9
  117. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  118. package/dist/operations/structural-limits.walker.d.ts +6 -6
  119. package/dist/operations/structural-limits.walker.js +145 -0
  120. package/dist/operations/validation-code.d.ts +11 -6
  121. package/dist/operations/validation-code.guidance.d.ts +6 -0
  122. package/dist/operations/validation-code.guidance.js +90 -0
  123. package/dist/operations/validation-code.js +4 -0
  124. package/dist/operations/write-scope.resolver.d.ts +10 -6
  125. package/dist/operations/write-scope.resolver.js +2 -0
  126. package/dist/protocol/absent-route.responder.d.ts +13 -12
  127. package/dist/protocol/absent-route.responder.js +19 -19
  128. package/dist/protocol/contract-document.responder.d.ts +3 -3
  129. package/dist/protocol/contract-document.responder.js +2 -2
  130. package/dist/protocol/http-request.decoder.d.ts +17 -13
  131. package/dist/protocol/http-request.decoder.js +10 -10
  132. package/dist/protocol/http-request.reader.d.ts +3 -3
  133. package/dist/protocol/http-response.encoder.d.ts +4 -4
  134. package/dist/protocol/http-response.encoder.js +94 -55
  135. package/dist/protocol/http-status.table.d.ts +2 -2
  136. package/dist/protocol/operation-response.guard.d.ts +2 -2
  137. package/dist/protocol/protocol-surface.d.ts +4 -4
  138. package/dist/protocol/protocol.binder.d.ts +50 -27
  139. package/dist/protocol/protocol.binder.js +12 -9
  140. package/dist/protocol/protocol.handler.d.ts +22 -13
  141. package/dist/protocol/protocol.handler.js +91 -17
  142. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  143. package/dist/protocol/unmounted-route.error.js +2 -2
  144. package/dist/runtime/caller-data.copier.d.ts +22 -5
  145. package/dist/runtime/caller-data.copier.js +31 -14
  146. package/dist/runtime/caller-data.door.d.ts +17 -11
  147. package/dist/runtime/caller-data.door.js +6 -4
  148. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  149. package/dist/runtime/computed-read-runtime.js +76 -50
  150. package/dist/runtime/computed-value.error.d.ts +7 -6
  151. package/dist/runtime/computed-value.error.js +5 -4
  152. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  153. package/dist/runtime/context-executor.runtime.js +275 -0
  154. package/dist/runtime/create-requirement.d.ts +44 -79
  155. package/dist/runtime/create-requirement.js +213 -73
  156. package/dist/runtime/decimal.d.ts +2 -2
  157. package/dist/runtime/decimal.js +1 -1
  158. package/dist/runtime/diagnostics-reporter.d.ts +54 -27
  159. package/dist/runtime/diagnostics-reporter.js +24 -0
  160. package/dist/runtime/error-boundary.d.ts +65 -8
  161. package/dist/runtime/error-boundary.js +49 -19
  162. package/dist/runtime/error-guidance.d.ts +12 -0
  163. package/dist/runtime/error-guidance.js +1 -0
  164. package/dist/runtime/error.catalog.d.ts +49 -0
  165. package/dist/runtime/error.catalog.js +49 -0
  166. package/dist/runtime/execution-options.d.ts +10 -2
  167. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  168. package/dist/runtime/field-check.evaluator.js +521 -0
  169. package/dist/runtime/field-compute.d.ts +64 -0
  170. package/dist/runtime/field-compute.js +1 -0
  171. package/dist/runtime/field-stage.plan.d.ts +15 -0
  172. package/dist/runtime/field-stage.plan.js +27 -0
  173. package/dist/runtime/field-stage.runtime.d.ts +37 -0
  174. package/dist/runtime/field-stage.runtime.js +147 -0
  175. package/dist/runtime/field-validator.runtime.d.ts +19 -0
  176. package/dist/runtime/field-validator.runtime.js +92 -0
  177. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  178. package/dist/runtime/framework-error-class.table.js +25 -0
  179. package/dist/runtime/framework-error.d.ts +68 -8
  180. package/dist/runtime/framework-error.factory.d.ts +4 -0
  181. package/dist/runtime/framework-error.factory.js +15 -0
  182. package/dist/runtime/framework-error.js +23 -2
  183. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  184. package/dist/runtime/interceptor-next.error.js +6 -0
  185. package/dist/runtime/json-value.d.ts +11 -6
  186. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  187. package/dist/runtime/level-lifecycle.runtime.js +39 -0
  188. package/dist/runtime/misuse-reporter.d.ts +12 -12
  189. package/dist/runtime/mutation-planner.d.ts +19 -10
  190. package/dist/runtime/mutation-planner.js +48 -35
  191. package/dist/runtime/nested-write.walker.d.ts +32 -0
  192. package/dist/runtime/nested-write.walker.js +73 -0
  193. package/dist/runtime/operation-code.guidance.d.ts +6 -0
  194. package/dist/runtime/operation-code.guidance.js +167 -0
  195. package/dist/runtime/operation-request.d.ts +33 -6
  196. package/dist/runtime/operation-response.d.ts +17 -17
  197. package/dist/runtime/operation-runtime.d.ts +127 -25
  198. package/dist/runtime/operation-runtime.js +441 -78
  199. package/dist/runtime/outcome-mapper.d.ts +16 -5
  200. package/dist/runtime/outcome-mapper.js +23 -6
  201. package/dist/runtime/output-validator.d.ts +10 -10
  202. package/dist/runtime/output-validator.js +3 -3
  203. package/dist/runtime/owned-execution.registry.d.ts +16 -6
  204. package/dist/runtime/pipe-output.validator.d.ts +43 -18
  205. package/dist/runtime/pipe-output.validator.js +15 -13
  206. package/dist/runtime/pipeline.d.ts +223 -34
  207. package/dist/runtime/readonly-value.d.ts +43 -0
  208. package/dist/runtime/readonly-value.js +150 -0
  209. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  210. package/dist/runtime/request-envelope.validator.js +12 -7
  211. package/dist/runtime/request-id.d.ts +1 -1
  212. package/dist/runtime/request-state.d.ts +14 -0
  213. package/dist/runtime/request-state.js +1 -0
  214. package/dist/runtime/request-state.resolver.d.ts +12 -0
  215. package/dist/runtime/request-state.resolver.js +20 -0
  216. package/dist/runtime/scalar-runtime.d.ts +35 -16
  217. package/dist/runtime/scalar-runtime.js +102 -34
  218. package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
  219. package/dist/runtime/unsent-value.normalizer.js +128 -0
  220. package/dist/transactions/deferred-operation.d.ts +35 -20
  221. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  222. package/dist/transactions/operation-arguments-encoder.js +2 -2
  223. package/dist/transactions/operation-fingerprint.js +2 -2
  224. package/dist/transactions/sql-statement.d.ts +85 -0
  225. package/dist/transactions/sql-statement.js +47 -0
  226. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  227. package/dist/transactions/sql-statement.validator.js +167 -0
  228. package/dist/transactions/transaction-envelope.d.ts +4 -4
  229. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  230. package/dist/transactions/transaction-integrity-error.js +5 -2
  231. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  232. package/dist/transactions/transaction-plan-assembler.js +169 -32
  233. package/dist/transactions/transaction-plan-validator.d.ts +45 -20
  234. package/dist/transactions/transaction-plan-validator.js +96 -38
  235. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  236. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  237. package/dist/transactions/transaction-reference-resolver.js +26 -14
  238. package/dist/transactions/transaction-reference-validator.d.ts +76 -4
  239. package/dist/transactions/transaction-reference-validator.js +129 -71
  240. package/dist/transactions/transaction-reference.d.ts +13 -13
  241. package/dist/transactions/transaction-reference.js +5 -0
  242. package/dist/transactions/transaction-request.d.ts +18 -5
  243. package/dist/transactions/transaction-response.d.ts +6 -6
  244. package/dist/transactions/transaction-runtime.d.ts +8 -7
  245. package/dist/transactions/transaction-runtime.js +191 -50
  246. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  247. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  248. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  249. package/dist/transactions/transaction-slot-path-error.js +2 -2
  250. package/dist/transactions/transaction-slot-writer.js +2 -2
  251. package/dist/transactions/transaction-stage.runtime.d.ts +82 -0
  252. package/dist/transactions/transaction-stage.runtime.js +126 -0
  253. package/package.json +9 -7
  254. package/src/runtime/field-check.evaluator.ts +720 -0
  255. package/dist/config/define-fields.d.ts +0 -42
  256. package/dist/config/define-fields.js +0 -3
  257. package/dist/config/framework-behaviors-config.d.ts +0 -30
  258. package/dist/config/framework-fields-config.d.ts +0 -42
  259. package/dist/config/framework-restrictions-config.d.ts +0 -142
  260. package/dist/json/avz.d.ts +0 -96
  261. package/dist/runtime/field-behavior.d.ts +0 -48
  262. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  263. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  264. /package/dist/{json → avz}/index.js +0 -0
  265. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  266. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  267. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,28 +1,41 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { FrameworkContracts } from "../compiler/contract.compiler.js";
3
- import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvContracts } from "../compiler/contract.compiler.js";
3
+ import type { AvConfigAny } from "../config/any-framework-config.js";
4
+ import type { AvMcpEndpoint } from "../config/config.resolver.js";
4
5
  import type { FrameworkOperationRequest } from "../runtime/operation-request.js";
5
- import type { OperationResponse } from "../runtime/operation-response.js";
6
- import type { TransactionRunner } from "../transactions/deferred-operation.js";
6
+ import type { AvOperationResponse } from "../runtime/operation-response.js";
7
+ import type { AvTransactionRunner } from "../transactions/deferred-operation.js";
7
8
  import type { FrameworkTransactionRequest } from "../transactions/transaction-request.js";
8
- import type { TransactionResponse } from "../transactions/transaction-response.js";
9
+ import type { AvTransactionResponse } from "../transactions/transaction-response.js";
9
10
  import type { ApplicationOperations, ApplicationTransactionBuilders, ClientOperations, ClientTransactionBuilders } from "./operation-facade.js";
10
11
  /**
11
12
  * One Aventara instance, as returned by {@link createFramework}: its compiled
12
13
  * Contracts, typed in-process operations, transaction builders and the
13
14
  * untyped `execute` entry a transport calls.
14
15
  */
15
- export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig> = {
16
- readonly entrypoint: string;
17
- readonly contracts: FrameworkContracts;
16
+ export type AvFramework<M extends AvAdapterModel = AvAdapterModel, Cfg = AvConfigAny> = {
17
+ /**
18
+ * The protocol's mount path (`api`) in its canonical form: `""` at the
19
+ * root, otherwise `/seg(/seg)*`.
20
+ */
21
+ readonly api: string;
22
+ /**
23
+ * The MCP endpoint `mcp` turns on — its canonical mount path and its
24
+ * authorization — for the host that serves it; `undefined` when MCP is off.
25
+ */
26
+ readonly mcp: AvMcpEndpoint | undefined;
27
+ readonly contracts: AvContracts;
18
28
  /**
19
29
  * Typed in-process operations under the Application Contract:
20
30
  * `framework.application.<resource>.<family>.<variant>(args, options?)`.
21
31
  *
22
32
  * Typed from the Application Contract as configured: what the application's
23
- * restrictions hide, deny or turn off is absent from the types, and a call is
24
- * validated like any other request. The optional second argument is
25
- * {@link ExecutionOptions}.
33
+ * exposure hides, denies or turns off is absent from the types, and a call is
34
+ * validated like any other request. A call resolves the operation's data (a
35
+ * first-style miss is `null`) and throws every failure as the `AvError`
36
+ * subclass of its code's class (`AvValidationError`, `AvNotFoundError`, …).
37
+ * The optional second argument is
38
+ * {@link AvExecutionOptions}.
26
39
  */
27
40
  readonly application: ApplicationOperations<M, Cfg>;
28
41
  /**
@@ -33,25 +46,33 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
33
46
  * as from a generated client, and arguments are read in the wire
34
47
  * forms a decoded request body carries, so a transport can pass `req.body` as
35
48
  * it is. Each call runs the client pipelines and the same validation as a
36
- * remote request.
49
+ * remote request, and settles like an application call: the data, or the
50
+ * failure thrown.
37
51
  */
38
52
  readonly client: ClientOperations<M, Cfg>;
39
53
  /**
40
54
  * Transaction builders under application rules:
41
55
  * `framework.appTx.<resource>.<family>.<variant>(args)` defers one operation
42
- * into a handle typed `Operation<OperationResultFor<…>>` from the Application
56
+ * into a handle typed `AvOperation<AvOperationResultFor<…>>` from the Application
43
57
  * Contract's view, and runs nothing. A handle exposes `$ref(field)` exactly
44
58
  * where its result is one row; the reference is bound to the handle, and its
45
59
  * index is bound when {@link transaction} runs the list it is in.
60
+ *
61
+ * `framework.appTx.$sql` defers a developer SQL step, written only as a tagged
62
+ * template whose every interpolated value is bound as a parameter (a `$ref`
63
+ * among them, resolved when the earlier steps have run). It runs in plan order
64
+ * in the same database transaction, with no pipelines around it; its entry in
65
+ * the committed data is its rows, typed by `appTx.$sql<Row>`. It exists only
66
+ * here: `clientTx`, the Client Contract and `/_transactions` have no SQL step.
46
67
  */
47
68
  readonly appTx: ApplicationTransactionBuilders<M, Cfg>;
48
69
  /**
49
70
  * The same builders under ClientContract rules, taking wire-form arguments.
50
- * Client and application handles may share one {@link transaction}; each step
51
- * runs under its own handle's rules.
71
+ * A {@link transaction} has one origin: client and application handles never
72
+ * share one (`A2004`/`V1020` at the first step of the other origin).
52
73
  */
53
74
  readonly clientTx: ClientTransactionBuilders<M, Cfg>;
54
- execute(request: FrameworkOperationRequest): Promise<OperationResponse>;
75
+ execute(request: FrameworkOperationRequest): Promise<AvOperationResponse>;
55
76
  /**
56
77
  * Validates a whole transaction plan, then runs its operations one after
57
78
  * another inside one Adapter transaction. Answers `A1009` with each
@@ -62,15 +83,18 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
62
83
  * Guards, pipes, hooks and interceptors run while the transaction is open, so
63
84
  * they should not perform network I/O or other slow work.
64
85
  */
65
- executeTransaction(request: FrameworkTransactionRequest): Promise<TransactionResponse>;
86
+ executeTransaction(request: FrameworkTransactionRequest): Promise<AvTransactionResponse>;
66
87
  /**
67
88
  * Runs handles from `appTx`/`clientTx` as one transaction:
68
- * `framework.transaction([h1, h2, …], options?)`. Resolves the committed
69
- * response, typed per position, or the failure response. Never rejects.
89
+ * `framework.transaction([h1, h2, …], options?)`. Resolves each handle's
90
+ * result in plan order, typed per position, once the transaction committed,
91
+ * or throws the failure as the `AvError` subclass of its code's class, with
92
+ * `cause.operation` naming the failing step.
70
93
  *
71
94
  * Refused before anything runs: an entry that is not one of this Framework's
72
- * handles, or the same handle twice (`A2004`/`V1001`); a `$ref` to a handle
73
- * not in the list (`A2007`/`V1010`).
95
+ * handles, or the same handle twice (`A2004`/`V1001`); `appTx` and `clientTx`
96
+ * handles in one list (`A2004`/`V1020`); a `$ref` to a handle not in the list
97
+ * (`A2007`/`V1010`).
74
98
  */
75
- readonly transaction: TransactionRunner;
99
+ readonly transaction: AvTransactionRunner;
76
100
  };
@@ -1,11 +1,13 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
3
- import type { FrameworkConfig } from "../config/framework-config.js";
4
- import type { Framework } from "./framework.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvConfigAny } from "../config/any-framework-config.js";
3
+ import type { AvConfigExact } from "../config/exact-framework-config.js";
4
+ import type { AvConfig } from "../config/framework-config.js";
5
+ import type { ErasedConfig } from "../config/stage-type.eraser.js";
6
+ import type { AvFramework } from "./framework.js";
5
7
  /**
6
8
  * Creates a Framework: validates the configuration, reads the adapter's
7
9
  * model and compiles the Contracts.
8
10
  *
9
- * @throws {@link FrameworkConstructionError} when any of those steps fails.
11
+ * @throws {@link AvConstructionError} when any of those steps fails.
10
12
  */
11
- export declare function createFramework<M extends AdapterModel, const Cfg = AnyFrameworkConfig>(config: Cfg & FrameworkConfig<M, Cfg>): Promise<Framework<M, Cfg>>;
13
+ export declare function createFramework<M extends AvAdapterModel, const Cfg = AvConfigAny>(config: Cfg & AvConfigExact<M, Cfg> & AvConfig<M, Cfg>): Promise<AvFramework<M, ErasedConfig<Cfg>>>;
@@ -1,28 +1,32 @@
1
1
  import { compileContracts } from "../compiler/contract.compiler.js";
2
+ import { computedFieldsOf, warnOnStaleComputedFields, } from "../config/computed-fields.js";
2
3
  import { resolveFrameworkConfig } from "../config/config.resolver.js";
3
4
  import { validateFrameworkConfig } from "../config/config.validator.js";
5
+ import { validateForcedOperations } from "../config/forced-operation.validator.js";
4
6
  import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
5
7
  import { copyEnvelopeAtDoor, refuseCallerData, } from "../runtime/caller-data.door.js";
6
8
  import { createDiagnosticsReporter, createTransactionDiagnosticsChannel, recordDiagnosticsSink, } from "../runtime/diagnostics-reporter.js";
7
9
  import { createMisuseReporter, } from "../runtime/misuse-reporter.js";
8
10
  import { internalFailure, operationFailure, } from "../runtime/operation-response.js";
9
- import { createOperationRuntime } from "../runtime/operation-runtime.js";
11
+ import { createOperationRuntime, createPipelineDependencies, } from "../runtime/operation-runtime.js";
10
12
  import { recordOwnedExecution } from "../runtime/owned-execution.registry.js";
11
13
  import { validateOperationEnvelope, validateTransactionEnvelope, } from "../runtime/request-envelope.validator.js";
12
14
  import { requestIdOf } from "../runtime/request-id.js";
15
+ import { stateOptionOf } from "../runtime/request-state.resolver.js";
13
16
  import { createTransactionPlanAssembler } from "../transactions/transaction-plan-assembler.js";
14
17
  import { createTransactionRuntime } from "../transactions/transaction-runtime.js";
15
- import { FrameworkConstructionError } from "./framework-construction.error.js";
16
- import { createOperationFacade, createOperationTree, } from "./operation-facade.js";
18
+ import { AvConstructionError } from "./framework-construction.error.js";
19
+ import { createOperationFacade, createOperationTree, settleOperation, } from "./operation-facade.js";
20
+ const APPLICATION_SQL_BUILDER = "$sql";
17
21
  export async function createFramework(config) {
18
22
  const configDiagnostics = validateFrameworkConfig(config);
19
23
  if (configDiagnostics.length > 0) {
20
- throw new FrameworkConstructionError("configuration", configDiagnostics);
24
+ throw new AvConstructionError("configuration", configDiagnostics);
21
25
  }
22
26
  const model = config.adapter.model;
23
27
  if (model.transactions === "interactive" &&
24
28
  typeof config.adapter.transaction !== "function") {
25
- throw new FrameworkConstructionError("discovery", [
29
+ throw new AvConstructionError("discovery", [
26
30
  {
27
31
  code: "DISCOVERY_TRANSACTION_CAPABILITY_MISMATCH",
28
32
  path: "adapter.transactions",
@@ -31,20 +35,26 @@ export async function createFramework(config) {
31
35
  ]);
32
36
  }
33
37
  const resolvedConfig = resolveFrameworkConfig(config);
38
+ warnOnStaleComputedFields(config.adapter.computedFields, computedFieldsOf({
39
+ trees: resolvedConfig.trees,
40
+ agentExtends: resolvedConfig.agent.parent,
41
+ }));
34
42
  const compilation = await compileContracts(model, resolvedConfig);
35
43
  if (!compilation.ok) {
36
- throw new FrameworkConstructionError("contract-compilation", compilation.diagnostics);
44
+ throw new AvConstructionError("contract-compilation", compilation.diagnostics);
37
45
  }
38
- const execute = createOperationRuntime({
39
- adapter: config.adapter,
40
- contracts: compilation.contracts,
41
- config: resolvedConfig,
42
- });
43
- const executeTransaction = createTransactionRuntime({
46
+ const forcing = validateForcedOperations(config, compilation.contracts);
47
+ if (forcing.length > 0) {
48
+ throw new AvConstructionError("configuration", forcing);
49
+ }
50
+ const runtimeDependencies = {
44
51
  adapter: config.adapter,
45
52
  contracts: compilation.contracts,
46
53
  config: resolvedConfig,
47
- });
54
+ };
55
+ const pipelineDependencies = createPipelineDependencies(runtimeDependencies, model);
56
+ const execute = createOperationRuntime(runtimeDependencies, pipelineDependencies);
57
+ const executeTransaction = createTransactionRuntime(runtimeDependencies, pipelineDependencies);
48
58
  const misuse = createMisuseReporter(resolvedConfig.misuse);
49
59
  const executeOperation = (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "caller");
50
60
  const protocol = {
@@ -53,33 +63,41 @@ export async function createFramework(config) {
53
63
  };
54
64
  const assembler = createTransactionPlanAssembler(compilation.contracts, protocol, misuse);
55
65
  const framework = {
56
- entrypoint: resolvedConfig.entrypoint,
66
+ api: resolvedConfig.api,
67
+ mcp: resolvedConfig.mcp,
57
68
  contracts: compilation.contracts,
58
- application: createOperationFacade(model, (resource, identity, args, requestId) => ({
69
+ application: createOperationFacade(model, (resource, identity, args, requestId, state) => ({
59
70
  ...identity,
60
71
  origin: "application",
61
72
  requestId,
73
+ ...(state === undefined ? {} : { state }),
62
74
  resource,
63
75
  arguments: args,
64
76
  }), executeOperation),
65
- client: createOperationFacade(model, (resource, identity, args, requestId) => ({
77
+ client: createOperationFacade(model, (resource, identity, args, requestId, state) => ({
66
78
  ...identity,
67
79
  origin: "client",
68
80
  protocol,
69
81
  requestId,
82
+ ...(state === undefined ? {} : { state }),
70
83
  resource,
71
84
  arguments: args,
72
85
  }), executeOperation),
73
- appTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("application", resource, identity, args === undefined ? {} : args)),
86
+ appTx: Object.freeze({
87
+ ...createOperationTree(model, (resource, identity) => (args) => assembler.defer("application", resource, identity, args === undefined ? {} : args)),
88
+ [APPLICATION_SQL_BUILDER]: (strings, ...values) => assembler.deferSql(strings, values),
89
+ }),
74
90
  clientTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("client", resource, identity, args === undefined ? {} : args)),
75
91
  execute: (request) => executeRequestTotally(execute, request, resolvedConfig.diagnostics, misuse),
76
92
  executeTransaction: (request) => executeTransactionRequestTotally(executeTransaction, request, resolvedConfig.diagnostics, misuse),
77
- transaction: ((operations, options) => runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), resolvedConfig.diagnostics)),
93
+ transaction: (async (operations, options) => settleOperation(await runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), stateOptionOf(options), resolvedConfig.diagnostics))),
78
94
  };
79
95
  recordDiagnosticsSink(framework, resolvedConfig.diagnostics);
80
96
  recordOwnedExecution(framework, {
81
- execute: (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "owned"),
82
- executeTransaction: (request) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics, undefined, { source: "owned" }),
97
+ execute: (request, refused) => executeTotally(execute, request, resolvedConfig.diagnostics, refused === undefined ? "owned" : { refused }),
98
+ executeTransaction: (request, refused) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics, undefined, refused === undefined
99
+ ? { source: "owned" }
100
+ : { source: "owned", refused }),
83
101
  });
84
102
  return framework;
85
103
  }
@@ -138,7 +156,7 @@ async function executeTransactionTotally(execute, request, diagnostics, origins,
138
156
  return internalFailure();
139
157
  }
140
158
  }
141
- async function runTransactionTotally(execute, assembler, operations, requestId, diagnostics) {
159
+ async function runTransactionTotally(execute, assembler, operations, requestId, state, diagnostics) {
142
160
  let assembled;
143
161
  try {
144
162
  assembled = await assembler.assemble(operations);
@@ -154,5 +172,14 @@ async function runTransactionTotally(execute, assembler, operations, requestId,
154
172
  if (!assembled.ok) {
155
173
  return assembled.response;
156
174
  }
157
- return executeTransactionTotally(execute, { origin: "application", requestId, plan: assembled.plan }, diagnostics, assembled.origins, { source: "owned", refused: assembled.refused });
175
+ return executeTransactionTotally(execute, {
176
+ origin: "application",
177
+ requestId,
178
+ ...(state === undefined ? {} : { state }),
179
+ plan: assembled.plan,
180
+ }, diagnostics, assembled.origins, {
181
+ source: "owned",
182
+ refused: assembled.refused,
183
+ statements: assembled.statements,
184
+ });
158
185
  }
@@ -1,72 +1,137 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { Contract } from "../contracts/contract.js";
3
- import type { ApplicationScalarForms, WireScalarForms } from "../contracts/scalar-value-type.js";
4
- import type { ResourceKey } from "../operations/operation-arguments.js";
5
- import type { DeferredOperationCall, OperationCall, OperationGrammar } from "../operations/operation-call.js";
6
- import type { OperationIdentity } from "../operations/operation-identity.js";
7
- import type { ExecutionOptions } from "../runtime/execution-options.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvContract } from "../contracts/contract.js";
3
+ import type { AvApplicationScalarForms, AvWireScalarForms } from "../contracts/scalar-value-type.js";
4
+ import type { AvResourceKey } from "../operations/operation-arguments.js";
5
+ import type { AvDeferredOperationCall, AvOperationCall, AvOperationGrammar } from "../operations/operation-call.js";
6
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
7
+ import type { AvExecutionOptions } from "../runtime/execution-options.js";
8
8
  import type { FrameworkOperationRequest } from "../runtime/operation-request.js";
9
- import type { OperationResponse } from "../runtime/operation-response.js";
10
- import type { ApplicationContractView, ClientContractView } from "./contract-view.js";
9
+ import type { AvOperationResponse } from "../runtime/operation-response.js";
10
+ import type { AvState } from "../runtime/request-state.js";
11
+ import type { SqlStatementBuilder } from "../transactions/sql-statement.js";
12
+ import type { AvTransactionResponse } from "../transactions/transaction-response.js";
13
+ import type { AvContractApplicationView, ClientContractView } from "./contract-view.js";
11
14
  /**
12
- * A model whose Resource names are not literal — the abstract `AdapterModel` behind
13
- * the default `Framework` — has no Contract to type a call against, so a surface over
15
+ * A model whose Resource names are not literal — the abstract `AvAdapterModel` behind
16
+ * the default `AvFramework` — has no Contract to type a call against, so a surface over
14
17
  * it is typed as the opaque object it is, and such a caller uses `execute`.
15
18
  */
16
19
  type OpaqueSurface = {
17
20
  readonly [resource: string]: unknown;
18
21
  };
22
+ /** The four typed surfaces of an `AvFramework`, named by the member that holds each. */
23
+ type FacadeSurface = "application" | "client" | "appTx" | "clientTx";
19
24
  /**
20
- * `framework.application`: one call per operation the Application Contract's
21
- * view advertises, its arguments in the application forms.
25
+ * One variant on a surface: a direct call (application or wire forms), or a
26
+ * deferred one for a transaction (`appTx`, `clientTx`).
22
27
  */
23
- export type ApplicationOperations<M extends AdapterModel, Cfg> = ApplicationFacade<ApplicationContractView<M, Cfg>>;
24
- type ApplicationFacade<C> = C extends Contract ? string extends ResourceKey<C> ? OpaqueSurface : {
25
- readonly [R in ResourceKey<C>]: {
26
- readonly [F in keyof OperationGrammar<C>[R]]: {
27
- readonly [V in keyof OperationGrammar<C>[R][F]]: OperationCall<C, R, OperationGrammar<C>[R][F][V] & OperationIdentity, ApplicationScalarForms, ApplicationScalarForms, "response", ExecutionOptions>;
28
- };
29
- };
30
- } : never;
28
+ type SurfaceCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, S extends FacadeSurface> = S extends "application" ? AvOperationCall<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms, AvExecutionOptions> : S extends "client" ? AvOperationCall<C, R, I, AvWireScalarForms, AvApplicationScalarForms, AvExecutionOptions> : S extends "appTx" ? AvDeferredOperationCall<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms, "application"> : AvDeferredOperationCall<C, R, I, AvWireScalarForms, AvApplicationScalarForms, "client">;
29
+ /** The families view `C` advertises on Resource `R`. */
30
+ type FamilyKey<C extends AvContract, R extends AvResourceKey<C>> = keyof AvOperationGrammar<C>[R];
31
+ /** One family node of surface `S`; the public names below are its four instances. */
32
+ type FamilyNode<C extends AvContract, S extends FacadeSurface, R extends AvResourceKey<C>, F extends FamilyKey<C, R>> = {
33
+ readonly [V in keyof AvOperationGrammar<C>[R][F]]: SurfaceCall<C, R, AvOperationGrammar<C>[R][F][V] & AvOperationIdentity, S>;
34
+ };
35
+ /** `framework.application.<Resource>.<family>`: one direct call per variant, application forms. */
36
+ export type AvApplicationFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "application", R, F>;
37
+ /** `framework.client.<Resource>.<family>`: one direct call per variant, wire forms. */
38
+ export type AvClientFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "client", R, F>;
39
+ /** `framework.appTx.<Resource>.<family>`: one deferred operation per variant. */
40
+ export type AvAppTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "appTx", R, F>;
41
+ /** `framework.clientTx.<Resource>.<family>`: one deferred operation per variant. */
42
+ export type AvClientTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "clientTx", R, F>;
43
+ /** `framework.application.<Resource>`: one {@link AvApplicationFamilyFacade} per family. */
44
+ export type AvApplicationResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
45
+ readonly [F in FamilyKey<C, R>]: AvApplicationFamilyFacade<C, R, F>;
46
+ };
47
+ /** `framework.client.<Resource>`: one {@link AvClientFamilyFacade} per family. */
48
+ export type AvClientResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
49
+ readonly [F in FamilyKey<C, R>]: AvClientFamilyFacade<C, R, F>;
50
+ };
51
+ /** `framework.appTx.<Resource>`: one {@link AvAppTxFamilyFacade} per family. */
52
+ export type AvAppTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
53
+ readonly [F in FamilyKey<C, R>]: AvAppTxFamilyFacade<C, R, F>;
54
+ };
55
+ /** `framework.clientTx.<Resource>`: one {@link AvClientTxFamilyFacade} per family. */
56
+ export type AvClientTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
57
+ readonly [F in FamilyKey<C, R>]: AvClientTxFamilyFacade<C, R, F>;
58
+ };
31
59
  /**
32
- * `framework.client`: the same over the Client Contract's view, its arguments in
33
- * the wire forms.
60
+ * `framework.application`: one {@link AvApplicationResourceFacade} per Resource
61
+ * of `C`, the Application Contract's view.
34
62
  */
35
- export type ClientOperations<M extends AdapterModel, Cfg> = ClientFacade<ClientContractView<M, Cfg>>;
36
- type ClientFacade<C> = C extends Contract ? string extends ResourceKey<C> ? OpaqueSurface : {
37
- readonly [R in ResourceKey<C>]: {
38
- readonly [F in keyof OperationGrammar<C>[R]]: {
39
- readonly [V in keyof OperationGrammar<C>[R][F]]: OperationCall<C, R, OperationGrammar<C>[R][F][V] & OperationIdentity, WireScalarForms, ApplicationScalarForms, "response", ExecutionOptions>;
40
- };
41
- };
42
- } : never;
63
+ export type AvApplicationFacade<C extends AvContract> = {
64
+ readonly [R in AvResourceKey<C>]: AvApplicationResourceFacade<C, R>;
65
+ };
43
66
  /**
44
- * `framework.appTx`: one deferred operation per operation the Application
45
- * Contract's view advertises — application rules, application forms.
67
+ * `framework.client`: one {@link AvClientResourceFacade} per Resource of `C`,
68
+ * the Client Contract's view.
46
69
  */
47
- export type ApplicationTransactionBuilders<M extends AdapterModel, Cfg> = ApplicationDeferredSurface<ApplicationContractView<M, Cfg>>;
48
- type ApplicationDeferredSurface<C> = C extends Contract ? string extends ResourceKey<C> ? OpaqueSurface : {
49
- readonly [R in ResourceKey<C>]: {
50
- readonly [F in keyof OperationGrammar<C>[R]]: {
51
- readonly [V in keyof OperationGrammar<C>[R][F]]: DeferredOperationCall<C, R, OperationGrammar<C>[R][F][V] & OperationIdentity, ApplicationScalarForms, ApplicationScalarForms>;
70
+ export type AvClientFacade<C extends AvContract> = {
71
+ readonly [R in AvResourceKey<C>]: AvClientResourceFacade<C, R>;
72
+ };
73
+ /** `framework.appTx.$sql`: the developer SQL step only an application transaction has. */
74
+ type ApplicationSqlStep = {
75
+ /**
76
+ * A developer SQL step, written only as a tagged template:
77
+ * ``framework.appTx.$sql<Row>`select … ${value}` ``. Every interpolated value
78
+ * is bound as a parameter. See {@link SqlStatementBuilder}.
79
+ */
80
+ readonly $sql: SqlStatementBuilder;
81
+ };
82
+ /**
83
+ * `framework.appTx`: one {@link AvAppTxResourceFacade} per Resource of `C`, the
84
+ * Application Contract's view, and `$sql`.
85
+ */
86
+ export type AvAppTxFacade<C extends AvContract> = {
87
+ readonly [R in AvResourceKey<C>]: AvAppTxResourceFacade<C, R>;
88
+ } & ApplicationSqlStep;
89
+ /**
90
+ * `framework.clientTx`: one {@link AvClientTxResourceFacade} per Resource of
91
+ * `C`, the Client Contract's view.
92
+ */
93
+ export type AvClientTxFacade<C extends AvContract> = {
94
+ readonly [R in AvResourceKey<C>]: AvClientTxResourceFacade<C, R>;
95
+ };
96
+ type ApplicationSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvApplicationFacade<C> : never;
97
+ type ClientSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvClientFacade<C> : never;
98
+ type ApplicationDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface & ApplicationSqlStep : AvAppTxFacade<C> : never;
99
+ type ClientDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvClientTxFacade<C> : never;
100
+ /** `framework.application`'s type: {@link AvApplicationFacade}, or opaque. */
101
+ export type ApplicationOperations<M extends AvAdapterModel, Cfg> = ApplicationSurface<AvContractApplicationView<M, Cfg>>;
102
+ /** `framework.client`'s type: {@link AvClientFacade}, or opaque. */
103
+ export type ClientOperations<M extends AvAdapterModel, Cfg> = ClientSurface<ClientContractView<M, Cfg>>;
104
+ /** `framework.appTx`'s type: {@link AvAppTxFacade}, or opaque with `$sql`. */
105
+ export type ApplicationTransactionBuilders<M extends AvAdapterModel, Cfg> = ApplicationDeferredSurface<AvContractApplicationView<M, Cfg>>;
106
+ /** `framework.clientTx`'s type: {@link AvClientTxFacade}, or opaque. */
107
+ export type ClientTransactionBuilders<M extends AvAdapterModel, Cfg> = ClientDeferredSurface<ClientContractView<M, Cfg>>;
108
+ /**
109
+ * The Resources of a pipeline ctx: `ctx.<Resource>.<family>.<variant>(args)`,
110
+ * application-origin, resolving the operation's data.
111
+ */
112
+ export type AvContextOperations<M extends AvAdapterModel> = ContextFacade<AvContractApplicationView<M>>;
113
+ type ContextFacade<C> = C extends AvContract ? string extends AvResourceKey<C> ? unknown : {
114
+ readonly [R in AvResourceKey<C>]: {
115
+ readonly [F in keyof AvOperationGrammar<C>[R]]: {
116
+ readonly [V in keyof AvOperationGrammar<C>[R][F]]: AvOperationCall<C, R, AvOperationGrammar<C>[R][F][V] & AvOperationIdentity, AvApplicationScalarForms, AvApplicationScalarForms, never>;
52
117
  };
53
118
  };
54
119
  } : never;
55
120
  /**
56
- * `framework.clientTx`: the same over the Client Contract's view — ClientContract
57
- * rules, wire forms.
121
+ * The Resources of compute's read-only ctx: `ctx.<Resource>.find.<variant>(args)`
122
+ * only (`find.count` included).
58
123
  */
59
- export type ClientTransactionBuilders<M extends AdapterModel, Cfg> = ClientDeferredSurface<ClientContractView<M, Cfg>>;
60
- type ClientDeferredSurface<C> = C extends Contract ? string extends ResourceKey<C> ? OpaqueSurface : {
61
- readonly [R in ResourceKey<C>]: {
62
- readonly [F in keyof OperationGrammar<C>[R]]: {
63
- readonly [V in keyof OperationGrammar<C>[R][F]]: DeferredOperationCall<C, R, OperationGrammar<C>[R][F][V] & OperationIdentity, WireScalarForms, ApplicationScalarForms>;
124
+ export type AvComputeReads<M extends AvAdapterModel> = ComputeReadFacade<AvContractApplicationView<M>>;
125
+ type ComputeReadFacade<C> = C extends AvContract ? string extends AvResourceKey<C> ? unknown : {
126
+ readonly [R in AvResourceKey<C>]: {
127
+ readonly [F in Extract<keyof AvOperationGrammar<C>[R], "find">]: {
128
+ readonly [V in keyof AvOperationGrammar<C>[R][F]]: AvOperationCall<C, R, AvOperationGrammar<C>[R][F][V] & AvOperationIdentity, AvApplicationScalarForms, AvApplicationScalarForms, never>;
64
129
  };
65
130
  };
66
131
  } : never;
67
- /** Builds the request one façade call hands to `execute`, under its request id. */
68
- export type FacadeRequest = (resource: string, identity: OperationIdentity, args: unknown, requestId: string) => FrameworkOperationRequest;
69
- type FacadeExecutor = (request: FrameworkOperationRequest) => Promise<OperationResponse>;
132
+ /** Builds the request one façade call hands to `execute`, under its request id and state. */
133
+ export type FacadeRequest = (resource: string, identity: AvOperationIdentity, args: unknown, requestId: string, state: AvState | undefined) => FrameworkOperationRequest;
134
+ type FacadeExecutor = (request: FrameworkOperationRequest) => Promise<AvOperationResponse>;
70
135
  /**
71
136
  * Builds a façade over `model`, the same object its types are read from, so a
72
137
  * call that type-checks always reaches `execute`: a Resource, variant or field
@@ -74,20 +139,26 @@ type FacadeExecutor = (request: FrameworkOperationRequest) => Promise<OperationR
74
139
  * validation layer answers it.
75
140
  *
76
141
  * Each call's request is `request`'s — its origin — under the caller's
77
- * `ExecutionOptions.requestId`, or a freshly minted id when there is none; an
142
+ * `AvExecutionOptions.requestId`, or a freshly minted id when there is none, and
143
+ * with the caller's `AvExecutionOptions.state` when it gives one; an
78
144
  * omitted argument is the empty argument object, which the type admits only
79
145
  * when every member is optional.
80
146
  */
81
- export declare function createOperationFacade<Facade>(model: AdapterModel, request: FacadeRequest, execute: FacadeExecutor): Facade;
147
+ export declare function createOperationFacade<Facade>(model: AvAdapterModel, request: FacadeRequest, execute: FacadeExecutor): Facade;
148
+ /**
149
+ * An in-process call's settlement (a façade call or `framework.transaction`):
150
+ * the response's data, or its failure thrown.
151
+ */
152
+ export declare function settleOperation(response: AvOperationResponse | AvTransactionResponse): unknown;
82
153
  /**
83
154
  * One leaf of an operation tree: the callable for one advertised variant. The
84
155
  * second parameter is a façade call's options; a builder leaf ignores it.
85
156
  */
86
- export type OperationLeaf = (resource: string, identity: OperationIdentity) => (args?: unknown, options?: unknown) => unknown;
157
+ export type OperationLeaf = (resource: string, identity: AvOperationIdentity) => (args?: unknown, options?: unknown) => unknown;
87
158
  /**
88
159
  * The runtime shape every façade and builder shares: one frozen property per
89
160
  * Resource of `model`, one per family under it, one leaf per variant the model
90
161
  * advertises in the standard grammar.
91
162
  */
92
- export declare function createOperationTree<Tree>(model: AdapterModel, leaf: OperationLeaf): Tree;
163
+ export declare function createOperationTree<Tree>(model: AvAdapterModel, leaf: OperationLeaf): Tree;
93
164
  export {};
@@ -1,8 +1,16 @@
1
1
  import { isOperationVariantAvailable } from "../contracts/resource-operations.js";
2
2
  import { parseOperationIdentity } from "../operations/operation-identity.js";
3
+ import { thrownFailure } from "../runtime/framework-error.factory.js";
3
4
  import { requestIdOf } from "../runtime/request-id.js";
5
+ import { stateOptionOf } from "../runtime/request-state.resolver.js";
4
6
  export function createOperationFacade(model, request, execute) {
5
- return createOperationTree(model, (resource, identity) => (args, options) => execute(request(resource, identity, args === undefined ? {} : args, requestIdOf(options))));
7
+ return createOperationTree(model, (resource, identity) => async (args, options) => settleOperation(await execute(request(resource, identity, args === undefined ? {} : args, requestIdOf(options), stateOptionOf(options)))));
8
+ }
9
+ export function settleOperation(response) {
10
+ if (response.cause !== null) {
11
+ throw thrownFailure(response);
12
+ }
13
+ return response.data;
6
14
  }
7
15
  export function createOperationTree(model, leaf) {
8
16
  const resources = Object.entries(model.resources).map(([resource, { operations }]) => {