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

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 (338) hide show
  1. package/CHANGELOG.md +2068 -1
  2. package/ERRORS.md +142 -0
  3. package/README.md +485 -60
  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 +33 -11
  8. package/dist/adapters/adapter-identifier.d.ts +15 -6
  9. package/dist/adapters/adapter-identifier.js +6 -1
  10. package/dist/adapters/adapter-model.d.ts +18 -9
  11. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  12. package/dist/adapters/adapter-operation.d.ts +21 -6
  13. package/dist/adapters/adapter-resource.d.ts +23 -9
  14. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  15. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  16. package/dist/adapters/adapter.interface.d.ts +59 -29
  17. package/dist/avz/avz-check.factory.d.ts +83 -0
  18. package/dist/avz/avz-check.factory.js +116 -0
  19. package/dist/avz/avz-check.registry.d.ts +35 -0
  20. package/dist/avz/avz-check.registry.js +9 -0
  21. package/dist/avz/avz.d.ts +203 -0
  22. package/dist/{json → avz}/avz.js +150 -8
  23. package/dist/{json → avz}/index.d.ts +2 -1
  24. package/dist/{json → avz}/json-shape.registry.d.ts +9 -8
  25. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  26. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  27. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  28. package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
  29. package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
  30. package/dist/compiler/contract.compiler.d.ts +23 -17
  31. package/dist/compiler/contract.compiler.js +753 -443
  32. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  33. package/dist/compiler/create-requirements.projector.js +423 -0
  34. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  35. package/dist/compiler/field-validator.compiler.js +238 -0
  36. package/dist/compiler/managed-elsewhere.projector.d.ts +52 -0
  37. package/dist/compiler/managed-elsewhere.projector.js +179 -0
  38. package/dist/compiler/managed-elsewhere.validator.d.ts +9 -0
  39. package/dist/compiler/managed-elsewhere.validator.js +74 -0
  40. package/dist/config/any-framework-config.d.ts +19 -12
  41. package/dist/config/computed-fields.d.ts +62 -0
  42. package/dist/config/computed-fields.js +73 -0
  43. package/dist/config/config-diagnostic.d.ts +11 -4
  44. package/dist/config/config-diagnostic.guidance.d.ts +6 -0
  45. package/dist/config/config-diagnostic.guidance.js +32 -0
  46. package/dist/config/config-layer.d.ts +15 -6
  47. package/dist/config/config.resolver.d.ts +98 -31
  48. package/dist/config/config.resolver.js +173 -44
  49. package/dist/config/config.validator.d.ts +7 -7
  50. package/dist/config/config.validator.js +792 -69
  51. package/dist/config/define-resource.d.ts +53 -0
  52. package/dist/config/define-resource.js +14 -0
  53. package/dist/config/effective-fields.d.ts +19 -23
  54. package/dist/config/entrypoint.normalizer.d.ts +4 -3
  55. package/dist/config/exact-framework-config.d.ts +325 -0
  56. package/dist/config/field-compute.resolver.d.ts +21 -0
  57. package/dist/config/field-compute.resolver.js +123 -0
  58. package/dist/config/field-pipeline-config.d.ts +47 -0
  59. package/dist/config/forced-operation.validator.d.ts +10 -0
  60. package/dist/config/forced-operation.validator.js +66 -0
  61. package/dist/config/framework-config.d.ts +148 -39
  62. package/dist/config/framework-exemptions-config.d.ts +91 -0
  63. package/dist/config/framework-exemptions-config.js +1 -0
  64. package/dist/config/framework-field-definition.d.ts +78 -0
  65. package/dist/config/framework-field-definition.js +28 -0
  66. package/dist/config/framework-resources-config.d.ts +127 -0
  67. package/dist/config/framework-resources-config.js +1 -0
  68. package/dist/config/pipeline-config.d.ts +56 -20
  69. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  70. package/dist/config/pipeline-tree.resolver.js +220 -0
  71. package/dist/config/stage-type.eraser.d.ts +65 -0
  72. package/dist/config/stage-type.eraser.js +1 -0
  73. package/dist/contracts/access-route.rules.d.ts +10 -0
  74. package/dist/contracts/access-route.rules.js +45 -0
  75. package/dist/contracts/capability.d.ts +37 -12
  76. package/dist/contracts/capability.js +20 -0
  77. package/dist/contracts/client-contract-structure.validator.d.ts +621 -114
  78. package/dist/contracts/client-contract-structure.validator.js +189 -10
  79. package/dist/contracts/contract-access.d.ts +29 -0
  80. package/dist/contracts/contract-access.js +1 -0
  81. package/dist/contracts/contract-canonicalizer.d.ts +27 -3
  82. package/dist/contracts/contract-canonicalizer.js +168 -29
  83. package/dist/contracts/contract-hash.d.ts +11 -7
  84. package/dist/contracts/contract-hash.js +4 -3
  85. package/dist/contracts/contract-limits.d.ts +4 -1
  86. package/dist/contracts/contract-limits.js +1 -0
  87. package/dist/contracts/contract-lookup.d.ts +5 -5
  88. package/dist/contracts/contract-protocol.d.ts +4 -4
  89. package/dist/contracts/contract.d.ts +51 -17
  90. package/dist/contracts/create-requirements.d.ts +35 -0
  91. package/dist/contracts/create-requirements.js +1 -0
  92. package/dist/contracts/enum-definition.d.ts +1 -1
  93. package/dist/contracts/field-check.d.ts +101 -0
  94. package/dist/contracts/field-check.js +1 -0
  95. package/dist/contracts/field.d.ts +109 -42
  96. package/dist/contracts/identifier.d.ts +4 -4
  97. package/dist/contracts/json-schema.projector.d.ts +11 -0
  98. package/dist/contracts/json-schema.projector.js +78 -0
  99. package/dist/contracts/json-shape.d.ts +12 -1
  100. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  101. package/dist/contracts/resource-operations.d.ts +28 -28
  102. package/dist/contracts/resource.d.ts +15 -9
  103. package/dist/contracts/scalar-value-type.d.ts +17 -15
  104. package/dist/contracts/scalar.d.ts +3 -3
  105. package/dist/contracts/transaction-capability.d.ts +1 -1
  106. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  107. package/dist/framework/access-facade.d.ts +116 -0
  108. package/dist/framework/access-facade.js +120 -0
  109. package/dist/framework/contract-view.d.ts +315 -145
  110. package/dist/framework/framework-construction.error.d.ts +21 -11
  111. package/dist/framework/framework-construction.error.js +20 -4
  112. package/dist/framework/framework.d.ts +71 -26
  113. package/dist/framework/framework.factory.d.ts +8 -6
  114. package/dist/framework/framework.factory.js +150 -38
  115. package/dist/framework/operation-facade.d.ts +192 -54
  116. package/dist/framework/operation-facade.js +10 -1
  117. package/dist/index.d.ts +67 -50
  118. package/dist/index.js +7 -6
  119. package/dist/internal.d.ts +20 -10
  120. package/dist/internal.js +9 -1
  121. package/dist/operations/database-refusal.d.ts +51 -0
  122. package/dist/operations/database-refusal.js +45 -0
  123. package/dist/operations/operation-arguments.d.ts +381 -228
  124. package/dist/operations/operation-call.d.ts +31 -28
  125. package/dist/operations/operation-identity.d.ts +10 -10
  126. package/dist/operations/operation-result.d.ts +25 -23
  127. package/dist/operations/operation-validator-core.d.ts +6 -6
  128. package/dist/operations/operation-validator-core.js +172 -38
  129. package/dist/operations/operation-validator.d.ts +10 -10
  130. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  131. package/dist/operations/structural-limits.walker.d.ts +7 -7
  132. package/dist/operations/structural-limits.walker.js +145 -0
  133. package/dist/operations/validation-code.d.ts +11 -6
  134. package/dist/operations/validation-code.guidance.d.ts +6 -0
  135. package/dist/operations/validation-code.guidance.js +90 -0
  136. package/dist/operations/validation-code.js +4 -0
  137. package/dist/operations/write-scope.resolver.d.ts +10 -6
  138. package/dist/operations/write-scope.resolver.js +2 -0
  139. package/dist/policy/access-provider.interface.d.ts +91 -0
  140. package/dist/policy/access-provider.interface.js +1 -0
  141. package/dist/policy/access-provider.registry.d.ts +17 -0
  142. package/dist/policy/access-provider.registry.js +15 -0
  143. package/dist/policy/access-question.d.ts +20 -0
  144. package/dist/policy/access-question.js +1 -0
  145. package/dist/policy/access-question.registry.d.ts +5 -0
  146. package/dist/policy/access-question.registry.js +19 -0
  147. package/dist/policy/access-question.runtime.d.ts +36 -0
  148. package/dist/policy/access-question.runtime.js +297 -0
  149. package/dist/policy/access-verb.table.d.ts +56 -0
  150. package/dist/policy/access-verb.table.js +21 -0
  151. package/dist/policy/access-verbs.d.ts +46 -0
  152. package/dist/policy/access-verbs.js +1 -0
  153. package/dist/policy/policy-admission.d.ts +20 -0
  154. package/dist/policy/policy-admission.js +409 -0
  155. package/dist/policy/policy-after-update.runtime.d.ts +79 -0
  156. package/dist/policy/policy-after-update.runtime.js +208 -0
  157. package/dist/policy/policy-condition.d.ts +15 -0
  158. package/dist/policy/policy-condition.js +36 -0
  159. package/dist/policy/policy-engine.d.ts +205 -0
  160. package/dist/policy/policy-engine.js +1 -0
  161. package/dist/policy/policy-named-rows.d.ts +18 -0
  162. package/dist/policy/policy-named-rows.js +51 -0
  163. package/dist/policy/policy-nested-write.runtime.d.ts +44 -0
  164. package/dist/policy/policy-nested-write.runtime.js +545 -0
  165. package/dist/policy/policy-read.runtime.d.ts +81 -0
  166. package/dist/policy/policy-read.runtime.js +503 -0
  167. package/dist/policy/policy-reference-write.runtime.d.ts +51 -0
  168. package/dist/policy/policy-reference-write.runtime.js +345 -0
  169. package/dist/policy/policy-request.d.ts +41 -0
  170. package/dist/policy/policy-request.js +63 -0
  171. package/dist/policy/policy-session.d.ts +106 -0
  172. package/dist/policy/policy-session.js +295 -0
  173. package/dist/policy/policy-startup.validator.d.ts +10 -0
  174. package/dist/policy/policy-startup.validator.js +112 -0
  175. package/dist/policy/policy-write.runtime.d.ts +39 -0
  176. package/dist/policy/policy-write.runtime.js +532 -0
  177. package/dist/prebuilt/core-version.generated.d.ts +2 -0
  178. package/dist/prebuilt/core-version.generated.js +1 -0
  179. package/dist/prebuilt/prebuilt-changes.d.ts +29 -0
  180. package/dist/prebuilt/prebuilt-changes.js +65 -0
  181. package/dist/prebuilt/prebuilt-contracts.d.ts +40 -0
  182. package/dist/prebuilt/prebuilt-contracts.emitter.d.ts +16 -0
  183. package/dist/prebuilt/prebuilt-contracts.emitter.js +50 -0
  184. package/dist/prebuilt/prebuilt-contracts.js +1 -0
  185. package/dist/prebuilt/prebuilt-contracts.loader.d.ts +19 -0
  186. package/dist/prebuilt/prebuilt-contracts.loader.js +77 -0
  187. package/dist/prebuilt/prebuilt-inputs.fingerprint.d.ts +16 -0
  188. package/dist/prebuilt/prebuilt-inputs.fingerprint.js +229 -0
  189. package/dist/protocol/absent-route.responder.d.ts +17 -34
  190. package/dist/protocol/absent-route.responder.js +53 -20
  191. package/dist/protocol/contract-document.responder.d.ts +5 -4
  192. package/dist/protocol/contract-document.responder.js +2 -2
  193. package/dist/protocol/http-request.decoder.d.ts +33 -13
  194. package/dist/protocol/http-request.decoder.js +34 -11
  195. package/dist/protocol/http-request.reader.d.ts +9 -6
  196. package/dist/protocol/http-request.reader.js +1 -0
  197. package/dist/protocol/http-response.encoder.d.ts +4 -4
  198. package/dist/protocol/http-response.encoder.js +94 -55
  199. package/dist/protocol/http-status.table.d.ts +2 -2
  200. package/dist/protocol/operation-response.guard.d.ts +2 -2
  201. package/dist/protocol/protocol-headers.d.ts +3 -3
  202. package/dist/protocol/protocol-surface.d.ts +10 -5
  203. package/dist/protocol/protocol-surface.js +7 -0
  204. package/dist/protocol/protocol.binder.d.ts +66 -28
  205. package/dist/protocol/protocol.binder.js +16 -10
  206. package/dist/protocol/protocol.handler.d.ts +34 -14
  207. package/dist/protocol/protocol.handler.js +122 -18
  208. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  209. package/dist/protocol/unmounted-route.error.js +2 -2
  210. package/dist/runtime/caller-data.copier.d.ts +22 -7
  211. package/dist/runtime/caller-data.copier.js +30 -17
  212. package/dist/runtime/caller-data.door.d.ts +18 -11
  213. package/dist/runtime/caller-data.door.js +6 -4
  214. package/dist/runtime/computed-read-runtime.d.ts +12 -6
  215. package/dist/runtime/computed-read-runtime.js +271 -71
  216. package/dist/runtime/computed-value.error.d.ts +7 -6
  217. package/dist/runtime/computed-value.error.js +5 -4
  218. package/dist/runtime/context-executor.runtime.d.ts +60 -0
  219. package/dist/runtime/context-executor.runtime.js +277 -0
  220. package/dist/runtime/core-class.brand.d.ts +10 -0
  221. package/dist/runtime/core-class.brand.js +21 -0
  222. package/dist/runtime/create-requirement.d.ts +34 -79
  223. package/dist/runtime/create-requirement.js +205 -74
  224. package/dist/runtime/decimal.d.ts +16 -2
  225. package/dist/runtime/decimal.js +22 -1
  226. package/dist/runtime/diagnostics-reporter.d.ts +91 -30
  227. package/dist/runtime/diagnostics-reporter.js +37 -1
  228. package/dist/runtime/error-boundary.d.ts +73 -9
  229. package/dist/runtime/error-boundary.js +57 -19
  230. package/dist/runtime/error-guidance.d.ts +12 -0
  231. package/dist/runtime/error-guidance.js +1 -0
  232. package/dist/runtime/error.catalog.d.ts +49 -0
  233. package/dist/runtime/error.catalog.js +49 -0
  234. package/dist/runtime/execution-options.d.ts +18 -2
  235. package/dist/runtime/field-check.evaluator.d.ts +27 -0
  236. package/dist/runtime/field-check.evaluator.js +521 -0
  237. package/dist/runtime/field-compute.d.ts +65 -0
  238. package/dist/runtime/field-compute.js +1 -0
  239. package/dist/runtime/field-stage.plan.d.ts +15 -0
  240. package/dist/runtime/field-stage.plan.js +27 -0
  241. package/dist/runtime/field-stage.runtime.d.ts +37 -0
  242. package/dist/runtime/field-stage.runtime.js +147 -0
  243. package/dist/runtime/field-validator.runtime.d.ts +29 -0
  244. package/dist/runtime/field-validator.runtime.js +126 -0
  245. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  246. package/dist/runtime/framework-error-class.table.js +25 -0
  247. package/dist/runtime/framework-error.d.ts +68 -8
  248. package/dist/runtime/framework-error.factory.d.ts +4 -0
  249. package/dist/runtime/framework-error.factory.js +15 -0
  250. package/dist/runtime/framework-error.js +32 -2
  251. package/dist/runtime/framework-warning.emitter.d.ts +6 -0
  252. package/dist/runtime/framework-warning.emitter.js +8 -0
  253. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  254. package/dist/runtime/interceptor-next.error.js +6 -0
  255. package/dist/runtime/json-value.d.ts +11 -6
  256. package/dist/runtime/level-lifecycle.runtime.d.ts +26 -0
  257. package/dist/runtime/level-lifecycle.runtime.js +40 -0
  258. package/dist/runtime/misuse-reporter.d.ts +12 -12
  259. package/dist/runtime/mutation-planner.d.ts +20 -16
  260. package/dist/runtime/mutation-planner.js +48 -35
  261. package/dist/runtime/nested-write.walker.d.ts +32 -0
  262. package/dist/runtime/nested-write.walker.js +73 -0
  263. package/dist/runtime/operation-code.guidance.d.ts +6 -0
  264. package/dist/runtime/operation-code.guidance.js +167 -0
  265. package/dist/runtime/operation-request.d.ts +45 -11
  266. package/dist/runtime/operation-response.d.ts +17 -17
  267. package/dist/runtime/operation-runtime.d.ts +133 -27
  268. package/dist/runtime/operation-runtime.js +576 -84
  269. package/dist/runtime/outcome-mapper.d.ts +17 -5
  270. package/dist/runtime/outcome-mapper.js +23 -6
  271. package/dist/runtime/output-validator.d.ts +11 -11
  272. package/dist/runtime/output-validator.js +3 -3
  273. package/dist/runtime/owned-execution.registry.d.ts +16 -6
  274. package/dist/runtime/pipe-output.validator.d.ts +43 -18
  275. package/dist/runtime/pipe-output.validator.js +15 -13
  276. package/dist/runtime/pipeline.d.ts +221 -34
  277. package/dist/runtime/readonly-value.d.ts +47 -0
  278. package/dist/runtime/readonly-value.js +189 -0
  279. package/dist/runtime/referential-action.d.ts +1 -1
  280. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  281. package/dist/runtime/request-envelope.validator.js +12 -7
  282. package/dist/runtime/request-id.d.ts +1 -1
  283. package/dist/runtime/request-state.d.ts +14 -0
  284. package/dist/runtime/request-state.js +1 -0
  285. package/dist/runtime/request-state.resolver.d.ts +12 -0
  286. package/dist/runtime/request-state.resolver.js +20 -0
  287. package/dist/runtime/scalar-runtime.d.ts +33 -25
  288. package/dist/runtime/scalar-runtime.js +105 -38
  289. package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
  290. package/dist/runtime/unsent-value.normalizer.js +128 -0
  291. package/dist/transactions/deferred-operation.d.ts +35 -20
  292. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  293. package/dist/transactions/operation-arguments-encoder.js +8 -3
  294. package/dist/transactions/operation-fingerprint.js +2 -2
  295. package/dist/transactions/sql-statement.d.ts +85 -0
  296. package/dist/transactions/sql-statement.js +47 -0
  297. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  298. package/dist/transactions/sql-statement.validator.js +167 -0
  299. package/dist/transactions/transaction-envelope.d.ts +9 -8
  300. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  301. package/dist/transactions/transaction-integrity-error.js +7 -2
  302. package/dist/transactions/transaction-plan-assembler.d.ts +30 -13
  303. package/dist/transactions/transaction-plan-assembler.js +184 -32
  304. package/dist/transactions/transaction-plan-validator.d.ts +50 -25
  305. package/dist/transactions/transaction-plan-validator.js +96 -38
  306. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  307. package/dist/transactions/transaction-reference-resolver.d.ts +21 -3
  308. package/dist/transactions/transaction-reference-resolver.js +26 -14
  309. package/dist/transactions/transaction-reference-validator.d.ts +74 -4
  310. package/dist/transactions/transaction-reference-validator.js +129 -71
  311. package/dist/transactions/transaction-reference.d.ts +14 -14
  312. package/dist/transactions/transaction-reference.js +5 -0
  313. package/dist/transactions/transaction-request.d.ts +22 -9
  314. package/dist/transactions/transaction-response.d.ts +6 -6
  315. package/dist/transactions/transaction-runtime.d.ts +12 -8
  316. package/dist/transactions/transaction-runtime.js +218 -50
  317. package/dist/transactions/transaction-settlement.runtime.d.ts +52 -0
  318. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  319. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  320. package/dist/transactions/transaction-slot-path-error.js +4 -2
  321. package/dist/transactions/transaction-slot-writer.js +2 -2
  322. package/dist/transactions/transaction-stage.runtime.d.ts +83 -0
  323. package/dist/transactions/transaction-stage.runtime.js +126 -0
  324. package/package.json +11 -9
  325. package/src/runtime/field-check.evaluator.ts +720 -0
  326. package/dist/config/define-fields.d.ts +0 -42
  327. package/dist/config/define-fields.js +0 -3
  328. package/dist/config/framework-behaviors-config.d.ts +0 -30
  329. package/dist/config/framework-fields-config.d.ts +0 -42
  330. package/dist/config/framework-restrictions-config.d.ts +0 -142
  331. package/dist/json/avz.d.ts +0 -96
  332. package/dist/runtime/field-behavior.d.ts +0 -48
  333. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  334. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  335. /package/dist/{json → avz}/index.js +0 -0
  336. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  337. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  338. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,81 +1,249 @@
1
- import { recordWriteFactsOf } from "../runtime/create-requirement.js";
2
- import { planOperationArgumentsPath } from "../runtime/error-boundary.js";
3
- import { internalFailure } from "../runtime/operation-response.js";
4
- import { executeValidatedOperation } from "../runtime/operation-runtime.js";
1
+ import { transactionLevelsOf } from "../config/pipeline-tree.resolver.js";
2
+ import { openRequestPolicy, } from "../policy/policy-request.js";
3
+ import { AdapterBoundary, planOperationArgumentsPath, planStepPath, sanitizeOperationFailure, } from "../runtime/error-boundary.js";
4
+ import { internalFailure, operationSuccess, } from "../runtime/operation-response.js";
5
+ import { admitOperation, EVERY_FIELD, executeAdmittedOperation, prepareStep, STEP_PIPES, withRequestState, } from "../runtime/operation-runtime.js";
5
6
  import { mapValidationOutcome } from "../runtime/outcome-mapper.js";
7
+ import { refusedStageOutput, serverContractFor, } from "../runtime/pipe-output.validator.js";
6
8
  import { resolveCascadeClosure } from "../runtime/referential-action.js";
7
- import { TransactionIntegrityError } from "./transaction-integrity-error.js";
9
+ import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
8
10
  import { validateTransactionPlan } from "./transaction-plan-validator.js";
9
- import { resolveTransactionReferences } from "./transaction-reference-resolver.js";
11
+ import { collectTransactionReferenceCandidates } from "./transaction-reference-collector.js";
12
+ import { resolveSqlStatement, resolveTransactionReferences, } from "./transaction-reference-resolver.js";
13
+ import { validateReferenceSlots } from "./transaction-reference-validator.js";
10
14
  import { transactionCommitted, transactionInfrastructureFailure, transactionOperationFailure, } from "./transaction-response.js";
11
- const TRANSACTION_ABORT = Object.freeze({ reason: "aventara-transaction-abort" });
12
- export function createTransactionRuntime(dependencies) {
13
- const { adapter, ...runtimeDependencies } = dependencies;
14
- const pipelineDependencies = {
15
- ...runtimeDependencies,
16
- recordWrites: recordWriteFactsOf(adapter),
17
- };
15
+ import { settleTransaction } from "./transaction-settlement.runtime.js";
16
+ import { TRANSACTION_PIPES, touchedTransactionLevels, transactionFacts, } from "./transaction-stage.runtime.js";
17
+ export function createTransactionRuntime(dependencies, pipelineDependencies) {
18
+ const { adapter } = dependencies;
18
19
  const planDependencies = {
19
20
  ...pipelineDependencies,
20
21
  cascades: resolveCascadeClosure(adapter.referentialActions),
22
+ sqlStatements: adapter.sqlStatements === true,
21
23
  };
22
- return async (request, diagnostics, origins, planArguments) => {
24
+ return async (seeded, diagnostics, origins, planArguments, caller) => {
25
+ const request = withRequestState(seeded);
23
26
  const validation = await validateTransactionPlan(planDependencies, request, origins, planArguments);
24
27
  if (!validation.ok) {
25
28
  return validation.response;
26
29
  }
27
- return executeTransactionPlan(adapter, pipelineDependencies, validation.plan, diagnostics);
30
+ return executeTransactionPlan(dependencies, pipelineDependencies, request, validation.plan, request.state, diagnostics, caller);
28
31
  };
29
32
  }
30
- async function executeTransactionPlan(adapter, dependencies, plan, diagnostics) {
31
- const ledger = { results: [], failure: undefined };
32
- const infrastructureFailure = (error) => {
33
- const operation = ledger.failure?.operation;
34
- diagnostics.transaction(operation)(error, "A3002");
35
- return transactionInfrastructureFailure(operation);
33
+ function planOrigin(request, plan) {
34
+ for (const step of plan.operations) {
35
+ if (step.kind === "operation") {
36
+ return step.request;
37
+ }
38
+ }
39
+ return request;
40
+ }
41
+ function stepView(step, args) {
42
+ if (step.kind === "sql") {
43
+ return {
44
+ sql: {
45
+ strings: step.strings,
46
+ values: step.values.map((value) => value.kind === "value"
47
+ ? value.value
48
+ : { $ref: { operation: value.operation, path: [value.field] } }),
49
+ },
50
+ };
51
+ }
52
+ return {
53
+ resource: step.request.resource,
54
+ family: step.request.family,
55
+ variant: step.request.variant,
56
+ args,
57
+ };
58
+ }
59
+ function pathKey(path) {
60
+ return JSON.stringify(path);
61
+ }
62
+ function relativeSlotPath(operation, path) {
63
+ return path.slice(planOperationArgumentsPath(operation.index).length);
64
+ }
65
+ function standingReferences(core, operation, args, steps, subject) {
66
+ const candidates = collectTransactionReferenceCandidates(serverContractFor(core, operation.contract), operation.request, operation.index, args);
67
+ const validation = validateReferenceSlots(candidates, steps, operation.index);
68
+ if (validation.ok) {
69
+ return validation;
70
+ }
71
+ const { issue } = validation;
72
+ const refused = refusedStageOutput(operation.request, [
73
+ {
74
+ ...issue,
75
+ path: ["arguments", ...relativeSlotPath(operation, issue.path ?? [])],
76
+ },
77
+ ], subject);
78
+ if (refused === undefined) {
79
+ throw new TypeError("A refused reference produced no refusal.");
80
+ }
81
+ return { ok: false, ...refused };
82
+ }
83
+ async function executeTransactionPlan(runtime, dependencies, request, plan, state, diagnostics, caller) {
84
+ const { adapter } = runtime;
85
+ const steps = new Map();
86
+ const stateful = (operation) => {
87
+ const known = steps.get(operation);
88
+ if (known !== undefined) {
89
+ return known;
90
+ }
91
+ const settle = (policy) => {
92
+ const step = policy === undefined
93
+ ? { ...operation.request, state }
94
+ : { ...operation.request, state, policy };
95
+ steps.set(operation, step);
96
+ return step;
97
+ };
98
+ const policy = openRequestPolicy(runtime.config.policy, runtime.contracts.core, { origin: operation.request.origin, state }, caller, adapter);
99
+ return policy instanceof Promise ? policy.then(settle) : settle(policy);
36
100
  };
37
- if (typeof adapter.transaction !== "function") {
38
- return infrastructureFailure(new TransactionIntegrityError("transaction-unavailable"));
101
+ const admitted = [];
102
+ const standing = [];
103
+ for (const step of plan.operations) {
104
+ if (step.kind === "sql") {
105
+ admitted.push({ ok: true, args: undefined, piped: false });
106
+ standing.push([]);
107
+ continue;
108
+ }
109
+ const report = diagnostics.operation(step.request, step.index);
110
+ let stepRequest;
111
+ try {
112
+ const opened = stateful(step);
113
+ stepRequest = opened instanceof Promise ? await opened : opened;
114
+ }
115
+ catch (error) {
116
+ report(error, "A3000");
117
+ return transactionOperationFailure(internalFailure(), step.index);
118
+ }
119
+ const admission = await admitOperation(dependencies, stepRequest, step.contract, step.arguments, planOperationArgumentsPath(step.index), report, { requestId: request.requestId, transaction: undefined, state }, {
120
+ select: EVERY_FIELD,
121
+ validation: { transactionReferences: true },
122
+ beforeBegin: true,
123
+ });
124
+ if (!admission.ok) {
125
+ return transactionOperationFailure(admission.response, step.index);
126
+ }
127
+ if (!admission.piped) {
128
+ standing.push(step.references);
129
+ }
130
+ else {
131
+ const references = standingReferences(dependencies.contracts.core, step, admission.args, plan.operations, STEP_PIPES);
132
+ if (!references.ok) {
133
+ report(references.error, "A3004");
134
+ return transactionOperationFailure(references.response, step.index);
135
+ }
136
+ standing.push(references.references);
137
+ }
138
+ admitted.push(admission);
39
139
  }
40
- const runPlanOperation = async (operation, executor) => {
140
+ const origin = planOrigin(request, plan);
141
+ const contract = dependencies.contracts[origin.origin];
142
+ const tree = dependencies.config[origin.origin].pipelines;
143
+ const view = plan.operations.map((step, index) => stepView(step, admitted[index]?.args));
144
+ const runPlanOperation = async (operation, args, transactionPiped, executor, results, outer) => {
41
145
  const report = diagnostics.operation(operation.request, operation.index);
146
+ const argumentsPath = planOperationArgumentsPath(operation.index);
147
+ const opened = stateful(operation);
148
+ const stepRequest = opened instanceof Promise ? await opened : opened;
42
149
  try {
43
- const resolved = resolveTransactionReferences(operation, ledger.results);
150
+ let live = standing[operation.index] ?? operation.references;
151
+ if (transactionPiped) {
152
+ const references = standingReferences(dependencies.contracts.core, operation, args, plan.operations, TRANSACTION_PIPES);
153
+ if (!references.ok) {
154
+ report(references.error, "A3004");
155
+ return references.response;
156
+ }
157
+ live = references.references;
158
+ }
159
+ const resolved = resolveTransactionReferences({
160
+ ...operation,
161
+ arguments: args,
162
+ references: live,
163
+ }, results);
44
164
  if (!resolved.ok) {
45
165
  return mapValidationOutcome(resolved.issues);
46
166
  }
47
- return await executeValidatedOperation(dependencies, operation.request, operation.contract, resolved.arguments, planOperationArgumentsPath(operation.index), executor, report);
167
+ const written = new Set(live
168
+ .filter((slot) => slot.written)
169
+ .map((slot) => pathKey(relativeSlotPath(operation, slot.path))));
170
+ const prepared = await prepareStep(dependencies, stepRequest, operation.contract, resolved.arguments, argumentsPath, report, executor, {
171
+ written: (path) => written.has(pathKey(path)),
172
+ transactionPiped,
173
+ pipedAroundReferences: admitted[operation.index]?.piped === true &&
174
+ (live.length > 0 || operation.references.length > 0),
175
+ }, outer);
176
+ if (!prepared.ok) {
177
+ return prepared.response;
178
+ }
179
+ return await executeAdmittedOperation(dependencies, stepRequest, operation.contract, prepared.args, argumentsPath, { kind: "transaction", executor, outer }, report);
48
180
  }
49
181
  catch (error) {
50
182
  report(error, "A3000");
51
183
  return internalFailure();
52
184
  }
53
185
  };
54
- try {
55
- await adapter.transaction(async (executor) => {
56
- for (const operation of plan.operations) {
57
- const response = await runPlanOperation(operation, executor);
58
- if (response.cause !== null) {
59
- ledger.failure = { response, operation: operation.index };
60
- throw TRANSACTION_ABORT;
61
- }
62
- ledger.results.push(response.data);
186
+ const runSqlStatement = async (step, executor, results) => {
187
+ const report = diagnostics.transaction(step.index);
188
+ const boundary = new AdapterBoundary();
189
+ try {
190
+ const resolved = resolveSqlStatement(step, results);
191
+ if (!resolved.ok) {
192
+ return mapValidationOutcome(resolved.issues);
193
+ }
194
+ if (typeof executor.executeSql !== "function") {
195
+ report(new AvTransactionIntegrityError("statement-unavailable"), "A3002");
196
+ return transactionInfrastructureFailure();
197
+ }
198
+ const executeSql = executor.executeSql.bind(executor);
199
+ try {
200
+ const rows = await boundary.execute(async () => {
201
+ const answer = await executeSql(resolved.statement);
202
+ if (!Array.isArray(answer)) {
203
+ throw new TypeError("Adapter executeSql must resolve the statement's rows as an array.");
204
+ }
205
+ return answer;
206
+ });
207
+ return operationSuccess([...rows], "A1000");
208
+ }
209
+ catch (error) {
210
+ return sanitizeOperationFailure(error, boundary.originOf(error), report, {
211
+ path: [...planStepPath(step.index), "values"],
212
+ arguments: resolved.statement.values,
213
+ });
63
214
  }
64
- });
65
- }
66
- catch (error) {
67
- if (error !== TRANSACTION_ABORT) {
68
- return infrastructureFailure(error);
69
215
  }
70
- return ledger.failure === undefined
71
- ? infrastructureFailure(new TransactionIntegrityError("foreign-abort"))
72
- : transactionOperationFailure(ledger.failure.response, ledger.failure.operation);
73
- }
74
- if (ledger.failure !== undefined) {
75
- return infrastructureFailure(new TransactionIntegrityError("resolved-after-abort"));
76
- }
77
- if (ledger.results.length !== plan.operations.length) {
78
- return infrastructureFailure(new TransactionIntegrityError("resolved-incomplete"));
216
+ catch (error) {
217
+ report(error, "A3000");
218
+ return internalFailure();
219
+ }
220
+ };
221
+ const settled = await settleTransaction({
222
+ adapter,
223
+ levels: touchedTransactionLevels(view, (resource) => transactionLevelsOf(tree, resource)),
224
+ plan: view,
225
+ contextOf: (current, executor) => dependencies.contexts.transaction({ requestId: origin.requestId, transaction: executor, state }, transactionFacts(contract, origin, current)),
226
+ failureView: { path: ["operations"], arguments: view },
227
+ report: diagnostics.transaction(),
228
+ runStep: (index, step, piped, executor, results, outer) => {
229
+ const operation = plan.operations[index];
230
+ if (operation === undefined) {
231
+ throw new TypeError(`Transaction step ${index} is not in the plan.`);
232
+ }
233
+ return operation.kind === "sql"
234
+ ? runSqlStatement(operation, executor, results)
235
+ : runPlanOperation(operation, step.args, piped, executor, results, outer);
236
+ },
237
+ });
238
+ switch (settled.kind) {
239
+ case "committed":
240
+ return transactionCommitted(settled.responses.map((response) => response.data));
241
+ case "rolled-back":
242
+ return settled.operation === undefined
243
+ ? settled.response
244
+ : transactionOperationFailure(settled.response, settled.operation);
245
+ case "broken":
246
+ diagnostics.transaction(settled.operation)(settled.error, "A3002");
247
+ return transactionInfrastructureFailure(settled.operation);
79
248
  }
80
- return transactionCommitted([...ledger.results]);
81
249
  }
@@ -0,0 +1,52 @@
1
+ import type { AvAdapter } from "../adapters/adapter.interface.js";
2
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
3
+ import type { AvAdapterTransactionExecutor } from "../adapters/adapter-transaction-executor.interface.js";
4
+ import type { ResolvedTransactionPipelineConfig } from "../config/pipeline-config.js";
5
+ import type { DiagnosticsReporter } from "../runtime/diagnostics-reporter.js";
6
+ import { type CallerArgumentsView, type OuterFailureLayer } from "../runtime/error-boundary.js";
7
+ import type { AvOperationFailureResponse, AvOperationResponse } from "../runtime/operation-response.js";
8
+ import type { AvTransactionContext } from "../runtime/pipeline.js";
9
+ import { type TransactionStepView } from "./transaction-stage.runtime.js";
10
+ /**
11
+ * Runs one step inside the open transaction: `step` as the transaction pipes
12
+ * left it, `piped` whether one ran, `results` the completed steps' data in plan
13
+ * order, `outer` where an error the step's own filters leave unhandled is handed:
14
+ * the touched Resources' transaction filters answer it once the transaction
15
+ * interceptors have unwound. Its answer is the step's own outcome.
16
+ */
17
+ type TransactionStepRunner<M extends AvAdapterModel> = (index: number, step: TransactionStepView, piped: boolean, executor: AvAdapterTransactionExecutor<M>, results: readonly unknown[], outer: OuterFailureLayer) => Promise<AvOperationResponse>;
18
+ /** How one transaction settled. */
19
+ type TransactionSettlement =
20
+ /** Committed: every step's own outcome, in plan order. */
21
+ {
22
+ readonly kind: "committed";
23
+ readonly responses: readonly AvOperationResponse[];
24
+ }
25
+ /** Rolled back on a deliberate outcome: a step's (with its index) or a stage's. */
26
+ | {
27
+ readonly kind: "rolled-back";
28
+ readonly response: AvOperationFailureResponse;
29
+ readonly operation: number | undefined;
30
+ }
31
+ /** The transaction contract broke: `A3002`, the error for diagnostics. */
32
+ | {
33
+ readonly kind: "broken";
34
+ readonly error: unknown;
35
+ readonly operation: number | undefined;
36
+ };
37
+ type TransactionSettlementInput<M extends AvAdapterModel> = {
38
+ readonly adapter: AvAdapter<M>;
39
+ /** The touched Resources' transaction levels, outer to inner. */
40
+ readonly levels: readonly ResolvedTransactionPipelineConfig[];
41
+ readonly plan: readonly TransactionStepView[];
42
+ /** The ctx a transaction stage is told, bound to the open transaction. */
43
+ readonly contextOf: (plan: readonly TransactionStepView[], executor: AvAdapterTransactionExecutor<M>) => AvTransactionContext;
44
+ /** What a stage failure's filters may read as the caller's arguments. */
45
+ readonly failureView: CallerArgumentsView;
46
+ /** The channel a transaction stage's own failure is reported on. */
47
+ readonly report: DiagnosticsReporter;
48
+ readonly runStep: TransactionStepRunner<M>;
49
+ };
50
+ /** Runs `plan` inside one Adapter transaction, its stages around its steps, and settles it. */
51
+ export declare function settleTransaction<M extends AvAdapterModel>(input: TransactionSettlementInput<M>): Promise<TransactionSettlement>;
52
+ export {};
@@ -0,0 +1,120 @@
1
+ import { filterChain, resolveUnhandledFailure, sanitizeOperationFailure, } from "../runtime/error-boundary.js";
2
+ import { thrownFailure } from "../runtime/framework-error.factory.js";
3
+ import { operationFailure } from "../runtime/operation-response.js";
4
+ import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
5
+ import { resolveTransactionStageFailure, runTransactionStages, TRANSACTION_ABORT, } from "./transaction-stage.runtime.js";
6
+ export async function settleTransaction(input) {
7
+ const { adapter, levels, plan, contextOf } = input;
8
+ if (typeof adapter.transaction !== "function") {
9
+ return {
10
+ kind: "broken",
11
+ error: new AvTransactionIntegrityError("transaction-unavailable"),
12
+ operation: undefined,
13
+ };
14
+ }
15
+ const ledger = { results: [], responses: [], failure: undefined, deferred: undefined };
16
+ const { results, responses } = ledger;
17
+ const failedOperation = () => ledger.failure?.kind === "rolled-back"
18
+ ? ledger.failure.operation
19
+ : undefined;
20
+ try {
21
+ await adapter.transaction(async (executor) => {
22
+ const staged = await runTransactionStages(levels, plan, (current) => contextOf(current, executor), async ({ plan: current, piped }) => {
23
+ const outer = {
24
+ defer: (failure) => {
25
+ ledger.deferred = { failure, plan: current };
26
+ return sanitizeOperationFailure(failure.error, failure.boundary.originOf(failure.error), () => { }, failure.view);
27
+ },
28
+ };
29
+ for (const [index, step] of current.entries()) {
30
+ const response = await input.runStep(index, step, piped, executor, results, outer);
31
+ if (response.cause !== null) {
32
+ ledger.failure = {
33
+ kind: "rolled-back",
34
+ response,
35
+ operation: index,
36
+ };
37
+ throw thrownFailure(response);
38
+ }
39
+ results.push(response.data);
40
+ responses.push(response);
41
+ }
42
+ return [...results];
43
+ });
44
+ if (staged.kind === "broken") {
45
+ ledger.failure = { kind: "broken", error: staged.error };
46
+ throw TRANSACTION_ABORT;
47
+ }
48
+ const deferred = ledger.deferred;
49
+ if (deferred !== undefined && ledger.failure?.kind === "rolled-back") {
50
+ ledger.failure = {
51
+ ...ledger.failure,
52
+ response: await resolveUnhandledFailure(deferred.failure, filterChain(levels.flatMap((level) => level.filters), contextOf(deferred.plan, executor))),
53
+ };
54
+ }
55
+ if (staged.kind === "ran") {
56
+ if (ledger.failure === undefined && results.length !== plan.length) {
57
+ ledger.failure = {
58
+ kind: "broken",
59
+ error: new AvTransactionIntegrityError("steps-not-run"),
60
+ };
61
+ }
62
+ if (ledger.failure !== undefined) {
63
+ throw TRANSACTION_ABORT;
64
+ }
65
+ return;
66
+ }
67
+ if (ledger.failure === undefined) {
68
+ let response;
69
+ if (staged.kind === "denied") {
70
+ response = operationFailure("A4001", {
71
+ message: "Operation denied by a framework guard.",
72
+ });
73
+ }
74
+ else if (staged.kind === "refused") {
75
+ input.report(staged.refusal.error, "A3004");
76
+ response = staged.refusal.response;
77
+ }
78
+ else {
79
+ response = await resolveTransactionStageFailure(staged.error, levels, contextOf(plan, executor), input.report, input.failureView);
80
+ }
81
+ ledger.failure = {
82
+ kind: "rolled-back",
83
+ response,
84
+ operation: undefined,
85
+ };
86
+ }
87
+ throw TRANSACTION_ABORT;
88
+ });
89
+ }
90
+ catch (error) {
91
+ if (error !== TRANSACTION_ABORT) {
92
+ return { kind: "broken", error, operation: failedOperation() };
93
+ }
94
+ if (ledger.failure === undefined) {
95
+ return {
96
+ kind: "broken",
97
+ error: new AvTransactionIntegrityError("foreign-abort"),
98
+ operation: undefined,
99
+ };
100
+ }
101
+ return ledger.failure.kind === "broken"
102
+ ? { kind: "broken", error: ledger.failure.error, operation: undefined }
103
+ : ledger.failure;
104
+ }
105
+ if (ledger.failure !== undefined) {
106
+ return {
107
+ kind: "broken",
108
+ error: new AvTransactionIntegrityError("resolved-after-abort"),
109
+ operation: failedOperation(),
110
+ };
111
+ }
112
+ if (responses.length !== plan.length) {
113
+ return {
114
+ kind: "broken",
115
+ error: new AvTransactionIntegrityError("resolved-incomplete"),
116
+ operation: undefined,
117
+ };
118
+ }
119
+ return { kind: "committed", responses };
120
+ }
@@ -2,13 +2,13 @@
2
2
  * The ways a transaction slot path can fail to name a member of its argument
3
3
  * view. Each is a framework defect, not a caller error.
4
4
  */
5
- export type TransactionSlotPathViolation = "slot-prefix" | "absent-member" | "non-object-ancestor";
5
+ export type AvTransactionSlotPathViolation = "slot-prefix" | "absent-member" | "non-object-ancestor";
6
6
  /**
7
7
  * Thrown internally when a slot path does not name a member of its argument
8
8
  * view; the caller receives `A3000`, and the diagnostics sink receives this
9
9
  * error.
10
10
  */
11
- export declare class TransactionSlotPathError extends Error {
12
- readonly violation: TransactionSlotPathViolation;
13
- constructor(violation: TransactionSlotPathViolation);
11
+ export declare class AvTransactionSlotPathError extends Error {
12
+ readonly violation: AvTransactionSlotPathViolation;
13
+ constructor(violation: AvTransactionSlotPathViolation);
14
14
  }
@@ -1,13 +1,15 @@
1
+ import { brandCoreClass } from "../runtime/core-class.brand.js";
1
2
  const TRANSACTION_SLOT_PATH_MESSAGES = {
2
3
  "slot-prefix": "Transaction slot path does not name a member below the operation's arguments.",
3
4
  "absent-member": "Transaction slot path names an absent member of the operation arguments.",
4
5
  "non-object-ancestor": "Transaction slot path descends through a non-object value.",
5
6
  };
6
- export class TransactionSlotPathError extends Error {
7
+ export class AvTransactionSlotPathError extends Error {
7
8
  violation;
8
9
  constructor(violation) {
9
10
  super(TRANSACTION_SLOT_PATH_MESSAGES[violation]);
10
- this.name = "TransactionSlotPathError";
11
+ this.name = "AvTransactionSlotPathError";
11
12
  this.violation = violation;
12
13
  }
13
14
  }
15
+ brandCoreClass(AvTransactionSlotPathError, "AvTransactionSlotPathError");
@@ -1,6 +1,6 @@
1
- import { TransactionSlotPathError } from "./transaction-slot-path-error.js";
1
+ import { AvTransactionSlotPathError } from "./transaction-slot-path-error.js";
2
2
  function slotPathMismatch(violation) {
3
- throw new TransactionSlotPathError(violation);
3
+ throw new AvTransactionSlotPathError(violation);
4
4
  }
5
5
  function cloneContainerWithReplacement(container, property, replacement) {
6
6
  const array = Array.isArray(container);
@@ -0,0 +1,83 @@
1
+ import type { ResolvedTransactionPipelineConfig } from "../config/pipeline-config.js";
2
+ import type { AvContract } from "../contracts/contract.js";
3
+ import type { ContextFacts } from "../runtime/context-executor.runtime.js";
4
+ import type { DiagnosticsReporter } from "../runtime/diagnostics-reporter.js";
5
+ import { type CallerArgumentsView } from "../runtime/error-boundary.js";
6
+ import type { OperationExecutionRequest } from "../runtime/operation-request.js";
7
+ import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
8
+ import { type RefusedStageOutput } from "../runtime/pipe-output.validator.js";
9
+ import type { AvTransactionContext, AvTransactionStep } from "../runtime/pipeline.js";
10
+ import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
11
+ /**
12
+ * The framework-owned rollback request. It is thrown out of the Adapter transaction
13
+ * callback only after a failure is recorded, and a rejection is recognized as it
14
+ * solely by identity — never by message, shape or class. It is a control signal,
15
+ * not a failure, so it never reaches diagnostics.
16
+ */
17
+ export declare const TRANSACTION_ABORT: Readonly<{
18
+ readonly reason: "aventara-transaction-abort";
19
+ }>;
20
+ /** One plan step as a transaction stage reads it (the erased {@link AvTransactionStep}). */
21
+ export type TransactionStepView = AvTransactionStep;
22
+ /** The subject a refused transaction pipe output is reported under. */
23
+ export declare const TRANSACTION_PIPES = "Transaction pipes";
24
+ /**
25
+ * The `$` facts a transaction stage is told: the plan as `$args`, not one
26
+ * operation (`$operation` is absent). Each ctx holds its own frozen copy of the
27
+ * plan, a `Date` or a `Uint8Array` in a step's arguments fresh.
28
+ */
29
+ export declare function transactionFacts(contract: AvContract, request: Pick<OperationExecutionRequest, "origin" | "requestId" | "transport">, plan: readonly TransactionStepView[]): ContextFacts;
30
+ /** How the transaction stages around a plan's steps ended. */
31
+ type TransactionStagesOutcome =
32
+ /** Every stage and step ran; the steps' results, as the stages left them. */
33
+ {
34
+ readonly kind: "ran";
35
+ }
36
+ /** A transaction guard returned `false`: `A4001`. */
37
+ | {
38
+ readonly kind: "denied";
39
+ }
40
+ /** A transaction pipe returned something that is not the plan: `A3004`. */
41
+ | {
42
+ readonly kind: "refused";
43
+ readonly refusal: RefusedStageOutput;
44
+ }
45
+ /** A stage or a step threw (the rollback request included). */
46
+ | {
47
+ readonly kind: "failed";
48
+ readonly error: unknown;
49
+ }
50
+ /**
51
+ * A transaction interceptor broke the stages' contract: it called `next()`
52
+ * twice (whatever it then did with the refusal). Answered `A3002`, past every
53
+ * filter, and the transaction rolls back.
54
+ */
55
+ | {
56
+ readonly kind: "broken";
57
+ readonly error: AvTransactionIntegrityError;
58
+ };
59
+ /**
60
+ * What the steps see after the stages: the plan, and whether a transaction pipe
61
+ * changed it, in which case every operation step's arguments are held to the
62
+ * server's rules and its validators again before it runs.
63
+ */
64
+ type StagedPlan = {
65
+ readonly plan: readonly TransactionStepView[];
66
+ readonly piped: boolean;
67
+ };
68
+ /**
69
+ * Each touched Resource's transaction levels, root then overlay, Resources in the
70
+ * order their first top-level operation step appears. A SQL step touches nothing.
71
+ */
72
+ export declare function touchedTransactionLevels(plan: readonly TransactionStepView[], levelsOf: (resource: string) => readonly ResolvedTransactionPipelineConfig[]): readonly ResolvedTransactionPipelineConfig[];
73
+ /**
74
+ * Runs the transaction stages of `levels` around `runSteps`, inside an open
75
+ * transaction. Never throws: every way the stages can end is the outcome.
76
+ */
77
+ export declare function runTransactionStages(levels: readonly ResolvedTransactionPipelineConfig[], plan: readonly TransactionStepView[], contextOf: (plan: readonly TransactionStepView[]) => AvTransactionContext, runSteps: (staged: StagedPlan) => Promise<readonly unknown[]>): Promise<TransactionStagesOutcome>;
78
+ /**
79
+ * An error a transaction stage threw, through the touched Resources' filters in
80
+ * exact reverse (the first that handles it wins), then final sanitization.
81
+ */
82
+ export declare function resolveTransactionStageFailure(error: unknown, levels: readonly ResolvedTransactionPipelineConfig[], context: AvTransactionContext, report: DiagnosticsReporter, view: CallerArgumentsView): Promise<AvOperationFailureResponse>;
83
+ export {};