@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,8 +1,10 @@
1
- import type { FrameworkContracts } from "../compiler/contract.compiler.js";
2
- import type { Framework } from "../framework/framework.js";
3
- import { type FrameworkDiagnosticsSink } from "../runtime/diagnostics-reporter.js";
4
- import type { ClientOperationRequest } from "../runtime/operation-request.js";
1
+ import type { AvContracts } from "../compiler/contract.compiler.js";
2
+ import type { RemoteRequestOrigin } from "../config/config-layer.js";
3
+ import type { AvFramework } from "../framework/framework.js";
4
+ import { type AvDiagnosticsSink } from "../runtime/diagnostics-reporter.js";
5
+ import type { RemoteOperationRequest } from "../runtime/operation-request.js";
5
6
  import type { OwnedExecution } from "../runtime/owned-execution.registry.js";
7
+ import type { AvState } from "../runtime/request-state.js";
6
8
  import { type AvProtocolRequest } from "./http-request.decoder.js";
7
9
  import { type AvProtocolResponse, type UnencodableReport } from "./http-response.encoder.js";
8
10
  /**
@@ -12,11 +14,18 @@ import { type AvProtocolResponse, type UnencodableReport } from "./http-response
12
14
  * constructed Framework) — and its configured diagnostics sink.
13
15
  */
14
16
  export type HandlerContext = {
15
- readonly contracts: FrameworkContracts;
16
- readonly execute: Framework["execute"];
17
- readonly executeTransaction: Framework["executeTransaction"];
17
+ readonly contracts: AvContracts;
18
+ /** The origin every request the binding decodes runs under. */
19
+ readonly origin: RemoteRequestOrigin;
20
+ readonly execute: AvFramework["execute"];
21
+ readonly executeTransaction: AvFramework["executeTransaction"];
18
22
  readonly owned: OwnedExecution | undefined;
19
- readonly sink: FrameworkDiagnosticsSink | undefined;
23
+ readonly sink: AvDiagnosticsSink | undefined;
24
+ };
25
+ /** What a host passes beside one protocol request. */
26
+ export type ProtocolCallOptions = {
27
+ /** Seeds the request's `ctx.$state`; called once, after decoding. Omitted, the state is `{}`. */
28
+ readonly state?: () => AvState | Promise<AvState>;
20
29
  };
21
30
  /**
22
31
  * Where a plan's `A3003` goes: the Framework's diagnostics sink, as a `"transaction"`
@@ -24,15 +33,15 @@ export type HandlerContext = {
24
33
  * encoder blames as `operation` when it blames one. One spelling for both
25
34
  * `protocol.encodeTransaction` and `protocol.handleTransaction`.
26
35
  */
27
- export declare function planUnencodableReport(sink: FrameworkDiagnosticsSink | undefined, requestId: string): UnencodableReport;
36
+ export declare function planUnencodableReport(sink: AvDiagnosticsSink | undefined, requestId: string, origin?: RemoteRequestOrigin): UnencodableReport;
28
37
  /**
29
38
  * Where one operation's `A3003` goes: the Framework's diagnostics sink, as an
30
39
  * `"operation"` diagnostic carrying the decoded request's identity and id — the shape
31
- * the public `OperationDiagnostic` already has. One spelling for
40
+ * the public `AvOperationDiagnostic` already has. One spelling for
32
41
  * `protocol.handleOperation` and for `protocol.encodeOperation` given the decoded
33
42
  * request.
34
43
  */
35
- export declare function operationUnencodableReport(sink: FrameworkDiagnosticsSink | undefined, request: ClientOperationRequest): UnencodableReport;
44
+ export declare function operationUnencodableReport(sink: AvDiagnosticsSink | undefined, request: RemoteOperationRequest): UnencodableReport;
36
45
  /**
37
46
  * `protocol.handleOperation(request)`: the three steps a host would otherwise spell
38
47
  * out — `decodeOperation` → `framework.execute` → `encodeOperation` — in one call,
@@ -40,7 +49,7 @@ export declare function operationUnencodableReport(sink: FrameworkDiagnosticsSin
40
49
  * itself (a transport failure, an identity mismatch, an unadvertised route) is
41
50
  * answered without executing.
42
51
  */
43
- export declare function handleOperationRequest(context: HandlerContext, request: AvProtocolRequest): Promise<AvProtocolResponse>;
52
+ export declare function handleOperationRequest(context: HandlerContext, request: AvProtocolRequest, options?: ProtocolCallOptions): Promise<AvProtocolResponse>;
44
53
  /**
45
54
  * `protocol.handleTransaction(request)`: the same shortcut for `/_transactions` —
46
55
  * `decodeTransaction` → `framework.executeTransaction` → `encodeTransaction`. The
@@ -52,4 +61,4 @@ export declare function handleOperationRequest(context: HandlerContext, request:
52
61
  * handleOperationRequest} is; an `A3003` is reported through {@link
53
62
  * planUnencodableReport}.
54
63
  */
55
- export declare function handleTransactionRequest(context: HandlerContext, request: AvProtocolRequest): Promise<AvProtocolResponse>;
64
+ export declare function handleTransactionRequest(context: HandlerContext, request: AvProtocolRequest, options?: ProtocolCallOptions): Promise<AvProtocolResponse>;
@@ -1,20 +1,78 @@
1
+ import { copyAtDoor } from "../runtime/caller-data.door.js";
1
2
  import { createDiagnosticsReporter, createReporter, } from "../runtime/diagnostics-reporter.js";
3
+ import { sanitizeOperationFailure } from "../runtime/error-boundary.js";
4
+ import { capturePlanAtCall } from "../transactions/transaction-plan-validator.js";
2
5
  import { decodeOperationRequest, decodeTransactionRequest, isParsedByDecoder, } from "./http-request.decoder.js";
3
6
  import { encodeOperationResponse, encodeTransactionResponse, } from "./http-response.encoder.js";
4
- function operationEntry(context, request) {
5
- return context.owned !== undefined && isParsedByDecoder(request.arguments)
6
- ? context.owned.execute
7
- : context.execute;
7
+ function admitOperation(context, request) {
8
+ const owned = context.owned;
9
+ if (isParsedByDecoder(request.arguments)) {
10
+ return { request, run: owned?.execute ?? context.execute };
11
+ }
12
+ const copy = copyAtDoor(request.arguments);
13
+ if (owned === undefined) {
14
+ return {
15
+ request: copy.ok ? { ...request, arguments: copy.value } : request,
16
+ run: context.execute,
17
+ };
18
+ }
19
+ if (copy.ok) {
20
+ return {
21
+ request: { ...request, arguments: copy.value },
22
+ run: (admitted) => owned.execute(admitted),
23
+ };
24
+ }
25
+ return {
26
+ request: { ...request, arguments: {} },
27
+ run: (admitted) => owned.execute(admitted, copy.error),
28
+ };
29
+ }
30
+ function admitTransaction(context, request) {
31
+ const owned = context.owned;
32
+ if (isParsedByDecoder(request.plan)) {
33
+ return {
34
+ request,
35
+ run: owned?.executeTransaction ?? context.executeTransaction,
36
+ };
37
+ }
38
+ const captured = capturePlanAtCall(request.plan);
39
+ if (owned === undefined) {
40
+ return {
41
+ request: captured.refused.size === 0
42
+ ? { ...request, plan: captured.plan }
43
+ : request,
44
+ run: context.executeTransaction,
45
+ };
46
+ }
47
+ return {
48
+ request: { ...request, plan: captured.plan },
49
+ run: (admitted) => owned.executeTransaction(admitted, captured.refused.size === 0 ? undefined : captured.refused),
50
+ };
8
51
  }
9
- function transactionEntry(context, request) {
10
- return context.owned !== undefined && isParsedByDecoder(request.plan)
11
- ? context.owned.executeTransaction
12
- : context.executeTransaction;
52
+ async function seededState(options, report, view) {
53
+ if (options?.state === undefined) {
54
+ return { ok: true, state: undefined };
55
+ }
56
+ try {
57
+ const state = await options.state();
58
+ return {
59
+ ok: true,
60
+ state: typeof state === "object" && state !== null && !Array.isArray(state)
61
+ ? state
62
+ : undefined,
63
+ };
64
+ }
65
+ catch (error) {
66
+ return {
67
+ ok: false,
68
+ response: sanitizeOperationFailure(error, "runtime", report, view),
69
+ };
70
+ }
13
71
  }
14
- export function planUnencodableReport(sink, requestId) {
72
+ export function planUnencodableReport(sink, requestId, origin = "client") {
15
73
  return (error, operation) => createReporter(sink, {
16
74
  kind: "transaction",
17
- origin: "client",
75
+ origin,
18
76
  requestId,
19
77
  ...(operation === undefined ? {} : { operation }),
20
78
  })(error, "A3003");
@@ -22,19 +80,35 @@ export function planUnencodableReport(sink, requestId) {
22
80
  export function operationUnencodableReport(sink, request) {
23
81
  return (error) => createDiagnosticsReporter(sink, request)(error, "A3003");
24
82
  }
25
- export async function handleOperationRequest(context, request) {
26
- const decoded = decodeOperationRequest(context.contracts, request);
83
+ export async function handleOperationRequest(context, request, options) {
84
+ const decoded = decodeOperationRequest(context.contracts, request, context.origin);
27
85
  if (!decoded.ok) {
28
86
  return decoded.response;
29
87
  }
30
- const response = await operationEntry(context, decoded.request)(decoded.request);
88
+ const admitted = admitOperation(context, decoded.request);
89
+ const seeded = await seededState(options, createDiagnosticsReporter(context.sink, admitted.request), { path: ["arguments"], arguments: admitted.request.arguments });
90
+ const response = seeded.ok
91
+ ? await admitted.run(seeded.state === undefined
92
+ ? admitted.request
93
+ : { ...admitted.request, state: seeded.state })
94
+ : seeded.response;
31
95
  return encodeOperationResponse(response, decoded.requestId, operationUnencodableReport(context.sink, decoded.request));
32
96
  }
33
- export async function handleTransactionRequest(context, request) {
34
- const decoded = decodeTransactionRequest(context.contracts, request);
97
+ export async function handleTransactionRequest(context, request, options) {
98
+ const decoded = decodeTransactionRequest(context.contracts, request, context.origin);
35
99
  if (!decoded.ok) {
36
100
  return decoded.response;
37
101
  }
38
- const response = await transactionEntry(context, decoded.request)(decoded.request);
39
- return encodeTransactionResponse(response, decoded.requestId, planUnencodableReport(context.sink, decoded.requestId));
102
+ const admitted = admitTransaction(context, decoded.request);
103
+ const seeded = await seededState(options, createReporter(context.sink, {
104
+ kind: "transaction",
105
+ origin: context.origin,
106
+ requestId: decoded.requestId,
107
+ }), { path: ["plan"], arguments: admitted.request.plan });
108
+ const response = seeded.ok
109
+ ? await admitted.run(seeded.state === undefined
110
+ ? admitted.request
111
+ : { ...admitted.request, state: seeded.state })
112
+ : seeded.response;
113
+ return encodeTransactionResponse(response, decoded.requestId, planUnencodableReport(context.sink, decoded.requestId, context.origin));
40
114
  }
@@ -5,15 +5,15 @@
5
5
  * `500 A3000` is unchanged; this error names the route the host left out, so the
6
6
  * server's diagnostics show it too. It is never sent to the caller.
7
7
  */
8
- export declare class UnmountedRouteError extends Error {
8
+ export declare class AvUnmountedRouteError extends Error {
9
9
  /** What the ClientContract advertises: `resource.family.variant`, or `transactions`. */
10
10
  readonly advertised: string;
11
- /** The route as the request reached it: method and entrypoint-relative path. */
11
+ /** The route as the request reached it: method and api-relative path. */
12
12
  readonly route: string;
13
- readonly name = "UnmountedRouteError";
13
+ readonly name = "AvUnmountedRouteError";
14
14
  constructor(
15
15
  /** What the ClientContract advertises: `resource.family.variant`, or `transactions`. */
16
16
  advertised: string,
17
- /** The route as the request reached it: method and entrypoint-relative path. */
17
+ /** The route as the request reached it: method and api-relative path. */
18
18
  route: string);
19
19
  }
@@ -1,7 +1,7 @@
1
- export class UnmountedRouteError extends Error {
1
+ export class AvUnmountedRouteError extends Error {
2
2
  advertised;
3
3
  route;
4
- name = "UnmountedRouteError";
4
+ name = "AvUnmountedRouteError";
5
5
  constructor(advertised, route) {
6
6
  super(`The ClientContract advertises ${advertised}, but the host mounted no route for ${route}, so protocol.answerAbsent answered it 500 A3000. Mount every protocol.surface() entry.`);
7
7
  this.advertised = advertised;
@@ -7,7 +7,7 @@ export type CallerDataPath = readonly (string | number)[];
7
7
  * root. Thrown by {@link copyCallerData} and caught by every door, which answers it as
8
8
  * the caller's `A2004`/`V1001` at its own address. It never carries the value.
9
9
  */
10
- export declare class CallerDataError extends Error {
10
+ export declare class AvCallerDataError extends Error {
11
11
  readonly kind: CallerDataFailureKind;
12
12
  readonly path: CallerDataPath;
13
13
  /**
@@ -15,7 +15,7 @@ export declare class CallerDataError extends Error {
15
15
  * tripwire read after the door; {@link locateCallerDataError} resolves it.
16
16
  */
17
17
  readonly within?: object | undefined;
18
- readonly name = "CallerDataError";
18
+ readonly name = "AvCallerDataError";
19
19
  constructor(kind: CallerDataFailureKind, path: CallerDataPath,
20
20
  /**
21
21
  * The control mirror `path` starts from, when the failure is a mirror's
@@ -41,19 +41,36 @@ export type CallerDataPolicy = {
41
41
  readonly keep?: CallerDataKeep;
42
42
  readonly mirror?: CallerDataMirror;
43
43
  };
44
+ /** The members a structural mirror copies by value rather than mirroring. */
45
+ type MirrorMembers = {
46
+ /** The policy a member at `path` (from the mirror's root) is copied by, or `undefined`. */
47
+ readonly copyAt: (path: CallerDataPath) => CallerDataPolicy | undefined;
48
+ /** Receives a member whose copy failed; the mirror holds `undefined` for it. */
49
+ readonly refused: (path: CallerDataPath, error: AvCallerDataError) => void;
50
+ };
51
+ /**
52
+ * Mirrors `value` by its descriptors, as a `$ref` control object is mirrored (no
53
+ * getter runs, an accessor stays a tripwire), except the members `members.copyAt`
54
+ * names by their path: each is copied by value under the policy it returns, and one
55
+ * whose copy fails is reported to `members.refused` and held as `undefined`.
56
+ *
57
+ * @throws {@link AvCallerDataError} at `[]` when `value` itself cannot be reflected.
58
+ */
59
+ export declare function mirrorCallerData(value: object, members: MirrorMembers): unknown;
44
60
  /**
45
61
  * Places a mirror tripwire's failure in the value the door copied: its path from the
46
62
  * copy's root, where `error.path` started from the mirror. A failure that is not a
47
63
  * tripwire's, or a mirror the copy does not hold, is returned as it is.
48
64
  */
49
- export declare function locateCallerDataError(error: CallerDataError, copy: unknown): CallerDataError;
65
+ export declare function locateCallerDataError(error: AvCallerDataError, copy: unknown): AvCallerDataError;
50
66
  /**
51
67
  * Copies a caller's value into fresh plain data (see the module note), reading the
52
68
  * caller's objects exactly once.
53
69
  *
54
- * @throws {@link CallerDataError} when a value cannot be read or is not plain data,
70
+ * @throws {@link AvCallerDataError} when a value cannot be read or is not plain data,
55
71
  * naming its path from `value`.
56
72
  */
57
73
  export declare function copyCallerData(value: unknown, policy?: CallerDataPolicy): unknown;
58
- /** The `V1001` message a door answers a {@link CallerDataError} with. */
74
+ /** The `V1001` message a door answers a {@link AvCallerDataError} with. */
59
75
  export declare function callerDataFailureMessage(kind: CallerDataFailureKind): string;
76
+ export {};
@@ -1,13 +1,13 @@
1
- import { Decimal } from "./decimal.js";
1
+ import { AvDecimal } from "./decimal.js";
2
2
  const FAILURE_MESSAGES = {
3
3
  "unreadable-value": "Value could not be read.",
4
4
  "non-plain-value": "Value must be plain data.",
5
5
  };
6
- export class CallerDataError extends Error {
6
+ export class AvCallerDataError extends Error {
7
7
  kind;
8
8
  path;
9
9
  within;
10
- name = "CallerDataError";
10
+ name = "AvCallerDataError";
11
11
  constructor(kind, path, within) {
12
12
  super(FAILURE_MESSAGES[kind]);
13
13
  this.kind = kind;
@@ -19,7 +19,7 @@ const NO_POLICY = {};
19
19
  const OBJECT_PROTOTYPE = Object.prototype;
20
20
  const DATE_PROTOTYPE = Date.prototype;
21
21
  const dateValueOf = Date.prototype.getTime;
22
- const decimalValueOf = Decimal.prototype.toString;
22
+ const decimalValueOf = AvDecimal.prototype.toString;
23
23
  const FAST_WALK_DEPTH = 256;
24
24
  const SLOW_WALK = Symbol("slow walk");
25
25
  class FastWalkFailure {
@@ -33,8 +33,8 @@ function copyValueType(value, prototype) {
33
33
  if (prototype === DATE_PROTOTYPE || value instanceof Date) {
34
34
  return new Date(dateValueOf.call(value));
35
35
  }
36
- if (value instanceof Decimal) {
37
- return new Decimal(decimalValueOf.call(value));
36
+ if (value instanceof AvDecimal) {
37
+ return new AvDecimal(decimalValueOf.call(value));
38
38
  }
39
39
  if (value instanceof Uint8Array) {
40
40
  return new Uint8Array(value);
@@ -134,7 +134,7 @@ function readAt(link, read) {
134
134
  return read();
135
135
  }
136
136
  catch {
137
- throw new CallerDataError("unreadable-value", pathOf(link));
137
+ throw new AvCallerDataError("unreadable-value", pathOf(link));
138
138
  }
139
139
  }
140
140
  function copySlow(value, policy, failedAt) {
@@ -154,7 +154,7 @@ function copySlow(value, policy, failedAt) {
154
154
  const task = stack.pop();
155
155
  if (task.kind === "leave") {
156
156
  if (task.refuse !== false) {
157
- throw new CallerDataError("unreadable-value", pathOf(task.refuse));
157
+ throw new AvCallerDataError("unreadable-value", pathOf(task.refuse));
158
158
  }
159
159
  ancestors.delete(task.container);
160
160
  continue;
@@ -172,7 +172,7 @@ function copySlow(value, policy, failedAt) {
172
172
  const refuse = current === failedAt ? link : false;
173
173
  const settle = (copy) => {
174
174
  if (refuse !== false) {
175
- throw new CallerDataError("unreadable-value", pathOf(refuse));
175
+ throw new AvCallerDataError("unreadable-value", pathOf(refuse));
176
176
  }
177
177
  task.assign(copy);
178
178
  };
@@ -209,7 +209,7 @@ function copySlow(value, policy, failedAt) {
209
209
  if (!isPlainPrototype(prototype)) {
210
210
  const copied = readAt(link, () => copyValueType(current, prototype));
211
211
  if (copied === undefined) {
212
- throw new CallerDataError("non-plain-value", pathOf(link));
212
+ throw new AvCallerDataError("non-plain-value", pathOf(link));
213
213
  }
214
214
  settle(copied);
215
215
  continue;
@@ -268,14 +268,14 @@ function pathSegment(array, key) {
268
268
  }
269
269
  return key;
270
270
  }
271
- function mirrorControlData(value) {
271
+ function mirrorControlData(value, members) {
272
272
  const shape = reflectNode(value);
273
273
  if (shape === undefined) {
274
- throw new CallerDataError("unreadable-value", []);
274
+ throw new AvCallerDataError("unreadable-value", []);
275
275
  }
276
276
  let root;
277
277
  const refuse = (kind, path) => {
278
- throw new CallerDataError(kind, path, root);
278
+ throw new AvCallerDataError(kind, path, root);
279
279
  };
280
280
  const mirrors = new Map();
281
281
  const stack = [
@@ -375,6 +375,20 @@ function mirrorControlData(value) {
375
375
  continue;
376
376
  }
377
377
  const memberLink = childLink(link, pathSegment(shape.array, key));
378
+ const byValue = members?.copyAt(pathOf(memberLink));
379
+ if (byValue !== undefined) {
380
+ try {
381
+ store(copyCallerData(member, byValue));
382
+ }
383
+ catch (error) {
384
+ if (!(error instanceof AvCallerDataError)) {
385
+ throw error;
386
+ }
387
+ members?.refused(pathOf(memberLink), error);
388
+ store(undefined);
389
+ }
390
+ continue;
391
+ }
378
392
  const memberShape = reflectNode(member);
379
393
  if (memberShape === undefined) {
380
394
  store(UNREADABLE);
@@ -408,6 +422,9 @@ function mirrorControlData(value) {
408
422
  }
409
423
  return root;
410
424
  }
425
+ export function mirrorCallerData(value, members) {
426
+ return mirrorControlData(value, members);
427
+ }
411
428
  export function locateCallerDataError(error, copy) {
412
429
  const within = error.within;
413
430
  if (within === undefined) {
@@ -416,7 +433,7 @@ export function locateCallerDataError(error, copy) {
416
433
  const at = pathTo(copy, within);
417
434
  return at === undefined
418
435
  ? error
419
- : new CallerDataError(error.kind, [...at, ...error.path]);
436
+ : new AvCallerDataError(error.kind, [...at, ...error.path]);
420
437
  }
421
438
  function pathTo(copy, target) {
422
439
  const seen = new Set();
@@ -1,20 +1,26 @@
1
- import type { ValidationIssue } from "../operations/validation-code.js";
2
- import { CallerDataError, type CallerDataPath, type CallerDataPolicy } from "./caller-data.copier.js";
3
- import type { FrameworkMisuseEvent, MisuseReporter } from "./misuse-reporter.js";
1
+ import type { AvValidationIssue } from "../operations/validation-code.js";
2
+ import { AvCallerDataError, type CallerDataPath, type CallerDataPolicy } from "./caller-data.copier.js";
3
+ import type { AvMisuseEvent, MisuseReporter } from "./misuse-reporter.js";
4
4
  /**
5
5
  * Where the arguments an execution entry receives came from.
6
6
  *
7
7
  * - `"caller"`: a server-side caller's own objects — copied at the door.
8
8
  * - `"owned"`: data no caller holds a reference to — a body the protocol decoder
9
- * parsed with `JSON.parse` for this request alone, or a plan the typed runner
10
- * assembled from copies its builders took. It is never copied again.
9
+ * parsed with `JSON.parse` for this request alone, a host's parsed body the
10
+ * protocol's shortcut copied at the call, or a plan the typed runner assembled
11
+ * from copies its builders took. It is never copied again.
11
12
  *
12
- * Only core's own modules choose `"owned"`: the public `framework.execute` and
13
- * `executeTransaction` always pass `"caller"`.
13
+ * - `{ refused }`: a body the protocol's shortcut copied at the call, whose copy
14
+ * failed — answered at the door as `"caller"` would answer it, never read again.
15
+ *
16
+ * Only core's own modules choose anything but `"caller"`: the public
17
+ * `framework.execute` and `executeTransaction` always pass `"caller"`.
14
18
  */
15
- export type ArgumentsSource = "caller" | "owned";
19
+ export type ArgumentsSource = "caller" | "owned" | {
20
+ readonly refused: AvCallerDataError;
21
+ };
16
22
  /** The operation identity a misuse event may name, as far as it could be read. */
17
- export type MisuseIdentity = Omit<FrameworkMisuseEvent, "kind" | "path">;
23
+ export type MisuseIdentity = Omit<AvMisuseEvent, "kind" | "path">;
18
24
  /**
19
25
  * The identity of a request the framework holds a copy of, keeping only what is
20
26
  * identity: an origin, a Resource name and a standard operation, each present only
@@ -30,7 +36,7 @@ export declare function misuseIdentityOf(request: {
30
36
  * The caller's `V1001` for a refused value at `address` (the door's own spelling of
31
37
  * where the copied value stands), reported once to the misuse hook.
32
38
  */
33
- export declare function refuseCallerData(error: CallerDataError, address: CallerDataPath, identity: MisuseIdentity, misuse: MisuseReporter): ValidationIssue;
39
+ export declare function refuseCallerData(error: AvCallerDataError, address: CallerDataPath, identity: MisuseIdentity, misuse: MisuseReporter): AvValidationIssue;
34
40
  /**
35
41
  * A door's copy of one caller value, or the failure it met. The door holds it until
36
42
  * its answer is due — a plan answers its steps in order — so the failure is a value
@@ -41,7 +47,7 @@ export type CallerDataCopy = {
41
47
  readonly value: unknown;
42
48
  } | {
43
49
  readonly ok: false;
44
- readonly error: CallerDataError;
50
+ readonly error: AvCallerDataError;
45
51
  };
46
52
  /** Copies `value` at a door, keeping {@link copyCallerData}'s refusal as a value. */
47
53
  export declare function copyAtDoor(value: unknown, policy?: CallerDataPolicy): CallerDataCopy;
@@ -1,8 +1,10 @@
1
1
  import { parseOperationIdentity } from "../operations/operation-identity.js";
2
2
  import { validationIssue } from "../operations/validation-code.js";
3
- import { CallerDataError, copyCallerData, } from "./caller-data.copier.js";
3
+ import { AvCallerDataError, copyCallerData, } from "./caller-data.copier.js";
4
4
  export function misuseIdentityOf(request) {
5
- const origin = request.origin === "application" || request.origin === "client"
5
+ const origin = request.origin === "application" ||
6
+ request.origin === "client" ||
7
+ request.origin === "agent"
6
8
  ? request.origin
7
9
  : undefined;
8
10
  const identity = typeof request.family === "string" && typeof request.variant === "string"
@@ -28,7 +30,7 @@ export function copyAtDoor(value, policy) {
28
30
  return { ok: true, value: copyCallerData(value, policy) };
29
31
  }
30
32
  catch (error) {
31
- if (error instanceof CallerDataError) {
33
+ if (error instanceof AvCallerDataError) {
32
34
  return { ok: false, error };
33
35
  }
34
36
  throw error;
@@ -53,7 +55,7 @@ export function copyEnvelopeAtDoor(request, members) {
53
55
  if (!copy.ok) {
54
56
  return {
55
57
  ok: false,
56
- error: new CallerDataError(copy.error.kind, [
58
+ error: new AvCallerDataError(copy.error.kind, [
57
59
  member,
58
60
  ...copy.error.path,
59
61
  ]),
@@ -1,8 +1,9 @@
1
- import type { FrameworkBehaviorsConfig } from "../config/framework-behaviors-config.js";
2
- import type { Contract, CoreContract } from "../contracts/contract.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { ResolvedComputeConfig } from "../config/field-compute.resolver.js";
3
+ import type { AvContract, AvContractCore } from "../contracts/contract.js";
4
+ import type { AvComputeContext } from "./field-compute.js";
3
5
  import type { OperationExecutionRequest } from "./operation-request.js";
4
- import type { PipelineContext } from "./pipeline.js";
5
- type ContextFactory = () => PipelineContext;
6
+ type ContextFactory = () => AvComputeContext;
6
7
  export type RelationReadPlan = {
7
8
  readonly field: string;
8
9
  readonly cardinality: "one" | "many";
@@ -27,10 +28,10 @@ export type PlannedReadOperation = {
27
28
  * are never mutated and hidden dependencies are resolved through the Core
28
29
  * Contract.
29
30
  */
30
- export declare function planReadOperation(core: CoreContract, active: Contract, behaviors: FrameworkBehaviorsConfig | undefined, request: OperationExecutionRequest, args: unknown): PlannedReadOperation;
31
+ export declare function planReadOperation(core: AvContractCore, model: AvAdapterModel, active: AvContract, compute: ResolvedComputeConfig | undefined, request: OperationExecutionRequest, args: unknown): PlannedReadOperation;
31
32
  /**
32
33
  * Materialize computed scalar reads and remove internal dependency fields,
33
34
  * against `active` — the Contract `planReadOperation` was given as `active`.
34
35
  */
35
- export declare function materializeReadOperation(active: Contract, behaviors: FrameworkBehaviorsConfig | undefined, request: OperationExecutionRequest, plan: PlannedReadOperation, value: unknown, contextFactory: ContextFactory): Promise<unknown>;
36
+ export declare function materializeReadOperation(active: AvContract, compute: ResolvedComputeConfig | undefined, request: OperationExecutionRequest, plan: PlannedReadOperation, value: unknown, contextFactory: ContextFactory): Promise<unknown>;
36
37
  export {};