@aventara/core 0.1.0-pilot.4 → 1.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/CHANGELOG.md +1478 -0
  2. package/README.md +275 -11
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +17 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -25
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/avz/avz.js +354 -0
  19. package/dist/avz/index.d.ts +7 -0
  20. package/dist/avz/index.js +1 -0
  21. package/dist/avz/json-shape.registry.d.ts +22 -0
  22. package/dist/avz/json-shape.registry.js +16 -0
  23. package/dist/avz/zod-issue.translator.d.ts +57 -0
  24. package/dist/avz/zod-issue.translator.js +149 -0
  25. package/dist/compiler/contract-compiler-diagnostic.d.ts +37 -5
  26. package/dist/compiler/contract.compiler.d.ts +18 -18
  27. package/dist/compiler/contract.compiler.js +595 -421
  28. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  29. package/dist/compiler/create-requirements.projector.js +423 -0
  30. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  31. package/dist/compiler/field-validator.compiler.js +238 -0
  32. package/dist/config/any-framework-config.d.ts +19 -12
  33. package/dist/config/config-diagnostic.d.ts +11 -4
  34. package/dist/config/config-layer.d.ts +15 -6
  35. package/dist/config/config.resolver.d.ts +75 -29
  36. package/dist/config/config.resolver.js +109 -44
  37. package/dist/config/config.validator.d.ts +7 -7
  38. package/dist/config/config.validator.js +586 -71
  39. package/dist/config/define-resource.d.ts +57 -0
  40. package/dist/config/define-resource.js +14 -0
  41. package/dist/config/effective-fields.d.ts +19 -23
  42. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  43. package/dist/config/exact-framework-config.d.ts +280 -0
  44. package/dist/config/field-compute.resolver.d.ts +19 -0
  45. package/dist/config/field-compute.resolver.js +115 -0
  46. package/dist/config/field-pipeline-config.d.ts +47 -0
  47. package/dist/config/forced-operation.validator.d.ts +10 -0
  48. package/dist/config/forced-operation.validator.js +66 -0
  49. package/dist/config/framework-config.d.ts +111 -37
  50. package/dist/config/framework-exemptions-config.d.ts +91 -0
  51. package/dist/config/framework-exemptions-config.js +1 -0
  52. package/dist/config/framework-field-definition.d.ts +78 -0
  53. package/dist/config/framework-field-definition.js +28 -0
  54. package/dist/config/framework-resources-config.d.ts +116 -0
  55. package/dist/config/framework-resources-config.js +1 -0
  56. package/dist/config/pipeline-config.d.ts +56 -20
  57. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  58. package/dist/config/pipeline-tree.resolver.js +220 -0
  59. package/dist/config/stage-type.eraser.d.ts +65 -0
  60. package/dist/config/stage-type.eraser.js +1 -0
  61. package/dist/contracts/capability.d.ts +11 -11
  62. package/dist/contracts/client-contract-structure.validator.d.ts +344 -29
  63. package/dist/contracts/client-contract-structure.validator.js +248 -7
  64. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  65. package/dist/contracts/contract-canonicalizer.js +172 -27
  66. package/dist/contracts/contract-hash.d.ts +12 -7
  67. package/dist/contracts/contract-hash.js +3 -2
  68. package/dist/contracts/contract-limits.d.ts +4 -1
  69. package/dist/contracts/contract-limits.js +1 -0
  70. package/dist/contracts/contract-lookup.d.ts +5 -5
  71. package/dist/contracts/contract-protocol.d.ts +4 -4
  72. package/dist/contracts/contract.d.ts +31 -16
  73. package/dist/contracts/create-requirements.d.ts +35 -0
  74. package/dist/contracts/create-requirements.js +1 -0
  75. package/dist/contracts/enum-definition.d.ts +1 -1
  76. package/dist/contracts/field-check.d.ts +101 -0
  77. package/dist/contracts/field-check.js +1 -0
  78. package/dist/contracts/field.d.ts +61 -41
  79. package/dist/contracts/identifier.d.ts +4 -4
  80. package/dist/contracts/json-shape.d.ts +76 -0
  81. package/dist/contracts/json-shape.js +1 -0
  82. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  83. package/dist/contracts/reference-write-limit.d.ts +7 -0
  84. package/dist/contracts/reference-write-limit.js +1 -0
  85. package/dist/contracts/resource-operations.d.ts +28 -28
  86. package/dist/contracts/resource.d.ts +15 -9
  87. package/dist/contracts/scalar-value-type.d.ts +25 -14
  88. package/dist/contracts/scalar.d.ts +3 -3
  89. package/dist/contracts/transaction-capability.d.ts +1 -1
  90. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  91. package/dist/framework/contract-view.d.ts +234 -63
  92. package/dist/framework/framework-construction.error.d.ts +10 -10
  93. package/dist/framework/framework-construction.error.js +2 -2
  94. package/dist/framework/framework.d.ts +50 -24
  95. package/dist/framework/framework.factory.d.ts +8 -6
  96. package/dist/framework/framework.factory.js +95 -32
  97. package/dist/framework/operation-facade.d.ts +123 -52
  98. package/dist/framework/operation-facade.js +9 -1
  99. package/dist/index.d.ts +55 -82
  100. package/dist/index.js +6 -26
  101. package/dist/internal.d.ts +40 -0
  102. package/dist/internal.js +18 -0
  103. package/dist/operations/operation-arguments.d.ts +316 -201
  104. package/dist/operations/operation-call.d.ts +27 -28
  105. package/dist/operations/operation-identity.d.ts +12 -10
  106. package/dist/operations/operation-identity.js +3 -0
  107. package/dist/operations/operation-result.d.ts +21 -21
  108. package/dist/operations/operation-validator-core.d.ts +6 -6
  109. package/dist/operations/operation-validator-core.js +41 -12
  110. package/dist/operations/operation-validator.d.ts +24 -9
  111. package/dist/operations/operation-validator.js +26 -10
  112. package/dist/operations/projection-scope.resolver.d.ts +7 -7
  113. package/dist/operations/structural-limits.walker.d.ts +19 -0
  114. package/dist/operations/structural-limits.walker.js +489 -0
  115. package/dist/operations/validation-code.d.ts +11 -6
  116. package/dist/operations/validation-code.js +4 -0
  117. package/dist/operations/write-scope.resolver.d.ts +6 -6
  118. package/dist/protocol/absent-route.responder.d.ts +13 -11
  119. package/dist/protocol/absent-route.responder.js +42 -16
  120. package/dist/protocol/contract-document.responder.d.ts +3 -3
  121. package/dist/protocol/contract-document.responder.js +2 -2
  122. package/dist/protocol/http-request.decoder.d.ts +23 -13
  123. package/dist/protocol/http-request.decoder.js +19 -11
  124. package/dist/protocol/http-request.reader.d.ts +3 -3
  125. package/dist/protocol/http-response.encoder.d.ts +4 -4
  126. package/dist/protocol/http-response.encoder.js +94 -55
  127. package/dist/protocol/http-status.table.d.ts +2 -2
  128. package/dist/protocol/operation-response.guard.d.ts +2 -2
  129. package/dist/protocol/protocol-surface.d.ts +4 -4
  130. package/dist/protocol/protocol.binder.d.ts +52 -27
  131. package/dist/protocol/protocol.binder.js +14 -9
  132. package/dist/protocol/protocol.handler.d.ts +28 -15
  133. package/dist/protocol/protocol.handler.js +55 -10
  134. package/dist/protocol/unmounted-route.error.d.ts +19 -0
  135. package/dist/protocol/unmounted-route.error.js +10 -0
  136. package/dist/runtime/caller-data.copier.d.ts +59 -0
  137. package/dist/runtime/caller-data.copier.js +470 -0
  138. package/dist/runtime/caller-data.door.d.ts +56 -0
  139. package/dist/runtime/caller-data.door.js +67 -0
  140. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  141. package/dist/runtime/computed-read-runtime.js +61 -55
  142. package/dist/runtime/computed-value.error.d.ts +13 -0
  143. package/dist/runtime/computed-value.error.js +9 -0
  144. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  145. package/dist/runtime/context-executor.runtime.js +275 -0
  146. package/dist/runtime/create-requirement.d.ts +22 -57
  147. package/dist/runtime/create-requirement.js +140 -37
  148. package/dist/runtime/decimal.d.ts +2 -2
  149. package/dist/runtime/decimal.js +1 -1
  150. package/dist/runtime/diagnostics-reporter.d.ts +64 -22
  151. package/dist/runtime/diagnostics-reporter.js +35 -4
  152. package/dist/runtime/error-boundary.d.ts +73 -8
  153. package/dist/runtime/error-boundary.js +104 -48
  154. package/dist/runtime/execution-options.d.ts +10 -2
  155. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  156. package/dist/runtime/field-check.evaluator.js +521 -0
  157. package/dist/runtime/field-compute.d.ts +64 -0
  158. package/dist/runtime/field-compute.js +1 -0
  159. package/dist/runtime/field-stage.plan.d.ts +15 -0
  160. package/dist/runtime/field-stage.plan.js +27 -0
  161. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  162. package/dist/runtime/field-stage.runtime.js +143 -0
  163. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  164. package/dist/runtime/field-validator.runtime.js +87 -0
  165. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  166. package/dist/runtime/framework-error-class.table.js +25 -0
  167. package/dist/runtime/framework-error.d.ts +79 -7
  168. package/dist/runtime/framework-error.factory.d.ts +4 -0
  169. package/dist/runtime/framework-error.factory.js +15 -0
  170. package/dist/runtime/framework-error.js +23 -2
  171. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  172. package/dist/runtime/interceptor-next.error.js +6 -0
  173. package/dist/runtime/json-value.d.ts +3 -3
  174. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  175. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  176. package/dist/runtime/misuse-reporter.d.ts +32 -0
  177. package/dist/runtime/misuse-reporter.js +19 -0
  178. package/dist/runtime/mutation-planner.d.ts +19 -10
  179. package/dist/runtime/mutation-planner.js +62 -36
  180. package/dist/runtime/nested-write.walker.d.ts +32 -0
  181. package/dist/runtime/nested-write.walker.js +73 -0
  182. package/dist/runtime/operation-request.d.ts +35 -15
  183. package/dist/runtime/operation-response.d.ts +17 -17
  184. package/dist/runtime/operation-runtime.d.ts +125 -30
  185. package/dist/runtime/operation-runtime.js +423 -83
  186. package/dist/runtime/outcome-mapper.d.ts +16 -5
  187. package/dist/runtime/outcome-mapper.js +35 -8
  188. package/dist/runtime/output-validator.d.ts +16 -6
  189. package/dist/runtime/output-validator.js +12 -1
  190. package/dist/runtime/owned-execution.registry.d.ts +13 -0
  191. package/dist/runtime/owned-execution.registry.js +7 -0
  192. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  193. package/dist/runtime/pipe-output.validator.js +12 -12
  194. package/dist/runtime/pipeline.d.ts +202 -28
  195. package/dist/runtime/readonly-value.d.ts +32 -0
  196. package/dist/runtime/readonly-value.js +141 -0
  197. package/dist/runtime/referential-action.d.ts +7 -0
  198. package/dist/runtime/request-envelope.validator.d.ts +5 -0
  199. package/dist/runtime/request-envelope.validator.js +123 -0
  200. package/dist/runtime/request-id.d.ts +1 -1
  201. package/dist/runtime/request-state.d.ts +14 -0
  202. package/dist/runtime/request-state.js +1 -0
  203. package/dist/runtime/request-state.resolver.d.ts +12 -0
  204. package/dist/runtime/request-state.resolver.js +20 -0
  205. package/dist/runtime/scalar-runtime.d.ts +56 -13
  206. package/dist/runtime/scalar-runtime.js +167 -86
  207. package/dist/transactions/deferred-operation.d.ts +35 -20
  208. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  209. package/dist/transactions/operation-arguments-encoder.js +2 -2
  210. package/dist/transactions/sql-statement.d.ts +77 -0
  211. package/dist/transactions/sql-statement.js +47 -0
  212. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  213. package/dist/transactions/sql-statement.validator.js +134 -0
  214. package/dist/transactions/transaction-envelope.d.ts +4 -4
  215. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  216. package/dist/transactions/transaction-integrity-error.js +5 -2
  217. package/dist/transactions/transaction-plan-assembler.d.ts +23 -9
  218. package/dist/transactions/transaction-plan-assembler.js +195 -82
  219. package/dist/transactions/transaction-plan-validator.d.ts +53 -21
  220. package/dist/transactions/transaction-plan-validator.js +246 -163
  221. package/dist/transactions/transaction-reference-collector.d.ts +30 -0
  222. package/dist/transactions/transaction-reference-collector.js +204 -0
  223. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  224. package/dist/transactions/transaction-reference-resolver.js +27 -10
  225. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  226. package/dist/transactions/transaction-reference-validator.js +82 -43
  227. package/dist/transactions/transaction-reference.d.ts +30 -58
  228. package/dist/transactions/transaction-request.d.ts +20 -7
  229. package/dist/transactions/transaction-response.d.ts +12 -7
  230. package/dist/transactions/transaction-response.js +24 -1
  231. package/dist/transactions/transaction-runtime.d.ts +11 -8
  232. package/dist/transactions/transaction-runtime.js +167 -50
  233. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  234. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  235. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  236. package/dist/transactions/transaction-slot-path-error.js +2 -2
  237. package/dist/transactions/transaction-slot-writer.js +2 -2
  238. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  239. package/dist/transactions/transaction-stage.runtime.js +123 -0
  240. package/package.json +18 -3
  241. package/src/runtime/field-check.evaluator.ts +720 -0
  242. package/dist/config/define-fields.d.ts +0 -35
  243. package/dist/config/define-fields.js +0 -3
  244. package/dist/config/framework-behaviors-config.d.ts +0 -30
  245. package/dist/config/framework-fields-config.d.ts +0 -36
  246. package/dist/config/framework-restrictions-config.d.ts +0 -142
  247. package/dist/operations/operation-boolean-nodes.d.ts +0 -11
  248. package/dist/operations/operation-boolean-nodes.js +0 -283
  249. package/dist/operations/operation-nesting.d.ts +0 -8
  250. package/dist/operations/operation-nesting.js +0 -307
  251. package/dist/runtime/field-behavior.d.ts +0 -48
  252. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  253. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  254. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  255. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,35 +0,0 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AdapterFieldKey } from "../adapters/adapter-resource.js";
3
- import type { FrameworkResourceKey, FrameworkScalarFieldConfig, FrameworkScalarTypeRef } from "./framework-fields-config.js";
4
- /**
5
- * What a configuration may say about a field the adapter already discovered:
6
- * everything in {@link FrameworkScalarFieldConfig} except `type`.
7
- */
8
- export type KnownScalarFieldConfig<M extends AdapterModel = AdapterModel> = Omit<FrameworkScalarFieldConfig<M>, "type"> & {
9
- readonly type?: never;
10
- };
11
- /**
12
- * A scalar field the configuration adds, which the adapter did not discover.
13
- * `type`, `nullable` and `list` are required.
14
- */
15
- export type AddedScalarFieldConfig<M extends AdapterModel = AdapterModel> = Omit<FrameworkScalarFieldConfig<M>, "type" | "nullable" | "list"> & {
16
- readonly type: FrameworkScalarTypeRef<M>;
17
- readonly nullable: boolean;
18
- readonly list: boolean;
19
- };
20
- /** The shape one authored field name admits, by what the adapter knows of it. */
21
- type ScalarFieldConfigFor<M extends AdapterModel, R extends FrameworkResourceKey<M>, F> = string extends AdapterFieldKey<M, R> ? FrameworkScalarFieldConfig<M> : F extends AdapterFieldKey<M, R> ? M["resources"][R]["fields"][F] extends {
22
- readonly kind: "relation";
23
- } ? never : KnownScalarFieldConfig<M> : AddedScalarFieldConfig<M>;
24
- /** The shape an authored `fields` block is checked against, keyed on its own names. */
25
- export type FrameworkFieldsShape<M extends AdapterModel, Self> = {
26
- readonly [R in keyof Self]: R extends FrameworkResourceKey<M> ? {
27
- readonly [F in keyof Self[R]]: ScalarFieldConfigFor<M, R, F>;
28
- } : never;
29
- };
30
- /**
31
- * Authors stage 1 of a configuration: the `fields` block, checked against
32
- * what the adapter discovered and returned unwidened.
33
- */
34
- export declare function defineFields<M extends AdapterModel, const Self extends FrameworkFieldsShape<M, Self>>(_model: M, fields: Self): Self;
35
- export {};
@@ -1,3 +0,0 @@
1
- export function defineFields(_model, fields) {
2
- return fields;
3
- }
@@ -1,30 +0,0 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { ComputedReadBehavior, ComputeOnCreate, ComputeOnUpdate } from "../runtime/field-behavior.js";
3
- import type { AnyFrameworkConfig } from "./any-framework-config.js";
4
- import type { EffectiveFieldKey } from "./effective-fields.js";
5
- import type { FrameworkResourceKey } from "./framework-fields-config.js";
6
- /** A read behavior: a compute function, or one declaring the fields it reads. */
7
- export type FrameworkReadBehavior<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = ComputedReadBehavior<M, Cfg, R>;
8
- /**
9
- * A field's behaviors: a value computed on create, on update, or on read.
10
- * `false` turns off a behavior set at an outer layer.
11
- */
12
- export type FrameworkFieldBehaviorConfig<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = {
13
- /** Computes the field's value when a row is created. */
14
- readonly create?: false | ComputeOnCreate<M, Cfg, R>;
15
- /** Computes the field's value when a row is updated. */
16
- readonly update?: false | ComputeOnUpdate<M, Cfg, R>;
17
- /** Computes the field's value when a row is read. */
18
- readonly read?: false | FrameworkReadBehavior<M, Cfg, R>;
19
- };
20
- /** Behaviors for one Resource's fields. */
21
- export type FrameworkResourceBehaviorsConfig<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = {
22
- /** Behaviors per field name. */
23
- readonly fields: Readonly<Partial<{
24
- [F in EffectiveFieldKey<M, Cfg, R>]: FrameworkFieldBehaviorConfig<M, Cfg, R>;
25
- }>>;
26
- };
27
- /** Server-side behaviors, per Resource. */
28
- export type FrameworkBehaviorsConfig<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig> = Readonly<Partial<{
29
- [R in FrameworkResourceKey<M>]: FrameworkResourceBehaviorsConfig<M, Cfg, R>;
30
- }>>;
@@ -1,36 +0,0 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { ScalarFieldCapabilities, ScalarFormat } from "../contracts/field.js";
3
- import type { LifecycleTrait } from "../contracts/lifecycle-trait.js";
4
- /** The lifecycle traits a configuration may set on a field. */
5
- export type FrameworkFieldLifecycleTrait = Extract<LifecycleTrait, "VIRTUAL">;
6
- /** The names of the Resources in adapter model `M`. */
7
- export type FrameworkResourceKey<M extends AdapterModel> = Extract<keyof M["resources"], string>;
8
- /** A scalar type or an enum of adapter model `M`, by name. */
9
- export type FrameworkScalarTypeRef<M extends AdapterModel> = {
10
- readonly scalar: Extract<keyof M["scalars"], string>;
11
- } | {
12
- readonly enum: Extract<keyof M["enums"], string>;
13
- };
14
- /**
15
- * A scalar field's settings. For a discovered field, the discovered values are
16
- * the baseline; a field the adapter did not discover must state `type`,
17
- * `nullable` and `list`.
18
- */
19
- export type FrameworkScalarFieldConfig<M extends AdapterModel = AdapterModel> = {
20
- /** The field's scalar or enum type. */
21
- readonly type?: FrameworkScalarTypeRef<M>;
22
- /** The scalar's format name, carried in the Contract. */
23
- readonly format?: ScalarFormat;
24
- /** Whether the field may be `null`. */
25
- readonly nullable?: boolean;
26
- /** Whether the field holds a list of values. */
27
- readonly list?: boolean;
28
- /** Persistence traits: `"VIRTUAL"` marks a field the store does not hold. */
29
- readonly lifecycle?: readonly FrameworkFieldLifecycleTrait[];
30
- /** The field's capabilities; see {@link ScalarFieldCapabilities}. */
31
- readonly capabilities?: Partial<ScalarFieldCapabilities>;
32
- };
33
- /** Field settings for one Resource, by field name. */
34
- export type FrameworkResourceFieldsConfig<M extends AdapterModel = AdapterModel> = Readonly<Record<string, FrameworkScalarFieldConfig<M>>>;
35
- /** Fields to add or describe, per Resource. */
36
- export type FrameworkFieldsConfig<M extends AdapterModel = AdapterModel> = Readonly<Partial<Record<FrameworkResourceKey<M>, FrameworkResourceFieldsConfig<M>>>>;
@@ -1,142 +0,0 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
2
- import type { AdapterFieldKey } from "../adapters/adapter-resource.js";
3
- import type { PaginationCapability, ProjectionScope, RelationFilterCapability, RelationMutationDirective, RelationReducer, ScalarFilterOperator, ScalarMutationDirective, WriteScope } from "../contracts/capability.js";
4
- import type { AnyFrameworkConfig } from "./any-framework-config.js";
5
- import type { EffectiveFieldKey } from "./effective-fields.js";
6
- import type { FrameworkResourceKey } from "./framework-fields-config.js";
7
- /**
8
- * `true` keeps a capability, `false` removes it, and a list keeps only the
9
- * listed entries. Restrictions only narrow what the adapter offers.
10
- */
11
- export type FrameworkCapabilitySetRestriction<T extends string> = boolean | readonly T[];
12
- /**
13
- * A restriction on a relation's `select` or `include` capability: `true`,
14
- * `false`, or the projection positions to keep.
15
- */
16
- export type FrameworkProjectionScopeRestriction = boolean | readonly ProjectionScope[];
17
- /**
18
- * A restriction on a relation's `create` or `update` capability. A directive
19
- * list narrows the directives only; the object form can also narrow the write
20
- * positions (`scopes`).
21
- *
22
- * `directives: []` leaves the relation writable with no directive;
23
- * `scopes: []` or `false` makes it not writable.
24
- */
25
- export type FrameworkRelationMutationRestriction = boolean | readonly RelationMutationDirective[] | {
26
- readonly directives?: readonly RelationMutationDirective[];
27
- readonly scopes?: readonly WriteScope[];
28
- };
29
- /**
30
- * A restriction on a relation's `reducers` capability: `true`, `false`, a
31
- * reducer list, or an object narrowing reducers and projection positions.
32
- */
33
- export type FrameworkRelationReducerRestriction = boolean | readonly RelationReducer[] | {
34
- readonly reducers?: readonly RelationReducer[];
35
- readonly scopes?: readonly ProjectionScope[];
36
- };
37
- /** Restrictions on a scalar field's capabilities. */
38
- export type FrameworkScalarCapabilityRestrictions = {
39
- /** Whether the field can be selected. */
40
- readonly select?: boolean;
41
- /** The filter operators to keep. */
42
- readonly filter?: FrameworkCapabilitySetRestriction<ScalarFilterOperator>;
43
- /** Whether results can be ordered by the field. */
44
- readonly order?: boolean;
45
- /** Whether ordering can place `null`s first or last. */
46
- readonly orderNulls?: boolean;
47
- /** The directives to keep when creating. */
48
- readonly create?: FrameworkCapabilitySetRestriction<ScalarMutationDirective>;
49
- /** The directives to keep when updating. */
50
- readonly update?: FrameworkCapabilitySetRestriction<ScalarMutationDirective>;
51
- };
52
- /**
53
- * Restrictions on a relation field's capabilities. `select`, `include`,
54
- * `reducers`, `create` and `update` can also be narrowed by argument position.
55
- */
56
- export type FrameworkRelationCapabilityRestrictions = {
57
- readonly select?: FrameworkProjectionScopeRestriction;
58
- readonly include?: FrameworkProjectionScopeRestriction;
59
- readonly filter?: FrameworkCapabilitySetRestriction<RelationFilterCapability>;
60
- readonly order?: boolean;
61
- readonly pagination?: FrameworkCapabilitySetRestriction<PaginationCapability>;
62
- readonly reducers?: FrameworkRelationReducerRestriction;
63
- readonly create?: FrameworkRelationMutationRestriction;
64
- readonly update?: FrameworkRelationMutationRestriction;
65
- };
66
- /** Restrictions for one scalar field. */
67
- export type FrameworkScalarFieldRestrictions = {
68
- /** `true` hides the field. */
69
- readonly hidden?: boolean;
70
- /** Capabilities to narrow. */
71
- readonly capabilities?: FrameworkScalarCapabilityRestrictions;
72
- };
73
- /** Restrictions for one relation field. */
74
- export type FrameworkRelationFieldRestrictions = {
75
- /** `true` hides the field. */
76
- readonly hidden?: boolean;
77
- /** Capabilities to narrow. */
78
- readonly capabilities?: FrameworkRelationCapabilityRestrictions;
79
- };
80
- /** Restrictions for one field: scalar or relation. */
81
- export type FrameworkFieldRestrictions = FrameworkScalarFieldRestrictions | FrameworkRelationFieldRestrictions;
82
- /**
83
- * Standard operations to turn off, by family and variant: `false` removes
84
- * one the adapter offers.
85
- */
86
- export type FrameworkResourceOperationRestrictions = {
87
- readonly find?: {
88
- readonly first?: boolean;
89
- readonly unique?: boolean;
90
- readonly many?: boolean;
91
- readonly count?: boolean;
92
- };
93
- readonly create?: {
94
- readonly one?: boolean;
95
- readonly many?: boolean;
96
- readonly count?: boolean;
97
- };
98
- readonly update?: {
99
- readonly first?: boolean;
100
- readonly unique?: boolean;
101
- readonly many?: boolean;
102
- readonly count?: boolean;
103
- };
104
- readonly delete?: {
105
- readonly first?: boolean;
106
- readonly unique?: boolean;
107
- readonly many?: boolean;
108
- readonly count?: boolean;
109
- };
110
- readonly upsert?: {
111
- readonly unique?: boolean;
112
- };
113
- };
114
- /** The restriction shape an adapter-discovered field admits, by its kind. */
115
- type AdapterFieldRestrictionsFor<TField> = TField extends {
116
- readonly kind: "scalar";
117
- } ? FrameworkScalarFieldRestrictions : TField extends {
118
- readonly kind: "relation";
119
- } ? FrameworkRelationFieldRestrictions : FrameworkFieldRestrictions;
120
- /**
121
- * The restriction shape one effective field name admits. Three cases, in
122
- * order.
123
- */
124
- type FieldRestrictionsFor<M extends AdapterModel, R extends FrameworkResourceKey<M>, F extends string> = string extends F ? FrameworkFieldRestrictions : F extends AdapterFieldKey<M, R> ? AdapterFieldRestrictionsFor<M["resources"][R]["fields"][F]> : FrameworkScalarFieldRestrictions;
125
- /** Restrictions for one Resource's fields, by field name. */
126
- export type FrameworkResourceFieldRestrictions<M extends AdapterModel, Cfg, R extends FrameworkResourceKey<M>> = Readonly<Partial<{
127
- [F in EffectiveFieldKey<M, Cfg, R>]: FieldRestrictionsFor<M, R, F>;
128
- }>>;
129
- /** Restrictions for one Resource. */
130
- export type FrameworkResourceRestrictions<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig, R extends FrameworkResourceKey<M> = FrameworkResourceKey<M>> = {
131
- /** `true` hides the whole Resource. */
132
- readonly hidden?: boolean;
133
- /** Restrictions per field. */
134
- readonly fields?: FrameworkResourceFieldRestrictions<M, Cfg, R>;
135
- /** Standard operations to turn off. */
136
- readonly operations?: FrameworkResourceOperationRestrictions;
137
- };
138
- /** What to hide or narrow, per Resource. */
139
- export type FrameworkRestrictionsConfig<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkConfig> = Readonly<Partial<{
140
- [R in FrameworkResourceKey<M>]: FrameworkResourceRestrictions<M, Cfg, R>;
141
- }>>;
142
- export {};
@@ -1,11 +0,0 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import type { OperationIdentity } from "./operation-identity.js";
3
- import type { ValidationIssue } from "./validation-code.js";
4
- /**
5
- * Enforces maxBooleanNodes across every general where tree in one semantic
6
- * operation, including root filters, returned-relation filters, and nested
7
- * relation mutation filters. Unique selectors are intentionally excluded.
8
- */
9
- export declare function findOperationBooleanNodeIssue(contract: Contract, request: OperationIdentity & {
10
- readonly resource: string;
11
- }, args: Readonly<Record<string, unknown>>): ValidationIssue | undefined;
@@ -1,283 +0,0 @@
1
- import { lookupField, lookupResource } from "../contracts/contract-lookup.js";
2
- import { advertisedDirectives, holdsAt, } from "../contracts/field.js";
3
- import { NESTED_PROJECTION_SCOPE, resolveProjectionScope, } from "./projection-scope.resolver.js";
4
- function isRecord(value) {
5
- return typeof value === "object" && value !== null && !Array.isArray(value);
6
- }
7
- function booleanNodeIssue(contract, path) {
8
- return {
9
- path,
10
- code: "V1015",
11
- message: `Boolean/filter node count exceeds maxBooleanNodes (${contract.limits.maxBooleanNodes}).`,
12
- };
13
- }
14
- function countNode(state, path) {
15
- state.count += 1;
16
- return state.count > state.contract.limits.maxBooleanNodes
17
- ? booleanNodeIssue(state.contract, path)
18
- : undefined;
19
- }
20
- function walkWhere(state, resourceName, value, path) {
21
- if (!isRecord(value)) {
22
- return undefined;
23
- }
24
- const resource = lookupResource(state.contract, resourceName);
25
- if (resource === undefined) {
26
- return undefined;
27
- }
28
- for (const [key, child] of Object.entries(value)) {
29
- const exceeded = countNode(state, [...path, key]);
30
- if (exceeded !== undefined) {
31
- return exceeded;
32
- }
33
- if (key === "AND" || key === "OR") {
34
- if (!Array.isArray(child)) {
35
- continue;
36
- }
37
- for (let index = 0; index < child.length; index += 1) {
38
- const issue = walkWhere(state, resourceName, child[index], [
39
- ...path,
40
- key,
41
- index,
42
- ]);
43
- if (issue !== undefined) {
44
- return issue;
45
- }
46
- }
47
- continue;
48
- }
49
- if (key === "NOT") {
50
- const issue = walkWhere(state, resourceName, child, [...path, key]);
51
- if (issue !== undefined) {
52
- return issue;
53
- }
54
- continue;
55
- }
56
- const field = lookupField(resource, key);
57
- if (field?.kind !== "relation") {
58
- continue;
59
- }
60
- if (field.cardinality === "one") {
61
- if (child === null || !isRecord(child)) {
62
- continue;
63
- }
64
- const issue = walkWhere(state, field.target, child, [...path, key]);
65
- if (issue !== undefined) {
66
- return issue;
67
- }
68
- continue;
69
- }
70
- if (!isRecord(child)) {
71
- continue;
72
- }
73
- for (const relationOperator of ["some", "every", "none"]) {
74
- if (!(relationOperator in child)) {
75
- continue;
76
- }
77
- const issue = walkWhere(state, field.target, child[relationOperator], [
78
- ...path,
79
- key,
80
- relationOperator,
81
- ]);
82
- if (issue !== undefined) {
83
- return issue;
84
- }
85
- }
86
- }
87
- return undefined;
88
- }
89
- function projectionRelation(contract, resourceName, entry, mode, scope) {
90
- if (Object.keys(entry).length !== 1) {
91
- return undefined;
92
- }
93
- const name = Object.keys(entry)[0];
94
- const field = lookupField(lookupResource(contract, resourceName), name);
95
- if (field?.kind !== "relation") {
96
- return undefined;
97
- }
98
- if (mode === "select" && !holdsAt(field.capabilities.select, scope)) {
99
- return undefined;
100
- }
101
- if (mode === "include" && !holdsAt(field.capabilities.include, scope)) {
102
- return undefined;
103
- }
104
- return { name, edge: field, value: entry[name] };
105
- }
106
- function walkProjection(state, resourceName, value, mode, scope, path) {
107
- if (!Array.isArray(value)) {
108
- return undefined;
109
- }
110
- for (let index = 0; index < value.length; index += 1) {
111
- const entry = value[index];
112
- if (!isRecord(entry)) {
113
- continue;
114
- }
115
- const relation = projectionRelation(state.contract, resourceName, entry, mode, scope);
116
- if (relation === undefined || !isRecord(relation.value)) {
117
- continue;
118
- }
119
- const relationPath = [...path, index, relation.name];
120
- if ("where" in relation.value &&
121
- relation.edge.capabilities.filter?.includes("nested") === true) {
122
- const issue = walkWhere(state, relation.edge.target, relation.value.where, [...relationPath, "where"]);
123
- if (issue !== undefined) {
124
- return issue;
125
- }
126
- }
127
- for (const nestedMode of ["select", "include"]) {
128
- if (!(nestedMode in relation.value)) {
129
- continue;
130
- }
131
- const issue = walkProjection(state, relation.edge.target, relation.value[nestedMode], nestedMode, NESTED_PROJECTION_SCOPE, [...relationPath, nestedMode]);
132
- if (issue !== undefined) {
133
- return issue;
134
- }
135
- }
136
- }
137
- return undefined;
138
- }
139
- function relationEntries(value) {
140
- return Array.isArray(value) ? value : [value];
141
- }
142
- function walkMutationData(state, resourceName, value, stage, path) {
143
- if (!isRecord(value)) {
144
- return undefined;
145
- }
146
- const resource = lookupResource(state.contract, resourceName);
147
- if (resource === undefined) {
148
- return undefined;
149
- }
150
- for (const [fieldName, fieldValue] of Object.entries(value)) {
151
- const edge = lookupField(resource, fieldName);
152
- if (edge?.kind !== "relation" || !isRecord(fieldValue)) {
153
- continue;
154
- }
155
- const supported = advertisedDirectives(edge.capabilities[stage]);
156
- for (const [directive, directiveValue] of Object.entries(fieldValue)) {
157
- if (supported?.includes(directive) !== true) {
158
- continue;
159
- }
160
- const entries = relationEntries(directiveValue);
161
- for (let index = 0; index < entries.length; index += 1) {
162
- const entry = entries[index];
163
- const indexPath = Array.isArray(directiveValue) ? [index] : [];
164
- const directivePath = [...path, fieldName, directive, ...indexPath];
165
- if (directive === "$create") {
166
- const issue = walkMutationData(state, edge.target, entry, "create", directivePath);
167
- if (issue !== undefined) {
168
- return issue;
169
- }
170
- continue;
171
- }
172
- if (!isRecord(entry)) {
173
- continue;
174
- }
175
- if (directive === "$connectOrCreate" && "create" in entry) {
176
- const issue = walkMutationData(state, edge.target, entry.create, "create", [...directivePath, "create"]);
177
- if (issue !== undefined) {
178
- return issue;
179
- }
180
- continue;
181
- }
182
- if (directive === "$update") {
183
- if ("where" in entry) {
184
- const issue = walkWhere(state, edge.target, entry.where, [
185
- ...directivePath,
186
- "where",
187
- ]);
188
- if (issue !== undefined) {
189
- return issue;
190
- }
191
- }
192
- if ("data" in entry) {
193
- const issue = walkMutationData(state, edge.target, entry.data, "update", [...directivePath, "data"]);
194
- if (issue !== undefined) {
195
- return issue;
196
- }
197
- }
198
- continue;
199
- }
200
- if (directive === "$delete" && "where" in entry) {
201
- const issue = walkWhere(state, edge.target, entry.where, [
202
- ...directivePath,
203
- "where",
204
- ]);
205
- if (issue !== undefined) {
206
- return issue;
207
- }
208
- continue;
209
- }
210
- if (directive === "$upsert") {
211
- for (const branch of ["create", "update"]) {
212
- if (!(branch in entry)) {
213
- continue;
214
- }
215
- const issue = walkMutationData(state, edge.target, entry[branch], branch, [...directivePath, branch]);
216
- if (issue !== undefined) {
217
- return issue;
218
- }
219
- }
220
- }
221
- }
222
- }
223
- }
224
- return undefined;
225
- }
226
- function isUniqueOperation(request) {
227
- return (request.variant === "unique" &&
228
- (request.family === "find" ||
229
- request.family === "update" ||
230
- request.family === "delete" ||
231
- request.family === "upsert"));
232
- }
233
- export function findOperationBooleanNodeIssue(contract, request, args) {
234
- const state = { contract, count: 0 };
235
- const projectionScope = resolveProjectionScope(lookupResource(contract, request.resource), request);
236
- if ("where" in args && !isUniqueOperation(request)) {
237
- const issue = walkWhere(state, request.resource, args.where, [
238
- "arguments",
239
- "where",
240
- ]);
241
- if (issue !== undefined) {
242
- return issue;
243
- }
244
- }
245
- for (const mode of ["select", "include"]) {
246
- if (!(mode in args)) {
247
- continue;
248
- }
249
- const issue = walkProjection(state, request.resource, args[mode], mode, projectionScope, ["arguments", mode]);
250
- if (issue !== undefined) {
251
- return issue;
252
- }
253
- }
254
- if (request.family === "create" && "data" in args) {
255
- const entries = Array.isArray(args.data) ? args.data : [args.data];
256
- for (let index = 0; index < entries.length; index += 1) {
257
- const issue = walkMutationData(state, request.resource, entries[index], "create", Array.isArray(args.data)
258
- ? ["arguments", "data", index]
259
- : ["arguments", "data"]);
260
- if (issue !== undefined) {
261
- return issue;
262
- }
263
- }
264
- }
265
- if (request.family === "update" && "data" in args) {
266
- const issue = walkMutationData(state, request.resource, args.data, "update", ["arguments", "data"]);
267
- if (issue !== undefined) {
268
- return issue;
269
- }
270
- }
271
- if (request.family === "upsert") {
272
- for (const branch of ["create", "update"]) {
273
- if (!(branch in args)) {
274
- continue;
275
- }
276
- const issue = walkMutationData(state, request.resource, args[branch], branch, ["arguments", branch]);
277
- if (issue !== undefined) {
278
- return issue;
279
- }
280
- }
281
- }
282
- return undefined;
283
- }
@@ -1,8 +0,0 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import type { ValidationIssue } from "./validation-code.js";
3
- /**
4
- * Enforces the Contract's semantic nesting limit across where, projection,
5
- * orderBy, mutation data, and relation traversal before deeper argument
6
- * validation.
7
- */
8
- export declare function findOperationNestingIssue(contract: Contract, resourceName: string, args: Readonly<Record<string, unknown>>): ValidationIssue | undefined;