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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/CHANGELOG.md +1140 -0
  2. package/README.md +224 -57
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +9 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -29
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/{json → avz}/avz.js +150 -8
  19. package/dist/{json → avz}/index.d.ts +2 -1
  20. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  21. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  22. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  23. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  24. package/dist/compiler/contract.compiler.d.ts +18 -18
  25. package/dist/compiler/contract.compiler.js +548 -441
  26. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  27. package/dist/compiler/create-requirements.projector.js +423 -0
  28. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  29. package/dist/compiler/field-validator.compiler.js +238 -0
  30. package/dist/config/any-framework-config.d.ts +19 -12
  31. package/dist/config/config-diagnostic.d.ts +11 -4
  32. package/dist/config/config-layer.d.ts +15 -6
  33. package/dist/config/config.resolver.d.ts +74 -31
  34. package/dist/config/config.resolver.js +108 -44
  35. package/dist/config/config.validator.d.ts +7 -7
  36. package/dist/config/config.validator.js +581 -72
  37. package/dist/config/define-resource.d.ts +57 -0
  38. package/dist/config/define-resource.js +14 -0
  39. package/dist/config/effective-fields.d.ts +19 -23
  40. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  41. package/dist/config/exact-framework-config.d.ts +280 -0
  42. package/dist/config/field-compute.resolver.d.ts +19 -0
  43. package/dist/config/field-compute.resolver.js +115 -0
  44. package/dist/config/field-pipeline-config.d.ts +47 -0
  45. package/dist/config/forced-operation.validator.d.ts +10 -0
  46. package/dist/config/forced-operation.validator.js +66 -0
  47. package/dist/config/framework-config.d.ts +110 -39
  48. package/dist/config/framework-exemptions-config.d.ts +91 -0
  49. package/dist/config/framework-exemptions-config.js +1 -0
  50. package/dist/config/framework-field-definition.d.ts +78 -0
  51. package/dist/config/framework-field-definition.js +28 -0
  52. package/dist/config/framework-resources-config.d.ts +116 -0
  53. package/dist/config/framework-resources-config.js +1 -0
  54. package/dist/config/pipeline-config.d.ts +56 -20
  55. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  56. package/dist/config/pipeline-tree.resolver.js +220 -0
  57. package/dist/config/stage-type.eraser.d.ts +65 -0
  58. package/dist/config/stage-type.eraser.js +1 -0
  59. package/dist/contracts/capability.d.ts +11 -11
  60. package/dist/contracts/client-contract-structure.validator.d.ts +323 -28
  61. package/dist/contracts/client-contract-structure.validator.js +152 -8
  62. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  63. package/dist/contracts/contract-canonicalizer.js +141 -28
  64. package/dist/contracts/contract-hash.d.ts +12 -7
  65. package/dist/contracts/contract-hash.js +3 -2
  66. package/dist/contracts/contract-limits.d.ts +4 -1
  67. package/dist/contracts/contract-limits.js +1 -0
  68. package/dist/contracts/contract-lookup.d.ts +5 -5
  69. package/dist/contracts/contract-protocol.d.ts +4 -4
  70. package/dist/contracts/contract.d.ts +24 -16
  71. package/dist/contracts/create-requirements.d.ts +35 -0
  72. package/dist/contracts/create-requirements.js +1 -0
  73. package/dist/contracts/enum-definition.d.ts +1 -1
  74. package/dist/contracts/field-check.d.ts +101 -0
  75. package/dist/contracts/field-check.js +1 -0
  76. package/dist/contracts/field.d.ts +52 -42
  77. package/dist/contracts/identifier.d.ts +4 -4
  78. package/dist/contracts/json-shape.d.ts +12 -1
  79. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  80. package/dist/contracts/resource-operations.d.ts +28 -28
  81. package/dist/contracts/resource.d.ts +15 -9
  82. package/dist/contracts/scalar-value-type.d.ts +15 -15
  83. package/dist/contracts/scalar.d.ts +3 -3
  84. package/dist/contracts/transaction-capability.d.ts +1 -1
  85. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  86. package/dist/framework/contract-view.d.ts +213 -147
  87. package/dist/framework/framework-construction.error.d.ts +10 -10
  88. package/dist/framework/framework-construction.error.js +2 -2
  89. package/dist/framework/framework.d.ts +47 -23
  90. package/dist/framework/framework.factory.d.ts +8 -6
  91. package/dist/framework/framework.factory.js +40 -20
  92. package/dist/framework/operation-facade.d.ts +123 -52
  93. package/dist/framework/operation-facade.js +9 -1
  94. package/dist/index.d.ts +55 -50
  95. package/dist/index.js +6 -6
  96. package/dist/internal.d.ts +15 -10
  97. package/dist/internal.js +3 -1
  98. package/dist/operations/operation-arguments.d.ts +267 -202
  99. package/dist/operations/operation-call.d.ts +27 -28
  100. package/dist/operations/operation-identity.d.ts +10 -10
  101. package/dist/operations/operation-result.d.ts +21 -21
  102. package/dist/operations/operation-validator-core.d.ts +6 -6
  103. package/dist/operations/operation-validator-core.js +13 -2
  104. package/dist/operations/operation-validator.d.ts +9 -9
  105. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  106. package/dist/operations/structural-limits.walker.d.ts +6 -6
  107. package/dist/operations/structural-limits.walker.js +145 -0
  108. package/dist/operations/validation-code.d.ts +11 -6
  109. package/dist/operations/validation-code.js +4 -0
  110. package/dist/operations/write-scope.resolver.d.ts +6 -6
  111. package/dist/protocol/absent-route.responder.d.ts +13 -12
  112. package/dist/protocol/absent-route.responder.js +19 -19
  113. package/dist/protocol/contract-document.responder.d.ts +3 -3
  114. package/dist/protocol/contract-document.responder.js +2 -2
  115. package/dist/protocol/http-request.decoder.d.ts +17 -13
  116. package/dist/protocol/http-request.decoder.js +10 -10
  117. package/dist/protocol/http-request.reader.d.ts +3 -3
  118. package/dist/protocol/http-response.encoder.d.ts +4 -4
  119. package/dist/protocol/http-response.encoder.js +94 -55
  120. package/dist/protocol/http-status.table.d.ts +2 -2
  121. package/dist/protocol/operation-response.guard.d.ts +2 -2
  122. package/dist/protocol/protocol-surface.d.ts +4 -4
  123. package/dist/protocol/protocol.binder.d.ts +50 -27
  124. package/dist/protocol/protocol.binder.js +12 -9
  125. package/dist/protocol/protocol.handler.d.ts +22 -13
  126. package/dist/protocol/protocol.handler.js +44 -9
  127. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  128. package/dist/protocol/unmounted-route.error.js +2 -2
  129. package/dist/runtime/caller-data.copier.d.ts +5 -5
  130. package/dist/runtime/caller-data.copier.js +13 -13
  131. package/dist/runtime/caller-data.door.d.ts +6 -6
  132. package/dist/runtime/caller-data.door.js +6 -4
  133. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  134. package/dist/runtime/computed-read-runtime.js +61 -48
  135. package/dist/runtime/computed-value.error.d.ts +6 -6
  136. package/dist/runtime/computed-value.error.js +3 -3
  137. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  138. package/dist/runtime/context-executor.runtime.js +275 -0
  139. package/dist/runtime/create-requirement.d.ts +10 -81
  140. package/dist/runtime/create-requirement.js +80 -57
  141. package/dist/runtime/decimal.d.ts +2 -2
  142. package/dist/runtime/decimal.js +1 -1
  143. package/dist/runtime/diagnostics-reporter.d.ts +53 -27
  144. package/dist/runtime/diagnostics-reporter.js +24 -0
  145. package/dist/runtime/error-boundary.d.ts +65 -8
  146. package/dist/runtime/error-boundary.js +45 -19
  147. package/dist/runtime/execution-options.d.ts +10 -2
  148. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  149. package/dist/runtime/field-check.evaluator.js +521 -0
  150. package/dist/runtime/field-compute.d.ts +64 -0
  151. package/dist/runtime/field-compute.js +1 -0
  152. package/dist/runtime/field-stage.plan.d.ts +15 -0
  153. package/dist/runtime/field-stage.plan.js +27 -0
  154. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  155. package/dist/runtime/field-stage.runtime.js +143 -0
  156. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  157. package/dist/runtime/field-validator.runtime.js +87 -0
  158. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  159. package/dist/runtime/framework-error-class.table.js +25 -0
  160. package/dist/runtime/framework-error.d.ts +68 -8
  161. package/dist/runtime/framework-error.factory.d.ts +4 -0
  162. package/dist/runtime/framework-error.factory.js +15 -0
  163. package/dist/runtime/framework-error.js +23 -2
  164. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  165. package/dist/runtime/interceptor-next.error.js +6 -0
  166. package/dist/runtime/json-value.d.ts +3 -3
  167. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  168. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  169. package/dist/runtime/misuse-reporter.d.ts +12 -12
  170. package/dist/runtime/mutation-planner.d.ts +19 -10
  171. package/dist/runtime/mutation-planner.js +54 -30
  172. package/dist/runtime/nested-write.walker.d.ts +32 -0
  173. package/dist/runtime/nested-write.walker.js +73 -0
  174. package/dist/runtime/operation-request.d.ts +33 -6
  175. package/dist/runtime/operation-response.d.ts +17 -17
  176. package/dist/runtime/operation-runtime.d.ts +113 -25
  177. package/dist/runtime/operation-runtime.js +395 -74
  178. package/dist/runtime/outcome-mapper.d.ts +16 -5
  179. package/dist/runtime/outcome-mapper.js +23 -6
  180. package/dist/runtime/output-validator.d.ts +10 -10
  181. package/dist/runtime/output-validator.js +3 -3
  182. package/dist/runtime/owned-execution.registry.d.ts +6 -6
  183. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  184. package/dist/runtime/pipe-output.validator.js +12 -12
  185. package/dist/runtime/pipeline.d.ts +196 -34
  186. package/dist/runtime/readonly-value.d.ts +32 -0
  187. package/dist/runtime/readonly-value.js +141 -0
  188. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  189. package/dist/runtime/request-envelope.validator.js +12 -7
  190. package/dist/runtime/request-id.d.ts +1 -1
  191. package/dist/runtime/request-state.d.ts +14 -0
  192. package/dist/runtime/request-state.js +1 -0
  193. package/dist/runtime/request-state.resolver.d.ts +12 -0
  194. package/dist/runtime/request-state.resolver.js +20 -0
  195. package/dist/runtime/scalar-runtime.d.ts +31 -16
  196. package/dist/runtime/scalar-runtime.js +16 -18
  197. package/dist/transactions/deferred-operation.d.ts +35 -20
  198. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  199. package/dist/transactions/operation-arguments-encoder.js +2 -2
  200. package/dist/transactions/sql-statement.d.ts +77 -0
  201. package/dist/transactions/sql-statement.js +47 -0
  202. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  203. package/dist/transactions/sql-statement.validator.js +134 -0
  204. package/dist/transactions/transaction-envelope.d.ts +4 -4
  205. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  206. package/dist/transactions/transaction-integrity-error.js +5 -2
  207. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  208. package/dist/transactions/transaction-plan-assembler.js +148 -34
  209. package/dist/transactions/transaction-plan-validator.d.ts +29 -20
  210. package/dist/transactions/transaction-plan-validator.js +70 -38
  211. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  212. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  213. package/dist/transactions/transaction-reference-resolver.js +26 -14
  214. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  215. package/dist/transactions/transaction-reference-validator.js +58 -26
  216. package/dist/transactions/transaction-reference.d.ts +13 -13
  217. package/dist/transactions/transaction-request.d.ts +18 -5
  218. package/dist/transactions/transaction-response.d.ts +6 -6
  219. package/dist/transactions/transaction-runtime.d.ts +8 -7
  220. package/dist/transactions/transaction-runtime.js +166 -50
  221. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  222. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  223. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  224. package/dist/transactions/transaction-slot-path-error.js +2 -2
  225. package/dist/transactions/transaction-slot-writer.js +2 -2
  226. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  227. package/dist/transactions/transaction-stage.runtime.js +123 -0
  228. package/package.json +6 -5
  229. package/src/runtime/field-check.evaluator.ts +720 -0
  230. package/dist/config/define-fields.d.ts +0 -42
  231. package/dist/config/define-fields.js +0 -3
  232. package/dist/config/framework-behaviors-config.d.ts +0 -30
  233. package/dist/config/framework-fields-config.d.ts +0 -42
  234. package/dist/config/framework-restrictions-config.d.ts +0 -142
  235. package/dist/json/avz.d.ts +0 -96
  236. package/dist/runtime/field-behavior.d.ts +0 -48
  237. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  238. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  239. /package/dist/{json → avz}/index.js +0 -0
  240. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  241. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  242. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,12 +1,14 @@
1
- import type { Contract } from "../contracts/contract.js";
1
+ import type { AvContract } from "../contracts/contract.js";
2
2
  import type { ScalarForms } from "../contracts/scalar-value-type.js";
3
- import type { OperationResponse } from "../runtime/operation-response.js";
4
- import type { Operation } from "../transactions/deferred-operation.js";
3
+ import type { AvOperation } from "../transactions/deferred-operation.js";
5
4
  import type { ReferenceableArgumentsFor } from "../transactions/transaction-reference.js";
6
- import type { OperationArgumentsFor, ResourceKey } from "./operation-arguments.js";
7
- import type { OperationFamily, OperationIdentity, OperationVariant } from "./operation-identity.js";
5
+ import type { AvOperationArgumentsFor, AvResourceKey } from "./operation-arguments.js";
6
+ import type { AvOperationFamily, AvOperationIdentity, AvOperationVariant } from "./operation-identity.js";
8
7
  import type { AdmittedOperationResult } from "./operation-result.js";
9
8
  type ProjectionKey = "select" | "include";
9
+ /** The origin of a deferred handle's builder (`AvOperationHandle`). */
10
+ type HandleOrigin = "application" | "client";
11
+ type AnyOrigin = any;
10
12
  type SelectOf<Args> = Args extends {
11
13
  readonly select?: infer Select;
12
14
  } ? Exclude<Select, undefined> : never;
@@ -30,15 +32,15 @@ type InferredProjection<Select, Include> = [Select] extends [never] ? [Include]
30
32
  type ArgumentList<Rest, Parameter> = Record<never, never> extends Rest ? [args?: Parameter] : [args: Parameter];
31
33
  /** A direct call's parameters: the argument, then the caller's per-call options. */
32
34
  type CallArgumentList<Rest, Parameter, Options> = Record<never, never> extends Rest ? [args?: Parameter, options?: Options] : [args: Parameter, options?: Options];
33
- type ResourceOperationsOf<C extends Contract, R extends ResourceKey<C>> = C["resources"][R]["operations"];
35
+ type ResourceOperationsOf<C extends AvContract, R extends AvResourceKey<C>> = C["resources"][R]["operations"];
34
36
  /**
35
37
  * The operations Contract `C` advertises: one property per Resource, one per
36
38
  * family under it, one identity per variant under that.
37
39
  */
38
- export type OperationGrammar<C extends Contract> = {
39
- readonly [R in ResourceKey<C>]: {
40
- readonly [F in Extract<keyof ResourceOperationsOf<C, R>, OperationFamily>]: {
41
- readonly [V in Extract<keyof NonNullable<ResourceOperationsOf<C, R>[F]>, OperationVariant<F>>]: Extract<OperationIdentity, {
40
+ export type AvOperationGrammar<C extends AvContract> = {
41
+ readonly [R in AvResourceKey<C>]: {
42
+ readonly [F in Extract<keyof ResourceOperationsOf<C, R>, AvOperationFamily>]: {
43
+ readonly [V in Extract<keyof NonNullable<ResourceOperationsOf<C, R>[F]>, AvOperationVariant<F>>]: Extract<AvOperationIdentity, {
42
44
  readonly family: F;
43
45
  readonly variant: V;
44
46
  }>;
@@ -50,33 +52,30 @@ export type OperationGrammar<C extends Contract> = {
50
52
  * This is the value a committed transaction or a remote call returns for the
51
53
  * operation.
52
54
  */
53
- export type OperationSlot<I extends OperationIdentity, Result> = I["variant"] extends "first" ? Result | null : Result;
54
- /**
55
- * What a direct call resolves, by its `Settlement`: `"response"` — the whole
56
- * `OperationResponse`, as core's façades answer in process, never throwing;
57
- * `"data"` — the slot, as a remote client answers, every failure thrown.
58
- */
59
- type Settled<Settlement extends "response" | "data", I extends OperationIdentity, Result> = Settlement extends "data" ? OperationSlot<I, Result> : OperationResponse<Result>;
60
- type ProjectingCall<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Args, ResultForms extends ScalarForms, Settlement extends "response" | "data", Options> = <const Select extends SelectOf<Args> = never, const Include extends IncludeOf<Args> = never>(...args: CallArgumentList<Omit<Args, ProjectionKey>, Omit<Args, ProjectionKey> & ProjectionArgument<Select, Include>, Options>) => Promise<Settled<Settlement, I, AdmittedOperationResult<C, R, I, InferredProjection<Select, Include>, ResultForms>>>;
61
- type PlainCall<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Args, ResultForms extends ScalarForms, Settlement extends "response" | "data", Options> = (...args: CallArgumentList<Args, Args, Options>) => Promise<Settled<Settlement, I, AdmittedOperationResult<C, R, I, unknown, ResultForms>>>;
55
+ export type AvOperationSlot<I extends AvOperationIdentity, Result> = I["variant"] extends "first" ? Result | null : Result;
56
+ /** What a direct call resolves: the slot, every failure thrown. */
57
+ type Settled<I extends AvOperationIdentity, Result> = AvOperationSlot<I, Result>;
58
+ type ProjectingCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Args, ResultForms extends ScalarForms, Options> = <const Select extends SelectOf<Args> = never, const Include extends IncludeOf<Args> = never>(...args: CallArgumentList<Omit<Args, ProjectionKey>, Omit<Args, ProjectionKey> & ProjectionArgument<Select, Include>, Options>) => Promise<Settled<I, AdmittedOperationResult<C, R, I, InferredProjection<Select, Include>, ResultForms>>>;
59
+ type PlainCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Args, ResultForms extends ScalarForms, Options> = (...args: CallArgumentList<Args, Args, Options>) => Promise<Settled<I, AdmittedOperationResult<C, R, I, unknown, ResultForms>>>;
62
60
  /**
63
61
  * One direct call: its arguments in `Forms`, its result in `ResultForms`,
64
- * resolving as `Settlement` says, taking `Options` per call — generic in its
62
+ * resolving the slot and throwing every failure, taking `Options` per call. It is generic in its
65
63
  * projection when it carries one.
66
64
  */
67
- export type OperationCall<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Forms extends ScalarForms, ResultForms extends ScalarForms, Settlement extends "response" | "data", Options> = "select" extends keyof OperationArgumentsFor<C, R, I, Forms> ? ProjectingCall<C, R, I, OperationArgumentsFor<C, R, I, Forms>, ResultForms, Settlement, Options> : PlainCall<C, R, I, OperationArgumentsFor<C, R, I, Forms>, ResultForms, Settlement, Options>;
65
+ export type AvOperationCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Forms extends ScalarForms, ResultForms extends ScalarForms, Options> = "select" extends keyof AvOperationArgumentsFor<C, R, I, Forms> ? ProjectingCall<C, R, I, AvOperationArgumentsFor<C, R, I, Forms>, ResultForms, Options> : PlainCall<C, R, I, AvOperationArgumentsFor<C, R, I, Forms>, ResultForms, Options>;
68
66
  /**
69
67
  * A deferred operation's arguments: `Forms`, with reference positions opened to a
70
68
  * `$ref` typed in `ResultForms` — the forms the source's final data is read in, so a
71
69
  * reference carries what its source resolves.
72
70
  */
73
- type DeferredArguments<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Forms extends ScalarForms, ResultForms extends ScalarForms> = ReferenceableArgumentsFor<C, R, I, Forms, ResultForms>;
74
- type DeferredProjectingCall<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Args, ResultForms extends ScalarForms> = <const Select extends SelectOf<Args> = never, const Include extends IncludeOf<Args> = never>(...args: ArgumentList<Omit<Args, ProjectionKey>, Omit<Args, ProjectionKey> & ProjectionArgument<Select, Include>>) => Operation<OperationSlot<I, AdmittedOperationResult<C, R, I, InferredProjection<Select, Include>, ResultForms>>>;
75
- type DeferredPlainCall<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Args, ResultForms extends ScalarForms> = (...args: ArgumentList<Args, Args>) => Operation<OperationSlot<I, AdmittedOperationResult<C, R, I, unknown, ResultForms>>>;
71
+ type DeferredArguments<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Forms extends ScalarForms, ResultForms extends ScalarForms> = ReferenceableArgumentsFor<C, R, I, Forms, ResultForms>;
72
+ type DeferredProjectingCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Args, ResultForms extends ScalarForms, Origin extends HandleOrigin> = <const Select extends SelectOf<Args> = never, const Include extends IncludeOf<Args> = never>(...args: ArgumentList<Omit<Args, ProjectionKey>, Omit<Args, ProjectionKey> & ProjectionArgument<Select, Include>>) => AvOperation<AvOperationSlot<I, AdmittedOperationResult<C, R, I, InferredProjection<Select, Include>, ResultForms>>, Origin>;
73
+ type DeferredPlainCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Args, ResultForms extends ScalarForms, Origin extends HandleOrigin> = (...args: ArgumentList<Args, Args>) => AvOperation<AvOperationSlot<I, AdmittedOperationResult<C, R, I, unknown, ResultForms>>, Origin>;
76
74
  /**
77
- * One deferred operation: a handle typed `Operation<OperationSlot<…>>` — `$ref`
78
- * present exactly where the result is one row. A handle is not a request and takes no
79
- * options.
75
+ * One deferred operation: a handle typed `AvOperation<AvOperationSlot<…>, Origin>`,
76
+ * with `$ref` present exactly where the result is one row. A handle is not a
77
+ * request and takes no options. `Origin` is the builder's: a transaction's
78
+ * handles all share one.
80
79
  */
81
- export type DeferredOperationCall<C extends Contract, R extends ResourceKey<C>, I extends OperationIdentity, Forms extends ScalarForms, ResultForms extends ScalarForms> = "select" extends keyof DeferredArguments<C, R, I, Forms, ResultForms> ? DeferredProjectingCall<C, R, I, DeferredArguments<C, R, I, Forms, ResultForms>, ResultForms> : DeferredPlainCall<C, R, I, DeferredArguments<C, R, I, Forms, ResultForms>, ResultForms>;
80
+ export type AvDeferredOperationCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, Forms extends ScalarForms, ResultForms extends ScalarForms, Origin extends HandleOrigin = AnyOrigin> = "select" extends keyof DeferredArguments<C, R, I, Forms, ResultForms> ? DeferredProjectingCall<C, R, I, DeferredArguments<C, R, I, Forms, ResultForms>, ResultForms, Origin> : DeferredPlainCall<C, R, I, DeferredArguments<C, R, I, Forms, ResultForms>, ResultForms, Origin>;
82
81
  export {};
@@ -1,18 +1,18 @@
1
- import type { ResourceOperations } from "../contracts/resource-operations.js";
1
+ import type { AvResourceOperations } from "../contracts/resource-operations.js";
2
2
  /** A standard operation family: `find`, `create`, `update`, `delete` or `upsert`. */
3
- export type OperationFamily = Extract<keyof ResourceOperations, string>;
3
+ export type AvOperationFamily = Extract<keyof AvResourceOperations, string>;
4
4
  /** The variants of operation family `F`, such as `many` or `unique`. */
5
- export type OperationVariant<F extends OperationFamily> = Extract<keyof NonNullable<ResourceOperations[F]>, string>;
5
+ export type AvOperationVariant<F extends AvOperationFamily> = Extract<keyof NonNullable<AvResourceOperations[F]>, string>;
6
6
  /** A standard operation's `family` and `variant`. */
7
- export type OperationIdentity = {
8
- [F in OperationFamily]: {
9
- [V in OperationVariant<F>]: {
7
+ export type AvOperationIdentity = {
8
+ [F in AvOperationFamily]: {
9
+ [V in AvOperationVariant<F>]: {
10
10
  readonly family: F;
11
11
  readonly variant: V;
12
12
  };
13
- }[OperationVariant<F>];
14
- }[OperationFamily];
15
- /** Parses a family and variant into an {@link OperationIdentity}, or `undefined` when they name no standard operation. */
16
- export declare function parseOperationIdentity(family: string, variant: string): OperationIdentity | undefined;
13
+ }[AvOperationVariant<F>];
14
+ }[AvOperationFamily];
15
+ /** Parses a family and variant into an {@link AvOperationIdentity}, or `undefined` when they name no standard operation. */
16
+ export declare function parseOperationIdentity(family: string, variant: string): AvOperationIdentity | undefined;
17
17
  /** Whether `family` names one of the standard operation families. */
18
18
  export declare function isOperationFamily(family: string): boolean;
@@ -1,21 +1,21 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import type { RelationField, ScalarField } from "../contracts/field.js";
3
- import type { ApplicationScalarForms, ScalarForms, ScalarValueType } from "../contracts/scalar-value-type.js";
4
- import type { FieldKey, OperationArgumentsFor, ResourceKey } from "./operation-arguments.js";
5
- import type { OperationIdentity } from "./operation-identity.js";
6
- type FieldOf<C extends Contract, K extends ResourceKey<C>, F extends FieldKey<C, K>> = C["resources"][K]["fields"][F];
1
+ import type { AvContract } from "../contracts/contract.js";
2
+ import type { AvRelationField, AvScalarField } from "../contracts/field.js";
3
+ import type { AvApplicationScalarForms, AvScalarValueType, ScalarForms } from "../contracts/scalar-value-type.js";
4
+ import type { AvFieldKey, AvOperationArgumentsFor, AvResourceKey } from "./operation-arguments.js";
5
+ import type { AvOperationIdentity } from "./operation-identity.js";
6
+ type FieldOf<C extends AvContract, K extends AvResourceKey<C>, F extends AvFieldKey<C, K>> = C["resources"][K]["fields"][F];
7
7
  /**
8
8
  * The fields returned when no projection is given: the scalars whose `select`
9
9
  * is exactly `true`. A write-only field never appears.
10
10
  */
11
- type DefaultKey<C extends Contract, K extends ResourceKey<C>> = {
12
- [F in FieldKey<C, K>]: FieldOf<C, K, F> extends {
11
+ type DefaultKey<C extends AvContract, K extends AvResourceKey<C>> = {
12
+ [F in AvFieldKey<C, K>]: FieldOf<C, K, F> extends {
13
13
  readonly kind: "scalar";
14
14
  readonly capabilities: {
15
15
  readonly select: true;
16
16
  };
17
17
  } ? F : never;
18
- }[FieldKey<C, K>];
18
+ }[AvFieldKey<C, K>];
19
19
  /** The field one projection entry names: a bare key, or a relation entry's key. */
20
20
  type EntryKey<Entry> = Entry extends string ? Entry : Entry extends object ? Extract<keyof Entry, string> : never;
21
21
  /**
@@ -31,26 +31,26 @@ type EntryArguments<Entry, F extends string> = Entry extends object ? Entry exte
31
31
  * `Entries` carries the relation entries' own arguments down; the scalar branch
32
32
  * ignores them.
33
33
  */
34
- type ProjectedFields<C extends Contract, K extends ResourceKey<C>, Keys extends FieldKey<C, K>, Entries, Forms extends ScalarForms> = {
35
- readonly [F in Keys]: FieldOf<C, K, F> extends ScalarField<C> ? ScalarValueType<C, FieldOf<C, K, F>, Forms> : FieldOf<C, K, F> extends RelationField<C> ? RelationResult<C, Extract<FieldOf<C, K, F>["target"], ResourceKey<C>>, FieldOf<C, K, F>, EntryArguments<Entries, F>, Forms> : never;
34
+ type ProjectedFields<C extends AvContract, K extends AvResourceKey<C>, Keys extends AvFieldKey<C, K>, Entries, Forms extends ScalarForms> = {
35
+ readonly [F in Keys]: FieldOf<C, K, F> extends AvScalarField<C> ? AvScalarValueType<C, FieldOf<C, K, F>, Forms> : FieldOf<C, K, F> extends AvRelationField<C> ? RelationResult<C, Extract<FieldOf<C, K, F>["target"], AvResourceKey<C>>, FieldOf<C, K, F>, EntryArguments<Entries, F>, Forms> : never;
36
36
  };
37
37
  /**
38
38
  * One projection level: `select` returns exactly its entries, `include` the
39
39
  * default fields plus the named relations, and no projection the default fields.
40
40
  */
41
- type ProjectedRecord<C extends Contract, K extends ResourceKey<C>, Arguments, Forms extends ScalarForms> = [Arguments] extends [never] ? ProjectedFields<C, K, DefaultKey<C, K>, never, Forms> : [Arguments] extends [{
41
+ type ProjectedRecord<C extends AvContract, K extends AvResourceKey<C>, Arguments, Forms extends ScalarForms> = [Arguments] extends [never] ? ProjectedFields<C, K, DefaultKey<C, K>, never, Forms> : [Arguments] extends [{
42
42
  readonly select: readonly (infer Entry)[];
43
- }] ? ProjectedFields<C, K, Extract<EntryKey<Entry>, FieldKey<C, K>>, Entry, Forms> : [Arguments] extends [{
43
+ }] ? ProjectedFields<C, K, Extract<EntryKey<Entry>, AvFieldKey<C, K>>, Entry, Forms> : [Arguments] extends [{
44
44
  readonly include: readonly (infer Entry)[];
45
- }] ? ProjectedFields<C, K, DefaultKey<C, K> | Extract<EntryKey<Entry>, FieldKey<C, K>>, Entry, Forms> : ProjectedFields<C, K, DefaultKey<C, K>, never, Forms>;
45
+ }] ? ProjectedFields<C, K, DefaultKey<C, K> | Extract<EntryKey<Entry>, AvFieldKey<C, K>>, Entry, Forms> : ProjectedFields<C, K, DefaultKey<C, K>, never, Forms>;
46
46
  /**
47
47
  * A to-many entry whose `select` asks for `$count`: the value is an object with
48
48
  * the rows and the count, not the row array.
49
49
  */
50
- type CountEnvelope<C extends Contract, Target extends ResourceKey<C>, Entry, Forms extends ScalarForms> = [Exclude<Entry, "$count">] extends [never] ? {
50
+ type CountEnvelope<C extends AvContract, Target extends AvResourceKey<C>, Entry, Forms extends ScalarForms> = [Exclude<Entry, "$count">] extends [never] ? {
51
51
  readonly count: number;
52
52
  } : {
53
- readonly data: readonly ProjectedFields<C, Target, Extract<EntryKey<Entry>, FieldKey<C, Target>>, Exclude<Entry, "$count">, Forms>[];
53
+ readonly data: readonly ProjectedFields<C, Target, Extract<EntryKey<Entry>, AvFieldKey<C, Target>>, Exclude<Entry, "$count">, Forms>[];
54
54
  readonly count: number;
55
55
  };
56
56
  /** The entries of an argument's own `select`, or `never` when it has none. */
@@ -61,16 +61,16 @@ type SelectEntry<Arguments> = Arguments extends {
61
61
  * The value of one relation entry. A to-many entry is the rows-and-count object
62
62
  * when its own `select` asks for `$count`; otherwise the row array.
63
63
  */
64
- type RelationResult<C extends Contract, Target extends ResourceKey<C>, Relation extends RelationField<C>, Arguments, Forms extends ScalarForms> = Relation["cardinality"] extends "many" ? [Extract<SelectEntry<Arguments>, "$count">] extends [never] ? readonly ProjectedRecord<C, Target, Arguments, Forms>[] : CountEnvelope<C, Target, SelectEntry<Arguments>, Forms> : ProjectedRecord<C, Target, Arguments, Forms> | (true extends Relation["nullable"] ? null : never);
64
+ type RelationResult<C extends AvContract, Target extends AvResourceKey<C>, Relation extends AvRelationField<C>, Arguments, Forms extends ScalarForms> = Relation["cardinality"] extends "many" ? [Extract<SelectEntry<Arguments>, "$count">] extends [never] ? readonly ProjectedRecord<C, Target, Arguments, Forms>[] : CountEnvelope<C, Target, SelectEntry<Arguments>, Forms> : ProjectedRecord<C, Target, Arguments, Forms> | (true extends Relation["nullable"] ? null : never);
65
65
  /**
66
- * The value a standard operation returns in `OperationResponse.data` on success,
66
+ * The value a standard operation returns in `AvOperationResponse.data` on success,
67
67
  * derived from the Contract, the Resource, the operation identity and the projection
68
68
  * argument.
69
69
  */
70
- export type OperationResultFor<C extends Contract, K extends ResourceKey<C>, I extends OperationIdentity, Args extends OperationArgumentsFor<C, K, I>, Forms extends ScalarForms = ApplicationScalarForms> = AdmittedOperationResult<C, K, I, Args, Forms>;
70
+ export type AvOperationResultFor<C extends AvContract, K extends AvResourceKey<C>, I extends AvOperationIdentity, Args extends AvOperationArgumentsFor<C, K, I>, Forms extends ScalarForms = AvApplicationScalarForms> = AdmittedOperationResult<C, K, I, Args, Forms>;
71
71
  /**
72
- * {@link OperationResultFor}, for a projection already checked against the
72
+ * {@link AvOperationResultFor}, for a projection already checked against the
73
73
  * operation's argument type.
74
74
  */
75
- export type AdmittedOperationResult<C extends Contract, K extends ResourceKey<C>, I extends OperationIdentity, Args, Forms extends ScalarForms = ApplicationScalarForms> = I["variant"] extends "count" ? number : I["variant"] extends "many" ? readonly ProjectedRecord<C, K, Args, Forms>[] : ProjectedRecord<C, K, Args, Forms>;
75
+ export type AdmittedOperationResult<C extends AvContract, K extends AvResourceKey<C>, I extends AvOperationIdentity, Args, Forms extends ScalarForms = AvApplicationScalarForms> = I["variant"] extends "count" ? number : I["variant"] extends "many" ? readonly ProjectedRecord<C, K, Args, Forms>[] : ProjectedRecord<C, K, Args, Forms>;
76
76
  export {};
@@ -1,6 +1,6 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import { type OperationIdentity } from "./operation-identity.js";
3
- import type { ValidationIssue } from "./validation-code.js";
1
+ import type { AvContract } from "../contracts/contract.js";
2
+ import { type AvOperationIdentity } from "./operation-identity.js";
3
+ import type { AvValidationIssue } from "./validation-code.js";
4
4
  /** An operation's arguments as an object, before validation. */
5
5
  export type SemanticOperationArguments = Readonly<Record<string, unknown>>;
6
6
  type OperationValidationSuccess = {
@@ -9,7 +9,7 @@ type OperationValidationSuccess = {
9
9
  };
10
10
  type OperationValidationFailure = {
11
11
  readonly ok: false;
12
- readonly issues: readonly ValidationIssue[];
12
+ readonly issues: readonly AvValidationIssue[];
13
13
  };
14
14
  /** The answer of {@link validateOperationArguments}: success, or the issues found. */
15
15
  export type OperationValidationResult = OperationValidationSuccess | OperationValidationFailure;
@@ -21,8 +21,8 @@ export type OperationValidationOptions = {
21
21
  * Contract does not have (`V1005` at `["resource"]`, rolling up to `A2001`). The one
22
22
  * spelling — the protocol's absence answers build theirs with it.
23
23
  */
24
- export declare function resourceUnavailableIssue(resource: string): ValidationIssue;
25
- export declare function validateOperationArguments(contract: Contract, request: OperationIdentity & {
24
+ export declare function resourceUnavailableIssue(resource: string): AvValidationIssue;
25
+ export declare function validateOperationArguments(contract: AvContract, request: AvOperationIdentity & {
26
26
  readonly resource: string;
27
27
  readonly arguments: unknown;
28
28
  }, options?: OperationValidationOptions): OperationValidationResult;
@@ -153,12 +153,15 @@ function checkDepth(contract, state, depth) {
153
153
  }
154
154
  return false;
155
155
  }
156
- function validateScalarFilter(fieldName, field, value, path, state) {
156
+ function validateScalarFilter(contract, fieldName, field, value, path, state, depth) {
157
157
  const supported = field.capabilities.filter;
158
158
  if (supported === undefined) {
159
159
  addIssue(state.issues, "V1006", path, `Filtering is not available on field "${fieldName}".`);
160
160
  return;
161
161
  }
162
+ validateScalarCondition(contract, fieldName, field, supported, value, path, state, depth);
163
+ }
164
+ function validateScalarCondition(contract, fieldName, field, supported, value, path, state, depth) {
162
165
  if (value === null) {
163
166
  if (!field.nullable) {
164
167
  addIssue(state.issues, "V1001", path, `Field "${fieldName}" is not nullable.`);
@@ -190,6 +193,14 @@ function validateScalarFilter(fieldName, field, value, path, state) {
190
193
  for (const operator of operators) {
191
194
  if (!includes(supported, operator)) {
192
195
  addIssue(state.issues, "V1006", [...path, operator], `Filter operator "${operator}" is not available on field "${fieldName}".`);
196
+ continue;
197
+ }
198
+ if (operator === "not") {
199
+ const operand = value[operator];
200
+ if (isPlainRecord(operand) && !checkDepth(contract, state, depth + 1)) {
201
+ continue;
202
+ }
203
+ validateScalarCondition(contract, fieldName, field, supported, operand, [...path, operator], state, isPlainRecord(operand) ? depth + 1 : depth);
193
204
  }
194
205
  }
195
206
  }
@@ -276,7 +287,7 @@ function validateWhere(contract, resourceName, where, path, state, depth) {
276
287
  }
277
288
  const fieldPath = [...path, key];
278
289
  if (field.kind === "scalar") {
279
- validateScalarFilter(key, field, value, fieldPath, state);
290
+ validateScalarFilter(contract, key, field, value, fieldPath, state, depth);
280
291
  }
281
292
  else if (state.scalarOnly === true) {
282
293
  addIssue(state.issues, "V1006", fieldPath, `Relation filter "${key}" is not available here: a nested $update or $delete filter on this relation takes scalar fields only.`);
@@ -1,10 +1,10 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import { type OperationIdentity } from "./operation-identity.js";
1
+ import type { AvContract } from "../contracts/contract.js";
2
+ import { type AvOperationIdentity } from "./operation-identity.js";
3
3
  import { type OperationValidationOptions, type OperationValidationResult } from "./operation-validator-core.js";
4
- import type { ValidationIssue } from "./validation-code.js";
4
+ import type { AvValidationIssue } from "./validation-code.js";
5
5
  export type { OperationValidationOptions, OperationValidationResult, SemanticOperationArguments, } from "./operation-validator-core.js";
6
6
  /** The key of a request's operation identity that makes it unavailable. */
7
- export declare function unavailableOperationKey(contract: Contract, request: {
7
+ export declare function unavailableOperationKey(contract: AvContract, request: {
8
8
  readonly resource: string;
9
9
  readonly family: string;
10
10
  }): "family" | "variant";
@@ -15,25 +15,25 @@ export declare function unavailableOperationKey(contract: Contract, request: {
15
15
  * {@link unavailableOperationKey}). The one spelling — the protocol's absence
16
16
  * answers build theirs with it, so a caller cannot tell which layer answered.
17
17
  */
18
- export declare function operationUnavailableIssue(contract: Contract, request: {
18
+ export declare function operationUnavailableIssue(contract: AvContract, request: {
19
19
  readonly resource: string;
20
20
  readonly family: string;
21
21
  readonly variant: string;
22
- }): ValidationIssue;
22
+ }): AvValidationIssue;
23
23
  /**
24
24
  * The availability answer alone — `V1006` when the active Contract does not advertise
25
25
  * the operation on a Resource it has — read from the request's identity, never its
26
26
  * arguments. A door that refuses unreadable arguments asks this first, so an
27
27
  * unadvertised operation answers `A2002` whatever its arguments hold.
28
28
  */
29
- export declare function findOperationAvailabilityIssue(contract: Contract, request: OperationIdentity & {
29
+ export declare function findOperationAvailabilityIssue(contract: AvContract, request: AvOperationIdentity & {
30
30
  readonly resource: string;
31
- }): ValidationIssue | undefined;
31
+ }): AvValidationIssue | undefined;
32
32
  /**
33
33
  * Validates one standard operation's arguments against a Contract. Operation
34
34
  * availability and request limits are checked before the arguments' grammar.
35
35
  */
36
- export declare function validateOperationArguments(contract: Contract, request: OperationIdentity & {
36
+ export declare function validateOperationArguments(contract: AvContract, request: AvOperationIdentity & {
37
37
  readonly resource: string;
38
38
  readonly arguments: unknown;
39
39
  }, options?: OperationValidationOptions): OperationValidationResult;
@@ -1,7 +1,7 @@
1
- import type { ProjectionScope } from "../contracts/capability.js";
2
- import type { Contract } from "../contracts/contract.js";
3
- import type { Resource } from "../contracts/resource.js";
4
- import type { OperationIdentity } from "./operation-identity.js";
1
+ import type { AvProjectionScope } from "../contracts/capability.js";
2
+ import type { AvContract } from "../contracts/contract.js";
3
+ import type { AvResource } from "../contracts/resource.js";
4
+ import type { AvOperationIdentity } from "./operation-identity.js";
5
5
  /**
6
6
  * Which projection position one request's **top-level** projection arguments sit
7
7
  * in, read off the variant the Resource advertises.
@@ -21,9 +21,9 @@ import type { OperationIdentity } from "./operation-identity.js";
21
21
  * answering `"record"` for one keeps this function a projection question rather
22
22
  * than a second, weaker copy of the availability gate.
23
23
  */
24
- export declare function resolveProjectionScope(resource: Resource<Contract> | undefined, request: OperationIdentity): ProjectionScope;
24
+ export declare function resolveProjectionScope(resource: AvResource<AvContract> | undefined, request: AvOperationIdentity): AvProjectionScope;
25
25
  /**
26
26
  * The position a projection NESTED beneath an admitted relation sits in: the
27
27
  * unrestricted one, at every depth, under every top-level scope.
28
28
  */
29
- export declare const NESTED_PROJECTION_SCOPE: ProjectionScope;
29
+ export declare const NESTED_PROJECTION_SCOPE: AvProjectionScope;
@@ -1,19 +1,19 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import type { OperationIdentity } from "./operation-identity.js";
3
- import type { ValidationIssue } from "./validation-code.js";
1
+ import type { AvContract } from "../contracts/contract.js";
2
+ import type { AvOperationIdentity } from "./operation-identity.js";
3
+ import type { AvValidationIssue } from "./validation-code.js";
4
4
  type Readable = Readonly<Record<string, unknown>>;
5
5
  /** What one walk of an operation's arguments found. */
6
6
  export type StructuralLimitsFinding = {
7
7
  /** The nesting issue, which wins over any boolean-node issue. */
8
- readonly nesting: ValidationIssue | undefined;
8
+ readonly nesting: AvValidationIssue | undefined;
9
9
  /** The boolean-node issue, when there is no nesting issue. */
10
- readonly booleanNodes: ValidationIssue | undefined;
10
+ readonly booleanNodes: AvValidationIssue | undefined;
11
11
  };
12
12
  /**
13
13
  * Enforces the structural limits on one operation's argument object: the nesting
14
14
  * issue if there is one, otherwise the boolean-node issue if there is one.
15
15
  */
16
- export declare function findStructuralLimitIssues(contract: Contract, request: OperationIdentity & {
16
+ export declare function findStructuralLimitIssues(contract: AvContract, request: AvOperationIdentity & {
17
17
  readonly resource: string;
18
18
  }, args: Readable): StructuralLimitsFinding;
19
19
  export {};
@@ -28,6 +28,109 @@ function nestingExceeded(state) {
28
28
  message: `Request nesting exceeds maxNestingDepth (${state.nestingLimit}).`,
29
29
  };
30
30
  }
31
+ function jsonDepthExceeded(state, fieldPath) {
32
+ state.nestingAtField = true;
33
+ state.nesting = {
34
+ path: state.tracking ? fieldPath : ["arguments", state.rootKey],
35
+ code: "V1021",
36
+ message: `Json value depth exceeds maxJsonDepth (${state.jsonDepthLimit}).`,
37
+ };
38
+ }
39
+ function isJsonField(field) {
40
+ return "scalar" in field.type && field.type.scalar === "json";
41
+ }
42
+ function jsonValueExceeds(state, value) {
43
+ const deepest = new Map();
44
+ const ancestors = new Set();
45
+ const stack = [{ leave: false, value, level: 0 }];
46
+ while (stack.length > 0) {
47
+ const task = stack.pop();
48
+ if (task.leave) {
49
+ ancestors.delete(task.container);
50
+ continue;
51
+ }
52
+ const current = task.value;
53
+ if (typeof current !== "object" ||
54
+ current === null ||
55
+ ancestors.has(current)) {
56
+ continue;
57
+ }
58
+ const inner = task.level + 1;
59
+ if (inner > state.jsonDepthLimit) {
60
+ return true;
61
+ }
62
+ const seen = deepest.get(current);
63
+ if (seen !== undefined && seen >= inner) {
64
+ continue;
65
+ }
66
+ deepest.set(current, inner);
67
+ ancestors.add(current);
68
+ stack.push({ leave: true, container: current });
69
+ const entries = Array.isArray(current)
70
+ ? current
71
+ : Object.values(current);
72
+ for (const entry of entries) {
73
+ stack.push({ leave: false, value: entry, level: inner });
74
+ }
75
+ }
76
+ return false;
77
+ }
78
+ function walkJsonWrite(state, field, value, path) {
79
+ const operands = isRecord(value) && Object.keys(value).some((key) => key.startsWith("$"))
80
+ ? Object.entries(value)
81
+ .filter(([key]) => key !== "$unset" && key !== "$ref")
82
+ .map(([, operand]) => operand)
83
+ : [value];
84
+ for (const operand of operands) {
85
+ const values = field.list && Array.isArray(operand) ? operand : [operand];
86
+ for (const entry of values) {
87
+ if (jsonValueExceeds(state, entry)) {
88
+ jsonDepthExceeded(state, path);
89
+ return;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ const JSON_LIST_OPERATORS = new Set(["in", "notIn", "hasEvery", "hasSome"]);
95
+ const JSON_VALUELESS_OPERATORS = new Set(["mode", "isEmpty", "path"]);
96
+ function walkJsonFilter(state, filter, depth, path) {
97
+ let level = depth;
98
+ let current = filter;
99
+ while (isRecord(current)) {
100
+ let next;
101
+ for (const operator of Object.keys(current)) {
102
+ const operand = current[operator];
103
+ if (operator === "not" && isRecord(operand)) {
104
+ next = operand;
105
+ continue;
106
+ }
107
+ if (JSON_VALUELESS_OPERATORS.has(operator)) {
108
+ continue;
109
+ }
110
+ const values = JSON_LIST_OPERATORS.has(operator) && Array.isArray(operand)
111
+ ? operand
112
+ : [operand];
113
+ for (const entry of values) {
114
+ if (jsonValueExceeds(state, entry)) {
115
+ jsonDepthExceeded(state, path);
116
+ return;
117
+ }
118
+ }
119
+ }
120
+ if (next === undefined) {
121
+ return;
122
+ }
123
+ level += 1;
124
+ if (level > state.nestingLimit) {
125
+ nestingExceeded(state);
126
+ return;
127
+ }
128
+ current = next;
129
+ }
130
+ if (jsonValueExceeds(state, current)) {
131
+ jsonDepthExceeded(state, path);
132
+ }
133
+ }
31
134
  function countBooleanNode(state, path, key) {
32
135
  if (state.booleanExceeded) {
33
136
  return;
@@ -74,7 +177,18 @@ function walkWhere(state, resourceName, value, depth, path, counting) {
74
177
  }
75
178
  else {
76
179
  const field = lookupField(resource, key);
180
+ if (field?.kind === "scalar") {
181
+ if (isJsonField(field)) {
182
+ walkJsonFilter(state, child, depth, extend(state, path, key));
183
+ }
184
+ else {
185
+ walkScalarNot(state, child, depth);
186
+ }
187
+ }
77
188
  if (field?.kind !== "relation") {
189
+ if (state.nesting !== undefined) {
190
+ return;
191
+ }
78
192
  continue;
79
193
  }
80
194
  if (field.cardinality === "one") {
@@ -97,6 +211,22 @@ function walkWhere(state, resourceName, value, depth, path, counting) {
97
211
  }
98
212
  }
99
213
  }
214
+ function walkScalarNot(state, filter, depth) {
215
+ let level = depth;
216
+ let current = filter;
217
+ while (isRecord(current) && Object.hasOwn(current, "not")) {
218
+ const operand = current.not;
219
+ if (!isRecord(operand)) {
220
+ return;
221
+ }
222
+ level += 1;
223
+ if (level > state.nestingLimit) {
224
+ nestingExceeded(state);
225
+ return;
226
+ }
227
+ current = operand;
228
+ }
229
+ }
100
230
  function walkOrderBy(state, resourceName, value, depth) {
101
231
  const resource = lookupResource(state.contract, resourceName);
102
232
  if (resource === undefined) {
@@ -194,6 +324,13 @@ function walkMutationData(state, resourceName, value, depth, path, stage, counti
194
324
  for (const fieldName of Object.keys(value)) {
195
325
  const edge = lookupField(resource, fieldName);
196
326
  const directives = value[fieldName];
327
+ if (edge?.kind === "scalar" && isJsonField(edge)) {
328
+ walkJsonWrite(state, edge, directives, extend(state, path, fieldName));
329
+ if (state.nesting !== undefined) {
330
+ return;
331
+ }
332
+ continue;
333
+ }
197
334
  if (edge?.kind !== "relation" || !isRecord(directives)) {
198
335
  continue;
199
336
  }
@@ -321,11 +458,13 @@ function walk(contract, request, args, tracking) {
321
458
  const state = {
322
459
  contract,
323
460
  nestingLimit: contract.limits.maxNestingDepth,
461
+ jsonDepthLimit: contract.limits.maxJsonDepth,
324
462
  booleanLimit: contract.limits.maxBooleanNodes,
325
463
  tracking,
326
464
  rootKey: "",
327
465
  booleanCount: 0,
328
466
  nesting: undefined,
467
+ nestingAtField: false,
329
468
  booleanNodes: undefined,
330
469
  booleanExceeded: false,
331
470
  };
@@ -334,6 +473,12 @@ function walk(contract, request, args, tracking) {
334
473
  }
335
474
  export function findStructuralLimitIssues(contract, request, args) {
336
475
  const untracked = walk(contract, request, args, false);
476
+ if (untracked.nestingAtField) {
477
+ return {
478
+ nesting: walk(contract, request, args, true).nesting,
479
+ booleanNodes: undefined,
480
+ };
481
+ }
337
482
  if (untracked.nesting !== undefined || !untracked.booleanExceeded) {
338
483
  return { nesting: untracked.nesting, booleanNodes: undefined };
339
484
  }
@@ -1,14 +1,19 @@
1
+ import type { AvFieldCheck } from "../contracts/field-check.js";
1
2
  /** The set of allocated Validation codes, as a runtime array. */
2
- export declare const VALIDATION_CODES: readonly ["V1000", "V1001", "V1002", "V1003", "V1004", "V1005", "V1006", "V1007", "V1008", "V1009", "V1010", "V1011", "V1012", "V1013", "V1014", "V1015", "V1016", "V1017", "V1018", "V1019"];
3
+ export declare const VALIDATION_CODES: readonly ["V1000", "V1001", "V1002", "V1003", "V1004", "V1005", "V1006", "V1007", "V1008", "V1009", "V1010", "V1011", "V1012", "V1013", "V1014", "V1015", "V1016", "V1017", "V1018", "V1019", "V1020", "V1021"];
3
4
  /** A validation code (`V1000` and up), one per kind of argument problem. */
4
- export type ValidationCode = (typeof VALIDATION_CODES)[number];
5
+ export type AvValidationCode = (typeof VALIDATION_CODES)[number];
5
6
  /** The framework's message for each validation code. */
6
- export declare const VALIDATION_CODE_MESSAGES: Readonly<Record<ValidationCode, string>>;
7
+ export declare const VALIDATION_CODE_MESSAGES: Readonly<Record<AvValidationCode, string>>;
7
8
  /** One validation problem: its code, message and the argument path it is at. */
8
- export type ValidationIssue = {
9
+ export type AvValidationIssue = {
9
10
  readonly path?: readonly (string | number)[];
10
- readonly code: ValidationCode;
11
+ readonly code: AvValidationCode;
11
12
  readonly message: string;
13
+ /** The failed field validator's check name (`max_length`, `string_format`, …). */
14
+ readonly check?: AvFieldCheck["check"];
15
+ /** That check's parameters, as the Contract stores them (`{ maximum: 80 }`). */
16
+ readonly params?: Readonly<Record<string, unknown>>;
12
17
  };
13
18
  /** Builds one validation issue at its path. */
14
- export declare function validationIssue(code: ValidationCode, path: readonly (string | number)[], message: string): ValidationIssue;
19
+ export declare function validationIssue(code: AvValidationCode, path: readonly (string | number)[], message: string): AvValidationIssue;
@@ -19,6 +19,8 @@ export const VALIDATION_CODES = [
19
19
  "V1017",
20
20
  "V1018",
21
21
  "V1019",
22
+ "V1020",
23
+ "V1021",
22
24
  ];
23
25
  export const VALIDATION_CODE_MESSAGES = {
24
26
  V1000: "Required value missing.",
@@ -41,6 +43,8 @@ export const VALIDATION_CODE_MESSAGES = {
41
43
  V1017: "Transaction fingerprint mismatch.",
42
44
  V1018: "Transaction reference resolved to no value.",
43
45
  V1019: "Transaction step depends on a row removed by an earlier step's cascade",
46
+ V1020: "Transaction mixes application and client steps.",
47
+ V1021: "Json value depth limit exceeded.",
44
48
  };
45
49
  export function validationIssue(code, path, message) {
46
50
  return { code, path, message };