@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
@@ -4,4 +4,5 @@ export const DEFAULT_CONTRACT_LIMITS = {
4
4
  maxListLimit: 250,
5
5
  maxTransactionOperations: 20,
6
6
  maxBooleanNodes: 50,
7
+ maxJsonDepth: 64,
7
8
  };
@@ -1,6 +1,6 @@
1
- import type { Contract } from "./contract.js";
2
- import type { Field } from "./field.js";
3
- import type { Resource } from "./resource.js";
1
+ import type { AvContract } from "./contract.js";
2
+ import type { AvField } from "./field.js";
3
+ import type { AvResource } from "./resource.js";
4
4
  /**
5
5
  * Own-property lookups over Contract registries.
6
6
  *
@@ -12,5 +12,5 @@ import type { Resource } from "./resource.js";
12
12
  * must go through here so an unknown key is unknown, whatever its name.
13
13
  */
14
14
  export declare function lookupOwn<T>(registry: Readonly<Record<string, T>> | undefined, key: string): T | undefined;
15
- export declare function lookupResource<C extends Contract>(contract: C, resourceName: string): Resource<C> | undefined;
16
- export declare function lookupField<C extends Contract>(resource: Resource<C> | undefined, fieldName: string): Field<C> | undefined;
15
+ export declare function lookupResource<C extends AvContract>(contract: C, resourceName: string): AvResource<C> | undefined;
16
+ export declare function lookupField<C extends AvContract>(resource: AvResource<C> | undefined, fieldName: string): AvField<C> | undefined;
@@ -5,13 +5,13 @@
5
5
  */
6
6
  export declare const AVENTARA_PROTOCOL_VERSION: 1;
7
7
  /** A Contract hash: `sha256:` followed by the hex digest. */
8
- export type ContractHash = `sha256:${string}`;
8
+ export type AvContractHash = `sha256:${string}`;
9
9
  /** The protocol a Contract is written for. */
10
- export type ContractProtocol = {
10
+ export type AvContractProtocol = {
11
11
  /** The protocol version; see {@link AVENTARA_PROTOCOL_VERSION}. */
12
12
  readonly version: typeof AVENTARA_PROTOCOL_VERSION;
13
13
  };
14
14
  /** A ClientContract's `protocol`: the protocol version and the Contract hash. */
15
- export type ClientContractProtocol = ContractProtocol & {
16
- readonly hash: ContractHash;
15
+ export type AvContractClientProtocol = AvContractProtocol & {
16
+ readonly hash: AvContractHash;
17
17
  };
@@ -1,33 +1,48 @@
1
- import type { ContractLimits } from "./contract-limits.js";
2
- import type { ClientContractProtocol } from "./contract-protocol.js";
3
- import type { EnumDefinition } from "./enum-definition.js";
4
- import type { Resource } from "./resource.js";
5
- import type { ScalarRegistry } from "./scalar.js";
6
- import type { TransactionCapability } from "./transaction-capability.js";
1
+ import type { AvContractLimits } from "./contract-limits.js";
2
+ import type { AvContractClientProtocol } from "./contract-protocol.js";
3
+ import type { AvEnumDefinition } from "./enum-definition.js";
4
+ import type { ReferenceWriteLimit } from "./reference-write-limit.js";
5
+ import type { AvResource } from "./resource.js";
6
+ import type { AvScalarRegistry } from "./scalar.js";
7
+ import type { AvTransactionCapability } from "./transaction-capability.js";
7
8
  /** What every Contract describes: scalars, enums, Resources, limits and transactions. */
8
- export interface Contract {
9
+ export interface AvContract {
9
10
  /** The scalar types available. */
10
- readonly scalars: ScalarRegistry;
11
+ readonly scalars: AvScalarRegistry;
11
12
  /** The enums, by name. */
12
- readonly enums: Readonly<Record<string, EnumDefinition>>;
13
+ readonly enums: Readonly<Record<string, AvEnumDefinition>>;
13
14
  /** The Resources, by name. */
14
- readonly resources: Readonly<Record<string, Resource<this>>>;
15
+ readonly resources: Readonly<Record<string, AvResource<this>>>;
15
16
  /** The request limits in force. */
16
- readonly limits: ContractLimits;
17
+ readonly limits: AvContractLimits;
17
18
  /** Whether interactive transactions are available. */
18
- readonly transactions: TransactionCapability;
19
+ readonly transactions: AvTransactionCapability;
20
+ /**
21
+ * `"uniform"` when one record must write the relations that hold a reference
22
+ * either all as relations or all through their reference fields; a record
23
+ * that mixes them is refused with `A2004`. Absent: each relation either way.
24
+ */
25
+ readonly referenceWrites?: ReferenceWriteLimit;
19
26
  }
20
27
  /** The Contract compiled from the root configuration. */
21
- export interface CoreContract extends Contract {
28
+ export interface AvContractCore extends AvContract {
22
29
  }
23
30
  /** The Contract in-process calls run under (`framework.application`). */
24
- export interface ApplicationContract extends Contract {
31
+ export interface AvContractApplication extends AvContract {
25
32
  }
26
33
  /**
27
34
  * The Contract remote clients run under, published at `GET /_contract` and
28
35
  * identified by its hash.
29
36
  */
30
- export interface ClientContract extends Contract {
37
+ export interface AvContractClient extends AvContract {
31
38
  /** The protocol version and this Contract's hash. */
32
- readonly protocol: ClientContractProtocol;
39
+ readonly protocol: AvContractClientProtocol;
40
+ }
41
+ /**
42
+ * The Contract an AI agent's calls run under (the `agent` layer), identified by
43
+ * its hash. MCP tools are built from it.
44
+ */
45
+ export interface AvContractAgent extends AvContract {
46
+ /** The protocol version and this Contract's hash. */
47
+ readonly protocol: AvContractClientProtocol;
33
48
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A required to-one relation and the scalar fields that hold its reference,
3
+ * relation first: `["author", "authorId"]`. A create writes the relation, or
4
+ * every one of the fields together (`["author", "tenantId", "authorId"]` for a
5
+ * composite reference), never both.
6
+ */
7
+ export type AvCreateRequirementGroup = readonly [string, string, ...string[]];
8
+ /**
9
+ * What a create of one Resource cannot do without, as the Contract's layer
10
+ * exposes it. Only fields the layer lets a caller write at create appear: a
11
+ * group whose reference fields the layer hides is its relation alone, in
12
+ * `required`; one whose relation it hides is its reference fields, in
13
+ * `required`; a field a compute stage fills at create (`COMPUTED_ON_CREATE`) is
14
+ * not required.
15
+ */
16
+ export type AvCreateRequirements = {
17
+ /**
18
+ * The fields every create must write: scalars with no default, generated or
19
+ * computed value, and relations whose reference fields the layer hides.
20
+ */
21
+ readonly required?: readonly [string, ...string[]];
22
+ /** The required relations a create writes either way: see {@link AvCreateRequirementGroup}. */
23
+ readonly oneOf?: readonly [
24
+ AvCreateRequirementGroup,
25
+ ...AvCreateRequirementGroup[]
26
+ ];
27
+ /**
28
+ * By parent Resource, then by its relation: the fields above that a create
29
+ * nested through that relation gets from its parent, so it is not required
30
+ * there. `{ "User": { "posts": ["author", "authorId"] } }`: a post created in
31
+ * `User.posts` needs neither `author` nor `authorId`; a group any of whose
32
+ * fields is listed is satisfied whole.
33
+ */
34
+ readonly parentSupplies?: Readonly<Record<string, Readonly<Record<string, readonly [string, ...string[]]>>>>;
35
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  /** An enum: its allowed values. */
2
- export type EnumDefinition = {
2
+ export type AvEnumDefinition = {
3
3
  /** The allowed values, in declaration order. */
4
4
  readonly values: readonly string[];
5
5
  };
@@ -0,0 +1,101 @@
1
+ /** The named string formats: what `AvZ.email()`, `AvZ.uuid()` and the rest check. */
2
+ export type AvFieldCheckFormat = "email" | "url" | "emoji" | "uuid" | "guid" | "nanoid" | "cuid" | "cuid2" | "ulid" | "xid" | "ksuid" | "datetime" | "date" | "time" | "duration" | "ipv4" | "ipv6" | "cidrv4" | "cidrv6" | "base64" | "base64url" | "json_string" | "e164" | "credit_card" | "iban" | "jwt";
3
+ /**
4
+ * A bound on a value (`AvZ.lt`, `AvZ.gte`, `AvZ.positive`, …). `value` is a number
5
+ * for an `int` or `float` field and a Json number; for a `bigint`, `decimal` or
6
+ * `datetime` field it is the bound's wire string.
7
+ */
8
+ export type AvFieldRangeCheck = {
9
+ readonly check: "less_than" | "greater_than";
10
+ readonly value: number | string;
11
+ readonly inclusive: boolean;
12
+ };
13
+ /** `AvZ.multipleOf`: `value` is written as {@link AvFieldRangeCheck}'s is. */
14
+ export type AvFieldMultipleCheck = {
15
+ readonly check: "multiple_of";
16
+ readonly value: number | string;
17
+ };
18
+ /** A length bound: a string's, or with `list: true` a list's. */
19
+ export type AvFieldLengthCheck = {
20
+ readonly check: "max_length";
21
+ readonly maximum: number;
22
+ readonly list?: true;
23
+ } | {
24
+ readonly check: "min_length";
25
+ readonly minimum: number;
26
+ readonly list?: true;
27
+ } | {
28
+ readonly check: "length_equals";
29
+ readonly length: number;
30
+ };
31
+ /** A pattern or a named format a string must match. */
32
+ export type AvFieldFormatCheck = {
33
+ readonly check: "string_format";
34
+ readonly format: "regex";
35
+ /** A JavaScript regular expression: its `source` and its `flags`. */
36
+ readonly pattern: {
37
+ readonly source: string;
38
+ readonly flags: string;
39
+ };
40
+ } | {
41
+ readonly check: "string_format";
42
+ readonly format: "includes";
43
+ readonly includes: string;
44
+ } | {
45
+ readonly check: "string_format";
46
+ readonly format: "starts_with";
47
+ readonly prefix: string;
48
+ } | {
49
+ readonly check: "string_format";
50
+ readonly format: "ends_with";
51
+ readonly suffix: string;
52
+ } | {
53
+ readonly check: "string_format";
54
+ readonly format: "lowercase" | "uppercase" | AvFieldCheckFormat;
55
+ };
56
+ /** A `bytes` value's byte length. */
57
+ export type AvFieldSizeCheck = {
58
+ readonly check: "max_size";
59
+ readonly maximum: number;
60
+ } | {
61
+ readonly check: "min_size";
62
+ readonly minimum: number;
63
+ } | {
64
+ readonly check: "size_equals";
65
+ readonly size: number;
66
+ };
67
+ /**
68
+ * One field validator as the Contract stores it: its check's name (`check`) and
69
+ * the check's parameters.
70
+ */
71
+ export type AvFieldCheck = AvFieldRangeCheck | AvFieldMultipleCheck | AvFieldLengthCheck | AvFieldFormatCheck | AvFieldSizeCheck;
72
+ /** The checks a Json Shape's string node may carry: its length, a pattern or a format. */
73
+ export type AvJsonStringCheck = {
74
+ readonly check: "max_length";
75
+ readonly maximum: number;
76
+ } | {
77
+ readonly check: "min_length";
78
+ readonly minimum: number;
79
+ } | {
80
+ readonly check: "length_equals";
81
+ readonly length: number;
82
+ } | AvFieldFormatCheck;
83
+ /** The checks a Json Shape's number or integer node may carry: bounds are numbers. */
84
+ export type AvJsonNumberCheck = {
85
+ readonly check: "less_than" | "greater_than";
86
+ readonly value: number;
87
+ readonly inclusive: boolean;
88
+ } | {
89
+ readonly check: "multiple_of";
90
+ readonly value: number;
91
+ };
92
+ /** The checks a Json Shape's array node may carry: its length. */
93
+ export type AvJsonListCheck = {
94
+ readonly check: "max_length";
95
+ readonly maximum: number;
96
+ readonly list: true;
97
+ } | {
98
+ readonly check: "min_length";
99
+ readonly minimum: number;
100
+ readonly list: true;
101
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,118 +1,138 @@
1
- import type { PaginationCapability, ProjectionScope, RelationFilterCapability, RelationMutationDirective, RelationReducer, ScalarFilterOperator, ScalarMutationDirective, WriteScope } from "./capability.js";
2
- import type { Contract } from "./contract.js";
3
- import type { LifecycleTrait } from "./lifecycle-trait.js";
1
+ import type { AvPaginationCapability, AvProjectionScope, AvRelationFilterCapability, AvRelationMutationDirective, AvRelationReducer, AvScalarFilterOperator, AvScalarMutationDirective, AvWriteScope } from "./capability.js";
2
+ import type { AvContract } from "./contract.js";
3
+ import type { AvFieldCheck } from "./field-check.js";
4
+ import type { JsonSchema } from "./json-shape.js";
5
+ import type { AvLifecycleTrait } from "./lifecycle-trait.js";
4
6
  /** A format name that refines a scalar type, carried in the Contract as data. */
5
- export type ScalarFormat = string;
7
+ export type AvScalarFormat = string;
6
8
  /** The projection positions a field can be selected in (at least one). */
7
- export type ProjectionScopes = readonly [ProjectionScope, ...ProjectionScope[]];
9
+ export type AvProjectionScopes = readonly [
10
+ AvProjectionScope,
11
+ ...AvProjectionScope[]
12
+ ];
8
13
  /**
9
14
  * The write positions a field can be written in (at least one). A scope list
10
- * applies to the top level of a write argument only; see {@link WriteScope}.
15
+ * applies to the top level of a write argument only; see {@link AvWriteScope}.
11
16
  */
12
- export type WriteScopes = readonly [WriteScope, ...WriteScope[]];
17
+ export type AvWriteScopes = readonly [AvWriteScope, ...AvWriteScope[]];
13
18
  /**
14
19
  * Whether a relation can be selected or included: `true`, or the projection
15
20
  * positions it can be used in.
16
21
  */
17
- export type RelationProjectionCapability = boolean | ProjectionScopes;
22
+ export type AvRelationProjectionCapability = boolean | AvProjectionScopes;
18
23
  /**
19
24
  * The reducers a relation admits, qualified by the projection positions they are
20
25
  * admitted in. The reducer list and the scope list are separate facts: `$count` is
21
26
  * one of a closed set of reducers, and the scopes say where the reducer may be
22
27
  * asked for.
23
28
  */
24
- export type ScopedRelationReducers = {
25
- readonly reducers: readonly RelationReducer[];
26
- readonly scopes: ProjectionScopes;
29
+ export type AvScopedRelationReducers = {
30
+ readonly reducers: readonly AvRelationReducer[];
31
+ readonly scopes: AvProjectionScopes;
27
32
  };
28
33
  /**
29
34
  * A relation's reducers: a reducer list, or an object with the reducers and
30
35
  * the projection positions they apply in.
31
36
  */
32
- export type RelationReducerCapability = readonly RelationReducer[] | ScopedRelationReducers;
37
+ export type AvRelationReducerCapability = readonly AvRelationReducer[] | AvScopedRelationReducers;
33
38
  /**
34
39
  * The mutation directives a relation admits at one write stage, and the write
35
40
  * positions they are admitted in. `directives: []` means writable with no
36
41
  * directive.
37
42
  */
38
- export type ScopedRelationMutations = {
39
- readonly directives: readonly RelationMutationDirective[];
40
- readonly scopes: WriteScopes;
43
+ export type AvScopedRelationMutations = {
44
+ readonly directives: readonly AvRelationMutationDirective[];
45
+ readonly scopes: AvWriteScopes;
41
46
  };
42
47
  /**
43
48
  * A relation's write capability for `create` or `update`: a directive list, or
44
49
  * an object with the directives and the write positions they apply in.
45
50
  */
46
- export type RelationMutationCapability = readonly RelationMutationDirective[] | ScopedRelationMutations;
51
+ export type AvRelationMutationCapability = readonly AvRelationMutationDirective[] | AvScopedRelationMutations;
47
52
  /** What can be done with a scalar field. Scalar capabilities apply in every position. */
48
- export type ScalarFieldCapabilities = {
53
+ export type AvScalarFieldCapabilities = {
49
54
  readonly select?: boolean;
50
- readonly filter?: readonly ScalarFilterOperator[];
55
+ readonly filter?: readonly AvScalarFilterOperator[];
51
56
  readonly order?: boolean;
52
57
  readonly orderNulls?: boolean;
53
- readonly create?: readonly ScalarMutationDirective[];
54
- readonly update?: readonly ScalarMutationDirective[];
58
+ readonly create?: readonly AvScalarMutationDirective[];
59
+ readonly update?: readonly AvScalarMutationDirective[];
55
60
  };
56
61
  /** What can be done with a relation field. */
57
- export type RelationFieldCapabilities = {
58
- readonly select?: RelationProjectionCapability;
59
- readonly include?: RelationProjectionCapability;
60
- readonly filter?: readonly RelationFilterCapability[];
62
+ export type AvRelationFieldCapabilities = {
63
+ readonly select?: AvRelationProjectionCapability;
64
+ readonly include?: AvRelationProjectionCapability;
65
+ readonly filter?: readonly AvRelationFilterCapability[];
61
66
  readonly order?: boolean;
62
- readonly pagination?: readonly PaginationCapability[];
63
- readonly reducers?: RelationReducerCapability;
64
- readonly create?: RelationMutationCapability;
65
- readonly update?: RelationMutationCapability;
67
+ readonly pagination?: readonly AvPaginationCapability[];
68
+ readonly reducers?: AvRelationReducerCapability;
69
+ readonly create?: AvRelationMutationCapability;
70
+ readonly update?: AvRelationMutationCapability;
71
+ /**
72
+ * What the `where` of a nested `$update` or `$delete` through this relation may
73
+ * filter: `"scalar"` means the target's scalar fields only, combined with
74
+ * `AND`/`OR`/`NOT`, and no relation filter at any depth. Absent: any filter the
75
+ * target takes.
76
+ */
77
+ readonly nestedWriteFilter?: "scalar";
66
78
  };
67
79
  /**
68
80
  * The reducers a relation advertises, in any projection position. Use
69
81
  * {@link advertisedReducersAt} for one position.
70
82
  */
71
- export declare function advertisedReducers(capability: RelationReducerCapability | undefined): readonly RelationReducer[] | undefined;
83
+ export declare function advertisedReducers(capability: AvRelationReducerCapability | undefined): readonly AvRelationReducer[] | undefined;
72
84
  /** Whether a projection capability holds at one projection position. */
73
- export declare function holdsAt(capability: RelationProjectionCapability | undefined, scope: ProjectionScope): boolean;
85
+ export declare function holdsAt(capability: AvRelationProjectionCapability | undefined, scope: AvProjectionScope): boolean;
74
86
  /**
75
87
  * Whether a projection capability holds in **any** projection position. Use
76
88
  * {@link holdsAt} when the position is known.
77
89
  */
78
- export declare function holdsInAnyScope(capability: RelationProjectionCapability | undefined): boolean;
90
+ export declare function holdsInAnyScope(capability: AvRelationProjectionCapability | undefined): boolean;
79
91
  /**
80
92
  * The reducers a relation advertises at one projection position, or
81
93
  * `undefined` where it has none there.
82
94
  */
83
- export declare function advertisedReducersAt(capability: RelationReducerCapability | undefined, scope: ProjectionScope): readonly RelationReducer[] | undefined;
95
+ export declare function advertisedReducersAt(capability: AvRelationReducerCapability | undefined, scope: AvProjectionScope): readonly AvRelationReducer[] | undefined;
84
96
  /**
85
97
  * The mutation directives a relation advertises at one write stage, in any
86
98
  * write position. `undefined` means the stage is unavailable; `[]` means
87
99
  * available with no directive.
88
100
  */
89
- export declare function advertisedDirectives(capability: RelationMutationCapability | undefined): readonly RelationMutationDirective[] | undefined;
101
+ export declare function advertisedDirectives(capability: AvRelationMutationCapability | undefined): readonly AvRelationMutationDirective[] | undefined;
90
102
  /**
91
103
  * The mutation directives a relation advertises at one write position, or
92
104
  * `undefined` where it is not writable there.
93
105
  */
94
- export declare function advertisedDirectivesAt(capability: RelationMutationCapability | undefined, scope: WriteScope): readonly RelationMutationDirective[] | undefined;
106
+ export declare function advertisedDirectivesAt(capability: AvRelationMutationCapability | undefined, scope: AvWriteScope): readonly AvRelationMutationDirective[] | undefined;
95
107
  /** A scalar field, including an enum-backed one. */
96
- export type ScalarField<C extends Contract> = {
108
+ export type AvScalarField<C extends AvContract> = {
97
109
  readonly kind: "scalar";
98
110
  readonly type: {
99
111
  readonly scalar: Extract<keyof C["scalars"], string>;
100
112
  } | {
101
113
  readonly enum: Extract<keyof C["enums"], string>;
102
114
  };
103
- readonly format?: ScalarFormat;
115
+ readonly format?: AvScalarFormat;
104
116
  readonly nullable: boolean;
105
117
  readonly list: boolean;
106
- readonly lifecycle: readonly LifecycleTrait[];
107
- readonly capabilities: ScalarFieldCapabilities;
118
+ readonly lifecycle: readonly AvLifecycleTrait[];
119
+ readonly capabilities: AvScalarFieldCapabilities;
120
+ /** A `json` field's shape, as JSON Schema: what every value written to it is. */
121
+ readonly json?: JsonSchema;
122
+ /**
123
+ * The field's validators: the root's checks, then the overlay's, in
124
+ * registration order. On a list field a check applies to each entry, except a
125
+ * `list: true` length check, which applies to the list.
126
+ */
127
+ readonly validators?: readonly AvFieldCheck[];
108
128
  };
109
129
  /** A relation field; the `target` Resource describes the related row. */
110
- export type RelationField<C extends Contract> = {
130
+ export type AvRelationField<C extends AvContract> = {
111
131
  readonly kind: "relation";
112
132
  readonly target: Extract<keyof C["resources"], string>;
113
133
  readonly cardinality: "one" | "many";
114
134
  readonly nullable: boolean;
115
- readonly capabilities: RelationFieldCapabilities;
135
+ readonly capabilities: AvRelationFieldCapabilities;
116
136
  };
117
137
  /** One field of a Resource: a scalar or a relation. */
118
- export type Field<C extends Contract> = ScalarField<C> | RelationField<C>;
138
+ export type AvField<C extends AvContract> = AvScalarField<C> | AvRelationField<C>;
@@ -1,7 +1,7 @@
1
- import type { Contract } from "./contract.js";
2
- import type { Field } from "./field.js";
1
+ import type { AvContract } from "./contract.js";
2
+ import type { AvField } from "./field.js";
3
3
  /** Keys of `TFields` whose field can be scalar-shaped. */
4
- export type ScalarFieldKey<TFields extends Readonly<Record<string, Field<Contract>>>> = Extract<{
4
+ export type AvScalarFieldKey<TFields extends Readonly<Record<string, AvField<AvContract>>>> = Extract<{
5
5
  [K in keyof TFields]: [
6
6
  Extract<TFields[K], {
7
7
  readonly kind: "scalar";
@@ -9,4 +9,4 @@ export type ScalarFieldKey<TFields extends Readonly<Record<string, Field<Contrac
9
9
  ] extends [never] ? never : K;
10
10
  }[keyof TFields], string>;
11
11
  /** Non-empty tuple of scalar field keys that identifies at most one Resource. */
12
- export type Identifier<TFields extends Readonly<Record<string, Field<Contract>>>> = readonly [ScalarFieldKey<TFields>, ...ScalarFieldKey<TFields>[]];
12
+ export type AvIdentifier<TFields extends Readonly<Record<string, AvField<AvContract>>>> = readonly [AvScalarFieldKey<TFields>, ...AvScalarFieldKey<TFields>[]];
@@ -0,0 +1,76 @@
1
+ import type { AvJsonListCheck, AvJsonNumberCheck, AvJsonStringCheck } from "./field-check.js";
2
+ /**
3
+ * The phantom key a Json Shape's TypeScript type travels under. Type-level only:
4
+ * no value ever holds it.
5
+ */
6
+ declare const jsonShapeValue: unique symbol;
7
+ /**
8
+ * A Json Shape, as the type system sees it: the TypeScript type `Value` of a
9
+ * value that conforms to it. `AvZ` builds every one; a value from anywhere else —
10
+ * a Zod schema included — is not one.
11
+ */
12
+ export interface JsonShape<Value = unknown> {
13
+ readonly [jsonShapeValue]: Value;
14
+ }
15
+ /** The TypeScript type a {@link JsonShape} describes. */
16
+ export type JsonShapeValue<Shape extends JsonShape> = Shape[typeof jsonShapeValue];
17
+ /** A JSON primitive: what a `const` names. */
18
+ export type JsonSchemaPrimitive = string | number | boolean | null;
19
+ /**
20
+ * A Json Shape in a Contract: passive JSON Schema (draft 2020-12), restricted to
21
+ * the forms Aventara emits.
22
+ */
23
+ export type JsonSchema = {
24
+ readonly type: "boolean" | "null";
25
+ } | {
26
+ readonly type: "string";
27
+ /** The node's checks, in the order they were added. */
28
+ readonly checks?: readonly AvJsonStringCheck[];
29
+ } | {
30
+ readonly type: "number" | "integer";
31
+ /** The node's checks, in the order they were added. */
32
+ readonly checks?: readonly AvJsonNumberCheck[];
33
+ } | {
34
+ readonly const: JsonSchemaPrimitive;
35
+ } | {
36
+ readonly type: "string";
37
+ readonly enum: readonly [string, ...string[]];
38
+ } | {
39
+ readonly type: "object";
40
+ readonly properties: {
41
+ readonly [key: string]: JsonSchema;
42
+ };
43
+ readonly required?: readonly string[];
44
+ readonly additionalProperties: false;
45
+ } | {
46
+ readonly type: "object";
47
+ readonly additionalProperties: JsonSchema;
48
+ } | {
49
+ readonly type: "array";
50
+ readonly items: JsonSchema;
51
+ /** The list's length checks, in the order they were added. */
52
+ readonly checks?: readonly AvJsonListCheck[];
53
+ } | {
54
+ readonly type: "array";
55
+ readonly prefixItems: readonly [JsonSchema, ...JsonSchema[]];
56
+ readonly items: false;
57
+ readonly minItems: number;
58
+ readonly maxItems: number;
59
+ } | {
60
+ readonly anyOf: readonly [JsonSchema, JsonSchema, ...JsonSchema[]];
61
+ } | {
62
+ readonly oneOf: readonly [JsonSchema, ...JsonSchema[]];
63
+ };
64
+ /**
65
+ * The type-level carrier of a shaped Json field's TypeScript type, on the field's
66
+ * `json` member in a typed Contract view. Never present at runtime.
67
+ */
68
+ export type JsonFieldType<Value> = {
69
+ readonly "~jsonType": Value;
70
+ };
71
+ /**
72
+ * A shaped Json field's `json` member in a typed Contract view: the schema, and
73
+ * the type it describes.
74
+ */
75
+ export type ShapedJsonSchema<Value> = JsonSchema & JsonFieldType<Value>;
76
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Where a field's value comes from, without saying whether it is writable:
3
3
  * `DEFAULTED` and `GENERATED_ON_*` by the data source, `COMPUTED_ON_*` by a
4
- * framework behavior; `VIRTUAL` marks a field that is not stored.
4
+ * compute stage; `VIRTUAL` marks a field that is not stored.
5
5
  */
6
6
  export declare const LIFECYCLE_TRAITS: readonly ["DEFAULTED", "GENERATED_ON_CREATE", "GENERATED_ON_UPDATE", "COMPUTED_ON_CREATE", "COMPUTED_ON_UPDATE", "COMPUTED_ON_READ", "VIRTUAL"];
7
7
  /** One of {@link LIFECYCLE_TRAITS}. */
8
- export type LifecycleTrait = (typeof LIFECYCLE_TRAITS)[number];
8
+ export type AvLifecycleTrait = (typeof LIFECYCLE_TRAITS)[number];
@@ -0,0 +1,7 @@
1
+ /** The limits a data source may put on how one record writes its references. */
2
+ export declare const REFERENCE_WRITE_LIMITS: readonly ["uniform"];
3
+ /**
4
+ * `"uniform"`: one record writes the relations that hold a reference either all
5
+ * as relations or all through their reference fields, never some each way.
6
+ */
7
+ export type ReferenceWriteLimit = (typeof REFERENCE_WRITE_LIMITS)[number];
@@ -0,0 +1 @@
1
+ export const REFERENCE_WRITE_LIMITS = ["uniform"];