@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
@@ -0,0 +1,16 @@
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvContracts } from "../compiler/contract.compiler.js";
3
+ import { type AvPrebuiltContracts } from "./prebuilt-contracts.js";
4
+ /**
5
+ * The prebuilt file's value for Contracts `compileContracts` compiled from
6
+ * `model` and `config` (the configuration as authored; its `adapter` and
7
+ * `prebuilt`, if any, are no inputs): each Contract's canonical text, and the
8
+ * fingerprints of the inputs.
9
+ */
10
+ export declare function prebuiltContractsOf(model: AvAdapterModel, config: object, contracts: AvContracts): Promise<AvPrebuiltContracts>;
11
+ /**
12
+ * The generated module that exports `prebuilt` as `aventaraContracts`. Each
13
+ * Contract stays a string, so loading it is one `JSON.parse`; the type is
14
+ * imported for checking only.
15
+ */
16
+ export declare function emitPrebuiltContracts(prebuilt: AvPrebuiltContracts): string;
@@ -0,0 +1,50 @@
1
+ import { canonicalContractTextOf } from "../contracts/contract-canonicalizer.js";
2
+ import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
3
+ import { CORE_VERSION } from "./core-version.generated.js";
4
+ import { PREBUILT_FORMAT, } from "./prebuilt-contracts.js";
5
+ import { prebuiltInputsFingerprint, prebuiltPartFingerprints, } from "./prebuilt-inputs.fingerprint.js";
6
+ export async function prebuiltContractsOf(model, config, contracts) {
7
+ const [fingerprint, fingerprints] = await Promise.all([
8
+ prebuiltInputsFingerprint(model, config),
9
+ prebuiltPartFingerprints(model, config),
10
+ ]);
11
+ return {
12
+ format: PREBUILT_FORMAT,
13
+ core: CORE_VERSION,
14
+ protocol: AVENTARA_PROTOCOL_VERSION,
15
+ fingerprint,
16
+ fingerprints,
17
+ contracts: {
18
+ core: canonicalContractTextOf(contracts.core),
19
+ application: canonicalContractTextOf(contracts.application),
20
+ client: canonicalContractTextOf(contracts.client),
21
+ agent: canonicalContractTextOf(contracts.agent),
22
+ },
23
+ };
24
+ }
25
+ const literal = (value) => JSON.stringify(value);
26
+ const key = (name) => name === "__proto__" ? `[${literal(name)}]` : literal(name);
27
+ export function emitPrebuiltContracts(prebuilt) {
28
+ const resources = Object.entries(prebuilt.fingerprints.resources).map(([name, fingerprint]) => `\t\t\t${key(name)}: ${literal(fingerprint)},\n`);
29
+ return `// Generated by @aventara/core from the configuration and the adapter's model. Do not edit: regenerate it.
30
+ import type { AvPrebuiltContracts } from "@aventara/core";
31
+
32
+ export const aventaraContracts: AvPrebuiltContracts = {
33
+ \tformat: ${prebuilt.format},
34
+ \tcore: ${literal(prebuilt.core)},
35
+ \tprotocol: ${prebuilt.protocol},
36
+ \tfingerprint: ${literal(prebuilt.fingerprint)},
37
+ \tfingerprints: {
38
+ \t\tshared: ${literal(prebuilt.fingerprints.shared)},
39
+ \t\tresources: {
40
+ ${resources.join("")}\t\t},
41
+ \t},
42
+ \tcontracts: {
43
+ \t\tcore: ${literal(prebuilt.contracts.core)},
44
+ \t\tapplication: ${literal(prebuilt.contracts.application)},
45
+ \t\tclient: ${literal(prebuilt.contracts.client)},
46
+ \t\tagent: ${literal(prebuilt.contracts.agent)},
47
+ \t},
48
+ };
49
+ `;
50
+ }
@@ -0,0 +1 @@
1
+ export const PREBUILT_FORMAT = 1;
@@ -0,0 +1,19 @@
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import { type AvContracts } from "../compiler/contract.compiler.js";
3
+ import type { ResolvedFrameworkConfig } from "../config/config.resolver.js";
4
+ /** The loaded Contracts, or why the file cannot be used. */
5
+ export type PrebuiltLoad = {
6
+ readonly ok: true;
7
+ readonly contracts: AvContracts;
8
+ } | {
9
+ readonly ok: false;
10
+ readonly reason: string;
11
+ };
12
+ /**
13
+ * Loads the Contracts of a prebuilt file when it was compiled by this core, for
14
+ * this protocol, from `config` (as authored) and `model`; binds them to the
15
+ * runtime pieces of the live `resolved` configuration.
16
+ */
17
+ export declare function loadPrebuiltContracts<M extends AvAdapterModel>(prebuilt: unknown, model: M, config: object, resolved: ResolvedFrameworkConfig<M>): Promise<PrebuiltLoad>;
18
+ /** Warns, once for the framework being created, that its prebuilt file was not used, and why. */
19
+ export declare function warnStalePrebuilt(reason: string): void;
@@ -0,0 +1,77 @@
1
+ import { bindPrebuiltContracts, } from "../compiler/contract.compiler.js";
2
+ import { recordCanonicalContractText } from "../contracts/contract-canonicalizer.js";
3
+ import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
4
+ import { emitFrameworkWarning } from "../runtime/framework-warning.emitter.js";
5
+ import { CORE_VERSION } from "./core-version.generated.js";
6
+ import { listedNames, prebuiltHeaderChanges, prebuiltInputChanges, } from "./prebuilt-changes.js";
7
+ import { PREBUILT_FORMAT } from "./prebuilt-contracts.js";
8
+ import { prebuiltInputsFingerprint, prebuiltPartFingerprints, } from "./prebuilt-inputs.fingerprint.js";
9
+ const PREBUILT_STALE_WARNING = "AVENTARA_PREBUILT_STALE";
10
+ function isRecord(value) {
11
+ return value !== null && typeof value === "object" && !Array.isArray(value);
12
+ }
13
+ async function changedInputs(stored, model, config) {
14
+ const changes = prebuiltInputChanges(stored, await prebuiltPartFingerprints(model, config));
15
+ return changes.length === 0
16
+ ? "its fingerprint does not match the configuration and model"
17
+ : `${listedNames(changes)} since it was built`;
18
+ }
19
+ function textAt(record, key) {
20
+ const value = Object.hasOwn(record, key) ? record[key] : undefined;
21
+ return typeof value === "string" ? value : undefined;
22
+ }
23
+ function parsedContracts(texts) {
24
+ if (!isRecord(texts)) {
25
+ return undefined;
26
+ }
27
+ const parsed = {};
28
+ for (const origin of ["core", "application", "client", "agent"]) {
29
+ const text = textAt(texts, origin);
30
+ if (text === undefined) {
31
+ return undefined;
32
+ }
33
+ let contract;
34
+ try {
35
+ contract = JSON.parse(text);
36
+ }
37
+ catch {
38
+ return undefined;
39
+ }
40
+ if (!isRecord(contract)) {
41
+ return undefined;
42
+ }
43
+ parsed[origin] = contract;
44
+ }
45
+ const contracts = parsed;
46
+ recordCanonicalContractText(contracts.client, textAt(texts, "client") ?? "");
47
+ recordCanonicalContractText(contracts.agent, textAt(texts, "agent") ?? "");
48
+ return contracts;
49
+ }
50
+ export async function loadPrebuiltContracts(prebuilt, model, config, resolved) {
51
+ if (!isRecord(prebuilt)) {
52
+ return { ok: false, reason: "it is not a prebuilt Contracts file" };
53
+ }
54
+ const [header] = prebuiltHeaderChanges(prebuilt, {
55
+ format: PREBUILT_FORMAT,
56
+ core: CORE_VERSION,
57
+ protocol: AVENTARA_PROTOCOL_VERSION,
58
+ });
59
+ if (header !== undefined) {
60
+ return { ok: false, reason: header };
61
+ }
62
+ if ((await prebuiltInputsFingerprint(model, config)) !== prebuilt.fingerprint) {
63
+ return {
64
+ ok: false,
65
+ reason: await changedInputs(prebuilt.fingerprints, model, config),
66
+ };
67
+ }
68
+ const contracts = parsedContracts(prebuilt.contracts);
69
+ if (contracts === undefined) {
70
+ return { ok: false, reason: "its Contracts are not readable JSON objects" };
71
+ }
72
+ bindPrebuiltContracts(model, resolved, contracts);
73
+ return { ok: true, contracts };
74
+ }
75
+ export function warnStalePrebuilt(reason) {
76
+ emitFrameworkWarning(`prebuilt Contracts are stale and were not used: ${reason}. The Contracts were compiled at startup instead; regenerate the file with aventara-build.`, PREBUILT_STALE_WARNING);
77
+ }
@@ -0,0 +1,16 @@
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ /**
3
+ * The fingerprint of the inputs Contracts are compiled from: `config` as
4
+ * authored (its `adapter` and `prebuilt` left out), `model`, this core's
5
+ * version, the protocol version and the file format.
6
+ */
7
+ export declare function prebuiltInputsFingerprint(model: AvAdapterModel, config: object): Promise<string>;
8
+ /** The inputs' parts, each fingerprinted on its own: what a file stores to name what changed. */
9
+ export type PrebuiltPartFingerprints = {
10
+ /** The inputs that belong to no single Resource. */
11
+ readonly shared: string;
12
+ /** Each Resource's inputs (its model, and its entries in every layer), by name, sorted. */
13
+ readonly resources: Readonly<Record<string, string>>;
14
+ };
15
+ /** The parts of the same inputs as {@link prebuiltInputsFingerprint}'s, each fingerprinted. */
16
+ export declare function prebuiltPartFingerprints(model: AvAdapterModel, config: object): Promise<PrebuiltPartFingerprints>;
@@ -0,0 +1,229 @@
1
+ import { avzCheckOf } from "../avz/avz-check.registry.js";
2
+ import { jsonShapeOf } from "../avz/json-shape.registry.js";
3
+ import { hashCanonicalContractText } from "../contracts/contract-hash.js";
4
+ import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
5
+ import { CORE_VERSION } from "./core-version.generated.js";
6
+ import { PREBUILT_FORMAT } from "./prebuilt-contracts.js";
7
+ const LAYERS = ["root", "application", "client", "agent"];
8
+ const NOT_INPUTS = new Set(["adapter", "prebuilt"]);
9
+ const PER_RESOURCE = "#resources";
10
+ function isRecord(value) {
11
+ return value !== null && typeof value === "object" && !Array.isArray(value);
12
+ }
13
+ function sortedRecord(record) {
14
+ const keys = Object.keys(record);
15
+ const prototype = Object.getPrototypeOf(record);
16
+ const plain = prototype === Object.prototype || prototype === null;
17
+ let written = plain;
18
+ for (let index = 0; written && index < keys.length; index += 1) {
19
+ const key = keys[index];
20
+ written =
21
+ !key.startsWith("#") &&
22
+ (index === 0 || keys[index - 1] < key);
23
+ }
24
+ if (written) {
25
+ return record;
26
+ }
27
+ const sorted = {};
28
+ if (!plain) {
29
+ const name = record.constructor?.name;
30
+ sorted["#class"] = typeof name === "string" ? name : "";
31
+ }
32
+ for (const key of keys.sort()) {
33
+ sorted[key.startsWith("#") ? `#${key}` : key] = record[key];
34
+ }
35
+ return sorted;
36
+ }
37
+ function inputMember(key, value) {
38
+ const raw = this[key];
39
+ switch (typeof raw) {
40
+ case "string":
41
+ return raw.startsWith("#") ? `#${raw}` : raw;
42
+ case "number":
43
+ return Number.isFinite(raw) ? raw : `#number(${raw})`;
44
+ case "bigint":
45
+ return `#bigint(${raw})`;
46
+ case "function":
47
+ return "#function";
48
+ case "symbol":
49
+ return `#symbol(${String(raw.description)})`;
50
+ case "undefined":
51
+ return "#undefined";
52
+ case "boolean":
53
+ return raw;
54
+ }
55
+ if (raw === null) {
56
+ return value;
57
+ }
58
+ const check = avzCheckOf(raw);
59
+ if (check !== undefined) {
60
+ return `#avz(${inputText(check)})`;
61
+ }
62
+ const shape = jsonShapeOf(raw);
63
+ if (shape !== undefined) {
64
+ return `#shape(${inputText(shape.schema)})`;
65
+ }
66
+ if (raw instanceof Date) {
67
+ return `#date(${Number.isNaN(raw.getTime()) ? "invalid" : raw.toISOString()})`;
68
+ }
69
+ if (raw instanceof RegExp) {
70
+ return `#regexp(${JSON.stringify(raw.source)},${raw.flags})`;
71
+ }
72
+ if (raw instanceof Map || raw instanceof Set) {
73
+ return `#${raw instanceof Map ? "map" : "set"}(${inputText([...raw])})`;
74
+ }
75
+ if (value !== raw) {
76
+ return `#json(${inputText(value)})`;
77
+ }
78
+ return Array.isArray(raw) ? raw : sortedRecord(raw);
79
+ }
80
+ function inputText(value) {
81
+ return JSON.stringify(value, inputMember);
82
+ }
83
+ function modelText(value) {
84
+ try {
85
+ return JSON.stringify(value) ?? "#undefined";
86
+ }
87
+ catch {
88
+ return inputText(value);
89
+ }
90
+ }
91
+ function recordAt(value, key) {
92
+ if (!isRecord(value) || !Object.hasOwn(value, key)) {
93
+ return undefined;
94
+ }
95
+ const member = value[key];
96
+ return isRecord(member) ? member : undefined;
97
+ }
98
+ function layerOf(config, layer) {
99
+ return layer === "root"
100
+ ? config
101
+ : Object.hasOwn(config, layer)
102
+ ? config[layer]
103
+ : undefined;
104
+ }
105
+ function sharedLayer(layer) {
106
+ if (!isRecord(layer)) {
107
+ return layer;
108
+ }
109
+ const shared = { ...layer };
110
+ if (isRecord(layer.resources)) {
111
+ shared.resources = PER_RESOURCE;
112
+ }
113
+ const exemptions = layer.exemptions;
114
+ if (isRecord(exemptions) && isRecord(exemptions.resources)) {
115
+ shared.exemptions = { ...exemptions, resources: PER_RESOURCE };
116
+ }
117
+ return shared;
118
+ }
119
+ function policyInput(policy) {
120
+ if (!isRecord(policy) || !Object.hasOwn(policy, "engine")) {
121
+ return policy;
122
+ }
123
+ const engine = policy.engine;
124
+ const governed = engine !== null && typeof engine === "object"
125
+ ? engine.governed
126
+ : undefined;
127
+ return { ...policy, engine: { governed: governed ?? null } };
128
+ }
129
+ function accessInput(access) {
130
+ if (!isRecord(access)) {
131
+ return access;
132
+ }
133
+ const engine = access.policy;
134
+ const governed = engine !== null && typeof engine === "object"
135
+ ? engine.governed
136
+ : undefined;
137
+ const policy = { policy: { governed: governed ?? null } };
138
+ return access.client === undefined
139
+ ? policy
140
+ : { ...policy, client: accessClientInput(access.client) };
141
+ }
142
+ function accessClientInput(client) {
143
+ if (!isRecord(client)) {
144
+ return client;
145
+ }
146
+ const verbs = isRecord(client.verbs)
147
+ ? Object.fromEntries(Object.entries(client.verbs).map(([name, verb]) => [
148
+ name,
149
+ isRecord(verb)
150
+ ? {
151
+ method: verb.method,
152
+ path: verb.path,
153
+ args: verb.args,
154
+ result: verb.result,
155
+ }
156
+ : verb,
157
+ ]))
158
+ : client.verbs;
159
+ return { url: client.url, verbs };
160
+ }
161
+ function authoredInputs(config) {
162
+ const authored = config;
163
+ const root = {};
164
+ for (const key of Object.keys(authored)) {
165
+ if (!NOT_INPUTS.has(key)) {
166
+ root[key] =
167
+ key === "policy"
168
+ ? policyInput(authored[key])
169
+ : key === "access"
170
+ ? accessInput(authored[key])
171
+ : authored[key];
172
+ }
173
+ }
174
+ return root;
175
+ }
176
+ const HEADER = `aventara-prebuilt format ${PREBUILT_FORMAT} core ${CORE_VERSION} protocol ${AVENTARA_PROTOCOL_VERSION}`;
177
+ export function prebuiltInputsFingerprint(model, config) {
178
+ return hashCanonicalContractText(`${HEADER}\n${inputText(authoredInputs(config))}\n${modelText(model)}`);
179
+ }
180
+ export async function prebuiltPartFingerprints(model, config) {
181
+ const root = authoredInputs(config);
182
+ const names = new Set(Object.keys(model.resources));
183
+ for (const layer of LAYERS) {
184
+ const value = layerOf(root, layer);
185
+ for (const name of Object.keys(recordAt(value, "resources") ?? {})) {
186
+ names.add(name);
187
+ }
188
+ const exemptions = recordAt(value, "exemptions");
189
+ for (const name of Object.keys(recordAt(exemptions, "resources") ?? {})) {
190
+ names.add(name);
191
+ }
192
+ }
193
+ const sharedRoot = sharedLayer(root);
194
+ for (const layer of LAYERS) {
195
+ if (layer !== "root" && Object.hasOwn(root, layer)) {
196
+ sharedRoot[layer] = sharedLayer(root[layer]);
197
+ }
198
+ }
199
+ const { resources: _resources, ...sharedModel } = model;
200
+ const shared = hashCanonicalContractText(`${HEADER}\n${inputText(sharedRoot)}\n${modelText(sharedModel)}`);
201
+ const sorted = [...names].sort();
202
+ const parts = sorted.map((name) => {
203
+ const entries = {};
204
+ for (const layer of LAYERS) {
205
+ const value = layerOf(root, layer);
206
+ const resources = recordAt(value, "resources");
207
+ const exemptions = recordAt(recordAt(value, "exemptions"), "resources");
208
+ const entry = {};
209
+ if (resources !== undefined && Object.hasOwn(resources, name)) {
210
+ entry.resources = resources[name];
211
+ }
212
+ if (exemptions !== undefined && Object.hasOwn(exemptions, name)) {
213
+ entry.exemptions = exemptions[name];
214
+ }
215
+ if (Object.keys(entry).length > 0) {
216
+ entries[layer] = entry;
217
+ }
218
+ }
219
+ const modelPart = Object.hasOwn(model.resources, name)
220
+ ? modelText(model.resources[name])
221
+ : "#absent";
222
+ return hashCanonicalContractText(`${inputText(entries)}\n${modelPart}`);
223
+ });
224
+ const hashes = await Promise.all(parts);
225
+ return {
226
+ shared: await shared,
227
+ resources: Object.fromEntries(sorted.map((name, index) => [name, hashes[index]])),
228
+ };
229
+ }
@@ -1,8 +1,8 @@
1
- import type { FrameworkContracts } from "../compiler/contract.compiler.js";
2
- import { type OperationIdentity } from "../operations/operation-identity.js";
3
- import { type FrameworkDiagnosticsSink } from "../runtime/diagnostics-reporter.js";
4
- import type { ClientProtocolIdentity } from "../runtime/operation-request.js";
5
- import { type OperationFailureResponse } from "../runtime/operation-response.js";
1
+ import type { AvContracts } from "../compiler/contract.compiler.js";
2
+ import type { RemoteRequestOrigin } from "../config/config-layer.js";
3
+ import { type AvOperationIdentity } from "../operations/operation-identity.js";
4
+ import { type AvDiagnosticsSink } from "../runtime/diagnostics-reporter.js";
5
+ import type { AvRequestProtocol } from "../runtime/operation-request.js";
6
6
  import type { AvProtocolRequest } from "./http-request.decoder.js";
7
7
  import { type ReadRequest } from "./http-request.reader.js";
8
8
  import { type AvProtocolResponse } from "./http-response.encoder.js";
@@ -20,37 +20,13 @@ export type OperationRouteSegments = {
20
20
  readonly family: string;
21
21
  readonly variant: string;
22
22
  };
23
- /** What a route check resolves to: the operation it names, or the answer that refuses it. */
24
- export type OperationRouteResolution = {
25
- readonly ok: true;
26
- readonly operation: OperationIdentity;
27
- } | {
28
- readonly ok: false;
29
- readonly failure: OperationFailureResponse;
30
- };
31
- /**
32
- * An operation route `/_resources/<resource>/<family>/<variant>` under one client
33
- * protocol identity: version → hash → Resource → operation. A Resource key is matched
34
- * exactly and only as the ClientContract's own key; a family/variant pair only when it
35
- * is a standard operation the Resource advertises, read through
36
- * `isOperationVariantAvailable` alone.
37
- */
38
- export declare function resolveOperationRoute(contracts: FrameworkContracts, protocol: ClientProtocolIdentity, route: OperationRouteSegments): OperationRouteResolution;
39
- /**
40
- * The `/_transactions` route under one client protocol identity: version → hash → the
41
- * ClientContract's transaction capability. The route exists only when that capability
42
- * is `"interactive"` — tested against the value itself, as `protocol.surface()` tests
43
- * it — and is otherwise absent with core's own refusal of a plan. `undefined` when the
44
- * route is there.
45
- */
46
- export declare function transactionsRouteFailure(contracts: FrameworkContracts, protocol: ClientProtocolIdentity): OperationFailureResponse | undefined;
47
23
  /**
48
24
  * What a route's checks before its body resolve to: the route a request
49
25
  * reaches, or the framework response that answers it instead.
50
26
  */
51
27
  type RouteCheck<Route> = ({
52
28
  readonly ok: true;
53
- readonly protocol: ClientProtocolIdentity;
29
+ readonly protocol: AvRequestProtocol;
54
30
  } & Route) | {
55
31
  readonly ok: false;
56
32
  readonly response: AvProtocolResponse;
@@ -63,9 +39,9 @@ type RouteCheck<Route> = ({
63
39
  * for both route styles: `decodeOperation` reads the body only after it passes,
64
40
  * `answerAbsent` never.
65
41
  */
66
- export declare function checkOperationRoute(contracts: FrameworkContracts, read: ReadRequest): RouteCheck<{
42
+ export declare function checkOperationRoute(contracts: AvContracts, read: ReadRequest, origin?: RemoteRequestOrigin): RouteCheck<{
67
43
  readonly resource: string;
68
- readonly operation: OperationIdentity;
44
+ readonly operation: AvOperationIdentity;
69
45
  }>;
70
46
  /**
71
47
  * `/_transactions`' checks before its body: the path (`A2000` unless exactly
@@ -73,12 +49,19 @@ export declare function checkOperationRoute(contracts: FrameworkContracts, read:
73
49
  * {@link transactionsRouteFailure} — version, hash, `"interactive"` — and the
74
50
  * method (`A2012`, `Allow: POST`).
75
51
  */
76
- export declare function checkTransactionsRoute(contracts: FrameworkContracts, read: ReadRequest): RouteCheck<object>;
52
+ export declare function checkTransactionsRoute(contracts: AvContracts, read: ReadRequest, origin?: RemoteRequestOrigin): RouteCheck<object>;
53
+ /**
54
+ * `/_access/can`'s checks before its body: the path (`A2000` unless exactly
55
+ * `/_access/can`), the identity headers' presence (`A2000`), then
56
+ * {@link accessCanRouteFailure} — version, hash, the `access` section — and the
57
+ * method (`A2012`, `Allow: POST`).
58
+ */
59
+ export declare function checkAccessCanRoute(contracts: AvContracts, read: ReadRequest, origin?: RemoteRequestOrigin): RouteCheck<object>;
77
60
  /**
78
61
  * `protocol.answerAbsent(request)` — the fallback a host that mounts one route per
79
62
  * `protocol.surface()` entry mounts for every path it did not. Never a catch-all into
80
63
  * framework handling: it reads no body, runs no pipeline, calls no Adapter, and takes
81
64
  * only the compiled Contracts. In order:
82
65
  */
83
- export declare function answerAbsentRequest(contracts: FrameworkContracts, received: AvProtocolRequest, sink?: FrameworkDiagnosticsSink): AvProtocolResponse | undefined;
66
+ export declare function answerAbsentRequest(contracts: AvContracts, received: AvProtocolRequest, sink?: AvDiagnosticsSink, origin?: RemoteRequestOrigin): AvProtocolResponse | undefined;
84
67
  export {};
@@ -3,22 +3,23 @@ import { isOperationVariantAvailable, } from "../contracts/resource-operations.j
3
3
  import { parseOperationIdentity, } from "../operations/operation-identity.js";
4
4
  import { operationUnavailableIssue } from "../operations/operation-validator.js";
5
5
  import { resourceUnavailableIssue } from "../operations/operation-validator-core.js";
6
+ import { validationIssue } from "../operations/validation-code.js";
6
7
  import { createReporter, } from "../runtime/diagnostics-reporter.js";
7
8
  import { INTERNAL_FAILURE_MESSAGE, operationFailure, } from "../runtime/operation-response.js";
8
9
  import { protocolIdentityFailure } from "../runtime/operation-runtime.js";
9
10
  import { mapValidationOutcome } from "../runtime/outcome-mapper.js";
10
11
  import { transactionsUnavailableFailure } from "../transactions/transaction-plan-validator.js";
11
- import { CONTRACT_ROUTE, GET_ONLY, isProtocolPath, operationRouteSegments, POST_ONLY, readRequest, TRANSACTIONS_ROUTE, } from "./http-request.reader.js";
12
+ import { ACCESS_CAN_ROUTE, CONTRACT_ROUTE, GET_ONLY, isProtocolPath, operationRouteSegments, POST_ONLY, readRequest, TRANSACTIONS_ROUTE, } from "./http-request.reader.js";
12
13
  import { encodeOperationResponse, } from "./http-response.encoder.js";
13
14
  import { identityHeadersMissing, transportFailure, } from "./protocol-failure.js";
14
15
  import { missingIdentityHeaders } from "./protocol-headers.js";
15
- import { UnmountedRouteError } from "./unmounted-route.error.js";
16
- export function resolveOperationRoute(contracts, protocol, route) {
17
- const identityFailure = protocolIdentityFailure(contracts, protocol);
16
+ import { AvUnmountedRouteError } from "./unmounted-route.error.js";
17
+ function resolveOperationRoute(contracts, protocol, route, origin = "client") {
18
+ const identityFailure = protocolIdentityFailure(contracts, protocol, origin);
18
19
  if (identityFailure !== undefined) {
19
20
  return { ok: false, failure: identityFailure };
20
21
  }
21
- const resource = lookupResource(contracts.client, route.resource);
22
+ const resource = lookupResource(contracts[origin], route.resource);
22
23
  if (resource === undefined) {
23
24
  return {
24
25
  ok: false,
@@ -32,19 +33,32 @@ export function resolveOperationRoute(contracts, protocol, route) {
32
33
  return {
33
34
  ok: false,
34
35
  failure: mapValidationOutcome([
35
- operationUnavailableIssue(contracts.client, route),
36
+ operationUnavailableIssue(contracts[origin], route),
36
37
  ]),
37
38
  };
38
39
  }
39
40
  return { ok: true, operation };
40
41
  }
41
- export function transactionsRouteFailure(contracts, protocol) {
42
- return (protocolIdentityFailure(contracts, protocol) ??
43
- (contracts.client.transactions === "interactive"
42
+ function transactionsRouteFailure(contracts, protocol, origin = "client") {
43
+ return (protocolIdentityFailure(contracts, protocol, origin) ??
44
+ (contracts[origin].transactions === "interactive"
44
45
  ? undefined
45
46
  : transactionsUnavailableFailure()));
46
47
  }
47
- export function checkOperationRoute(contracts, read) {
48
+ function accessCanUnavailableFailure() {
49
+ const message = "Access questions are not available on the active Contract.";
50
+ return operationFailure("A2002", {
51
+ message,
52
+ issues: [validationIssue("V1006", ["questions"], message)],
53
+ });
54
+ }
55
+ function accessCanRouteFailure(contracts, protocol, origin = "client") {
56
+ return (protocolIdentityFailure(contracts, protocol, origin) ??
57
+ (contracts[origin].access === undefined
58
+ ? accessCanUnavailableFailure()
59
+ : undefined));
60
+ }
61
+ export function checkOperationRoute(contracts, read, origin = "client") {
48
62
  const segments = operationRouteSegments(read.request.path);
49
63
  if (segments === undefined) {
50
64
  return refusedWith(transportFailure("A2000", read.requestId));
@@ -52,7 +66,7 @@ export function checkOperationRoute(contracts, read) {
52
66
  if (read.protocol === undefined) {
53
67
  return refusedWith(identityFailureOf(read));
54
68
  }
55
- const route = resolveOperationRoute(contracts, read.protocol, segments);
69
+ const route = resolveOperationRoute(contracts, read.protocol, segments, origin);
56
70
  if (!route.ok) {
57
71
  return refusedWith(encodeOperationResponse(route.failure, read.requestId));
58
72
  }
@@ -65,14 +79,29 @@ export function checkOperationRoute(contracts, read) {
65
79
  }
66
80
  : refusedWith(transportFailure("A2012", read.requestId, POST_ONLY));
67
81
  }
68
- export function checkTransactionsRoute(contracts, read) {
82
+ export function checkTransactionsRoute(contracts, read, origin = "client") {
69
83
  if (read.request.path !== TRANSACTIONS_ROUTE) {
70
84
  return refusedWith(transportFailure("A2000", read.requestId));
71
85
  }
72
86
  if (read.protocol === undefined) {
73
87
  return refusedWith(identityFailureOf(read));
74
88
  }
75
- const absent = transactionsRouteFailure(contracts, read.protocol);
89
+ const absent = transactionsRouteFailure(contracts, read.protocol, origin);
90
+ if (absent !== undefined) {
91
+ return refusedWith(encodeOperationResponse(absent, read.requestId));
92
+ }
93
+ return read.request.method === "POST"
94
+ ? { ok: true, protocol: read.protocol }
95
+ : refusedWith(transportFailure("A2012", read.requestId, POST_ONLY));
96
+ }
97
+ export function checkAccessCanRoute(contracts, read, origin = "client") {
98
+ if (read.request.path !== ACCESS_CAN_ROUTE) {
99
+ return refusedWith(transportFailure("A2000", read.requestId));
100
+ }
101
+ if (read.protocol === undefined) {
102
+ return refusedWith(identityFailureOf(read));
103
+ }
104
+ const absent = accessCanRouteFailure(contracts, read.protocol, origin);
76
105
  if (absent !== undefined) {
77
106
  return refusedWith(encodeOperationResponse(absent, read.requestId));
78
107
  }
@@ -86,7 +115,7 @@ function identityFailureOf(read) {
86
115
  function refusedWith(response) {
87
116
  return { ok: false, response };
88
117
  }
89
- export function answerAbsentRequest(contracts, received, sink) {
118
+ export function answerAbsentRequest(contracts, received, sink, origin = "client") {
90
119
  const read = readRequest(received);
91
120
  if (!read.ok) {
92
121
  return read.response;
@@ -100,31 +129,35 @@ export function answerAbsentRequest(contracts, received, sink) {
100
129
  ? unmounted(read.requestId)
101
130
  : transportFailure("A2012", read.requestId, GET_ONLY);
102
131
  }
132
+ if (path === ACCESS_CAN_ROUTE) {
133
+ const route = checkAccessCanRoute(contracts, read, origin);
134
+ return route.ok ? unmounted(read.requestId) : route.response;
135
+ }
103
136
  if (path === TRANSACTIONS_ROUTE) {
104
- const route = checkTransactionsRoute(contracts, read);
137
+ const route = checkTransactionsRoute(contracts, read, origin);
105
138
  if (!route.ok) {
106
139
  return route.response;
107
140
  }
108
141
  createReporter(sink, {
109
142
  kind: "transaction",
110
- origin: "client",
143
+ origin,
111
144
  requestId: read.requestId,
112
- })(new UnmountedRouteError("transactions", `POST ${TRANSACTIONS_ROUTE}`), "A3000");
145
+ })(new AvUnmountedRouteError("transactions", `POST ${TRANSACTIONS_ROUTE}`), "A3000");
113
146
  return unmounted(read.requestId);
114
147
  }
115
- const route = checkOperationRoute(contracts, read);
148
+ const route = checkOperationRoute(contracts, read, origin);
116
149
  if (!route.ok) {
117
150
  return route.response;
118
151
  }
119
152
  const { family, variant } = route.operation;
120
153
  createReporter(sink, {
121
154
  kind: "operation",
122
- origin: "client",
155
+ origin,
123
156
  resource: route.resource,
124
157
  family,
125
158
  variant,
126
159
  requestId: read.requestId,
127
- })(new UnmountedRouteError(`${route.resource}.${family}.${variant}`, `POST ${path}`), "A3000");
160
+ })(new AvUnmountedRouteError(`${route.resource}.${family}.${variant}`, `POST ${path}`), "A3000");
128
161
  return unmounted(read.requestId);
129
162
  }
130
163
  function unmounted(requestId) {