@aventara/core 0.1.0-pilot.4 → 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.
- package/CHANGELOG.md +1478 -0
- package/README.md +275 -11
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
- package/dist/adapters/adapter-field.d.ts +11 -11
- package/dist/adapters/adapter-identifier.d.ts +6 -6
- package/dist/adapters/adapter-model.d.ts +17 -9
- package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
- package/dist/adapters/adapter-operation.d.ts +3 -3
- package/dist/adapters/adapter-resource.d.ts +18 -9
- package/dist/adapters/adapter-sql-statement.d.ts +19 -0
- package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
- package/dist/adapters/adapter.interface.d.ts +49 -25
- package/dist/avz/avz-check.factory.d.ts +83 -0
- package/dist/avz/avz-check.factory.js +116 -0
- package/dist/avz/avz-check.registry.d.ts +35 -0
- package/dist/avz/avz-check.registry.js +9 -0
- package/dist/avz/avz.d.ts +203 -0
- package/dist/avz/avz.js +354 -0
- package/dist/avz/index.d.ts +7 -0
- package/dist/avz/index.js +1 -0
- package/dist/avz/json-shape.registry.d.ts +22 -0
- package/dist/avz/json-shape.registry.js +16 -0
- package/dist/avz/zod-issue.translator.d.ts +57 -0
- package/dist/avz/zod-issue.translator.js +149 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +37 -5
- package/dist/compiler/contract.compiler.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +595 -421
- package/dist/compiler/create-requirements.projector.d.ts +49 -0
- package/dist/compiler/create-requirements.projector.js +423 -0
- package/dist/compiler/field-validator.compiler.d.ts +47 -0
- package/dist/compiler/field-validator.compiler.js +238 -0
- package/dist/config/any-framework-config.d.ts +19 -12
- package/dist/config/config-diagnostic.d.ts +11 -4
- package/dist/config/config-layer.d.ts +15 -6
- package/dist/config/config.resolver.d.ts +75 -29
- package/dist/config/config.resolver.js +109 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +586 -71
- package/dist/config/define-resource.d.ts +57 -0
- package/dist/config/define-resource.js +14 -0
- package/dist/config/effective-fields.d.ts +19 -23
- package/dist/config/entrypoint.normalizer.d.ts +1 -1
- package/dist/config/exact-framework-config.d.ts +280 -0
- package/dist/config/field-compute.resolver.d.ts +19 -0
- package/dist/config/field-compute.resolver.js +115 -0
- package/dist/config/field-pipeline-config.d.ts +47 -0
- package/dist/config/forced-operation.validator.d.ts +10 -0
- package/dist/config/forced-operation.validator.js +66 -0
- package/dist/config/framework-config.d.ts +111 -37
- package/dist/config/framework-exemptions-config.d.ts +91 -0
- package/dist/config/framework-exemptions-config.js +1 -0
- package/dist/config/framework-field-definition.d.ts +78 -0
- package/dist/config/framework-field-definition.js +28 -0
- package/dist/config/framework-resources-config.d.ts +116 -0
- package/dist/config/framework-resources-config.js +1 -0
- package/dist/config/pipeline-config.d.ts +56 -20
- package/dist/config/pipeline-tree.resolver.d.ts +79 -0
- package/dist/config/pipeline-tree.resolver.js +220 -0
- package/dist/config/stage-type.eraser.d.ts +65 -0
- package/dist/config/stage-type.eraser.js +1 -0
- package/dist/contracts/capability.d.ts +11 -11
- package/dist/contracts/client-contract-structure.validator.d.ts +344 -29
- package/dist/contracts/client-contract-structure.validator.js +248 -7
- package/dist/contracts/contract-canonicalizer.d.ts +19 -3
- package/dist/contracts/contract-canonicalizer.js +172 -27
- package/dist/contracts/contract-hash.d.ts +12 -7
- package/dist/contracts/contract-hash.js +3 -2
- package/dist/contracts/contract-limits.d.ts +4 -1
- package/dist/contracts/contract-limits.js +1 -0
- package/dist/contracts/contract-lookup.d.ts +5 -5
- package/dist/contracts/contract-protocol.d.ts +4 -4
- package/dist/contracts/contract.d.ts +31 -16
- package/dist/contracts/create-requirements.d.ts +35 -0
- package/dist/contracts/create-requirements.js +1 -0
- package/dist/contracts/enum-definition.d.ts +1 -1
- package/dist/contracts/field-check.d.ts +101 -0
- package/dist/contracts/field-check.js +1 -0
- package/dist/contracts/field.d.ts +61 -41
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-shape.d.ts +76 -0
- package/dist/contracts/json-shape.js +1 -0
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- 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 +28 -28
- package/dist/contracts/resource.d.ts +15 -9
- package/dist/contracts/scalar-value-type.d.ts +25 -14
- package/dist/contracts/scalar.d.ts +3 -3
- package/dist/contracts/transaction-capability.d.ts +1 -1
- package/dist/contracts/wire-scalar-format.d.ts +4 -4
- package/dist/framework/contract-view.d.ts +234 -63
- package/dist/framework/framework-construction.error.d.ts +10 -10
- package/dist/framework/framework-construction.error.js +2 -2
- package/dist/framework/framework.d.ts +50 -24
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +95 -32
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +55 -82
- package/dist/index.js +6 -26
- package/dist/internal.d.ts +40 -0
- package/dist/internal.js +18 -0
- package/dist/operations/operation-arguments.d.ts +316 -201
- package/dist/operations/operation-call.d.ts +27 -28
- package/dist/operations/operation-identity.d.ts +12 -10
- package/dist/operations/operation-identity.js +3 -0
- package/dist/operations/operation-result.d.ts +21 -21
- package/dist/operations/operation-validator-core.d.ts +6 -6
- package/dist/operations/operation-validator-core.js +41 -12
- package/dist/operations/operation-validator.d.ts +24 -9
- package/dist/operations/operation-validator.js +26 -10
- package/dist/operations/projection-scope.resolver.d.ts +7 -7
- package/dist/operations/structural-limits.walker.d.ts +19 -0
- package/dist/operations/structural-limits.walker.js +489 -0
- package/dist/operations/validation-code.d.ts +11 -6
- package/dist/operations/validation-code.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +6 -6
- package/dist/protocol/absent-route.responder.d.ts +13 -11
- package/dist/protocol/absent-route.responder.js +42 -16
- package/dist/protocol/contract-document.responder.d.ts +3 -3
- package/dist/protocol/contract-document.responder.js +2 -2
- package/dist/protocol/http-request.decoder.d.ts +23 -13
- package/dist/protocol/http-request.decoder.js +19 -11
- package/dist/protocol/http-request.reader.d.ts +3 -3
- package/dist/protocol/http-response.encoder.d.ts +4 -4
- package/dist/protocol/http-response.encoder.js +94 -55
- package/dist/protocol/http-status.table.d.ts +2 -2
- package/dist/protocol/operation-response.guard.d.ts +2 -2
- package/dist/protocol/protocol-surface.d.ts +4 -4
- package/dist/protocol/protocol.binder.d.ts +52 -27
- package/dist/protocol/protocol.binder.js +14 -9
- package/dist/protocol/protocol.handler.d.ts +28 -15
- package/dist/protocol/protocol.handler.js +55 -10
- 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 +67 -0
- package/dist/runtime/computed-read-runtime.d.ts +7 -6
- package/dist/runtime/computed-read-runtime.js +61 -55
- package/dist/runtime/computed-value.error.d.ts +13 -0
- package/dist/runtime/computed-value.error.js +9 -0
- package/dist/runtime/context-executor.runtime.d.ts +59 -0
- package/dist/runtime/context-executor.runtime.js +275 -0
- package/dist/runtime/create-requirement.d.ts +22 -57
- package/dist/runtime/create-requirement.js +140 -37
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +64 -22
- package/dist/runtime/diagnostics-reporter.js +35 -4
- package/dist/runtime/error-boundary.d.ts +73 -8
- package/dist/runtime/error-boundary.js +104 -48
- package/dist/runtime/execution-options.d.ts +10 -2
- package/dist/runtime/field-check.evaluator.d.ts +29 -0
- package/dist/runtime/field-check.evaluator.js +521 -0
- package/dist/runtime/field-compute.d.ts +64 -0
- package/dist/runtime/field-compute.js +1 -0
- package/dist/runtime/field-stage.plan.d.ts +15 -0
- package/dist/runtime/field-stage.plan.js +27 -0
- package/dist/runtime/field-stage.runtime.d.ts +35 -0
- package/dist/runtime/field-stage.runtime.js +143 -0
- package/dist/runtime/field-validator.runtime.d.ts +11 -0
- package/dist/runtime/field-validator.runtime.js +87 -0
- package/dist/runtime/framework-error-class.table.d.ts +33 -0
- package/dist/runtime/framework-error-class.table.js +25 -0
- package/dist/runtime/framework-error.d.ts +79 -7
- package/dist/runtime/framework-error.factory.d.ts +4 -0
- package/dist/runtime/framework-error.factory.js +15 -0
- package/dist/runtime/framework-error.js +23 -2
- package/dist/runtime/interceptor-next.error.d.ts +5 -0
- package/dist/runtime/interceptor-next.error.js +6 -0
- package/dist/runtime/json-value.d.ts +3 -3
- package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
- package/dist/runtime/level-lifecycle.runtime.js +42 -0
- package/dist/runtime/misuse-reporter.d.ts +32 -0
- package/dist/runtime/misuse-reporter.js +19 -0
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +62 -36
- package/dist/runtime/nested-write.walker.d.ts +32 -0
- package/dist/runtime/nested-write.walker.js +73 -0
- package/dist/runtime/operation-request.d.ts +35 -15
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +125 -30
- package/dist/runtime/operation-runtime.js +423 -83
- package/dist/runtime/outcome-mapper.d.ts +16 -5
- package/dist/runtime/outcome-mapper.js +35 -8
- package/dist/runtime/output-validator.d.ts +16 -6
- package/dist/runtime/output-validator.js +12 -1
- package/dist/runtime/owned-execution.registry.d.ts +13 -0
- package/dist/runtime/owned-execution.registry.js +7 -0
- package/dist/runtime/pipe-output.validator.d.ts +33 -18
- package/dist/runtime/pipe-output.validator.js +12 -12
- package/dist/runtime/pipeline.d.ts +202 -28
- package/dist/runtime/readonly-value.d.ts +32 -0
- package/dist/runtime/readonly-value.js +141 -0
- package/dist/runtime/referential-action.d.ts +7 -0
- package/dist/runtime/request-envelope.validator.d.ts +5 -0
- package/dist/runtime/request-envelope.validator.js +123 -0
- package/dist/runtime/request-id.d.ts +1 -1
- package/dist/runtime/request-state.d.ts +14 -0
- package/dist/runtime/request-state.js +1 -0
- package/dist/runtime/request-state.resolver.d.ts +12 -0
- package/dist/runtime/request-state.resolver.js +20 -0
- package/dist/runtime/scalar-runtime.d.ts +56 -13
- package/dist/runtime/scalar-runtime.js +167 -86
- package/dist/transactions/deferred-operation.d.ts +35 -20
- package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
- package/dist/transactions/operation-arguments-encoder.js +2 -2
- package/dist/transactions/sql-statement.d.ts +77 -0
- package/dist/transactions/sql-statement.js +47 -0
- package/dist/transactions/sql-statement.validator.d.ts +44 -0
- package/dist/transactions/sql-statement.validator.js +134 -0
- package/dist/transactions/transaction-envelope.d.ts +4 -4
- package/dist/transactions/transaction-integrity-error.d.ts +6 -6
- package/dist/transactions/transaction-integrity-error.js +5 -2
- package/dist/transactions/transaction-plan-assembler.d.ts +23 -9
- package/dist/transactions/transaction-plan-assembler.js +195 -82
- package/dist/transactions/transaction-plan-validator.d.ts +53 -21
- package/dist/transactions/transaction-plan-validator.js +246 -163
- 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 +19 -2
- package/dist/transactions/transaction-reference-resolver.js +27 -10
- package/dist/transactions/transaction-reference-validator.d.ts +34 -4
- package/dist/transactions/transaction-reference-validator.js +82 -43
- package/dist/transactions/transaction-reference.d.ts +30 -58
- package/dist/transactions/transaction-request.d.ts +20 -7
- package/dist/transactions/transaction-response.d.ts +12 -7
- package/dist/transactions/transaction-response.js +24 -1
- package/dist/transactions/transaction-runtime.d.ts +11 -8
- package/dist/transactions/transaction-runtime.js +167 -50
- package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
- package/dist/transactions/transaction-settlement.runtime.js +120 -0
- package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
- package/dist/transactions/transaction-slot-path-error.js +2 -2
- package/dist/transactions/transaction-slot-writer.js +2 -2
- package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
- package/dist/transactions/transaction-stage.runtime.js +123 -0
- package/package.json +18 -3
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -35
- package/dist/config/define-fields.js +0 -3
- package/dist/config/framework-behaviors-config.d.ts +0 -30
- package/dist/config/framework-fields-config.d.ts +0 -36
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- 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
- package/dist/runtime/field-behavior.d.ts +0 -48
- /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
- /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
- /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
- /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
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
|
+
export function frozenCopy(value) {
|
|
40
|
+
const copies = new Map();
|
|
41
|
+
const copy = (current) => {
|
|
42
|
+
const scalar = scalarCopy(current);
|
|
43
|
+
if (scalar !== undefined) {
|
|
44
|
+
return scalar;
|
|
45
|
+
}
|
|
46
|
+
if (!isContainer(current)) {
|
|
47
|
+
return current;
|
|
48
|
+
}
|
|
49
|
+
if (copies.has(current)) {
|
|
50
|
+
return copies.get(current);
|
|
51
|
+
}
|
|
52
|
+
copies.set(current, current);
|
|
53
|
+
const entries = [];
|
|
54
|
+
let changed = !DEEP_FROZEN.has(current);
|
|
55
|
+
for (const key of Reflect.ownKeys(current)) {
|
|
56
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
57
|
+
if (descriptor === undefined ||
|
|
58
|
+
!("value" in descriptor) ||
|
|
59
|
+
(Array.isArray(current) && key === "length")) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const next = copy(descriptor.value);
|
|
63
|
+
changed ||= next !== descriptor.value;
|
|
64
|
+
entries.push([key, descriptor, next]);
|
|
65
|
+
}
|
|
66
|
+
if (!changed) {
|
|
67
|
+
copies.set(current, current);
|
|
68
|
+
return current;
|
|
69
|
+
}
|
|
70
|
+
const target = Array.isArray(current)
|
|
71
|
+
? new Array(current.length)
|
|
72
|
+
: Object.create(Object.getPrototypeOf(current));
|
|
73
|
+
for (const [key, descriptor, next] of entries) {
|
|
74
|
+
Object.defineProperty(target, key, {
|
|
75
|
+
value: next,
|
|
76
|
+
enumerable: descriptor.enumerable ?? false,
|
|
77
|
+
writable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const frozen = deepFreeze(target);
|
|
82
|
+
copies.set(current, frozen);
|
|
83
|
+
return frozen;
|
|
84
|
+
};
|
|
85
|
+
return copy(value);
|
|
86
|
+
}
|
|
87
|
+
function readOnlyWrite(subject) {
|
|
88
|
+
return new TypeError(`${subject} is read-only here.`);
|
|
89
|
+
}
|
|
90
|
+
const VIEWS = new WeakMap();
|
|
91
|
+
export function readonlyView(value, subject) {
|
|
92
|
+
if (!isContainer(value)) {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
const known = VIEWS.get(value);
|
|
96
|
+
if (known !== undefined) {
|
|
97
|
+
return known;
|
|
98
|
+
}
|
|
99
|
+
const real = value;
|
|
100
|
+
const standIn = Array.isArray(value)
|
|
101
|
+
? []
|
|
102
|
+
: Object.create(Object.getPrototypeOf(value));
|
|
103
|
+
const refuse = () => {
|
|
104
|
+
throw readOnlyWrite(subject);
|
|
105
|
+
};
|
|
106
|
+
const view = new Proxy(standIn, {
|
|
107
|
+
get: (_target, key) => readonlyView(real[key], subject),
|
|
108
|
+
has: (_target, key) => key in real,
|
|
109
|
+
ownKeys: () => Reflect.ownKeys(real),
|
|
110
|
+
getOwnPropertyDescriptor: (target, key) => {
|
|
111
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(real, key);
|
|
112
|
+
if (descriptor === undefined) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (Reflect.getOwnPropertyDescriptor(target, key)?.configurable === false) {
|
|
116
|
+
return {
|
|
117
|
+
value: descriptor.value,
|
|
118
|
+
enumerable: false,
|
|
119
|
+
writable: true,
|
|
120
|
+
configurable: false,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return "value" in descriptor
|
|
124
|
+
? {
|
|
125
|
+
value: readonlyView(descriptor.value, subject),
|
|
126
|
+
enumerable: descriptor.enumerable ?? false,
|
|
127
|
+
writable: false,
|
|
128
|
+
configurable: true,
|
|
129
|
+
}
|
|
130
|
+
: { ...descriptor, configurable: true };
|
|
131
|
+
},
|
|
132
|
+
getPrototypeOf: () => Object.getPrototypeOf(real),
|
|
133
|
+
set: refuse,
|
|
134
|
+
defineProperty: refuse,
|
|
135
|
+
deleteProperty: refuse,
|
|
136
|
+
setPrototypeOf: refuse,
|
|
137
|
+
preventExtensions: refuse,
|
|
138
|
+
});
|
|
139
|
+
VIEWS.set(value, view);
|
|
140
|
+
return view;
|
|
141
|
+
}
|
|
@@ -23,6 +23,13 @@ export type ReferentialEdge = {
|
|
|
23
23
|
readonly field: string;
|
|
24
24
|
/** The Resource the edge points AT — the one whose deletion fires `onDelete`. */
|
|
25
25
|
readonly target: string;
|
|
26
|
+
/**
|
|
27
|
+
* The scalar fields of the ENCLOSING Resource that hold the reference, in the
|
|
28
|
+
* order the store pairs them with the `target`'s key. A record that writes the
|
|
29
|
+
* relation `field` and any of these names the reference twice and is refused;
|
|
30
|
+
* a required relation may be written through all of them instead.
|
|
31
|
+
*/
|
|
32
|
+
readonly references: readonly string[];
|
|
26
33
|
/** What deleting a `target` row does to rows of the ENCLOSING Resource. */
|
|
27
34
|
readonly onDelete: ReferentialDeleteEffect;
|
|
28
35
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AvValidationIssue } from "../operations/validation-code.js";
|
|
2
|
+
/** The issues of one malformed operation request envelope; empty when well formed. */
|
|
3
|
+
export declare function validateOperationEnvelope(request: unknown): readonly AvValidationIssue[];
|
|
4
|
+
/** The issues of one malformed transaction request envelope; empty when well formed. */
|
|
5
|
+
export declare function validateTransactionEnvelope(request: unknown): readonly AvValidationIssue[];
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const ORIGINS = ["application", "client", "agent"];
|
|
2
|
+
const OPERATION_IDENTITY_MEMBERS = ["resource", "family", "variant"];
|
|
3
|
+
export function validateOperationEnvelope(request) {
|
|
4
|
+
if (!isRecord(request)) {
|
|
5
|
+
return [issue([], "V1001", "Operation request must be an object.")];
|
|
6
|
+
}
|
|
7
|
+
const issues = [...originAndIdentityIssues(request)];
|
|
8
|
+
for (const member of OPERATION_IDENTITY_MEMBERS) {
|
|
9
|
+
const failure = requiredStringIssue(request, member);
|
|
10
|
+
if (failure !== undefined) {
|
|
11
|
+
issues.push(failure);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return issues;
|
|
15
|
+
}
|
|
16
|
+
export function validateTransactionEnvelope(request) {
|
|
17
|
+
if (!isRecord(request)) {
|
|
18
|
+
return [issue([], "V1001", "Transaction request must be an object.")];
|
|
19
|
+
}
|
|
20
|
+
return originAndIdentityIssues(request);
|
|
21
|
+
}
|
|
22
|
+
function originAndIdentityIssues(request) {
|
|
23
|
+
const issues = [];
|
|
24
|
+
const origin = request.origin;
|
|
25
|
+
if (origin === undefined) {
|
|
26
|
+
issues.push(issue(["origin"], "V1000", 'Required property "origin" is missing.'));
|
|
27
|
+
}
|
|
28
|
+
else if (typeof origin !== "string") {
|
|
29
|
+
issues.push(issue(["origin"], "V1001", "Request origin must be a string."));
|
|
30
|
+
}
|
|
31
|
+
else if (!ORIGINS.includes(origin)) {
|
|
32
|
+
issues.push(issue(["origin"], "V1002", 'Request origin must be "application", "client" or "agent".'));
|
|
33
|
+
}
|
|
34
|
+
const requestId = request.requestId;
|
|
35
|
+
if (requestId === undefined || requestId === "") {
|
|
36
|
+
issues.push(issue(["requestId"], "V1000", 'Required property "requestId" is missing or empty.'));
|
|
37
|
+
}
|
|
38
|
+
else if (typeof requestId !== "string") {
|
|
39
|
+
issues.push(issue(["requestId"], "V1001", "Request id must be a string."));
|
|
40
|
+
}
|
|
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));
|
|
48
|
+
if (request.transport !== undefined) {
|
|
49
|
+
issues.push(...transportIssues(request.transport));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (origin === "application") {
|
|
53
|
+
for (const member of ["protocol", "transport"]) {
|
|
54
|
+
if (request[member] !== undefined) {
|
|
55
|
+
issues.push(issue([member], "V1005", `Property "${member}" belongs to a client or agent request, not an application one.`));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return issues;
|
|
60
|
+
}
|
|
61
|
+
function protocolIssues(protocol, origin) {
|
|
62
|
+
if (protocol === undefined) {
|
|
63
|
+
return [
|
|
64
|
+
issue(["protocol"], "V1000", `Required property "protocol" is missing from ${origin === "client" ? "a client" : "an agent"} request.`),
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
if (!isRecord(protocol)) {
|
|
68
|
+
return [
|
|
69
|
+
issue(["protocol"], "V1001", "Protocol identity must be an object."),
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
const issues = [];
|
|
73
|
+
if (protocol.version === undefined) {
|
|
74
|
+
issues.push(issue(["protocol", "version"], "V1000", 'Required property "version" is missing.'));
|
|
75
|
+
}
|
|
76
|
+
else if (!Number.isInteger(protocol.version)) {
|
|
77
|
+
issues.push(issue(["protocol", "version"], "V1001", "Protocol version must be an integer."));
|
|
78
|
+
}
|
|
79
|
+
if (protocol.hash === undefined) {
|
|
80
|
+
issues.push(issue(["protocol", "hash"], "V1000", 'Required property "hash" is missing.'));
|
|
81
|
+
}
|
|
82
|
+
else if (typeof protocol.hash !== "string") {
|
|
83
|
+
issues.push(issue(["protocol", "hash"], "V1001", "Protocol hash must be a string."));
|
|
84
|
+
}
|
|
85
|
+
return issues;
|
|
86
|
+
}
|
|
87
|
+
function transportIssues(transport) {
|
|
88
|
+
if (!isRecord(transport)) {
|
|
89
|
+
return [
|
|
90
|
+
issue(["transport"], "V1001", "Transport metadata must be an object."),
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
const issues = [];
|
|
94
|
+
if (transport.method !== "POST") {
|
|
95
|
+
issues.push(issue(["transport", "method"], "V1001", 'Transport method must be "POST".'));
|
|
96
|
+
}
|
|
97
|
+
const headers = transport.headers;
|
|
98
|
+
if (!isRecord(headers)) {
|
|
99
|
+
issues.push(issue(["transport", "headers"], "V1001", "Transport headers must be an object."));
|
|
100
|
+
return issues;
|
|
101
|
+
}
|
|
102
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
103
|
+
if (typeof value !== "string") {
|
|
104
|
+
issues.push(issue(["transport", "headers", name], "V1001", "A transport header value must be a string."));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return issues;
|
|
108
|
+
}
|
|
109
|
+
function requiredStringIssue(request, member) {
|
|
110
|
+
const value = request[member];
|
|
111
|
+
if (value === undefined) {
|
|
112
|
+
return issue([member], "V1000", `Required property "${member}" is missing.`);
|
|
113
|
+
}
|
|
114
|
+
return typeof value === "string"
|
|
115
|
+
? undefined
|
|
116
|
+
: issue([member], "V1001", `Property "${member}" must be a string.`);
|
|
117
|
+
}
|
|
118
|
+
function isRecord(value) {
|
|
119
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
120
|
+
}
|
|
121
|
+
function issue(path, code, message) {
|
|
122
|
+
return { path, code, message };
|
|
123
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The request id of one call or transaction run: the caller's
|
|
3
|
-
* `
|
|
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,55 +1,98 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
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";
|
|
5
6
|
import type { OperationValidationOptions, SemanticOperationArguments } from "../operations/operation-validator.js";
|
|
6
|
-
import type {
|
|
7
|
+
import type { AvValidationIssue } from "../operations/validation-code.js";
|
|
8
|
+
import { type TransactionSlotShape } from "../transactions/transaction-reference.js";
|
|
7
9
|
export type ScalarNormalizationResult = {
|
|
8
10
|
readonly ok: true;
|
|
9
11
|
readonly arguments: SemanticOperationArguments;
|
|
10
12
|
} | {
|
|
11
13
|
readonly ok: false;
|
|
12
|
-
readonly issues: readonly
|
|
14
|
+
readonly issues: readonly AvValidationIssue[];
|
|
13
15
|
};
|
|
14
16
|
export type ScalarValueNormalizationResult = {
|
|
15
17
|
readonly ok: true;
|
|
16
18
|
readonly value: unknown;
|
|
17
19
|
} | {
|
|
18
20
|
readonly ok: false;
|
|
19
|
-
readonly issues: readonly
|
|
21
|
+
readonly issues: readonly AvValidationIssue[];
|
|
20
22
|
};
|
|
21
23
|
type Path = readonly (string | number)[];
|
|
22
24
|
/**
|
|
23
25
|
* The one discriminant between an argument OBJECT and a VALUE wherever a position
|
|
24
26
|
* admits both — a filter position above all: a **plain** record is an operator object,
|
|
25
|
-
* and anything else — a `Date`, a core `
|
|
27
|
+
* and anything else — a `Date`, a core `AvDecimal`, a `Uint8Array` — is a value, which
|
|
26
28
|
* equality shorthand then holds to the field's scalar. The validator (`operation-
|
|
27
29
|
* validator-core.ts`) reads a filter position through this same answer, and an
|
|
28
30
|
* adapter's filter translation is expected to, so a position cannot be operators to
|
|
29
31
|
* one reader and a value to another.
|
|
30
32
|
*/
|
|
31
33
|
export declare function isPlainRecord(value: unknown): value is Readonly<Record<string, unknown>>;
|
|
34
|
+
/**
|
|
35
|
+
* An operation argument's JSON value is bounded by `maxJsonDepth`, which the
|
|
36
|
+
* structural walk enforces before this runs; a `$sql` step's parameter is not
|
|
37
|
+
* bounded by it. The traversal therefore carries its own stack on the heap: a
|
|
38
|
+
* payload deep enough to exhaust the call stack must still normalize rather
|
|
39
|
+
* than become an internal failure.
|
|
40
|
+
*
|
|
41
|
+
* `seen` holds the ancestors of the value being visited, so a repeated
|
|
42
|
+
* sibling reference is legal and only a genuine cycle is rejected.
|
|
43
|
+
*
|
|
44
|
+
* Every node it emits is typed {@link AvJsonValue}, so the public type and what
|
|
45
|
+
* this traversal produces are one fact: a branch that emitted anything else
|
|
46
|
+
* would not compile.
|
|
47
|
+
*/
|
|
48
|
+
export declare function normalizeJsonValue(value: unknown, path: Path, seen: Set<object>): ScalarValueNormalizationResult;
|
|
32
49
|
/**
|
|
33
50
|
* Normalizes one field value to Aventara's provider-neutral runtime form.
|
|
34
51
|
* `runtime` is used for framework-produced values regardless of request origin.
|
|
35
52
|
*/
|
|
36
|
-
export declare function normalizeScalarFieldValue(contract:
|
|
53
|
+
export declare function normalizeScalarFieldValue(contract: AvContract, field: AvScalarField<AvContract>, value: unknown, origin: AvRequestOrigin | "runtime", path: Path): ScalarValueNormalizationResult;
|
|
54
|
+
/**
|
|
55
|
+
* Every way a normalized value written to `field` does not conform to the field's
|
|
56
|
+
* Json Shape, each at its full path; none for an unshaped field or a `null`.
|
|
57
|
+
* `position` says whether `value` is the field's whole value or one entry of a
|
|
58
|
+
* list field (a `$push` operand).
|
|
59
|
+
*
|
|
60
|
+
* @throws Error when the field carries a shape no checker is bound to — a Contract
|
|
61
|
+
* the Framework did not compile.
|
|
62
|
+
*/
|
|
63
|
+
export declare function jsonShapeIssues(field: AvScalarField<AvContract>, value: unknown, path: Path, position?: "value" | "entry"): readonly AvValidationIssue[];
|
|
37
64
|
/**
|
|
38
65
|
* Copies one validated runtime value of a scalar field into a value the framework
|
|
39
66
|
* owns, per scalar codec: `datetime` → a new `Date`, `bytes` → a sliced `Uint8Array`,
|
|
40
67
|
* `json` → a structured deep copy, and a list → a new array of copied items. `decimal`
|
|
41
68
|
* keeps its identity, and strings, numbers, booleans, bigints, enum members and `null`
|
|
42
69
|
* are immutable and returned unchanged. {@link SCALAR_ATOM_COPIERS} is exhaustive over
|
|
43
|
-
* {@link
|
|
70
|
+
* {@link AvBuiltInScalar}, so a new codec cannot reach this function without declaring
|
|
44
71
|
* its copy.
|
|
45
72
|
*/
|
|
46
|
-
export declare function copyScalarFieldValue(field:
|
|
73
|
+
export declare function copyScalarFieldValue(field: AvScalarField<AvContract>, value: unknown): unknown;
|
|
74
|
+
/**
|
|
75
|
+
* The operators of a step's own filter whose operand is a reference position, and
|
|
76
|
+
* the shape each holds — the one table the normalization below and the reference
|
|
77
|
+
* collector (`transaction-reference-collector.ts`) both read. `not` also takes a
|
|
78
|
+
* nested operator object. Not here, so never a reference: `mode`, `isEmpty`, `path`
|
|
79
|
+
* and a `json` field's `string*`/`array*` operators, which take no field value.
|
|
80
|
+
*/
|
|
81
|
+
export declare const REFERENCE_OPERANDS: Readonly<Partial<Record<AvScalarFilterOperator, TransactionSlotShape>>>;
|
|
82
|
+
/** The shape of `operator`'s operand when it is a reference position. */
|
|
83
|
+
export declare function referenceOperandShape(operator: string): TransactionSlotShape | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Where a normalization writes: `"copy"` leaves the arguments it reads untouched,
|
|
86
|
+
* `"in-place"` writes into them — only for arguments the framework owns and reads
|
|
87
|
+
* nowhere else afterwards: a door's copy, or a body the protocol decoder parsed.
|
|
88
|
+
*/
|
|
89
|
+
export type NormalizationWrite = "copy" | "in-place";
|
|
47
90
|
/**
|
|
48
91
|
* Normalizes every scalar leaf in one structurally valid standard operation.
|
|
49
92
|
* Client wire values are decoded; application values are validated in runtime form.
|
|
50
93
|
*/
|
|
51
|
-
export declare function normalizeOperationScalarValues(contract:
|
|
94
|
+
export declare function normalizeOperationScalarValues(contract: AvContract, request: AvOperationIdentity & {
|
|
52
95
|
readonly resource: string;
|
|
53
96
|
readonly arguments: SemanticOperationArguments;
|
|
54
|
-
},
|
|
97
|
+
}, origin: AvRequestOrigin, options?: OperationValidationOptions, write?: NormalizationWrite): ScalarNormalizationResult;
|
|
55
98
|
export {};
|