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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/CHANGELOG.md +2068 -1
  2. package/ERRORS.md +142 -0
  3. package/README.md +485 -60
  4. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  5. package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
  6. package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
  7. package/dist/adapters/adapter-field.d.ts +33 -11
  8. package/dist/adapters/adapter-identifier.d.ts +15 -6
  9. package/dist/adapters/adapter-identifier.js +6 -1
  10. package/dist/adapters/adapter-model.d.ts +18 -9
  11. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  12. package/dist/adapters/adapter-operation.d.ts +21 -6
  13. package/dist/adapters/adapter-resource.d.ts +23 -9
  14. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  15. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  16. package/dist/adapters/adapter.interface.d.ts +59 -29
  17. package/dist/avz/avz-check.factory.d.ts +83 -0
  18. package/dist/avz/avz-check.factory.js +116 -0
  19. package/dist/avz/avz-check.registry.d.ts +35 -0
  20. package/dist/avz/avz-check.registry.js +9 -0
  21. package/dist/avz/avz.d.ts +203 -0
  22. package/dist/{json → avz}/avz.js +150 -8
  23. package/dist/{json → avz}/index.d.ts +2 -1
  24. package/dist/{json → avz}/json-shape.registry.d.ts +9 -8
  25. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  26. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  27. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  28. package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
  29. package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
  30. package/dist/compiler/contract.compiler.d.ts +23 -17
  31. package/dist/compiler/contract.compiler.js +753 -443
  32. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  33. package/dist/compiler/create-requirements.projector.js +423 -0
  34. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  35. package/dist/compiler/field-validator.compiler.js +238 -0
  36. package/dist/compiler/managed-elsewhere.projector.d.ts +52 -0
  37. package/dist/compiler/managed-elsewhere.projector.js +179 -0
  38. package/dist/compiler/managed-elsewhere.validator.d.ts +9 -0
  39. package/dist/compiler/managed-elsewhere.validator.js +74 -0
  40. package/dist/config/any-framework-config.d.ts +19 -12
  41. package/dist/config/computed-fields.d.ts +62 -0
  42. package/dist/config/computed-fields.js +73 -0
  43. package/dist/config/config-diagnostic.d.ts +11 -4
  44. package/dist/config/config-diagnostic.guidance.d.ts +6 -0
  45. package/dist/config/config-diagnostic.guidance.js +32 -0
  46. package/dist/config/config-layer.d.ts +15 -6
  47. package/dist/config/config.resolver.d.ts +98 -31
  48. package/dist/config/config.resolver.js +173 -44
  49. package/dist/config/config.validator.d.ts +7 -7
  50. package/dist/config/config.validator.js +792 -69
  51. package/dist/config/define-resource.d.ts +53 -0
  52. package/dist/config/define-resource.js +14 -0
  53. package/dist/config/effective-fields.d.ts +19 -23
  54. package/dist/config/entrypoint.normalizer.d.ts +4 -3
  55. package/dist/config/exact-framework-config.d.ts +325 -0
  56. package/dist/config/field-compute.resolver.d.ts +21 -0
  57. package/dist/config/field-compute.resolver.js +123 -0
  58. package/dist/config/field-pipeline-config.d.ts +47 -0
  59. package/dist/config/forced-operation.validator.d.ts +10 -0
  60. package/dist/config/forced-operation.validator.js +66 -0
  61. package/dist/config/framework-config.d.ts +148 -39
  62. package/dist/config/framework-exemptions-config.d.ts +91 -0
  63. package/dist/config/framework-exemptions-config.js +1 -0
  64. package/dist/config/framework-field-definition.d.ts +78 -0
  65. package/dist/config/framework-field-definition.js +28 -0
  66. package/dist/config/framework-resources-config.d.ts +127 -0
  67. package/dist/config/framework-resources-config.js +1 -0
  68. package/dist/config/pipeline-config.d.ts +56 -20
  69. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  70. package/dist/config/pipeline-tree.resolver.js +220 -0
  71. package/dist/config/stage-type.eraser.d.ts +65 -0
  72. package/dist/config/stage-type.eraser.js +1 -0
  73. package/dist/contracts/access-route.rules.d.ts +10 -0
  74. package/dist/contracts/access-route.rules.js +45 -0
  75. package/dist/contracts/capability.d.ts +37 -12
  76. package/dist/contracts/capability.js +20 -0
  77. package/dist/contracts/client-contract-structure.validator.d.ts +621 -114
  78. package/dist/contracts/client-contract-structure.validator.js +189 -10
  79. package/dist/contracts/contract-access.d.ts +29 -0
  80. package/dist/contracts/contract-access.js +1 -0
  81. package/dist/contracts/contract-canonicalizer.d.ts +27 -3
  82. package/dist/contracts/contract-canonicalizer.js +168 -29
  83. package/dist/contracts/contract-hash.d.ts +11 -7
  84. package/dist/contracts/contract-hash.js +4 -3
  85. package/dist/contracts/contract-limits.d.ts +4 -1
  86. package/dist/contracts/contract-limits.js +1 -0
  87. package/dist/contracts/contract-lookup.d.ts +5 -5
  88. package/dist/contracts/contract-protocol.d.ts +4 -4
  89. package/dist/contracts/contract.d.ts +51 -17
  90. package/dist/contracts/create-requirements.d.ts +35 -0
  91. package/dist/contracts/create-requirements.js +1 -0
  92. package/dist/contracts/enum-definition.d.ts +1 -1
  93. package/dist/contracts/field-check.d.ts +101 -0
  94. package/dist/contracts/field-check.js +1 -0
  95. package/dist/contracts/field.d.ts +109 -42
  96. package/dist/contracts/identifier.d.ts +4 -4
  97. package/dist/contracts/json-schema.projector.d.ts +11 -0
  98. package/dist/contracts/json-schema.projector.js +78 -0
  99. package/dist/contracts/json-shape.d.ts +12 -1
  100. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  101. package/dist/contracts/resource-operations.d.ts +28 -28
  102. package/dist/contracts/resource.d.ts +15 -9
  103. package/dist/contracts/scalar-value-type.d.ts +17 -15
  104. package/dist/contracts/scalar.d.ts +3 -3
  105. package/dist/contracts/transaction-capability.d.ts +1 -1
  106. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  107. package/dist/framework/access-facade.d.ts +116 -0
  108. package/dist/framework/access-facade.js +120 -0
  109. package/dist/framework/contract-view.d.ts +315 -145
  110. package/dist/framework/framework-construction.error.d.ts +21 -11
  111. package/dist/framework/framework-construction.error.js +20 -4
  112. package/dist/framework/framework.d.ts +71 -26
  113. package/dist/framework/framework.factory.d.ts +8 -6
  114. package/dist/framework/framework.factory.js +150 -38
  115. package/dist/framework/operation-facade.d.ts +192 -54
  116. package/dist/framework/operation-facade.js +10 -1
  117. package/dist/index.d.ts +67 -50
  118. package/dist/index.js +7 -6
  119. package/dist/internal.d.ts +20 -10
  120. package/dist/internal.js +9 -1
  121. package/dist/operations/database-refusal.d.ts +51 -0
  122. package/dist/operations/database-refusal.js +45 -0
  123. package/dist/operations/operation-arguments.d.ts +381 -228
  124. package/dist/operations/operation-call.d.ts +31 -28
  125. package/dist/operations/operation-identity.d.ts +10 -10
  126. package/dist/operations/operation-result.d.ts +25 -23
  127. package/dist/operations/operation-validator-core.d.ts +6 -6
  128. package/dist/operations/operation-validator-core.js +172 -38
  129. package/dist/operations/operation-validator.d.ts +10 -10
  130. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  131. package/dist/operations/structural-limits.walker.d.ts +7 -7
  132. package/dist/operations/structural-limits.walker.js +145 -0
  133. package/dist/operations/validation-code.d.ts +11 -6
  134. package/dist/operations/validation-code.guidance.d.ts +6 -0
  135. package/dist/operations/validation-code.guidance.js +90 -0
  136. package/dist/operations/validation-code.js +4 -0
  137. package/dist/operations/write-scope.resolver.d.ts +10 -6
  138. package/dist/operations/write-scope.resolver.js +2 -0
  139. package/dist/policy/access-provider.interface.d.ts +91 -0
  140. package/dist/policy/access-provider.interface.js +1 -0
  141. package/dist/policy/access-provider.registry.d.ts +17 -0
  142. package/dist/policy/access-provider.registry.js +15 -0
  143. package/dist/policy/access-question.d.ts +20 -0
  144. package/dist/policy/access-question.js +1 -0
  145. package/dist/policy/access-question.registry.d.ts +5 -0
  146. package/dist/policy/access-question.registry.js +19 -0
  147. package/dist/policy/access-question.runtime.d.ts +36 -0
  148. package/dist/policy/access-question.runtime.js +297 -0
  149. package/dist/policy/access-verb.table.d.ts +56 -0
  150. package/dist/policy/access-verb.table.js +21 -0
  151. package/dist/policy/access-verbs.d.ts +46 -0
  152. package/dist/policy/access-verbs.js +1 -0
  153. package/dist/policy/policy-admission.d.ts +20 -0
  154. package/dist/policy/policy-admission.js +409 -0
  155. package/dist/policy/policy-after-update.runtime.d.ts +79 -0
  156. package/dist/policy/policy-after-update.runtime.js +208 -0
  157. package/dist/policy/policy-condition.d.ts +15 -0
  158. package/dist/policy/policy-condition.js +36 -0
  159. package/dist/policy/policy-engine.d.ts +205 -0
  160. package/dist/policy/policy-engine.js +1 -0
  161. package/dist/policy/policy-named-rows.d.ts +18 -0
  162. package/dist/policy/policy-named-rows.js +51 -0
  163. package/dist/policy/policy-nested-write.runtime.d.ts +44 -0
  164. package/dist/policy/policy-nested-write.runtime.js +545 -0
  165. package/dist/policy/policy-read.runtime.d.ts +81 -0
  166. package/dist/policy/policy-read.runtime.js +503 -0
  167. package/dist/policy/policy-reference-write.runtime.d.ts +51 -0
  168. package/dist/policy/policy-reference-write.runtime.js +345 -0
  169. package/dist/policy/policy-request.d.ts +41 -0
  170. package/dist/policy/policy-request.js +63 -0
  171. package/dist/policy/policy-session.d.ts +106 -0
  172. package/dist/policy/policy-session.js +295 -0
  173. package/dist/policy/policy-startup.validator.d.ts +10 -0
  174. package/dist/policy/policy-startup.validator.js +112 -0
  175. package/dist/policy/policy-write.runtime.d.ts +39 -0
  176. package/dist/policy/policy-write.runtime.js +532 -0
  177. package/dist/prebuilt/core-version.generated.d.ts +2 -0
  178. package/dist/prebuilt/core-version.generated.js +1 -0
  179. package/dist/prebuilt/prebuilt-changes.d.ts +29 -0
  180. package/dist/prebuilt/prebuilt-changes.js +65 -0
  181. package/dist/prebuilt/prebuilt-contracts.d.ts +40 -0
  182. package/dist/prebuilt/prebuilt-contracts.emitter.d.ts +16 -0
  183. package/dist/prebuilt/prebuilt-contracts.emitter.js +50 -0
  184. package/dist/prebuilt/prebuilt-contracts.js +1 -0
  185. package/dist/prebuilt/prebuilt-contracts.loader.d.ts +19 -0
  186. package/dist/prebuilt/prebuilt-contracts.loader.js +77 -0
  187. package/dist/prebuilt/prebuilt-inputs.fingerprint.d.ts +16 -0
  188. package/dist/prebuilt/prebuilt-inputs.fingerprint.js +229 -0
  189. package/dist/protocol/absent-route.responder.d.ts +17 -34
  190. package/dist/protocol/absent-route.responder.js +53 -20
  191. package/dist/protocol/contract-document.responder.d.ts +5 -4
  192. package/dist/protocol/contract-document.responder.js +2 -2
  193. package/dist/protocol/http-request.decoder.d.ts +33 -13
  194. package/dist/protocol/http-request.decoder.js +34 -11
  195. package/dist/protocol/http-request.reader.d.ts +9 -6
  196. package/dist/protocol/http-request.reader.js +1 -0
  197. package/dist/protocol/http-response.encoder.d.ts +4 -4
  198. package/dist/protocol/http-response.encoder.js +94 -55
  199. package/dist/protocol/http-status.table.d.ts +2 -2
  200. package/dist/protocol/operation-response.guard.d.ts +2 -2
  201. package/dist/protocol/protocol-headers.d.ts +3 -3
  202. package/dist/protocol/protocol-surface.d.ts +10 -5
  203. package/dist/protocol/protocol-surface.js +7 -0
  204. package/dist/protocol/protocol.binder.d.ts +66 -28
  205. package/dist/protocol/protocol.binder.js +16 -10
  206. package/dist/protocol/protocol.handler.d.ts +34 -14
  207. package/dist/protocol/protocol.handler.js +122 -18
  208. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  209. package/dist/protocol/unmounted-route.error.js +2 -2
  210. package/dist/runtime/caller-data.copier.d.ts +22 -7
  211. package/dist/runtime/caller-data.copier.js +30 -17
  212. package/dist/runtime/caller-data.door.d.ts +18 -11
  213. package/dist/runtime/caller-data.door.js +6 -4
  214. package/dist/runtime/computed-read-runtime.d.ts +12 -6
  215. package/dist/runtime/computed-read-runtime.js +271 -71
  216. package/dist/runtime/computed-value.error.d.ts +7 -6
  217. package/dist/runtime/computed-value.error.js +5 -4
  218. package/dist/runtime/context-executor.runtime.d.ts +60 -0
  219. package/dist/runtime/context-executor.runtime.js +277 -0
  220. package/dist/runtime/core-class.brand.d.ts +10 -0
  221. package/dist/runtime/core-class.brand.js +21 -0
  222. package/dist/runtime/create-requirement.d.ts +34 -79
  223. package/dist/runtime/create-requirement.js +205 -74
  224. package/dist/runtime/decimal.d.ts +16 -2
  225. package/dist/runtime/decimal.js +22 -1
  226. package/dist/runtime/diagnostics-reporter.d.ts +91 -30
  227. package/dist/runtime/diagnostics-reporter.js +37 -1
  228. package/dist/runtime/error-boundary.d.ts +73 -9
  229. package/dist/runtime/error-boundary.js +57 -19
  230. package/dist/runtime/error-guidance.d.ts +12 -0
  231. package/dist/runtime/error-guidance.js +1 -0
  232. package/dist/runtime/error.catalog.d.ts +49 -0
  233. package/dist/runtime/error.catalog.js +49 -0
  234. package/dist/runtime/execution-options.d.ts +18 -2
  235. package/dist/runtime/field-check.evaluator.d.ts +27 -0
  236. package/dist/runtime/field-check.evaluator.js +521 -0
  237. package/dist/runtime/field-compute.d.ts +65 -0
  238. package/dist/runtime/field-compute.js +1 -0
  239. package/dist/runtime/field-stage.plan.d.ts +15 -0
  240. package/dist/runtime/field-stage.plan.js +27 -0
  241. package/dist/runtime/field-stage.runtime.d.ts +37 -0
  242. package/dist/runtime/field-stage.runtime.js +147 -0
  243. package/dist/runtime/field-validator.runtime.d.ts +29 -0
  244. package/dist/runtime/field-validator.runtime.js +126 -0
  245. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  246. package/dist/runtime/framework-error-class.table.js +25 -0
  247. package/dist/runtime/framework-error.d.ts +68 -8
  248. package/dist/runtime/framework-error.factory.d.ts +4 -0
  249. package/dist/runtime/framework-error.factory.js +15 -0
  250. package/dist/runtime/framework-error.js +32 -2
  251. package/dist/runtime/framework-warning.emitter.d.ts +6 -0
  252. package/dist/runtime/framework-warning.emitter.js +8 -0
  253. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  254. package/dist/runtime/interceptor-next.error.js +6 -0
  255. package/dist/runtime/json-value.d.ts +11 -6
  256. package/dist/runtime/level-lifecycle.runtime.d.ts +26 -0
  257. package/dist/runtime/level-lifecycle.runtime.js +40 -0
  258. package/dist/runtime/misuse-reporter.d.ts +12 -12
  259. package/dist/runtime/mutation-planner.d.ts +20 -16
  260. package/dist/runtime/mutation-planner.js +48 -35
  261. package/dist/runtime/nested-write.walker.d.ts +32 -0
  262. package/dist/runtime/nested-write.walker.js +73 -0
  263. package/dist/runtime/operation-code.guidance.d.ts +6 -0
  264. package/dist/runtime/operation-code.guidance.js +167 -0
  265. package/dist/runtime/operation-request.d.ts +45 -11
  266. package/dist/runtime/operation-response.d.ts +17 -17
  267. package/dist/runtime/operation-runtime.d.ts +133 -27
  268. package/dist/runtime/operation-runtime.js +576 -84
  269. package/dist/runtime/outcome-mapper.d.ts +17 -5
  270. package/dist/runtime/outcome-mapper.js +23 -6
  271. package/dist/runtime/output-validator.d.ts +11 -11
  272. package/dist/runtime/output-validator.js +3 -3
  273. package/dist/runtime/owned-execution.registry.d.ts +16 -6
  274. package/dist/runtime/pipe-output.validator.d.ts +43 -18
  275. package/dist/runtime/pipe-output.validator.js +15 -13
  276. package/dist/runtime/pipeline.d.ts +221 -34
  277. package/dist/runtime/readonly-value.d.ts +47 -0
  278. package/dist/runtime/readonly-value.js +189 -0
  279. package/dist/runtime/referential-action.d.ts +1 -1
  280. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  281. package/dist/runtime/request-envelope.validator.js +12 -7
  282. package/dist/runtime/request-id.d.ts +1 -1
  283. package/dist/runtime/request-state.d.ts +14 -0
  284. package/dist/runtime/request-state.js +1 -0
  285. package/dist/runtime/request-state.resolver.d.ts +12 -0
  286. package/dist/runtime/request-state.resolver.js +20 -0
  287. package/dist/runtime/scalar-runtime.d.ts +33 -25
  288. package/dist/runtime/scalar-runtime.js +105 -38
  289. package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
  290. package/dist/runtime/unsent-value.normalizer.js +128 -0
  291. package/dist/transactions/deferred-operation.d.ts +35 -20
  292. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  293. package/dist/transactions/operation-arguments-encoder.js +8 -3
  294. package/dist/transactions/operation-fingerprint.js +2 -2
  295. package/dist/transactions/sql-statement.d.ts +85 -0
  296. package/dist/transactions/sql-statement.js +47 -0
  297. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  298. package/dist/transactions/sql-statement.validator.js +167 -0
  299. package/dist/transactions/transaction-envelope.d.ts +9 -8
  300. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  301. package/dist/transactions/transaction-integrity-error.js +7 -2
  302. package/dist/transactions/transaction-plan-assembler.d.ts +30 -13
  303. package/dist/transactions/transaction-plan-assembler.js +184 -32
  304. package/dist/transactions/transaction-plan-validator.d.ts +50 -25
  305. package/dist/transactions/transaction-plan-validator.js +96 -38
  306. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  307. package/dist/transactions/transaction-reference-resolver.d.ts +21 -3
  308. package/dist/transactions/transaction-reference-resolver.js +26 -14
  309. package/dist/transactions/transaction-reference-validator.d.ts +74 -4
  310. package/dist/transactions/transaction-reference-validator.js +129 -71
  311. package/dist/transactions/transaction-reference.d.ts +14 -14
  312. package/dist/transactions/transaction-reference.js +5 -0
  313. package/dist/transactions/transaction-request.d.ts +22 -9
  314. package/dist/transactions/transaction-response.d.ts +6 -6
  315. package/dist/transactions/transaction-runtime.d.ts +12 -8
  316. package/dist/transactions/transaction-runtime.js +218 -50
  317. package/dist/transactions/transaction-settlement.runtime.d.ts +52 -0
  318. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  319. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  320. package/dist/transactions/transaction-slot-path-error.js +4 -2
  321. package/dist/transactions/transaction-slot-writer.js +2 -2
  322. package/dist/transactions/transaction-stage.runtime.d.ts +83 -0
  323. package/dist/transactions/transaction-stage.runtime.js +126 -0
  324. package/package.json +11 -9
  325. package/src/runtime/field-check.evaluator.ts +720 -0
  326. package/dist/config/define-fields.d.ts +0 -42
  327. package/dist/config/define-fields.js +0 -3
  328. package/dist/config/framework-behaviors-config.d.ts +0 -30
  329. package/dist/config/framework-fields-config.d.ts +0 -42
  330. package/dist/config/framework-restrictions-config.d.ts +0 -142
  331. package/dist/json/avz.d.ts +0 -96
  332. package/dist/runtime/field-behavior.d.ts +0 -48
  333. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  334. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  335. /package/dist/{json → avz}/index.js +0 -0
  336. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  337. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  338. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,48 +1,35 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
3
- import type { RequestOrigin } from "../config/config-layer.js";
4
- import type { ContractLimits } from "../contracts/contract-limits.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvConfigAny } from "../config/any-framework-config.js";
3
+ import type { AvRequestOrigin } from "../config/config-layer.js";
4
+ import type { ErasedResources } from "../config/stage-type.eraser.js";
5
+ import type { AvContractLimits } from "../contracts/contract-limits.js";
5
6
  import type { JsonShape, ShapedJsonSchema } from "../contracts/json-shape.js";
6
- /**
7
- * Whether `resolveRecord` descends into a value: an object that is no array and
8
- * no Json Shape.
9
- */
10
- type IsLayeredRecord<T> = [T] extends [readonly unknown[]] ? false : [T] extends [JsonShape] ? false : [T] extends [object] ? true : false;
11
- /**
12
- * A root record with a scoped record layered over it: a key the scoped side
13
- * states wins; when both sides are records they merge, recursively; otherwise
14
- * the scoped value replaces the root one.
15
- */
16
- type LayeredRecord<Root, Scoped> = {
17
- readonly [K in keyof Root | keyof Scoped]: K extends keyof Scoped ? K extends keyof Root ? [IsLayeredRecord<Root[K]>, IsLayeredRecord<Scoped[K]>] extends [
18
- true,
19
- true
20
- ] ? LayeredRecord<Root[K], Scoped[K]> : Scoped[K] : Scoped[K] : K extends keyof Root ? Root[K] : never;
21
- };
22
7
  /**
23
8
  * A record whose keys are literal, or `never`. An absent block, an index-signature
24
- * record — the `AnyFrameworkConfig` default, or a configuration annotated with the
25
- * wide `FrameworkConfig<M>` — names no field, so it contributes nothing rather
9
+ * record — the `AvConfigAny` default, or a configuration annotated with the
10
+ * wide `AvConfig<M>` — names no field, so it contributes nothing rather
26
11
  * than widening every resource's field set to `string`.
27
12
  */
28
13
  type LiteralRecord<T> = unknown extends T ? never : [NonNullable<T>] extends [never] ? never : [NonNullable<T>] extends [object] ? string extends keyof NonNullable<T> ? never : NonNullable<T> : never;
29
- type LayeredBlocks<Root, Scoped> = [Root] extends [never] ? Scoped : [Scoped] extends [never] ? Root : LayeredRecord<Root, Scoped>;
30
- /**
31
- * One configuration block as a derived Contract is compiled from it: the root
32
- * `Key`, with layer `Layer`'s `Key` layered over it.
33
- */
34
- type LayerBlock<Cfg, Layer extends RequestOrigin, Key extends "fields" | "restrictions"> = LayeredBlocks<LiteralRecord<(Cfg & {
35
- readonly [K in Key]?: unknown;
36
- })[Key]>, LiteralRecord<((Cfg & {
37
- readonly [L in Layer]?: unknown;
38
- })[Layer] & {
39
- readonly [K in Key]?: unknown;
40
- })[Key]>>;
41
- /** Root's own `Key` block, before any layer is layered over it. */
42
- type RootBlock<Cfg, Key extends "fields" | "restrictions"> = LiteralRecord<(Cfg & {
14
+ /** The root's own `Key` block. */
15
+ type RootBlock<Cfg, Key extends PropertyKey> = LiteralRecord<(Cfg & {
43
16
  readonly [K in Key]?: unknown;
44
17
  })[Key]>;
45
- /** One key's entry in a layered block, or `never` when the block has none. */
18
+ /** The root's `resources` block, its stages erased. */
19
+ type ResourcesBlock<Cfg> = ErasedResources<RootBlock<Cfg, "resources">>;
20
+ /** A `resources` block reduced to the `fields` entries the view reads. */
21
+ type ViewBlock<Block> = [Block] extends [never] ? never : {
22
+ readonly [R in keyof Block as "fields" extends keyof NonNullable<Block[R]> ? R : never]: {
23
+ readonly fields: (NonNullable<Block[R]> & {
24
+ readonly fields?: unknown;
25
+ })["fields"];
26
+ };
27
+ };
28
+ /** An overlay's `resources` block, its stages erased (see {@link ResourcesBlock}). */
29
+ type OverlayResourcesBlock<Cfg, Layer extends AvRequestOrigin> = ErasedResources<LiteralRecord<(LiteralRecord<OverlayOf<Cfg, Layer>> & {
30
+ readonly resources?: unknown;
31
+ })["resources"]>>;
32
+ /** One key's entry in a block, or `never` when the block has none. */
46
33
  type EntryOf<Block, Key> = [Block] extends [never] ? never : Key extends keyof Block ? LiteralRecord<NonNullable<Block[Key]>> : never;
47
34
  type ConfiguredCapabilities<FieldConfig> = [FieldConfig] extends [never] ? Record<never, never> : FieldConfig extends {
48
35
  readonly capabilities: infer Capabilities;
@@ -102,148 +89,331 @@ type AddedField<FieldConfig> = {
102
89
  type AddedFieldKey<ModelFields, ResourceConfig> = [ResourceConfig] extends [
103
90
  never
104
91
  ] ? never : Exclude<Extract<keyof ResourceConfig, string>, keyof ModelFields>;
92
+ /** A field entry's `definition`, or `never` when it states none. */
93
+ type DefinitionOf<FieldEntry> = EntryOf<FieldEntry, "definition">;
105
94
  /**
106
- * Whether a restriction entry hides what it names: only a literal `hidden: true`
107
- * does; `false` restores it.
95
+ * A Resource's fields before exposure: the model's and the ones the root's
96
+ * definitions add, each with its definition applied.
108
97
  */
109
- type IsHidden<Restriction> = [Restriction] extends [never] ? false : Restriction extends {
110
- readonly hidden: true;
111
- } ? true : false;
98
+ type LayeredFields<ModelFields, ResourceConfig> = {
99
+ readonly [F in keyof ModelFields | AddedFieldKey<ModelFields, ResourceConfig>]: F extends keyof ModelFields ? LayeredModelField<ModelFields[F], DefinitionOf<EntryOf<ResourceConfig, F>>> : AddedField<DefinitionOf<EntryOf<ResourceConfig, F>>>;
100
+ };
101
+ /** The configuration's `policy.engine`, read by indexed access (see {@link RootBlock}). */
102
+ type PolicyEngineOf<Cfg> = (NonNullable<(Cfg & {
103
+ readonly policy?: unknown;
104
+ })["policy"]> & {
105
+ readonly engine?: unknown;
106
+ })["engine"];
107
+ /** The configuration's `access.policy`, read by indexed access. */
108
+ type AccessEngineOf<Cfg> = ((Cfg & {
109
+ readonly access?: {
110
+ readonly policy?: unknown;
111
+ };
112
+ })["access"] & {
113
+ readonly policy?: unknown;
114
+ })["policy"];
115
+ /** The configuration's policy engine's `governed` set, when its type states one. */
116
+ type GovernedBlock<Cfg> = LiteralRecord<(NonNullable<PolicyEngineOf<Cfg>> & AccessEngineOf<Cfg> & {
117
+ readonly governed?: unknown;
118
+ })["governed"]>;
119
+ /** The names `Governed` lists for Resource `R`, or `never`. */
120
+ type GovernedNames<Governed, R> = [Governed] extends [never] ? never : R extends keyof Governed ? Governed[R] extends readonly (infer Name)[] ? Name : never : never;
121
+ /** The `governed: true` mark, added to a field: a key the field does not have. */
122
+ type GovernedMark = {
123
+ readonly governed: true;
124
+ };
125
+ /** A Resource's fields with each governed one marked. */
126
+ type GovernedFields<Fields, Governed> = [Governed] extends [never] ? Fields : {
127
+ readonly [F in keyof Fields]: F extends Governed ? Fields[F] & GovernedMark : Fields[F];
128
+ };
129
+ /** The root's `resources` block's Resources marked `managedElsewhere: true`. */
130
+ type ManagedBlock<Block> = [Block] extends [never] ? never : {
131
+ [R in keyof Block]-?: NonNullable<Block[R]> extends {
132
+ readonly managedElsewhere: true;
133
+ } ? R : never;
134
+ }[keyof Block];
135
+ /** The write families a managed Resource never offers. */
136
+ type WriteFamily = "create" | "update" | "delete" | "upsert";
137
+ /** The two write capabilities a field may have. */
138
+ type WriteStage = "create" | "update";
139
+ /** A managed Resource's operations: its reads alone. */
140
+ type ReadOperations<Operations> = {
141
+ readonly [F in keyof Operations as F extends WriteFamily ? never : F]: Operations[F];
142
+ };
143
+ /** Capabilities with each write member narrowed to `Kept` tokens, dropped when none is left. */
144
+ type KeptWrites<Caps, Kept> = {
145
+ readonly [K in keyof Caps as K extends WriteStage ? [Extract<MemberTokens<NonNullable<Caps[K]>>, Kept>] extends [never] ? never : K : K]: K extends WriteStage ? WithTokens<NonNullable<Caps[K]>, Extract<MemberTokens<NonNullable<Caps[K]>>, Kept>> : Caps[K];
146
+ };
147
+ /** A field whose writes keep only `Kept` directives. */
148
+ type WritesKept<Field, Kept> = {
149
+ readonly [P in keyof Field]: P extends "capabilities" ? KeptWrites<Field[P], Kept> : Field[P];
150
+ };
151
+ /** The directives a relation into a managed Resource keeps: the source row's own, where it holds the key. */
152
+ type SourceRowDirectives<Field> = Field extends {
153
+ readonly referenceFields: readonly [unknown, ...unknown[]];
154
+ } ? "$connect" | "$disconnect" : never;
155
+ /** A Resource's fields, written as a managed Resource's or as relations into one. */
156
+ type ManagedFields<Fields, Managed, IsManaged> = [Managed] extends [never] ? Fields : IsManaged extends true ? {
157
+ readonly [F in keyof Fields]: WritesKept<Fields[F], never>;
158
+ } : {
159
+ readonly [F in keyof Fields]: Fields[F] extends {
160
+ readonly kind: "relation";
161
+ readonly target: Managed;
162
+ } ? WritesKept<Fields[F], SourceRowDirectives<Fields[F]>> : Fields[F];
163
+ };
112
164
  /**
113
- * The keys a restrictions block hides, or `never` for a view that reads no
114
- * restrictions.
165
+ * The root's view with what is managed elsewhere applied: each managed
166
+ * Resource's writes withheld, and each relation's into one; under `Hidden` (the
167
+ * client's view) the managed Resources and every relation into them left out.
115
168
  */
116
- type HiddenKey<Restrictions> = [Restrictions] extends [never] ? never : {
117
- [K in keyof Restrictions]-?: IsHidden<EntryOf<Restrictions, K>> extends true ? K : never;
118
- }[keyof Restrictions];
119
- /** A restriction entry's `capabilities` block, or `never` when it states none. */
120
- type CapabilityRestrictionsOf<Entry> = [Entry] extends [never] ? never : EntryOf<Entry, "capabilities">;
121
- /** A restriction member that is a literal `false`: a denial. */
122
- type IsDenial<Value> = [Value] extends [false] ? true : false;
123
- /** A restriction member that is a literal `true`: a restoration. */
124
- type IsRestoration<Value> = [Value] extends [true] ? true : false;
125
- /** The tokens a capability member advertises, its qualifier aside. */
126
- type MemberTokens<Member, TokenKey extends string> = Member extends {
127
- readonly scopes: unknown;
128
- } ? TokenKey extends keyof Member ? Member[TokenKey] : never : Member;
129
- /** The positions a scope-qualified member holds in; `never` for an unqualified one. */
130
- type MemberScopes<Member> = Member extends {
131
- readonly scopes: infer Scopes;
132
- } ? Scopes : never;
133
- /** A relation's `create`, `update` or `reducers` member narrowed by a restriction. */
134
- type NarrowedScopedTokens<Member, Restriction, TokenKey extends "directives" | "reducers"> = Restriction extends readonly unknown[] ? [MemberScopes<Member>] extends [never] ? Restriction : {
135
- readonly [K in TokenKey | "scopes"]: K extends "scopes" ? MemberScopes<Member> : Restriction;
136
- } : Restriction extends object ? (Restriction extends {
137
- readonly scopes: infer Scopes;
138
- } ? Scopes : MemberScopes<Member>) extends infer Scopes ? [Scopes] extends [never] ? Restriction extends {
139
- readonly [K in TokenKey]: infer Tokens;
140
- } ? Tokens : MemberTokens<Member, TokenKey> : Scopes extends readonly [] ? false : {
141
- readonly [K in TokenKey | "scopes"]: K extends "scopes" ? Scopes : Restriction extends {
142
- readonly [T in TokenKey]: infer Tokens;
143
- } ? Tokens : MemberTokens<Member, TokenKey>;
144
- } : never : Member;
145
- /** One capability member narrowed by a list (or, on a relation, an object) restriction. */
146
- type NarrowedMember<Kind, Key, Member, Restriction> = Kind extends "relation" ? Key extends "select" | "include" ? Restriction extends readonly [] ? false : Restriction : Key extends "create" | "update" ? NarrowedScopedTokens<Member, Restriction, "directives"> : Key extends "reducers" ? NarrowedScopedTokens<Member, Restriction, "reducers"> : Restriction : Restriction;
147
- /** One capability member of a field under its layer's restrictions. */
148
- type RestrictedMember<Kind, Key, Member, Root, Layered> = IsRestoration<Layered> extends true ? Root extends readonly unknown[] | {
149
- readonly scopes?: unknown;
150
- } ? NarrowedMember<Kind, Key, Member, Root> : Member : [Layered] extends [boolean] ? Member : NarrowedMember<Kind, Key, Member, Layered>;
151
- /** The members a capabilities restriction denies, or narrows to nothing. */
152
- type DeniedMember<Kind, Own, Root, Layered> = {
153
- [P in keyof Own]-?: P extends keyof Layered ? IsDenial<Layered[P]> extends true ? P : [
154
- RestrictedMember<Kind, P, Own[P], P extends keyof Root ? Root[P] : undefined, Layered[P]>
155
- ] extends [false] ? P : never : never;
156
- }[keyof Own];
157
- /** A field's capabilities under its layer's restrictions. */
158
- type RestrictedCapabilities<Kind, Own, Root, Layered> = {
159
- readonly [P in keyof Own as P extends DeniedMember<Kind, Own, Root, Layered> ? never : P]: P extends keyof Layered ? RestrictedMember<Kind, P, Own[P], P extends keyof Root ? Root[P] : undefined, Layered[P]> : Own[P];
160
- };
161
- /** A view field with its layer's capability restrictions applied. */
162
- type RestrictedField<Field, RootEntry, Entry> = [
163
- CapabilityRestrictionsOf<Entry>
164
- ] extends [never] ? Field : {
165
- readonly [P in keyof Field]: P extends "capabilities" ? RestrictedCapabilities<Field extends {
166
- readonly kind: infer Kind;
167
- } ? Kind : never, Field[P], CapabilityRestrictionsOf<RootEntry>, CapabilityRestrictionsOf<Entry>> : Field[P];
169
+ type ManagedView<Resources, Managed, Hidden> = [Managed] extends [never] ? Resources : ManagedResources<Resources, Managed, Hidden>;
170
+ /** {@link ManagedView}'s Resources when something is managed elsewhere. */
171
+ type ManagedResources<in out Resources, in out Managed, in out Hidden> = {
172
+ readonly [R in Exclude<keyof Resources, Hidden>]: {
173
+ readonly [P in keyof Resources[R]]: P extends "fields" ? [Hidden] extends [never] ? ManagedFields<Resources[R][P], Managed, R extends Managed ? true : false> : {
174
+ readonly [F in keyof Resources[R][P] as Resources[R][P][F] extends {
175
+ readonly kind: "relation";
176
+ readonly target: Hidden;
177
+ } ? never : F]: Resources[R][P][F];
178
+ } : P extends "operations" ? R extends Managed ? ReadOperations<Resources[R][P]> : Resources[R][P] : Resources[R][P];
179
+ };
168
180
  };
169
181
  /**
170
- * A Resource's fields in the view: the model's and the ones the configuration
171
- * adds, less the ones this view's restrictions hide, each with its capability
172
- * restrictions applied.
182
+ * One Resource before exposure: the model's own, with its fields layered and
183
+ * marked where governed, and its create requirements less what the layers'
184
+ * compute stages fill.
173
185
  */
174
- type LayeredFields<ModelFields, ResourceConfig, FieldRestrictions, RootFieldRestrictions> = {
175
- readonly [F in Exclude<keyof ModelFields | AddedFieldKey<ModelFields, ResourceConfig>, HiddenKey<FieldRestrictions>>]: RestrictedField<F extends keyof ModelFields ? LayeredModelField<ModelFields[F], EntryOf<ResourceConfig, F>> : AddedField<EntryOf<ResourceConfig, F>>, EntryOf<RootFieldRestrictions, F>, EntryOf<FieldRestrictions, F>>;
186
+ type LayeredResource<in out Resource, in out ResourceConfig, in out OverlayConfig, in out Governed = never> = {
187
+ readonly [P in keyof Resource]: P extends "fields" ? GovernedFields<LayeredFields<Resource[P], EntryOf<ResourceConfig, "fields">>, Governed> : P extends "createRequirements" ? RequirementsLessComputed<Exclude<Resource[P], undefined>, ComputedOnCreateKey<EntryOf<ResourceConfig, "fields">> | ComputedOnCreateKey<EntryOf<OverlayConfig, "fields">>> : Resource[P];
188
+ };
189
+ /** The fields of a `fields` block with a `compute.create` stage. */
190
+ type ComputedOnCreateKey<FieldsBlock> = [FieldsBlock] extends [never] ? never : {
191
+ [F in keyof FieldsBlock]-?: NonNullable<FieldsBlock[F]> extends {
192
+ readonly pipelines?: infer Pipelines;
193
+ } ? NonNullable<Pipelines> extends {
194
+ readonly compute?: infer Compute;
195
+ } ? "create" extends keyof NonNullable<Compute> ? F : never : never : never;
196
+ }[keyof FieldsBlock];
197
+ /**
198
+ * A create-requirement statement less `Computed`: a required field leaves
199
+ * `required`, a group's reference field leaves its group, and a group left with
200
+ * none is satisfied and leaves `oneOf`. A member left empty is absent, as the
201
+ * compiler leaves it (`projectCreateRequirements`).
202
+ */
203
+ export type RequirementsLessComputed<Requirements, Computed> = [
204
+ Computed
205
+ ] extends [never] ? Requirements : {
206
+ readonly [P in keyof Requirements as P extends "required" | "oneOf" ? LessComputed<P, Requirements[P], Computed> extends readonly [] ? never : P : P]: P extends "required" | "oneOf" ? LessComputed<P, Requirements[P], Computed> : Requirements[P];
207
+ };
208
+ /** One member of a statement less `Computed`: its names, or its groups. */
209
+ type LessComputed<Member, List, Computed> = Member extends "required" ? NamesLessComputed<List, Computed> : GroupsLessComputed<List, Computed>;
210
+ /** A name tuple less `Computed`, still a tuple. */
211
+ type NamesLessComputed<Names, Computed> = Names extends readonly [
212
+ infer Head,
213
+ ...infer Rest
214
+ ] ? Head extends Computed ? NamesLessComputed<Rest, Computed> : readonly [Head, ...NamesLessComputed<Rest, Computed>] : readonly [];
215
+ /** A group tuple less `Computed` reference fields; a group left with none is dropped. */
216
+ type GroupsLessComputed<Groups, Computed> = Groups extends readonly [
217
+ infer Group,
218
+ ...infer Rest
219
+ ] ? Group extends readonly [infer Relation, ...infer References] ? NamesLessComputed<References, Computed> extends readonly [] ? GroupsLessComputed<Rest, Computed> : readonly [
220
+ readonly [Relation, ...NamesLessComputed<References, Computed>],
221
+ ...GroupsLessComputed<Rest, Computed>
222
+ ] : GroupsLessComputed<Rest, Computed> : readonly [];
223
+ /** The Resources before exposure: the model, with the root's definitions applied. */
224
+ type LayeredResources<Resources, Block, OverlayBlock, Governed = never> = {
225
+ readonly [R in keyof Resources]: LayeredResource<Resources[R], EntryOf<Block, R>, EntryOf<OverlayBlock, R>, GovernedNames<Governed, R>>;
176
226
  };
177
- /** The variants of one family an operations restriction turns off: literal `false` only. */
178
- type DisabledVariant<FamilyRestriction> = [FamilyRestriction] extends [never] ? never : {
179
- [V in keyof FamilyRestriction]-?: IsDenial<FamilyRestriction[V]> extends true ? V : never;
180
- }[keyof FamilyRestriction];
181
- /** The variants of the unique style, which need an identifier the layer keeps. */
182
- type UniqueVariant = "unique";
183
227
  /**
184
- * The variants of one family the layer advertises: the model's, less those turned
185
- * off, less the unique one when no identifier survives.
228
+ * The style a layer's `exposed` sets: `false` picks, `true` or absent omits, a
229
+ * widened `boolean` keeps the parent's view.
186
230
  */
187
- type AvailableVariant<Family, FamilyRestriction, UniqueLost> = Exclude<keyof Family, DisabledVariant<FamilyRestriction> | (UniqueLost extends true ? UniqueVariant : never)>;
188
- /** The families with at least one variant the layer advertises. */
189
- type AvailableFamily<Operations, OperationRestrictions, UniqueLost> = {
231
+ type ExposureStyleOf<Exposed> = [Exposed] extends [false] ? "pick" : [Exposed] extends [true] ? "omit" : unknown extends Exposed ? "omit" : "keep";
232
+ /** A layer's `exposed`, read by indexed access (see {@link RootBlock}). */
233
+ type ExposedOf<Layer> = (Layer & {
234
+ readonly exposed?: unknown;
235
+ })["exposed"];
236
+ /** A layer's `exemptions.resources` block, or `never` when it states none. */
237
+ type ExemptionsOf<Layer> = LiteralRecord<(LiteralRecord<(Layer & {
238
+ readonly exemptions?: unknown;
239
+ })["exemptions"]> & {
240
+ readonly resources?: unknown;
241
+ })["resources"]>;
242
+ /** An overlay's own configuration: `application` or `client`. */
243
+ type OverlayOf<Cfg, Layer extends AvRequestOrigin> = (Cfg & {
244
+ readonly [L in Layer]?: unknown;
245
+ })[Layer];
246
+ /** One key's raw entry in an exemptions block: `true`, a list or an object. */
247
+ type RawEntry<Block, Key> = [Block] extends [never] ? unknown : Key extends keyof Block ? NonNullable<Block[Key]> : unknown;
248
+ /** An entry that exempts its subtree whole under Omit: a literal `true`. */
249
+ type IsWhole<Entry> = [Entry] extends [true] ? true : false;
250
+ /** Whether a Pick entry exempts anything: `true`, `boolean`, a non-empty list or an object. */
251
+ type Grants<Entry> = [Entry] extends [false] ? false : [Entry] extends [boolean] ? true : [Entry] extends [readonly []] ? false : [Entry] extends [object] ? true : false;
252
+ /** The keys of a block whose entry is a literal `true`. */
253
+ type WholeKey<Block> = [Block] extends [never] ? never : {
254
+ [K in keyof Block]-?: IsWhole<NonNullable<Block[K]>> extends true ? K : never;
255
+ }[keyof Block];
256
+ /** Whether any member of an object entry grants (see {@link Grants}). */
257
+ type AnyMemberGrants<Entry, Exclude = never> = true extends {
258
+ [K in keyof Entry]-?: K extends Exclude ? false : Grants<NonNullable<Entry[K]>>;
259
+ }[keyof Entry] ? true : false;
260
+ /** Whether a Pick field entry grants a capability: an object must grant one inside. */
261
+ type FieldGrants<Entry> = [Entry] extends [readonly unknown[]] ? Grants<Entry> : [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? AnyMemberGrants<Entry, AdapterLimit> : false;
262
+ /** Whether one family's entry grants a variant. */
263
+ type FamilyGrants<Entry> = [Entry] extends [readonly unknown[]] ? Grants<Entry> : [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? AnyMemberGrants<Entry> : false;
264
+ /** Whether an operations entry grants an operation. */
265
+ type OperationsGrant<Entry> = [Entry] extends [readonly unknown[]] ? Grants<Entry> : [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? true extends {
266
+ [F in keyof Entry]-?: FamilyGrants<NonNullable<Entry[F]>>;
267
+ }[keyof Entry] ? true : false : false;
268
+ /** Whether a Pick Resource entry grants a field or an operation. */
269
+ type ResourceGrants<Entry> = [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? true extends OperationsGrant<NonNullable<OperationsEntryOf<Entry>>> | (true extends {
270
+ [F in keyof FieldsEntryOf<Entry>]-?: FieldGrants<NonNullable<FieldsEntryOf<Entry>[F]>>;
271
+ }[keyof FieldsEntryOf<Entry>] ? true : false) ? true : false : false;
272
+ /** The keys of a Pick `fields` block whose entry grants (see {@link FieldGrants}). */
273
+ type GrantedFieldKey<Block> = [Block] extends [never] ? never : {
274
+ [K in keyof Block]-?: FieldGrants<NonNullable<Block[K]>> extends true ? K : never;
275
+ }[keyof Block];
276
+ /** The keys of a Pick `resources` block whose entry grants (see {@link ResourceGrants}). */
277
+ type GrantedResourceKey<Block> = [Block] extends [never] ? never : {
278
+ [K in keyof Block]-?: ResourceGrants<NonNullable<Block[K]>> extends true ? K : never;
279
+ }[keyof Block];
280
+ /** The names a list entry lists. */
281
+ type Listed<Entry> = Entry extends readonly (infer Name)[] ? Name : never;
282
+ /** A token member's tokens, its qualifier aside. */
283
+ type MemberTokens<Member> = Member extends {
284
+ readonly scopes: unknown;
285
+ } ? {
286
+ [K in keyof Member]: K extends "scopes" ? never : Member[K] extends readonly (infer Token)[] ? Token : never;
287
+ }[keyof Member] : Member extends readonly (infer Token)[] ? Token : never;
288
+ /** A token member with its tokens replaced by `Tokens`, qualifier kept. */
289
+ type WithTokens<Member, Tokens> = Member extends {
290
+ readonly scopes: unknown;
291
+ } ? {
292
+ readonly [K in keyof Member]: K extends "scopes" ? Member[K] : readonly Tokens[];
293
+ } : readonly Tokens[];
294
+ /** One capability member under an Omit object entry: a token list removes those tokens. */
295
+ type OmittedMember<Member, Entry> = Entry extends readonly unknown[] ? WithTokens<Member, Exclude<MemberTokens<Member>, Listed<Entry>>> : Member;
296
+ /** One capability member under a Pick object entry: a token list keeps only those tokens. */
297
+ type PickedMember<Member, Entry> = Entry extends readonly unknown[] ? WithTokens<Member, Extract<MemberTokens<Member>, Listed<Entry>>> : Member;
298
+ /** The capability members no exemption names and a Pick still keeps. */
299
+ type AdapterLimit = "nestedWriteFilter" | "filterModes" | "pathFilterModes";
300
+ /** A field's capabilities under its exemption, a list of names or an object. */
301
+ type ExemptedCapabilities<Caps, Entry, Style> = Style extends "omit" ? Entry extends readonly unknown[] ? {
302
+ readonly [P in keyof Caps as P extends Listed<Entry> ? never : P]: Caps[P];
303
+ } : {
304
+ readonly [P in keyof Caps as P extends keyof Entry ? IsWhole<Entry[P]> extends true ? never : P : P]: P extends keyof Entry ? OmittedMember<Caps[P], Entry[P]> : Caps[P];
305
+ } : Entry extends readonly unknown[] ? {
306
+ readonly [P in keyof Caps as P extends Listed<Entry> | AdapterLimit ? P : never]: Caps[P];
307
+ } : {
308
+ readonly [P in keyof Caps as P extends AdapterLimit ? P : P extends keyof Entry ? Grants<Entry[P]> extends true ? P : never : never]: P extends keyof Entry ? PickedMember<Caps[P], Entry[P]> : Caps[P];
309
+ };
310
+ /** One field under its exemption: `true` (or `boolean`) keeps the parent's field. */
311
+ type ExemptedField<Field, Entry, Style> = [Entry] extends [boolean] ? Field : {
312
+ readonly [P in keyof Field]: P extends "capabilities" ? ExemptedCapabilities<Field[P], Entry, Style> : Field[P];
313
+ };
314
+ /** A Resource's fields under its exemptions' `fields` block. */
315
+ type ExemptedFields<Fields, Block, Style> = Style extends "omit" ? [Block] extends [never] ? Fields : {
316
+ readonly [F in Exclude<keyof Fields, WholeKey<Block>>]: F extends keyof Block ? ExemptedField<Fields[F], NonNullable<Block[F]>, "omit"> : Fields[F];
317
+ } : {
318
+ readonly [F in Extract<keyof Fields, GrantedFieldKey<Block>>]: ExemptedField<Fields[F], RawEntry<Block, F>, "pick">;
319
+ };
320
+ /** The fields an exemptions `fields` block leaves a Resource without. */
321
+ type RemovedField<Fields, Block, Style> = Style extends "omit" ? WholeKey<Block> : Exclude<keyof Fields, GrantedFieldKey<Block>>;
322
+ /** One family's entry in an operations entry: `true` for a listed family. */
323
+ type FamilyEntry<Operations, Family> = Operations extends readonly unknown[] ? Family extends Listed<Operations> ? true : unknown : [Operations] extends [boolean] ? Operations : Family extends keyof Operations ? NonNullable<Operations[Family]> : unknown;
324
+ /** The keys of a per-variant object entry set to a literal `true`. */
325
+ type TrueVariant<Entry> = {
326
+ [V in keyof Entry]-?: IsWhole<NonNullable<Entry[V]>> extends true ? V : never;
327
+ }[keyof Entry];
328
+ /** The variants of one family a layer keeps, by its style. */
329
+ type KeptVariant<Family, Entry, Style, UniqueLost> = Exclude<Style extends "omit" ? IsWhole<Entry> extends true ? never : Entry extends readonly unknown[] ? Exclude<keyof Family, Listed<Entry>> : [Entry] extends [boolean] ? keyof Family : Entry extends object ? Exclude<keyof Family, TrueVariant<Entry>> : keyof Family : [Entry] extends [false] ? never : [Entry] extends [boolean] ? keyof Family : Entry extends readonly unknown[] ? Extract<keyof Family, Listed<Entry>> : Entry extends object ? Extract<keyof Family, TrueVariant<Entry>> : never, UniqueLost extends true ? UniqueVariant : never>;
330
+ /** The variants of the unique style, which need an identifier the layer keeps. */
331
+ type UniqueVariant = "unique";
332
+ /** The families with at least one variant the layer keeps. */
333
+ type KeptFamily<Operations, Entry, Style, UniqueLost> = {
190
334
  [F in keyof Operations]-?: [
191
- AvailableVariant<NonNullable<Operations[F]>, EntryOf<OperationRestrictions, F>, UniqueLost>
335
+ KeptVariant<NonNullable<Operations[F]>, FamilyEntry<Entry, F>, Style, UniqueLost>
192
336
  ] extends [never] ? never : F;
193
337
  }[keyof Operations];
194
- /** A Resource's operations under its layer's restrictions. */
195
- type RestrictedOperations<Operations, OperationRestrictions, UniqueLost> = [
196
- OperationRestrictions
197
- ] extends [never] ? UniqueLost extends true ? LayerOperations<Operations, never, UniqueLost> : Operations : LayerOperations<Operations, OperationRestrictions, UniqueLost>;
198
- type LayerOperations<Operations, OperationRestrictions, UniqueLost> = {
199
- readonly [F in AvailableFamily<Operations, OperationRestrictions, UniqueLost>]: {
200
- readonly [V in AvailableVariant<NonNullable<Operations[F]>, EntryOf<OperationRestrictions, F>, UniqueLost>]: NonNullable<Operations[F]>[V];
338
+ /** A Resource's operations under its exemptions' `operations` entry. */
339
+ type ExemptedOperations<Operations, Entry, Style, UniqueLost> = Style extends "omit" ? unknown extends Entry ? UniqueLost extends true ? KeptOperations<Operations, Entry, Style, UniqueLost> : Operations : KeptOperations<Operations, Entry, Style, UniqueLost> : KeptOperations<Operations, Entry, Style, UniqueLost>;
340
+ type KeptOperations<Operations, Entry, Style, UniqueLost> = {
341
+ readonly [F in KeptFamily<Operations, Entry, Style, UniqueLost>]: {
342
+ readonly [V in KeptVariant<NonNullable<Operations[F]>, FamilyEntry<Entry, F>, Style, UniqueLost>]: NonNullable<Operations[F]>[V];
201
343
  };
202
344
  };
203
- /** A Resource's identifiers less those naming a hidden field. */
204
- type KeptIdentifiers<Identifiers, Hidden> = [Hidden] extends [never] ? Identifiers : Identifiers extends readonly (infer Identifier)[] ? readonly (Identifier extends readonly (infer Field)[] ? [Extract<Field, Hidden>] extends [never] ? Identifier : never : never)[] : Identifiers;
205
- /** Whether hiding fields left a Resource with no identifier at all. */
206
- type IdentifiersLost<Identifiers, Hidden> = [Hidden] extends [never] ? false : [
207
- KeptIdentifiers<Identifiers, Hidden> extends readonly (infer Kept)[] ? Kept : never
345
+ /** A Resource's identifiers less those naming a removed field. */
346
+ type KeptIdentifiers<Identifiers, Removed> = [Removed] extends [never] ? Identifiers : Identifiers extends readonly (infer Identifier)[] ? readonly (Identifier extends readonly (infer Field)[] ? [Extract<Field, Removed>] extends [never] ? Identifier : never : never)[] : Identifiers;
347
+ /** Whether removing fields left a Resource with no identifier at all. */
348
+ type IdentifiersLost<Identifiers, Removed> = [Removed] extends [never] ? false : [
349
+ KeptIdentifiers<Identifiers, Removed> extends readonly (infer Kept)[] ? Kept : never
208
350
  ] extends [never] ? true : false;
209
- /**
210
- * One Resource in the view: the model's own, with its fields layered and its
211
- * layer's restrictions applied to its fields, operations and identifiers.
212
- */
213
- type LayeredResource<in out Resource, in out ResourceConfig, in out ResourceRestrictions, in out RootResourceRestrictions> = {
214
- readonly [P in keyof Resource]: P extends "fields" ? LayeredFields<Resource[P], ResourceConfig, EntryOf<ResourceRestrictions, "fields">, EntryOf<RootResourceRestrictions, "fields">> : P extends "operations" ? RestrictedOperations<Resource[P], EntryOf<ResourceRestrictions, "operations">, IdentifiersLost<Resource extends {
351
+ /** A Resource's `fields` and `operations` entries, read off its exemption object. */
352
+ type FieldsEntryOf<Entry> = LiteralRecord<(Entry & {
353
+ readonly fields?: unknown;
354
+ })["fields"]>;
355
+ type OperationsEntryOf<Entry> = (Entry & {
356
+ readonly operations?: unknown;
357
+ })["operations"];
358
+ /** One Resource under an object exemption: its fields, operations and identifiers. */
359
+ type ExemptedResourceObject<in out Resource, in out FieldsBlock, in out OperationsEntry, in out Style> = {
360
+ readonly [P in keyof Resource]: P extends "fields" ? ExemptedFields<Resource[P], FieldsBlock, Style> : P extends "operations" ? ExemptedOperations<Resource[P], OperationsEntry, Style, IdentifiersLost<Resource extends {
215
361
  readonly identifiers: infer Ids;
216
- } ? Ids : never, HiddenKey<EntryOf<ResourceRestrictions, "fields">>>> : P extends "identifiers" ? KeptIdentifiers<Resource[P], HiddenKey<EntryOf<ResourceRestrictions, "fields">>> : Resource[P];
362
+ } ? Ids : never, RemovedField<Resource extends {
363
+ readonly fields: infer Fields;
364
+ } ? Fields : never, FieldsBlock, Style>>> : P extends "identifiers" ? KeptIdentifiers<Resource[P], RemovedField<Resource extends {
365
+ readonly fields: infer Fields;
366
+ } ? Fields : never, FieldsBlock, Style>> : Resource[P];
217
367
  };
368
+ /** One Resource under its exemption: `true` (or `boolean`) keeps the parent's. */
369
+ type ExemptedResource<Resource, Entry, Style> = [Entry] extends [boolean] ? Resource : ExemptedResourceObject<Resource, FieldsEntryOf<Entry>, OperationsEntryOf<Entry>, Style>;
370
+ /** A layer's Resources: its parent's, with its exemptions applied in its style. */
371
+ type ExposedResources<Resources, Style, Block> = Style extends "omit" ? [Block] extends [never] ? Resources : {
372
+ readonly [R in Exclude<keyof Resources, WholeKey<Block>>]: R extends keyof Block ? ExemptedResource<Resources[R], NonNullable<Block[R]>, "omit"> : Resources[R];
373
+ } : Style extends "pick" ? {
374
+ readonly [R in Extract<keyof Resources, GrantedResourceKey<Block>>]: ExemptedResource<Resources[R], RawEntry<Block, R>, "pick">;
375
+ } : Resources;
376
+ /** The Resources of the root's final view: what every overlay starts from. */
377
+ export type RootViewResources<M extends AvAdapterModel, Cfg> = ManagedView<ExposedResources<LayeredResources<M["resources"], ResourcesBlock<Cfg>, never>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>>, ManagedBlock<RootBlock<Cfg, "resources">>, never>;
378
+ /** The Resources of an overlay's final view: the root's view, narrowed by it. */
379
+ export type OverlayViewResources<M extends AvAdapterModel, Cfg, Layer extends "application" | "client"> = ExposedResources<ManagedView<ExposedResources<LayeredResources<M["resources"], ResourcesBlock<Cfg>, OverlayResourcesBlock<Cfg, Layer>>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>>, ManagedBlock<RootBlock<Cfg, "resources">>, Layer extends "client" ? ManagedBlock<RootBlock<Cfg, "resources">> : never>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, Layer>>>, ExemptionsOf<OverlayOf<Cfg, Layer>>>;
218
380
  /**
219
- * The Resources in the view. `Restrictions` is the layer's layered
220
- * `restrictions` block and `RootRestrictions` root's own, whose narrowings a
221
- * restoration inherits; both `never` for a configuration that restricts nothing.
381
+ * One derived Contract's type: the model, with the root's `fields` entries
382
+ * applied, then the root's exposure, then the overlay's over the root's view.
383
+ * `framework.application`, `client`, `appTx` and `clientTx` are typed over it,
384
+ * and a declaration file names it when it writes one of their nodes.
222
385
  */
223
- type LayeredResources<Resources, Block, Restrictions, RootRestrictions> = {
224
- readonly [R in Exclude<keyof Resources, HiddenKey<Restrictions>>]: LayeredResource<Resources[R], EntryOf<Block, R>, EntryOf<Restrictions, R>, EntryOf<RootRestrictions, R>>;
386
+ export type AvContractView<M extends AvAdapterModel, RootFields, RootStyle, RootExemptions, OverlayStyle, OverlayExemptions, OverlayFields, Governed = never> = {
387
+ readonly scalars: M["scalars"];
388
+ readonly enums: M["enums"];
389
+ readonly resources: ExposedResources<ExposedResources<LayeredResources<M["resources"], RootFields, OverlayFields, Governed>, RootStyle, RootExemptions>, OverlayStyle, OverlayExemptions>;
390
+ readonly limits: AvContractLimits;
391
+ readonly transactions: M["transactions"];
225
392
  };
226
393
  /**
227
- * One derived Contract's type: the model, with a layer's `fields` block applied
228
- * and its layered `restrictions` block (`Restrictions`, over root's own,
229
- * `RootRestrictions`) applied.
394
+ * {@link AvContractView} for a configuration that marks Resources managed
395
+ * elsewhere (`Managed`): their writes, and the writes of relations into them,
396
+ * withheld after the root's exposure; under `Hidden` (the client's view) they
397
+ * and every relation into them left out.
230
398
  */
231
- type DerivedContractView<M extends AdapterModel, FieldsBlock, Restrictions, RootRestrictions> = {
399
+ export type AvManagedContractView<M extends AvAdapterModel, RootFields, RootStyle, RootExemptions, OverlayStyle, OverlayExemptions, OverlayFields, Governed, in out Managed, in out Hidden> = {
232
400
  readonly scalars: M["scalars"];
233
401
  readonly enums: M["enums"];
234
- readonly resources: LayeredResources<M["resources"], FieldsBlock, Restrictions, RootRestrictions>;
235
- readonly limits: ContractLimits;
402
+ readonly resources: ExposedResources<ManagedView<ExposedResources<LayeredResources<M["resources"], RootFields, OverlayFields, Governed>, RootStyle, RootExemptions>, Managed, Hidden>, OverlayStyle, OverlayExemptions>;
403
+ readonly limits: AvContractLimits;
236
404
  readonly transactions: M["transactions"];
237
405
  };
238
406
  /**
239
407
  * The Application Contract's type, derived from the adapter model and the
240
408
  * configuration.
241
409
  */
242
- export type ApplicationContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "application", "fields">, LayerBlock<Cfg, "application", "restrictions">, RootBlock<Cfg, "restrictions">> : never;
410
+ export type AvContractApplicationView<M extends AvAdapterModel, Cfg = AvConfigAny> = [Cfg] extends [unknown] ? [ManagedBlock<RootBlock<Cfg, "resources">>] extends [never] ? AvContractView<M, ViewBlock<ResourcesBlock<Cfg>>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, "application">>>, ExemptionsOf<OverlayOf<Cfg, "application">>, ViewBlock<OverlayResourcesBlock<Cfg, "application">>, GovernedBlock<Cfg>> : AvManagedContractView<M, ViewBlock<ResourcesBlock<Cfg>>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, "application">>>, ExemptionsOf<OverlayOf<Cfg, "application">>, ViewBlock<OverlayResourcesBlock<Cfg, "application">>, GovernedBlock<Cfg>, ManagedBlock<RootBlock<Cfg, "resources">>, never> : never;
243
411
  /**
244
412
  * The Client Contract's type, derived from the adapter model and the
245
413
  * configuration: what the client layer hides is absent. It types
246
414
  * `framework.client` and `framework.clientTx`.
247
415
  */
248
- export type ClientContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "client", "fields">, LayerBlock<Cfg, "client", "restrictions">, RootBlock<Cfg, "restrictions">> : never;
416
+ export type ClientContractView<M extends AvAdapterModel, Cfg = AvConfigAny> = [
417
+ Cfg
418
+ ] extends [unknown] ? [ManagedBlock<RootBlock<Cfg, "resources">>] extends [never] ? AvContractView<M, ViewBlock<ResourcesBlock<Cfg>>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, "client">>>, ExemptionsOf<OverlayOf<Cfg, "client">>, ViewBlock<OverlayResourcesBlock<Cfg, "client">>, GovernedBlock<Cfg>> : AvManagedContractView<M, ViewBlock<ResourcesBlock<Cfg>>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, "client">>>, ExemptionsOf<OverlayOf<Cfg, "client">>, ViewBlock<OverlayResourcesBlock<Cfg, "client">>, GovernedBlock<Cfg>, ManagedBlock<RootBlock<Cfg, "resources">>, ManagedBlock<RootBlock<Cfg, "resources">>> : never;
249
419
  export {};
@@ -1,16 +1,26 @@
1
- import type { AdapterDiscoveryDiagnostic } from "../adapters/adapter-discovery-diagnostic.js";
2
- import type { ContractCompilerDiagnostic } from "../compiler/contract-compiler-diagnostic.js";
3
- import type { ConfigDiagnostic } from "../config/config-diagnostic.js";
1
+ import type { AvAdapterDiscoveryDiagnostic } from "../adapters/adapter-discovery-diagnostic.js";
2
+ import type { AvContractCompilerDiagnostic } from "../compiler/contract-compiler-diagnostic.js";
3
+ import type { AvConfigDiagnostic } from "../config/config-diagnostic.js";
4
4
  /** The construction step that failed. */
5
- export type FrameworkConstructionStage = "configuration" | "discovery" | "contract-compilation";
6
- /** One problem reported by {@link FrameworkConstructionError}. */
7
- export type FrameworkConstructionDiagnostic = ConfigDiagnostic | AdapterDiscoveryDiagnostic | ContractCompilerDiagnostic;
5
+ export type AvConstructionStage = "configuration" | "discovery" | "contract-compilation";
6
+ /** One problem found while constructing, before its documentation link is added. */
7
+ type ConstructionProblem = AvConfigDiagnostic | AvAdapterDiscoveryDiagnostic | AvContractCompilerDiagnostic;
8
+ /**
9
+ * One problem reported by {@link AvConstructionError}: its `code`, `path` and
10
+ * `message`, and `docs`, the URL of the code's entry on the error-codes page
11
+ * (the same as `AvErrorCatalog[code].docs`).
12
+ */
13
+ export type AvConstructionDiagnostic = ConstructionProblem & {
14
+ readonly docs: string;
15
+ };
8
16
  /**
9
17
  * Thrown by {@link createFramework} when construction fails: `stage` says
10
- * where, and `diagnostics` lists every problem found there.
18
+ * where, and `diagnostics` lists every problem found there. The message names
19
+ * the first of them and how many more there are.
11
20
  */
12
- export declare class FrameworkConstructionError extends Error {
13
- readonly stage: FrameworkConstructionStage;
14
- readonly diagnostics: readonly FrameworkConstructionDiagnostic[];
15
- constructor(stage: FrameworkConstructionStage, diagnostics: readonly FrameworkConstructionDiagnostic[]);
21
+ export declare class AvConstructionError extends Error {
22
+ readonly stage: AvConstructionStage;
23
+ readonly diagnostics: readonly AvConstructionDiagnostic[];
24
+ constructor(stage: AvConstructionStage, diagnostics: readonly ConstructionProblem[]);
16
25
  }
26
+ export {};
@@ -1,15 +1,31 @@
1
+ import { brandCoreClass } from "../runtime/core-class.brand.js";
2
+ import { errorDocsUrl } from "../runtime/error.catalog.js";
1
3
  const FRAMEWORK_CONSTRUCTION_MESSAGES = {
2
4
  configuration: "Aventara framework configuration validation failed",
3
5
  discovery: "Aventara adapter discovery validation failed",
4
6
  "contract-compilation": "Aventara contract compilation failed",
5
7
  };
6
- export class FrameworkConstructionError extends Error {
8
+ function constructionMessage(stage, diagnostics) {
9
+ const base = FRAMEWORK_CONSTRUCTION_MESSAGES[stage];
10
+ const [first] = diagnostics;
11
+ if (first === undefined) {
12
+ return base;
13
+ }
14
+ const where = first.path === "" ? "" : ` at ${first.path}`;
15
+ const more = diagnostics.length > 1 ? ` (+${diagnostics.length - 1} more)` : "";
16
+ return `${base}: ${first.code}${where}: ${first.message}${more}`;
17
+ }
18
+ export class AvConstructionError extends Error {
7
19
  stage;
8
20
  diagnostics;
9
21
  constructor(stage, diagnostics) {
10
- super(FRAMEWORK_CONSTRUCTION_MESSAGES[stage]);
11
- this.name = "FrameworkConstructionError";
22
+ super(constructionMessage(stage, diagnostics));
23
+ this.name = "AvConstructionError";
12
24
  this.stage = stage;
13
- this.diagnostics = [...diagnostics];
25
+ this.diagnostics = diagnostics.map((diagnostic) => ({
26
+ ...diagnostic,
27
+ docs: errorDocsUrl(diagnostic.code),
28
+ }));
14
29
  }
15
30
  }
31
+ brandCoreClass(AvConstructionError, "AvConstructionError");