@aventara/core 1.0.0-rc.1 → 1.0.0-rc.3
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 +341 -1
- package/ERRORS.md +142 -0
- package/README.md +24 -1
- package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
- package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
- package/dist/adapters/adapter-field.d.ts +14 -0
- package/dist/adapters/adapter-model.d.ts +9 -0
- package/dist/adapters/adapter.interface.d.ts +10 -0
- package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
- package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
- package/dist/compiler/contract.compiler.js +94 -6
- package/dist/config/computed-fields.d.ts +62 -0
- package/dist/config/computed-fields.js +80 -0
- package/dist/config/config-diagnostic.guidance.d.ts +6 -0
- package/dist/config/config-diagnostic.guidance.js +32 -0
- package/dist/config/define-resource.d.ts +1 -1
- package/dist/config/exact-framework-config.d.ts +50 -20
- package/dist/config/field-compute.resolver.d.ts +2 -0
- package/dist/config/field-compute.resolver.js +8 -0
- package/dist/config/framework-config.d.ts +7 -6
- package/dist/config/framework-resources-config.d.ts +18 -12
- package/dist/config/pipeline-config.d.ts +4 -4
- package/dist/contracts/capability.d.ts +10 -1
- package/dist/contracts/capability.js +2 -0
- package/dist/contracts/client-contract-structure.validator.d.ts +65 -35
- package/dist/contracts/client-contract-structure.validator.js +4 -2
- package/dist/contracts/contract-canonicalizer.d.ts +7 -0
- package/dist/contracts/contract-canonicalizer.js +18 -4
- package/dist/contracts/field.d.ts +30 -1
- package/dist/framework/contract-view.d.ts +4 -4
- package/dist/framework/framework-construction.error.d.ts +12 -3
- package/dist/framework/framework-construction.error.js +5 -1
- package/dist/framework/framework.factory.d.ts +1 -1
- package/dist/framework/framework.factory.js +9 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/internal.d.ts +2 -0
- package/dist/internal.js +1 -0
- package/dist/operations/database-refusal.d.ts +51 -0
- package/dist/operations/database-refusal.js +45 -0
- package/dist/operations/operation-arguments.d.ts +102 -31
- package/dist/operations/operation-validator-core.js +145 -36
- package/dist/operations/validation-code.guidance.d.ts +6 -0
- package/dist/operations/validation-code.guidance.js +90 -0
- package/dist/operations/write-scope.resolver.d.ts +4 -0
- package/dist/operations/write-scope.resolver.js +2 -0
- package/dist/protocol/protocol.handler.js +55 -16
- package/dist/runtime/caller-data.copier.d.ts +17 -0
- package/dist/runtime/caller-data.copier.js +18 -1
- package/dist/runtime/caller-data.door.d.ts +11 -5
- package/dist/runtime/computed-read-runtime.js +15 -2
- package/dist/runtime/computed-value.error.d.ts +3 -2
- package/dist/runtime/computed-value.error.js +3 -2
- package/dist/runtime/create-requirement.d.ts +41 -5
- package/dist/runtime/create-requirement.js +137 -20
- package/dist/runtime/diagnostics-reporter.d.ts +2 -1
- package/dist/runtime/error-boundary.js +4 -0
- package/dist/runtime/error-guidance.d.ts +12 -0
- package/dist/runtime/error-guidance.js +1 -0
- package/dist/runtime/error.catalog.d.ts +49 -0
- package/dist/runtime/error.catalog.js +49 -0
- package/dist/runtime/field-stage.runtime.d.ts +2 -0
- package/dist/runtime/field-stage.runtime.js +8 -4
- package/dist/runtime/field-validator.runtime.d.ts +18 -1
- package/dist/runtime/field-validator.runtime.js +47 -8
- package/dist/runtime/json-value.d.ts +10 -5
- package/dist/runtime/level-lifecycle.runtime.d.ts +2 -2
- package/dist/runtime/level-lifecycle.runtime.js +2 -5
- package/dist/runtime/mutation-planner.js +3 -14
- package/dist/runtime/operation-code.guidance.d.ts +6 -0
- package/dist/runtime/operation-code.guidance.js +167 -0
- package/dist/runtime/operation-runtime.d.ts +20 -6
- package/dist/runtime/operation-runtime.js +82 -36
- package/dist/runtime/owned-execution.registry.d.ts +12 -2
- package/dist/runtime/pipe-output.validator.d.ts +10 -0
- package/dist/runtime/pipe-output.validator.js +4 -2
- package/dist/runtime/pipeline.d.ts +35 -8
- package/dist/runtime/readonly-value.d.ts +14 -3
- package/dist/runtime/readonly-value.js +10 -1
- package/dist/runtime/scalar-runtime.d.ts +5 -1
- package/dist/runtime/scalar-runtime.js +86 -16
- package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
- package/dist/runtime/unsent-value.normalizer.js +128 -0
- package/dist/transactions/operation-fingerprint.js +2 -2
- package/dist/transactions/sql-statement.d.ts +8 -0
- package/dist/transactions/sql-statement.validator.js +36 -3
- package/dist/transactions/transaction-plan-assembler.d.ts +1 -1
- package/dist/transactions/transaction-plan-assembler.js +33 -10
- package/dist/transactions/transaction-plan-validator.d.ts +16 -0
- package/dist/transactions/transaction-plan-validator.js +27 -1
- package/dist/transactions/transaction-reference-validator.d.ts +42 -0
- package/dist/transactions/transaction-reference-validator.js +82 -56
- package/dist/transactions/transaction-reference.js +5 -0
- package/dist/transactions/transaction-runtime.js +47 -22
- package/dist/transactions/transaction-stage.runtime.d.ts +2 -1
- package/dist/transactions/transaction-stage.runtime.js +7 -4
- package/package.json +4 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { validatedFieldsOf, } from "../compiler/field-validator.compiler.js";
|
|
1
|
+
import { hasFieldValidators, validatedFieldsOf, } from "../compiler/field-validator.compiler.js";
|
|
2
|
+
import { AvComputedValueError } from "./computed-value.error.js";
|
|
2
3
|
import { entryCheckIssues, fieldCheckIssues } from "./field-check.evaluator.js";
|
|
3
4
|
import { isPlainRecord, valueAt, writeRecordPathsOf, } from "./field-stage.runtime.js";
|
|
4
5
|
import { nestedWriteTargetsOf } from "./nested-write.walker.js";
|
|
@@ -14,7 +15,10 @@ function rulesOf(contract, compiled, resource, name) {
|
|
|
14
15
|
const field = fields !== undefined && Object.hasOwn(fields, name)
|
|
15
16
|
? fields[name]
|
|
16
17
|
: undefined;
|
|
17
|
-
if (field
|
|
18
|
+
if (field === undefined) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (field.kind === "scalar" && field.json !== undefined) {
|
|
18
22
|
return { kind: "shape", field };
|
|
19
23
|
}
|
|
20
24
|
const checks = Object.hasOwn(compiled, name) ? compiled[name] : undefined;
|
|
@@ -36,17 +40,17 @@ function entryIssues(rules, entry, at) {
|
|
|
36
40
|
const { compiled } = rules;
|
|
37
41
|
return entryCheckIssues(compiled.checks, entry, compiled.subject ?? "string", at);
|
|
38
42
|
}
|
|
39
|
-
function recordIssues(contract, resource, records, args, argumentsPath, select) {
|
|
43
|
+
function recordIssues(contract, resource, records, args, argumentsPath, select, deferred) {
|
|
40
44
|
const compiled = validatedFieldsOf(contract, resource);
|
|
41
45
|
const issues = [];
|
|
42
|
-
for (const path of records) {
|
|
46
|
+
for (const { path, stage } of records) {
|
|
43
47
|
const record = valueAt(args, path);
|
|
44
48
|
if (!isPlainRecord(record)) {
|
|
45
49
|
continue;
|
|
46
50
|
}
|
|
47
51
|
for (const name of Object.keys(record)) {
|
|
48
52
|
const rules = rulesOf(contract, compiled, resource, name);
|
|
49
|
-
if (rules === undefined) {
|
|
53
|
+
if (rules === undefined || deferred?.(resource, stage, name) === true) {
|
|
50
54
|
continue;
|
|
51
55
|
}
|
|
52
56
|
const fieldPath = [...path, name];
|
|
@@ -78,10 +82,45 @@ function recordIssues(contract, resource, records, args, argumentsPath, select)
|
|
|
78
82
|
}
|
|
79
83
|
return issues;
|
|
80
84
|
}
|
|
81
|
-
export function fieldValidatorIssues(contract, references, request, args, argumentsPath, select) {
|
|
82
|
-
const issues = recordIssues(contract, request.resource, writeRecordPathsOf(request.family, args)
|
|
85
|
+
export function fieldValidatorIssues(contract, references, request, args, argumentsPath, select, deferred) {
|
|
86
|
+
const issues = recordIssues(contract, request.resource, writeRecordPathsOf(request.family, args).map((path) => ({
|
|
87
|
+
path,
|
|
88
|
+
stage: request.family === "create" || path[0] === "create"
|
|
89
|
+
? "create"
|
|
90
|
+
: "update",
|
|
91
|
+
})), args, argumentsPath, select, deferred);
|
|
83
92
|
for (const target of nestedWriteTargetsOf(contract, references, request, args)) {
|
|
84
|
-
issues.push(...recordIssues(contract, target.resource, target.records
|
|
93
|
+
issues.push(...recordIssues(contract, target.resource, target.records, args, argumentsPath, select, deferred));
|
|
85
94
|
}
|
|
86
95
|
return issues;
|
|
87
96
|
}
|
|
97
|
+
function holdsField(contract, resource, field) {
|
|
98
|
+
const fields = Object.hasOwn(contract.resources, resource)
|
|
99
|
+
? contract.resources[resource]?.fields
|
|
100
|
+
: undefined;
|
|
101
|
+
return fields !== undefined && Object.hasOwn(fields, field);
|
|
102
|
+
}
|
|
103
|
+
export function hiddenFieldRefusal(contracts, references, request, args, argumentsPath) {
|
|
104
|
+
const { core, active } = contracts;
|
|
105
|
+
if (core === active || !hasFieldValidators(core)) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
const judged = [];
|
|
109
|
+
const issues = fieldValidatorIssues(core, references, request, args, argumentsPath, () => true, (resource, stage, field) => {
|
|
110
|
+
if (holdsField(active, resource, field)) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
judged.push({ resource, stage, field });
|
|
114
|
+
return false;
|
|
115
|
+
});
|
|
116
|
+
const [first] = issues;
|
|
117
|
+
if (first === undefined) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const path = first.path ?? [];
|
|
121
|
+
const at = judged.find(({ field }) => path.includes(field)) ?? judged[0];
|
|
122
|
+
if (at === undefined) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
return new AvComputedValueError(at.resource, at.field, at.stage, issues, `compute.${at.stage} on ${at.resource}.${at.field}, a field the ${request.origin} layer hides, returned a value its validators refuse (${first.code}: ${first.message})`);
|
|
126
|
+
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A JSON value: the form of the `json` scalar, in arguments and results.
|
|
3
3
|
*
|
|
4
|
-
* A `Date`, a `bigint`, a `Uint8Array`, a {@link AvDecimal}
|
|
5
|
-
* instance
|
|
6
|
-
*
|
|
4
|
+
* A `Date`, a `bigint`, a `Uint8Array`, a {@link AvDecimal} and any other class
|
|
5
|
+
* instance are refused (`V1001`), as are a non-finite `number` (`V1004`) and a
|
|
6
|
+
* cycle (`V1001`). An `undefined` inside the value is what JSON makes of it: a key
|
|
7
|
+
* holding it is left out, an array element holding it (or a hole) is `null`. The
|
|
8
|
+
* type admits a key holding `undefined`, so an object with an optional property is
|
|
9
|
+
* a JSON value; an array element stays typed without it, as JSON has no such
|
|
10
|
+
* value.
|
|
7
11
|
*
|
|
8
|
-
* Results are fresh plain copies, so mutating one is safe
|
|
12
|
+
* Results are fresh plain copies, so mutating one is safe; a result never holds a
|
|
13
|
+
* key whose value is `undefined`.
|
|
9
14
|
*
|
|
10
15
|
* A `json` field's value is this without its top-level `null`: a field-level
|
|
11
16
|
* `null` is the field's absence, which only `nullable: true` admits.
|
|
12
17
|
*/
|
|
13
18
|
export type AvJsonValue = string | number | boolean | null | readonly AvJsonValue[] | {
|
|
14
|
-
readonly [key: string]: AvJsonValue;
|
|
19
|
+
readonly [key: string]: AvJsonValue | undefined;
|
|
15
20
|
};
|
|
@@ -17,8 +17,8 @@ export type NextReuse<Refusal extends Error = Error> = {
|
|
|
17
17
|
* Runs `levels`' lifecycle around `inner`: every interceptor, outer to inner,
|
|
18
18
|
* around every before hook, `inner`, and every after hook. `settle` turns what
|
|
19
19
|
* `inner` or an interceptor below resolved into what the stage above sees (the
|
|
20
|
-
* operation read-materializes it).
|
|
21
|
-
* the result; the result itself goes on to the interceptors, which may answer a
|
|
20
|
+
* operation read-materializes it). Each after hook is told its own deep-frozen
|
|
21
|
+
* copy of the result; the result itself goes on to the interceptors, which may answer a
|
|
22
22
|
* different one. Every `next()` is single use: a second call rejects with
|
|
23
23
|
* `refuse()`'s error, recorded in `reuse`, and runs nothing.
|
|
24
24
|
*/
|
|
@@ -20,11 +20,8 @@ export async function runLevelLifecycle(levels, context, inner, settle, reuse, r
|
|
|
20
20
|
}
|
|
21
21
|
const result = await settle(await inner());
|
|
22
22
|
const after = [...levels].reverse().flatMap((level) => level.hooks.after);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (const hook of after) {
|
|
26
|
-
await hook(told, context());
|
|
27
|
-
}
|
|
23
|
+
for (const hook of after) {
|
|
24
|
+
await hook(frozenCopy(result), context());
|
|
28
25
|
}
|
|
29
26
|
return result;
|
|
30
27
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { lookupField, lookupResource } from "../contracts/contract-lookup.js";
|
|
2
2
|
import { AvComputedValueError } from "./computed-value.error.js";
|
|
3
3
|
import { replaceAt, valueAt } from "./field-stage.runtime.js";
|
|
4
|
-
import {
|
|
4
|
+
import { frozenCopy } from "./readonly-value.js";
|
|
5
|
+
import { normalizeScalarFieldValue } from "./scalar-runtime.js";
|
|
5
6
|
function writeScalarField(contracts, resourceName, fieldName) {
|
|
6
7
|
const field = lookupField(lookupResource(contracts.core, resourceName), fieldName) ??
|
|
7
8
|
lookupField(lookupResource(contracts.active, resourceName), fieldName);
|
|
@@ -57,7 +58,7 @@ async function computeRecord(contracts, compute, resourceName, stage, data, cont
|
|
|
57
58
|
if (field === undefined) {
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
|
-
const snapshot =
|
|
61
|
+
const snapshot = frozenCopy(logicalData);
|
|
61
62
|
const computed = await callback({
|
|
62
63
|
field: fieldName,
|
|
63
64
|
value: snapshot[fieldName],
|
|
@@ -79,18 +80,6 @@ async function computeRecord(contracts, compute, resourceName, stage, data, cont
|
|
|
79
80
|
if (!validation.ok) {
|
|
80
81
|
throw new AvComputedValueError(resourceName, fieldName, stage, validation.issues);
|
|
81
82
|
}
|
|
82
|
-
const shapeIssues = jsonShapeIssues(field, validation.value, [
|
|
83
|
-
"resources",
|
|
84
|
-
resourceName,
|
|
85
|
-
"fields",
|
|
86
|
-
fieldName,
|
|
87
|
-
"pipelines",
|
|
88
|
-
"compute",
|
|
89
|
-
stage,
|
|
90
|
-
]);
|
|
91
|
-
if (shapeIssues.length > 0) {
|
|
92
|
-
throw new AvComputedValueError(resourceName, fieldName, stage, shapeIssues);
|
|
93
|
-
}
|
|
94
83
|
logicalData[fieldName] = validation.value;
|
|
95
84
|
}
|
|
96
85
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ErrorCodeDescription } from "./error-guidance.js";
|
|
2
|
+
import type { AvOperationCode } from "./operation-response.js";
|
|
3
|
+
/** Meaning, cause and fix of every outcome code. */
|
|
4
|
+
export declare const OPERATION_CODE_GUIDANCE: {
|
|
5
|
+
readonly [C in AvOperationCode]: ErrorCodeDescription;
|
|
6
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
export const OPERATION_CODE_GUIDANCE = {
|
|
2
|
+
A1000: {
|
|
3
|
+
message: "Success.",
|
|
4
|
+
cause: "A read, a count or another operation without a more specific success code succeeded.",
|
|
5
|
+
fix: "Nothing: the call succeeded.",
|
|
6
|
+
},
|
|
7
|
+
A1001: {
|
|
8
|
+
message: "No match.",
|
|
9
|
+
cause: "A first-style operation (find.first, update.first, delete.first) matched no row; data is null and the generated client resolves null.",
|
|
10
|
+
fix: "Nothing: handle the null result. A unique operation answers A2003 instead.",
|
|
11
|
+
},
|
|
12
|
+
A1002: {
|
|
13
|
+
message: "Created.",
|
|
14
|
+
cause: "create.one created a row.",
|
|
15
|
+
fix: "Nothing: the call succeeded.",
|
|
16
|
+
},
|
|
17
|
+
A1003: {
|
|
18
|
+
message: "Created many.",
|
|
19
|
+
cause: "create.many or create.count created rows.",
|
|
20
|
+
fix: "Nothing: the call succeeded.",
|
|
21
|
+
},
|
|
22
|
+
A1004: {
|
|
23
|
+
message: "Updated.",
|
|
24
|
+
cause: "update.first or update.unique updated a row.",
|
|
25
|
+
fix: "Nothing: the call succeeded.",
|
|
26
|
+
},
|
|
27
|
+
A1005: {
|
|
28
|
+
message: "Updated many.",
|
|
29
|
+
cause: "update.many or update.count updated rows.",
|
|
30
|
+
fix: "Nothing: the call succeeded.",
|
|
31
|
+
},
|
|
32
|
+
A1006: {
|
|
33
|
+
message: "Deleted.",
|
|
34
|
+
cause: "delete.first or delete.unique deleted a row.",
|
|
35
|
+
fix: "Nothing: the call succeeded.",
|
|
36
|
+
},
|
|
37
|
+
A1007: {
|
|
38
|
+
message: "Deleted many.",
|
|
39
|
+
cause: "delete.count deleted rows.",
|
|
40
|
+
fix: "Nothing: the call succeeded.",
|
|
41
|
+
},
|
|
42
|
+
A1008: {
|
|
43
|
+
message: "Upserted.",
|
|
44
|
+
cause: "upsert.unique created or updated a row.",
|
|
45
|
+
fix: "Nothing: the call succeeded.",
|
|
46
|
+
},
|
|
47
|
+
A1009: {
|
|
48
|
+
message: "Transaction committed.",
|
|
49
|
+
cause: "A whole transaction plan committed; data holds one result per step.",
|
|
50
|
+
fix: "Nothing: the plan committed.",
|
|
51
|
+
},
|
|
52
|
+
A2000: {
|
|
53
|
+
message: "Invalid request.",
|
|
54
|
+
cause: "The HTTP request cannot be interpreted: malformed JSON, a body that is not a JSON object, an unknown `/_*` path, a body that does not decode in its Content-Encoding, or a missing Aventara-Protocol-Version or Aventara-Contract-Hash header (the message names it).",
|
|
55
|
+
fix: "Send a JSON object with both identity headers. The generated client does this for you.",
|
|
56
|
+
},
|
|
57
|
+
A2001: {
|
|
58
|
+
message: "Unknown Resource.",
|
|
59
|
+
cause: 'The Resource is not in the caller\'s contract: misspelt, hidden by exposure, or added to the schema after aventara:prepare last ran. cause.message is "The requested Resource is not available." and the issue is V1005 at `["resource"]`.',
|
|
60
|
+
fix: "Use the model's exact name. After a schema change run the adapter's generate step (`npm run aventara:prepare` in a scaffolded project), restart, and regenerate the client. A Resource hidden on purpose is reached from server code (framework.application).",
|
|
61
|
+
},
|
|
62
|
+
A2002: {
|
|
63
|
+
message: "Unknown operation.",
|
|
64
|
+
cause: 'The operation is not available on that Resource: a typo, removed by exposure, an operation the adapter does not offer (such as delete.many), or a ctx.$sql, appTx.$sql or ctx.$transaction the adapter or the layer cannot run. The issue is V1006 at `["family"]` or `["variant"]`.',
|
|
65
|
+
fix: "Call an operation the contract lists (`GET <api>/_contract`), regenerate a stale client, and check the layer's exemptions and transactionsStyle.",
|
|
66
|
+
},
|
|
67
|
+
A2003: {
|
|
68
|
+
message: "Not found.",
|
|
69
|
+
cause: "A unique operation (find.unique, update.unique, delete.unique) matched no row, or a $connect names a record that does not exist. The operation fails, so no after hook runs.",
|
|
70
|
+
fix: "Catch AvNotFoundError, or use a first-style operation, which answers A1001 with null. Check the $connect identifier.",
|
|
71
|
+
},
|
|
72
|
+
A2004: {
|
|
73
|
+
message: "Validation failed.",
|
|
74
|
+
cause: 'The arguments break a contract rule or a field validator. cause.issues lists each problem by V-code and path; a validator\'s issue also has check and params. The validators judge the values after the pipes and write compute, so a computed value they refuse is here too, at its field. A required create field left out is here (V1000). So is a value the database itself refused: too long for its column or its index, or out of its range (V1004), or holding a character it cannot store or a pattern it cannot read (V1001), with the issue at `["arguments"]`, or at the value where the adapter can place it (a bigint its driver cannot bind), and its message saying what the database refused. So is a record written through a relation that writes that relation, or a field holding its reference, back (V1012, at that field), where the adapter admits no such write.',
|
|
75
|
+
fix: "Fix the argument each issue's path points at, as its V-code says. A field the server must fill takes a compute.create stage. For a value the database refused, send one its column holds. For a nested write that writes its relation back, leave that field out: the parent supplies it.",
|
|
76
|
+
},
|
|
77
|
+
A2005: {
|
|
78
|
+
message: "Contract mismatch.",
|
|
79
|
+
cause: "The caller's Aventara-Contract-Hash is not the server's current one: the schema, the configuration, the limits or the exposure changed, or the client targets another deployment.",
|
|
80
|
+
fix: "Regenerate the client against the running server: `npm run avclient:generate`.",
|
|
81
|
+
},
|
|
82
|
+
A2006: {
|
|
83
|
+
message: "Protocol mismatch.",
|
|
84
|
+
cause: "Aventara-Protocol-Version is not 1.",
|
|
85
|
+
fix: "Send `Aventara-Protocol-Version: 1`, or upgrade the client.",
|
|
86
|
+
},
|
|
87
|
+
A2007: {
|
|
88
|
+
message: "Invalid transaction reference.",
|
|
89
|
+
cause: "A transaction $ref or fingerprint is invalid: the issues are V1010, V1011, V1016, V1017 or V1018, and cause.operation is the step. A $ref with no fingerprint is A2004 / V1000.",
|
|
90
|
+
fix: "Let the generated client or framework.appTx build plans; check the $ref path and that the referenced step comes earlier.",
|
|
91
|
+
},
|
|
92
|
+
A2008: {
|
|
93
|
+
message: "Conflict.",
|
|
94
|
+
cause: "A uniqueness or reference constraint failed: a duplicate value, a missing parent, or a $disconnect or $set that would orphan a required child (also through update.first or a developer SQL statement). Sending it again unchanged fails the same way.",
|
|
95
|
+
fix: "Change the data. For a duplicate, update the existing row or use upsert.unique.",
|
|
96
|
+
},
|
|
97
|
+
A2009: {
|
|
98
|
+
message: "Limit exceeded.",
|
|
99
|
+
cause: "A contract limit was crossed: nesting depth (V1013), list or plan size (V1014), boolean nodes (V1015) or Json value depth (V1021).",
|
|
100
|
+
fix: "Ask for less (paginate, split the plan), or raise the limit under `limits`.",
|
|
101
|
+
},
|
|
102
|
+
A2010: {
|
|
103
|
+
message: "Payload too large.",
|
|
104
|
+
cause: "The decoded request body exceeds maxRequestBytes (default 1048576).",
|
|
105
|
+
fix: "Send less, or raise limits.maxRequestBytes.",
|
|
106
|
+
},
|
|
107
|
+
A2011: {
|
|
108
|
+
message: "Unsupported media type.",
|
|
109
|
+
cause: "The body is not application/json, or its Content-Encoding is not gzip, deflate or br.",
|
|
110
|
+
fix: "Send `Content-Type: application/json`.",
|
|
111
|
+
},
|
|
112
|
+
A2012: {
|
|
113
|
+
message: "Method not allowed.",
|
|
114
|
+
cause: "The HTTP method does not fit the route; the Allow header names the right one (`POST` on operations and `/_transactions`, `GET` on `/_contract`).",
|
|
115
|
+
fix: "Use the method the Allow header names.",
|
|
116
|
+
},
|
|
117
|
+
A2013: {
|
|
118
|
+
message: "Concurrent modification.",
|
|
119
|
+
cause: "A competing writer reached the state first; nothing was written.",
|
|
120
|
+
fix: "Retry. No retry is automatic.",
|
|
121
|
+
},
|
|
122
|
+
A2014: {
|
|
123
|
+
message: "Stale selection.",
|
|
124
|
+
cause: "The selected state changed before the write; nothing was written.",
|
|
125
|
+
fix: "Read again, then retry.",
|
|
126
|
+
},
|
|
127
|
+
A3000: {
|
|
128
|
+
message: "Internal error.",
|
|
129
|
+
cause: 'An unexpected failure on the server: a stage threw an error that is not an AvError, an interceptor called next() twice, a compute stage reached a write through its read-only ctx, a compute stage returned a value of the wrong type, or a compute.create returned undefined for a required field. cause.message is always "Internal framework error."',
|
|
130
|
+
fix: "Read the real error in the diagnostics sink (the root `diagnostics` key) or the server log line for the request id, and fix that stage. To answer with a code of your choice, throw an AvError.",
|
|
131
|
+
},
|
|
132
|
+
A3001: {
|
|
133
|
+
message: "Adapter error.",
|
|
134
|
+
cause: 'A database or ORM failure that is not something the caller can fix. cause.message is always "Adapter execution failed."',
|
|
135
|
+
fix: "Read the raw error in the diagnostics sink; check the database, its connection and the migration state.",
|
|
136
|
+
},
|
|
137
|
+
A3002: {
|
|
138
|
+
message: "Transaction error.",
|
|
139
|
+
cause: "Transaction infrastructure failed (commit or rollback, or the transaction expired or was closed under a step), or a Resource transaction interceptor called next() twice or resolved without calling it.",
|
|
140
|
+
fix: "Read the diagnostics sink. Call next() exactly once in a transaction interceptor; retry an infrastructure failure.",
|
|
141
|
+
},
|
|
142
|
+
A3003: {
|
|
143
|
+
message: "Serialization error.",
|
|
144
|
+
cause: "A result could not be encoded for transport.",
|
|
145
|
+
fix: "Read the diagnostics sink; make compute.read stages and Json values return plain data of the field's type.",
|
|
146
|
+
},
|
|
147
|
+
A3004: {
|
|
148
|
+
message: "Pipe output invalid.",
|
|
149
|
+
cause: 'A server pipe, field pipe or transaction pipe (or write compute) returned arguments the server\'s own contract refuses: a field the Resource does not have, a wrong type, a dropped required field, a reference written together with its relation (V1012), or a changed plan. cause.message is always "A server pipeline produced invalid arguments."',
|
|
150
|
+
fix: "Read the server log line, which names the pipe, the operation and the path, and fix the pipe. A pipe returns a new object of the same shape, or undefined to keep the arguments.",
|
|
151
|
+
},
|
|
152
|
+
A4000: {
|
|
153
|
+
message: "Unauthenticated.",
|
|
154
|
+
cause: 'A guard threw new AvError("A4000", ...): authentication is required or failed. The framework never authenticates by itself.',
|
|
155
|
+
fix: "Send the credentials your guards expect, such as the Authorization header.",
|
|
156
|
+
},
|
|
157
|
+
A4001: {
|
|
158
|
+
message: "Forbidden.",
|
|
159
|
+
cause: 'A guard returned false ("Operation denied by a framework guard."), a field write guard or a nested write\'s target guard included, or a stage threw A4001.',
|
|
160
|
+
fix: "Call as a caller the guard admits, or stop sending the guarded field. To answer another code, throw an AvError from the guard.",
|
|
161
|
+
},
|
|
162
|
+
A4002: {
|
|
163
|
+
message: "Policy denied.",
|
|
164
|
+
cause: 'A guard or hook threw new AvError("A4002", ...) with a policy reason of your own.',
|
|
165
|
+
fix: "Read cause.message for the policy's reason.",
|
|
166
|
+
},
|
|
167
|
+
};
|
|
@@ -104,7 +104,13 @@ export type ValidatedOperationArguments = {
|
|
|
104
104
|
};
|
|
105
105
|
/** Validates one operation's arguments through the Framework Validation Layer. */
|
|
106
106
|
export declare function validateOperationRequest(contract: AvContract, request: FrameworkOperationRequest, options?: OperationValidationOptions, write?: NormalizationWrite): ValidatedOperationArguments;
|
|
107
|
-
/**
|
|
107
|
+
/** The subject a refused output of an operation's pipes is reported under at a plan step. */
|
|
108
|
+
export declare const STEP_PIPES = "Pipes";
|
|
109
|
+
/**
|
|
110
|
+
* Every sent field's path. A `$ref` is an object of `$`-keys, which no field
|
|
111
|
+
* pipe or validator takes, so a plan step's literal values before BEGIN are
|
|
112
|
+
* every field too, wherever a pipe left a reference or a literal.
|
|
113
|
+
*/
|
|
108
114
|
export declare const EVERY_FIELD: () => boolean;
|
|
109
115
|
/**
|
|
110
116
|
* What admission leaves: the deep-frozen arguments every later stage reads, and
|
|
@@ -123,16 +129,24 @@ export type AdmittedOperation = {
|
|
|
123
129
|
export type AdmissionScope = {
|
|
124
130
|
/**
|
|
125
131
|
* The sent values the field pipes and validators take: every one for a single
|
|
126
|
-
* call
|
|
127
|
-
* at the step.
|
|
132
|
+
* call and for a plan step before BEGIN (an unresolved `$ref` is an object of
|
|
133
|
+
* `$`-keys, which they never take), its resolved `$ref` values at the step.
|
|
128
134
|
*/
|
|
129
135
|
readonly select: (path: readonly (string | number)[]) => boolean;
|
|
130
136
|
/** Before BEGIN a plan step's `$ref` slots are unresolved: these admit them. */
|
|
131
137
|
readonly validation?: OperationValidationOptions;
|
|
138
|
+
/**
|
|
139
|
+
* A plan step or a forced call, admitted before BEGIN: the validators judge
|
|
140
|
+
* there the sent values no later stage can change (a field with no write
|
|
141
|
+
* compute stage of its record's phase), so a caller's refusal opens no
|
|
142
|
+
* transaction. Everything is judged again after write compute.
|
|
143
|
+
*/
|
|
144
|
+
readonly beforeBegin?: boolean;
|
|
132
145
|
};
|
|
133
146
|
/**
|
|
134
|
-
* Runs an operation's admission — its guards
|
|
135
|
-
* the
|
|
147
|
+
* Runs an operation's admission — its guards and pipes, and before BEGIN the
|
|
148
|
+
* validators of the values nothing after it changes — and answers the
|
|
149
|
+
* deep-frozen arguments the rest of the operation reads, or the refusal.
|
|
136
150
|
*/
|
|
137
151
|
export declare function admitOperation<M extends AvAdapterModel>(dependencies: OperationPipelineDependencies<M>, request: StatefulOperationRequest, contract: AvContract, args: unknown, argumentsPath: readonly (string | number)[], report: DiagnosticsReporter, scope: ExecutorScope<M>, admission?: AdmissionScope): Promise<AdmittedOperation>;
|
|
138
152
|
/** How a plan step's arguments were changed between their admission and the step. */
|
|
@@ -146,7 +160,7 @@ export type StepChanges = {
|
|
|
146
160
|
};
|
|
147
161
|
/**
|
|
148
162
|
* A plan step's (or a forced call's) arguments at the step: resolved values
|
|
149
|
-
* through their field
|
|
163
|
+
* through their field pipes, and re-checked when a stage changed them.
|
|
150
164
|
*/
|
|
151
165
|
export declare function prepareStep<M extends AvAdapterModel>(dependencies: OperationPipelineDependencies<M>, request: StatefulOperationRequest, contract: AvContract, args: unknown, argumentsPath: readonly (string | number)[], report: DiagnosticsReporter, executor: AvAdapterTransactionExecutor<M>, changes: StepChanges, outer: OuterFailureLayer): Promise<AdmittedOperation>;
|
|
152
166
|
/**
|