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

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 (242) hide show
  1. package/CHANGELOG.md +1140 -0
  2. package/README.md +224 -57
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +9 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -29
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/{json → avz}/avz.js +150 -8
  19. package/dist/{json → avz}/index.d.ts +2 -1
  20. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  21. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  22. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  23. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  24. package/dist/compiler/contract.compiler.d.ts +18 -18
  25. package/dist/compiler/contract.compiler.js +548 -441
  26. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  27. package/dist/compiler/create-requirements.projector.js +423 -0
  28. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  29. package/dist/compiler/field-validator.compiler.js +238 -0
  30. package/dist/config/any-framework-config.d.ts +19 -12
  31. package/dist/config/config-diagnostic.d.ts +11 -4
  32. package/dist/config/config-layer.d.ts +15 -6
  33. package/dist/config/config.resolver.d.ts +74 -31
  34. package/dist/config/config.resolver.js +108 -44
  35. package/dist/config/config.validator.d.ts +7 -7
  36. package/dist/config/config.validator.js +581 -72
  37. package/dist/config/define-resource.d.ts +57 -0
  38. package/dist/config/define-resource.js +14 -0
  39. package/dist/config/effective-fields.d.ts +19 -23
  40. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  41. package/dist/config/exact-framework-config.d.ts +280 -0
  42. package/dist/config/field-compute.resolver.d.ts +19 -0
  43. package/dist/config/field-compute.resolver.js +115 -0
  44. package/dist/config/field-pipeline-config.d.ts +47 -0
  45. package/dist/config/forced-operation.validator.d.ts +10 -0
  46. package/dist/config/forced-operation.validator.js +66 -0
  47. package/dist/config/framework-config.d.ts +110 -39
  48. package/dist/config/framework-exemptions-config.d.ts +91 -0
  49. package/dist/config/framework-exemptions-config.js +1 -0
  50. package/dist/config/framework-field-definition.d.ts +78 -0
  51. package/dist/config/framework-field-definition.js +28 -0
  52. package/dist/config/framework-resources-config.d.ts +116 -0
  53. package/dist/config/framework-resources-config.js +1 -0
  54. package/dist/config/pipeline-config.d.ts +56 -20
  55. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  56. package/dist/config/pipeline-tree.resolver.js +220 -0
  57. package/dist/config/stage-type.eraser.d.ts +65 -0
  58. package/dist/config/stage-type.eraser.js +1 -0
  59. package/dist/contracts/capability.d.ts +11 -11
  60. package/dist/contracts/client-contract-structure.validator.d.ts +323 -28
  61. package/dist/contracts/client-contract-structure.validator.js +152 -8
  62. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  63. package/dist/contracts/contract-canonicalizer.js +141 -28
  64. package/dist/contracts/contract-hash.d.ts +12 -7
  65. package/dist/contracts/contract-hash.js +3 -2
  66. package/dist/contracts/contract-limits.d.ts +4 -1
  67. package/dist/contracts/contract-limits.js +1 -0
  68. package/dist/contracts/contract-lookup.d.ts +5 -5
  69. package/dist/contracts/contract-protocol.d.ts +4 -4
  70. package/dist/contracts/contract.d.ts +24 -16
  71. package/dist/contracts/create-requirements.d.ts +35 -0
  72. package/dist/contracts/create-requirements.js +1 -0
  73. package/dist/contracts/enum-definition.d.ts +1 -1
  74. package/dist/contracts/field-check.d.ts +101 -0
  75. package/dist/contracts/field-check.js +1 -0
  76. package/dist/contracts/field.d.ts +52 -42
  77. package/dist/contracts/identifier.d.ts +4 -4
  78. package/dist/contracts/json-shape.d.ts +12 -1
  79. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  80. package/dist/contracts/resource-operations.d.ts +28 -28
  81. package/dist/contracts/resource.d.ts +15 -9
  82. package/dist/contracts/scalar-value-type.d.ts +15 -15
  83. package/dist/contracts/scalar.d.ts +3 -3
  84. package/dist/contracts/transaction-capability.d.ts +1 -1
  85. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  86. package/dist/framework/contract-view.d.ts +213 -147
  87. package/dist/framework/framework-construction.error.d.ts +10 -10
  88. package/dist/framework/framework-construction.error.js +2 -2
  89. package/dist/framework/framework.d.ts +47 -23
  90. package/dist/framework/framework.factory.d.ts +8 -6
  91. package/dist/framework/framework.factory.js +40 -20
  92. package/dist/framework/operation-facade.d.ts +123 -52
  93. package/dist/framework/operation-facade.js +9 -1
  94. package/dist/index.d.ts +55 -50
  95. package/dist/index.js +6 -6
  96. package/dist/internal.d.ts +15 -10
  97. package/dist/internal.js +3 -1
  98. package/dist/operations/operation-arguments.d.ts +267 -202
  99. package/dist/operations/operation-call.d.ts +27 -28
  100. package/dist/operations/operation-identity.d.ts +10 -10
  101. package/dist/operations/operation-result.d.ts +21 -21
  102. package/dist/operations/operation-validator-core.d.ts +6 -6
  103. package/dist/operations/operation-validator-core.js +13 -2
  104. package/dist/operations/operation-validator.d.ts +9 -9
  105. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  106. package/dist/operations/structural-limits.walker.d.ts +6 -6
  107. package/dist/operations/structural-limits.walker.js +145 -0
  108. package/dist/operations/validation-code.d.ts +11 -6
  109. package/dist/operations/validation-code.js +4 -0
  110. package/dist/operations/write-scope.resolver.d.ts +6 -6
  111. package/dist/protocol/absent-route.responder.d.ts +13 -12
  112. package/dist/protocol/absent-route.responder.js +19 -19
  113. package/dist/protocol/contract-document.responder.d.ts +3 -3
  114. package/dist/protocol/contract-document.responder.js +2 -2
  115. package/dist/protocol/http-request.decoder.d.ts +17 -13
  116. package/dist/protocol/http-request.decoder.js +10 -10
  117. package/dist/protocol/http-request.reader.d.ts +3 -3
  118. package/dist/protocol/http-response.encoder.d.ts +4 -4
  119. package/dist/protocol/http-response.encoder.js +94 -55
  120. package/dist/protocol/http-status.table.d.ts +2 -2
  121. package/dist/protocol/operation-response.guard.d.ts +2 -2
  122. package/dist/protocol/protocol-surface.d.ts +4 -4
  123. package/dist/protocol/protocol.binder.d.ts +50 -27
  124. package/dist/protocol/protocol.binder.js +12 -9
  125. package/dist/protocol/protocol.handler.d.ts +22 -13
  126. package/dist/protocol/protocol.handler.js +44 -9
  127. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  128. package/dist/protocol/unmounted-route.error.js +2 -2
  129. package/dist/runtime/caller-data.copier.d.ts +5 -5
  130. package/dist/runtime/caller-data.copier.js +13 -13
  131. package/dist/runtime/caller-data.door.d.ts +6 -6
  132. package/dist/runtime/caller-data.door.js +6 -4
  133. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  134. package/dist/runtime/computed-read-runtime.js +61 -48
  135. package/dist/runtime/computed-value.error.d.ts +6 -6
  136. package/dist/runtime/computed-value.error.js +3 -3
  137. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  138. package/dist/runtime/context-executor.runtime.js +275 -0
  139. package/dist/runtime/create-requirement.d.ts +10 -81
  140. package/dist/runtime/create-requirement.js +80 -57
  141. package/dist/runtime/decimal.d.ts +2 -2
  142. package/dist/runtime/decimal.js +1 -1
  143. package/dist/runtime/diagnostics-reporter.d.ts +53 -27
  144. package/dist/runtime/diagnostics-reporter.js +24 -0
  145. package/dist/runtime/error-boundary.d.ts +65 -8
  146. package/dist/runtime/error-boundary.js +45 -19
  147. package/dist/runtime/execution-options.d.ts +10 -2
  148. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  149. package/dist/runtime/field-check.evaluator.js +521 -0
  150. package/dist/runtime/field-compute.d.ts +64 -0
  151. package/dist/runtime/field-compute.js +1 -0
  152. package/dist/runtime/field-stage.plan.d.ts +15 -0
  153. package/dist/runtime/field-stage.plan.js +27 -0
  154. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  155. package/dist/runtime/field-stage.runtime.js +143 -0
  156. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  157. package/dist/runtime/field-validator.runtime.js +87 -0
  158. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  159. package/dist/runtime/framework-error-class.table.js +25 -0
  160. package/dist/runtime/framework-error.d.ts +68 -8
  161. package/dist/runtime/framework-error.factory.d.ts +4 -0
  162. package/dist/runtime/framework-error.factory.js +15 -0
  163. package/dist/runtime/framework-error.js +23 -2
  164. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  165. package/dist/runtime/interceptor-next.error.js +6 -0
  166. package/dist/runtime/json-value.d.ts +3 -3
  167. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  168. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  169. package/dist/runtime/misuse-reporter.d.ts +12 -12
  170. package/dist/runtime/mutation-planner.d.ts +19 -10
  171. package/dist/runtime/mutation-planner.js +54 -30
  172. package/dist/runtime/nested-write.walker.d.ts +32 -0
  173. package/dist/runtime/nested-write.walker.js +73 -0
  174. package/dist/runtime/operation-request.d.ts +33 -6
  175. package/dist/runtime/operation-response.d.ts +17 -17
  176. package/dist/runtime/operation-runtime.d.ts +113 -25
  177. package/dist/runtime/operation-runtime.js +395 -74
  178. package/dist/runtime/outcome-mapper.d.ts +16 -5
  179. package/dist/runtime/outcome-mapper.js +23 -6
  180. package/dist/runtime/output-validator.d.ts +10 -10
  181. package/dist/runtime/output-validator.js +3 -3
  182. package/dist/runtime/owned-execution.registry.d.ts +6 -6
  183. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  184. package/dist/runtime/pipe-output.validator.js +12 -12
  185. package/dist/runtime/pipeline.d.ts +196 -34
  186. package/dist/runtime/readonly-value.d.ts +32 -0
  187. package/dist/runtime/readonly-value.js +141 -0
  188. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  189. package/dist/runtime/request-envelope.validator.js +12 -7
  190. package/dist/runtime/request-id.d.ts +1 -1
  191. package/dist/runtime/request-state.d.ts +14 -0
  192. package/dist/runtime/request-state.js +1 -0
  193. package/dist/runtime/request-state.resolver.d.ts +12 -0
  194. package/dist/runtime/request-state.resolver.js +20 -0
  195. package/dist/runtime/scalar-runtime.d.ts +31 -16
  196. package/dist/runtime/scalar-runtime.js +16 -18
  197. package/dist/transactions/deferred-operation.d.ts +35 -20
  198. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  199. package/dist/transactions/operation-arguments-encoder.js +2 -2
  200. package/dist/transactions/sql-statement.d.ts +77 -0
  201. package/dist/transactions/sql-statement.js +47 -0
  202. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  203. package/dist/transactions/sql-statement.validator.js +134 -0
  204. package/dist/transactions/transaction-envelope.d.ts +4 -4
  205. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  206. package/dist/transactions/transaction-integrity-error.js +5 -2
  207. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  208. package/dist/transactions/transaction-plan-assembler.js +148 -34
  209. package/dist/transactions/transaction-plan-validator.d.ts +29 -20
  210. package/dist/transactions/transaction-plan-validator.js +70 -38
  211. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  212. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  213. package/dist/transactions/transaction-reference-resolver.js +26 -14
  214. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  215. package/dist/transactions/transaction-reference-validator.js +58 -26
  216. package/dist/transactions/transaction-reference.d.ts +13 -13
  217. package/dist/transactions/transaction-request.d.ts +18 -5
  218. package/dist/transactions/transaction-response.d.ts +6 -6
  219. package/dist/transactions/transaction-runtime.d.ts +8 -7
  220. package/dist/transactions/transaction-runtime.js +166 -50
  221. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  222. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  223. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  224. package/dist/transactions/transaction-slot-path-error.js +2 -2
  225. package/dist/transactions/transaction-slot-writer.js +2 -2
  226. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  227. package/dist/transactions/transaction-stage.runtime.js +123 -0
  228. package/package.json +6 -5
  229. package/src/runtime/field-check.evaluator.ts +720 -0
  230. package/dist/config/define-fields.d.ts +0 -42
  231. package/dist/config/define-fields.js +0 -3
  232. package/dist/config/framework-behaviors-config.d.ts +0 -30
  233. package/dist/config/framework-fields-config.d.ts +0 -42
  234. package/dist/config/framework-restrictions-config.d.ts +0 -142
  235. package/dist/json/avz.d.ts +0 -96
  236. package/dist/runtime/field-behavior.d.ts +0 -48
  237. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  238. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  239. /package/dist/{json → avz}/index.js +0 -0
  240. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  241. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  242. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,48 +1,27 @@
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
+ /** An overlay's `resources` block, its stages erased (see {@link ResourcesBlock}). */
21
+ type OverlayResourcesBlock<Cfg, Layer extends AvRequestOrigin> = ErasedResources<LiteralRecord<(LiteralRecord<OverlayOf<Cfg, Layer>> & {
22
+ readonly resources?: unknown;
23
+ })["resources"]>>;
24
+ /** One key's entry in a block, or `never` when the block has none. */
46
25
  type EntryOf<Block, Key> = [Block] extends [never] ? never : Key extends keyof Block ? LiteralRecord<NonNullable<Block[Key]>> : never;
47
26
  type ConfiguredCapabilities<FieldConfig> = [FieldConfig] extends [never] ? Record<never, never> : FieldConfig extends {
48
27
  readonly capabilities: infer Capabilities;
@@ -102,148 +81,235 @@ type AddedField<FieldConfig> = {
102
81
  type AddedFieldKey<ModelFields, ResourceConfig> = [ResourceConfig] extends [
103
82
  never
104
83
  ] ? never : Exclude<Extract<keyof ResourceConfig, string>, keyof ModelFields>;
84
+ /** A field entry's `definition`, or `never` when it states none. */
85
+ type DefinitionOf<FieldEntry> = EntryOf<FieldEntry, "definition">;
105
86
  /**
106
- * Whether a restriction entry hides what it names: only a literal `hidden: true`
107
- * does; `false` restores it.
87
+ * A Resource's fields before exposure: the model's and the ones the root's
88
+ * definitions add, each with its definition applied.
108
89
  */
109
- type IsHidden<Restriction> = [Restriction] extends [never] ? false : Restriction extends {
110
- readonly hidden: true;
111
- } ? true : false;
90
+ type LayeredFields<ModelFields, ResourceConfig> = {
91
+ readonly [F in keyof ModelFields | AddedFieldKey<ModelFields, ResourceConfig>]: F extends keyof ModelFields ? LayeredModelField<ModelFields[F], DefinitionOf<EntryOf<ResourceConfig, F>>> : AddedField<DefinitionOf<EntryOf<ResourceConfig, F>>>;
92
+ };
112
93
  /**
113
- * The keys a restrictions block hides, or `never` for a view that reads no
114
- * restrictions.
94
+ * One Resource before exposure: the model's own, with its fields layered and
95
+ * its create requirements less what the layers' compute stages fill.
115
96
  */
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];
97
+ type LayeredResource<in out Resource, in out ResourceConfig, in out OverlayConfig> = {
98
+ readonly [P in keyof Resource]: P extends "fields" ? LayeredFields<Resource[P], EntryOf<ResourceConfig, "fields">> : P extends "createRequirements" ? RequirementsLessComputed<Exclude<Resource[P], undefined>, ComputedOnCreateKey<EntryOf<ResourceConfig, "fields">> | ComputedOnCreateKey<EntryOf<OverlayConfig, "fields">>> : Resource[P];
99
+ };
100
+ /** The fields of a `fields` block with a `compute.create` stage. */
101
+ type ComputedOnCreateKey<FieldsBlock> = [FieldsBlock] extends [never] ? never : {
102
+ [F in keyof FieldsBlock]-?: NonNullable<FieldsBlock[F]> extends {
103
+ readonly pipelines?: infer Pipelines;
104
+ } ? NonNullable<Pipelines> extends {
105
+ readonly compute?: infer Compute;
106
+ } ? "create" extends keyof NonNullable<Compute> ? F : never : never : never;
107
+ }[keyof FieldsBlock];
108
+ /**
109
+ * A create-requirement statement less `Computed`: a required field leaves
110
+ * `required`, a group's reference field leaves its group, and a group left with
111
+ * none is satisfied and leaves `oneOf`. A member left empty is absent, as the
112
+ * compiler leaves it (`projectCreateRequirements`).
113
+ */
114
+ type RequirementsLessComputed<Requirements, Computed> = [Computed] extends [
115
+ never
116
+ ] ? Requirements : {
117
+ 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];
160
118
  };
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];
119
+ /** One member of a statement less `Computed`: its names, or its groups. */
120
+ type LessComputed<Member, List, Computed> = Member extends "required" ? NamesLessComputed<List, Computed> : GroupsLessComputed<List, Computed>;
121
+ /** A name tuple less `Computed`, still a tuple. */
122
+ type NamesLessComputed<Names, Computed> = Names extends readonly [
123
+ infer Head,
124
+ ...infer Rest
125
+ ] ? Head extends Computed ? NamesLessComputed<Rest, Computed> : readonly [Head, ...NamesLessComputed<Rest, Computed>] : readonly [];
126
+ /** A group tuple less `Computed` reference fields; a group left with none is dropped. */
127
+ type GroupsLessComputed<Groups, Computed> = Groups extends readonly [
128
+ infer Group,
129
+ ...infer Rest
130
+ ] ? Group extends readonly [infer Relation, ...infer References] ? NamesLessComputed<References, Computed> extends readonly [] ? GroupsLessComputed<Rest, Computed> : readonly [
131
+ readonly [Relation, ...NamesLessComputed<References, Computed>],
132
+ ...GroupsLessComputed<Rest, Computed>
133
+ ] : GroupsLessComputed<Rest, Computed> : readonly [];
134
+ /** The Resources before exposure: the model, with the root's definitions applied. */
135
+ type LayeredResources<Resources, Block, OverlayBlock> = {
136
+ readonly [R in keyof Resources]: LayeredResource<Resources[R], EntryOf<Block, R>, EntryOf<OverlayBlock, R>>;
168
137
  };
169
138
  /**
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.
139
+ * The style a layer's `exposed` sets: `false` picks, `true` or absent omits, a
140
+ * widened `boolean` keeps the parent's view.
173
141
  */
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>>;
142
+ type ExposureStyleOf<Exposed> = [Exposed] extends [false] ? "pick" : [Exposed] extends [true] ? "omit" : unknown extends Exposed ? "omit" : "keep";
143
+ /** A layer's `exposed`, read by indexed access (see {@link RootBlock}). */
144
+ type ExposedOf<Layer> = (Layer & {
145
+ readonly exposed?: unknown;
146
+ })["exposed"];
147
+ /** A layer's `exemptions.resources` block, or `never` when it states none. */
148
+ type ExemptionsOf<Layer> = LiteralRecord<(LiteralRecord<(Layer & {
149
+ readonly exemptions?: unknown;
150
+ })["exemptions"]> & {
151
+ readonly resources?: unknown;
152
+ })["resources"]>;
153
+ /** An overlay's own configuration: `application` or `client`. */
154
+ type OverlayOf<Cfg, Layer extends AvRequestOrigin> = (Cfg & {
155
+ readonly [L in Layer]?: unknown;
156
+ })[Layer];
157
+ /** One key's raw entry in an exemptions block: `true`, a list or an object. */
158
+ type RawEntry<Block, Key> = [Block] extends [never] ? unknown : Key extends keyof Block ? NonNullable<Block[Key]> : unknown;
159
+ /** An entry that exempts its subtree whole under Omit: a literal `true`. */
160
+ type IsWhole<Entry> = [Entry] extends [true] ? true : false;
161
+ /** Whether a Pick entry exempts anything: `true`, `boolean`, a non-empty list or an object. */
162
+ type Grants<Entry> = [Entry] extends [false] ? false : [Entry] extends [boolean] ? true : [Entry] extends [readonly []] ? false : [Entry] extends [object] ? true : false;
163
+ /** The keys of a block whose entry is a literal `true`. */
164
+ type WholeKey<Block> = [Block] extends [never] ? never : {
165
+ [K in keyof Block]-?: IsWhole<NonNullable<Block[K]>> extends true ? K : never;
166
+ }[keyof Block];
167
+ /** Whether any member of an object entry grants (see {@link Grants}). */
168
+ type AnyMemberGrants<Entry, Exclude = never> = true extends {
169
+ [K in keyof Entry]-?: K extends Exclude ? false : Grants<NonNullable<Entry[K]>>;
170
+ }[keyof Entry] ? true : false;
171
+ /** Whether a Pick field entry grants a capability: an object must grant one inside. */
172
+ type FieldGrants<Entry> = [Entry] extends [readonly unknown[]] ? Grants<Entry> : [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? AnyMemberGrants<Entry, AdapterLimit> : false;
173
+ /** Whether one family's entry grants a variant. */
174
+ type FamilyGrants<Entry> = [Entry] extends [readonly unknown[]] ? Grants<Entry> : [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? AnyMemberGrants<Entry> : false;
175
+ /** Whether an operations entry grants an operation. */
176
+ type OperationsGrant<Entry> = [Entry] extends [readonly unknown[]] ? Grants<Entry> : [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? true extends {
177
+ [F in keyof Entry]-?: FamilyGrants<NonNullable<Entry[F]>>;
178
+ }[keyof Entry] ? true : false : false;
179
+ /** Whether a Pick Resource entry grants a field or an operation. */
180
+ type ResourceGrants<Entry> = [Entry] extends [boolean] ? Grants<Entry> : [Entry] extends [object] ? true extends OperationsGrant<NonNullable<OperationsEntryOf<Entry>>> | (true extends {
181
+ [F in keyof FieldsEntryOf<Entry>]-?: FieldGrants<NonNullable<FieldsEntryOf<Entry>[F]>>;
182
+ }[keyof FieldsEntryOf<Entry>] ? true : false) ? true : false : false;
183
+ /** The keys of a Pick `fields` block whose entry grants (see {@link FieldGrants}). */
184
+ type GrantedFieldKey<Block> = [Block] extends [never] ? never : {
185
+ [K in keyof Block]-?: FieldGrants<NonNullable<Block[K]>> extends true ? K : never;
186
+ }[keyof Block];
187
+ /** The keys of a Pick `resources` block whose entry grants (see {@link ResourceGrants}). */
188
+ type GrantedResourceKey<Block> = [Block] extends [never] ? never : {
189
+ [K in keyof Block]-?: ResourceGrants<NonNullable<Block[K]>> extends true ? K : never;
190
+ }[keyof Block];
191
+ /** The names a list entry lists. */
192
+ type Listed<Entry> = Entry extends readonly (infer Name)[] ? Name : never;
193
+ /** A token member's tokens, its qualifier aside. */
194
+ type MemberTokens<Member> = Member extends {
195
+ readonly scopes: unknown;
196
+ } ? {
197
+ [K in keyof Member]: K extends "scopes" ? never : Member[K] extends readonly (infer Token)[] ? Token : never;
198
+ }[keyof Member] : Member extends readonly (infer Token)[] ? Token : never;
199
+ /** A token member with its tokens replaced by `Tokens`, qualifier kept. */
200
+ type WithTokens<Member, Tokens> = Member extends {
201
+ readonly scopes: unknown;
202
+ } ? {
203
+ readonly [K in keyof Member]: K extends "scopes" ? Member[K] : readonly Tokens[];
204
+ } : readonly Tokens[];
205
+ /** One capability member under an Omit object entry: a token list removes those tokens. */
206
+ type OmittedMember<Member, Entry> = Entry extends readonly unknown[] ? WithTokens<Member, Exclude<MemberTokens<Member>, Listed<Entry>>> : Member;
207
+ /** One capability member under a Pick object entry: a token list keeps only those tokens. */
208
+ type PickedMember<Member, Entry> = Entry extends readonly unknown[] ? WithTokens<Member, Extract<MemberTokens<Member>, Listed<Entry>>> : Member;
209
+ /** The capability members no exemption names and a Pick still keeps. */
210
+ type AdapterLimit = "nestedWriteFilter";
211
+ /** A field's capabilities under its exemption, a list of names or an object. */
212
+ type ExemptedCapabilities<Caps, Entry, Style> = Style extends "omit" ? Entry extends readonly unknown[] ? {
213
+ readonly [P in keyof Caps as P extends Listed<Entry> ? never : P]: Caps[P];
214
+ } : {
215
+ 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];
216
+ } : Entry extends readonly unknown[] ? {
217
+ readonly [P in keyof Caps as P extends Listed<Entry> | AdapterLimit ? P : never]: Caps[P];
218
+ } : {
219
+ 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];
220
+ };
221
+ /** One field under its exemption: `true` (or `boolean`) keeps the parent's field. */
222
+ type ExemptedField<Field, Entry, Style> = [Entry] extends [boolean] ? Field : {
223
+ readonly [P in keyof Field]: P extends "capabilities" ? ExemptedCapabilities<Field[P], Entry, Style> : Field[P];
224
+ };
225
+ /** A Resource's fields under its exemptions' `fields` block. */
226
+ type ExemptedFields<Fields, Block, Style> = Style extends "omit" ? [Block] extends [never] ? Fields : {
227
+ readonly [F in Exclude<keyof Fields, WholeKey<Block>>]: F extends keyof Block ? ExemptedField<Fields[F], NonNullable<Block[F]>, "omit"> : Fields[F];
228
+ } : {
229
+ readonly [F in Extract<keyof Fields, GrantedFieldKey<Block>>]: ExemptedField<Fields[F], RawEntry<Block, F>, "pick">;
176
230
  };
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];
231
+ /** The fields an exemptions `fields` block leaves a Resource without. */
232
+ type RemovedField<Fields, Block, Style> = Style extends "omit" ? WholeKey<Block> : Exclude<keyof Fields, GrantedFieldKey<Block>>;
233
+ /** One family's entry in an operations entry: `true` for a listed family. */
234
+ 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;
235
+ /** The keys of a per-variant object entry set to a literal `true`. */
236
+ type TrueVariant<Entry> = {
237
+ [V in keyof Entry]-?: IsWhole<NonNullable<Entry[V]>> extends true ? V : never;
238
+ }[keyof Entry];
239
+ /** The variants of one family a layer keeps, by its style. */
240
+ 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>;
181
241
  /** The variants of the unique style, which need an identifier the layer keeps. */
182
242
  type UniqueVariant = "unique";
183
- /**
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.
186
- */
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> = {
243
+ /** The families with at least one variant the layer keeps. */
244
+ type KeptFamily<Operations, Entry, Style, UniqueLost> = {
190
245
  [F in keyof Operations]-?: [
191
- AvailableVariant<NonNullable<Operations[F]>, EntryOf<OperationRestrictions, F>, UniqueLost>
246
+ KeptVariant<NonNullable<Operations[F]>, FamilyEntry<Entry, F>, Style, UniqueLost>
192
247
  ] extends [never] ? never : F;
193
248
  }[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];
249
+ /** A Resource's operations under its exemptions' `operations` entry. */
250
+ 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>;
251
+ type KeptOperations<Operations, Entry, Style, UniqueLost> = {
252
+ readonly [F in KeptFamily<Operations, Entry, Style, UniqueLost>]: {
253
+ readonly [V in KeptVariant<NonNullable<Operations[F]>, FamilyEntry<Entry, F>, Style, UniqueLost>]: NonNullable<Operations[F]>[V];
201
254
  };
202
255
  };
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
256
+ /** A Resource's identifiers less those naming a removed field. */
257
+ 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;
258
+ /** Whether removing fields left a Resource with no identifier at all. */
259
+ type IdentifiersLost<Identifiers, Removed> = [Removed] extends [never] ? false : [
260
+ KeptIdentifiers<Identifiers, Removed> extends readonly (infer Kept)[] ? Kept : never
208
261
  ] 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 {
262
+ /** A Resource's `fields` and `operations` entries, read off its exemption object. */
263
+ type FieldsEntryOf<Entry> = LiteralRecord<(Entry & {
264
+ readonly fields?: unknown;
265
+ })["fields"]>;
266
+ type OperationsEntryOf<Entry> = (Entry & {
267
+ readonly operations?: unknown;
268
+ })["operations"];
269
+ /** One Resource under an object exemption: its fields, operations and identifiers. */
270
+ type ExemptedResourceObject<in out Resource, in out FieldsBlock, in out OperationsEntry, in out Style> = {
271
+ 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
272
  readonly identifiers: infer Ids;
216
- } ? Ids : never, HiddenKey<EntryOf<ResourceRestrictions, "fields">>>> : P extends "identifiers" ? KeptIdentifiers<Resource[P], HiddenKey<EntryOf<ResourceRestrictions, "fields">>> : Resource[P];
217
- };
218
- /**
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.
222
- */
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>>;
273
+ } ? Ids : never, RemovedField<Resource extends {
274
+ readonly fields: infer Fields;
275
+ } ? Fields : never, FieldsBlock, Style>>> : P extends "identifiers" ? KeptIdentifiers<Resource[P], RemovedField<Resource extends {
276
+ readonly fields: infer Fields;
277
+ } ? Fields : never, FieldsBlock, Style>> : Resource[P];
225
278
  };
279
+ /** One Resource under its exemption: `true` (or `boolean`) keeps the parent's. */
280
+ type ExemptedResource<Resource, Entry, Style> = [Entry] extends [boolean] ? Resource : ExemptedResourceObject<Resource, FieldsEntryOf<Entry>, OperationsEntryOf<Entry>, Style>;
281
+ /** A layer's Resources: its parent's, with its exemptions applied in its style. */
282
+ type ExposedResources<Resources, Style, Block> = Style extends "omit" ? [Block] extends [never] ? Resources : {
283
+ readonly [R in Exclude<keyof Resources, WholeKey<Block>>]: R extends keyof Block ? ExemptedResource<Resources[R], NonNullable<Block[R]>, "omit"> : Resources[R];
284
+ } : Style extends "pick" ? {
285
+ readonly [R in Extract<keyof Resources, GrantedResourceKey<Block>>]: ExemptedResource<Resources[R], RawEntry<Block, R>, "pick">;
286
+ } : Resources;
287
+ /** The Resources of the root's final view: what every overlay starts from. */
288
+ export type RootViewResources<M extends AvAdapterModel, Cfg> = ExposedResources<LayeredResources<M["resources"], ResourcesBlock<Cfg>, never>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>>;
289
+ /** The Resources of an overlay's final view: the root's view, narrowed by it. */
290
+ export type OverlayViewResources<M extends AvAdapterModel, Cfg, Layer extends "application" | "client"> = ExposedResources<ExposedResources<LayeredResources<M["resources"], ResourcesBlock<Cfg>, OverlayResourcesBlock<Cfg, Layer>>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, Layer>>>, ExemptionsOf<OverlayOf<Cfg, Layer>>>;
226
291
  /**
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.
292
+ * One derived Contract's type: the model, with the root's `resources` block
293
+ * applied, then the root's exposure, then the overlay's over the root's view.
230
294
  */
231
- type DerivedContractView<M extends AdapterModel, FieldsBlock, Restrictions, RootRestrictions> = {
295
+ type DerivedContractView<M extends AvAdapterModel, FieldsBlock, RootStyle, RootExemptions, OverlayStyle, OverlayExemptions, OverlayBlock> = {
232
296
  readonly scalars: M["scalars"];
233
297
  readonly enums: M["enums"];
234
- readonly resources: LayeredResources<M["resources"], FieldsBlock, Restrictions, RootRestrictions>;
235
- readonly limits: ContractLimits;
298
+ readonly resources: ExposedResources<ExposedResources<LayeredResources<M["resources"], FieldsBlock, OverlayBlock>, RootStyle, RootExemptions>, OverlayStyle, OverlayExemptions>;
299
+ readonly limits: AvContractLimits;
236
300
  readonly transactions: M["transactions"];
237
301
  };
238
302
  /**
239
303
  * The Application Contract's type, derived from the adapter model and the
240
304
  * configuration.
241
305
  */
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;
306
+ export type AvContractApplicationView<M extends AvAdapterModel, Cfg = AvConfigAny> = [Cfg] extends [unknown] ? DerivedContractView<M, ResourcesBlock<Cfg>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, "application">>>, ExemptionsOf<OverlayOf<Cfg, "application">>, OverlayResourcesBlock<Cfg, "application">> : never;
243
307
  /**
244
308
  * The Client Contract's type, derived from the adapter model and the
245
309
  * configuration: what the client layer hides is absent. It types
246
310
  * `framework.client` and `framework.clientTx`.
247
311
  */
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;
312
+ export type ClientContractView<M extends AvAdapterModel, Cfg = AvConfigAny> = [
313
+ Cfg
314
+ ] extends [unknown] ? DerivedContractView<M, ResourcesBlock<Cfg>, ExposureStyleOf<ExposedOf<Cfg>>, ExemptionsOf<Cfg>, ExposureStyleOf<ExposedOf<OverlayOf<Cfg, "client">>>, ExemptionsOf<OverlayOf<Cfg, "client">>, OverlayResourcesBlock<Cfg, "client">> : never;
249
315
  export {};
@@ -1,16 +1,16 @@
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 reported by {@link AvConstructionError}. */
7
+ export type AvConstructionDiagnostic = AvConfigDiagnostic | AvAdapterDiscoveryDiagnostic | AvContractCompilerDiagnostic;
8
8
  /**
9
9
  * Thrown by {@link createFramework} when construction fails: `stage` says
10
10
  * where, and `diagnostics` lists every problem found there.
11
11
  */
12
- export declare class FrameworkConstructionError extends Error {
13
- readonly stage: FrameworkConstructionStage;
14
- readonly diagnostics: readonly FrameworkConstructionDiagnostic[];
15
- constructor(stage: FrameworkConstructionStage, diagnostics: readonly FrameworkConstructionDiagnostic[]);
12
+ export declare class AvConstructionError extends Error {
13
+ readonly stage: AvConstructionStage;
14
+ readonly diagnostics: readonly AvConstructionDiagnostic[];
15
+ constructor(stage: AvConstructionStage, diagnostics: readonly AvConstructionDiagnostic[]);
16
16
  }
@@ -3,12 +3,12 @@ const FRAMEWORK_CONSTRUCTION_MESSAGES = {
3
3
  discovery: "Aventara adapter discovery validation failed",
4
4
  "contract-compilation": "Aventara contract compilation failed",
5
5
  };
6
- export class FrameworkConstructionError extends Error {
6
+ export class AvConstructionError extends Error {
7
7
  stage;
8
8
  diagnostics;
9
9
  constructor(stage, diagnostics) {
10
10
  super(FRAMEWORK_CONSTRUCTION_MESSAGES[stage]);
11
- this.name = "FrameworkConstructionError";
11
+ this.name = "AvConstructionError";
12
12
  this.stage = stage;
13
13
  this.diagnostics = [...diagnostics];
14
14
  }
@@ -1,28 +1,41 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { FrameworkContracts } from "../compiler/contract.compiler.js";
3
- import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvContracts } from "../compiler/contract.compiler.js";
3
+ import type { AvConfigAny } from "../config/any-framework-config.js";
4
+ import type { AvMcpEndpoint } from "../config/config.resolver.js";
4
5
  import type { FrameworkOperationRequest } from "../runtime/operation-request.js";
5
- import type { OperationResponse } from "../runtime/operation-response.js";
6
- import type { TransactionRunner } from "../transactions/deferred-operation.js";
6
+ import type { AvOperationResponse } from "../runtime/operation-response.js";
7
+ import type { AvTransactionRunner } from "../transactions/deferred-operation.js";
7
8
  import type { FrameworkTransactionRequest } from "../transactions/transaction-request.js";
8
- import type { TransactionResponse } from "../transactions/transaction-response.js";
9
+ import type { AvTransactionResponse } from "../transactions/transaction-response.js";
9
10
  import type { ApplicationOperations, ApplicationTransactionBuilders, ClientOperations, ClientTransactionBuilders } from "./operation-facade.js";
10
11
  /**
11
12
  * One Aventara instance, as returned by {@link createFramework}: its compiled
12
13
  * Contracts, typed in-process operations, transaction builders and the
13
14
  * untyped `execute` entry a transport calls.
14
15
  */
15
- export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig> = {
16
- readonly entrypoint: string;
17
- readonly contracts: FrameworkContracts;
16
+ export type AvFramework<M extends AvAdapterModel = AvAdapterModel, Cfg = AvConfigAny> = {
17
+ /**
18
+ * The protocol's mount path (`api`) in its canonical form: `""` at the
19
+ * root, otherwise `/seg(/seg)*`.
20
+ */
21
+ readonly api: string;
22
+ /**
23
+ * The MCP endpoint `mcp` turns on — its canonical mount path and its
24
+ * authorization — for the host that serves it; `undefined` when MCP is off.
25
+ */
26
+ readonly mcp: AvMcpEndpoint | undefined;
27
+ readonly contracts: AvContracts;
18
28
  /**
19
29
  * Typed in-process operations under the Application Contract:
20
30
  * `framework.application.<resource>.<family>.<variant>(args, options?)`.
21
31
  *
22
32
  * Typed from the Application Contract as configured: what the application's
23
- * restrictions hide, deny or turn off is absent from the types, and a call is
24
- * validated like any other request. The optional second argument is
25
- * {@link ExecutionOptions}.
33
+ * exposure hides, denies or turns off is absent from the types, and a call is
34
+ * validated like any other request. A call resolves the operation's data (a
35
+ * first-style miss is `null`) and throws every failure as the `AvError`
36
+ * subclass of its code's class (`AvValidationError`, `AvNotFoundError`, …).
37
+ * The optional second argument is
38
+ * {@link AvExecutionOptions}.
26
39
  */
27
40
  readonly application: ApplicationOperations<M, Cfg>;
28
41
  /**
@@ -33,25 +46,33 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
33
46
  * as from a generated client, and arguments are read in the wire
34
47
  * forms a decoded request body carries, so a transport can pass `req.body` as
35
48
  * it is. Each call runs the client pipelines and the same validation as a
36
- * remote request.
49
+ * remote request, and settles like an application call: the data, or the
50
+ * failure thrown.
37
51
  */
38
52
  readonly client: ClientOperations<M, Cfg>;
39
53
  /**
40
54
  * Transaction builders under application rules:
41
55
  * `framework.appTx.<resource>.<family>.<variant>(args)` defers one operation
42
- * into a handle typed `Operation<OperationResultFor<…>>` from the Application
56
+ * into a handle typed `AvOperation<AvOperationResultFor<…>>` from the Application
43
57
  * Contract's view, and runs nothing. A handle exposes `$ref(field)` exactly
44
58
  * where its result is one row; the reference is bound to the handle, and its
45
59
  * index is bound when {@link transaction} runs the list it is in.
60
+ *
61
+ * `framework.appTx.$sql` defers a developer SQL step, written only as a tagged
62
+ * template whose every interpolated value is bound as a parameter (a `$ref`
63
+ * among them, resolved when the earlier steps have run). It runs in plan order
64
+ * in the same database transaction, with no pipelines around it; its entry in
65
+ * the committed data is its rows, typed by `appTx.$sql<Row>`. It exists only
66
+ * here: `clientTx`, the Client Contract and `/_transactions` have no SQL step.
46
67
  */
47
68
  readonly appTx: ApplicationTransactionBuilders<M, Cfg>;
48
69
  /**
49
70
  * The same builders under ClientContract rules, taking wire-form arguments.
50
- * Client and application handles may share one {@link transaction}; each step
51
- * runs under its own handle's rules.
71
+ * A {@link transaction} has one origin: client and application handles never
72
+ * share one (`A2004`/`V1020` at the first step of the other origin).
52
73
  */
53
74
  readonly clientTx: ClientTransactionBuilders<M, Cfg>;
54
- execute(request: FrameworkOperationRequest): Promise<OperationResponse>;
75
+ execute(request: FrameworkOperationRequest): Promise<AvOperationResponse>;
55
76
  /**
56
77
  * Validates a whole transaction plan, then runs its operations one after
57
78
  * another inside one Adapter transaction. Answers `A1009` with each
@@ -62,15 +83,18 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
62
83
  * Guards, pipes, hooks and interceptors run while the transaction is open, so
63
84
  * they should not perform network I/O or other slow work.
64
85
  */
65
- executeTransaction(request: FrameworkTransactionRequest): Promise<TransactionResponse>;
86
+ executeTransaction(request: FrameworkTransactionRequest): Promise<AvTransactionResponse>;
66
87
  /**
67
88
  * Runs handles from `appTx`/`clientTx` as one transaction:
68
- * `framework.transaction([h1, h2, …], options?)`. Resolves the committed
69
- * response, typed per position, or the failure response. Never rejects.
89
+ * `framework.transaction([h1, h2, …], options?)`. Resolves each handle's
90
+ * result in plan order, typed per position, once the transaction committed,
91
+ * or throws the failure as the `AvError` subclass of its code's class, with
92
+ * `cause.operation` naming the failing step.
70
93
  *
71
94
  * Refused before anything runs: an entry that is not one of this Framework's
72
- * handles, or the same handle twice (`A2004`/`V1001`); a `$ref` to a handle
73
- * not in the list (`A2007`/`V1010`).
95
+ * handles, or the same handle twice (`A2004`/`V1001`); `appTx` and `clientTx`
96
+ * handles in one list (`A2004`/`V1020`); a `$ref` to a handle not in the list
97
+ * (`A2007`/`V1010`).
74
98
  */
75
- readonly transaction: TransactionRunner;
99
+ readonly transaction: AvTransactionRunner;
76
100
  };
@@ -1,11 +1,13 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AnyFrameworkConfig } from "../config/any-framework-config.js";
3
- import type { FrameworkConfig } from "../config/framework-config.js";
4
- import type { Framework } from "./framework.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
+ import type { AvConfigAny } from "../config/any-framework-config.js";
3
+ import type { AvConfigExact } from "../config/exact-framework-config.js";
4
+ import type { AvConfig } from "../config/framework-config.js";
5
+ import type { ErasedConfig } from "../config/stage-type.eraser.js";
6
+ import type { AvFramework } from "./framework.js";
5
7
  /**
6
8
  * Creates a Framework: validates the configuration, reads the adapter's
7
9
  * model and compiles the Contracts.
8
10
  *
9
- * @throws {@link FrameworkConstructionError} when any of those steps fails.
11
+ * @throws {@link AvConstructionError} when any of those steps fails.
10
12
  */
11
- export declare function createFramework<M extends AdapterModel, const Cfg = AnyFrameworkConfig>(config: Cfg & FrameworkConfig<M, Cfg>): Promise<Framework<M, Cfg>>;
13
+ export declare function createFramework<M extends AvAdapterModel, const Cfg = AvConfigAny>(config: Cfg & AvConfig<M, Cfg> & AvConfigExact<M, Cfg>): Promise<AvFramework<M, ErasedConfig<Cfg>>>;