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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/CHANGELOG.md +1140 -0
  2. package/README.md +224 -57
  3. package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
  4. package/dist/adapters/adapter-field.d.ts +11 -11
  5. package/dist/adapters/adapter-identifier.d.ts +6 -6
  6. package/dist/adapters/adapter-model.d.ts +9 -9
  7. package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
  8. package/dist/adapters/adapter-operation.d.ts +3 -3
  9. package/dist/adapters/adapter-resource.d.ts +18 -9
  10. package/dist/adapters/adapter-sql-statement.d.ts +19 -0
  11. package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
  12. package/dist/adapters/adapter.interface.d.ts +49 -29
  13. package/dist/avz/avz-check.factory.d.ts +83 -0
  14. package/dist/avz/avz-check.factory.js +116 -0
  15. package/dist/avz/avz-check.registry.d.ts +35 -0
  16. package/dist/avz/avz-check.registry.js +9 -0
  17. package/dist/avz/avz.d.ts +203 -0
  18. package/dist/{json → avz}/avz.js +150 -8
  19. package/dist/{json → avz}/index.d.ts +2 -1
  20. package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
  21. package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
  22. package/dist/{json → avz}/zod-issue.translator.js +7 -0
  23. package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
  24. package/dist/compiler/contract.compiler.d.ts +18 -18
  25. package/dist/compiler/contract.compiler.js +548 -441
  26. package/dist/compiler/create-requirements.projector.d.ts +49 -0
  27. package/dist/compiler/create-requirements.projector.js +423 -0
  28. package/dist/compiler/field-validator.compiler.d.ts +47 -0
  29. package/dist/compiler/field-validator.compiler.js +238 -0
  30. package/dist/config/any-framework-config.d.ts +19 -12
  31. package/dist/config/config-diagnostic.d.ts +11 -4
  32. package/dist/config/config-layer.d.ts +15 -6
  33. package/dist/config/config.resolver.d.ts +74 -31
  34. package/dist/config/config.resolver.js +108 -44
  35. package/dist/config/config.validator.d.ts +7 -7
  36. package/dist/config/config.validator.js +581 -72
  37. package/dist/config/define-resource.d.ts +57 -0
  38. package/dist/config/define-resource.js +14 -0
  39. package/dist/config/effective-fields.d.ts +19 -23
  40. package/dist/config/entrypoint.normalizer.d.ts +1 -1
  41. package/dist/config/exact-framework-config.d.ts +280 -0
  42. package/dist/config/field-compute.resolver.d.ts +19 -0
  43. package/dist/config/field-compute.resolver.js +115 -0
  44. package/dist/config/field-pipeline-config.d.ts +47 -0
  45. package/dist/config/forced-operation.validator.d.ts +10 -0
  46. package/dist/config/forced-operation.validator.js +66 -0
  47. package/dist/config/framework-config.d.ts +110 -39
  48. package/dist/config/framework-exemptions-config.d.ts +91 -0
  49. package/dist/config/framework-exemptions-config.js +1 -0
  50. package/dist/config/framework-field-definition.d.ts +78 -0
  51. package/dist/config/framework-field-definition.js +28 -0
  52. package/dist/config/framework-resources-config.d.ts +116 -0
  53. package/dist/config/framework-resources-config.js +1 -0
  54. package/dist/config/pipeline-config.d.ts +56 -20
  55. package/dist/config/pipeline-tree.resolver.d.ts +79 -0
  56. package/dist/config/pipeline-tree.resolver.js +220 -0
  57. package/dist/config/stage-type.eraser.d.ts +65 -0
  58. package/dist/config/stage-type.eraser.js +1 -0
  59. package/dist/contracts/capability.d.ts +11 -11
  60. package/dist/contracts/client-contract-structure.validator.d.ts +323 -28
  61. package/dist/contracts/client-contract-structure.validator.js +152 -8
  62. package/dist/contracts/contract-canonicalizer.d.ts +19 -3
  63. package/dist/contracts/contract-canonicalizer.js +141 -28
  64. package/dist/contracts/contract-hash.d.ts +12 -7
  65. package/dist/contracts/contract-hash.js +3 -2
  66. package/dist/contracts/contract-limits.d.ts +4 -1
  67. package/dist/contracts/contract-limits.js +1 -0
  68. package/dist/contracts/contract-lookup.d.ts +5 -5
  69. package/dist/contracts/contract-protocol.d.ts +4 -4
  70. package/dist/contracts/contract.d.ts +24 -16
  71. package/dist/contracts/create-requirements.d.ts +35 -0
  72. package/dist/contracts/create-requirements.js +1 -0
  73. package/dist/contracts/enum-definition.d.ts +1 -1
  74. package/dist/contracts/field-check.d.ts +101 -0
  75. package/dist/contracts/field-check.js +1 -0
  76. package/dist/contracts/field.d.ts +52 -42
  77. package/dist/contracts/identifier.d.ts +4 -4
  78. package/dist/contracts/json-shape.d.ts +12 -1
  79. package/dist/contracts/lifecycle-trait.d.ts +2 -2
  80. package/dist/contracts/resource-operations.d.ts +28 -28
  81. package/dist/contracts/resource.d.ts +15 -9
  82. package/dist/contracts/scalar-value-type.d.ts +15 -15
  83. package/dist/contracts/scalar.d.ts +3 -3
  84. package/dist/contracts/transaction-capability.d.ts +1 -1
  85. package/dist/contracts/wire-scalar-format.d.ts +4 -4
  86. package/dist/framework/contract-view.d.ts +213 -147
  87. package/dist/framework/framework-construction.error.d.ts +10 -10
  88. package/dist/framework/framework-construction.error.js +2 -2
  89. package/dist/framework/framework.d.ts +47 -23
  90. package/dist/framework/framework.factory.d.ts +8 -6
  91. package/dist/framework/framework.factory.js +40 -20
  92. package/dist/framework/operation-facade.d.ts +123 -52
  93. package/dist/framework/operation-facade.js +9 -1
  94. package/dist/index.d.ts +55 -50
  95. package/dist/index.js +6 -6
  96. package/dist/internal.d.ts +15 -10
  97. package/dist/internal.js +3 -1
  98. package/dist/operations/operation-arguments.d.ts +267 -202
  99. package/dist/operations/operation-call.d.ts +27 -28
  100. package/dist/operations/operation-identity.d.ts +10 -10
  101. package/dist/operations/operation-result.d.ts +21 -21
  102. package/dist/operations/operation-validator-core.d.ts +6 -6
  103. package/dist/operations/operation-validator-core.js +13 -2
  104. package/dist/operations/operation-validator.d.ts +9 -9
  105. package/dist/operations/projection-scope.resolver.d.ts +6 -6
  106. package/dist/operations/structural-limits.walker.d.ts +6 -6
  107. package/dist/operations/structural-limits.walker.js +145 -0
  108. package/dist/operations/validation-code.d.ts +11 -6
  109. package/dist/operations/validation-code.js +4 -0
  110. package/dist/operations/write-scope.resolver.d.ts +6 -6
  111. package/dist/protocol/absent-route.responder.d.ts +13 -12
  112. package/dist/protocol/absent-route.responder.js +19 -19
  113. package/dist/protocol/contract-document.responder.d.ts +3 -3
  114. package/dist/protocol/contract-document.responder.js +2 -2
  115. package/dist/protocol/http-request.decoder.d.ts +17 -13
  116. package/dist/protocol/http-request.decoder.js +10 -10
  117. package/dist/protocol/http-request.reader.d.ts +3 -3
  118. package/dist/protocol/http-response.encoder.d.ts +4 -4
  119. package/dist/protocol/http-response.encoder.js +94 -55
  120. package/dist/protocol/http-status.table.d.ts +2 -2
  121. package/dist/protocol/operation-response.guard.d.ts +2 -2
  122. package/dist/protocol/protocol-surface.d.ts +4 -4
  123. package/dist/protocol/protocol.binder.d.ts +50 -27
  124. package/dist/protocol/protocol.binder.js +12 -9
  125. package/dist/protocol/protocol.handler.d.ts +22 -13
  126. package/dist/protocol/protocol.handler.js +44 -9
  127. package/dist/protocol/unmounted-route.error.d.ts +4 -4
  128. package/dist/protocol/unmounted-route.error.js +2 -2
  129. package/dist/runtime/caller-data.copier.d.ts +5 -5
  130. package/dist/runtime/caller-data.copier.js +13 -13
  131. package/dist/runtime/caller-data.door.d.ts +6 -6
  132. package/dist/runtime/caller-data.door.js +6 -4
  133. package/dist/runtime/computed-read-runtime.d.ts +7 -6
  134. package/dist/runtime/computed-read-runtime.js +61 -48
  135. package/dist/runtime/computed-value.error.d.ts +6 -6
  136. package/dist/runtime/computed-value.error.js +3 -3
  137. package/dist/runtime/context-executor.runtime.d.ts +59 -0
  138. package/dist/runtime/context-executor.runtime.js +275 -0
  139. package/dist/runtime/create-requirement.d.ts +10 -81
  140. package/dist/runtime/create-requirement.js +80 -57
  141. package/dist/runtime/decimal.d.ts +2 -2
  142. package/dist/runtime/decimal.js +1 -1
  143. package/dist/runtime/diagnostics-reporter.d.ts +53 -27
  144. package/dist/runtime/diagnostics-reporter.js +24 -0
  145. package/dist/runtime/error-boundary.d.ts +65 -8
  146. package/dist/runtime/error-boundary.js +45 -19
  147. package/dist/runtime/execution-options.d.ts +10 -2
  148. package/dist/runtime/field-check.evaluator.d.ts +29 -0
  149. package/dist/runtime/field-check.evaluator.js +521 -0
  150. package/dist/runtime/field-compute.d.ts +64 -0
  151. package/dist/runtime/field-compute.js +1 -0
  152. package/dist/runtime/field-stage.plan.d.ts +15 -0
  153. package/dist/runtime/field-stage.plan.js +27 -0
  154. package/dist/runtime/field-stage.runtime.d.ts +35 -0
  155. package/dist/runtime/field-stage.runtime.js +143 -0
  156. package/dist/runtime/field-validator.runtime.d.ts +11 -0
  157. package/dist/runtime/field-validator.runtime.js +87 -0
  158. package/dist/runtime/framework-error-class.table.d.ts +33 -0
  159. package/dist/runtime/framework-error-class.table.js +25 -0
  160. package/dist/runtime/framework-error.d.ts +68 -8
  161. package/dist/runtime/framework-error.factory.d.ts +4 -0
  162. package/dist/runtime/framework-error.factory.js +15 -0
  163. package/dist/runtime/framework-error.js +23 -2
  164. package/dist/runtime/interceptor-next.error.d.ts +5 -0
  165. package/dist/runtime/interceptor-next.error.js +6 -0
  166. package/dist/runtime/json-value.d.ts +3 -3
  167. package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
  168. package/dist/runtime/level-lifecycle.runtime.js +42 -0
  169. package/dist/runtime/misuse-reporter.d.ts +12 -12
  170. package/dist/runtime/mutation-planner.d.ts +19 -10
  171. package/dist/runtime/mutation-planner.js +54 -30
  172. package/dist/runtime/nested-write.walker.d.ts +32 -0
  173. package/dist/runtime/nested-write.walker.js +73 -0
  174. package/dist/runtime/operation-request.d.ts +33 -6
  175. package/dist/runtime/operation-response.d.ts +17 -17
  176. package/dist/runtime/operation-runtime.d.ts +113 -25
  177. package/dist/runtime/operation-runtime.js +395 -74
  178. package/dist/runtime/outcome-mapper.d.ts +16 -5
  179. package/dist/runtime/outcome-mapper.js +23 -6
  180. package/dist/runtime/output-validator.d.ts +10 -10
  181. package/dist/runtime/output-validator.js +3 -3
  182. package/dist/runtime/owned-execution.registry.d.ts +6 -6
  183. package/dist/runtime/pipe-output.validator.d.ts +33 -18
  184. package/dist/runtime/pipe-output.validator.js +12 -12
  185. package/dist/runtime/pipeline.d.ts +196 -34
  186. package/dist/runtime/readonly-value.d.ts +32 -0
  187. package/dist/runtime/readonly-value.js +141 -0
  188. package/dist/runtime/request-envelope.validator.d.ts +3 -3
  189. package/dist/runtime/request-envelope.validator.js +12 -7
  190. package/dist/runtime/request-id.d.ts +1 -1
  191. package/dist/runtime/request-state.d.ts +14 -0
  192. package/dist/runtime/request-state.js +1 -0
  193. package/dist/runtime/request-state.resolver.d.ts +12 -0
  194. package/dist/runtime/request-state.resolver.js +20 -0
  195. package/dist/runtime/scalar-runtime.d.ts +31 -16
  196. package/dist/runtime/scalar-runtime.js +16 -18
  197. package/dist/transactions/deferred-operation.d.ts +35 -20
  198. package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
  199. package/dist/transactions/operation-arguments-encoder.js +2 -2
  200. package/dist/transactions/sql-statement.d.ts +77 -0
  201. package/dist/transactions/sql-statement.js +47 -0
  202. package/dist/transactions/sql-statement.validator.d.ts +44 -0
  203. package/dist/transactions/sql-statement.validator.js +134 -0
  204. package/dist/transactions/transaction-envelope.d.ts +4 -4
  205. package/dist/transactions/transaction-integrity-error.d.ts +6 -6
  206. package/dist/transactions/transaction-integrity-error.js +5 -2
  207. package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
  208. package/dist/transactions/transaction-plan-assembler.js +148 -34
  209. package/dist/transactions/transaction-plan-validator.d.ts +29 -20
  210. package/dist/transactions/transaction-plan-validator.js +70 -38
  211. package/dist/transactions/transaction-reference-collector.d.ts +5 -5
  212. package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
  213. package/dist/transactions/transaction-reference-resolver.js +26 -14
  214. package/dist/transactions/transaction-reference-validator.d.ts +34 -4
  215. package/dist/transactions/transaction-reference-validator.js +58 -26
  216. package/dist/transactions/transaction-reference.d.ts +13 -13
  217. package/dist/transactions/transaction-request.d.ts +18 -5
  218. package/dist/transactions/transaction-response.d.ts +6 -6
  219. package/dist/transactions/transaction-runtime.d.ts +8 -7
  220. package/dist/transactions/transaction-runtime.js +166 -50
  221. package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
  222. package/dist/transactions/transaction-settlement.runtime.js +120 -0
  223. package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
  224. package/dist/transactions/transaction-slot-path-error.js +2 -2
  225. package/dist/transactions/transaction-slot-writer.js +2 -2
  226. package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
  227. package/dist/transactions/transaction-stage.runtime.js +123 -0
  228. package/package.json +6 -5
  229. package/src/runtime/field-check.evaluator.ts +720 -0
  230. package/dist/config/define-fields.d.ts +0 -42
  231. package/dist/config/define-fields.js +0 -3
  232. package/dist/config/framework-behaviors-config.d.ts +0 -30
  233. package/dist/config/framework-fields-config.d.ts +0 -42
  234. package/dist/config/framework-restrictions-config.d.ts +0 -142
  235. package/dist/json/avz.d.ts +0 -96
  236. package/dist/runtime/field-behavior.d.ts +0 -48
  237. /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
  238. /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
  239. /package/dist/{json → avz}/index.js +0 -0
  240. /package/dist/{json → avz}/json-shape.registry.js +0 -0
  241. /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
  242. /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
@@ -1,8 +1,26 @@
1
- import * as zodMini from "zod/mini";
1
+ import { array as zodArray, boolean as zodBoolean, discriminatedUnion as zodDiscriminatedUnion, enum as zodEnum, int as zodInt, literal as zodLiteral, null as zodNull, nullable as zodNullable, number as zodNumber, optional as zodOptional, record as zodRecord, strictObject as zodStrictObject, string as zodString, tuple as zodTuple, union as zodUnion, } from "zod/mini";
2
+ import { fieldCheckIssue, passesFieldCheck, } from "../runtime/field-check.evaluator.js";
3
+ import * as checks from "./avz-check.factory.js";
4
+ import { avzCheckOf, } from "./avz-check.registry.js";
2
5
  import { registerJsonShape } from "./json-shape.registry.js";
3
- import { translateZodIssues } from "./zod-issue.translator.js";
4
- const z = zodMini;
5
- const SHAPE_PROTOTYPE = Object.freeze(Object.create(null));
6
+ import { AVZ_CHECK_ISSUE, translateZodIssues, } from "./zod-issue.translator.js";
7
+ const z = {
8
+ string: zodString,
9
+ number: zodNumber,
10
+ int: zodInt,
11
+ boolean: zodBoolean,
12
+ null: zodNull,
13
+ literal: zodLiteral,
14
+ enum: zodEnum,
15
+ strictObject: zodStrictObject,
16
+ array: zodArray,
17
+ tuple: zodTuple,
18
+ record: zodRecord,
19
+ union: zodUnion,
20
+ discriminatedUnion: zodDiscriminatedUnion,
21
+ optional: zodOptional,
22
+ nullable: zodNullable,
23
+ };
6
24
  const compiled = new WeakMap();
7
25
  function compiledOf(builder, value) {
8
26
  const found = typeof value === "object" && value !== null
@@ -20,10 +38,17 @@ function requiredPart(builder, value) {
20
38
  }
21
39
  return part;
22
40
  }
23
- function build(node, zod, schema, optionalKey = false) {
41
+ function build(node, zod, schema, optionalKey = false, checked) {
24
42
  const shape = Object.freeze(Object.assign(Object.create(SHAPE_PROTOTYPE), { kind: node.kind }));
25
43
  const frozenSchema = deepFreeze(schema);
26
- compiled.set(shape, { node, zod, schema: frozenSchema, optionalKey });
44
+ compiled.set(shape, {
45
+ node,
46
+ zod,
47
+ schema: frozenSchema,
48
+ optionalKey,
49
+ unchecked: checked?.unchecked ?? zod,
50
+ checks: checked?.checks ?? [],
51
+ });
27
52
  registerJsonShape(shape, {
28
53
  schema: frozenSchema,
29
54
  validate: (value) => {
@@ -35,6 +60,69 @@ function build(node, zod, schema, optionalKey = false) {
35
60
  });
36
61
  return shape;
37
62
  }
63
+ const CHECKABLE = {
64
+ string: { target: "string", subject: "string", label: "string" },
65
+ number: { target: "number", subject: "number", label: "number" },
66
+ int: { target: "number", subject: "number", label: "int" },
67
+ array: { target: "list", subject: "number", label: "array" },
68
+ };
69
+ function shapeCheck(kind, target, added) {
70
+ const data = avzCheckOf(added);
71
+ if (data === undefined) {
72
+ throw new TypeError(`AvZ.${kind}(…).check: every check must be built with AvZ (AvZ.maxLength(…), AvZ.email(), …); a Zod check or any other value is not accepted.`);
73
+ }
74
+ const fits = target === "string"
75
+ ? data.check === "string_format" ||
76
+ data.check === "length_equals" ||
77
+ ((data.check === "max_length" || data.check === "min_length") &&
78
+ data.list !== true)
79
+ : target === "number"
80
+ ? (data.check === "less_than" ||
81
+ data.check === "greater_than" ||
82
+ data.check === "multiple_of") &&
83
+ typeof data.value === "number"
84
+ : (data.check === "max_length" || data.check === "min_length") &&
85
+ data.list === true;
86
+ if (!fits) {
87
+ throw new TypeError(`AvZ.${kind}(…).check: the check "${data.check}"${"format" in data ? ` (${data.format})` : ""} does not apply to ${kind === "array" ? "an array's length; an array takes AvZ.minItems and AvZ.maxItems" : `a${kind === "int" ? "n" : ""} ${kind} shape`}.`);
88
+ }
89
+ return data;
90
+ }
91
+ function zodChecks(checks, subject) {
92
+ return (payload) => {
93
+ for (const check of checks) {
94
+ if (passesFieldCheck(check, payload.value, subject)) {
95
+ continue;
96
+ }
97
+ const issue = fieldCheckIssue(check, subject, []);
98
+ payload.issues.push({
99
+ code: "custom",
100
+ message: issue.message,
101
+ input: payload.value,
102
+ path: [],
103
+ params: { [AVZ_CHECK_ISSUE]: issue },
104
+ continue: true,
105
+ });
106
+ }
107
+ };
108
+ }
109
+ function addChecks(...added) {
110
+ const part = compiledOf("check", this);
111
+ const kind = part.node.kind;
112
+ const checkable = CHECKABLE[kind];
113
+ if (added.length === 0) {
114
+ return this;
115
+ }
116
+ if (checkable === undefined) {
117
+ throw new TypeError(`AvZ.${kind}(…).check: only a string, number, int or array shape takes checks.`);
118
+ }
119
+ const all = [
120
+ ...part.checks,
121
+ ...added.map((check) => shapeCheck(kind, checkable.target, check)),
122
+ ];
123
+ return build(part.node, part.unchecked.check(zodChecks(all, checkable.subject)), { ...part.schema, checks: all }, part.optionalKey, { unchecked: part.unchecked, checks: all });
124
+ }
125
+ const SHAPE_PROTOTYPE = Object.freeze(Object.assign(Object.create(null), { check: addChecks }));
38
126
  function deepFreeze(value) {
39
127
  if (typeof value === "object" && value !== null) {
40
128
  for (const child of Object.values(value)) {
@@ -74,6 +162,10 @@ const enumShape = (values) => {
74
162
  enum: copy,
75
163
  });
76
164
  };
165
+ function contractKeyOrder(keys) {
166
+ const sorted = [...keys].sort((left, right) => left < right ? -1 : left > right ? 1 : 0);
167
+ return Object.keys(Object.fromEntries(sorted.map((key) => [key, true])));
168
+ }
77
169
  const object = (fields) => {
78
170
  if (typeof fields !== "object" || fields === null || Array.isArray(fields)) {
79
171
  throw new TypeError("AvZ.object: the fields must be an object of shapes.");
@@ -85,12 +177,14 @@ const object = (fields) => {
85
177
  for (const key of Object.keys(fields)) {
86
178
  const part = compiledOf("object", fields[key]);
87
179
  nodes[key] = part.node;
88
- zods[key] = part.zod;
89
180
  properties[key] = part.schema;
90
181
  if (!part.optionalKey) {
91
182
  required.push(key);
92
183
  }
93
184
  }
185
+ for (const key of contractKeyOrder(Object.keys(fields))) {
186
+ zods[key] = compiledOf("object", fields[key]).zod;
187
+ }
94
188
  return build({ kind: "object", fields: nodes }, z.strictObject(zods), {
95
189
  type: "object",
96
190
  properties,
@@ -140,7 +234,9 @@ const record = (key, value) => {
140
234
  required: [...keys],
141
235
  additionalProperties: false,
142
236
  };
143
- return build({ kind: "record", value: valuePart.node }, z.record(keyPart.zod, valuePart.zod), schema);
237
+ return build({ kind: "record", value: valuePart.node }, z.record(keyNode.kind === "enum"
238
+ ? z.enum(contractKeyOrder(keyNode.values))
239
+ : keyPart.zod, valuePart.zod), schema);
144
240
  };
145
241
  const union = (options) => {
146
242
  if (!Array.isArray(options) || options.length < 2) {
@@ -209,4 +305,50 @@ export class AvZ {
209
305
  static discriminatedUnion = discriminatedUnion;
210
306
  static optional = optional;
211
307
  static nullable = nullable;
308
+ static lt = checks.lt;
309
+ static lte = checks.lte;
310
+ static gt = checks.gt;
311
+ static gte = checks.gte;
312
+ static positive = checks.positive;
313
+ static nonnegative = checks.nonnegative;
314
+ static negative = checks.negative;
315
+ static nonpositive = checks.nonpositive;
316
+ static multipleOf = checks.multipleOf;
317
+ static maxLength = checks.maxLength;
318
+ static minLength = checks.minLength;
319
+ static length = checks.length;
320
+ static maxItems = checks.maxItems;
321
+ static minItems = checks.minItems;
322
+ static maxSize = checks.maxSize;
323
+ static minSize = checks.minSize;
324
+ static size = checks.size;
325
+ static regex = checks.regex;
326
+ static includes = checks.includes;
327
+ static startsWith = checks.startsWith;
328
+ static endsWith = checks.endsWith;
329
+ static lowercase = checks.lowercase;
330
+ static uppercase = checks.uppercase;
331
+ static email = checks.email;
332
+ static url = checks.url;
333
+ static emoji = checks.emoji;
334
+ static uuid = checks.uuid;
335
+ static guid = checks.guid;
336
+ static nanoid = checks.nanoid;
337
+ static cuid = checks.cuid;
338
+ static cuid2 = checks.cuid2;
339
+ static ulid = checks.ulid;
340
+ static xid = checks.xid;
341
+ static ksuid = checks.ksuid;
342
+ static ipv4 = checks.ipv4;
343
+ static ipv6 = checks.ipv6;
344
+ static cidrv4 = checks.cidrv4;
345
+ static cidrv6 = checks.cidrv6;
346
+ static base64 = checks.base64;
347
+ static base64url = checks.base64url;
348
+ static jsonString = checks.jsonString;
349
+ static e164 = checks.e164;
350
+ static creditCard = checks.creditCard;
351
+ static iban = checks.iban;
352
+ static jwt = checks.jwt;
353
+ static iso = checks.iso;
212
354
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
- * `@aventara/core/json` — `AvZ`, which builds the TypeScript shape of a Json
2
+ * `@aventara/core/avz` — `AvZ`, which builds the TypeScript shape of a Json
3
3
  * field, and the types of the shapes it builds.
4
4
  */
5
+ export type { ShapedJsonSchema as AvZShapedSchema } from "../contracts/json-shape.js";
5
6
  export type { AvZNullable, AvZObject, AvZOptional, AvZShape } from "./avz.js";
6
7
  export { AvZ } from "./avz.js";
@@ -1,7 +1,7 @@
1
- import type { Contract } from "../contracts/contract.js";
2
- import type { ScalarField } from "../contracts/field.js";
1
+ import type { AvContract } from "../contracts/contract.js";
2
+ import type { AvScalarField } from "../contracts/field.js";
3
3
  import type { JsonSchema } from "../contracts/json-shape.js";
4
- import type { ValidationIssue } from "../operations/validation-code.js";
4
+ import type { AvValidationIssue } from "../operations/validation-code.js";
5
5
  /** What core may do with a Json Shape: read its Contract form, check a value. */
6
6
  export type JsonShapeRuntime = {
7
7
  /** The shape's Contract form. */
@@ -10,13 +10,13 @@ export type JsonShapeRuntime = {
10
10
  * Every way `value` — a JSON value — does not conform, each at its path inside
11
11
  * the value; none when it conforms.
12
12
  */
13
- readonly validate: (value: unknown) => readonly ValidationIssue[];
13
+ readonly validate: (value: unknown) => readonly AvValidationIssue[];
14
14
  };
15
- /** Records `shape` as a Json Shape. For `@aventara/core/json` only. */
15
+ /** Records `shape` as a Json Shape. For `@aventara/core/avz` only. */
16
16
  export declare function registerJsonShape(shape: object, runtime: JsonShapeRuntime): void;
17
17
  /** The Json Shape `value` is, or `undefined` when `AvZ` did not build it. */
18
18
  export declare function jsonShapeOf(value: unknown): JsonShapeRuntime | undefined;
19
19
  /** Binds a compiled Contract field to the shape it enforces. Compiler only. */
20
- export declare function bindShapedField(field: ScalarField<Contract>, shape: JsonShapeRuntime): void;
20
+ export declare function bindShapedField(field: AvScalarField<AvContract>, shape: JsonShapeRuntime): void;
21
21
  /** The shape a compiled Contract field enforces, or `undefined`. */
22
- export declare function shapeOfField(field: ScalarField<Contract>): JsonShapeRuntime | undefined;
22
+ export declare function shapeOfField(field: AvScalarField<AvContract>): JsonShapeRuntime | undefined;
@@ -1,5 +1,10 @@
1
1
  import type { JsonSchemaPrimitive } from "../contracts/json-shape.js";
2
- import type { ValidationIssue } from "../operations/validation-code.js";
2
+ import type { AvValidationIssue } from "../operations/validation-code.js";
3
+ /**
4
+ * The key a shape node's failed check travels under in its Zod issue's `params`:
5
+ * the finished Aventara issue, path relative to the node (`avz.ts`).
6
+ */
7
+ export declare const AVZ_CHECK_ISSUE = "aventara.check";
3
8
  /** A shape as the translator reads it: its form and its parts, no Zod. */
4
9
  export type AvZNode = {
5
10
  readonly kind: "string" | "number" | "int" | "boolean" | "null";
@@ -42,10 +47,11 @@ type ZodIssueLike = {
42
47
  readonly options?: readonly unknown[];
43
48
  readonly minimum?: unknown;
44
49
  readonly maximum?: unknown;
50
+ readonly params?: Readonly<Record<string, unknown>>;
45
51
  };
46
52
  /**
47
53
  * Aventara's issues for the ones Zod raised judging `value` against the shape
48
54
  * `root`: each at its path inside the value, in Zod's order.
49
55
  */
50
- export declare function translateZodIssues(root: AvZNode, value: unknown, issues: readonly ZodIssueLike[]): readonly ValidationIssue[];
56
+ export declare function translateZodIssues(root: AvZNode, value: unknown, issues: readonly ZodIssueLike[]): readonly AvValidationIssue[];
51
57
  export {};
@@ -1,3 +1,4 @@
1
+ export const AVZ_CHECK_ISSUE = "aventara.check";
1
2
  const MISSING = Symbol("missing");
2
3
  function issue(code, path, message) {
3
4
  return { code, path, message };
@@ -104,6 +105,12 @@ function translateOne(root, value, zodIssue) {
104
105
  return [issue("V1000", path, "Required value missing.")];
105
106
  }
106
107
  switch (zodIssue.code) {
108
+ case "custom": {
109
+ const checked = zodIssue.params?.[AVZ_CHECK_ISSUE];
110
+ return checked === undefined
111
+ ? [issue("V1001", path, `Value does not match ${describe(node)}.`)]
112
+ : [{ ...checked, path: [...path, ...(checked.path ?? [])] }];
113
+ }
107
114
  case "invalid_type":
108
115
  return [issue("V1001", path, `Value must be ${describe(node)}.`)];
109
116
  case "invalid_value":
@@ -1,5 +1,31 @@
1
- /** Codes of {@link ContractCompilerDiagnostic}. */
2
- export type ContractCompilerDiagnosticCode = "COMPILER_UNKNOWN_RESOURCE" | "COMPILER_UNKNOWN_FIELD" | "COMPILER_RELATION_FIELD_CONFIG_UNSUPPORTED" | "COMPILER_INCOMPLETE_FIELD" | "COMPILER_STRUCTURAL_FIELD_OVERRIDE" | "COMPILER_MISSING_SCALAR" | "COMPILER_MISSING_ENUM" | "COMPILER_DANGLING_RELATION" | "COMPILER_UNAVAILABLE_OPERATION" | "COMPILER_UNAVAILABLE_CAPABILITY" | "COMPILER_INVALID_LIFECYCLE" | "COMPILER_MISSING_READ_BEHAVIOR" | "COMPILER_INVALID_BEHAVIOR_DEPENDENCY"
1
+ /** Codes of {@link AvContractCompilerDiagnostic}. */
2
+ export type AvContractCompilerDiagnosticCode = "COMPILER_UNKNOWN_RESOURCE" | "COMPILER_UNKNOWN_FIELD" | "COMPILER_RELATION_FIELD_CONFIG_UNSUPPORTED" | "COMPILER_INCOMPLETE_FIELD" | "COMPILER_STRUCTURAL_FIELD_OVERRIDE" | "COMPILER_MISSING_SCALAR" | "COMPILER_MISSING_ENUM" | "COMPILER_DANGLING_RELATION" | "COMPILER_UNAVAILABLE_OPERATION" | "COMPILER_UNAVAILABLE_CAPABILITY" | "COMPILER_INVALID_LIFECYCLE" | "COMPILER_MISSING_READ_COMPUTE" | "COMPILER_INVALID_COMPUTE_DEPENDENCY"
3
+ /**
4
+ * A Resource name the adapter model holds starts with `$`, which is reserved
5
+ * for the framework's own names (`ctx.$sql`, `$ref`, …).
6
+ */
7
+ | "COMPILER_RESERVED_RESOURCE_NAME"
8
+ /**
9
+ * A layer exposes a unique operation variant (`find.unique`, `update.unique`,
10
+ * `delete.unique`, `upsert.unique`) and no complete identifier of its Resource:
11
+ * a Pick that did not pick one, or an Omit that hid every one.
12
+ */
13
+ | "COMPILER_MISSING_IDENTIFIER"
14
+ /**
15
+ * A layer still creates a Resource (a create or upsert variant, or a nested
16
+ * create through a parent's relation) and leaves one of its create
17
+ * requirements unwritable on create: a required field hidden or with its
18
+ * `create` capability exempted and no `compute.create`, or a required relation
19
+ * not writable on create with a reference field neither writable nor computed.
20
+ */
21
+ | "COMPILER_HIDDEN_REQUIRED_FIELD"
22
+ /**
23
+ * A field validator cannot apply: it is not a check built with `AvZ`, it does
24
+ * not fit the field's type (`AvZ.maxLength` on an `int` field, `AvZ.maxItems`
25
+ * on a field that is not a list), or the field is a relation or a Json field
26
+ * (whose checks are in its shape).
27
+ */
28
+ | "COMPILER_INVALID_VALIDATOR"
3
29
  /**
4
30
  * A field's `json` shape cannot apply: the field is not a Json field the
5
31
  * adapter discovered, the value is not a shape built with `AvZ`, or the shape
@@ -8,14 +34,14 @@ export type ContractCompilerDiagnosticCode = "COMPILER_UNKNOWN_RESOURCE" | "COMP
8
34
  | "COMPILER_INVALID_JSON_SHAPE"
9
35
  /**
10
36
  * The finished, hashed client projection is not a structurally valid
11
- * `ClientContract`. A framework-bug guard: the server never serves what its own
37
+ * `AvContractClient`. A framework-bug guard: the server never serves what its own
12
38
  * generator would refuse. `path` is the JSONPath inside the ClientContract
13
39
  * (`$.enums.status.values[1]`).
14
40
  */
15
41
  | "COMPILER_INVALID_CLIENT_CONTRACT";
16
42
  /** One reason a configuration could not be compiled into Contracts. */
17
- export type ContractCompilerDiagnostic = {
18
- readonly code: ContractCompilerDiagnosticCode;
43
+ export type AvContractCompilerDiagnostic = {
44
+ readonly code: AvContractCompilerDiagnosticCode;
19
45
  readonly path: string;
20
46
  readonly message: string;
21
47
  };
@@ -1,12 +1,17 @@
1
- import type { AdapterModel } from "../adapters/adapter-model.js";
1
+ import type { AvAdapterModel } from "../adapters/adapter-model.js";
2
2
  import type { ResolvedFrameworkConfig } from "../config/config.resolver.js";
3
- import type { ApplicationContract, ClientContract, CoreContract } from "../contracts/contract.js";
4
- import type { ContractCompilerDiagnostic } from "./contract-compiler-diagnostic.js";
5
- /** The Core, Application and Client Contracts compiled from one configuration. */
6
- export type FrameworkContracts = {
7
- readonly core: CoreContract;
8
- readonly application: ApplicationContract;
9
- readonly client: ClientContract;
3
+ import type { AvContractAgent, AvContractApplication, AvContractClient, AvContractCore } from "../contracts/contract.js";
4
+ import type { AvContractCompilerDiagnostic } from "./contract-compiler-diagnostic.js";
5
+ /** The Core, Application, Client and Agent Contracts compiled from one configuration. */
6
+ export type AvContracts = {
7
+ readonly core: AvContractCore;
8
+ readonly application: AvContractApplication;
9
+ readonly client: AvContractClient;
10
+ /**
11
+ * The agent layer's Contract, which MCP tools are built from. With no `agent`
12
+ * layer configured it is the Client Contract's view.
13
+ */
14
+ readonly agent: AvContractAgent;
10
15
  };
11
16
  /**
12
17
  * The result of {@link compileContracts}: the three Contracts, or the
@@ -14,19 +19,14 @@ export type FrameworkContracts = {
14
19
  */
15
20
  export type ContractCompilationResult = {
16
21
  readonly ok: true;
17
- readonly contracts: FrameworkContracts;
22
+ readonly contracts: AvContracts;
18
23
  } | {
19
24
  readonly ok: false;
20
- readonly diagnostics: readonly ContractCompilerDiagnostic[];
25
+ readonly diagnostics: readonly AvContractCompilerDiagnostic[];
21
26
  };
22
- /**
23
- * Whether writing `configured` VERBATIM as capability member `key` would advertise
24
- * something `baseline` does not — the question the `fields` walk asks before it copies
25
- * a value onto an adapter field.
26
- */
27
- export declare function capabilityAddsBaseline(fieldKind: "scalar" | "relation", baseline: Readonly<Record<string, unknown>>, key: string, configured: unknown): boolean;
28
27
  /**
29
28
  * Compiles the Core Contract from the adapter model and the root
30
- * configuration, then the Application and Client Contracts from it.
29
+ * configuration, then the Application and Client Contracts from it, then the
30
+ * Agent Contract from the view of the layer it extends.
31
31
  */
32
- export declare function compileContracts<M extends AdapterModel>(model: M, config: ResolvedFrameworkConfig<M>): Promise<ContractCompilationResult>;
32
+ export declare function compileContracts<M extends AvAdapterModel>(model: M, config: ResolvedFrameworkConfig<M>): Promise<ContractCompilationResult>;