@aventara/core 0.1.0-pilot.4 → 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 (255) hide show
  1. package/CHANGELOG.md +1478 -0
  2. package/README.md +275 -11
  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 +17 -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 -25
  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/avz/avz.js +354 -0
  19. package/dist/avz/index.d.ts +7 -0
  20. package/dist/avz/index.js +1 -0
  21. package/dist/avz/json-shape.registry.d.ts +22 -0
  22. package/dist/avz/json-shape.registry.js +16 -0
  23. package/dist/avz/zod-issue.translator.d.ts +57 -0
  24. package/dist/avz/zod-issue.translator.js +149 -0
  25. package/dist/compiler/contract-compiler-diagnostic.d.ts +37 -5
  26. package/dist/compiler/contract.compiler.d.ts +18 -18
  27. package/dist/compiler/contract.compiler.js +595 -421
  28. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  29. package/dist/compiler/create-requirements.projector.js +423 -0
  30. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  31. package/dist/compiler/field-validator.compiler.js +238 -0
  32. package/dist/config/any-framework-config.d.ts +19 -12
  33. package/dist/config/config-diagnostic.d.ts +11 -4
  34. package/dist/config/config-layer.d.ts +15 -6
  35. package/dist/config/config.resolver.d.ts +75 -29
  36. package/dist/config/config.resolver.js +109 -44
  37. package/dist/config/config.validator.d.ts +7 -7
  38. package/dist/config/config.validator.js +586 -71
  39. package/dist/config/define-resource.d.ts +57 -0
  40. package/dist/config/define-resource.js +14 -0
  41. package/dist/config/effective-fields.d.ts +19 -23
  42. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  43. package/dist/config/exact-framework-config.d.ts +280 -0
  44. package/dist/config/field-compute.resolver.d.ts +19 -0
  45. package/dist/config/field-compute.resolver.js +115 -0
  46. package/dist/config/field-pipeline-config.d.ts +47 -0
  47. package/dist/config/forced-operation.validator.d.ts +10 -0
  48. package/dist/config/forced-operation.validator.js +66 -0
  49. package/dist/config/framework-config.d.ts +111 -37
  50. package/dist/config/framework-exemptions-config.d.ts +91 -0
  51. package/dist/config/framework-exemptions-config.js +1 -0
  52. package/dist/config/framework-field-definition.d.ts +78 -0
  53. package/dist/config/framework-field-definition.js +28 -0
  54. package/dist/config/framework-resources-config.d.ts +116 -0
  55. package/dist/config/framework-resources-config.js +1 -0
  56. package/dist/config/pipeline-config.d.ts +56 -20
  57. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  58. package/dist/config/pipeline-tree.resolver.js +220 -0
  59. package/dist/config/stage-type.eraser.d.ts +65 -0
  60. package/dist/config/stage-type.eraser.js +1 -0
  61. package/dist/contracts/capability.d.ts +11 -11
  62. package/dist/contracts/client-contract-structure.validator.d.ts +344 -29
  63. package/dist/contracts/client-contract-structure.validator.js +248 -7
  64. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  65. package/dist/contracts/contract-canonicalizer.js +172 -27
  66. package/dist/contracts/contract-hash.d.ts +12 -7
  67. package/dist/contracts/contract-hash.js +3 -2
  68. package/dist/contracts/contract-limits.d.ts +4 -1
  69. package/dist/contracts/contract-limits.js +1 -0
  70. package/dist/contracts/contract-lookup.d.ts +5 -5
  71. package/dist/contracts/contract-protocol.d.ts +4 -4
  72. package/dist/contracts/contract.d.ts +31 -16
  73. package/dist/contracts/create-requirements.d.ts +35 -0
  74. package/dist/contracts/create-requirements.js +1 -0
  75. package/dist/contracts/enum-definition.d.ts +1 -1
  76. package/dist/contracts/field-check.d.ts +101 -0
  77. package/dist/contracts/field-check.js +1 -0
  78. package/dist/contracts/field.d.ts +61 -41
  79. package/dist/contracts/identifier.d.ts +4 -4
  80. package/dist/contracts/json-shape.d.ts +76 -0
  81. package/dist/contracts/json-shape.js +1 -0
  82. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  83. package/dist/contracts/reference-write-limit.d.ts +7 -0
  84. package/dist/contracts/reference-write-limit.js +1 -0
  85. package/dist/contracts/resource-operations.d.ts +28 -28
  86. package/dist/contracts/resource.d.ts +15 -9
  87. package/dist/contracts/scalar-value-type.d.ts +25 -14
  88. package/dist/contracts/scalar.d.ts +3 -3
  89. package/dist/contracts/transaction-capability.d.ts +1 -1
  90. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  91. package/dist/framework/contract-view.d.ts +234 -63
  92. package/dist/framework/framework-construction.error.d.ts +10 -10
  93. package/dist/framework/framework-construction.error.js +2 -2
  94. package/dist/framework/framework.d.ts +50 -24
  95. package/dist/framework/framework.factory.d.ts +8 -6
  96. package/dist/framework/framework.factory.js +95 -32
  97. package/dist/framework/operation-facade.d.ts +123 -52
  98. package/dist/framework/operation-facade.js +9 -1
  99. package/dist/index.d.ts +55 -82
  100. package/dist/index.js +6 -26
  101. package/dist/internal.d.ts +40 -0
  102. package/dist/internal.js +18 -0
  103. package/dist/operations/operation-arguments.d.ts +316 -201
  104. package/dist/operations/operation-call.d.ts +27 -28
  105. package/dist/operations/operation-identity.d.ts +12 -10
  106. package/dist/operations/operation-identity.js +3 -0
  107. package/dist/operations/operation-result.d.ts +21 -21
  108. package/dist/operations/operation-validator-core.d.ts +6 -6
  109. package/dist/operations/operation-validator-core.js +41 -12
  110. package/dist/operations/operation-validator.d.ts +24 -9
  111. package/dist/operations/operation-validator.js +26 -10
  112. package/dist/operations/projection-scope.resolver.d.ts +7 -7
  113. package/dist/operations/structural-limits.walker.d.ts +19 -0
  114. package/dist/operations/structural-limits.walker.js +489 -0
  115. package/dist/operations/validation-code.d.ts +11 -6
  116. package/dist/operations/validation-code.js +4 -0
  117. package/dist/operations/write-scope.resolver.d.ts +6 -6
  118. package/dist/protocol/absent-route.responder.d.ts +13 -11
  119. package/dist/protocol/absent-route.responder.js +42 -16
  120. package/dist/protocol/contract-document.responder.d.ts +3 -3
  121. package/dist/protocol/contract-document.responder.js +2 -2
  122. package/dist/protocol/http-request.decoder.d.ts +23 -13
  123. package/dist/protocol/http-request.decoder.js +19 -11
  124. package/dist/protocol/http-request.reader.d.ts +3 -3
  125. package/dist/protocol/http-response.encoder.d.ts +4 -4
  126. package/dist/protocol/http-response.encoder.js +94 -55
  127. package/dist/protocol/http-status.table.d.ts +2 -2
  128. package/dist/protocol/operation-response.guard.d.ts +2 -2
  129. package/dist/protocol/protocol-surface.d.ts +4 -4
  130. package/dist/protocol/protocol.binder.d.ts +52 -27
  131. package/dist/protocol/protocol.binder.js +14 -9
  132. package/dist/protocol/protocol.handler.d.ts +28 -15
  133. package/dist/protocol/protocol.handler.js +55 -10
  134. package/dist/protocol/unmounted-route.error.d.ts +19 -0
  135. package/dist/protocol/unmounted-route.error.js +10 -0
  136. package/dist/runtime/caller-data.copier.d.ts +59 -0
  137. package/dist/runtime/caller-data.copier.js +470 -0
  138. package/dist/runtime/caller-data.door.d.ts +56 -0
  139. package/dist/runtime/caller-data.door.js +67 -0
  140. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  141. package/dist/runtime/computed-read-runtime.js +61 -55
  142. package/dist/runtime/computed-value.error.d.ts +13 -0
  143. package/dist/runtime/computed-value.error.js +9 -0
  144. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  145. package/dist/runtime/context-executor.runtime.js +275 -0
  146. package/dist/runtime/create-requirement.d.ts +22 -57
  147. package/dist/runtime/create-requirement.js +140 -37
  148. package/dist/runtime/decimal.d.ts +2 -2
  149. package/dist/runtime/decimal.js +1 -1
  150. package/dist/runtime/diagnostics-reporter.d.ts +64 -22
  151. package/dist/runtime/diagnostics-reporter.js +35 -4
  152. package/dist/runtime/error-boundary.d.ts +73 -8
  153. package/dist/runtime/error-boundary.js +104 -48
  154. package/dist/runtime/execution-options.d.ts +10 -2
  155. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  156. package/dist/runtime/field-check.evaluator.js +521 -0
  157. package/dist/runtime/field-compute.d.ts +64 -0
  158. package/dist/runtime/field-compute.js +1 -0
  159. package/dist/runtime/field-stage.plan.d.ts +15 -0
  160. package/dist/runtime/field-stage.plan.js +27 -0
  161. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  162. package/dist/runtime/field-stage.runtime.js +143 -0
  163. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  164. package/dist/runtime/field-validator.runtime.js +87 -0
  165. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  166. package/dist/runtime/framework-error-class.table.js +25 -0
  167. package/dist/runtime/framework-error.d.ts +79 -7
  168. package/dist/runtime/framework-error.factory.d.ts +4 -0
  169. package/dist/runtime/framework-error.factory.js +15 -0
  170. package/dist/runtime/framework-error.js +23 -2
  171. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  172. package/dist/runtime/interceptor-next.error.js +6 -0
  173. package/dist/runtime/json-value.d.ts +3 -3
  174. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  175. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  176. package/dist/runtime/misuse-reporter.d.ts +32 -0
  177. package/dist/runtime/misuse-reporter.js +19 -0
  178. package/dist/runtime/mutation-planner.d.ts +19 -10
  179. package/dist/runtime/mutation-planner.js +62 -36
  180. package/dist/runtime/nested-write.walker.d.ts +32 -0
  181. package/dist/runtime/nested-write.walker.js +73 -0
  182. package/dist/runtime/operation-request.d.ts +35 -15
  183. package/dist/runtime/operation-response.d.ts +17 -17
  184. package/dist/runtime/operation-runtime.d.ts +125 -30
  185. package/dist/runtime/operation-runtime.js +423 -83
  186. package/dist/runtime/outcome-mapper.d.ts +16 -5
  187. package/dist/runtime/outcome-mapper.js +35 -8
  188. package/dist/runtime/output-validator.d.ts +16 -6
  189. package/dist/runtime/output-validator.js +12 -1
  190. package/dist/runtime/owned-execution.registry.d.ts +13 -0
  191. package/dist/runtime/owned-execution.registry.js +7 -0
  192. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  193. package/dist/runtime/pipe-output.validator.js +12 -12
  194. package/dist/runtime/pipeline.d.ts +202 -28
  195. package/dist/runtime/readonly-value.d.ts +32 -0
  196. package/dist/runtime/readonly-value.js +141 -0
  197. package/dist/runtime/referential-action.d.ts +7 -0
  198. package/dist/runtime/request-envelope.validator.d.ts +5 -0
  199. package/dist/runtime/request-envelope.validator.js +123 -0
  200. package/dist/runtime/request-id.d.ts +1 -1
  201. package/dist/runtime/request-state.d.ts +14 -0
  202. package/dist/runtime/request-state.js +1 -0
  203. package/dist/runtime/request-state.resolver.d.ts +12 -0
  204. package/dist/runtime/request-state.resolver.js +20 -0
  205. package/dist/runtime/scalar-runtime.d.ts +56 -13
  206. package/dist/runtime/scalar-runtime.js +167 -86
  207. package/dist/transactions/deferred-operation.d.ts +35 -20
  208. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  209. package/dist/transactions/operation-arguments-encoder.js +2 -2
  210. package/dist/transactions/sql-statement.d.ts +77 -0
  211. package/dist/transactions/sql-statement.js +47 -0
  212. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  213. package/dist/transactions/sql-statement.validator.js +134 -0
  214. package/dist/transactions/transaction-envelope.d.ts +4 -4
  215. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  216. package/dist/transactions/transaction-integrity-error.js +5 -2
  217. package/dist/transactions/transaction-plan-assembler.d.ts +23 -9
  218. package/dist/transactions/transaction-plan-assembler.js +195 -82
  219. package/dist/transactions/transaction-plan-validator.d.ts +53 -21
  220. package/dist/transactions/transaction-plan-validator.js +246 -163
  221. package/dist/transactions/transaction-reference-collector.d.ts +30 -0
  222. package/dist/transactions/transaction-reference-collector.js +204 -0
  223. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  224. package/dist/transactions/transaction-reference-resolver.js +27 -10
  225. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  226. package/dist/transactions/transaction-reference-validator.js +82 -43
  227. package/dist/transactions/transaction-reference.d.ts +30 -58
  228. package/dist/transactions/transaction-request.d.ts +20 -7
  229. package/dist/transactions/transaction-response.d.ts +12 -7
  230. package/dist/transactions/transaction-response.js +24 -1
  231. package/dist/transactions/transaction-runtime.d.ts +11 -8
  232. package/dist/transactions/transaction-runtime.js +167 -50
  233. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  234. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  235. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  236. package/dist/transactions/transaction-slot-path-error.js +2 -2
  237. package/dist/transactions/transaction-slot-writer.js +2 -2
  238. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  239. package/dist/transactions/transaction-stage.runtime.js +123 -0
  240. package/package.json +18 -3
  241. package/src/runtime/field-check.evaluator.ts +720 -0
  242. package/dist/config/define-fields.d.ts +0 -35
  243. package/dist/config/define-fields.js +0 -3
  244. package/dist/config/framework-behaviors-config.d.ts +0 -30
  245. package/dist/config/framework-fields-config.d.ts +0 -36
  246. package/dist/config/framework-restrictions-config.d.ts +0 -142
  247. package/dist/operations/operation-boolean-nodes.d.ts +0 -11
  248. package/dist/operations/operation-boolean-nodes.js +0 -283
  249. package/dist/operations/operation-nesting.d.ts +0 -8
  250. package/dist/operations/operation-nesting.js +0 -307
  251. package/dist/runtime/field-behavior.d.ts +0 -48
  252. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  253. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  254. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  255. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,62 +1,62 @@
1
- import type { ProjectionScope, WriteScope } from "./capability.js";
1
+ import type { AvProjectionScope, AvWriteScope } from "./capability.js";
2
2
  /**
3
3
  * The argument scopes one advertised operation variant qualifies its arguments
4
4
  * with: which projection position its projection arguments sit in, and which write
5
5
  * position its data argument sits in.
6
6
  */
7
- export type OperationVariantScopes = {
8
- readonly projection: ProjectionScope;
9
- readonly write?: WriteScope;
7
+ export type AvOperationVariantScopes = {
8
+ readonly projection: AvProjectionScope;
9
+ readonly write?: AvWriteScope;
10
10
  } | {
11
- readonly projection?: ProjectionScope;
12
- readonly write: WriteScope;
11
+ readonly projection?: AvProjectionScope;
12
+ readonly write: AvWriteScope;
13
13
  };
14
14
  /**
15
15
  * Availability of one standard operation variant: `true` for "available, with no
16
16
  * scope qualification stated", or the scopes the variant qualifies its arguments
17
17
  * with.
18
18
  */
19
- export type OperationAvailability = true | OperationVariantScopes;
19
+ export type AvOperationAvailability = true | AvOperationVariantScopes;
20
20
  /** Availability of protocol-defined standard operations for one Resource. */
21
- export type ResourceOperations = {
21
+ export type AvResourceOperations = {
22
22
  readonly find?: {
23
- readonly first?: OperationAvailability;
24
- readonly unique?: OperationAvailability;
25
- readonly many?: OperationAvailability;
26
- readonly count?: OperationAvailability;
23
+ readonly first?: AvOperationAvailability;
24
+ readonly unique?: AvOperationAvailability;
25
+ readonly many?: AvOperationAvailability;
26
+ readonly count?: AvOperationAvailability;
27
27
  };
28
28
  readonly create?: {
29
- readonly one?: OperationAvailability;
30
- readonly many?: OperationAvailability;
31
- readonly count?: OperationAvailability;
29
+ readonly one?: AvOperationAvailability;
30
+ readonly many?: AvOperationAvailability;
31
+ readonly count?: AvOperationAvailability;
32
32
  };
33
33
  readonly update?: {
34
- readonly first?: OperationAvailability;
35
- readonly unique?: OperationAvailability;
36
- readonly many?: OperationAvailability;
37
- readonly count?: OperationAvailability;
34
+ readonly first?: AvOperationAvailability;
35
+ readonly unique?: AvOperationAvailability;
36
+ readonly many?: AvOperationAvailability;
37
+ readonly count?: AvOperationAvailability;
38
38
  };
39
39
  readonly delete?: {
40
- readonly first?: OperationAvailability;
41
- readonly unique?: OperationAvailability;
42
- readonly many?: OperationAvailability;
43
- readonly count?: OperationAvailability;
40
+ readonly first?: AvOperationAvailability;
41
+ readonly unique?: AvOperationAvailability;
42
+ readonly many?: AvOperationAvailability;
43
+ readonly count?: AvOperationAvailability;
44
44
  };
45
45
  readonly upsert?: {
46
- readonly unique?: OperationAvailability;
46
+ readonly unique?: AvOperationAvailability;
47
47
  };
48
48
  };
49
49
  /**
50
- * Whether one `ResourceOperations` entry marks its variant available: it is
50
+ * Whether one `AvResourceOperations` entry marks its variant available: it is
51
51
  * `true` or an argument-position descriptor.
52
52
  */
53
- export declare function isOperationVariantAvailable(availability: unknown): availability is OperationAvailability;
53
+ export declare function isOperationVariantAvailable(availability: unknown): availability is AvOperationAvailability;
54
54
  /**
55
55
  * The projection position one advertised variant's projection arguments sit in.
56
56
  */
57
- export declare function projectionScopeOf(availability: unknown): ProjectionScope;
57
+ export declare function projectionScopeOf(availability: unknown): AvProjectionScope;
58
58
  /**
59
59
  * The write position one advertised variant's data argument sits in, and the write
60
60
  * mirror of {@link projectionScopeOf}.
61
61
  */
62
- export declare function writeScopeOf(availability: unknown): WriteScope;
62
+ export declare function writeScopeOf(availability: unknown): AvWriteScope;
@@ -1,12 +1,18 @@
1
- import type { Contract } from "./contract.js";
2
- import type { Field } from "./field.js";
3
- import type { Identifier } from "./identifier.js";
4
- import type { ResourceOperations } from "./resource-operations.js";
1
+ import type { AvContract } from "./contract.js";
2
+ import type { AvCreateRequirements } from "./create-requirements.js";
3
+ import type { AvField } from "./field.js";
4
+ import type { AvIdentifier } from "./identifier.js";
5
+ import type { AvResourceOperations } from "./resource-operations.js";
5
6
  /** A Resource's fields, by name. */
6
- export type ResourceFieldMap<C extends Contract> = Readonly<Record<string, Field<C>>>;
7
- /** One Resource: its fields, identifiers and available operations. */
8
- export type Resource<C extends Contract, TFields extends ResourceFieldMap<C> = ResourceFieldMap<C>> = {
7
+ export type AvResourceFieldMap<C extends AvContract> = Readonly<Record<string, AvField<C>>>;
8
+ /**
9
+ * One Resource: its fields, identifiers and available operations, and what a
10
+ * create of it cannot do without.
11
+ */
12
+ export type AvResource<C extends AvContract, TFields extends AvResourceFieldMap<C> = AvResourceFieldMap<C>> = {
9
13
  readonly fields: TFields;
10
- readonly identifiers: readonly Identifier<TFields>[];
11
- readonly operations: ResourceOperations;
14
+ readonly identifiers: readonly AvIdentifier<TFields>[];
15
+ readonly operations: AvResourceOperations;
16
+ /** What a create must write; absent when it requires nothing. */
17
+ readonly createRequirements?: AvCreateRequirements;
12
18
  };
@@ -1,41 +1,42 @@
1
- import type { Decimal } from "../runtime/decimal.js";
2
- import type { JsonValue } from "../runtime/json-value.js";
3
- import type { Contract } from "./contract.js";
4
- import type { ScalarField } from "./field.js";
5
- import type { BuiltInScalar } from "./scalar.js";
1
+ import type { AvDecimal } from "../runtime/decimal.js";
2
+ import type { AvJsonValue } from "../runtime/json-value.js";
3
+ import type { AvContract } from "./contract.js";
4
+ import type { AvScalarField } from "./field.js";
5
+ import type { JsonFieldType } from "./json-shape.js";
6
+ import type { AvBuiltInScalar } from "./scalar.js";
6
7
  /**
7
8
  * A scalar-form map: the TypeScript type each built-in scalar takes on one side
8
9
  * of a boundary. Every built-in must be listed.
9
10
  */
10
11
  export type ScalarForms = {
11
- readonly [Scalar in BuiltInScalar]: unknown;
12
+ readonly [Scalar in AvBuiltInScalar]: unknown;
12
13
  };
13
14
  /**
14
15
  * The TypeScript form each built-in scalar takes in process: in results of
15
16
  * either origin, and in `framework.application` arguments. `decimal` is
16
- * Aventara's own {@link Decimal}.
17
+ * Aventara's own {@link AvDecimal}.
17
18
  */
18
- export type ApplicationScalarForms = {
19
+ export type AvApplicationScalarForms = {
19
20
  readonly string: string;
20
21
  readonly boolean: boolean;
21
22
  readonly int: number;
22
23
  readonly float: number;
23
24
  readonly bigint: bigint;
24
- readonly decimal: Decimal;
25
+ readonly decimal: AvDecimal;
25
26
  readonly datetime: Date;
26
27
  readonly bytes: Uint8Array;
27
28
  /**
28
29
  * Any JSON value. A field-level `null` is the field's absence and is allowed
29
30
  * only where the field is nullable; a `null` inside the value is JSON's own.
30
31
  */
31
- readonly json: Exclude<JsonValue, null>;
32
+ readonly json: Exclude<AvJsonValue, null>;
32
33
  };
33
34
  /**
34
35
  * The encoded forms of the built-in scalars: base-10 bigint strings, decimal strings,
35
36
  * canonical ISO-8601 UTC datetimes and RFC 4648 base64 bytes. For a transport or a
36
37
  * generated client to pass as `Forms`.
37
38
  */
38
- export type WireScalarForms = {
39
+ export type AvWireScalarForms = {
39
40
  readonly string: string;
40
41
  readonly boolean: boolean;
41
42
  readonly int: number;
@@ -45,14 +46,24 @@ export type WireScalarForms = {
45
46
  readonly datetime: string;
46
47
  readonly bytes: string;
47
48
  /** The same as in process: a JSON value needs no encoding to cross a JSON wire. */
48
- readonly json: Exclude<JsonValue, null>;
49
+ readonly json: Exclude<AvJsonValue, null>;
49
50
  };
50
51
  /** One value of a scalar field, before `list` and `nullable` apply. */
51
- export type ScalarAtom<C extends Contract, Type, Forms extends ScalarForms> = Type extends {
52
+ export type ScalarAtom<C extends AvContract, Type, Forms extends ScalarForms> = Type extends {
52
53
  readonly enum: infer Enum extends keyof C["enums"];
53
54
  } ? C["enums"][Enum]["values"][number] : Type extends {
54
55
  readonly scalar: infer Scalar;
55
56
  } ? Scalar extends keyof Forms ? Forms[Scalar] : unknown : never;
57
+ /**
58
+ * One value of a scalar field, before `list` and `nullable` apply: its Json
59
+ * Shape's type where the field is shaped, otherwise {@link ScalarAtom}.
60
+ */
61
+ export type FieldAtom<C extends AvContract, Field extends {
62
+ readonly type: unknown;
63
+ readonly json?: unknown;
64
+ }, Forms extends ScalarForms> = Field extends {
65
+ readonly json: JsonFieldType<infer Value>;
66
+ } ? Value : ScalarAtom<C, Field["type"], Forms>;
56
67
  /**
57
68
  * `list: true` makes the value a read-only array of atoms. A `list` the Contract
58
69
  * left as a plain `boolean` admits either, so neither form is promised.
@@ -67,5 +78,5 @@ type ListValue<List, Atom> = [List] extends [false] ? Atom : [List] extends [tru
67
78
  * - `list: true` → `readonly T[]`, whose entries are never `null`;
68
79
  * - `nullable: true` → `| null`, on the whole value, list or not.
69
80
  */
70
- export type ScalarValueType<C extends Contract, Field extends ScalarField<C>, Forms extends ScalarForms = ApplicationScalarForms> = ListValue<Field["list"], ScalarAtom<C, Field["type"], Forms>> | (true extends Field["nullable"] ? null : never);
81
+ export type AvScalarValueType<C extends AvContract, Field extends AvScalarField<C>, Forms extends ScalarForms = AvApplicationScalarForms> = ListValue<Field["list"], FieldAtom<C, Field, Forms>> | (true extends Field["nullable"] ? null : never);
71
82
  export {};
@@ -1,10 +1,10 @@
1
1
  /** The built-in scalar types of the Aventara protocol. */
2
2
  export declare const BUILT_IN_SCALARS: readonly ["string", "boolean", "int", "float", "bigint", "decimal", "datetime", "bytes", "json"];
3
3
  /** One of {@link BUILT_IN_SCALARS}. */
4
- export type BuiltInScalar = (typeof BUILT_IN_SCALARS)[number];
4
+ export type AvBuiltInScalar = (typeof BUILT_IN_SCALARS)[number];
5
5
  /** One entry of a scalar registry. */
6
- export type ScalarDefinition = {
6
+ export type AvScalarDefinition = {
7
7
  readonly builtin: true;
8
8
  };
9
9
  /** The scalar types an adapter model or Contract supports, by name. */
10
- export type ScalarRegistry = Readonly<Record<string, ScalarDefinition>>;
10
+ export type AvScalarRegistry = Readonly<Record<string, AvScalarDefinition>>;
@@ -1,4 +1,4 @@
1
1
  /** The transaction capabilities. */
2
2
  export declare const TRANSACTION_CAPABILITIES: readonly ["none", "interactive"];
3
3
  /** `"none"` or `"interactive"`: whether transactions can run. */
4
- export type TransactionCapability = (typeof TRANSACTION_CAPABILITIES)[number];
4
+ export type AvTransactionCapability = (typeof TRANSACTION_CAPABILITIES)[number];
@@ -1,5 +1,5 @@
1
- import type { BuiltInScalar } from "./scalar.js";
2
- import type { ApplicationScalarForms, WireScalarForms } from "./scalar-value-type.js";
1
+ import type { AvBuiltInScalar } from "./scalar.js";
2
+ import type { AvApplicationScalarForms, AvWireScalarForms } from "./scalar-value-type.js";
3
3
  /**
4
4
  * The built-in scalars whose wire form is not their runtime form — the ones a JSON
5
5
  * wire carries as a string with a grammar of its own. Derived from the two form maps
@@ -7,8 +7,8 @@ import type { ApplicationScalarForms, WireScalarForms } from "./scalar-value-typ
7
7
  * compile below until its grammar is written.
8
8
  */
9
9
  type WireEncodedScalar = {
10
- readonly [S in BuiltInScalar]: WireScalarForms[S] extends ApplicationScalarForms[S] ? never : S;
11
- }[BuiltInScalar];
10
+ readonly [S in AvBuiltInScalar]: AvWireScalarForms[S] extends AvApplicationScalarForms[S] ? never : S;
11
+ }[AvBuiltInScalar];
12
12
  /**
13
13
  * `AvProtocol.scalarFormats` — the wire grammars of protocol version 1, as passive
14
14
  * data: one anchored pattern SOURCE string per wire-encoded scalar, in
@@ -1,40 +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";
5
- /** Whether `resolveRecord` descends into a value: an object that is no array. */
6
- type IsLayeredRecord<T> = [T] extends [readonly unknown[]] ? false : [T] extends [object] ? true : false;
7
- /**
8
- * A root record with a scoped record layered over it: a key the scoped side
9
- * states wins; when both sides are records they merge, recursively; otherwise
10
- * the scoped value replaces the root one.
11
- */
12
- type LayeredRecord<Root, Scoped> = {
13
- readonly [K in keyof Root | keyof Scoped]: K extends keyof Scoped ? K extends keyof Root ? [IsLayeredRecord<Root[K]>, IsLayeredRecord<Scoped[K]>] extends [
14
- true,
15
- true
16
- ] ? LayeredRecord<Root[K], Scoped[K]> : Scoped[K] : Scoped[K] : K extends keyof Root ? Root[K] : never;
17
- };
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";
6
+ import type { JsonShape, ShapedJsonSchema } from "../contracts/json-shape.js";
18
7
  /**
19
8
  * A record whose keys are literal, or `never`. An absent block, an index-signature
20
- * record — the `AnyFrameworkConfig` default, or a configuration annotated with the
21
- * 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
22
11
  * than widening every resource's field set to `string`.
23
12
  */
24
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;
25
- type LayeredBlocks<Root, Scoped> = [Root] extends [never] ? Scoped : [Scoped] extends [never] ? Root : LayeredRecord<Root, Scoped>;
26
- /**
27
- * One configuration block as a derived Contract is compiled from it: the root
28
- * `Key`, with layer `Layer`'s `Key` layered over it.
29
- */
30
- type LayerBlock<Cfg, Layer extends RequestOrigin, Key extends "fields" | "restrictions"> = LayeredBlocks<LiteralRecord<(Cfg & {
14
+ /** The root's own `Key` block. */
15
+ type RootBlock<Cfg, Key extends PropertyKey> = LiteralRecord<(Cfg & {
31
16
  readonly [K in Key]?: unknown;
32
- })[Key]>, LiteralRecord<((Cfg & {
33
- readonly [L in Layer]?: unknown;
34
- })[Layer] & {
35
- readonly [K in Key]?: unknown;
36
- })[Key]>>;
37
- /** One key's entry in a layered block, or `never` when the block has none. */
17
+ })[Key]>;
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. */
38
25
  type EntryOf<Block, Key> = [Block] extends [never] ? never : Key extends keyof Block ? LiteralRecord<NonNullable<Block[Key]>> : never;
39
26
  type ConfiguredCapabilities<FieldConfig> = [FieldConfig] extends [never] ? Record<never, never> : FieldConfig extends {
40
27
  readonly capabilities: infer Capabilities;
@@ -61,10 +48,19 @@ type LayeredModelField<Field, FieldConfig> = Field extends {
61
48
  } ? [FieldConfig] extends [never] ? Field extends {
62
49
  readonly capabilities: infer Capabilities;
63
50
  } ? "select" extends keyof Capabilities ? Field : ConfiguredModelField<Field, FieldConfig> : ConfiguredModelField<Field, FieldConfig> : ConfiguredModelField<Field, FieldConfig> : Field;
64
- /** A discovered scalar with its configured capabilities applied, member by member. */
51
+ /**
52
+ * A discovered scalar with its configured capabilities applied, member by member,
53
+ * and its configured Json Shape, whose type its value takes.
54
+ */
65
55
  type ConfiguredModelField<Field, FieldConfig> = {
66
56
  readonly [P in keyof Field]: P extends "capabilities" ? LayeredCapabilities<Field[P], ConfiguredCapabilities<FieldConfig>> : Field[P];
67
- };
57
+ } & ConfiguredJsonShape<FieldConfig>;
58
+ /** A configured Json Shape as a view field's `json` member; nothing otherwise. */
59
+ type ConfiguredJsonShape<FieldConfig> = [FieldConfig] extends [never] ? unknown : FieldConfig extends {
60
+ readonly json: JsonShape<infer Value>;
61
+ } ? {
62
+ readonly json: ShapedJsonSchema<Value>;
63
+ } : unknown;
68
64
  /** A scalar the configuration adds, exactly as the configuration states it. */
69
65
  type AddedField<FieldConfig> = {
70
66
  readonly kind: "scalar";
@@ -85,60 +81,235 @@ type AddedField<FieldConfig> = {
85
81
  type AddedFieldKey<ModelFields, ResourceConfig> = [ResourceConfig] extends [
86
82
  never
87
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">;
88
86
  /**
89
- * Whether a restriction entry hides what it names: only a literal `hidden: true`
90
- * 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.
91
89
  */
92
- type IsHidden<Restriction> = [Restriction] extends [never] ? false : Restriction extends {
93
- readonly hidden: true;
94
- } ? 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
+ };
95
93
  /**
96
- * The keys a restrictions block hides, or `never` for a view that reads no
97
- * 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.
98
96
  */
99
- type HiddenKey<Restrictions> = [Restrictions] extends [never] ? never : {
100
- [K in keyof Restrictions]-?: IsHidden<EntryOf<Restrictions, K>> extends true ? K : never;
101
- }[keyof Restrictions];
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];
102
108
  /**
103
- * A Resource's fields in the view: the model's and the ones the configuration
104
- * adds, less the ones this view's restrictions hide.
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`).
105
113
  */
106
- type LayeredFields<ModelFields, ResourceConfig, FieldRestrictions> = {
107
- readonly [F in Exclude<keyof ModelFields | AddedFieldKey<ModelFields, ResourceConfig>, HiddenKey<FieldRestrictions>>]: F extends keyof ModelFields ? LayeredModelField<ModelFields[F], EntryOf<ResourceConfig, F>> : AddedField<EntryOf<ResourceConfig, F>>;
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];
108
118
  };
109
- /** One Resource in the view: the model's own, with its fields layered. */
110
- type LayeredResource<in out Resource, in out ResourceConfig, in out ResourceRestrictions> = {
111
- readonly [P in keyof Resource]: P extends "fields" ? LayeredFields<Resource[P], ResourceConfig, EntryOf<ResourceRestrictions, "fields">> : Resource[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>>;
112
137
  };
113
138
  /**
114
- * The Resources in the view. `Restrictions` is the layered `restrictions` block
115
- * whose `hidden` entries this view applies, or `never` for a view that applies
116
- * none.
139
+ * The style a layer's `exposed` sets: `false` picks, `true` or absent omits, a
140
+ * widened `boolean` keeps the parent's view.
117
141
  */
118
- type LayeredResources<Resources, Block, Restrictions> = {
119
- readonly [R in Exclude<keyof Resources, HiddenKey<Restrictions>>]: LayeredResource<Resources[R], EntryOf<Block, R>, EntryOf<Restrictions, R>>;
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">;
230
+ };
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>;
241
+ /** The variants of the unique style, which need an identifier the layer keeps. */
242
+ type UniqueVariant = "unique";
243
+ /** The families with at least one variant the layer keeps. */
244
+ type KeptFamily<Operations, Entry, Style, UniqueLost> = {
245
+ [F in keyof Operations]-?: [
246
+ KeptVariant<NonNullable<Operations[F]>, FamilyEntry<Entry, F>, Style, UniqueLost>
247
+ ] extends [never] ? never : F;
248
+ }[keyof Operations];
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];
254
+ };
255
+ };
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
261
+ ] extends [never] ? true : false;
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 {
272
+ readonly identifiers: infer Ids;
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];
120
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>>>;
121
291
  /**
122
- * One derived Contract's type: the model, with a layer's `fields` block applied
123
- * and, when `Restrictions` is a block rather than `never`, its hidden entries
124
- * removed.
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.
125
294
  */
126
- type DerivedContractView<M extends AdapterModel, FieldsBlock, Restrictions> = {
295
+ type DerivedContractView<M extends AvAdapterModel, FieldsBlock, RootStyle, RootExemptions, OverlayStyle, OverlayExemptions, OverlayBlock> = {
127
296
  readonly scalars: M["scalars"];
128
297
  readonly enums: M["enums"];
129
- readonly resources: LayeredResources<M["resources"], FieldsBlock, Restrictions>;
130
- readonly limits: ContractLimits;
298
+ readonly resources: ExposedResources<ExposedResources<LayeredResources<M["resources"], FieldsBlock, OverlayBlock>, RootStyle, RootExemptions>, OverlayStyle, OverlayExemptions>;
299
+ readonly limits: AvContractLimits;
131
300
  readonly transactions: M["transactions"];
132
301
  };
133
302
  /**
134
303
  * The Application Contract's type, derived from the adapter model and the
135
304
  * configuration.
136
305
  */
137
- export type ApplicationContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "application", "fields">, never> : 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;
138
307
  /**
139
308
  * The Client Contract's type, derived from the adapter model and the
140
309
  * configuration: what the client layer hides is absent. It types
141
310
  * `framework.client` and `framework.clientTx`.
142
311
  */
143
- export type ClientContractView<M extends AdapterModel, Cfg = AnyFrameworkConfig> = [Cfg] extends [unknown] ? DerivedContractView<M, LayerBlock<Cfg, "client", "fields">, LayerBlock<Cfg, "client", "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;
144
315
  export {};