@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
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  The Aventara framework itself: the framework factory (`createFramework`), configuration and its resolution, the
4
4
  adapter interfaces an ORM adapter implements, Contract compilation and identity, validation, operation semantics, the
5
- pipeline runtime, transactions and execution. Its HTTP protocol — passive data and pure functions; it mounts nothing —
6
- is the separate entry point `@aventara/core/protocol`, which hosts such as `@aventara/nest` serve.
5
+ pipeline runtime, transactions and execution. Its HTTP protocol is the separate entry point `@aventara/core/protocol`,
6
+ which hosts such as `@aventara/nest` serve. The protocol is passive data and pure functions, and it mounts nothing.
7
7
 
8
- Core is ORM- and transport-agnostic: it imports neither Prisma nor NestJS. An application uses it through an adapter
9
- (`@aventara/prisma7-adapter`) and a host (`@aventara/nest`), and the usual way to set that up is the CLI.
8
+ Core imports neither Prisma nor NestJS. An application uses it through an adapter (`@aventara/prisma7-adapter`) and a
9
+ host (`@aventara/nest`), and the usual way to set that up is the CLI.
10
10
 
11
11
  ## Install
12
12
 
@@ -20,17 +20,17 @@ Node `^22.18.0 || >=24.2.0`. ES modules, with a CommonJS `default` condition.
20
20
 
21
21
  ## Documentation
22
22
 
23
- Start from the `@aventara/cli` README (what `new` and `init` write), then `@aventara/nest` (mounting a `Framework`)
24
- and `@aventara/prisma7-adapter` (the Prisma 7 adapter and its generate step); each package's README ships in its
23
+ Start from the `@aventara/cli` README (what `new` and `init` write), then `@aventara/nest` (mounting an `AvFramework`)
24
+ and `@aventara/prisma7-adapter` (the Prisma 7 adapter and its generate step). Each package's README ships in its
25
25
  tarball and shows on its npm page.
26
26
 
27
27
  ## Typed Json fields
28
28
 
29
- A `Json` field is any JSON by default. To give it a shape, build one with `AvZ` from `@aventara/core/json` and declare
30
- it on the field in the configuration:
29
+ A `Json` field is any JSON by default. To give it a shape, build one with `AvZ` from `@aventara/core/avz` and declare
30
+ it as the field's `definition.json` in the configuration's `resources` tree:
31
31
 
32
32
  ```ts
33
- import { AvZ } from "@aventara/core/json";
33
+ import { AvZ } from "@aventara/core/avz";
34
34
 
35
35
  const postMeta = AvZ.object({
36
36
  seo: AvZ.object({ title: AvZ.string(), keywords: AvZ.array(AvZ.string()) }),
@@ -42,86 +42,253 @@ const postMeta = AvZ.object({
42
42
  export type PostMeta = AvZ.infer<typeof postMeta>;
43
43
 
44
44
  const framework = await createFramework({
45
- entrypoint: "/api",
45
+ api: "/api",
46
46
  adapter,
47
- fields: { Post: { meta: { json: postMeta } } },
47
+ resources: { Post: { fields: { meta: { definition: { json: postMeta } } } } },
48
48
  });
49
49
  ```
50
50
 
51
- - **Typed.** `framework.application`, `framework.client`, `appTx` and `clientTx` read and write `Post.meta` as
52
- `PostMeta`, not as generic JSON, and so does a client generated with `avclient` (it emits the type; it needs no
53
- Zod).
54
- - **Checked on every write.** A create, update, upsert, nested write or transaction step that writes `meta` — a value
55
- a transaction step takes from an earlier step included — is checked against the shape before the database is
56
- asked. A value out of shape is refused with `A2004`, one issue per problem at its exact path:
51
+ `framework.application`, `framework.client`, `appTx` and `clientTx` read and write `Post.meta` as `PostMeta` instead
52
+ of generic JSON. So does a client generated with `avclient`, which emits the type and needs no Zod.
57
53
 
58
- ```json
59
- { "code": "V1001", "path": ["arguments", "data", "meta", "seo", "title"], "message": "Value must be a string." }
60
- ```
54
+ The shape is also one of `meta`'s validators. Every write of `meta` is checked against it before the database is
55
+ asked: a create, update, upsert, nested write or transaction step, including a value a transaction step takes from an
56
+ earlier step. It is checked where validators run, after every pipe and before any interceptor or hook, and its issues
57
+ come in field order with the other validators'. A value out of shape is refused with `A2004`, one issue per problem at its
58
+ exact path:
59
+
60
+ ```json
61
+ { "code": "V1001", "path": ["arguments", "data", "meta", "seo", "title"], "message": "Value must be a string." }
62
+ ```
63
+
64
+ A missing key is `V1000`, a value outside an enum or a literal `V1002`, an integer outside the safe range `V1004`,
65
+ and a key the shape does not declare `V1005`, once per key. Reads and filters are never checked against a shape, so
66
+ rows written before the shape existed stay readable.
67
+
68
+ `AvZ` has `string`, `number`, `int`, `boolean`, `null`, `literal`, `enum`, `object`, `array`, `tuple`, `record`,
69
+ `union`, `discriminatedUnion`, `optional` and `nullable`. A shape node takes checks with `.check(...)`: a string takes
70
+ length, pattern and format checks, a number or an integer takes bounds and `multipleOf`, and an array takes
71
+ `AvZ.minItems`/`AvZ.maxItems`, as in `AvZ.string().check(AvZ.maxLength(80))`. There are no refinements, transforms or
72
+ defaults. Objects are closed: a key the shape does not declare is refused. `optional` marks an object key that may be
73
+ left out.
74
+
75
+ Only a field the adapter discovered as `Json` takes a shape. The shape cannot admit `null` or absence at its top
76
+ level; whether the field may be `null` comes from your schema. A shape is built with `AvZ` only. A Zod schema is
77
+ refused, both as a type error and when the framework starts.
61
78
 
62
- A missing key is `V1000`, a value outside an enum or a literal `V1002`, an integer outside the safe range `V1004`,
63
- and a key the shape does not declare `V1005`, once per key. Reads and filters are never checked against a shape, so
64
- rows written before the shape existed stay readable.
65
- - **Types only.** `AvZ` has `string`, `number`, `int`, `boolean`, `null`, `literal`, `enum`, `object`, `array`,
66
- `tuple`, `record`, `union`, `discriminatedUnion`, `optional` and `nullable` — no lengths, ranges, patterns,
67
- refinements, transforms or defaults. Objects are closed: a key the shape does not declare is refused. `optional`
68
- marks an object key that may be left out.
69
- - **Where it applies.** Only a field the adapter discovered as `Json` takes a shape, and the shape itself cannot admit
70
- `null` or absence at its top level — whether the field may be `null` comes from your schema. A shape is built with
71
- `AvZ` only: a Zod schema is not accepted, as a type error and when the framework starts.
72
- - **In the Contract.** The shape is part of the ClientContract, as JSON Schema; adding or changing one changes the
73
- ClientContract hash, so regenerate the client.
79
+ The shape is part of the ClientContract, as JSON Schema. Adding or changing one changes the ClientContract hash, so
80
+ regenerate the client.
74
81
 
75
82
  The shape types `AvZShape`, `AvZObject`, `AvZOptional` and `AvZNullable` are exported so a project that emits
76
83
  declarations can name the shapes it exports.
77
84
 
78
- `@aventara/core/json` is the only entry that loads Zod (`zod/mini`); an application that declares no shape never loads
85
+ `@aventara/core/avz` is the only entry that loads Zod (`zod/mini`); an application that declares no shape never loads
79
86
  it.
80
87
 
88
+ ## Server-side calls resolve their data and throw their failures
89
+
90
+ `framework.application`, `framework.client`, `framework.transaction([...])` and a pipeline's `ctx` calls settle the way
91
+ a generated client does: they resolve the data (a row, a list, a count, `null` for a `first` that matched nothing; a
92
+ committed transaction its steps' results in order) and throw every failure as the `AvError` subclass of its code's
93
+ class, exported from `@aventara/core`:
94
+
95
+ ```ts
96
+ import { AvNotFoundError, AvValidationError } from "@aventara/core";
97
+
98
+ try {
99
+ const post = await framework.application.Post.update.unique({ where: { id }, data: { title } });
100
+ } catch (error) {
101
+ if (error instanceof AvNotFoundError) return null; // A2003
102
+ if (error instanceof AvValidationError) throw badRequest(error.cause.issues);
103
+ throw error;
104
+ }
105
+ ```
106
+
107
+ | Class | Codes |
108
+ | ------------------------- | ------------------------------------------- |
109
+ | `AvProtocolError` | A2000, A2001, A2002, A2006, A2010–A2012 |
110
+ | `AvNotFoundError` | A2003 |
111
+ | `AvValidationError` | A2004, A2007, A2009 |
112
+ | `AvContractMismatchError` | A2005 |
113
+ | `AvConflictError` | A2008, A2013, A2014 |
114
+ | `AvInternalError` | A3000–A3004 |
115
+ | `AvAuthError` | A4000–A4002 |
116
+
117
+ `error.code` and `error.cause` are the envelope's (a transaction's `cause.operation` names the failing step). The
118
+ generated client throws the same classes by the same table. `framework.execute` and `framework.executeTransaction`, the
119
+ entries a transport calls, still answer the envelope.
120
+
121
+ ## Required create fields are typed
122
+
123
+ Each Resource's Contract states what a create cannot do without (`createRequirements`), as the adapter reads it off
124
+ the database schema: the fields every create must write, and each required relation, which a create writes either as
125
+ the relation or through the fields that hold its reference, never both. The façades, `appTx`/`clientTx`, a stage's
126
+ `ctx` and the generated client type every create payload by it:
127
+
128
+ ```ts
129
+ await framework.application.Post.create.one({ data: { title: "Hi", authorId } }); // ok
130
+ await framework.application.Post.create.one({ data: { title: "Hi", author: { $connect: { id: authorId } } } }); // ok
131
+ // @ts-expect-error neither `author` nor `authorId`
132
+ await framework.application.Post.create.one({ data: { title: "Hi" } });
133
+ // @ts-expect-error `author` and `authorId` both
134
+ await framework.application.Post.create.one({ data: { title: "Hi", authorId, author: { $connect: { id: authorId } } } });
135
+ ```
136
+
137
+ It covers `create.one`'s `data`, every `create.many` record, `upsert`'s `create`, and nested `$create`,
138
+ `$connectOrCreate` and `$upsert` payloads, where the relation the create is nested through is supplied by its parent.
139
+ A `$ref` satisfies a field. Each layer's Contract states only what that layer lets a caller write: hide `authorId` and
140
+ `author` alone is required; hide `author` and `authorId` is. A field a `compute.create` stage fills is not required,
141
+ whether the stage is written inline in `createFramework({...})`, in a `defineResource` block or in a typed config.
142
+ The runtime still refuses what the types refuse (`A2004`, `V1000` or `V1012`).
143
+
144
+ A `create.many` or `create.count` record cannot write a relation, so there `authorId` is required. A layer that hides
145
+ `authorId` while it keeps those variants fails at startup (`COMPILER_HIDDEN_REQUIRED_FIELD`): expose `authorId`, give
146
+ it a `compute.create`, or exempt `create.many` and `create.count` in that layer
147
+ (`exemptions: { resources: { Post: { fields: { authorId: true }, operations: { create: ["many", "count"] } } } }`).
148
+
149
+ A field your operation pipe fills server-side is now required of the caller. Give it a `compute.create` stage (or a
150
+ database default) so callers can leave it out, or have them pass it.
151
+
152
+ ## Returning a façade from a method
153
+
154
+ A Nest project emits declarations (`declaration: true`), so a method without a return type has its type written out.
155
+ Every node of the typed façades has a name for that: a whole surface (`AvApplicationFacade`), one Resource
156
+ (`AvApplicationResourceFacade`), one family (`AvApplicationFamilyFacade`), and the same three for `client`, `appTx` and
157
+ `clientTx` (`AvClientFacade`, `AvAppTxResourceFacade`, …). The declaration writes the name, with the Contract view as
158
+ its argument, so this compiles:
159
+
160
+ ```ts
161
+ @Injectable()
162
+ export class PostsService {
163
+ constructor(@InjectFramework() private readonly framework: AppFramework) {}
164
+
165
+ posts() {
166
+ return this.framework.application.Post;
167
+ }
168
+ }
169
+ ```
170
+
171
+ The view is written out in full, about 400 KB of declaration per such method over 50 Resources. Give the method a
172
+ return type to keep it small: `AppFramework["application"]["Post"]` is written as that reference, about 0.2 KB.
173
+
174
+ ```ts
175
+ posts(): AppFramework["application"]["Post"] {
176
+ return this.framework.application.Post;
177
+ }
178
+ ```
179
+
180
+ A variant (`this.framework.application.Post.find.many`) is a call type the declaration cannot name: give that method a
181
+ return type, or return the call's result, whose row type is small. An application that publishes no declarations can
182
+ set `"declaration": false` and skip the question.
183
+
184
+ An exported `defineResource(...)` result, and an exported configuration or Framework builder holding typed stages,
185
+ need no annotation: their stages are written by their public types (`readonly AvGuard[]`, `readonly AvPipe[]`, …),
186
+ never with the model the inline stages were typed from.
187
+
81
188
  ## Server-side calls copy their input
82
189
 
83
190
  `framework.application`, `framework.client`, `framework.execute`, `framework.executeTransaction`, and the `appTx` /
84
191
  `clientTx` builders read what you pass them once, when you call them, and copy it into plain data the framework owns.
85
- Everything after that — validation, your guards and pipes, computed values, the adapter — sees only the copy:
86
-
87
- - **Changing your object afterwards changes nothing.** An Immer draft revoked after `produce`, or a reactive store that
88
- moves on, is safe to pass: the call already has its own copy.
89
- - **A live Proxy works** (Vue `reactive`, MobX): it is read through its traps once.
90
- - **`Date`, `Decimal` and `Uint8Array`** (a Node `Buffer` too) are copied as themselves; `bigint` and other primitives are
91
- values.
92
- - **Only plain data.** Arrays and plain objects (`{}` or `Object.create(null)`) are copied with their own enumerable
93
- string keys, like JSON: inherited, non-enumerable and symbol keys are dropped. Any other object — a class instance, a
94
- `Map` — is refused.
95
- - **A value that cannot be read** (a revoked Proxy, a getter that throws) is refused too. Both refusals are your
96
- request's error, not the server's: `A2004` with one `V1001` at the value's path — `["arguments", …]`, or
97
- `["operations", i, "args", …]` with `cause.operation` in a transaction — before any guard, pipe or adapter runs:
192
+ Validation, your guards and pipes, computed values and the adapter all see only the copy, and your stages see it
193
+ frozen: only a pipe changes the arguments, by returning new ones, so what the validators checked is what the adapter
194
+ writes. In practice:
195
+
196
+ - Changing your object afterwards changes nothing. An Immer draft revoked after `produce`, or a reactive store that
197
+ moves on, is safe to pass, because the call already has its own copy.
198
+ - A live Proxy (Vue `reactive`, MobX) works: it is read through its traps once.
199
+ - `Date`, `AvDecimal` and `Uint8Array` (a Node `Buffer` too) are copied as themselves; `bigint` and other primitives
200
+ are values.
201
+ - Arrays and plain objects (`{}` or `Object.create(null)`) are copied with their own enumerable string keys, like JSON:
202
+ inherited, non-enumerable and symbol keys are dropped. Any other object, such as a class instance or a `Map`, is
203
+ refused.
204
+ - A value that cannot be read (a revoked Proxy, a getter that throws) is refused too. Both refusals are errors in your
205
+ request, not the server's: `A2004` with one `V1001` at the value's path (`["arguments", …]`, or
206
+ `["operations", i, "args", …]` with `cause.operation` in a transaction), before any guard, pipe or adapter runs:
98
207
 
99
208
  ```json
100
209
  { "code": "V1001", "path": ["arguments", "where", "id"], "message": "Value could not be read." }
101
210
  ```
102
211
 
103
- A builder never throws: `appTx`/`clientTx` keep the refusal, and `framework.transaction([...])` answers it.
212
+ A builder never throws: `appTx`/`clientTx` keep the refusal, and `framework.transaction([...])` throws it as an
213
+ `AvValidationError`.
104
214
 
105
215
  To count these refusals, set `misuse` at the root of the configuration, beside `diagnostics`:
106
216
 
107
217
  ```ts
108
218
  const framework = await createFramework({
109
- entrypoint: "/api",
219
+ api: "/api",
110
220
  adapter,
111
221
  misuse: (event) => metrics.increment("aventara.misuse", { kind: event.kind }),
112
222
  });
113
223
  ```
114
224
 
115
- It receives one `FrameworkMisuseEvent` per refusal — `kind` (`"unreadable-value"` or `"non-plain-value"`), the `path`
116
- the caller received, and `origin`, `resource`, `family`, `variant` and the transaction step (`operation`) when they could
117
- be read — never the value itself. It cannot change the response: an error it throws, or a promise it rejects, is
118
- ignored. `diagnostics` keeps receiving the server's own unexpected failures, and nothing is reported to both.
225
+ It receives one `AvMisuseEvent` per refusal, never the value itself. The event has `kind` (`"unreadable-value"` or
226
+ `"non-plain-value"`), the `path` the caller received, and `origin`, `resource`, `family`, `variant` and the
227
+ transaction step (`operation`) when they could be read. It cannot change the response: an error it throws, or a
228
+ promise it rejects, is ignored. `diagnostics` keeps receiving the server's own unexpected failures, and nothing is
229
+ reported to both.
230
+
231
+ HTTP requests are not copied twice. A body that `protocol.handleOperation` / `handleTransaction` parse from raw content
232
+ (as `@aventara/nest` hands it to them) is already plain data. A body your host parsed itself, passed as
233
+ `{ kind: "parsed" }`, is copied like any server-side input.
234
+
235
+ ## Developer SQL in an application transaction
236
+
237
+ `framework.appTx.$sql` adds a SQL statement to an application transaction. It is written only as a tagged template, and
238
+ every interpolated value is a bound parameter, never part of the SQL text:
239
+
240
+ ```ts
241
+ const post = framework.appTx.Post.create.one({ data: { title, authorId }, select: ["id"] });
242
+ const job = framework.appTx.$sql<{ msg_id: bigint }>`
243
+ select pgmq.send('jobs', jsonb_build_object('postId', ${post.$ref("id")}))`;
244
+
245
+ const [created, rows] = await framework.transaction([post, job]);
246
+ // rows is { msg_id: bigint }[]; without <Row> it is unknown[]
247
+ ```
248
+
249
+ - The statement runs in plan order, in the same database transaction as the other steps. If it fails, or a later step
250
+ fails, everything rolls back.
251
+ - A value is a string, number, boolean, `bigint`, `null`, `Date`, `AvDecimal`, `Uint8Array`, a JSON value (a plain
252
+ object or array, bound as JSON text, so cast it: `${value}::jsonb`), or a `$ref` to an earlier step's field, which
253
+ is read after that step ran and then bound. Values are copied like every other input (see above).
254
+ - The SQL text is static. A table or column name cannot come from a value.
255
+ - A later step cannot `$ref` a SQL step's rows (`A2007`/`V1010`).
256
+ - No guard, pipe, hook, interceptor or filter runs around a SQL step. A SQL error is answered as the adapter
257
+ classifies it (a uniqueness or reference violation is `A2008`, anything else `A3001`).
258
+ - A stage's `ctx.$sql` runs the same bound template at once. Inside a transaction it joins it; outside one it is a plain
259
+ statement, with no transaction opened around it.
260
+ - It exists only here. `clientTx` has no `$sql`, the ClientContract carries nothing of it, and `/_transactions` cannot
261
+ express it. The adapter must support it (`@aventara/prisma7-adapter` does wherever it runs transactions); otherwise a
262
+ plan holding one is refused with `A2002`.
263
+
264
+ Aventara itself never writes raw SQL. This tagged template is the only way SQL reaches the database, and the SQL is
265
+ yours.
266
+
267
+ ## The agent layer
268
+
269
+ `agent` is a layer for calls an AI agent makes, served over MCP. It narrows the view of the layer it `extends`
270
+ (`"client"` when left out, or `"application"`, or `"root"`) and never widens it; its stages run after that layer's, and
271
+ each one sees `ctx.$origin === "agent"`:
272
+
273
+ ```ts
274
+ const framework = await createFramework({
275
+ api: "/api",
276
+ mcp: "/mcp",
277
+ adapter,
278
+ agent: {
279
+ exposed: true,
280
+ exemptions: { resources: { Post: { operations: { delete: true } } } },
281
+ pipelines: { guards: [(ctx) => ctx.$state.user !== undefined] },
282
+ },
283
+ });
284
+ ```
119
285
 
120
- HTTP requests cost nothing extra: a body that `protocol.handleOperation` / `handleTransaction` parse from raw content
121
- (as `@aventara/nest` hands it to them) is already plain data and is not copied again. A body your host parsed itself,
122
- passed as `{ kind: "parsed" }`, is copied like any server-side input.
286
+ It compiles to `framework.contracts.agent`, identified by its own hash, and `framework.mcp` is the resolved MCP
287
+ endpoint. A host runs agent calls through `AvProtocol.bind(framework, { origin: "agent" })`, which validates them
288
+ exactly as client calls are validated, against the Agent Contract.
123
289
 
124
290
  ## License
125
291
 
126
- PolyForm Shield 1.0.0 with an additional permission — free to use, including in commercial applications; you may not
127
- use it to build a product that competes with Aventara itself. See `LICENSE` and `LICENSE-ADDITIONAL-PERMISSION.md`.
292
+ PolyForm Shield 1.0.0 with an additional permission. It is free to use, including in commercial applications, but you
293
+ may not use it to build a product that competes with Aventara itself. See `LICENSE` and
294
+ `LICENSE-ADDITIONAL-PERMISSION.md`.
@@ -1,8 +1,8 @@
1
- /** Codes of {@link AdapterDiscoveryDiagnostic}. */
2
- export type AdapterDiscoveryDiagnosticCode = "DISCOVERY_TRANSACTION_CAPABILITY_MISMATCH";
1
+ /** Codes of {@link AvAdapterDiscoveryDiagnostic}. */
2
+ export type AvAdapterDiscoveryDiagnosticCode = "DISCOVERY_TRANSACTION_CAPABILITY_MISMATCH";
3
3
  /** A problem found in what the adapter discovered, reported at framework construction. */
4
- export type AdapterDiscoveryDiagnostic = {
5
- readonly code: AdapterDiscoveryDiagnosticCode;
4
+ export type AvAdapterDiscoveryDiagnostic = {
5
+ readonly code: AvAdapterDiscoveryDiagnosticCode;
6
6
  readonly path: "adapter.transactions";
7
7
  readonly message: string;
8
8
  };
@@ -1,29 +1,29 @@
1
- import type { RelationFieldCapabilities, ScalarFieldCapabilities, ScalarFormat } from "../contracts/field.js";
2
- import type { LifecycleTrait } from "../contracts/lifecycle-trait.js";
3
- import type { AdapterModel } from "./adapter-model.js";
1
+ import type { AvRelationFieldCapabilities, AvScalarFieldCapabilities, AvScalarFormat } from "../contracts/field.js";
2
+ import type { AvLifecycleTrait } from "../contracts/lifecycle-trait.js";
3
+ import type { AvAdapterModel } from "./adapter-model.js";
4
4
  /** Provider-observable lifecycle facts available during adapter discovery. */
5
- export type AdapterLifecycleTrait = Extract<LifecycleTrait, "DEFAULTED" | "GENERATED_ON_CREATE" | "GENERATED_ON_UPDATE">;
5
+ export type AvAdapterLifecycleTrait = Extract<AvLifecycleTrait, "DEFAULTED" | "GENERATED_ON_CREATE" | "GENERATED_ON_UPDATE">;
6
6
  /** Scalar-shaped provider field expressed only in Aventara vocabulary. */
7
- export type AdapterScalarField<M extends AdapterModel> = {
7
+ export type AvAdapterScalarField<M extends AvAdapterModel> = {
8
8
  readonly kind: "scalar";
9
9
  readonly type: {
10
10
  readonly scalar: Extract<keyof M["scalars"], string>;
11
11
  } | {
12
12
  readonly enum: Extract<keyof M["enums"], string>;
13
13
  };
14
- readonly format?: ScalarFormat;
14
+ readonly format?: AvScalarFormat;
15
15
  readonly nullable: boolean;
16
16
  readonly list: boolean;
17
- readonly lifecycle: readonly AdapterLifecycleTrait[];
18
- readonly capabilities: ScalarFieldCapabilities;
17
+ readonly lifecycle: readonly AvAdapterLifecycleTrait[];
18
+ readonly capabilities: AvScalarFieldCapabilities;
19
19
  };
20
20
  /** A discovered relation field; the `target` Resource describes the related row. */
21
- export type AdapterRelationField<M extends AdapterModel> = {
21
+ export type AvAdapterRelationField<M extends AvAdapterModel> = {
22
22
  readonly kind: "relation";
23
23
  readonly target: Extract<keyof M["resources"], string>;
24
24
  readonly cardinality: "one" | "many";
25
25
  readonly nullable: boolean;
26
- readonly capabilities: RelationFieldCapabilities;
26
+ readonly capabilities: AvRelationFieldCapabilities;
27
27
  };
28
28
  /** One field the adapter discovered: a scalar or a relation. */
29
- export type AdapterField<M extends AdapterModel> = AdapterScalarField<M> | AdapterRelationField<M>;
29
+ export type AvAdapterField<M extends AvAdapterModel> = AvAdapterScalarField<M> | AvAdapterRelationField<M>;
@@ -1,7 +1,7 @@
1
- import type { AdapterField } from "./adapter-field.js";
2
- import type { AdapterModel } from "./adapter-model.js";
1
+ import type { AvAdapterField } from "./adapter-field.js";
2
+ import type { AvAdapterModel } from "./adapter-model.js";
3
3
  /** Keys of `TFields` whose discovered field can be scalar-shaped. */
4
- export type AdapterScalarFieldKey<TFields extends Readonly<Record<string, AdapterField<AdapterModel>>>> = Extract<{
4
+ export type AvAdapterScalarFieldKey<TFields extends Readonly<Record<string, AvAdapterField<AvAdapterModel>>>> = Extract<{
5
5
  [K in keyof TFields]: [
6
6
  Extract<TFields[K], {
7
7
  readonly kind: "scalar";
@@ -9,7 +9,7 @@ export type AdapterScalarFieldKey<TFields extends Readonly<Record<string, Adapte
9
9
  ] extends [never] ? never : K;
10
10
  }[keyof TFields], string>;
11
11
  /** Non-empty scalar-field tuple discovered as provider uniqueness. */
12
- export type AdapterIdentifier<TFields extends Readonly<Record<string, AdapterField<AdapterModel>>>> = readonly [
13
- AdapterScalarFieldKey<TFields>,
14
- ...AdapterScalarFieldKey<TFields>[]
12
+ export type AvAdapterIdentifier<TFields extends Readonly<Record<string, AvAdapterField<AvAdapterModel>>>> = readonly [
13
+ AvAdapterScalarFieldKey<TFields>,
14
+ ...AvAdapterScalarFieldKey<TFields>[]
15
15
  ];
@@ -1,21 +1,21 @@
1
- import type { EnumDefinition } from "../contracts/enum-definition.js";
1
+ import type { AvEnumDefinition } from "../contracts/enum-definition.js";
2
2
  import type { ReferenceWriteLimit } from "../contracts/reference-write-limit.js";
3
- import type { ScalarRegistry } from "../contracts/scalar.js";
4
- import type { TransactionCapability } from "../contracts/transaction-capability.js";
5
- import type { AdapterResource } from "./adapter-resource.js";
3
+ import type { AvScalarRegistry } from "../contracts/scalar.js";
4
+ import type { AvTransactionCapability } from "../contracts/transaction-capability.js";
5
+ import type { AvAdapterResource } from "./adapter-resource.js";
6
6
  /**
7
7
  * Canonical provider-discovery facts before framework configuration or
8
8
  * Contract compilation is applied.
9
9
  */
10
- export interface AdapterModel {
10
+ export interface AvAdapterModel {
11
11
  /** The scalar types the data source supports. */
12
- readonly scalars: ScalarRegistry;
12
+ readonly scalars: AvScalarRegistry;
13
13
  /** The enums the data source declares, by name. */
14
- readonly enums: Readonly<Record<string, EnumDefinition>>;
14
+ readonly enums: Readonly<Record<string, AvEnumDefinition>>;
15
15
  /** The discovered Resources, by name. */
16
- readonly resources: Readonly<Record<string, AdapterResource<this>>>;
16
+ readonly resources: Readonly<Record<string, AvAdapterResource<this>>>;
17
17
  /** Whether the adapter can run interactive transactions. */
18
- readonly transactions: TransactionCapability;
18
+ readonly transactions: AvTransactionCapability;
19
19
  /**
20
20
  * `"uniform"` when the data source takes one record's references only one
21
21
  * way at a time: every relation that holds a reference written as a
@@ -1,10 +1,10 @@
1
- import type { AdapterModel } from "./adapter-model.js";
2
- import type { AdapterOperation } from "./adapter-operation.js";
1
+ import type { AvAdapterModel } from "./adapter-model.js";
2
+ import type { AvAdapterOperation } from "./adapter-operation.js";
3
3
  /**
4
4
  * Executes one operation against the provider, directly or inside a provider
5
5
  * transaction.
6
6
  */
7
- export interface AdapterOperationExecutor<M extends AdapterModel = AdapterModel> {
7
+ export interface AvAdapterOperationExecutor<M extends AvAdapterModel = AvAdapterModel> {
8
8
  /** Runs one validated operation and resolves its raw result. */
9
- execute(operation: AdapterOperation<M>): Promise<unknown>;
9
+ execute(operation: AvAdapterOperation<M>): Promise<unknown>;
10
10
  }
@@ -1,12 +1,12 @@
1
- import type { OperationIdentity } from "../operations/operation-identity.js";
1
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
2
2
  import type { SemanticOperationArguments } from "../operations/operation-validator.js";
3
- import type { AdapterModel } from "./adapter-model.js";
3
+ import type { AvAdapterModel } from "./adapter-model.js";
4
4
  /**
5
5
  * Provider execution request after framework semantic validation.
6
6
  * Operation identity and arguments remain provider-neutral; adapters receive
7
7
  * only validated semantic argument objects, never raw transport input.
8
8
  */
9
- export type AdapterOperation<M extends AdapterModel = AdapterModel> = OperationIdentity & {
9
+ export type AvAdapterOperation<M extends AvAdapterModel = AvAdapterModel> = AvOperationIdentity & {
10
10
  readonly resource: Extract<keyof M["resources"], string>;
11
11
  readonly arguments: SemanticOperationArguments;
12
12
  };
@@ -1,20 +1,29 @@
1
- import type { ResourceOperations } from "../contracts/resource-operations.js";
2
- import type { AdapterField } from "./adapter-field.js";
3
- import type { AdapterIdentifier } from "./adapter-identifier.js";
4
- import type { AdapterModel } from "./adapter-model.js";
1
+ import type { AvCreateRequirements } from "../contracts/create-requirements.js";
2
+ import type { AvResourceOperations } from "../contracts/resource-operations.js";
3
+ import type { AvAdapterField } from "./adapter-field.js";
4
+ import type { AvAdapterIdentifier } from "./adapter-identifier.js";
5
+ import type { AvAdapterModel } from "./adapter-model.js";
5
6
  /** A discovered Resource's fields, by name. */
6
- export type AdapterFieldMap<M extends AdapterModel> = Readonly<Record<string, AdapterField<M>>>;
7
+ export type AvAdapterFieldMap<M extends AvAdapterModel> = Readonly<Record<string, AvAdapterField<M>>>;
7
8
  /**
8
9
  * The field names the adapter discovered for Resource `R`, before any
9
10
  * configuration adds to them.
10
11
  */
11
- export type AdapterFieldKey<M extends AdapterModel, R extends Extract<keyof M["resources"], string>> = Extract<keyof M["resources"][R]["fields"], string>;
12
+ export type AvAdapterFieldKey<M extends AvAdapterModel, R extends Extract<keyof M["resources"], string>> = Extract<keyof M["resources"][R]["fields"], string>;
12
13
  /** Provider-discovered facts for one Aventara Resource candidate. */
13
- export type AdapterResource<M extends AdapterModel, TFields extends AdapterFieldMap<M> = AdapterFieldMap<M>> = {
14
+ export type AvAdapterResource<M extends AvAdapterModel, TFields extends AvAdapterFieldMap<M> = AvAdapterFieldMap<M>> = {
14
15
  /** The Resource's fields, by name. */
15
16
  readonly fields: TFields;
16
17
  /** The field tuples that identify at most one row. */
17
- readonly identifiers: readonly AdapterIdentifier<TFields>[];
18
+ readonly identifiers: readonly AvAdapterIdentifier<TFields>[];
18
19
  /** The standard operations the data source can run for this Resource. */
19
- readonly operations: ResourceOperations;
20
+ readonly operations: AvResourceOperations;
21
+ /**
22
+ * What a create cannot do without, in the store's own terms: every field it
23
+ * requires, every required to-one relation with its reference fields, and
24
+ * the relation (`parentSupplies`) through which a nested create gets them
25
+ * from its parent. Absent when it requires nothing, or when the adapter
26
+ * cannot say; nothing is then checked or typed before the store.
27
+ */
28
+ readonly createRequirements?: AvCreateRequirements;
20
29
  };
@@ -0,0 +1,19 @@
1
+ import type { AvDecimal } from "../runtime/decimal.js";
2
+ import type { AvJsonValue } from "../runtime/json-value.js";
3
+ /**
4
+ * One value a developer SQL statement binds, after every `$ref` in it was
5
+ * resolved: a primitive, a `Date`, a {@link AvDecimal}, a `Uint8Array`, or a
6
+ * plain object or array, which is a JSON value and is bound as JSON text. Never
7
+ * spliced into the statement's text.
8
+ */
9
+ export type AvAdapterSqlValue = string | number | boolean | bigint | null | Date | AvDecimal | Uint8Array | AvJsonValue;
10
+ /**
11
+ * One developer SQL statement, as `framework.appTx.$sql` wrote it: the static
12
+ * text of its tagged template, and the values written between those pieces, in
13
+ * order. `strings` holds exactly one entry more than `values`. The adapter binds
14
+ * every value as a parameter of the statement; no value ever becomes SQL text.
15
+ */
16
+ export type AvAdapterSqlStatement = {
17
+ readonly strings: readonly string[];
18
+ readonly values: readonly AvAdapterSqlValue[];
19
+ };
@@ -0,0 +1,19 @@
1
+ import type { AvAdapterModel } from "./adapter-model.js";
2
+ import type { AvAdapterOperationExecutor } from "./adapter-operation-executor.interface.js";
3
+ import type { AvAdapterSqlStatement } from "./adapter-sql-statement.js";
4
+ /**
5
+ * What an Adapter's `transaction` callback is handed: the transaction-scoped
6
+ * operation executor, and — when the Adapter declares `sqlStatements` — the
7
+ * statement runner `framework.appTx.$sql` steps run through.
8
+ */
9
+ export interface AvAdapterTransactionExecutor<M extends AvAdapterModel = AvAdapterModel> extends AvAdapterOperationExecutor<M> {
10
+ /**
11
+ * Runs one developer SQL statement on the open transaction, every value bound
12
+ * as a parameter, and resolves the rows it returned (none for a statement that
13
+ * returns no rows). Present exactly when the Adapter declares `sqlStatements`.
14
+ *
15
+ * A failure is thrown like an operation's: a deliberate `AvError` for
16
+ * an outcome the Adapter classified, anything else to be answered `A3001`.
17
+ */
18
+ executeSql?(statement: AvAdapterSqlStatement): Promise<readonly unknown[]>;
19
+ }