@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { VALIDATION_CODE_MESSAGES, VALIDATION_CODES, } from "../operations/validation-code.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AvError } from "./framework-error.js";
|
|
3
3
|
import { INTERNAL_FAILURE_MESSAGE, internalFailure, OPERATION_CODES, operationFailure, } from "./operation-response.js";
|
|
4
4
|
import { PIPE_OUTPUT_FAILURE_MESSAGE } from "./pipe-output.validator.js";
|
|
5
5
|
export const ADAPTER_FAILURE_MESSAGE = "Adapter execution failed.";
|
|
@@ -79,8 +79,11 @@ function projectPath(value) {
|
|
|
79
79
|
export const OPERATION_ARGUMENTS_PATH = [
|
|
80
80
|
"arguments",
|
|
81
81
|
];
|
|
82
|
+
export function planStepPath(index) {
|
|
83
|
+
return ["operations", index];
|
|
84
|
+
}
|
|
82
85
|
export function planOperationArgumentsPath(index) {
|
|
83
|
-
return [
|
|
86
|
+
return [...planStepPath(index), "args"];
|
|
84
87
|
}
|
|
85
88
|
const UNRESOLVED = Symbol("unresolved-path-segment");
|
|
86
89
|
function readOwnMember(container, key) {
|
|
@@ -100,38 +103,43 @@ function readSegment(container, segment) {
|
|
|
100
103
|
}
|
|
101
104
|
return readOwnMember(container, segment);
|
|
102
105
|
}
|
|
103
|
-
function
|
|
106
|
+
function vouchPath(path, view) {
|
|
104
107
|
try {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for (let index = 0; index < view.path.length; index += 1) {
|
|
109
|
-
if (path[index] !== view.path[index]) {
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
108
|
+
const root = [view.path, OPERATION_ARGUMENTS_PATH].find((prefix) => startsWith(path, prefix));
|
|
109
|
+
if (root === undefined) {
|
|
110
|
+
return undefined;
|
|
112
111
|
}
|
|
113
112
|
let current = view.arguments;
|
|
114
|
-
for (let index =
|
|
113
|
+
for (let index = root.length; index < path.length; index += 1) {
|
|
115
114
|
const segment = path[index];
|
|
116
115
|
if (segment === undefined) {
|
|
117
|
-
return
|
|
116
|
+
return undefined;
|
|
118
117
|
}
|
|
119
118
|
current = readSegment(current, segment);
|
|
120
119
|
if (current === UNRESOLVED) {
|
|
121
|
-
return
|
|
120
|
+
return undefined;
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
|
-
return
|
|
123
|
+
return [...view.path, ...path.slice(root.length)];
|
|
125
124
|
}
|
|
126
125
|
catch {
|
|
127
|
-
return
|
|
126
|
+
return undefined;
|
|
128
127
|
}
|
|
129
128
|
}
|
|
129
|
+
function startsWith(path, prefix) {
|
|
130
|
+
return (path.length >= prefix.length &&
|
|
131
|
+
prefix.every((segment, index) => path[index] === segment));
|
|
132
|
+
}
|
|
130
133
|
function isValidationCode(value) {
|
|
131
134
|
return (typeof value === "string" &&
|
|
132
135
|
VALIDATION_CODES.includes(value));
|
|
133
136
|
}
|
|
134
|
-
|
|
137
|
+
export const MAX_DEVELOPER_ISSUE_MESSAGE_LENGTH = 1_000;
|
|
138
|
+
function isDeveloperMessage(message) {
|
|
139
|
+
return (message.length <= MAX_DEVELOPER_ISSUE_MESSAGE_LENGTH &&
|
|
140
|
+
message.trim().length > 0);
|
|
141
|
+
}
|
|
142
|
+
function projectIssue(value, unvouched, view, author) {
|
|
135
143
|
if (typeof value !== "object" || value === null) {
|
|
136
144
|
return undefined;
|
|
137
145
|
}
|
|
@@ -142,23 +150,32 @@ function projectIssue(value, unvouched, view) {
|
|
|
142
150
|
}
|
|
143
151
|
return undefined;
|
|
144
152
|
}
|
|
145
|
-
const
|
|
153
|
+
const supplied = readProperty(value, "message");
|
|
146
154
|
const rawPath = readProperty(value, "path");
|
|
147
|
-
if (typeof
|
|
155
|
+
if (typeof supplied !== "string") {
|
|
148
156
|
return undefined;
|
|
149
157
|
}
|
|
150
|
-
|
|
158
|
+
let message = VALIDATION_CODE_MESSAGES[code];
|
|
159
|
+
if (author === "developer") {
|
|
160
|
+
if (isDeveloperMessage(supplied)) {
|
|
161
|
+
message = supplied;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
unvouched.push(supplied);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
151
167
|
if (rawPath === undefined) {
|
|
152
|
-
return { code, message
|
|
168
|
+
return { code, message };
|
|
153
169
|
}
|
|
154
|
-
const
|
|
155
|
-
|
|
170
|
+
const projected = projectPath(rawPath);
|
|
171
|
+
const path = projected === undefined ? undefined : vouchPath(projected, view);
|
|
172
|
+
if (path === undefined) {
|
|
156
173
|
unvouched.push(rawPath);
|
|
157
|
-
return { code, message
|
|
174
|
+
return { code, message };
|
|
158
175
|
}
|
|
159
|
-
return { path, code, message
|
|
176
|
+
return { path, code, message };
|
|
160
177
|
}
|
|
161
|
-
function projectCause(value, unvouched, view) {
|
|
178
|
+
function projectCause(value, unvouched, view, author) {
|
|
162
179
|
const message = readProperty(value, "message");
|
|
163
180
|
if (typeof message !== "string") {
|
|
164
181
|
return undefined;
|
|
@@ -166,7 +183,7 @@ function projectCause(value, unvouched, view) {
|
|
|
166
183
|
const rawIssues = readList(readProperty(value, "issues"));
|
|
167
184
|
const rawOperation = readProperty(value, "operation");
|
|
168
185
|
const issues = rawIssues
|
|
169
|
-
?.map((issue) => projectIssue(issue, unvouched, view))
|
|
186
|
+
?.map((issue) => projectIssue(issue, unvouched, view, author))
|
|
170
187
|
.filter((issue) => issue !== undefined);
|
|
171
188
|
return {
|
|
172
189
|
message,
|
|
@@ -190,7 +207,7 @@ function readProperty(value, key) {
|
|
|
190
207
|
}
|
|
191
208
|
function isFrameworkErrorInstance(error) {
|
|
192
209
|
try {
|
|
193
|
-
return error instanceof
|
|
210
|
+
return error instanceof AvError;
|
|
194
211
|
}
|
|
195
212
|
catch {
|
|
196
213
|
return false;
|
|
@@ -206,7 +223,7 @@ function isOperationErrorCode(value) {
|
|
|
206
223
|
OPERATION_CODES.includes(value) &&
|
|
207
224
|
!value.startsWith("A1"));
|
|
208
225
|
}
|
|
209
|
-
function vetDeliberateOutcome(error, view) {
|
|
226
|
+
function vetDeliberateOutcome(error, view, author) {
|
|
210
227
|
if (!isFrameworkErrorInstance(error)) {
|
|
211
228
|
return undefined;
|
|
212
229
|
}
|
|
@@ -218,7 +235,7 @@ function vetDeliberateOutcome(error, view) {
|
|
|
218
235
|
return MALFORMED_OUTCOME;
|
|
219
236
|
}
|
|
220
237
|
const unvouched = [];
|
|
221
|
-
const cause = projectCause(rawCause, unvouched, view);
|
|
238
|
+
const cause = projectCause(rawCause, unvouched, view, author);
|
|
222
239
|
return cause === undefined ? MALFORMED_OUTCOME : { code, cause, unvouched };
|
|
223
240
|
}
|
|
224
241
|
function reportUnvouched(outcome, report) {
|
|
@@ -226,13 +243,20 @@ function reportUnvouched(outcome, report) {
|
|
|
226
243
|
report(value, outcome.code);
|
|
227
244
|
}
|
|
228
245
|
}
|
|
246
|
+
function reportDeliberate(thrown, outcome, report) {
|
|
247
|
+
if (isInternalCode(outcome.code)) {
|
|
248
|
+
report(thrown, outcome.code, { deliberate: true });
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
reportUnvouched(outcome, report);
|
|
252
|
+
}
|
|
229
253
|
function deliberateFailure(outcome) {
|
|
230
254
|
return operationFailure(outcome.code, isInternalCode(outcome.code)
|
|
231
255
|
? internalCause(outcome.code, outcome.cause)
|
|
232
256
|
: outcome.cause);
|
|
233
257
|
}
|
|
234
258
|
export function sanitizeOperationFailure(error, origin, report, view) {
|
|
235
|
-
const outcome = vetDeliberateOutcome(error, view);
|
|
259
|
+
const outcome = vetDeliberateOutcome(error, view, origin === "adapter" ? "adapter" : "developer");
|
|
236
260
|
if (outcome === undefined) {
|
|
237
261
|
report(error, unexpectedCode(origin));
|
|
238
262
|
return unexpectedFailure(origin);
|
|
@@ -240,29 +264,61 @@ export function sanitizeOperationFailure(error, origin, report, view) {
|
|
|
240
264
|
if (outcome === MALFORMED_OUTCOME) {
|
|
241
265
|
report(error, "A3000");
|
|
242
266
|
}
|
|
243
|
-
|
|
267
|
+
else {
|
|
268
|
+
reportDeliberate(error, outcome, report);
|
|
269
|
+
}
|
|
244
270
|
return deliberateFailure(outcome);
|
|
245
271
|
}
|
|
246
|
-
export async function resolveOperationFailure(error, filters, context, boundary, report, view) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
272
|
+
export async function resolveOperationFailure(error, filters, context, boundary, report, view, outer) {
|
|
273
|
+
const failure = { error, view, boundary, report };
|
|
274
|
+
const handled = await filterChain(filters, context).attempt(error, view, boundary);
|
|
275
|
+
if (handled !== undefined) {
|
|
276
|
+
return answerHandled(failure, handled);
|
|
277
|
+
}
|
|
278
|
+
return outer === undefined
|
|
279
|
+
? sanitizeUnhandled(failure)
|
|
280
|
+
: outer.defer(failure);
|
|
281
|
+
}
|
|
282
|
+
function answerHandled(failure, handled) {
|
|
283
|
+
if (handled.outcome === MALFORMED_OUTCOME) {
|
|
284
|
+
failure.report(failure.error, "A3000");
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
reportDeliberate(handled.returned, handled.outcome, failure.report);
|
|
260
288
|
}
|
|
261
|
-
return
|
|
289
|
+
return deliberateFailure(handled.outcome);
|
|
290
|
+
}
|
|
291
|
+
function sanitizeUnhandled(failure) {
|
|
292
|
+
return sanitizeOperationFailure(failure.error, failure.boundary.originOf(failure.error), failure.report, failure.view);
|
|
293
|
+
}
|
|
294
|
+
export async function resolveUnhandledFailure(failure, chain) {
|
|
295
|
+
const handled = await chain.attempt(failure.error, failure.view, failure.boundary);
|
|
296
|
+
return handled === undefined
|
|
297
|
+
? sanitizeUnhandled(failure)
|
|
298
|
+
: answerHandled(failure, handled);
|
|
299
|
+
}
|
|
300
|
+
export function filterChain(filters, context) {
|
|
301
|
+
return {
|
|
302
|
+
attempt: async (error, view, boundary) => {
|
|
303
|
+
for (let index = filters.length - 1; index >= 0; index -= 1) {
|
|
304
|
+
const filter = filters[index];
|
|
305
|
+
if (filter === undefined) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const handled = await attemptFilter(filter, error, context, view, boundary);
|
|
309
|
+
if (handled !== undefined) {
|
|
310
|
+
return handled;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return undefined;
|
|
314
|
+
},
|
|
315
|
+
};
|
|
262
316
|
}
|
|
263
|
-
async function attemptFilter(filter, error, context, view) {
|
|
317
|
+
async function attemptFilter(filter, error, context, view, boundary) {
|
|
264
318
|
try {
|
|
265
|
-
|
|
319
|
+
const returned = await filter(error, context);
|
|
320
|
+
const outcome = vetDeliberateOutcome(returned, view, boundary.originOf(returned) === "adapter" ? "adapter" : "developer");
|
|
321
|
+
return outcome === undefined ? undefined : { returned, outcome };
|
|
266
322
|
}
|
|
267
323
|
catch {
|
|
268
324
|
return undefined;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import type { AvState } from "./request-state.js";
|
|
1
2
|
/**
|
|
2
3
|
* Options for one in-process call: the optional second argument of every
|
|
3
4
|
* `framework.application.*` / `framework.client.*` call and of
|
|
4
5
|
* `framework.transaction`.
|
|
5
6
|
*/
|
|
6
|
-
export type
|
|
7
|
+
export type AvExecutionOptions = {
|
|
7
8
|
/**
|
|
8
9
|
* The id every pipeline context and every diagnostic of this call or run
|
|
9
|
-
* carries
|
|
10
|
+
* carries, such as a correlation id the caller already holds. Omitted, the Framework
|
|
10
11
|
* mints one; the empty string counts as omitted.
|
|
11
12
|
*/
|
|
12
13
|
readonly requestId?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The call's or run's `ctx.$state`: the one object every stage of it, and
|
|
16
|
+
* every ctx call those stages make, reads and writes. It is used as it is, not
|
|
17
|
+
* copied, so the caller sees what the stages wrote. Omitted (or not an
|
|
18
|
+
* object), the Framework starts the request with `{}`.
|
|
19
|
+
*/
|
|
20
|
+
readonly state?: AvState & object;
|
|
13
21
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AvFieldCheck } from "../contracts/field-check.js";
|
|
2
|
+
import type { AvValidationIssue } from "../operations/validation-code.js";
|
|
3
|
+
/** What a check judges: the runtime form of the value it is given. */
|
|
4
|
+
export type FieldCheckSubject = "string" | "number" | "bigint" | "decimal" | "datetime" | "bytes";
|
|
5
|
+
/**
|
|
6
|
+
* What a check judges on a field of each scalar type that takes checks; a field
|
|
7
|
+
* of any other type (an enum's) holds a string.
|
|
8
|
+
*/
|
|
9
|
+
export declare const FIELD_CHECK_SUBJECTS: Readonly<Record<string, FieldCheckSubject>>;
|
|
10
|
+
type Path = readonly (string | number)[];
|
|
11
|
+
/**
|
|
12
|
+
* Whether `value` passes `check`; `true` for a value the check does not judge
|
|
13
|
+
* (a value of another form, which validation refused before the checks run).
|
|
14
|
+
*/
|
|
15
|
+
export declare function passesFieldCheck(check: AvFieldCheck, value: unknown, subject: FieldCheckSubject): boolean;
|
|
16
|
+
/** The issue of one failed check at `path`: its V-code, zod's check and its parameters. */
|
|
17
|
+
export declare function fieldCheckIssue(check: AvFieldCheck, subject: FieldCheckSubject, path: Path): AvValidationIssue;
|
|
18
|
+
/**
|
|
19
|
+
* The issues of the checks `value` breaks, one per broken check, in the checks'
|
|
20
|
+
* order. On a list (`list`), a `list: true` length check judges the list at
|
|
21
|
+
* `path` and every other check judges each entry, at its index; `null` is no
|
|
22
|
+
* value and breaks nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function fieldCheckIssues(checks: readonly AvFieldCheck[], value: unknown, subject: FieldCheckSubject, path: Path, list: boolean): readonly AvValidationIssue[];
|
|
25
|
+
/** The issues of the checks one value — a whole value, or a list's entry — breaks. */
|
|
26
|
+
export declare function entryCheckIssues(checks: readonly AvFieldCheck[], value: unknown, subject: FieldCheckSubject, path: Path): readonly AvValidationIssue[];
|
|
27
|
+
/** Whether a check judges a list's own length (`AvZ.minItems`/`AvZ.maxItems`). */
|
|
28
|
+
export declare function isListCheck(check: AvFieldCheck): boolean;
|
|
29
|
+
export {};
|