@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,53 @@
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvConfigAny } from "./any-framework-config.js";
3
+ import type { ExactOverlayResource, ExactRootResource } from "./exact-framework-config.js";
4
+ import type { AvConfigResourceKey } from "./framework-field-definition.js";
5
+ import type { AvConfigResource } from "./framework-resources-config.js";
6
+ import type { ErasedOverlayBlocks, ErasedResourceBlock } from "./stage-type.eraser.js";
7
+ /** A configuration whose root `resources` is `{ [R]: Block }`. */
8
+ type ResourceBlockConfig<R extends string, Block> = {
9
+ readonly resources: {
10
+ readonly [K in R]: Block;
11
+ };
12
+ };
13
+ /** The layers above the root a Resource may carry blocks for. */
14
+ type OverlayLayer = "application" | "client" | "agent";
15
+ /** A Resource's overlay blocks, as authored: either, both or neither. */
16
+ type ResourceOverlays = {
17
+ readonly [L in OverlayLayer]?: unknown;
18
+ };
19
+ /**
20
+ * What {@link defineResource} returns: `root`, and `application`, `client` and
21
+ * `agent` exactly when they were given, each `{ [R]: block }` to spread into that
22
+ * layer's `resources`. Each block is as authored, with every stage list typed by
23
+ * its public stage type (`readonly AvGuard[]`, `readonly AvPipe[]`, …).
24
+ */
25
+ export type AvDefinedResource<R extends string, Block, Overlays> = {
26
+ readonly [L in "root" | Extract<keyof Overlays, OverlayLayer>]: {
27
+ readonly [K in R]: L extends keyof Overlays ? Overlays[L] : Block;
28
+ };
29
+ };
30
+ /**
31
+ * Defines one Resource's configuration on its own: its root block (pipelines,
32
+ * operations, transactions and fields, typed as `resources.<R>` is typed in
33
+ * place) and, optionally, its `application`, `client` and `agent` blocks (typed
34
+ * as `application.resources.<R>`, `client.resources.<R>` and
35
+ * `agent.resources.<R>` are: stages only, no `definition`, and every field the
36
+ * model or the root block has). Returns
37
+ * `{ root, application?, client?, agent? }`, each `{ [R]: block }` to spread into its
38
+ * layer's `resources`; a layer without a block is left out.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * export const post = defineResource<Model>()(
43
+ * "Post",
44
+ * { fields: { title: { pipelines: { pipes: [trim] } } } },
45
+ * { client: { pipelines: { guards: [signedIn] } } },
46
+ * );
47
+ * // aventara.config.ts
48
+ * resources: { ...post.root, ...payment.root },
49
+ * client: { resources: { ...post.client } },
50
+ * ```
51
+ */
52
+ export declare function defineResource<M extends AvAdapterModel>(): <const R extends AvConfigResourceKey<M>, const Block = AvConfigResource<M, AvConfigAny, R, "root">, const Overlays extends ResourceOverlays = Record<never, never>>(resource: R, block: Block & NoInfer<AvConfigResource<M, ResourceBlockConfig<R, Block>, R, "root"> & ExactRootResource<M, R, Block>>, overlays?: Overlays & { readonly [L in keyof Overlays]: L extends OverlayLayer ? NoInfer<AvConfigResource<M, ResourceBlockConfig<R, Block>, R, "overlay", L> & ExactOverlayResource<M, ResourceBlockConfig<R, Block>, R, Overlays[L]>> : never; }) => AvDefinedResource<R, ErasedResourceBlock<Block>, ErasedOverlayBlocks<Overlays>>;
53
+ export {};
@@ -0,0 +1,14 @@
1
+ export function defineResource() {
2
+ return (resource, block, overlays) => {
3
+ const defined = {
4
+ root: { [resource]: block },
5
+ };
6
+ for (const layer of ["application", "client", "agent"]) {
7
+ const overlay = overlays?.[layer];
8
+ if (overlay !== undefined) {
9
+ defined[layer] = { [resource]: overlay };
10
+ }
11
+ }
12
+ return defined;
13
+ };
14
+ }
@@ -1,30 +1,26 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AdapterFieldKey } from "../adapters/adapter-resource.js";
3
- import type { AnyFieldsBlock } from "./any-framework-config.js";
4
- import type { RequestOrigin } from "./config-layer.js";
5
- import type { FrameworkResourceKey } from "./framework-fields-config.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvAdapterFieldKey } from "../adapters/adapter-resource.js";
3
+ import type { AvConfigResourceKey } from "./framework-field-definition.js";
6
4
  /**
7
- * The `fields` block a configuration layer owns, or `never` when it has none.
5
+ * The root `resources` block a configuration owns, or `never` when it has
6
+ * none.
8
7
  *
9
8
  * `Cfg` is an authored literal, not a validated shape, so the block is read
10
- * structurally. A layer without a `fields` property infers `unknown`, which
11
- * is not an {@link AnyFieldsBlock}, so it contributes nothing.
9
+ * structurally. A configuration without a `resources` property infers
10
+ * `unknown`, which is no object, so it contributes nothing.
12
11
  */
13
- type FieldsBlockOf<Layer> = Layer extends {
14
- readonly fields?: infer Block;
15
- } ? Block extends AnyFieldsBlock ? Block : never : never;
16
- /** The field names a single `fields` block declares for `R`. */
17
- type FieldsBlockKey<Block, R extends string> = [Block] extends [never] ? never : R extends keyof Block ? Extract<keyof NonNullable<Block[R]>, string> : never;
18
- /** The field names the configuration's root `fields` block adds to Resource `R`. */
19
- export type ConfigFieldKey<M extends AdapterModel, Cfg, R extends FrameworkResourceKey<M>> = FieldsBlockKey<FieldsBlockOf<Cfg>, R>;
20
- /** The single answer to "what are `R`'s field names under this configuration". */
21
- export type EffectiveFieldKey<M extends AdapterModel, Cfg, R extends FrameworkResourceKey<M>> = AdapterFieldKey<M, R> | ConfigFieldKey<M, Cfg, R>;
22
- /** The overlay `Cfg` carries for `Origin`, or `never` when it declares none. */
23
- type OriginOverlayOf<Cfg, Origin extends RequestOrigin> = Origin extends keyof Cfg ? NonNullable<Cfg[Origin]> : never;
12
+ type ResourcesBlockOf<Cfg> = Cfg extends {
13
+ readonly resources?: infer Block;
14
+ } ? Block extends object ? Block : never : never;
15
+ /** The field names the root `resources.<R>.fields` block names for `R`. */
16
+ type ResourcesBlockFieldKey<Block, R extends string> = [Block] extends [never] ? never : R extends keyof Block ? NonNullable<Block[R]> extends {
17
+ readonly fields?: infer Fields;
18
+ } ? Extract<keyof NonNullable<Fields>, string> : never : never;
24
19
  /**
25
- * `R`'s field names as seen from one request origin: the root layer plus
26
- * whatever the `application` or `client` overlay adds. A name added under
27
- * `client` is not visible under `application`, and the other way round.
20
+ * The field names the configuration's root `resources.<R>.fields` block
21
+ * names: its configured fields, and any discovered field it configures.
28
22
  */
29
- export type EffectiveFieldKeyAt<M extends AdapterModel, Cfg, R extends FrameworkResourceKey<M>, Origin extends RequestOrigin> = EffectiveFieldKey<M, Cfg, R> | FieldsBlockKey<FieldsBlockOf<OriginOverlayOf<Cfg, Origin>>, R>;
23
+ export type AvConfigFieldKey<M extends AvAdapterModel, Cfg, R extends AvConfigResourceKey<M>> = ResourcesBlockFieldKey<ResourcesBlockOf<Cfg>, R>;
24
+ /** The single answer to "what are `R`'s field names under this configuration". */
25
+ export type AvEffectiveFieldKey<M extends AvAdapterModel, Cfg, R extends AvConfigResourceKey<M>> = AvAdapterFieldKey<M, R> | AvConfigFieldKey<M, Cfg, R>;
30
26
  export {};
@@ -1,10 +1,10 @@
1
1
  /**
2
- * The framework entrypoint's mount path, in its one canonical form: `""` at the root,
2
+ * A mount path (the server's `api` or `mcp` path, a client entrypoint's path), in its one canonical form: `""` at the root,
3
3
  * otherwise `/seg(/seg)*` — one leading slash, no trailing slash, no empty segment.
4
4
  * Root is the empty string, not `"/"`, so a route joins onto it by concatenation with
5
5
  * no special case.
6
6
  */
7
- export type EntrypointPath = "" | `/${string}`;
7
+ type EntrypointPath = "" | `/${string}`;
8
8
  /**
9
9
  * Why a mount path is refused. Only the slash spelling is ever coerced
10
10
  * (`api`, `/api/` and `//api//` are one intent, `/api`); everything else that is
@@ -17,7 +17,7 @@ export type EntrypointRefusalReason = "whitespace" | "scheme" | "query" | "fragm
17
17
  * and the rule, and never echoes the value: an entrypoint may carry
18
18
  * credentials (the client's rule, shared by the server).
19
19
  */
20
- export type EntrypointNormalization = {
20
+ type EntrypointNormalization = {
21
21
  readonly ok: true;
22
22
  readonly path: EntrypointPath;
23
23
  } | {
@@ -30,3 +30,4 @@ export type EntrypointNormalization = {
30
30
  * or a refusal.
31
31
  */
32
32
  export declare function normalizeEntrypoint(value: string): EntrypointNormalization;
33
+ export {};
@@ -0,0 +1,325 @@
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvAdapterFieldKey } from "../adapters/adapter-resource.js";
3
+ import type { AvScalarFieldCapabilities } from "../contracts/field.js";
4
+ import type { OverlayViewResources, RootViewResources } from "../framework/contract-view.js";
5
+ import type { AvEffectiveFieldKey } from "./effective-fields.js";
6
+ import type { AvConfigResourceKey } from "./framework-field-definition.js";
7
+ import type { AvConfigLayerKind } from "./framework-resources-config.js";
8
+ /** A key whose value this walk does not open. */
9
+ type Leaf = true;
10
+ type PipelinesSchema = {
11
+ readonly guards: Leaf;
12
+ readonly pipes: Leaf;
13
+ readonly hooks: {
14
+ readonly before: Leaf;
15
+ readonly after: Leaf;
16
+ };
17
+ readonly interceptors: Leaf;
18
+ readonly filters: Leaf;
19
+ };
20
+ type LimitsSchema = {
21
+ readonly maxRequestBytes: Leaf;
22
+ readonly maxNestingDepth: Leaf;
23
+ readonly maxListLimit: Leaf;
24
+ readonly maxTransactionOperations: Leaf;
25
+ readonly maxBooleanNodes: Leaf;
26
+ readonly maxJsonDepth: Leaf;
27
+ };
28
+ type LevelSchema = {
29
+ readonly pipelines: PipelinesSchema;
30
+ readonly forceTransaction: Leaf;
31
+ };
32
+ type Operations<M extends AvAdapterModel, R extends AvConfigResourceKey<M>> = M["resources"][R]["operations"];
33
+ type OperationsSchema<M extends AvAdapterModel, R extends AvConfigResourceKey<M>> = {
34
+ readonly [F in keyof Operations<M, R>]: LevelSchema & {
35
+ readonly [V in keyof NonNullable<Operations<M, R>[F]>]: LevelSchema;
36
+ };
37
+ };
38
+ type CapabilitySchema<Capabilities> = {
39
+ readonly [K in keyof Capabilities]-?: Leaf;
40
+ };
41
+ type DefinitionSchema = {
42
+ readonly type: Leaf;
43
+ readonly nullable: Leaf;
44
+ readonly list: Leaf;
45
+ readonly lifecycle: Leaf;
46
+ readonly format: Leaf;
47
+ readonly capabilities: CapabilitySchema<AvScalarFieldCapabilities>;
48
+ readonly json: Leaf;
49
+ };
50
+ type ScalarPipelinesSchema = {
51
+ readonly validators: Leaf;
52
+ readonly pipes: Leaf;
53
+ readonly compute: {
54
+ readonly create: Leaf;
55
+ readonly read: {
56
+ readonly dependsOn: Leaf;
57
+ readonly compute: Leaf;
58
+ };
59
+ readonly update: Leaf;
60
+ };
61
+ readonly guards: Leaf;
62
+ };
63
+ type RelationPipelinesSchema = {
64
+ readonly guards: Leaf;
65
+ };
66
+ type ScalarFieldSchema = {
67
+ readonly pipelines: ScalarPipelinesSchema;
68
+ };
69
+ type RelationFieldSchema = {
70
+ readonly pipelines: RelationPipelinesSchema;
71
+ };
72
+ type RootScalarFieldSchema = ScalarFieldSchema & {
73
+ readonly definition: DefinitionSchema;
74
+ };
75
+ type RootRelationFieldSchema = RelationFieldSchema & {
76
+ readonly definition: DefinitionSchema;
77
+ };
78
+ /** A field entry's keys: a relation takes write guards only; only the root defines. */
79
+ type FieldSchema<M extends AvAdapterModel, R extends AvConfigResourceKey<M>, F, Kind extends AvConfigLayerKind> = F extends AvAdapterFieldKey<M, R> ? M["resources"][R]["fields"][F] extends {
80
+ readonly kind: "relation";
81
+ } ? Kind extends "root" ? RootRelationFieldSchema : RelationFieldSchema : Kind extends "root" ? RootScalarFieldSchema : ScalarFieldSchema : Kind extends "root" ? RootScalarFieldSchema : ScalarFieldSchema;
82
+ declare const otherKeys: unique symbol;
83
+ type ResourceSchema<M extends AvAdapterModel, R extends AvConfigResourceKey<M>, Fields> = {
84
+ readonly pipelines: PipelinesSchema;
85
+ readonly operations: OperationsSchema<M, R>;
86
+ readonly transactions: {
87
+ readonly pipelines: PipelinesSchema;
88
+ };
89
+ readonly fields: Fields;
90
+ };
91
+ /** A layer's fields of Resource `R`, named by `FieldName`. */
92
+ type FieldsSchema<M extends AvAdapterModel, R extends AvConfigResourceKey<M>, Kind extends AvConfigLayerKind, FieldName> = {
93
+ readonly [F in FieldName & string]: FieldSchema<M, R, F, Kind>;
94
+ };
95
+ declare const listOf: unique symbol;
96
+ /** The names a list at this place may hold. */
97
+ type ListOf<Names> = {
98
+ readonly [listOf]: Names;
99
+ };
100
+ /** The tokens one capability member lists, its position qualifier aside. */
101
+ type TokenOf<Member> = Member extends {
102
+ readonly scopes: unknown;
103
+ } ? {
104
+ [K in keyof Member]: K extends "scopes" ? never : Member[K] extends readonly (infer Token)[] ? Token : never;
105
+ }[keyof Member] : Member extends readonly (infer Token)[] ? Token : never;
106
+ /** The capability members an exemption never names. */
107
+ type AdapterStatedMember = "nestedWriteFilter" | "filterModes" | "pathFilterModes";
108
+ /** A field's exemption against its capabilities: their names, and each one's tokens. */
109
+ type CapabilityExemptionSchema<Caps> = ListOf<Exclude<keyof Caps, AdapterStatedMember>> & {
110
+ readonly [K in Exclude<keyof Caps, AdapterStatedMember>]-?: ListOf<TokenOf<NonNullable<Caps[K]>>>;
111
+ };
112
+ type FieldExemptionSchema<M extends AvAdapterModel, R extends AvConfigResourceKey<M>, F> = F extends AvAdapterFieldKey<M, R> ? M["resources"][R]["fields"][F] extends {
113
+ readonly kind: "relation";
114
+ readonly capabilities: infer Caps;
115
+ } ? CapabilityExemptionSchema<Caps> : M["resources"][R]["fields"][F] extends {
116
+ readonly capabilities: infer Caps;
117
+ } ? CapabilityExemptionSchema<Caps & {
118
+ readonly select?: true;
119
+ }> : ListOf<keyof AvScalarFieldCapabilities> & CapabilitySchema<AvScalarFieldCapabilities> : ListOf<keyof AvScalarFieldCapabilities> & CapabilitySchema<AvScalarFieldCapabilities>;
120
+ /** A Resource's operations exemption against the operations it offers. */
121
+ type OperationsExemptionSchema<Ops> = ListOf<keyof Ops> & {
122
+ readonly [F in keyof Ops]-?: ListOf<keyof NonNullable<Ops[F]>> & {
123
+ readonly [V in keyof NonNullable<Ops[F]>]: Leaf;
124
+ };
125
+ };
126
+ type ExemptionsSchema<M extends AvAdapterModel, Cfg> = {
127
+ readonly resources: {
128
+ readonly [R in AvConfigResourceKey<M>]: {
129
+ readonly operations: OperationsExemptionSchema<Operations<M, R>>;
130
+ readonly fields: {
131
+ readonly [F in AvEffectiveFieldKey<M, Cfg, R>]: FieldExemptionSchema<M, R, F>;
132
+ };
133
+ };
134
+ };
135
+ };
136
+ declare const refusal: unique symbol;
137
+ /** What a level refuses an unknown key for: `layer` cannot expose it, `parent` hid it, under `at`. */
138
+ type Refusal<Layer extends string, Parent extends string, At extends string> = {
139
+ readonly [refusal]: {
140
+ readonly layer: Layer;
141
+ readonly parent: Parent;
142
+ readonly at: At;
143
+ };
144
+ };
145
+ /** The sentence a refused key `K` holding `Value` is typed as; `never` for an entry written `false`. */
146
+ type RefusalOf<Info, K, Value> = [Value] extends [false] ? never : Info extends {
147
+ readonly layer: infer Layer extends string;
148
+ readonly parent: infer Parent extends string;
149
+ readonly at: infer At extends string;
150
+ } ? Value extends readonly unknown[] ? {
151
+ readonly [S in `Error: ${Layer} cannot expose '${At}${K & string}': hidden by ${Parent}`]: true;
152
+ } : readonly [
153
+ `Error: ${Layer} cannot expose '${At}${K & string}': hidden by ${Parent}`
154
+ ] : never;
155
+ /** A Pick layer's operations exemption, a family or variant its parent hid refused by name. */
156
+ type PickOperationsSchema<Ops, Layer extends string, Parent extends string, R extends string> = ListOf<keyof Ops> & {
157
+ readonly [F in keyof Ops]-?: ListOf<keyof NonNullable<Ops[F]>> & {
158
+ readonly [V in keyof NonNullable<Ops[F]>]: Leaf;
159
+ } & Refusal<Layer, Parent, `${R}.${F & string}.`>;
160
+ } & Refusal<Layer, Parent, `${R}.`>;
161
+ /** The fields of one Resource of a view. */
162
+ type ViewFields<Resource> = Resource extends {
163
+ readonly fields: infer Fields;
164
+ } ? Fields : never;
165
+ /** A Pick layer's exemptions, against its parent's view. */
166
+ type PickExemptionsSchema<Resources, Layer extends string, Parent extends string> = {
167
+ readonly resources: {
168
+ readonly [R in keyof Resources]: {
169
+ readonly operations: PickOperationsSchema<Resources[R] extends {
170
+ readonly operations: infer Ops;
171
+ } ? Ops : never, Layer, Parent, R & string>;
172
+ readonly fields: {
173
+ readonly [F in keyof ViewFields<Resources[R]>]: CapabilityExemptionSchema<ViewFields<Resources[R]>[F] extends {
174
+ readonly capabilities: infer Caps;
175
+ } ? Caps : never> & Refusal<Layer, Parent, `${R & string}.${F & string}.`>;
176
+ } & Refusal<Layer, Parent, `${R & string}.`>;
177
+ };
178
+ } & Refusal<Layer, Parent, "">;
179
+ };
180
+ /** A layer's own configuration: `application`, `client` or `agent`. */
181
+ type OverlayOf<Cfg, Layer extends "application" | "client" | "agent"> = (Cfg & {
182
+ readonly [L in Layer]?: unknown;
183
+ })[Layer];
184
+ /** An overlay's exemptions schema, by the overlay's own `exposed`. */
185
+ type OverlayExemptionsSchema<M extends AvAdapterModel, Cfg, Overlay, Layer extends "application" | "client"> = Overlay extends {
186
+ readonly exposed: false;
187
+ } ? PickExemptionsSchema<RootViewResources<M, Cfg>, Layer, "root"> : ExemptionsSchema<M, Cfg>;
188
+ type LayerKeysSchema = {
189
+ readonly exposed: Leaf;
190
+ readonly transactionsStyle: Leaf;
191
+ readonly limits: LimitsSchema;
192
+ readonly pipelines: PipelinesSchema;
193
+ };
194
+ type RootResourcesSchema<M extends AvAdapterModel> = {
195
+ readonly [R in AvConfigResourceKey<M>]: ResourceSchema<M, R, FieldsSchema<M, R, "root", AvAdapterFieldKey<M, R>> & {
196
+ readonly [otherKeys]: RootScalarFieldSchema;
197
+ }> & {
198
+ readonly managedElsewhere: Leaf;
199
+ };
200
+ };
201
+ /**
202
+ * One root `resources.<R>` block, checked key by key as
203
+ * {@link AvConfigExact} checks it in place.
204
+ */
205
+ export type ExactRootResource<M extends AvAdapterModel, R extends AvConfigResourceKey<M>, Block> = Exact<RootResourcesSchema<M>[R], Block>;
206
+ /**
207
+ * One overlay `resources.<R>` block, checked key by key as
208
+ * {@link AvConfigExact} checks it in place, its field names read from `Cfg`.
209
+ */
210
+ export type ExactOverlayResource<M extends AvAdapterModel, Cfg, R extends AvConfigResourceKey<M>, Block> = Exact<ResourceSchema<M, R, FieldsSchema<M, R, "overlay", AvEffectiveFieldKey<M, Cfg, R>>>, Block>;
211
+ type OverlaySchema<M extends AvAdapterModel, Cfg, Layer extends "application" | "client"> = LayerKeysSchema & {
212
+ readonly resources: {
213
+ readonly [R in AvConfigResourceKey<M>]: ResourceSchema<M, R, FieldsSchema<M, R, "overlay", AvEffectiveFieldKey<M, Cfg, R>>>;
214
+ };
215
+ readonly exemptions: OverlayExemptionsSchema<M, Cfg, OverlayOf<Cfg, Layer>, Layer>;
216
+ };
217
+ type McpSchema = {
218
+ readonly path: Leaf;
219
+ readonly authorization: {
220
+ readonly servers: Leaf;
221
+ readonly verify: Leaf;
222
+ };
223
+ };
224
+ /** The layer the agent extends, as authored: `"client"` when it states none. */
225
+ type AgentParentOf<Cfg> = OverlayOf<Cfg, "agent"> extends {
226
+ readonly extends: infer Parent;
227
+ } ? Parent : "client";
228
+ /** A Pick agent's exemptions, against the view of the layer it extends. */
229
+ type AgentPickExemptionsSchema<M extends AvAdapterModel, Cfg, Parent> = Parent extends "application" | "client" ? [Parent] extends ["application"] | ["client"] ? PickExemptionsSchema<OverlayViewResources<M, Cfg, Parent>, "agent", Parent> : PickExemptionsSchema<RootViewResources<M, Cfg>, "agent", "root"> : PickExemptionsSchema<RootViewResources<M, Cfg>, "agent", "root">;
230
+ type AgentSchema<M extends AvAdapterModel, Cfg> = LayerKeysSchema & {
231
+ readonly extends: Leaf;
232
+ readonly resources: {
233
+ readonly [R in AvConfigResourceKey<M>]: ResourceSchema<M, R, FieldsSchema<M, R, "overlay", AvEffectiveFieldKey<M, Cfg, R>>>;
234
+ };
235
+ readonly exemptions: OverlayOf<Cfg, "agent"> extends {
236
+ readonly exposed: false;
237
+ } ? AgentPickExemptionsSchema<M, Cfg, AgentParentOf<Cfg>> : ExemptionsSchema<M, Cfg>;
238
+ };
239
+ type RootSchema<M extends AvAdapterModel, Cfg> = LayerKeysSchema & {
240
+ readonly api: Leaf;
241
+ readonly mcp: McpSchema;
242
+ readonly adapter: Leaf;
243
+ readonly prebuilt: Leaf;
244
+ readonly policy: {
245
+ readonly engine: Leaf;
246
+ readonly principal: Leaf;
247
+ };
248
+ readonly access: Leaf;
249
+ readonly diagnostics: Leaf;
250
+ readonly misuse: Leaf;
251
+ readonly resources: RootResourcesSchema<M>;
252
+ readonly exemptions: ExemptionsSchema<M, Cfg>;
253
+ readonly application: OverlaySchema<M, Cfg, "application">;
254
+ readonly client: OverlaySchema<M, Cfg, "client">;
255
+ readonly agent: AgentSchema<M, Cfg>;
256
+ };
257
+ /**
258
+ * `V` with every key schema `S` lacks mapped to `never`, or to the sentence a
259
+ * refusing level states; every leaf `unknown`.
260
+ */
261
+ type Exact<S, V> = [S] extends [Leaf] ? unknown : V extends readonly unknown[] ? S extends ListOf<infer Names> ? readonly Names[] : unknown : V extends (...args: any) => any ? unknown : V extends object ? string extends keyof V ? unknown : {
262
+ readonly [K in keyof V]: K extends keyof S ? Exact<S[K], V[K]> : typeof otherKeys extends keyof S ? Exact<S[typeof otherKeys], V[K]> : typeof refusal extends keyof S ? RefusalOf<S[typeof refusal], K, V[K]> : never;
263
+ } : unknown;
264
+ /**
265
+ * The authored configuration `Cfg`, checked key by key: a key no level of the
266
+ * configuration admits is `never`, a type error at the key. Such a key is a moved
267
+ * rc.0 key, a `definition` in an overlay, a stage a relation field does not take,
268
+ * or a name the model and the root do not have.
269
+ */
270
+ export type AvConfigExact<M extends AvAdapterModel, Cfg> = Exact<RootSchema<M, Cfg>, Cfg> & ExposedWithExemptions<Cfg, "application"> & ExposedWithExemptions<Cfg, "client"> & ExposedWithExemptions<Cfg, "agent"> & ForceNeedsTransactions<M, Cfg> & (Cfg extends {
271
+ readonly access: object;
272
+ readonly policy: object;
273
+ } ? {
274
+ readonly policy: readonly [
275
+ "Error: `access` brings the policy engine; remove `policy`"
276
+ ];
277
+ } : unknown);
278
+ /** A layer's own literal `transactionsStyle`, `undefined` when it states none. */
279
+ type StyleOf<Layer> = Layer extends {
280
+ readonly transactionsStyle: infer Style;
281
+ } ? Style : undefined;
282
+ /** Whether one origin's effective `transactionsStyle` is certainly `"none"`. */
283
+ type CertainlyNone<M extends AvAdapterModel, Cfg, Layer extends "application" | "client"> = [M["transactions"]] extends ["none"] ? true : [StyleOf<OverlayOf<Cfg, Layer>>] extends [undefined] ? [StyleOf<Cfg>] extends ["none"] ? true : false : [StyleOf<OverlayOf<Cfg, Layer>>] extends ["none"] ? true : false;
284
+ /** A `resources` tree in which no family or variant may set `forceTransaction: true`. */
285
+ type UnforcedResources<M extends AvAdapterModel> = {
286
+ readonly resources?: {
287
+ readonly [R in AvConfigResourceKey<M>]?: {
288
+ readonly operations?: {
289
+ readonly [F in keyof Operations<M, R>]?: {
290
+ readonly forceTransaction?: false;
291
+ } & {
292
+ readonly [V in keyof NonNullable<Operations<M, R>[F]>]?: {
293
+ readonly forceTransaction?: false;
294
+ };
295
+ };
296
+ };
297
+ };
298
+ };
299
+ };
300
+ /** Refuses `forceTransaction: true` where the effective style is certainly `"none"`. */
301
+ type ForceNeedsTransactions<M extends AvAdapterModel, Cfg> = string extends keyof Cfg ? unknown : ForcedLayers<M, Cfg>;
302
+ /** Whether the agent's effective `transactionsStyle` is certainly `"none"`. */
303
+ type AgentCertainlyNone<M extends AvAdapterModel, Cfg> = [
304
+ M["transactions"]
305
+ ] extends ["none"] ? true : [StyleOf<OverlayOf<Cfg, "agent">>] extends [undefined] ? [AgentParentOf<Cfg>] extends ["application"] ? CertainlyNone<M, Cfg, "application"> : [AgentParentOf<Cfg>] extends ["client"] ? CertainlyNone<M, Cfg, "client"> : [AgentParentOf<Cfg>] extends ["root"] ? [StyleOf<Cfg>] extends ["none"] ? true : false : false : [StyleOf<OverlayOf<Cfg, "agent">>] extends ["none"] ? true : false;
306
+ type ForcedLayers<M extends AvAdapterModel, Cfg> = (AgentCertainlyNone<M, Cfg> extends true ? {
307
+ readonly agent?: UnforcedResources<M>;
308
+ } : unknown) & (CertainlyNone<M, Cfg, "application"> extends true ? CertainlyNone<M, Cfg, "client"> extends true ? UnforcedResources<M> : unknown : unknown) & (CertainlyNone<M, Cfg, "application"> extends true ? {
309
+ readonly application?: UnforcedResources<M>;
310
+ } : unknown) & (CertainlyNone<M, Cfg, "client"> extends true ? {
311
+ readonly client?: UnforcedResources<M>;
312
+ } : unknown);
313
+ /** Requires an overlay's `exposed` when the overlay states `exemptions`. */
314
+ type ExposedWithExemptions<Cfg, Layer extends "application" | "client" | "agent"> = Cfg extends {
315
+ readonly [L in Layer]: infer Overlay;
316
+ } ? Overlay extends {
317
+ readonly exemptions: unknown;
318
+ } ? Overlay extends {
319
+ readonly exposed: unknown;
320
+ } ? unknown : {
321
+ readonly [L in Layer]: {
322
+ readonly exposed: boolean;
323
+ };
324
+ } : unknown : unknown;
325
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { AvComputeCreate, AvComputeRead, AvComputeUpdate } from "../runtime/field-compute.js";
2
+ /** One field's compute stages for one origin, each phase already chained. */
3
+ export type ResolvedFieldCompute = {
4
+ readonly create?: AvComputeCreate;
5
+ readonly update?: AvComputeUpdate;
6
+ readonly read?: AvComputeRead;
7
+ };
8
+ /** Compute stages for one origin, by Resource and field name. */
9
+ export type ResolvedComputeConfig = Readonly<Record<string, Readonly<Record<string, ResolvedFieldCompute>>>>;
10
+ /**
11
+ * One layer's compute stages, read off its `resources` tree: per Resource, per
12
+ * field, its `pipelines.compute`. Only phases a layer states are present.
13
+ */
14
+ export declare function computeOfLayer(resources: unknown): ResolvedComputeConfig;
15
+ /**
16
+ * The compute stages that run for one origin: the root's, then the overlay's,
17
+ * chained phase by phase. Nothing is disabled from below.
18
+ */
19
+ export declare function chainCompute(root: ResolvedComputeConfig, overlay: ResolvedComputeConfig): ResolvedComputeConfig;
20
+ /** The fields of `resource` with a `compute.create` stage in `compute`. */
21
+ export declare function createComputedFields(compute: ResolvedComputeConfig, resource: string): ReadonlySet<string>;
@@ -0,0 +1,123 @@
1
+ function chainWrite(root, overlay) {
2
+ if (root === undefined || overlay === undefined) {
3
+ return root ?? overlay;
4
+ }
5
+ return async (context) => {
6
+ const first = await root(context);
7
+ if (first === undefined) {
8
+ return overlay(context);
9
+ }
10
+ const second = await overlay({
11
+ ...context,
12
+ value: first,
13
+ data: { ...context.data, [context.field]: first },
14
+ });
15
+ return second === undefined ? first : second;
16
+ };
17
+ }
18
+ function readCompute(stage) {
19
+ return typeof stage === "function" ? stage : stage.compute;
20
+ }
21
+ function readDependencies(stage) {
22
+ return typeof stage === "function" ? [] : (stage.dependsOn ?? []);
23
+ }
24
+ function chainRead(root, overlay) {
25
+ if (root === undefined || overlay === undefined) {
26
+ return root ?? overlay;
27
+ }
28
+ const rootCompute = readCompute(root);
29
+ const overlayCompute = readCompute(overlay);
30
+ const compute = async (context) => {
31
+ const first = await rootCompute(context);
32
+ if (first === undefined) {
33
+ return overlayCompute(context);
34
+ }
35
+ const second = await overlayCompute({
36
+ ...context,
37
+ value: first,
38
+ record: { ...context.record, [context.field]: first },
39
+ });
40
+ return second === undefined ? first : second;
41
+ };
42
+ const dependsOn = [
43
+ ...new Set([...readDependencies(root), ...readDependencies(overlay)]),
44
+ ];
45
+ return typeof root === "function" && typeof overlay === "function"
46
+ ? compute
47
+ : { dependsOn, compute };
48
+ }
49
+ function isRecord(value) {
50
+ return value !== null && typeof value === "object" && !Array.isArray(value);
51
+ }
52
+ export function computeOfLayer(resources) {
53
+ const result = {};
54
+ if (!isRecord(resources)) {
55
+ return result;
56
+ }
57
+ for (const [resourceName, resource] of Object.entries(resources)) {
58
+ if (!isRecord(resource) || !isRecord(resource.fields)) {
59
+ continue;
60
+ }
61
+ for (const [fieldName, field] of Object.entries(resource.fields)) {
62
+ if (!isRecord(field) || !isRecord(field.pipelines)) {
63
+ continue;
64
+ }
65
+ const compute = field.pipelines.compute;
66
+ if (!isRecord(compute)) {
67
+ continue;
68
+ }
69
+ const phases = {};
70
+ if (compute.create !== undefined) {
71
+ phases.create = compute.create;
72
+ }
73
+ if (compute.update !== undefined) {
74
+ phases.update = compute.update;
75
+ }
76
+ if (compute.read !== undefined) {
77
+ phases.read = compute.read;
78
+ }
79
+ if (Object.keys(phases).length === 0) {
80
+ continue;
81
+ }
82
+ result[resourceName] ??= {};
83
+ result[resourceName][fieldName] = phases;
84
+ }
85
+ }
86
+ return result;
87
+ }
88
+ export function chainCompute(root, overlay) {
89
+ const result = {};
90
+ for (const resourceName of new Set([
91
+ ...Object.keys(root),
92
+ ...Object.keys(overlay),
93
+ ])) {
94
+ const rootFields = root[resourceName] ?? {};
95
+ const overlayFields = overlay[resourceName] ?? {};
96
+ const fields = {};
97
+ for (const fieldName of new Set([
98
+ ...Object.keys(rootFields),
99
+ ...Object.keys(overlayFields),
100
+ ])) {
101
+ const rootField = rootFields[fieldName] ?? {};
102
+ const overlayField = overlayFields[fieldName] ?? {};
103
+ const create = chainWrite(rootField.create, overlayField.create);
104
+ const update = chainWrite(rootField.update, overlayField.update);
105
+ const read = chainRead(rootField.read, overlayField.read);
106
+ fields[fieldName] = {
107
+ ...(create !== undefined ? { create } : {}),
108
+ ...(update !== undefined ? { update } : {}),
109
+ ...(read !== undefined ? { read } : {}),
110
+ };
111
+ }
112
+ result[resourceName] = fields;
113
+ }
114
+ return result;
115
+ }
116
+ export function createComputedFields(compute, resource) {
117
+ const fields = Object.hasOwn(compute, resource)
118
+ ? compute[resource]
119
+ : undefined;
120
+ return new Set(Object.entries(fields ?? {})
121
+ .filter(([, phases]) => phases.create !== undefined)
122
+ .map(([field]) => field));
123
+ }