@aventara/core 0.1.0-pilot.4 → 1.0.0-rc.1

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 (255) hide show
  1. package/CHANGELOG.md +1478 -0
  2. package/README.md +275 -11
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +17 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -25
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/avz/avz.js +354 -0
  19. package/dist/avz/index.d.ts +7 -0
  20. package/dist/avz/index.js +1 -0
  21. package/dist/avz/json-shape.registry.d.ts +22 -0
  22. package/dist/avz/json-shape.registry.js +16 -0
  23. package/dist/avz/zod-issue.translator.d.ts +57 -0
  24. package/dist/avz/zod-issue.translator.js +149 -0
  25. package/dist/compiler/contract-compiler-diagnostic.d.ts +37 -5
  26. package/dist/compiler/contract.compiler.d.ts +18 -18
  27. package/dist/compiler/contract.compiler.js +595 -421
  28. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  29. package/dist/compiler/create-requirements.projector.js +423 -0
  30. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  31. package/dist/compiler/field-validator.compiler.js +238 -0
  32. package/dist/config/any-framework-config.d.ts +19 -12
  33. package/dist/config/config-diagnostic.d.ts +11 -4
  34. package/dist/config/config-layer.d.ts +15 -6
  35. package/dist/config/config.resolver.d.ts +75 -29
  36. package/dist/config/config.resolver.js +109 -44
  37. package/dist/config/config.validator.d.ts +7 -7
  38. package/dist/config/config.validator.js +586 -71
  39. package/dist/config/define-resource.d.ts +57 -0
  40. package/dist/config/define-resource.js +14 -0
  41. package/dist/config/effective-fields.d.ts +19 -23
  42. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  43. package/dist/config/exact-framework-config.d.ts +280 -0
  44. package/dist/config/field-compute.resolver.d.ts +19 -0
  45. package/dist/config/field-compute.resolver.js +115 -0
  46. package/dist/config/field-pipeline-config.d.ts +47 -0
  47. package/dist/config/forced-operation.validator.d.ts +10 -0
  48. package/dist/config/forced-operation.validator.js +66 -0
  49. package/dist/config/framework-config.d.ts +111 -37
  50. package/dist/config/framework-exemptions-config.d.ts +91 -0
  51. package/dist/config/framework-exemptions-config.js +1 -0
  52. package/dist/config/framework-field-definition.d.ts +78 -0
  53. package/dist/config/framework-field-definition.js +28 -0
  54. package/dist/config/framework-resources-config.d.ts +116 -0
  55. package/dist/config/framework-resources-config.js +1 -0
  56. package/dist/config/pipeline-config.d.ts +56 -20
  57. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  58. package/dist/config/pipeline-tree.resolver.js +220 -0
  59. package/dist/config/stage-type.eraser.d.ts +65 -0
  60. package/dist/config/stage-type.eraser.js +1 -0
  61. package/dist/contracts/capability.d.ts +11 -11
  62. package/dist/contracts/client-contract-structure.validator.d.ts +344 -29
  63. package/dist/contracts/client-contract-structure.validator.js +248 -7
  64. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  65. package/dist/contracts/contract-canonicalizer.js +172 -27
  66. package/dist/contracts/contract-hash.d.ts +12 -7
  67. package/dist/contracts/contract-hash.js +3 -2
  68. package/dist/contracts/contract-limits.d.ts +4 -1
  69. package/dist/contracts/contract-limits.js +1 -0
  70. package/dist/contracts/contract-lookup.d.ts +5 -5
  71. package/dist/contracts/contract-protocol.d.ts +4 -4
  72. package/dist/contracts/contract.d.ts +31 -16
  73. package/dist/contracts/create-requirements.d.ts +35 -0
  74. package/dist/contracts/create-requirements.js +1 -0
  75. package/dist/contracts/enum-definition.d.ts +1 -1
  76. package/dist/contracts/field-check.d.ts +101 -0
  77. package/dist/contracts/field-check.js +1 -0
  78. package/dist/contracts/field.d.ts +61 -41
  79. package/dist/contracts/identifier.d.ts +4 -4
  80. package/dist/contracts/json-shape.d.ts +76 -0
  81. package/dist/contracts/json-shape.js +1 -0
  82. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  83. package/dist/contracts/reference-write-limit.d.ts +7 -0
  84. package/dist/contracts/reference-write-limit.js +1 -0
  85. package/dist/contracts/resource-operations.d.ts +28 -28
  86. package/dist/contracts/resource.d.ts +15 -9
  87. package/dist/contracts/scalar-value-type.d.ts +25 -14
  88. package/dist/contracts/scalar.d.ts +3 -3
  89. package/dist/contracts/transaction-capability.d.ts +1 -1
  90. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  91. package/dist/framework/contract-view.d.ts +234 -63
  92. package/dist/framework/framework-construction.error.d.ts +10 -10
  93. package/dist/framework/framework-construction.error.js +2 -2
  94. package/dist/framework/framework.d.ts +50 -24
  95. package/dist/framework/framework.factory.d.ts +8 -6
  96. package/dist/framework/framework.factory.js +95 -32
  97. package/dist/framework/operation-facade.d.ts +123 -52
  98. package/dist/framework/operation-facade.js +9 -1
  99. package/dist/index.d.ts +55 -82
  100. package/dist/index.js +6 -26
  101. package/dist/internal.d.ts +40 -0
  102. package/dist/internal.js +18 -0
  103. package/dist/operations/operation-arguments.d.ts +316 -201
  104. package/dist/operations/operation-call.d.ts +27 -28
  105. package/dist/operations/operation-identity.d.ts +12 -10
  106. package/dist/operations/operation-identity.js +3 -0
  107. package/dist/operations/operation-result.d.ts +21 -21
  108. package/dist/operations/operation-validator-core.d.ts +6 -6
  109. package/dist/operations/operation-validator-core.js +41 -12
  110. package/dist/operations/operation-validator.d.ts +24 -9
  111. package/dist/operations/operation-validator.js +26 -10
  112. package/dist/operations/projection-scope.resolver.d.ts +7 -7
  113. package/dist/operations/structural-limits.walker.d.ts +19 -0
  114. package/dist/operations/structural-limits.walker.js +489 -0
  115. package/dist/operations/validation-code.d.ts +11 -6
  116. package/dist/operations/validation-code.js +4 -0
  117. package/dist/operations/write-scope.resolver.d.ts +6 -6
  118. package/dist/protocol/absent-route.responder.d.ts +13 -11
  119. package/dist/protocol/absent-route.responder.js +42 -16
  120. package/dist/protocol/contract-document.responder.d.ts +3 -3
  121. package/dist/protocol/contract-document.responder.js +2 -2
  122. package/dist/protocol/http-request.decoder.d.ts +23 -13
  123. package/dist/protocol/http-request.decoder.js +19 -11
  124. package/dist/protocol/http-request.reader.d.ts +3 -3
  125. package/dist/protocol/http-response.encoder.d.ts +4 -4
  126. package/dist/protocol/http-response.encoder.js +94 -55
  127. package/dist/protocol/http-status.table.d.ts +2 -2
  128. package/dist/protocol/operation-response.guard.d.ts +2 -2
  129. package/dist/protocol/protocol-surface.d.ts +4 -4
  130. package/dist/protocol/protocol.binder.d.ts +52 -27
  131. package/dist/protocol/protocol.binder.js +14 -9
  132. package/dist/protocol/protocol.handler.d.ts +28 -15
  133. package/dist/protocol/protocol.handler.js +55 -10
  134. package/dist/protocol/unmounted-route.error.d.ts +19 -0
  135. package/dist/protocol/unmounted-route.error.js +10 -0
  136. package/dist/runtime/caller-data.copier.d.ts +59 -0
  137. package/dist/runtime/caller-data.copier.js +470 -0
  138. package/dist/runtime/caller-data.door.d.ts +56 -0
  139. package/dist/runtime/caller-data.door.js +67 -0
  140. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  141. package/dist/runtime/computed-read-runtime.js +61 -55
  142. package/dist/runtime/computed-value.error.d.ts +13 -0
  143. package/dist/runtime/computed-value.error.js +9 -0
  144. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  145. package/dist/runtime/context-executor.runtime.js +275 -0
  146. package/dist/runtime/create-requirement.d.ts +22 -57
  147. package/dist/runtime/create-requirement.js +140 -37
  148. package/dist/runtime/decimal.d.ts +2 -2
  149. package/dist/runtime/decimal.js +1 -1
  150. package/dist/runtime/diagnostics-reporter.d.ts +64 -22
  151. package/dist/runtime/diagnostics-reporter.js +35 -4
  152. package/dist/runtime/error-boundary.d.ts +73 -8
  153. package/dist/runtime/error-boundary.js +104 -48
  154. package/dist/runtime/execution-options.d.ts +10 -2
  155. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  156. package/dist/runtime/field-check.evaluator.js +521 -0
  157. package/dist/runtime/field-compute.d.ts +64 -0
  158. package/dist/runtime/field-compute.js +1 -0
  159. package/dist/runtime/field-stage.plan.d.ts +15 -0
  160. package/dist/runtime/field-stage.plan.js +27 -0
  161. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  162. package/dist/runtime/field-stage.runtime.js +143 -0
  163. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  164. package/dist/runtime/field-validator.runtime.js +87 -0
  165. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  166. package/dist/runtime/framework-error-class.table.js +25 -0
  167. package/dist/runtime/framework-error.d.ts +79 -7
  168. package/dist/runtime/framework-error.factory.d.ts +4 -0
  169. package/dist/runtime/framework-error.factory.js +15 -0
  170. package/dist/runtime/framework-error.js +23 -2
  171. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  172. package/dist/runtime/interceptor-next.error.js +6 -0
  173. package/dist/runtime/json-value.d.ts +3 -3
  174. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  175. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  176. package/dist/runtime/misuse-reporter.d.ts +32 -0
  177. package/dist/runtime/misuse-reporter.js +19 -0
  178. package/dist/runtime/mutation-planner.d.ts +19 -10
  179. package/dist/runtime/mutation-planner.js +62 -36
  180. package/dist/runtime/nested-write.walker.d.ts +32 -0
  181. package/dist/runtime/nested-write.walker.js +73 -0
  182. package/dist/runtime/operation-request.d.ts +35 -15
  183. package/dist/runtime/operation-response.d.ts +17 -17
  184. package/dist/runtime/operation-runtime.d.ts +125 -30
  185. package/dist/runtime/operation-runtime.js +423 -83
  186. package/dist/runtime/outcome-mapper.d.ts +16 -5
  187. package/dist/runtime/outcome-mapper.js +35 -8
  188. package/dist/runtime/output-validator.d.ts +16 -6
  189. package/dist/runtime/output-validator.js +12 -1
  190. package/dist/runtime/owned-execution.registry.d.ts +13 -0
  191. package/dist/runtime/owned-execution.registry.js +7 -0
  192. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  193. package/dist/runtime/pipe-output.validator.js +12 -12
  194. package/dist/runtime/pipeline.d.ts +202 -28
  195. package/dist/runtime/readonly-value.d.ts +32 -0
  196. package/dist/runtime/readonly-value.js +141 -0
  197. package/dist/runtime/referential-action.d.ts +7 -0
  198. package/dist/runtime/request-envelope.validator.d.ts +5 -0
  199. package/dist/runtime/request-envelope.validator.js +123 -0
  200. package/dist/runtime/request-id.d.ts +1 -1
  201. package/dist/runtime/request-state.d.ts +14 -0
  202. package/dist/runtime/request-state.js +1 -0
  203. package/dist/runtime/request-state.resolver.d.ts +12 -0
  204. package/dist/runtime/request-state.resolver.js +20 -0
  205. package/dist/runtime/scalar-runtime.d.ts +56 -13
  206. package/dist/runtime/scalar-runtime.js +167 -86
  207. package/dist/transactions/deferred-operation.d.ts +35 -20
  208. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  209. package/dist/transactions/operation-arguments-encoder.js +2 -2
  210. package/dist/transactions/sql-statement.d.ts +77 -0
  211. package/dist/transactions/sql-statement.js +47 -0
  212. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  213. package/dist/transactions/sql-statement.validator.js +134 -0
  214. package/dist/transactions/transaction-envelope.d.ts +4 -4
  215. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  216. package/dist/transactions/transaction-integrity-error.js +5 -2
  217. package/dist/transactions/transaction-plan-assembler.d.ts +23 -9
  218. package/dist/transactions/transaction-plan-assembler.js +195 -82
  219. package/dist/transactions/transaction-plan-validator.d.ts +53 -21
  220. package/dist/transactions/transaction-plan-validator.js +246 -163
  221. package/dist/transactions/transaction-reference-collector.d.ts +30 -0
  222. package/dist/transactions/transaction-reference-collector.js +204 -0
  223. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  224. package/dist/transactions/transaction-reference-resolver.js +27 -10
  225. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  226. package/dist/transactions/transaction-reference-validator.js +82 -43
  227. package/dist/transactions/transaction-reference.d.ts +30 -58
  228. package/dist/transactions/transaction-request.d.ts +20 -7
  229. package/dist/transactions/transaction-response.d.ts +12 -7
  230. package/dist/transactions/transaction-response.js +24 -1
  231. package/dist/transactions/transaction-runtime.d.ts +11 -8
  232. package/dist/transactions/transaction-runtime.js +167 -50
  233. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  234. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  235. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  236. package/dist/transactions/transaction-slot-path-error.js +2 -2
  237. package/dist/transactions/transaction-slot-writer.js +2 -2
  238. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  239. package/dist/transactions/transaction-stage.runtime.js +123 -0
  240. package/package.json +18 -3
  241. package/src/runtime/field-check.evaluator.ts +720 -0
  242. package/dist/config/define-fields.d.ts +0 -35
  243. package/dist/config/define-fields.js +0 -3
  244. package/dist/config/framework-behaviors-config.d.ts +0 -30
  245. package/dist/config/framework-fields-config.d.ts +0 -36
  246. package/dist/config/framework-restrictions-config.d.ts +0 -142
  247. package/dist/operations/operation-boolean-nodes.d.ts +0 -11
  248. package/dist/operations/operation-boolean-nodes.js +0 -283
  249. package/dist/operations/operation-nesting.d.ts +0 -8
  250. package/dist/operations/operation-nesting.js +0 -307
  251. package/dist/runtime/field-behavior.d.ts +0 -48
  252. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  253. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  254. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  255. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,16 +1,16 @@
1
- import type { AdapterDiscoveryDiagnostic } from "../adapters/adapter-discovery-diagnostic.js";
2
- import type { ContractCompilerDiagnostic } from "../compiler/contract-compiler-diagnostic.js";
3
- import type { ConfigDiagnostic } from "../config/config-diagnostic.js";
1
+ import type { AvAdapterDiscoveryDiagnostic } from "../adapters/adapter-discovery-diagnostic.js";
2
+ import type { AvContractCompilerDiagnostic } from "../compiler/contract-compiler-diagnostic.js";
3
+ import type { AvConfigDiagnostic } from "../config/config-diagnostic.js";
4
4
  /** The construction step that failed. */
5
- export type FrameworkConstructionStage = "configuration" | "discovery" | "contract-compilation";
6
- /** One problem reported by {@link FrameworkConstructionError}. */
7
- export type FrameworkConstructionDiagnostic = ConfigDiagnostic | AdapterDiscoveryDiagnostic | ContractCompilerDiagnostic;
5
+ export type AvConstructionStage = "configuration" | "discovery" | "contract-compilation";
6
+ /** One problem reported by {@link AvConstructionError}. */
7
+ export type AvConstructionDiagnostic = AvConfigDiagnostic | AvAdapterDiscoveryDiagnostic | AvContractCompilerDiagnostic;
8
8
  /**
9
9
  * Thrown by {@link createFramework} when construction fails: `stage` says
10
10
  * where, and `diagnostics` lists every problem found there.
11
11
  */
12
- export declare class FrameworkConstructionError extends Error {
13
- readonly stage: FrameworkConstructionStage;
14
- readonly diagnostics: readonly FrameworkConstructionDiagnostic[];
15
- constructor(stage: FrameworkConstructionStage, diagnostics: readonly FrameworkConstructionDiagnostic[]);
12
+ export declare class AvConstructionError extends Error {
13
+ readonly stage: AvConstructionStage;
14
+ readonly diagnostics: readonly AvConstructionDiagnostic[];
15
+ constructor(stage: AvConstructionStage, diagnostics: readonly AvConstructionDiagnostic[]);
16
16
  }
@@ -3,12 +3,12 @@ const FRAMEWORK_CONSTRUCTION_MESSAGES = {
3
3
  discovery: "Aventara adapter discovery validation failed",
4
4
  "contract-compilation": "Aventara contract compilation failed",
5
5
  };
6
- export class FrameworkConstructionError extends Error {
6
+ export class AvConstructionError extends Error {
7
7
  stage;
8
8
  diagnostics;
9
9
  constructor(stage, diagnostics) {
10
10
  super(FRAMEWORK_CONSTRUCTION_MESSAGES[stage]);
11
- this.name = "FrameworkConstructionError";
11
+ this.name = "AvConstructionError";
12
12
  this.stage = stage;
13
13
  this.diagnostics = [...diagnostics];
14
14
  }
@@ -1,55 +1,78 @@
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
- * A call is validated like any other request, so it still refuses what a
23
- * restriction removed. The optional second argument is
24
- * {@link ExecutionOptions}.
32
+ * Typed from the Application Contract as configured: what the application's
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}.
25
39
  */
26
40
  readonly application: ApplicationOperations<M, Cfg>;
27
41
  /**
28
42
  * The same operations under ClientContract rules:
29
43
  * `framework.client.<resource>.<family>.<variant>(args, options?)`.
30
44
  *
31
- * What the client layer hides is absent, and arguments are read in the wire
45
+ * What the client layer hides, denies or turns off is absent from the types,
46
+ * as from a generated client, and arguments are read in the wire
32
47
  * forms a decoded request body carries, so a transport can pass `req.body` as
33
48
  * it is. Each call runs the client pipelines and the same validation as a
34
- * remote request.
49
+ * remote request, and settles like an application call: the data, or the
50
+ * failure thrown.
35
51
  */
36
52
  readonly client: ClientOperations<M, Cfg>;
37
53
  /**
38
54
  * Transaction builders under application rules:
39
55
  * `framework.appTx.<resource>.<family>.<variant>(args)` defers one operation
40
- * into a handle typed `Operation<OperationResultFor<…>>` from the Application
56
+ * into a handle typed `AvOperation<AvOperationResultFor<…>>` from the Application
41
57
  * Contract's view, and runs nothing. A handle exposes `$ref(field)` exactly
42
58
  * where its result is one row; the reference is bound to the handle, and its
43
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.
44
67
  */
45
68
  readonly appTx: ApplicationTransactionBuilders<M, Cfg>;
46
69
  /**
47
70
  * The same builders under ClientContract rules, taking wire-form arguments.
48
- * Client and application handles may share one {@link transaction}; each step
49
- * 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).
50
73
  */
51
74
  readonly clientTx: ClientTransactionBuilders<M, Cfg>;
52
- execute(request: FrameworkOperationRequest): Promise<OperationResponse>;
75
+ execute(request: FrameworkOperationRequest): Promise<AvOperationResponse>;
53
76
  /**
54
77
  * Validates a whole transaction plan, then runs its operations one after
55
78
  * another inside one Adapter transaction. Answers `A1009` with each
@@ -60,15 +83,18 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
60
83
  * Guards, pipes, hooks and interceptors run while the transaction is open, so
61
84
  * they should not perform network I/O or other slow work.
62
85
  */
63
- executeTransaction(request: FrameworkTransactionRequest): Promise<TransactionResponse>;
86
+ executeTransaction(request: FrameworkTransactionRequest): Promise<AvTransactionResponse>;
64
87
  /**
65
88
  * Runs handles from `appTx`/`clientTx` as one transaction:
66
- * `framework.transaction([h1, h2, …], options?)`. Resolves the committed
67
- * 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.
68
93
  *
69
94
  * Refused before anything runs: an entry that is not one of this Framework's
70
- * handles, or the same handle twice (`A2004`/`V1001`); a `$ref` to a handle
71
- * 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`).
72
98
  */
73
- readonly transaction: TransactionRunner;
99
+ readonly transaction: AvTransactionRunner;
74
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 & AvConfig<M, Cfg> & AvConfigExact<M, Cfg>): Promise<AvFramework<M, ErasedConfig<Cfg>>>;
@@ -1,24 +1,31 @@
1
1
  import { compileContracts } from "../compiler/contract.compiler.js";
2
2
  import { resolveFrameworkConfig } from "../config/config.resolver.js";
3
3
  import { validateFrameworkConfig } from "../config/config.validator.js";
4
+ import { validateForcedOperations } from "../config/forced-operation.validator.js";
4
5
  import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
6
+ import { copyEnvelopeAtDoor, refuseCallerData, } from "../runtime/caller-data.door.js";
5
7
  import { createDiagnosticsReporter, createTransactionDiagnosticsChannel, recordDiagnosticsSink, } from "../runtime/diagnostics-reporter.js";
6
- import { internalFailure } from "../runtime/operation-response.js";
7
- import { createOperationRuntime } from "../runtime/operation-runtime.js";
8
+ import { createMisuseReporter, } from "../runtime/misuse-reporter.js";
9
+ import { internalFailure, operationFailure, } from "../runtime/operation-response.js";
10
+ import { createOperationRuntime, createPipelineDependencies, } from "../runtime/operation-runtime.js";
11
+ import { recordOwnedExecution } from "../runtime/owned-execution.registry.js";
12
+ import { validateOperationEnvelope, validateTransactionEnvelope, } from "../runtime/request-envelope.validator.js";
8
13
  import { requestIdOf } from "../runtime/request-id.js";
14
+ import { stateOptionOf } from "../runtime/request-state.resolver.js";
9
15
  import { createTransactionPlanAssembler } from "../transactions/transaction-plan-assembler.js";
10
16
  import { createTransactionRuntime } from "../transactions/transaction-runtime.js";
11
- import { FrameworkConstructionError } from "./framework-construction.error.js";
12
- import { createOperationFacade, createOperationTree, } from "./operation-facade.js";
17
+ import { AvConstructionError } from "./framework-construction.error.js";
18
+ import { createOperationFacade, createOperationTree, settleOperation, } from "./operation-facade.js";
19
+ const APPLICATION_SQL_BUILDER = "$sql";
13
20
  export async function createFramework(config) {
14
21
  const configDiagnostics = validateFrameworkConfig(config);
15
22
  if (configDiagnostics.length > 0) {
16
- throw new FrameworkConstructionError("configuration", configDiagnostics);
23
+ throw new AvConstructionError("configuration", configDiagnostics);
17
24
  }
18
25
  const model = config.adapter.model;
19
26
  if (model.transactions === "interactive" &&
20
27
  typeof config.adapter.transaction !== "function") {
21
- throw new FrameworkConstructionError("discovery", [
28
+ throw new AvConstructionError("discovery", [
22
29
  {
23
30
  code: "DISCOVERY_TRANSACTION_CAPABILITY_MISMATCH",
24
31
  path: "adapter.transactions",
@@ -29,80 +36,127 @@ export async function createFramework(config) {
29
36
  const resolvedConfig = resolveFrameworkConfig(config);
30
37
  const compilation = await compileContracts(model, resolvedConfig);
31
38
  if (!compilation.ok) {
32
- throw new FrameworkConstructionError("contract-compilation", compilation.diagnostics);
39
+ throw new AvConstructionError("contract-compilation", compilation.diagnostics);
33
40
  }
34
- const execute = createOperationRuntime({
35
- adapter: config.adapter,
36
- contracts: compilation.contracts,
37
- config: resolvedConfig,
38
- });
39
- const executeTransaction = createTransactionRuntime({
41
+ const forcing = validateForcedOperations(config, compilation.contracts);
42
+ if (forcing.length > 0) {
43
+ throw new AvConstructionError("configuration", forcing);
44
+ }
45
+ const runtimeDependencies = {
40
46
  adapter: config.adapter,
41
47
  contracts: compilation.contracts,
42
48
  config: resolvedConfig,
43
- });
44
- const executeOperation = (request) => executeTotally(execute, request, resolvedConfig.diagnostics);
49
+ };
50
+ const pipelineDependencies = createPipelineDependencies(runtimeDependencies, model);
51
+ const execute = createOperationRuntime(runtimeDependencies, pipelineDependencies);
52
+ const executeTransaction = createTransactionRuntime(runtimeDependencies, pipelineDependencies);
53
+ const misuse = createMisuseReporter(resolvedConfig.misuse);
54
+ const executeOperation = (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "caller");
45
55
  const protocol = {
46
56
  version: AVENTARA_PROTOCOL_VERSION,
47
57
  hash: compilation.contracts.client.protocol.hash,
48
58
  };
49
- const assembler = createTransactionPlanAssembler(compilation.contracts, protocol);
59
+ const assembler = createTransactionPlanAssembler(compilation.contracts, protocol, misuse);
50
60
  const framework = {
51
- entrypoint: resolvedConfig.entrypoint,
61
+ api: resolvedConfig.api,
62
+ mcp: resolvedConfig.mcp,
52
63
  contracts: compilation.contracts,
53
- application: createOperationFacade(model, (resource, identity, args, requestId) => ({
64
+ application: createOperationFacade(model, (resource, identity, args, requestId, state) => ({
54
65
  ...identity,
55
- scope: "application",
66
+ origin: "application",
56
67
  requestId,
68
+ ...(state === undefined ? {} : { state }),
57
69
  resource,
58
70
  arguments: args,
59
71
  }), executeOperation),
60
- client: createOperationFacade(model, (resource, identity, args, requestId) => ({
72
+ client: createOperationFacade(model, (resource, identity, args, requestId, state) => ({
61
73
  ...identity,
62
- scope: "client",
74
+ origin: "client",
63
75
  protocol,
64
76
  requestId,
77
+ ...(state === undefined ? {} : { state }),
65
78
  resource,
66
79
  arguments: args,
67
80
  }), executeOperation),
68
- appTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("application", resource, identity, args === undefined ? {} : args)),
81
+ appTx: Object.freeze({
82
+ ...createOperationTree(model, (resource, identity) => (args) => assembler.defer("application", resource, identity, args === undefined ? {} : args)),
83
+ [APPLICATION_SQL_BUILDER]: (strings, ...values) => assembler.deferSql(strings, values),
84
+ }),
69
85
  clientTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("client", resource, identity, args === undefined ? {} : args)),
70
- execute: executeOperation,
71
- executeTransaction: (request) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics),
72
- transaction: ((operations, options) => runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), resolvedConfig.diagnostics)),
86
+ execute: (request) => executeRequestTotally(execute, request, resolvedConfig.diagnostics, misuse),
87
+ executeTransaction: (request) => executeTransactionRequestTotally(executeTransaction, request, resolvedConfig.diagnostics, misuse),
88
+ transaction: (async (operations, options) => settleOperation(await runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), stateOptionOf(options), resolvedConfig.diagnostics))),
73
89
  };
74
90
  recordDiagnosticsSink(framework, resolvedConfig.diagnostics);
91
+ recordOwnedExecution(framework, {
92
+ execute: (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "owned"),
93
+ executeTransaction: (request) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics, undefined, { source: "owned" }),
94
+ });
75
95
  return framework;
76
96
  }
77
- async function executeTotally(execute, request, diagnostics) {
97
+ async function executeTotally(execute, request, diagnostics, source) {
78
98
  const report = createDiagnosticsReporter(diagnostics, request);
79
99
  try {
80
- return await execute(request, report);
100
+ return await execute(request, report, source);
81
101
  }
82
102
  catch (error) {
83
103
  report(error, "A3000");
84
104
  return internalFailure();
85
105
  }
86
106
  }
87
- async function executeTransactionTotally(execute, request, diagnostics, origins) {
107
+ function executeRequestTotally(execute, request, diagnostics, misuse) {
108
+ const envelope = copyEnvelopeAtDoor(request, ["protocol", "transport"]);
109
+ if (!envelope.ok) {
110
+ return Promise.resolve(operationFailure("A2004", {
111
+ message: "Operation arguments failed framework validation.",
112
+ issues: [refuseCallerData(envelope.error, [], {}, misuse)],
113
+ }));
114
+ }
115
+ const malformed = validateOperationEnvelope(envelope.value);
116
+ if (malformed.length > 0) {
117
+ return Promise.resolve(operationFailure("A2004", {
118
+ message: "Operation arguments failed framework validation.",
119
+ issues: malformed,
120
+ }));
121
+ }
122
+ return executeTotally(execute, envelope.value, diagnostics, "caller");
123
+ }
124
+ function executeTransactionRequestTotally(execute, request, diagnostics, misuse) {
125
+ const envelope = copyEnvelopeAtDoor(request, ["protocol", "transport"]);
126
+ if (!envelope.ok) {
127
+ return Promise.resolve(operationFailure("A2004", {
128
+ message: "Transaction plan failed framework validation.",
129
+ issues: [refuseCallerData(envelope.error, [], {}, misuse)],
130
+ }));
131
+ }
132
+ const malformed = validateTransactionEnvelope(envelope.value);
133
+ if (malformed.length > 0) {
134
+ return Promise.resolve(operationFailure("A2004", {
135
+ message: "Transaction plan failed framework validation.",
136
+ issues: malformed,
137
+ }));
138
+ }
139
+ return executeTransactionTotally(execute, envelope.value, diagnostics, undefined, { source: "caller" });
140
+ }
141
+ async function executeTransactionTotally(execute, request, diagnostics, origins, planArguments) {
88
142
  const channel = createTransactionDiagnosticsChannel(diagnostics, request);
89
143
  const report = channel.transaction();
90
144
  try {
91
- return await execute(request, channel, origins);
145
+ return await execute(request, channel, origins, planArguments);
92
146
  }
93
147
  catch (error) {
94
148
  report(error, "A3000");
95
149
  return internalFailure();
96
150
  }
97
151
  }
98
- async function runTransactionTotally(execute, assembler, operations, requestId, diagnostics) {
152
+ async function runTransactionTotally(execute, assembler, operations, requestId, state, diagnostics) {
99
153
  let assembled;
100
154
  try {
101
155
  assembled = await assembler.assemble(operations);
102
156
  }
103
157
  catch (error) {
104
158
  createTransactionDiagnosticsChannel(diagnostics, {
105
- scope: "application",
159
+ origin: "application",
106
160
  requestId,
107
161
  plan: operations,
108
162
  }).transaction()(error, "A3000");
@@ -111,5 +165,14 @@ async function runTransactionTotally(execute, assembler, operations, requestId,
111
165
  if (!assembled.ok) {
112
166
  return assembled.response;
113
167
  }
114
- return executeTransactionTotally(execute, { scope: "application", requestId, plan: assembled.plan }, diagnostics, assembled.origins);
168
+ return executeTransactionTotally(execute, {
169
+ origin: "application",
170
+ requestId,
171
+ ...(state === undefined ? {} : { state }),
172
+ plan: assembled.plan,
173
+ }, diagnostics, assembled.origins, {
174
+ source: "owned",
175
+ refused: assembled.refused,
176
+ statements: assembled.statements,
177
+ });
115
178
  }
@@ -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 {};