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

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 (267) hide show
  1. package/CHANGELOG.md +1434 -0
  2. package/ERRORS.md +142 -0
  3. package/README.md +247 -57
  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 +25 -11
  8. package/dist/adapters/adapter-identifier.d.ts +6 -6
  9. package/dist/adapters/adapter-model.d.ts +18 -9
  10. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  11. package/dist/adapters/adapter-operation.d.ts +3 -3
  12. package/dist/adapters/adapter-resource.d.ts +18 -9
  13. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  14. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  15. package/dist/adapters/adapter.interface.d.ts +59 -29
  16. package/dist/avz/avz-check.factory.d.ts +83 -0
  17. package/dist/avz/avz-check.factory.js +116 -0
  18. package/dist/avz/avz-check.registry.d.ts +35 -0
  19. package/dist/avz/avz-check.registry.js +9 -0
  20. package/dist/avz/avz.d.ts +203 -0
  21. package/dist/{json → avz}/avz.js +150 -8
  22. package/dist/{json → avz}/index.d.ts +2 -1
  23. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  24. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  25. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  26. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  27. package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
  28. package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
  29. package/dist/compiler/contract.compiler.d.ts +18 -18
  30. package/dist/compiler/contract.compiler.js +637 -442
  31. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  32. package/dist/compiler/create-requirements.projector.js +423 -0
  33. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  34. package/dist/compiler/field-validator.compiler.js +238 -0
  35. package/dist/config/any-framework-config.d.ts +19 -12
  36. package/dist/config/computed-fields.d.ts +62 -0
  37. package/dist/config/computed-fields.js +80 -0
  38. package/dist/config/config-diagnostic.d.ts +11 -4
  39. package/dist/config/config-diagnostic.guidance.d.ts +6 -0
  40. package/dist/config/config-diagnostic.guidance.js +32 -0
  41. package/dist/config/config-layer.d.ts +15 -6
  42. package/dist/config/config.resolver.d.ts +74 -31
  43. package/dist/config/config.resolver.js +108 -44
  44. package/dist/config/config.validator.d.ts +7 -7
  45. package/dist/config/config.validator.js +581 -72
  46. package/dist/config/define-resource.d.ts +57 -0
  47. package/dist/config/define-resource.js +14 -0
  48. package/dist/config/effective-fields.d.ts +19 -23
  49. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  50. package/dist/config/exact-framework-config.d.ts +308 -0
  51. package/dist/config/field-compute.resolver.d.ts +21 -0
  52. package/dist/config/field-compute.resolver.js +123 -0
  53. package/dist/config/field-pipeline-config.d.ts +47 -0
  54. package/dist/config/forced-operation.validator.d.ts +10 -0
  55. package/dist/config/forced-operation.validator.js +66 -0
  56. package/dist/config/framework-config.d.ts +111 -39
  57. package/dist/config/framework-exemptions-config.d.ts +91 -0
  58. package/dist/config/framework-exemptions-config.js +1 -0
  59. package/dist/config/framework-field-definition.d.ts +78 -0
  60. package/dist/config/framework-field-definition.js +28 -0
  61. package/dist/config/framework-resources-config.d.ts +122 -0
  62. package/dist/config/framework-resources-config.js +1 -0
  63. package/dist/config/pipeline-config.d.ts +56 -20
  64. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  65. package/dist/config/pipeline-tree.resolver.js +220 -0
  66. package/dist/config/stage-type.eraser.d.ts +65 -0
  67. package/dist/config/stage-type.eraser.js +1 -0
  68. package/dist/contracts/capability.d.ts +21 -12
  69. package/dist/contracts/capability.js +2 -0
  70. package/dist/contracts/client-contract-structure.validator.d.ts +388 -63
  71. package/dist/contracts/client-contract-structure.validator.js +156 -10
  72. package/dist/contracts/contract-canonicalizer.d.ts +26 -3
  73. package/dist/contracts/contract-canonicalizer.js +156 -29
  74. package/dist/contracts/contract-hash.d.ts +12 -7
  75. package/dist/contracts/contract-hash.js +3 -2
  76. package/dist/contracts/contract-limits.d.ts +4 -1
  77. package/dist/contracts/contract-limits.js +1 -0
  78. package/dist/contracts/contract-lookup.d.ts +5 -5
  79. package/dist/contracts/contract-protocol.d.ts +4 -4
  80. package/dist/contracts/contract.d.ts +24 -16
  81. package/dist/contracts/create-requirements.d.ts +35 -0
  82. package/dist/contracts/create-requirements.js +1 -0
  83. package/dist/contracts/enum-definition.d.ts +1 -1
  84. package/dist/contracts/field-check.d.ts +101 -0
  85. package/dist/contracts/field-check.js +1 -0
  86. package/dist/contracts/field.d.ts +81 -42
  87. package/dist/contracts/identifier.d.ts +4 -4
  88. package/dist/contracts/json-shape.d.ts +12 -1
  89. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  90. package/dist/contracts/resource-operations.d.ts +28 -28
  91. package/dist/contracts/resource.d.ts +15 -9
  92. package/dist/contracts/scalar-value-type.d.ts +15 -15
  93. package/dist/contracts/scalar.d.ts +3 -3
  94. package/dist/contracts/transaction-capability.d.ts +1 -1
  95. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  96. package/dist/framework/contract-view.d.ts +213 -147
  97. package/dist/framework/framework-construction.error.d.ts +19 -10
  98. package/dist/framework/framework-construction.error.js +7 -3
  99. package/dist/framework/framework.d.ts +47 -23
  100. package/dist/framework/framework.factory.d.ts +8 -6
  101. package/dist/framework/framework.factory.js +49 -22
  102. package/dist/framework/operation-facade.d.ts +123 -52
  103. package/dist/framework/operation-facade.js +9 -1
  104. package/dist/index.d.ts +57 -50
  105. package/dist/index.js +7 -6
  106. package/dist/internal.d.ts +17 -10
  107. package/dist/internal.js +4 -1
  108. package/dist/operations/database-refusal.d.ts +51 -0
  109. package/dist/operations/database-refusal.js +45 -0
  110. package/dist/operations/operation-arguments.d.ts +343 -207
  111. package/dist/operations/operation-call.d.ts +27 -28
  112. package/dist/operations/operation-identity.d.ts +10 -10
  113. package/dist/operations/operation-result.d.ts +21 -21
  114. package/dist/operations/operation-validator-core.d.ts +6 -6
  115. package/dist/operations/operation-validator-core.js +99 -6
  116. package/dist/operations/operation-validator.d.ts +9 -9
  117. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  118. package/dist/operations/structural-limits.walker.d.ts +6 -6
  119. package/dist/operations/structural-limits.walker.js +145 -0
  120. package/dist/operations/validation-code.d.ts +11 -6
  121. package/dist/operations/validation-code.guidance.d.ts +6 -0
  122. package/dist/operations/validation-code.guidance.js +90 -0
  123. package/dist/operations/validation-code.js +4 -0
  124. package/dist/operations/write-scope.resolver.d.ts +10 -6
  125. package/dist/operations/write-scope.resolver.js +2 -0
  126. package/dist/protocol/absent-route.responder.d.ts +13 -12
  127. package/dist/protocol/absent-route.responder.js +19 -19
  128. package/dist/protocol/contract-document.responder.d.ts +3 -3
  129. package/dist/protocol/contract-document.responder.js +2 -2
  130. package/dist/protocol/http-request.decoder.d.ts +17 -13
  131. package/dist/protocol/http-request.decoder.js +10 -10
  132. package/dist/protocol/http-request.reader.d.ts +3 -3
  133. package/dist/protocol/http-response.encoder.d.ts +4 -4
  134. package/dist/protocol/http-response.encoder.js +94 -55
  135. package/dist/protocol/http-status.table.d.ts +2 -2
  136. package/dist/protocol/operation-response.guard.d.ts +2 -2
  137. package/dist/protocol/protocol-surface.d.ts +4 -4
  138. package/dist/protocol/protocol.binder.d.ts +50 -27
  139. package/dist/protocol/protocol.binder.js +12 -9
  140. package/dist/protocol/protocol.handler.d.ts +22 -13
  141. package/dist/protocol/protocol.handler.js +91 -17
  142. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  143. package/dist/protocol/unmounted-route.error.js +2 -2
  144. package/dist/runtime/caller-data.copier.d.ts +22 -5
  145. package/dist/runtime/caller-data.copier.js +31 -14
  146. package/dist/runtime/caller-data.door.d.ts +17 -11
  147. package/dist/runtime/caller-data.door.js +6 -4
  148. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  149. package/dist/runtime/computed-read-runtime.js +76 -50
  150. package/dist/runtime/computed-value.error.d.ts +7 -6
  151. package/dist/runtime/computed-value.error.js +5 -4
  152. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  153. package/dist/runtime/context-executor.runtime.js +275 -0
  154. package/dist/runtime/create-requirement.d.ts +44 -79
  155. package/dist/runtime/create-requirement.js +213 -73
  156. package/dist/runtime/decimal.d.ts +2 -2
  157. package/dist/runtime/decimal.js +1 -1
  158. package/dist/runtime/diagnostics-reporter.d.ts +54 -27
  159. package/dist/runtime/diagnostics-reporter.js +24 -0
  160. package/dist/runtime/error-boundary.d.ts +65 -8
  161. package/dist/runtime/error-boundary.js +49 -19
  162. package/dist/runtime/error-guidance.d.ts +12 -0
  163. package/dist/runtime/error-guidance.js +1 -0
  164. package/dist/runtime/error.catalog.d.ts +49 -0
  165. package/dist/runtime/error.catalog.js +49 -0
  166. package/dist/runtime/execution-options.d.ts +10 -2
  167. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  168. package/dist/runtime/field-check.evaluator.js +521 -0
  169. package/dist/runtime/field-compute.d.ts +64 -0
  170. package/dist/runtime/field-compute.js +1 -0
  171. package/dist/runtime/field-stage.plan.d.ts +15 -0
  172. package/dist/runtime/field-stage.plan.js +27 -0
  173. package/dist/runtime/field-stage.runtime.d.ts +37 -0
  174. package/dist/runtime/field-stage.runtime.js +147 -0
  175. package/dist/runtime/field-validator.runtime.d.ts +19 -0
  176. package/dist/runtime/field-validator.runtime.js +92 -0
  177. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  178. package/dist/runtime/framework-error-class.table.js +25 -0
  179. package/dist/runtime/framework-error.d.ts +68 -8
  180. package/dist/runtime/framework-error.factory.d.ts +4 -0
  181. package/dist/runtime/framework-error.factory.js +15 -0
  182. package/dist/runtime/framework-error.js +23 -2
  183. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  184. package/dist/runtime/interceptor-next.error.js +6 -0
  185. package/dist/runtime/json-value.d.ts +11 -6
  186. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  187. package/dist/runtime/level-lifecycle.runtime.js +39 -0
  188. package/dist/runtime/misuse-reporter.d.ts +12 -12
  189. package/dist/runtime/mutation-planner.d.ts +19 -10
  190. package/dist/runtime/mutation-planner.js +48 -35
  191. package/dist/runtime/nested-write.walker.d.ts +32 -0
  192. package/dist/runtime/nested-write.walker.js +73 -0
  193. package/dist/runtime/operation-code.guidance.d.ts +6 -0
  194. package/dist/runtime/operation-code.guidance.js +167 -0
  195. package/dist/runtime/operation-request.d.ts +33 -6
  196. package/dist/runtime/operation-response.d.ts +17 -17
  197. package/dist/runtime/operation-runtime.d.ts +127 -25
  198. package/dist/runtime/operation-runtime.js +441 -78
  199. package/dist/runtime/outcome-mapper.d.ts +16 -5
  200. package/dist/runtime/outcome-mapper.js +23 -6
  201. package/dist/runtime/output-validator.d.ts +10 -10
  202. package/dist/runtime/output-validator.js +3 -3
  203. package/dist/runtime/owned-execution.registry.d.ts +16 -6
  204. package/dist/runtime/pipe-output.validator.d.ts +43 -18
  205. package/dist/runtime/pipe-output.validator.js +15 -13
  206. package/dist/runtime/pipeline.d.ts +223 -34
  207. package/dist/runtime/readonly-value.d.ts +43 -0
  208. package/dist/runtime/readonly-value.js +150 -0
  209. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  210. package/dist/runtime/request-envelope.validator.js +12 -7
  211. package/dist/runtime/request-id.d.ts +1 -1
  212. package/dist/runtime/request-state.d.ts +14 -0
  213. package/dist/runtime/request-state.js +1 -0
  214. package/dist/runtime/request-state.resolver.d.ts +12 -0
  215. package/dist/runtime/request-state.resolver.js +20 -0
  216. package/dist/runtime/scalar-runtime.d.ts +35 -16
  217. package/dist/runtime/scalar-runtime.js +102 -34
  218. package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
  219. package/dist/runtime/unsent-value.normalizer.js +128 -0
  220. package/dist/transactions/deferred-operation.d.ts +35 -20
  221. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  222. package/dist/transactions/operation-arguments-encoder.js +2 -2
  223. package/dist/transactions/operation-fingerprint.js +2 -2
  224. package/dist/transactions/sql-statement.d.ts +85 -0
  225. package/dist/transactions/sql-statement.js +47 -0
  226. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  227. package/dist/transactions/sql-statement.validator.js +167 -0
  228. package/dist/transactions/transaction-envelope.d.ts +4 -4
  229. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  230. package/dist/transactions/transaction-integrity-error.js +5 -2
  231. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  232. package/dist/transactions/transaction-plan-assembler.js +169 -32
  233. package/dist/transactions/transaction-plan-validator.d.ts +45 -20
  234. package/dist/transactions/transaction-plan-validator.js +96 -38
  235. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  236. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  237. package/dist/transactions/transaction-reference-resolver.js +26 -14
  238. package/dist/transactions/transaction-reference-validator.d.ts +76 -4
  239. package/dist/transactions/transaction-reference-validator.js +129 -71
  240. package/dist/transactions/transaction-reference.d.ts +13 -13
  241. package/dist/transactions/transaction-reference.js +5 -0
  242. package/dist/transactions/transaction-request.d.ts +18 -5
  243. package/dist/transactions/transaction-response.d.ts +6 -6
  244. package/dist/transactions/transaction-runtime.d.ts +8 -7
  245. package/dist/transactions/transaction-runtime.js +191 -50
  246. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  247. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  248. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  249. package/dist/transactions/transaction-slot-path-error.js +2 -2
  250. package/dist/transactions/transaction-slot-writer.js +2 -2
  251. package/dist/transactions/transaction-stage.runtime.d.ts +82 -0
  252. package/dist/transactions/transaction-stage.runtime.js +126 -0
  253. package/package.json +9 -7
  254. package/src/runtime/field-check.evaluator.ts +720 -0
  255. package/dist/config/define-fields.d.ts +0 -42
  256. package/dist/config/define-fields.js +0 -3
  257. package/dist/config/framework-behaviors-config.d.ts +0 -30
  258. package/dist/config/framework-fields-config.d.ts +0 -42
  259. package/dist/config/framework-restrictions-config.d.ts +0 -142
  260. package/dist/json/avz.d.ts +0 -96
  261. package/dist/runtime/field-behavior.d.ts +0 -48
  262. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  263. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  264. /package/dist/{json → avz}/index.js +0 -0
  265. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  266. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  267. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -0,0 +1,150 @@
1
+ import { AvDecimal } from "./decimal.js";
2
+ function isContainer(value) {
3
+ if (value === null || typeof value !== "object") {
4
+ return false;
5
+ }
6
+ if (Array.isArray(value)) {
7
+ return true;
8
+ }
9
+ if (value instanceof AvDecimal) {
10
+ return false;
11
+ }
12
+ const prototype = Object.getPrototypeOf(value);
13
+ return prototype === Object.prototype || prototype === null;
14
+ }
15
+ const DEEP_FROZEN = new WeakSet();
16
+ export function deepFreeze(value) {
17
+ if (!isContainer(value) || DEEP_FROZEN.has(value)) {
18
+ return value;
19
+ }
20
+ Object.freeze(value);
21
+ DEEP_FROZEN.add(value);
22
+ for (const key of Reflect.ownKeys(value)) {
23
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
24
+ if (descriptor !== undefined && "value" in descriptor) {
25
+ deepFreeze(descriptor.value);
26
+ }
27
+ }
28
+ return value;
29
+ }
30
+ function scalarCopy(value) {
31
+ if (value instanceof Date) {
32
+ return new Date(value.getTime());
33
+ }
34
+ if (value instanceof Uint8Array) {
35
+ return value.slice();
36
+ }
37
+ return undefined;
38
+ }
39
+ const SCALAR_FREE = new WeakSet();
40
+ export function frozenCopy(value) {
41
+ const copies = new Map();
42
+ const walking = new Set();
43
+ let cycled = false;
44
+ const copy = (current) => {
45
+ const scalar = scalarCopy(current);
46
+ if (scalar !== undefined) {
47
+ return scalar;
48
+ }
49
+ if (!isContainer(current) || SCALAR_FREE.has(current)) {
50
+ return current;
51
+ }
52
+ if (copies.has(current)) {
53
+ cycled ||= walking.has(current);
54
+ return copies.get(current);
55
+ }
56
+ copies.set(current, current);
57
+ walking.add(current);
58
+ const entries = [];
59
+ let changed = !DEEP_FROZEN.has(current);
60
+ for (const key of Reflect.ownKeys(current)) {
61
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
62
+ if (descriptor === undefined ||
63
+ !("value" in descriptor) ||
64
+ (Array.isArray(current) && key === "length")) {
65
+ continue;
66
+ }
67
+ const next = copy(descriptor.value);
68
+ changed ||= next !== descriptor.value;
69
+ entries.push([key, descriptor, next]);
70
+ }
71
+ walking.delete(current);
72
+ if (!changed) {
73
+ copies.set(current, current);
74
+ if (!cycled) {
75
+ SCALAR_FREE.add(current);
76
+ }
77
+ return current;
78
+ }
79
+ const target = Array.isArray(current)
80
+ ? new Array(current.length)
81
+ : Object.create(Object.getPrototypeOf(current));
82
+ for (const [key, descriptor, next] of entries) {
83
+ Object.defineProperty(target, key, {
84
+ value: next,
85
+ enumerable: descriptor.enumerable ?? false,
86
+ writable: true,
87
+ configurable: true,
88
+ });
89
+ }
90
+ const frozen = deepFreeze(target);
91
+ copies.set(current, frozen);
92
+ return frozen;
93
+ };
94
+ return copy(value);
95
+ }
96
+ function readOnlyWrite(subject) {
97
+ return new TypeError(`${subject} is read-only here.`);
98
+ }
99
+ const VIEWS = new WeakMap();
100
+ export function readonlyView(value, subject) {
101
+ if (!isContainer(value)) {
102
+ return value;
103
+ }
104
+ const known = VIEWS.get(value);
105
+ if (known !== undefined) {
106
+ return known;
107
+ }
108
+ const real = value;
109
+ const standIn = Array.isArray(value)
110
+ ? []
111
+ : Object.create(Object.getPrototypeOf(value));
112
+ const refuse = () => {
113
+ throw readOnlyWrite(subject);
114
+ };
115
+ const view = new Proxy(standIn, {
116
+ get: (_target, key) => readonlyView(real[key], subject),
117
+ has: (_target, key) => key in real,
118
+ ownKeys: () => Reflect.ownKeys(real),
119
+ getOwnPropertyDescriptor: (target, key) => {
120
+ const descriptor = Reflect.getOwnPropertyDescriptor(real, key);
121
+ if (descriptor === undefined) {
122
+ return undefined;
123
+ }
124
+ if (Reflect.getOwnPropertyDescriptor(target, key)?.configurable === false) {
125
+ return {
126
+ value: descriptor.value,
127
+ enumerable: false,
128
+ writable: true,
129
+ configurable: false,
130
+ };
131
+ }
132
+ return "value" in descriptor
133
+ ? {
134
+ value: readonlyView(descriptor.value, subject),
135
+ enumerable: descriptor.enumerable ?? false,
136
+ writable: false,
137
+ configurable: true,
138
+ }
139
+ : { ...descriptor, configurable: true };
140
+ },
141
+ getPrototypeOf: () => Object.getPrototypeOf(real),
142
+ set: refuse,
143
+ defineProperty: refuse,
144
+ deleteProperty: refuse,
145
+ setPrototypeOf: refuse,
146
+ preventExtensions: refuse,
147
+ });
148
+ VIEWS.set(value, view);
149
+ return view;
150
+ }
@@ -1,5 +1,5 @@
1
- import type { ValidationIssue } from "../operations/validation-code.js";
1
+ import type { AvValidationIssue } from "../operations/validation-code.js";
2
2
  /** The issues of one malformed operation request envelope; empty when well formed. */
3
- export declare function validateOperationEnvelope(request: unknown): readonly ValidationIssue[];
3
+ export declare function validateOperationEnvelope(request: unknown): readonly AvValidationIssue[];
4
4
  /** The issues of one malformed transaction request envelope; empty when well formed. */
5
- export declare function validateTransactionEnvelope(request: unknown): readonly ValidationIssue[];
5
+ export declare function validateTransactionEnvelope(request: unknown): readonly AvValidationIssue[];
@@ -1,4 +1,4 @@
1
- const ORIGINS = ["application", "client"];
1
+ const ORIGINS = ["application", "client", "agent"];
2
2
  const OPERATION_IDENTITY_MEMBERS = ["resource", "family", "variant"];
3
3
  export function validateOperationEnvelope(request) {
4
4
  if (!isRecord(request)) {
@@ -29,7 +29,7 @@ function originAndIdentityIssues(request) {
29
29
  issues.push(issue(["origin"], "V1001", "Request origin must be a string."));
30
30
  }
31
31
  else if (!ORIGINS.includes(origin)) {
32
- issues.push(issue(["origin"], "V1002", 'Request origin must be "application" or "client".'));
32
+ issues.push(issue(["origin"], "V1002", 'Request origin must be "application", "client" or "agent".'));
33
33
  }
34
34
  const requestId = request.requestId;
35
35
  if (requestId === undefined || requestId === "") {
@@ -38,8 +38,13 @@ function originAndIdentityIssues(request) {
38
38
  else if (typeof requestId !== "string") {
39
39
  issues.push(issue(["requestId"], "V1001", "Request id must be a string."));
40
40
  }
41
- if (origin === "client") {
42
- issues.push(...protocolIssues(request.protocol));
41
+ const state = request.state;
42
+ if (state !== undefined &&
43
+ (typeof state !== "object" || state === null || Array.isArray(state))) {
44
+ issues.push(issue(["state"], "V1001", "Request state must be an object."));
45
+ }
46
+ if (origin === "client" || origin === "agent") {
47
+ issues.push(...protocolIssues(request.protocol, origin));
43
48
  if (request.transport !== undefined) {
44
49
  issues.push(...transportIssues(request.transport));
45
50
  }
@@ -47,16 +52,16 @@ function originAndIdentityIssues(request) {
47
52
  else if (origin === "application") {
48
53
  for (const member of ["protocol", "transport"]) {
49
54
  if (request[member] !== undefined) {
50
- issues.push(issue([member], "V1005", `Property "${member}" belongs to a client request, not an application one.`));
55
+ issues.push(issue([member], "V1005", `Property "${member}" belongs to a client or agent request, not an application one.`));
51
56
  }
52
57
  }
53
58
  }
54
59
  return issues;
55
60
  }
56
- function protocolIssues(protocol) {
61
+ function protocolIssues(protocol, origin) {
57
62
  if (protocol === undefined) {
58
63
  return [
59
- issue(["protocol"], "V1000", 'Required property "protocol" is missing from a client request.'),
64
+ issue(["protocol"], "V1000", `Required property "protocol" is missing from ${origin === "client" ? "a client" : "an agent"} request.`),
60
65
  ];
61
66
  }
62
67
  if (!isRecord(protocol)) {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The request id of one call or transaction run: the caller's
3
- * `ExecutionOptions.requestId` when it is a non-empty string, otherwise a new
3
+ * `AvExecutionOptions.requestId` when it is a non-empty string, otherwise a new
4
4
  * one. Any other value is ignored.
5
5
  */
6
6
  export declare function requestIdOf(options: unknown): string;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The per-request state every stage reads and writes as `ctx.$state`. Empty
3
+ * until the application declares its members by module augmentation:
4
+ *
5
+ * ```ts
6
+ * declare module "@aventara/core" {
7
+ * interface AvState {
8
+ * user?: { id: string; roles: string[] };
9
+ * }
10
+ * }
11
+ * ```
12
+ */
13
+ export interface AvState {
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { AvState } from "./request-state.js";
2
+ /**
3
+ * The state of one request: the seed when it is an object, otherwise a fresh
4
+ * `{}`. A seed that is not an object is ignored, as an unusable request id is.
5
+ */
6
+ export declare function requestStateOf(seed: unknown): AvState;
7
+ /**
8
+ * The state an in-process call's `AvExecutionOptions` seeds, or `undefined`.
9
+ * Read as `unknown`, like the request id: a façade is total for untyped
10
+ * callers, so a getter that throws or a value that is not an object is ignored.
11
+ */
12
+ export declare function stateOptionOf(options: unknown): AvState | undefined;
@@ -0,0 +1,20 @@
1
+ export function requestStateOf(seed) {
2
+ return typeof seed === "object" && seed !== null && !Array.isArray(seed)
3
+ ? seed
4
+ : {};
5
+ }
6
+ export function stateOptionOf(options) {
7
+ if (typeof options !== "object" || options === null) {
8
+ return undefined;
9
+ }
10
+ let state;
11
+ try {
12
+ state = options.state;
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ return typeof state === "object" && state !== null && !Array.isArray(state)
18
+ ? state
19
+ : undefined;
20
+ }
@@ -1,41 +1,60 @@
1
- import type { RequestOrigin } from "../config/config-layer.js";
2
- import type { ScalarFilterOperator } from "../contracts/capability.js";
3
- import type { Contract } from "../contracts/contract.js";
4
- import type { ScalarField } from "../contracts/field.js";
5
- import type { OperationIdentity } from "../operations/operation-identity.js";
1
+ import type { AvRequestOrigin } from "../config/config-layer.js";
2
+ import { type AvScalarFilterOperator } from "../contracts/capability.js";
3
+ import type { AvContract } from "../contracts/contract.js";
4
+ import type { AvScalarField } from "../contracts/field.js";
5
+ import type { AvOperationIdentity } from "../operations/operation-identity.js";
6
6
  import type { OperationValidationOptions, SemanticOperationArguments } from "../operations/operation-validator.js";
7
- import type { ValidationIssue } from "../operations/validation-code.js";
7
+ import type { AvValidationIssue } from "../operations/validation-code.js";
8
8
  import { type TransactionSlotShape } from "../transactions/transaction-reference.js";
9
9
  export type ScalarNormalizationResult = {
10
10
  readonly ok: true;
11
11
  readonly arguments: SemanticOperationArguments;
12
12
  } | {
13
13
  readonly ok: false;
14
- readonly issues: readonly ValidationIssue[];
14
+ readonly issues: readonly AvValidationIssue[];
15
15
  };
16
16
  export type ScalarValueNormalizationResult = {
17
17
  readonly ok: true;
18
18
  readonly value: unknown;
19
19
  } | {
20
20
  readonly ok: false;
21
- readonly issues: readonly ValidationIssue[];
21
+ readonly issues: readonly AvValidationIssue[];
22
22
  };
23
23
  type Path = readonly (string | number)[];
24
24
  /**
25
25
  * The one discriminant between an argument OBJECT and a VALUE wherever a position
26
26
  * admits both — a filter position above all: a **plain** record is an operator object,
27
- * and anything else — a `Date`, a core `Decimal`, a `Uint8Array` — is a value, which
27
+ * and anything else — a `Date`, a core `AvDecimal`, a `Uint8Array` — is a value, which
28
28
  * equality shorthand then holds to the field's scalar. The validator (`operation-
29
29
  * validator-core.ts`) reads a filter position through this same answer, and an
30
30
  * adapter's filter translation is expected to, so a position cannot be operators to
31
31
  * one reader and a value to another.
32
32
  */
33
33
  export declare function isPlainRecord(value: unknown): value is Readonly<Record<string, unknown>>;
34
+ /** What a refused `undefined` the request reads with is told. */
35
+ export declare const UNSENT_READ_VALUE_MESSAGE = "Value must not be undefined: it would be left out, and the request would reach more rows.";
36
+ /** The `V1001` of an `undefined` the request reads with. */
37
+ export declare function unsentReadValueIssue(path: Path): AvValidationIssue;
38
+ /**
39
+ * An operation argument's JSON value is bounded by `maxJsonDepth`, which the
40
+ * structural walk enforces before this runs; a `$sql` step's parameter is not
41
+ * bounded by it. The traversal therefore carries its own stack on the heap: a
42
+ * payload deep enough to exhaust the call stack must still normalize rather
43
+ * than become an internal failure.
44
+ *
45
+ * `seen` holds the ancestors of the value being visited, so a repeated
46
+ * sibling reference is legal and only a genuine cycle is rejected.
47
+ *
48
+ * Every node it emits is typed {@link AvJsonValue}, so the public type and what
49
+ * this traversal produces are one fact: a branch that emitted anything else
50
+ * would not compile.
51
+ */
52
+ export declare function normalizeJsonValue(value: unknown, path: Path, seen: Set<object>): ScalarValueNormalizationResult;
34
53
  /**
35
54
  * Normalizes one field value to Aventara's provider-neutral runtime form.
36
55
  * `runtime` is used for framework-produced values regardless of request origin.
37
56
  */
38
- export declare function normalizeScalarFieldValue(contract: Contract, field: ScalarField<Contract>, value: unknown, origin: RequestOrigin | "runtime", path: Path): ScalarValueNormalizationResult;
57
+ export declare function normalizeScalarFieldValue(contract: AvContract, field: AvScalarField<AvContract>, value: unknown, origin: AvRequestOrigin | "runtime", path: Path): ScalarValueNormalizationResult;
39
58
  /**
40
59
  * Every way a normalized value written to `field` does not conform to the field's
41
60
  * Json Shape, each at its full path; none for an unshaped field or a `null`.
@@ -45,17 +64,17 @@ export declare function normalizeScalarFieldValue(contract: Contract, field: Sca
45
64
  * @throws Error when the field carries a shape no checker is bound to — a Contract
46
65
  * the Framework did not compile.
47
66
  */
48
- export declare function jsonShapeIssues(field: ScalarField<Contract>, value: unknown, path: Path, position?: "value" | "entry"): readonly ValidationIssue[];
67
+ export declare function jsonShapeIssues(field: AvScalarField<AvContract>, value: unknown, path: Path, position?: "value" | "entry"): readonly AvValidationIssue[];
49
68
  /**
50
69
  * Copies one validated runtime value of a scalar field into a value the framework
51
70
  * owns, per scalar codec: `datetime` → a new `Date`, `bytes` → a sliced `Uint8Array`,
52
71
  * `json` → a structured deep copy, and a list → a new array of copied items. `decimal`
53
72
  * keeps its identity, and strings, numbers, booleans, bigints, enum members and `null`
54
73
  * are immutable and returned unchanged. {@link SCALAR_ATOM_COPIERS} is exhaustive over
55
- * {@link BuiltInScalar}, so a new codec cannot reach this function without declaring
74
+ * {@link AvBuiltInScalar}, so a new codec cannot reach this function without declaring
56
75
  * its copy.
57
76
  */
58
- export declare function copyScalarFieldValue(field: ScalarField<Contract>, value: unknown): unknown;
77
+ export declare function copyScalarFieldValue(field: AvScalarField<AvContract>, value: unknown): unknown;
59
78
  /**
60
79
  * The operators of a step's own filter whose operand is a reference position, and
61
80
  * the shape each holds — the one table the normalization below and the reference
@@ -63,7 +82,7 @@ export declare function copyScalarFieldValue(field: ScalarField<Contract>, value
63
82
  * nested operator object. Not here, so never a reference: `mode`, `isEmpty`, `path`
64
83
  * and a `json` field's `string*`/`array*` operators, which take no field value.
65
84
  */
66
- export declare const REFERENCE_OPERANDS: Readonly<Partial<Record<ScalarFilterOperator, TransactionSlotShape>>>;
85
+ export declare const REFERENCE_OPERANDS: Readonly<Partial<Record<AvScalarFilterOperator, TransactionSlotShape>>>;
67
86
  /** The shape of `operator`'s operand when it is a reference position. */
68
87
  export declare function referenceOperandShape(operator: string): TransactionSlotShape | undefined;
69
88
  /**
@@ -76,8 +95,8 @@ export type NormalizationWrite = "copy" | "in-place";
76
95
  * Normalizes every scalar leaf in one structurally valid standard operation.
77
96
  * Client wire values are decoded; application values are validated in runtime form.
78
97
  */
79
- export declare function normalizeOperationScalarValues(contract: Contract, request: OperationIdentity & {
98
+ export declare function normalizeOperationScalarValues(contract: AvContract, request: AvOperationIdentity & {
80
99
  readonly resource: string;
81
100
  readonly arguments: SemanticOperationArguments;
82
- }, origin: RequestOrigin, options?: OperationValidationOptions, write?: NormalizationWrite): ScalarNormalizationResult;
101
+ }, origin: AvRequestOrigin, options?: OperationValidationOptions, write?: NormalizationWrite): ScalarNormalizationResult;
83
102
  export {};