@aventara/core 0.1.0-pilot.3 → 1.0.0-rc.0
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.
- package/CHANGELOG.md +338 -0
- package/README.md +100 -3
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +2 -0
- package/dist/adapters/adapter-field.d.ts +3 -26
- package/dist/adapters/adapter-identifier.d.ts +1 -11
- package/dist/adapters/adapter-model.d.ts +12 -0
- package/dist/adapters/adapter-operation-executor.interface.d.ts +5 -1
- package/dist/adapters/adapter-resource.d.ts +7 -28
- package/dist/adapters/adapter.interface.d.ts +25 -26
- package/dist/compiler/contract-compiler-diagnostic.d.ts +8 -0
- package/dist/compiler/contract.compiler.d.ts +11 -22
- package/dist/compiler/contract.compiler.js +67 -0
- package/dist/config/any-framework-config.d.ts +5 -26
- package/dist/config/config-diagnostic.d.ts +2 -0
- package/dist/config/config-layer.d.ts +6 -19
- package/dist/config/config.resolver.d.ts +9 -14
- package/dist/config/config.resolver.js +1 -0
- package/dist/config/config.validator.d.ts +6 -3
- package/dist/config/config.validator.js +6 -0
- package/dist/config/define-fields.d.ts +15 -48
- package/dist/config/effective-fields.d.ts +6 -29
- package/dist/config/entrypoint.normalizer.d.ts +6 -18
- package/dist/config/framework-behaviors-config.d.ts +11 -10
- package/dist/config/framework-config.d.ts +19 -16
- package/dist/config/framework-fields-config.d.ts +20 -7
- package/dist/config/framework-restrictions-config.d.ts +41 -61
- package/dist/config/pipeline-config.d.ts +7 -17
- package/dist/contracts/capability.d.ts +13 -49
- package/dist/contracts/client-contract-structure.validator.d.ts +28 -54
- package/dist/contracts/client-contract-structure.validator.js +99 -2
- package/dist/contracts/contract-canonicalizer.d.ts +4 -6
- package/dist/contracts/contract-canonicalizer.js +32 -0
- package/dist/contracts/contract-hash.d.ts +3 -2
- package/dist/contracts/contract-limits.d.ts +7 -1
- package/dist/contracts/contract-protocol.d.ts +7 -8
- package/dist/contracts/contract.d.ts +20 -4
- package/dist/contracts/enum-definition.d.ts +2 -0
- package/dist/contracts/field.d.ts +40 -167
- package/dist/contracts/identifier.d.ts +1 -16
- package/dist/contracts/json-shape.d.ts +65 -0
- package/dist/contracts/json-shape.js +1 -0
- package/dist/contracts/lifecycle-trait.d.ts +4 -3
- package/dist/contracts/reference-write-limit.d.ts +7 -0
- package/dist/contracts/reference-write-limit.js +1 -0
- package/dist/contracts/resource-operations.d.ts +2 -62
- package/dist/contracts/resource.d.ts +2 -0
- package/dist/contracts/scalar-value-type.d.ts +28 -48
- package/dist/contracts/scalar.d.ts +4 -3
- package/dist/contracts/transaction-capability.d.ts +2 -0
- package/dist/contracts/wire-scalar-format.d.ts +6 -21
- package/dist/framework/contract-view.d.ts +152 -130
- package/dist/framework/framework-construction.error.d.ts +6 -1
- package/dist/framework/framework.d.ts +33 -46
- package/dist/framework/framework.factory.d.ts +3 -17
- package/dist/framework/framework.factory.js +56 -13
- package/dist/framework/operation-facade.d.ts +3 -7
- package/dist/index.d.ts +8 -40
- package/dist/index.js +0 -20
- package/dist/internal.d.ts +35 -0
- package/dist/internal.js +16 -0
- package/dist/json/avz.d.ts +96 -0
- package/dist/json/avz.js +212 -0
- package/dist/json/index.d.ts +6 -0
- package/dist/json/index.js +1 -0
- package/dist/json/json-shape.registry.d.ts +22 -0
- package/dist/json/json-shape.registry.js +16 -0
- package/dist/json/zod-issue.translator.d.ts +51 -0
- package/dist/json/zod-issue.translator.js +142 -0
- package/dist/operations/operation-arguments.d.ts +198 -303
- package/dist/operations/operation-call.d.ts +13 -15
- package/dist/operations/operation-identity.d.ts +6 -2
- package/dist/operations/operation-identity.js +3 -0
- package/dist/operations/operation-result.d.ts +15 -61
- package/dist/operations/operation-validator-core.d.ts +6 -5
- package/dist/operations/operation-validator-core.js +28 -10
- package/dist/operations/operation-validator.d.ts +22 -9
- package/dist/operations/operation-validator.js +26 -10
- package/dist/operations/projection-scope.resolver.d.ts +1 -11
- package/dist/operations/structural-limits.walker.d.ts +19 -0
- package/dist/operations/structural-limits.walker.js +344 -0
- package/dist/operations/validation-code.d.ts +5 -17
- package/dist/operations/write-scope.resolver.d.ts +3 -28
- package/dist/protocol/absent-route.responder.d.ts +25 -39
- package/dist/protocol/absent-route.responder.js +32 -6
- package/dist/protocol/av-protocol.d.ts +2 -8
- package/dist/protocol/contract-document.responder.d.ts +5 -18
- package/dist/protocol/http-request.decoder.d.ts +18 -59
- package/dist/protocol/http-request.decoder.js +11 -3
- package/dist/protocol/http-request.reader.d.ts +5 -5
- package/dist/protocol/http-response.encoder.d.ts +14 -20
- package/dist/protocol/http-status.table.d.ts +0 -8
- package/dist/protocol/index.d.ts +2 -7
- package/dist/protocol/operation-response.guard.d.ts +0 -15
- package/dist/protocol/protocol-failure.d.ts +8 -27
- package/dist/protocol/protocol-headers.d.ts +15 -42
- package/dist/protocol/protocol-surface.d.ts +0 -22
- package/dist/protocol/protocol.binder.d.ts +19 -27
- package/dist/protocol/protocol.binder.js +3 -1
- package/dist/protocol/protocol.handler.d.ts +19 -23
- package/dist/protocol/protocol.handler.js +14 -4
- package/dist/protocol/unmounted-route.error.d.ts +19 -0
- package/dist/protocol/unmounted-route.error.js +10 -0
- package/dist/runtime/caller-data.copier.d.ts +59 -0
- package/dist/runtime/caller-data.copier.js +470 -0
- package/dist/runtime/caller-data.door.d.ts +56 -0
- package/dist/runtime/caller-data.door.js +65 -0
- package/dist/runtime/computed-read-runtime.js +3 -10
- package/dist/runtime/computed-value.error.d.ts +13 -0
- package/dist/runtime/computed-value.error.js +9 -0
- package/dist/runtime/create-requirement.d.ts +43 -7
- package/dist/runtime/create-requirement.js +89 -9
- package/dist/runtime/decimal.d.ts +5 -3
- package/dist/runtime/diagnostics-reporter.d.ts +33 -37
- package/dist/runtime/diagnostics-reporter.js +11 -4
- package/dist/runtime/error-boundary.d.ts +14 -10
- package/dist/runtime/error-boundary.js +65 -35
- package/dist/runtime/execution-options.d.ts +3 -7
- package/dist/runtime/field-behavior.d.ts +14 -21
- package/dist/runtime/framework-error.d.ts +14 -2
- package/dist/runtime/json-value.d.ts +7 -15
- package/dist/runtime/misuse-reporter.d.ts +32 -0
- package/dist/runtime/misuse-reporter.js +19 -0
- package/dist/runtime/mutation-planner.d.ts +6 -12
- package/dist/runtime/mutation-planner.js +13 -11
- package/dist/runtime/operation-request.d.ts +11 -11
- package/dist/runtime/operation-response.d.ts +18 -23
- package/dist/runtime/operation-runtime.d.ts +25 -33
- package/dist/runtime/operation-runtime.js +37 -18
- package/dist/runtime/outcome-mapper.js +12 -2
- package/dist/runtime/output-validator.d.ts +10 -0
- package/dist/runtime/output-validator.js +11 -0
- package/dist/runtime/owned-execution.registry.d.ts +13 -0
- package/dist/runtime/owned-execution.registry.js +7 -0
- package/dist/runtime/pipeline.d.ts +33 -36
- package/dist/runtime/referential-action.d.ts +8 -26
- package/dist/runtime/request-envelope.validator.d.ts +5 -0
- package/dist/runtime/request-envelope.validator.js +118 -0
- package/dist/runtime/request-id.d.ts +3 -10
- package/dist/runtime/scalar-runtime.d.ts +42 -14
- package/dist/runtime/scalar-runtime.js +162 -79
- package/dist/transactions/deferred-operation.d.ts +10 -21
- package/dist/transactions/operation-arguments-encoder.d.ts +1 -0
- package/dist/transactions/operation-fingerprint.d.ts +3 -1
- package/dist/transactions/transaction-envelope.d.ts +2 -4
- package/dist/transactions/transaction-integrity-error.d.ts +4 -15
- package/dist/transactions/transaction-plan-assembler.d.ts +6 -1
- package/dist/transactions/transaction-plan-assembler.js +74 -75
- package/dist/transactions/transaction-plan-validator.d.ts +33 -24
- package/dist/transactions/transaction-plan-validator.js +204 -153
- package/dist/transactions/transaction-reference-collector.d.ts +30 -0
- package/dist/transactions/transaction-reference-collector.js +204 -0
- package/dist/transactions/transaction-reference-resolver.d.ts +9 -12
- package/dist/transactions/transaction-reference-resolver.js +10 -5
- package/dist/transactions/transaction-reference-validator.js +24 -17
- package/dist/transactions/transaction-reference.d.ts +31 -64
- package/dist/transactions/transaction-request.d.ts +6 -8
- package/dist/transactions/transaction-response.d.ts +10 -7
- package/dist/transactions/transaction-response.js +24 -1
- package/dist/transactions/transaction-runtime.d.ts +7 -5
- package/dist/transactions/transaction-runtime.js +4 -3
- package/dist/transactions/transaction-slot-path-error.d.ts +5 -15
- package/dist/transactions/transaction-slot-writer.d.ts +3 -13
- package/package.json +17 -3
- package/dist/operations/operation-boolean-nodes.d.ts +0 -11
- package/dist/operations/operation-boolean-nodes.js +0 -283
- package/dist/operations/operation-nesting.d.ts +0 -8
- package/dist/operations/operation-nesting.js +0 -307
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AvZ } from "./avz.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Contract } from "../contracts/contract.js";
|
|
2
|
+
import type { ScalarField } from "../contracts/field.js";
|
|
3
|
+
import type { JsonSchema } from "../contracts/json-shape.js";
|
|
4
|
+
import type { ValidationIssue } from "../operations/validation-code.js";
|
|
5
|
+
/** What core may do with a Json Shape: read its Contract form, check a value. */
|
|
6
|
+
export type JsonShapeRuntime = {
|
|
7
|
+
/** The shape's Contract form. */
|
|
8
|
+
readonly schema: JsonSchema;
|
|
9
|
+
/**
|
|
10
|
+
* Every way `value` — a JSON value — does not conform, each at its path inside
|
|
11
|
+
* the value; none when it conforms.
|
|
12
|
+
*/
|
|
13
|
+
readonly validate: (value: unknown) => readonly ValidationIssue[];
|
|
14
|
+
};
|
|
15
|
+
/** Records `shape` as a Json Shape. For `@aventara/core/json` only. */
|
|
16
|
+
export declare function registerJsonShape(shape: object, runtime: JsonShapeRuntime): void;
|
|
17
|
+
/** The Json Shape `value` is, or `undefined` when `AvZ` did not build it. */
|
|
18
|
+
export declare function jsonShapeOf(value: unknown): JsonShapeRuntime | undefined;
|
|
19
|
+
/** Binds a compiled Contract field to the shape it enforces. Compiler only. */
|
|
20
|
+
export declare function bindShapedField(field: ScalarField<Contract>, shape: JsonShapeRuntime): void;
|
|
21
|
+
/** The shape a compiled Contract field enforces, or `undefined`. */
|
|
22
|
+
export declare function shapeOfField(field: ScalarField<Contract>): JsonShapeRuntime | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const shapes = new WeakMap();
|
|
2
|
+
const fields = new WeakMap();
|
|
3
|
+
export function registerJsonShape(shape, runtime) {
|
|
4
|
+
shapes.set(shape, runtime);
|
|
5
|
+
}
|
|
6
|
+
export function jsonShapeOf(value) {
|
|
7
|
+
return typeof value === "object" && value !== null
|
|
8
|
+
? shapes.get(value)
|
|
9
|
+
: undefined;
|
|
10
|
+
}
|
|
11
|
+
export function bindShapedField(field, shape) {
|
|
12
|
+
fields.set(field, shape);
|
|
13
|
+
}
|
|
14
|
+
export function shapeOfField(field) {
|
|
15
|
+
return fields.get(field);
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { JsonSchemaPrimitive } from "../contracts/json-shape.js";
|
|
2
|
+
import type { ValidationIssue } from "../operations/validation-code.js";
|
|
3
|
+
/** A shape as the translator reads it: its form and its parts, no Zod. */
|
|
4
|
+
export type AvZNode = {
|
|
5
|
+
readonly kind: "string" | "number" | "int" | "boolean" | "null";
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "literal";
|
|
8
|
+
readonly value: JsonSchemaPrimitive;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "enum";
|
|
11
|
+
readonly values: readonly string[];
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "object";
|
|
14
|
+
readonly fields: Readonly<Record<string, AvZNode>>;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "array";
|
|
17
|
+
readonly item: AvZNode;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "tuple";
|
|
20
|
+
readonly items: readonly AvZNode[];
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "record";
|
|
23
|
+
readonly value: AvZNode;
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: "union";
|
|
26
|
+
readonly options: readonly AvZNode[];
|
|
27
|
+
} | {
|
|
28
|
+
readonly kind: "discriminatedUnion";
|
|
29
|
+
readonly discriminator: string;
|
|
30
|
+
readonly options: readonly AvZNode[];
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "optional" | "nullable";
|
|
33
|
+
readonly inner: AvZNode;
|
|
34
|
+
};
|
|
35
|
+
/** The members of a Zod issue this module reads. */
|
|
36
|
+
type ZodIssueLike = {
|
|
37
|
+
readonly code: string;
|
|
38
|
+
readonly path: readonly PropertyKey[];
|
|
39
|
+
readonly origin?: string;
|
|
40
|
+
readonly keys?: readonly string[];
|
|
41
|
+
readonly note?: string;
|
|
42
|
+
readonly options?: readonly unknown[];
|
|
43
|
+
readonly minimum?: unknown;
|
|
44
|
+
readonly maximum?: unknown;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Aventara's issues for the ones Zod raised judging `value` against the shape
|
|
48
|
+
* `root`: each at its path inside the value, in Zod's order.
|
|
49
|
+
*/
|
|
50
|
+
export declare function translateZodIssues(root: AvZNode, value: unknown, issues: readonly ZodIssueLike[]): readonly ValidationIssue[];
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const MISSING = Symbol("missing");
|
|
2
|
+
function issue(code, path, message) {
|
|
3
|
+
return { code, path, message };
|
|
4
|
+
}
|
|
5
|
+
function valueAt(root, path) {
|
|
6
|
+
let current = root;
|
|
7
|
+
for (const segment of path) {
|
|
8
|
+
if (typeof current !== "object" ||
|
|
9
|
+
current === null ||
|
|
10
|
+
!Object.hasOwn(current, segment)) {
|
|
11
|
+
return MISSING;
|
|
12
|
+
}
|
|
13
|
+
current = current[segment];
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
function unwrap(node) {
|
|
18
|
+
return node.kind === "optional" || node.kind === "nullable"
|
|
19
|
+
? unwrap(node.inner)
|
|
20
|
+
: node;
|
|
21
|
+
}
|
|
22
|
+
function selectedOption(node, value) {
|
|
23
|
+
const tag = valueAt(value, [node.discriminator]);
|
|
24
|
+
return node.options.find((option) => {
|
|
25
|
+
const field = option.kind === "object" ? option.fields[node.discriminator] : undefined;
|
|
26
|
+
const inner = field === undefined ? undefined : unwrap(field);
|
|
27
|
+
return inner?.kind === "literal"
|
|
28
|
+
? Object.is(inner.value, tag)
|
|
29
|
+
: inner?.kind === "enum" && inner.values.includes(tag);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function nodeAt(root, value, path) {
|
|
33
|
+
let node = root;
|
|
34
|
+
let current = value;
|
|
35
|
+
for (const segment of path) {
|
|
36
|
+
node = node === undefined ? undefined : unwrap(node);
|
|
37
|
+
if (node?.kind === "discriminatedUnion") {
|
|
38
|
+
node = selectedOption(node, current);
|
|
39
|
+
}
|
|
40
|
+
switch (node?.kind) {
|
|
41
|
+
case "object":
|
|
42
|
+
node = node.fields[segment];
|
|
43
|
+
break;
|
|
44
|
+
case "array":
|
|
45
|
+
node = node.item;
|
|
46
|
+
break;
|
|
47
|
+
case "tuple":
|
|
48
|
+
node = typeof segment === "number" ? node.items[segment] : undefined;
|
|
49
|
+
break;
|
|
50
|
+
case "record":
|
|
51
|
+
node = node.value;
|
|
52
|
+
break;
|
|
53
|
+
default:
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
current = valueAt(current, [segment]);
|
|
57
|
+
}
|
|
58
|
+
return node;
|
|
59
|
+
}
|
|
60
|
+
function describe(node) {
|
|
61
|
+
if (node === undefined) {
|
|
62
|
+
return "the field's shape";
|
|
63
|
+
}
|
|
64
|
+
switch (node.kind) {
|
|
65
|
+
case "string":
|
|
66
|
+
return "a string";
|
|
67
|
+
case "number":
|
|
68
|
+
return "a number";
|
|
69
|
+
case "int":
|
|
70
|
+
return "an integer";
|
|
71
|
+
case "boolean":
|
|
72
|
+
return "a boolean";
|
|
73
|
+
case "null":
|
|
74
|
+
return "null";
|
|
75
|
+
case "literal":
|
|
76
|
+
return JSON.stringify(node.value);
|
|
77
|
+
case "enum":
|
|
78
|
+
return `one of ${node.values.map((value) => JSON.stringify(value)).join(", ")}`;
|
|
79
|
+
case "object":
|
|
80
|
+
case "record":
|
|
81
|
+
return "an object";
|
|
82
|
+
case "array":
|
|
83
|
+
return "a list";
|
|
84
|
+
case "tuple":
|
|
85
|
+
return `a list of exactly ${node.items.length} entries`;
|
|
86
|
+
case "union":
|
|
87
|
+
case "discriminatedUnion":
|
|
88
|
+
return [...new Set(node.options.map(describe))].join(" or ");
|
|
89
|
+
case "optional":
|
|
90
|
+
return describe(node.inner);
|
|
91
|
+
case "nullable":
|
|
92
|
+
return `${describe(node.inner)} or null`;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function pathOf(path) {
|
|
96
|
+
return path.map((segment) => typeof segment === "symbol" ? String(segment) : segment);
|
|
97
|
+
}
|
|
98
|
+
function translateOne(root, value, zodIssue) {
|
|
99
|
+
const path = pathOf(zodIssue.path);
|
|
100
|
+
const node = nodeAt(root, value, path);
|
|
101
|
+
const absent = path.length > 0 && valueAt(value, path) === MISSING;
|
|
102
|
+
if (absent &&
|
|
103
|
+
(zodIssue.code === "invalid_type" || zodIssue.code === "invalid_value")) {
|
|
104
|
+
return [issue("V1000", path, "Required value missing.")];
|
|
105
|
+
}
|
|
106
|
+
switch (zodIssue.code) {
|
|
107
|
+
case "invalid_type":
|
|
108
|
+
return [issue("V1001", path, `Value must be ${describe(node)}.`)];
|
|
109
|
+
case "invalid_value":
|
|
110
|
+
return [issue("V1002", path, `Value must be ${describe(node)}.`)];
|
|
111
|
+
case "unrecognized_keys":
|
|
112
|
+
return (zodIssue.keys ?? []).map((key) => issue("V1005", [...path, key], "Key is not part of the shape."));
|
|
113
|
+
case "invalid_union": {
|
|
114
|
+
if (zodIssue.note !== undefined && Array.isArray(zodIssue.options)) {
|
|
115
|
+
if (absent) {
|
|
116
|
+
return [issue("V1000", path, "Required value missing.")];
|
|
117
|
+
}
|
|
118
|
+
const allowed = zodIssue.options
|
|
119
|
+
.map((option) => JSON.stringify(option))
|
|
120
|
+
.join(", ");
|
|
121
|
+
return [issue("V1002", path, `Value must be one of ${allowed}.`)];
|
|
122
|
+
}
|
|
123
|
+
return [issue("V1001", path, `Value must be ${describe(node)}.`)];
|
|
124
|
+
}
|
|
125
|
+
case "too_big":
|
|
126
|
+
case "too_small":
|
|
127
|
+
if (zodIssue.origin === "array" && node !== undefined) {
|
|
128
|
+
return [issue("V1001", path, `Value must be ${describe(node)}.`)];
|
|
129
|
+
}
|
|
130
|
+
if (zodIssue.origin === "int" || zodIssue.origin === "number") {
|
|
131
|
+
return [
|
|
132
|
+
issue("V1004", path, "Value must be a safe integer (between -9007199254740991 and 9007199254740991)."),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
return [issue("V1001", path, `Value does not match ${describe(node)}.`)];
|
|
136
|
+
default:
|
|
137
|
+
return [issue("V1001", path, `Value does not match ${describe(node)}.`)];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function translateZodIssues(root, value, issues) {
|
|
141
|
+
return issues.flatMap((zodIssue) => translateOne(root, value, zodIssue));
|
|
142
|
+
}
|