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

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 (338) hide show
  1. package/CHANGELOG.md +2068 -1
  2. package/ERRORS.md +142 -0
  3. package/README.md +485 -60
  4. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  5. package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
  6. package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
  7. package/dist/adapters/adapter-field.d.ts +33 -11
  8. package/dist/adapters/adapter-identifier.d.ts +15 -6
  9. package/dist/adapters/adapter-identifier.js +6 -1
  10. package/dist/adapters/adapter-model.d.ts +18 -9
  11. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  12. package/dist/adapters/adapter-operation.d.ts +21 -6
  13. package/dist/adapters/adapter-resource.d.ts +23 -9
  14. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  15. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  16. package/dist/adapters/adapter.interface.d.ts +59 -29
  17. package/dist/avz/avz-check.factory.d.ts +83 -0
  18. package/dist/avz/avz-check.factory.js +116 -0
  19. package/dist/avz/avz-check.registry.d.ts +35 -0
  20. package/dist/avz/avz-check.registry.js +9 -0
  21. package/dist/avz/avz.d.ts +203 -0
  22. package/dist/{json → avz}/avz.js +150 -8
  23. package/dist/{json → avz}/index.d.ts +2 -1
  24. package/dist/{json → avz}/json-shape.registry.d.ts +9 -8
  25. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  26. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  27. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  28. package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
  29. package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
  30. package/dist/compiler/contract.compiler.d.ts +23 -17
  31. package/dist/compiler/contract.compiler.js +753 -443
  32. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  33. package/dist/compiler/create-requirements.projector.js +423 -0
  34. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  35. package/dist/compiler/field-validator.compiler.js +238 -0
  36. package/dist/compiler/managed-elsewhere.projector.d.ts +52 -0
  37. package/dist/compiler/managed-elsewhere.projector.js +179 -0
  38. package/dist/compiler/managed-elsewhere.validator.d.ts +9 -0
  39. package/dist/compiler/managed-elsewhere.validator.js +74 -0
  40. package/dist/config/any-framework-config.d.ts +19 -12
  41. package/dist/config/computed-fields.d.ts +62 -0
  42. package/dist/config/computed-fields.js +73 -0
  43. package/dist/config/config-diagnostic.d.ts +11 -4
  44. package/dist/config/config-diagnostic.guidance.d.ts +6 -0
  45. package/dist/config/config-diagnostic.guidance.js +32 -0
  46. package/dist/config/config-layer.d.ts +15 -6
  47. package/dist/config/config.resolver.d.ts +98 -31
  48. package/dist/config/config.resolver.js +173 -44
  49. package/dist/config/config.validator.d.ts +7 -7
  50. package/dist/config/config.validator.js +792 -69
  51. package/dist/config/define-resource.d.ts +53 -0
  52. package/dist/config/define-resource.js +14 -0
  53. package/dist/config/effective-fields.d.ts +19 -23
  54. package/dist/config/entrypoint.normalizer.d.ts +4 -3
  55. package/dist/config/exact-framework-config.d.ts +325 -0
  56. package/dist/config/field-compute.resolver.d.ts +21 -0
  57. package/dist/config/field-compute.resolver.js +123 -0
  58. package/dist/config/field-pipeline-config.d.ts +47 -0
  59. package/dist/config/forced-operation.validator.d.ts +10 -0
  60. package/dist/config/forced-operation.validator.js +66 -0
  61. package/dist/config/framework-config.d.ts +148 -39
  62. package/dist/config/framework-exemptions-config.d.ts +91 -0
  63. package/dist/config/framework-exemptions-config.js +1 -0
  64. package/dist/config/framework-field-definition.d.ts +78 -0
  65. package/dist/config/framework-field-definition.js +28 -0
  66. package/dist/config/framework-resources-config.d.ts +127 -0
  67. package/dist/config/framework-resources-config.js +1 -0
  68. package/dist/config/pipeline-config.d.ts +56 -20
  69. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  70. package/dist/config/pipeline-tree.resolver.js +220 -0
  71. package/dist/config/stage-type.eraser.d.ts +65 -0
  72. package/dist/config/stage-type.eraser.js +1 -0
  73. package/dist/contracts/access-route.rules.d.ts +10 -0
  74. package/dist/contracts/access-route.rules.js +45 -0
  75. package/dist/contracts/capability.d.ts +37 -12
  76. package/dist/contracts/capability.js +20 -0
  77. package/dist/contracts/client-contract-structure.validator.d.ts +621 -114
  78. package/dist/contracts/client-contract-structure.validator.js +189 -10
  79. package/dist/contracts/contract-access.d.ts +29 -0
  80. package/dist/contracts/contract-access.js +1 -0
  81. package/dist/contracts/contract-canonicalizer.d.ts +27 -3
  82. package/dist/contracts/contract-canonicalizer.js +168 -29
  83. package/dist/contracts/contract-hash.d.ts +11 -7
  84. package/dist/contracts/contract-hash.js +4 -3
  85. package/dist/contracts/contract-limits.d.ts +4 -1
  86. package/dist/contracts/contract-limits.js +1 -0
  87. package/dist/contracts/contract-lookup.d.ts +5 -5
  88. package/dist/contracts/contract-protocol.d.ts +4 -4
  89. package/dist/contracts/contract.d.ts +51 -17
  90. package/dist/contracts/create-requirements.d.ts +35 -0
  91. package/dist/contracts/create-requirements.js +1 -0
  92. package/dist/contracts/enum-definition.d.ts +1 -1
  93. package/dist/contracts/field-check.d.ts +101 -0
  94. package/dist/contracts/field-check.js +1 -0
  95. package/dist/contracts/field.d.ts +109 -42
  96. package/dist/contracts/identifier.d.ts +4 -4
  97. package/dist/contracts/json-schema.projector.d.ts +11 -0
  98. package/dist/contracts/json-schema.projector.js +78 -0
  99. package/dist/contracts/json-shape.d.ts +12 -1
  100. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  101. package/dist/contracts/resource-operations.d.ts +28 -28
  102. package/dist/contracts/resource.d.ts +15 -9
  103. package/dist/contracts/scalar-value-type.d.ts +17 -15
  104. package/dist/contracts/scalar.d.ts +3 -3
  105. package/dist/contracts/transaction-capability.d.ts +1 -1
  106. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  107. package/dist/framework/access-facade.d.ts +116 -0
  108. package/dist/framework/access-facade.js +120 -0
  109. package/dist/framework/contract-view.d.ts +315 -145
  110. package/dist/framework/framework-construction.error.d.ts +21 -11
  111. package/dist/framework/framework-construction.error.js +20 -4
  112. package/dist/framework/framework.d.ts +71 -26
  113. package/dist/framework/framework.factory.d.ts +8 -6
  114. package/dist/framework/framework.factory.js +150 -38
  115. package/dist/framework/operation-facade.d.ts +192 -54
  116. package/dist/framework/operation-facade.js +10 -1
  117. package/dist/index.d.ts +67 -50
  118. package/dist/index.js +7 -6
  119. package/dist/internal.d.ts +20 -10
  120. package/dist/internal.js +9 -1
  121. package/dist/operations/database-refusal.d.ts +51 -0
  122. package/dist/operations/database-refusal.js +45 -0
  123. package/dist/operations/operation-arguments.d.ts +381 -228
  124. package/dist/operations/operation-call.d.ts +31 -28
  125. package/dist/operations/operation-identity.d.ts +10 -10
  126. package/dist/operations/operation-result.d.ts +25 -23
  127. package/dist/operations/operation-validator-core.d.ts +6 -6
  128. package/dist/operations/operation-validator-core.js +172 -38
  129. package/dist/operations/operation-validator.d.ts +10 -10
  130. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  131. package/dist/operations/structural-limits.walker.d.ts +7 -7
  132. package/dist/operations/structural-limits.walker.js +145 -0
  133. package/dist/operations/validation-code.d.ts +11 -6
  134. package/dist/operations/validation-code.guidance.d.ts +6 -0
  135. package/dist/operations/validation-code.guidance.js +90 -0
  136. package/dist/operations/validation-code.js +4 -0
  137. package/dist/operations/write-scope.resolver.d.ts +10 -6
  138. package/dist/operations/write-scope.resolver.js +2 -0
  139. package/dist/policy/access-provider.interface.d.ts +91 -0
  140. package/dist/policy/access-provider.interface.js +1 -0
  141. package/dist/policy/access-provider.registry.d.ts +17 -0
  142. package/dist/policy/access-provider.registry.js +15 -0
  143. package/dist/policy/access-question.d.ts +20 -0
  144. package/dist/policy/access-question.js +1 -0
  145. package/dist/policy/access-question.registry.d.ts +5 -0
  146. package/dist/policy/access-question.registry.js +19 -0
  147. package/dist/policy/access-question.runtime.d.ts +36 -0
  148. package/dist/policy/access-question.runtime.js +297 -0
  149. package/dist/policy/access-verb.table.d.ts +56 -0
  150. package/dist/policy/access-verb.table.js +21 -0
  151. package/dist/policy/access-verbs.d.ts +46 -0
  152. package/dist/policy/access-verbs.js +1 -0
  153. package/dist/policy/policy-admission.d.ts +20 -0
  154. package/dist/policy/policy-admission.js +409 -0
  155. package/dist/policy/policy-after-update.runtime.d.ts +79 -0
  156. package/dist/policy/policy-after-update.runtime.js +208 -0
  157. package/dist/policy/policy-condition.d.ts +15 -0
  158. package/dist/policy/policy-condition.js +36 -0
  159. package/dist/policy/policy-engine.d.ts +205 -0
  160. package/dist/policy/policy-engine.js +1 -0
  161. package/dist/policy/policy-named-rows.d.ts +18 -0
  162. package/dist/policy/policy-named-rows.js +51 -0
  163. package/dist/policy/policy-nested-write.runtime.d.ts +44 -0
  164. package/dist/policy/policy-nested-write.runtime.js +545 -0
  165. package/dist/policy/policy-read.runtime.d.ts +81 -0
  166. package/dist/policy/policy-read.runtime.js +503 -0
  167. package/dist/policy/policy-reference-write.runtime.d.ts +51 -0
  168. package/dist/policy/policy-reference-write.runtime.js +345 -0
  169. package/dist/policy/policy-request.d.ts +41 -0
  170. package/dist/policy/policy-request.js +63 -0
  171. package/dist/policy/policy-session.d.ts +106 -0
  172. package/dist/policy/policy-session.js +295 -0
  173. package/dist/policy/policy-startup.validator.d.ts +10 -0
  174. package/dist/policy/policy-startup.validator.js +112 -0
  175. package/dist/policy/policy-write.runtime.d.ts +39 -0
  176. package/dist/policy/policy-write.runtime.js +532 -0
  177. package/dist/prebuilt/core-version.generated.d.ts +2 -0
  178. package/dist/prebuilt/core-version.generated.js +1 -0
  179. package/dist/prebuilt/prebuilt-changes.d.ts +29 -0
  180. package/dist/prebuilt/prebuilt-changes.js +65 -0
  181. package/dist/prebuilt/prebuilt-contracts.d.ts +40 -0
  182. package/dist/prebuilt/prebuilt-contracts.emitter.d.ts +16 -0
  183. package/dist/prebuilt/prebuilt-contracts.emitter.js +50 -0
  184. package/dist/prebuilt/prebuilt-contracts.js +1 -0
  185. package/dist/prebuilt/prebuilt-contracts.loader.d.ts +19 -0
  186. package/dist/prebuilt/prebuilt-contracts.loader.js +77 -0
  187. package/dist/prebuilt/prebuilt-inputs.fingerprint.d.ts +16 -0
  188. package/dist/prebuilt/prebuilt-inputs.fingerprint.js +229 -0
  189. package/dist/protocol/absent-route.responder.d.ts +17 -34
  190. package/dist/protocol/absent-route.responder.js +53 -20
  191. package/dist/protocol/contract-document.responder.d.ts +5 -4
  192. package/dist/protocol/contract-document.responder.js +2 -2
  193. package/dist/protocol/http-request.decoder.d.ts +33 -13
  194. package/dist/protocol/http-request.decoder.js +34 -11
  195. package/dist/protocol/http-request.reader.d.ts +9 -6
  196. package/dist/protocol/http-request.reader.js +1 -0
  197. package/dist/protocol/http-response.encoder.d.ts +4 -4
  198. package/dist/protocol/http-response.encoder.js +94 -55
  199. package/dist/protocol/http-status.table.d.ts +2 -2
  200. package/dist/protocol/operation-response.guard.d.ts +2 -2
  201. package/dist/protocol/protocol-headers.d.ts +3 -3
  202. package/dist/protocol/protocol-surface.d.ts +10 -5
  203. package/dist/protocol/protocol-surface.js +7 -0
  204. package/dist/protocol/protocol.binder.d.ts +66 -28
  205. package/dist/protocol/protocol.binder.js +16 -10
  206. package/dist/protocol/protocol.handler.d.ts +34 -14
  207. package/dist/protocol/protocol.handler.js +122 -18
  208. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  209. package/dist/protocol/unmounted-route.error.js +2 -2
  210. package/dist/runtime/caller-data.copier.d.ts +22 -7
  211. package/dist/runtime/caller-data.copier.js +30 -17
  212. package/dist/runtime/caller-data.door.d.ts +18 -11
  213. package/dist/runtime/caller-data.door.js +6 -4
  214. package/dist/runtime/computed-read-runtime.d.ts +12 -6
  215. package/dist/runtime/computed-read-runtime.js +271 -71
  216. package/dist/runtime/computed-value.error.d.ts +7 -6
  217. package/dist/runtime/computed-value.error.js +5 -4
  218. package/dist/runtime/context-executor.runtime.d.ts +60 -0
  219. package/dist/runtime/context-executor.runtime.js +277 -0
  220. package/dist/runtime/core-class.brand.d.ts +10 -0
  221. package/dist/runtime/core-class.brand.js +21 -0
  222. package/dist/runtime/create-requirement.d.ts +34 -79
  223. package/dist/runtime/create-requirement.js +205 -74
  224. package/dist/runtime/decimal.d.ts +16 -2
  225. package/dist/runtime/decimal.js +22 -1
  226. package/dist/runtime/diagnostics-reporter.d.ts +91 -30
  227. package/dist/runtime/diagnostics-reporter.js +37 -1
  228. package/dist/runtime/error-boundary.d.ts +73 -9
  229. package/dist/runtime/error-boundary.js +57 -19
  230. package/dist/runtime/error-guidance.d.ts +12 -0
  231. package/dist/runtime/error-guidance.js +1 -0
  232. package/dist/runtime/error.catalog.d.ts +49 -0
  233. package/dist/runtime/error.catalog.js +49 -0
  234. package/dist/runtime/execution-options.d.ts +18 -2
  235. package/dist/runtime/field-check.evaluator.d.ts +27 -0
  236. package/dist/runtime/field-check.evaluator.js +521 -0
  237. package/dist/runtime/field-compute.d.ts +65 -0
  238. package/dist/runtime/field-compute.js +1 -0
  239. package/dist/runtime/field-stage.plan.d.ts +15 -0
  240. package/dist/runtime/field-stage.plan.js +27 -0
  241. package/dist/runtime/field-stage.runtime.d.ts +37 -0
  242. package/dist/runtime/field-stage.runtime.js +147 -0
  243. package/dist/runtime/field-validator.runtime.d.ts +29 -0
  244. package/dist/runtime/field-validator.runtime.js +126 -0
  245. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  246. package/dist/runtime/framework-error-class.table.js +25 -0
  247. package/dist/runtime/framework-error.d.ts +68 -8
  248. package/dist/runtime/framework-error.factory.d.ts +4 -0
  249. package/dist/runtime/framework-error.factory.js +15 -0
  250. package/dist/runtime/framework-error.js +32 -2
  251. package/dist/runtime/framework-warning.emitter.d.ts +6 -0
  252. package/dist/runtime/framework-warning.emitter.js +8 -0
  253. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  254. package/dist/runtime/interceptor-next.error.js +6 -0
  255. package/dist/runtime/json-value.d.ts +11 -6
  256. package/dist/runtime/level-lifecycle.runtime.d.ts +26 -0
  257. package/dist/runtime/level-lifecycle.runtime.js +40 -0
  258. package/dist/runtime/misuse-reporter.d.ts +12 -12
  259. package/dist/runtime/mutation-planner.d.ts +20 -16
  260. package/dist/runtime/mutation-planner.js +48 -35
  261. package/dist/runtime/nested-write.walker.d.ts +32 -0
  262. package/dist/runtime/nested-write.walker.js +73 -0
  263. package/dist/runtime/operation-code.guidance.d.ts +6 -0
  264. package/dist/runtime/operation-code.guidance.js +167 -0
  265. package/dist/runtime/operation-request.d.ts +45 -11
  266. package/dist/runtime/operation-response.d.ts +17 -17
  267. package/dist/runtime/operation-runtime.d.ts +133 -27
  268. package/dist/runtime/operation-runtime.js +576 -84
  269. package/dist/runtime/outcome-mapper.d.ts +17 -5
  270. package/dist/runtime/outcome-mapper.js +23 -6
  271. package/dist/runtime/output-validator.d.ts +11 -11
  272. package/dist/runtime/output-validator.js +3 -3
  273. package/dist/runtime/owned-execution.registry.d.ts +16 -6
  274. package/dist/runtime/pipe-output.validator.d.ts +43 -18
  275. package/dist/runtime/pipe-output.validator.js +15 -13
  276. package/dist/runtime/pipeline.d.ts +221 -34
  277. package/dist/runtime/readonly-value.d.ts +47 -0
  278. package/dist/runtime/readonly-value.js +189 -0
  279. package/dist/runtime/referential-action.d.ts +1 -1
  280. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  281. package/dist/runtime/request-envelope.validator.js +12 -7
  282. package/dist/runtime/request-id.d.ts +1 -1
  283. package/dist/runtime/request-state.d.ts +14 -0
  284. package/dist/runtime/request-state.js +1 -0
  285. package/dist/runtime/request-state.resolver.d.ts +12 -0
  286. package/dist/runtime/request-state.resolver.js +20 -0
  287. package/dist/runtime/scalar-runtime.d.ts +33 -25
  288. package/dist/runtime/scalar-runtime.js +105 -38
  289. package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
  290. package/dist/runtime/unsent-value.normalizer.js +128 -0
  291. package/dist/transactions/deferred-operation.d.ts +35 -20
  292. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  293. package/dist/transactions/operation-arguments-encoder.js +8 -3
  294. package/dist/transactions/operation-fingerprint.js +2 -2
  295. package/dist/transactions/sql-statement.d.ts +85 -0
  296. package/dist/transactions/sql-statement.js +47 -0
  297. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  298. package/dist/transactions/sql-statement.validator.js +167 -0
  299. package/dist/transactions/transaction-envelope.d.ts +9 -8
  300. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  301. package/dist/transactions/transaction-integrity-error.js +7 -2
  302. package/dist/transactions/transaction-plan-assembler.d.ts +30 -13
  303. package/dist/transactions/transaction-plan-assembler.js +184 -32
  304. package/dist/transactions/transaction-plan-validator.d.ts +50 -25
  305. package/dist/transactions/transaction-plan-validator.js +96 -38
  306. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  307. package/dist/transactions/transaction-reference-resolver.d.ts +21 -3
  308. package/dist/transactions/transaction-reference-resolver.js +26 -14
  309. package/dist/transactions/transaction-reference-validator.d.ts +74 -4
  310. package/dist/transactions/transaction-reference-validator.js +129 -71
  311. package/dist/transactions/transaction-reference.d.ts +14 -14
  312. package/dist/transactions/transaction-reference.js +5 -0
  313. package/dist/transactions/transaction-request.d.ts +22 -9
  314. package/dist/transactions/transaction-response.d.ts +6 -6
  315. package/dist/transactions/transaction-runtime.d.ts +12 -8
  316. package/dist/transactions/transaction-runtime.js +218 -50
  317. package/dist/transactions/transaction-settlement.runtime.d.ts +52 -0
  318. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  319. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  320. package/dist/transactions/transaction-slot-path-error.js +4 -2
  321. package/dist/transactions/transaction-slot-writer.js +2 -2
  322. package/dist/transactions/transaction-stage.runtime.d.ts +83 -0
  323. package/dist/transactions/transaction-stage.runtime.js +126 -0
  324. package/package.json +11 -9
  325. package/src/runtime/field-check.evaluator.ts +720 -0
  326. package/dist/config/define-fields.d.ts +0 -42
  327. package/dist/config/define-fields.js +0 -3
  328. package/dist/config/framework-behaviors-config.d.ts +0 -30
  329. package/dist/config/framework-fields-config.d.ts +0 -42
  330. package/dist/config/framework-restrictions-config.d.ts +0 -142
  331. package/dist/json/avz.d.ts +0 -96
  332. package/dist/runtime/field-behavior.d.ts +0 -48
  333. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  334. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  335. /package/dist/{json → avz}/index.js +0 -0
  336. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  337. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  338. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -0,0 +1,85 @@
1
+ import type { AvAdapterSqlValue } from "../adapters/adapter-sql-statement.js";
2
+ import type { AvContract } from "../contracts/contract.js";
3
+ import type { AvScalarField } from "../contracts/field.js";
4
+ import type { AvCallerDataError } from "../runtime/caller-data.copier.js";
5
+ import type { AvOperation } from "./deferred-operation.js";
6
+ import type { AvTransactionReference } from "./transaction-reference.js";
7
+ /**
8
+ * One value an `appTx.$sql` template binds: a primitive, a `Date`, an `AvDecimal`, a
9
+ * `Uint8Array`, a JSON value (a plain object or array, bound as JSON text — cast it,
10
+ * `${value}::jsonb`), or a `$ref` to an earlier step's field, resolved when the
11
+ * earlier steps have run and then bound like any other value.
12
+ */
13
+ export type AvSqlStatementValue = AvAdapterSqlValue | AvTransactionReference;
14
+ /**
15
+ * `framework.appTx.$sql`: a developer SQL step, written only as a tagged template —
16
+ * ``framework.appTx.$sql`select pgmq.send('jobs', jsonb_build_object('id', ${ref}))` ``.
17
+ * Every interpolated value is bound as a parameter, never spliced into the text, so
18
+ * the text is static: a table or column name cannot come from a value.
19
+ *
20
+ * The step runs in plan order inside the same database transaction as the other
21
+ * steps; its entry in the committed `data` is the rows the statement returned,
22
+ * typed `Row[]` (`unknown[]` unless `Row` is given). A later step cannot `$ref` a
23
+ * SQL step's rows. No guard, pipe, hook, interceptor or filter runs around it: it
24
+ * has no Resource or operation for one to wrap.
25
+ */
26
+ export type AvSqlStatementBuilder = <Row = unknown>(strings: TemplateStringsArray, ...values: readonly AvSqlStatementValue[]) => AvOperation<Row[], "application">;
27
+ /** One value of a planned SQL step, as the typed runner bound it. */
28
+ export type PlannedSqlValue = {
29
+ readonly kind: "value";
30
+ readonly value: unknown;
31
+ }
32
+ /** A `$ref` placeholder standing as the whole value: the source's position and field. */
33
+ | {
34
+ readonly kind: "reference";
35
+ readonly operation: number;
36
+ readonly field: string;
37
+ }
38
+ /**
39
+ * A whole value that is a `$ref` control object the caller wrote, mirrored at
40
+ * the builder: validated as an operation step's reference is.
41
+ */
42
+ | {
43
+ readonly kind: "candidate";
44
+ readonly candidate: unknown;
45
+ }
46
+ /** A `$ref` placeholder found inside a value, at `path` within it: refused. */
47
+ | {
48
+ readonly kind: "misplaced-reference";
49
+ readonly path: readonly (string | number)[];
50
+ };
51
+ /**
52
+ * A SQL step as the typed runner hands it to the validator, unvalidated: the
53
+ * template's static text (`undefined` when the call was no genuine tagged
54
+ * template), its values with each `$ref` bound to its source's position, or why the
55
+ * builder could not copy the values.
56
+ */
57
+ export type PlannedSqlStatement = {
58
+ readonly strings: readonly string[] | undefined;
59
+ readonly values: readonly PlannedSqlValue[];
60
+ readonly refused?: AvCallerDataError;
61
+ };
62
+ /** One validated value of a SQL step: bound as it is, or resolved from a `$ref`. */
63
+ export type ValidatedSqlValue = {
64
+ readonly kind: "value";
65
+ readonly value: AvAdapterSqlValue;
66
+ } | {
67
+ readonly kind: "reference";
68
+ readonly operation: number;
69
+ readonly field: string;
70
+ /** The source field, under its own step's Contract: what the value is read as. */
71
+ readonly source: AvScalarField<AvContract>;
72
+ };
73
+ /** A SQL step the Framework Validation Layer accepted. */
74
+ export type ValidatedSqlStatement = {
75
+ readonly kind: "sql";
76
+ readonly index: number;
77
+ readonly strings: readonly string[];
78
+ readonly values: readonly ValidatedSqlValue[];
79
+ };
80
+ /**
81
+ * The static text of a genuine tagged template, read once and copied, or
82
+ * `undefined` when `strings` is not one or does not fit `valueCount` values.
83
+ * Total: a hostile value is `undefined`, never a throw.
84
+ */
85
+ export declare function readSqlTemplate(strings: unknown, valueCount: number): readonly string[] | undefined;
@@ -0,0 +1,47 @@
1
+ function ownData(target, key) {
2
+ const descriptor = Object.getOwnPropertyDescriptor(target, key);
3
+ return descriptor !== undefined && "value" in descriptor
4
+ ? descriptor.value
5
+ : undefined;
6
+ }
7
+ function frozenStrings(value, length) {
8
+ if (!Array.isArray(value) || !Object.isFrozen(value)) {
9
+ return undefined;
10
+ }
11
+ const size = ownData(value, "length");
12
+ if (typeof size !== "number" ||
13
+ size < 1 ||
14
+ (length !== undefined && size !== length)) {
15
+ return undefined;
16
+ }
17
+ const strings = [];
18
+ for (let index = 0; index < size; index += 1) {
19
+ const entry = ownData(value, String(index));
20
+ if (typeof entry !== "string") {
21
+ return undefined;
22
+ }
23
+ strings.push(entry);
24
+ }
25
+ return strings;
26
+ }
27
+ export function readSqlTemplate(strings, valueCount) {
28
+ try {
29
+ if (typeof strings !== "object" || strings === null) {
30
+ return undefined;
31
+ }
32
+ const raw = Object.getOwnPropertyDescriptor(strings, "raw");
33
+ if (raw === undefined || raw.enumerable || !("value" in raw)) {
34
+ return undefined;
35
+ }
36
+ const cooked = frozenStrings(strings, valueCount + 1);
37
+ if (cooked === undefined) {
38
+ return undefined;
39
+ }
40
+ return frozenStrings(raw.value, cooked.length) === undefined
41
+ ? undefined
42
+ : Object.freeze(cooked);
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
@@ -0,0 +1,44 @@
1
+ import type { AvAdapterSqlValue } from "../adapters/adapter-sql-statement.js";
2
+ import type { AvValidationIssue } from "../operations/validation-code.js";
3
+ import type { MisuseReporter } from "../runtime/misuse-reporter.js";
4
+ import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
5
+ import type { PlannedSqlStatement, ValidatedSqlStatement } from "./sql-statement.js";
6
+ import type { ValidatedTransactionStep } from "./transaction-plan-validator.js";
7
+ type Path = readonly (string | number)[];
8
+ type SqlStatementValidation = {
9
+ readonly ok: true;
10
+ readonly statement: ValidatedSqlStatement;
11
+ } | {
12
+ readonly ok: false;
13
+ readonly response: AvOperationFailureResponse;
14
+ };
15
+ /** What validating a SQL step needs from the plan around it. */
16
+ type SqlStatementValidationContext = {
17
+ /** The step's position in the plan. */
18
+ readonly index: number;
19
+ /** The steps validated before it, by position. */
20
+ readonly earlier: readonly ValidatedTransactionStep[];
21
+ /** Whether the Adapter declares `sqlStatements`. */
22
+ readonly available: boolean;
23
+ readonly misuse: MisuseReporter;
24
+ };
25
+ /**
26
+ * One bindable value of a SQL step, in its runtime form, or the issues that refuse
27
+ * it: a primitive (a `number` only when finite), a valid `Date`, an `AvDecimal`, a
28
+ * `Uint8Array`, or a JSON value — a plain object or array, held to the same rules
29
+ * as a `json` field's value. `undefined` and anything else are no value to bind.
30
+ */
31
+ export declare function normalizeSqlValue(value: unknown, path: Path): {
32
+ readonly ok: true;
33
+ readonly value: AvAdapterSqlValue;
34
+ } | {
35
+ readonly ok: false;
36
+ readonly issues: readonly AvValidationIssue[];
37
+ };
38
+ /**
39
+ * Validates one SQL step: the Adapter runs SQL statements, the call was a genuine
40
+ * tagged template, its values could be copied, every value is bindable, and every
41
+ * `$ref` stands as a whole value and reads one field of an earlier single-row step.
42
+ */
43
+ export declare function validateSqlStatement(statement: PlannedSqlStatement, context: SqlStatementValidationContext): SqlStatementValidation;
44
+ export {};
@@ -0,0 +1,167 @@
1
+ import { validationIssue } from "../operations/validation-code.js";
2
+ import { AvCallerDataError, locateCallerDataError, } from "../runtime/caller-data.copier.js";
3
+ import { refuseCallerData } from "../runtime/caller-data.door.js";
4
+ import { isAvDecimal } from "../runtime/decimal.js";
5
+ import { planStepPath } from "../runtime/error-boundary.js";
6
+ import { operationFailure } from "../runtime/operation-response.js";
7
+ import { mapValidationOutcome } from "../runtime/outcome-mapper.js";
8
+ import { isPlainRecord, normalizeJsonValue, } from "../runtime/scalar-runtime.js";
9
+ import { inspectReferenceCandidate, invalidSourceIndexIssue, referenceSourceAt, referenceSourceField, } from "./transaction-reference-validator.js";
10
+ import { transactionOperationFailure } from "./transaction-response.js";
11
+ function refused(issue, index) {
12
+ return {
13
+ ok: false,
14
+ response: transactionOperationFailure(mapValidationOutcome([issue]), index),
15
+ };
16
+ }
17
+ export function normalizeSqlValue(value, path) {
18
+ if (value === null ||
19
+ typeof value === "string" ||
20
+ typeof value === "boolean" ||
21
+ typeof value === "bigint" ||
22
+ isAvDecimal(value) ||
23
+ value instanceof Uint8Array) {
24
+ return { ok: true, value };
25
+ }
26
+ if (typeof value === "number") {
27
+ return Number.isFinite(value)
28
+ ? { ok: true, value }
29
+ : {
30
+ ok: false,
31
+ issues: [
32
+ validationIssue("V1004", path, "Value must be a finite number."),
33
+ ],
34
+ };
35
+ }
36
+ if (value instanceof Date) {
37
+ return Number.isNaN(value.getTime())
38
+ ? {
39
+ ok: false,
40
+ issues: [
41
+ validationIssue("V1003", path, "Value must use a valid Date value."),
42
+ ],
43
+ }
44
+ : { ok: true, value };
45
+ }
46
+ if (Array.isArray(value) || isPlainRecord(value)) {
47
+ const json = normalizeJsonValue(value, path, new Set());
48
+ return json.ok
49
+ ? { ok: true, value: json.value }
50
+ : { ok: false, issues: json.issues };
51
+ }
52
+ return {
53
+ ok: false,
54
+ issues: [
55
+ validationIssue("V1001", path, "Value must be a string, number, boolean, bigint, null, Date, Decimal, Uint8Array or JSON value."),
56
+ ],
57
+ };
58
+ }
59
+ export function validateSqlStatement(statement, context) {
60
+ const { index } = context;
61
+ if (!context.available) {
62
+ const message = "SQL statements are not available on this Adapter.";
63
+ return {
64
+ ok: false,
65
+ response: transactionOperationFailure(operationFailure("A2002", {
66
+ message,
67
+ issues: [validationIssue("V1006", [], message)],
68
+ }), index),
69
+ };
70
+ }
71
+ if (statement.strings === undefined) {
72
+ return refused(validationIssue("V1001", ["strings"], "SQL must be written as a tagged template: framework.appTx.$sql`…`."), index);
73
+ }
74
+ if (statement.refused !== undefined) {
75
+ return refused(refuseCallerData(statement.refused, [...planStepPath(index), "values"], { origin: "application", operation: index }, context.misuse), index);
76
+ }
77
+ try {
78
+ return validateSqlValues(statement, statement.strings, context);
79
+ }
80
+ catch (error) {
81
+ if (!(error instanceof AvCallerDataError)) {
82
+ throw error;
83
+ }
84
+ return refused(refuseCallerData(locateCallerDataError(error, statement.values.map((planned) => planned.kind === "value"
85
+ ? planned.value
86
+ : planned.kind === "candidate"
87
+ ? planned.candidate
88
+ : undefined)), [...planStepPath(index), "values"], { origin: "application", operation: index }, context.misuse), index);
89
+ }
90
+ }
91
+ function validateSqlValues(statement, strings, context) {
92
+ const { index, earlier } = context;
93
+ const values = [];
94
+ const issues = [];
95
+ for (const [position, planned] of statement.values.entries()) {
96
+ const path = ["values", position];
97
+ switch (planned.kind) {
98
+ case "misplaced-reference":
99
+ return refused(validationIssue("V1010", [...path, ...planned.path, "$ref"], "A transaction reference in a SQL step must be a whole value."), index);
100
+ case "candidate": {
101
+ const inspection = inspectReferenceCandidate(planned.candidate, path, earlier, index);
102
+ if (!inspection.ok) {
103
+ return refused(inspection.issue, index);
104
+ }
105
+ if (inspection.field.kind !== "scalar" || inspection.field.list) {
106
+ return refused(validationIssue("V1011", inspection.pathPath, "Transaction reference source is not a single scalar field."), index);
107
+ }
108
+ values.push({
109
+ kind: "reference",
110
+ operation: inspection.source.index,
111
+ field: inspection.segment,
112
+ source: inspection.field,
113
+ });
114
+ break;
115
+ }
116
+ case "reference": {
117
+ const source = referenceSourceAt(earlier, planned.operation, index);
118
+ if (source === undefined) {
119
+ return refused(invalidSourceIndexIssue([...path, "$ref", "operation"]), index);
120
+ }
121
+ const read = referenceSourceField(source, planned.field, [
122
+ ...path,
123
+ "$ref",
124
+ "path",
125
+ ]);
126
+ if (!read.ok) {
127
+ return refused(read.issue, index);
128
+ }
129
+ if (read.field.kind !== "scalar" || read.field.list) {
130
+ return refused(validationIssue("V1011", [...path, "$ref", "path"], "Transaction reference source is not a single scalar field."), index);
131
+ }
132
+ values.push({
133
+ kind: "reference",
134
+ operation: planned.operation,
135
+ field: planned.field,
136
+ source: read.field,
137
+ });
138
+ break;
139
+ }
140
+ case "value": {
141
+ const normalized = normalizeSqlValue(planned.value, path);
142
+ if (normalized.ok) {
143
+ values.push({ kind: "value", value: normalized.value });
144
+ }
145
+ else {
146
+ issues.push(...normalized.issues);
147
+ }
148
+ break;
149
+ }
150
+ }
151
+ }
152
+ if (issues.length > 0) {
153
+ return {
154
+ ok: false,
155
+ response: transactionOperationFailure(mapValidationOutcome(issues), index),
156
+ };
157
+ }
158
+ return {
159
+ ok: true,
160
+ statement: {
161
+ kind: "sql",
162
+ index,
163
+ strings,
164
+ values,
165
+ },
166
+ };
167
+ }
@@ -1,31 +1,31 @@
1
- import type { ValidationIssue } from "../operations/validation-code.js";
2
- export type TransactionEnvelopeSchema = {
1
+ import type { AvValidationIssue } from "../operations/validation-code.js";
2
+ type TransactionEnvelopeSchema = {
3
3
  readonly required: readonly string[];
4
4
  readonly optional?: readonly string[];
5
5
  readonly invalidContainerPath: readonly (string | number)[];
6
6
  readonly invalidContainerMessage: string;
7
7
  };
8
- export type TransactionEnvelopeInspection = {
8
+ type TransactionEnvelopeInspection = {
9
9
  readonly ok: true;
10
10
  readonly values: ReadonlyMap<string, unknown>;
11
11
  } | {
12
12
  readonly ok: false;
13
- readonly issue: ValidationIssue;
13
+ readonly issue: AvValidationIssue;
14
14
  };
15
- export type TransactionOperationsInspection = {
15
+ type TransactionOperationsInspection = {
16
16
  readonly ok: true;
17
17
  readonly value: object;
18
18
  readonly length: number;
19
19
  } | {
20
20
  readonly ok: false;
21
- readonly issue: ValidationIssue;
21
+ readonly issue: AvValidationIssue;
22
22
  };
23
- export type TransactionOperationEntryInspection = {
23
+ type TransactionOperationEntryInspection = {
24
24
  readonly ok: true;
25
25
  readonly value: unknown;
26
26
  } | {
27
27
  readonly ok: false;
28
- readonly issue: ValidationIssue;
28
+ readonly issue: AvValidationIssue;
29
29
  };
30
30
  /**
31
31
  * The caller uses the returned length and per-index inspector rather than
@@ -39,3 +39,4 @@ export declare function inspectTransactionOperationEntry(operations: object, ind
39
39
  * Proxies are unsupported; reflection failures are contained as envelope issues.
40
40
  */
41
41
  export declare function inspectTransactionEnvelope(value: unknown, schema: TransactionEnvelopeSchema): TransactionEnvelopeInspection;
42
+ export {};
@@ -1,13 +1,13 @@
1
1
  /**
2
- * The ways an Adapter transaction can break the framework's transaction
3
- * contract. Each is answered `A3002`.
2
+ * The ways an Adapter transaction, or a stage running inside it, can break the
3
+ * framework's transaction contract. Each is answered `A3002` and rolls back.
4
4
  */
5
- export type TransactionIntegrityViolation = "transaction-unavailable" | "resolved-after-abort" | "resolved-incomplete" | "foreign-abort";
5
+ export type AvTransactionIntegrityViolation = "transaction-unavailable" | "resolved-after-abort" | "resolved-incomplete" | "foreign-abort" | "statement-unavailable" | "next-called-twice" | "steps-not-run";
6
6
  /**
7
7
  * Reported to diagnostics when an Adapter transaction breaks the framework's
8
8
  * transaction contract. The caller receives `A3002`.
9
9
  */
10
- export declare class TransactionIntegrityError extends Error {
11
- readonly violation: TransactionIntegrityViolation;
12
- constructor(violation: TransactionIntegrityViolation);
10
+ export declare class AvTransactionIntegrityError extends Error {
11
+ readonly violation: AvTransactionIntegrityViolation;
12
+ constructor(violation: AvTransactionIntegrityViolation);
13
13
  }
@@ -1,14 +1,19 @@
1
+ import { brandCoreClass } from "../runtime/core-class.brand.js";
1
2
  const TRANSACTION_INTEGRITY_MESSAGES = {
2
3
  "transaction-unavailable": "Adapter transaction function is unavailable.",
3
4
  "resolved-after-abort": "Adapter transaction resolved after the framework requested rollback.",
4
5
  "resolved-incomplete": "Adapter transaction resolved before the plan completed.",
5
6
  "foreign-abort": "Adapter transaction rejected with a rollback request this plan never made.",
7
+ "statement-unavailable": "Adapter declares sqlStatements but its transaction executor has no executeSql.",
8
+ "next-called-twice": "A transaction interceptor called next() more than once; next() runs the plan's steps once.",
9
+ "steps-not-run": "A transaction interceptor resolved without calling next(); the plan's steps never ran.",
6
10
  };
7
- export class TransactionIntegrityError extends Error {
11
+ export class AvTransactionIntegrityError extends Error {
8
12
  violation;
9
13
  constructor(violation) {
10
14
  super(TRANSACTION_INTEGRITY_MESSAGES[violation]);
11
- this.name = "TransactionIntegrityError";
15
+ this.name = "AvTransactionIntegrityError";
12
16
  this.violation = violation;
13
17
  }
14
18
  }
19
+ brandCoreClass(AvTransactionIntegrityError, "AvTransactionIntegrityError");
@@ -1,12 +1,16 @@
1
- import type { FrameworkContracts } from "../compiler/contract.compiler.js";
2
- import type { RequestOrigin } from "../config/config-layer.js";
3
- import type { OperationIdentity } from "../operations/operation-identity.js";
4
- import type { CallerDataError } from "../runtime/caller-data.copier.js";
1
+ import type { AvContracts } from "../compiler/contract.compiler.js";
2
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
3
+ import { AvCallerDataError } from "../runtime/caller-data.copier.js";
5
4
  import type { MisuseReporter } from "../runtime/misuse-reporter.js";
6
- import type { ClientProtocolIdentity } from "../runtime/operation-request.js";
7
- import type { OperationFailureResponse } from "../runtime/operation-response.js";
8
- import type { Operation, OperationFingerprint } from "./deferred-operation.js";
5
+ import type { AvRequestProtocol } from "../runtime/operation-request.js";
6
+ import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
7
+ import type { AvOperation, OperationFingerprint } from "./deferred-operation.js";
8
+ import type { PlannedSqlStatement } from "./sql-statement.js";
9
9
  import type { TransactionOperationOrigin } from "./transaction-request.js";
10
+ /** The origin a handle's builder gives it. */
11
+ type HandleOrigin = "application" | "client";
12
+ /** The scalar forms a builder takes its arguments in. */
13
+ type ArgumentForms = "wire" | "application";
10
14
  /** One wire node, exactly as the transaction runtime receives it. */
11
15
  type WireOperationNode = {
12
16
  readonly resource: string;
@@ -15,22 +19,35 @@ type WireOperationNode = {
15
19
  readonly args: unknown;
16
20
  readonly fingerprint: OperationFingerprint | null;
17
21
  };
22
+ declare const SQL_STEP_NODE: Readonly<{
23
+ fingerprint: null;
24
+ }>;
25
+ type PlanNode = WireOperationNode | typeof SQL_STEP_NODE;
18
26
  export type AssembledTransactionPlan = {
19
27
  readonly ok: true;
20
28
  readonly plan: {
21
- readonly operations: readonly WireOperationNode[];
29
+ readonly operations: readonly PlanNode[];
22
30
  };
23
31
  /** Each operation's own origin, by index (mixed plans). */
24
32
  readonly origins: readonly TransactionOperationOrigin[];
25
33
  /** The steps whose arguments their builder could not copy, by index. */
26
- readonly refused: ReadonlyMap<number, CallerDataError>;
34
+ readonly refused: ReadonlyMap<number, AvCallerDataError>;
35
+ /** The `appTx.$sql` steps, by index, with each `$ref` bound to its source's position. */
36
+ readonly statements: ReadonlyMap<number, PlannedSqlStatement>;
27
37
  } | {
28
38
  readonly ok: false;
29
- readonly response: OperationFailureResponse;
39
+ readonly response: AvOperationFailureResponse;
30
40
  };
31
41
  export type TransactionPlanAssembler = {
32
- /** Defers one operation into a handle; nothing runs. */
33
- defer(origin: RequestOrigin, resource: string, identity: OperationIdentity, args: unknown): Operation<unknown>;
42
+ /**
43
+ * Defers one operation into a handle; nothing runs. `forms` says which scalar
44
+ * forms a client-origin handle's arguments are in: `"wire"` (`clientTx`, the
45
+ * default) or `"application"` (`serverClientTx`), encoded into the wire forms
46
+ * from the builder's copy.
47
+ */
48
+ defer(origin: HandleOrigin, resource: string, identity: AvOperationIdentity, args: unknown, forms?: ArgumentForms): AvOperation<unknown>;
49
+ /** Defers one `appTx.$sql` statement into a handle; nothing runs. */
50
+ deferSql(strings: unknown, values: readonly unknown[]): AvOperation<unknown>;
34
51
  /** Binds a list of handles into the passive plan, or refuses it. */
35
52
  assemble(operations: unknown): Promise<AssembledTransactionPlan>;
36
53
  };
@@ -39,5 +56,5 @@ export type TransactionPlanAssembler = {
39
56
  * handle, so a handle another instance built — typed against another model,
40
57
  * bound to other Contracts — is refused rather than run.
41
58
  */
42
- export declare function createTransactionPlanAssembler(contracts: FrameworkContracts, protocol: ClientProtocolIdentity, misuse: MisuseReporter): TransactionPlanAssembler;
59
+ export declare function createTransactionPlanAssembler(contracts: AvContracts, protocol: AvRequestProtocol, misuse: MisuseReporter): TransactionPlanAssembler;
43
60
  export {};