@aventara/core 1.0.0-rc.0 → 1.0.0-rc.2
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 +1434 -0
- package/ERRORS.md +142 -0
- package/README.md +247 -57
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
- 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 +25 -11
- package/dist/adapters/adapter-identifier.d.ts +6 -6
- package/dist/adapters/adapter-model.d.ts +18 -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 +59 -29
- 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/{json → avz}/avz.js +150 -8
- package/dist/{json → avz}/index.d.ts +2 -1
- package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
- package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
- package/dist/{json → avz}/zod-issue.translator.js +7 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
- 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.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +637 -442
- 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/computed-fields.d.ts +62 -0
- package/dist/config/computed-fields.js +80 -0
- package/dist/config/config-diagnostic.d.ts +11 -4
- package/dist/config/config-diagnostic.guidance.d.ts +6 -0
- package/dist/config/config-diagnostic.guidance.js +32 -0
- package/dist/config/config-layer.d.ts +15 -6
- package/dist/config/config.resolver.d.ts +74 -31
- package/dist/config/config.resolver.js +108 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +581 -72
- 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 +308 -0
- package/dist/config/field-compute.resolver.d.ts +21 -0
- package/dist/config/field-compute.resolver.js +123 -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 -39
- 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 +122 -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 +21 -12
- package/dist/contracts/capability.js +2 -0
- package/dist/contracts/client-contract-structure.validator.d.ts +388 -63
- package/dist/contracts/client-contract-structure.validator.js +156 -10
- package/dist/contracts/contract-canonicalizer.d.ts +26 -3
- package/dist/contracts/contract-canonicalizer.js +156 -29
- 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 +24 -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 +81 -42
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-shape.d.ts +12 -1
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- 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 +15 -15
- 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 +213 -147
- package/dist/framework/framework-construction.error.d.ts +19 -10
- package/dist/framework/framework-construction.error.js +7 -3
- package/dist/framework/framework.d.ts +47 -23
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +49 -22
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +57 -50
- package/dist/index.js +7 -6
- package/dist/internal.d.ts +17 -10
- package/dist/internal.js +4 -1
- package/dist/operations/database-refusal.d.ts +51 -0
- package/dist/operations/database-refusal.js +45 -0
- package/dist/operations/operation-arguments.d.ts +343 -207
- package/dist/operations/operation-call.d.ts +27 -28
- package/dist/operations/operation-identity.d.ts +10 -10
- 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 +99 -6
- package/dist/operations/operation-validator.d.ts +9 -9
- package/dist/operations/projection-scope.resolver.d.ts +6 -6
- package/dist/operations/structural-limits.walker.d.ts +6 -6
- package/dist/operations/structural-limits.walker.js +145 -0
- package/dist/operations/validation-code.d.ts +11 -6
- package/dist/operations/validation-code.guidance.d.ts +6 -0
- package/dist/operations/validation-code.guidance.js +90 -0
- package/dist/operations/validation-code.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +10 -6
- package/dist/operations/write-scope.resolver.js +2 -0
- package/dist/protocol/absent-route.responder.d.ts +13 -12
- package/dist/protocol/absent-route.responder.js +19 -19
- 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 +17 -13
- package/dist/protocol/http-request.decoder.js +10 -10
- 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 +50 -27
- package/dist/protocol/protocol.binder.js +12 -9
- package/dist/protocol/protocol.handler.d.ts +22 -13
- package/dist/protocol/protocol.handler.js +91 -17
- package/dist/protocol/unmounted-route.error.d.ts +4 -4
- package/dist/protocol/unmounted-route.error.js +2 -2
- package/dist/runtime/caller-data.copier.d.ts +22 -5
- package/dist/runtime/caller-data.copier.js +31 -14
- package/dist/runtime/caller-data.door.d.ts +17 -11
- package/dist/runtime/caller-data.door.js +6 -4
- package/dist/runtime/computed-read-runtime.d.ts +7 -6
- package/dist/runtime/computed-read-runtime.js +76 -50
- package/dist/runtime/computed-value.error.d.ts +7 -6
- package/dist/runtime/computed-value.error.js +5 -4
- 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 +44 -79
- package/dist/runtime/create-requirement.js +213 -73
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +54 -27
- package/dist/runtime/diagnostics-reporter.js +24 -0
- package/dist/runtime/error-boundary.d.ts +65 -8
- package/dist/runtime/error-boundary.js +49 -19
- 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/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 +37 -0
- package/dist/runtime/field-stage.runtime.js +147 -0
- package/dist/runtime/field-validator.runtime.d.ts +19 -0
- package/dist/runtime/field-validator.runtime.js +92 -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 +68 -8
- 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 +11 -6
- package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
- package/dist/runtime/level-lifecycle.runtime.js +39 -0
- package/dist/runtime/misuse-reporter.d.ts +12 -12
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +48 -35
- package/dist/runtime/nested-write.walker.d.ts +32 -0
- package/dist/runtime/nested-write.walker.js +73 -0
- package/dist/runtime/operation-code.guidance.d.ts +6 -0
- package/dist/runtime/operation-code.guidance.js +167 -0
- package/dist/runtime/operation-request.d.ts +33 -6
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +127 -25
- package/dist/runtime/operation-runtime.js +441 -78
- package/dist/runtime/outcome-mapper.d.ts +16 -5
- package/dist/runtime/outcome-mapper.js +23 -6
- package/dist/runtime/output-validator.d.ts +10 -10
- package/dist/runtime/output-validator.js +3 -3
- package/dist/runtime/owned-execution.registry.d.ts +16 -6
- package/dist/runtime/pipe-output.validator.d.ts +43 -18
- package/dist/runtime/pipe-output.validator.js +15 -13
- package/dist/runtime/pipeline.d.ts +223 -34
- package/dist/runtime/readonly-value.d.ts +43 -0
- package/dist/runtime/readonly-value.js +150 -0
- package/dist/runtime/request-envelope.validator.d.ts +3 -3
- package/dist/runtime/request-envelope.validator.js +12 -7
- 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 +35 -16
- package/dist/runtime/scalar-runtime.js +102 -34
- package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
- package/dist/runtime/unsent-value.normalizer.js +128 -0
- 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/operation-fingerprint.js +2 -2
- package/dist/transactions/sql-statement.d.ts +85 -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 +167 -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 +21 -11
- package/dist/transactions/transaction-plan-assembler.js +169 -32
- package/dist/transactions/transaction-plan-validator.d.ts +45 -20
- package/dist/transactions/transaction-plan-validator.js +96 -38
- package/dist/transactions/transaction-reference-collector.d.ts +5 -5
- package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
- package/dist/transactions/transaction-reference-resolver.js +26 -14
- package/dist/transactions/transaction-reference-validator.d.ts +76 -4
- package/dist/transactions/transaction-reference-validator.js +129 -71
- package/dist/transactions/transaction-reference.d.ts +13 -13
- package/dist/transactions/transaction-reference.js +5 -0
- package/dist/transactions/transaction-request.d.ts +18 -5
- package/dist/transactions/transaction-response.d.ts +6 -6
- package/dist/transactions/transaction-runtime.d.ts +8 -7
- package/dist/transactions/transaction-runtime.js +191 -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 +82 -0
- package/dist/transactions/transaction-stage.runtime.js +126 -0
- package/package.json +9 -7
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -42
- 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 -42
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- package/dist/json/avz.d.ts +0 -96
- 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/{json → avz}/index.js +0 -0
- /package/dist/{json → avz}/json-shape.registry.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,18 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AvCanonicalJsonError } from "../contracts/contract-canonicalizer.js";
|
|
2
2
|
import { lookupField, lookupResource } from "../contracts/contract-lookup.js";
|
|
3
3
|
import { parseOperationIdentity } from "../operations/operation-identity.js";
|
|
4
|
-
import { findOperationAvailabilityIssue, unavailableOperationKey, } from "../operations/operation-validator.js";
|
|
4
|
+
import { findOperationAvailabilityIssue, operationUnavailableIssue, unavailableOperationKey, } from "../operations/operation-validator.js";
|
|
5
|
+
import { resourceUnavailableIssue } from "../operations/operation-validator-core.js";
|
|
5
6
|
import { VALIDATION_CODE_MESSAGES, validationIssue, } from "../operations/validation-code.js";
|
|
6
|
-
import {
|
|
7
|
+
import { AvCallerDataError, locateCallerDataError, mirrorCallerData, } from "../runtime/caller-data.copier.js";
|
|
7
8
|
import { copyAtDoor, misuseIdentityOf, refuseCallerData, } from "../runtime/caller-data.door.js";
|
|
8
9
|
import { planReadOperation, } from "../runtime/computed-read-runtime.js";
|
|
9
10
|
import { planOperationArgumentsPath, planStepPath, } from "../runtime/error-boundary.js";
|
|
10
11
|
import { createMisuseReporter } from "../runtime/misuse-reporter.js";
|
|
11
12
|
import { operationFailure } from "../runtime/operation-response.js";
|
|
12
13
|
import { activeContract, validateOperationRequest, validateProtocolIdentity, } from "../runtime/operation-runtime.js";
|
|
13
|
-
import { mapValidationOutcome } from "../runtime/outcome-mapper.js";
|
|
14
|
+
import { mapValidationOutcome, VALIDATION_OUTCOME_MESSAGES, } from "../runtime/outcome-mapper.js";
|
|
14
15
|
import { encodeOperationArgumentsForWire } from "./operation-arguments-encoder.js";
|
|
15
16
|
import { computeOperationFingerprint, isOperationFingerprint, } from "./operation-fingerprint.js";
|
|
17
|
+
import { validateSqlStatement } from "./sql-statement.validator.js";
|
|
16
18
|
import { inspectTransactionEnvelope, inspectTransactionOperationEntry, inspectTransactionOperations, } from "./transaction-envelope.js";
|
|
17
19
|
import { routeTransactionReferenceCandidate, } from "./transaction-reference.js";
|
|
18
20
|
import { collectTransactionReferenceCandidates, } from "./transaction-reference-collector.js";
|
|
@@ -22,9 +24,41 @@ const CALLER_PLAN = { source: "caller" };
|
|
|
22
24
|
const STEP_ARGUMENTS_POLICY = {
|
|
23
25
|
mirror: (value) => Object.hasOwn(value, "$ref"),
|
|
24
26
|
};
|
|
27
|
+
export function capturePlanAtCall(plan) {
|
|
28
|
+
const refused = new Map();
|
|
29
|
+
if (typeof plan !== "object" || plan === null) {
|
|
30
|
+
return { plan, refused };
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const mirrored = mirrorCallerData(plan, {
|
|
34
|
+
copyAt: (path) => path.length === 3 &&
|
|
35
|
+
path[0] === "operations" &&
|
|
36
|
+
typeof path[1] === "number" &&
|
|
37
|
+
path[2] === "args"
|
|
38
|
+
? STEP_ARGUMENTS_POLICY
|
|
39
|
+
: undefined,
|
|
40
|
+
refused: (path, error) => {
|
|
41
|
+
refused.set(path[1], error);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return { plan: mirrored, refused };
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof AvCallerDataError) {
|
|
48
|
+
return { plan, refused };
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
25
53
|
function captureSteps(operations, operationCount, planArguments) {
|
|
26
54
|
const steps = [];
|
|
55
|
+
const statements = planArguments.source === "owned" ? planArguments.statements : undefined;
|
|
27
56
|
for (let index = 0; index < operationCount; index += 1) {
|
|
57
|
+
const statement = statements?.get(index);
|
|
58
|
+
if (statement !== undefined) {
|
|
59
|
+
steps.push({ ok: true, kind: "sql", statement });
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
28
62
|
const operationEntry = inspectTransactionOperationEntry(operations, index);
|
|
29
63
|
if (!operationEntry.ok) {
|
|
30
64
|
steps.push({
|
|
@@ -55,7 +89,7 @@ function captureSteps(operations, operationCount, planArguments) {
|
|
|
55
89
|
: planArguments.source === "owned"
|
|
56
90
|
? { ok: true, value: args }
|
|
57
91
|
: copyAtDoor(args, STEP_ARGUMENTS_POLICY);
|
|
58
|
-
steps.push({ ok: true, node, args: copy });
|
|
92
|
+
steps.push({ ok: true, kind: "operation", node, args: copy });
|
|
59
93
|
if (!copy.ok) {
|
|
60
94
|
break;
|
|
61
95
|
}
|
|
@@ -73,11 +107,16 @@ const OPERATION_KEYS = [
|
|
|
73
107
|
function isObject(value) {
|
|
74
108
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
109
|
}
|
|
76
|
-
function operationKeyFailure(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
110
|
+
function operationKeyFailure(contract, step, operation) {
|
|
111
|
+
const { resource, family, variant } = step;
|
|
112
|
+
const issue = typeof family === "string" && typeof variant === "string"
|
|
113
|
+
? operationUnavailableIssue(contract, { resource, family, variant })
|
|
114
|
+
: validationIssue("V1006", [
|
|
115
|
+
typeof family === "string"
|
|
116
|
+
? unavailableOperationKey(contract, { resource, family })
|
|
117
|
+
: "family",
|
|
118
|
+
], `Operation is not available on Resource "${resource}".`);
|
|
119
|
+
return transactionOperationFailure(mapValidationOutcome([issue]), operation);
|
|
81
120
|
}
|
|
82
121
|
function structuralFailure(rejection, operation) {
|
|
83
122
|
return operationFailure("A2004", {
|
|
@@ -93,9 +132,10 @@ function structuralFailure(rejection, operation) {
|
|
|
93
132
|
...(operation === undefined ? {} : { operation }),
|
|
94
133
|
});
|
|
95
134
|
}
|
|
96
|
-
function syntheticRequest(origin,
|
|
135
|
+
function syntheticRequest(origin, request, resource, identity, args) {
|
|
97
136
|
const common = {
|
|
98
|
-
requestId,
|
|
137
|
+
requestId: request.requestId,
|
|
138
|
+
...(request.state === undefined ? {} : { state: request.state }),
|
|
99
139
|
resource,
|
|
100
140
|
...identity,
|
|
101
141
|
arguments: args,
|
|
@@ -104,7 +144,7 @@ function syntheticRequest(origin, requestId, resource, identity, args) {
|
|
|
104
144
|
? { ...common, origin: "application" }
|
|
105
145
|
: {
|
|
106
146
|
...common,
|
|
107
|
-
origin:
|
|
147
|
+
origin: origin.origin,
|
|
108
148
|
protocol: origin.protocol,
|
|
109
149
|
...(origin.transport === undefined
|
|
110
150
|
? {}
|
|
@@ -115,7 +155,7 @@ function requestOrigin(request) {
|
|
|
115
155
|
return request.origin === "application"
|
|
116
156
|
? { origin: "application" }
|
|
117
157
|
: {
|
|
118
|
-
origin:
|
|
158
|
+
origin: request.origin,
|
|
119
159
|
protocol: request.protocol,
|
|
120
160
|
...(request.transport === undefined
|
|
121
161
|
? {}
|
|
@@ -124,7 +164,21 @@ function requestOrigin(request) {
|
|
|
124
164
|
}
|
|
125
165
|
function originContracts(contracts, origins) {
|
|
126
166
|
const layers = new Set(origins.map(({ origin }) => origin));
|
|
127
|
-
return [...layers].map((origin) => origin
|
|
167
|
+
return [...layers].map((origin) => contracts[origin]);
|
|
168
|
+
}
|
|
169
|
+
function mixedOriginFailure(origins) {
|
|
170
|
+
const [first] = origins ?? [];
|
|
171
|
+
const other = first === undefined
|
|
172
|
+
? -1
|
|
173
|
+
: (origins ?? []).findIndex(({ origin }) => origin !== first.origin);
|
|
174
|
+
return other === -1
|
|
175
|
+
? undefined
|
|
176
|
+
: transactionOperationFailure(operationFailure("A2004", {
|
|
177
|
+
message: "Transaction plan failed framework validation.",
|
|
178
|
+
issues: [
|
|
179
|
+
validationIssue("V1020", [], VALIDATION_CODE_MESSAGES.V1020),
|
|
180
|
+
],
|
|
181
|
+
}), other);
|
|
128
182
|
}
|
|
129
183
|
function* relationTraversals(contract, resourceName, value, path) {
|
|
130
184
|
const resource = lookupResource(contract, resourceName);
|
|
@@ -208,6 +262,10 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
208
262
|
if (protocolFailure !== undefined) {
|
|
209
263
|
return { ok: false, response: protocolFailure };
|
|
210
264
|
}
|
|
265
|
+
const mixed = mixedOriginFailure(origins);
|
|
266
|
+
if (mixed !== undefined) {
|
|
267
|
+
return { ok: false, response: mixed };
|
|
268
|
+
}
|
|
211
269
|
const ownOrigin = requestOrigin(request);
|
|
212
270
|
const originOf = (index) => origins?.[index] ?? ownOrigin;
|
|
213
271
|
const planContracts = origins === undefined || origins.length === 0
|
|
@@ -259,17 +317,28 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
259
317
|
if (!step.ok) {
|
|
260
318
|
return { ok: false, response: step.response };
|
|
261
319
|
}
|
|
320
|
+
if (step.kind === "sql") {
|
|
321
|
+
const statement = validateSqlStatement(step.statement, {
|
|
322
|
+
index,
|
|
323
|
+
earlier: validated,
|
|
324
|
+
available: dependencies.sqlStatements,
|
|
325
|
+
misuse,
|
|
326
|
+
});
|
|
327
|
+
if (!statement.ok) {
|
|
328
|
+
return statement;
|
|
329
|
+
}
|
|
330
|
+
validated.push(statement.statement);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
262
333
|
const node = step.node;
|
|
263
334
|
const origin = originOf(index);
|
|
264
|
-
const contract = origin.origin
|
|
265
|
-
? dependencies.contracts.application
|
|
266
|
-
: dependencies.contracts.client;
|
|
335
|
+
const contract = dependencies.contracts[origin.origin];
|
|
267
336
|
const resourceValue = node.get("resource");
|
|
268
337
|
if (typeof resourceValue !== "string") {
|
|
269
338
|
return {
|
|
270
339
|
ok: false,
|
|
271
340
|
response: transactionOperationFailure(operationFailure("A2001", {
|
|
272
|
-
message:
|
|
341
|
+
message: VALIDATION_OUTCOME_MESSAGES.A2001,
|
|
273
342
|
issues: [
|
|
274
343
|
validationIssue("V1001", ["resource"], "resource must be a string."),
|
|
275
344
|
],
|
|
@@ -279,12 +348,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
279
348
|
if (lookupResource(contract, resourceValue) === undefined) {
|
|
280
349
|
return {
|
|
281
350
|
ok: false,
|
|
282
|
-
response: transactionOperationFailure(
|
|
283
|
-
message: "Operation arguments failed framework validation.",
|
|
284
|
-
issues: [
|
|
285
|
-
validationIssue("V1005", ["resource"], `Resource "${resourceValue}" is not available in the active Contract.`),
|
|
286
|
-
],
|
|
287
|
-
}), index),
|
|
351
|
+
response: transactionOperationFailure(mapValidationOutcome([resourceUnavailableIssue(resourceValue)]), index),
|
|
288
352
|
};
|
|
289
353
|
}
|
|
290
354
|
const family = node.get("family");
|
|
@@ -295,12 +359,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
295
359
|
if (identity === undefined) {
|
|
296
360
|
return {
|
|
297
361
|
ok: false,
|
|
298
|
-
response: operationKeyFailure(
|
|
299
|
-
? unavailableOperationKey(contract, {
|
|
300
|
-
resource: resourceValue,
|
|
301
|
-
family,
|
|
302
|
-
})
|
|
303
|
-
: "family", "Operation is not part of the standard operation grammar.", index),
|
|
362
|
+
response: operationKeyFailure(contract, { resource: resourceValue, family, variant }, index),
|
|
304
363
|
};
|
|
305
364
|
}
|
|
306
365
|
const stepRequest = { resource: resourceValue, ...identity };
|
|
@@ -326,7 +385,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
326
385
|
};
|
|
327
386
|
}
|
|
328
387
|
try {
|
|
329
|
-
const operationRequest = syntheticRequest(origin, request
|
|
388
|
+
const operationRequest = syntheticRequest(origin, request, resourceValue, identity, step.args.value);
|
|
330
389
|
const operationValidation = validateOperationRequest(contract, operationRequest, { transactionReferences: true });
|
|
331
390
|
if (!operationValidation.ok) {
|
|
332
391
|
return {
|
|
@@ -338,9 +397,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
338
397
|
index,
|
|
339
398
|
request: operationRequest,
|
|
340
399
|
arguments: operationValidation.arguments,
|
|
341
|
-
projection: planReadOperation(dependencies.contracts.core, contract,
|
|
342
|
-
? dependencies.config.application
|
|
343
|
-
: dependencies.config.client).behaviors, operationRequest, operationValidation.arguments).projection,
|
|
400
|
+
projection: planReadOperation(dependencies.contracts.core, dependencies.config.adapter.model, contract, dependencies.config[origin.origin].compute, operationRequest, operationValidation.arguments).projection,
|
|
344
401
|
declaredFingerprint: node.get("fingerprint"),
|
|
345
402
|
candidates: collectTransactionReferenceCandidates(contract, operationRequest, index, operationValidation.arguments),
|
|
346
403
|
};
|
|
@@ -353,7 +410,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
353
410
|
arguments: referenceValidation.requestArguments,
|
|
354
411
|
};
|
|
355
412
|
const validatedArguments = referenceValidation.arguments;
|
|
356
|
-
const wireArguments = origin.origin
|
|
413
|
+
const wireArguments = origin.origin !== "application"
|
|
357
414
|
? validatedRequest.arguments
|
|
358
415
|
: encodeOperationArgumentsForWire(contract, validatedRequest, validatedArguments);
|
|
359
416
|
let fingerprint;
|
|
@@ -366,7 +423,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
366
423
|
});
|
|
367
424
|
}
|
|
368
425
|
catch (error) {
|
|
369
|
-
if (!(error instanceof
|
|
426
|
+
if (!(error instanceof AvCanonicalJsonError)) {
|
|
370
427
|
throw error;
|
|
371
428
|
}
|
|
372
429
|
return {
|
|
@@ -404,6 +461,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
404
461
|
}
|
|
405
462
|
}
|
|
406
463
|
validated.push({
|
|
464
|
+
kind: "operation",
|
|
407
465
|
index: candidate.index,
|
|
408
466
|
request: validatedRequest,
|
|
409
467
|
contract,
|
|
@@ -414,7 +472,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
414
472
|
});
|
|
415
473
|
}
|
|
416
474
|
catch (error) {
|
|
417
|
-
if (!(error instanceof
|
|
475
|
+
if (!(error instanceof AvCallerDataError)) {
|
|
418
476
|
throw error;
|
|
419
477
|
}
|
|
420
478
|
return {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvContract } from "../contracts/contract.js";
|
|
2
|
+
import type { AvScalarField } from "../contracts/field.js";
|
|
3
|
+
import type { AvOperationIdentity } from "../operations/operation-identity.js";
|
|
4
4
|
import type { SemanticOperationArguments } from "../operations/operation-validator.js";
|
|
5
5
|
import { type TransactionSlotShape } from "./transaction-reference.js";
|
|
6
6
|
type Path = readonly (string | number)[];
|
|
7
7
|
/** One `$ref` candidate found at a reference position, before it is validated. */
|
|
8
8
|
export type TransactionReferenceCandidateSlot = {
|
|
9
9
|
readonly path: Path;
|
|
10
|
-
readonly field:
|
|
10
|
+
readonly field: AvScalarField<AvContract>;
|
|
11
11
|
readonly shape: TransactionSlotShape;
|
|
12
12
|
/** The slot is a scalar value of mutation data: what it resolves to is written. */
|
|
13
13
|
readonly written: boolean;
|
|
@@ -24,7 +24,7 @@ export type TransactionReferenceCandidateSlot = {
|
|
|
24
24
|
* It reads the validated argument view, whose normalization keeps every key where
|
|
25
25
|
* the caller wrote it, so a slot path names the same member of the wire view.
|
|
26
26
|
*/
|
|
27
|
-
export declare function collectTransactionReferenceCandidates(contract:
|
|
27
|
+
export declare function collectTransactionReferenceCandidates(contract: AvContract, request: AvOperationIdentity & {
|
|
28
28
|
readonly resource: string;
|
|
29
29
|
}, index: number, args: SemanticOperationArguments): readonly TransactionReferenceCandidateSlot[];
|
|
30
30
|
export {};
|
|
@@ -1,13 +1,30 @@
|
|
|
1
|
+
import type { AvAdapterSqlStatement } from "../adapters/adapter-sql-statement.js";
|
|
1
2
|
import type { SemanticOperationArguments } from "../operations/operation-validator.js";
|
|
2
|
-
import type {
|
|
3
|
+
import type { AvValidationIssue } from "../operations/validation-code.js";
|
|
4
|
+
import type { ValidatedSqlStatement } from "./sql-statement.js";
|
|
3
5
|
import type { ValidatedTransactionOperation } from "./transaction-plan-validator.js";
|
|
4
6
|
export type ResolvedTransactionArguments = {
|
|
5
7
|
readonly ok: true;
|
|
6
8
|
readonly arguments: SemanticOperationArguments;
|
|
7
9
|
} | {
|
|
8
10
|
readonly ok: false;
|
|
9
|
-
readonly issues: readonly
|
|
11
|
+
readonly issues: readonly AvValidationIssue[];
|
|
10
12
|
};
|
|
13
|
+
export type ResolvedSqlStatement = {
|
|
14
|
+
readonly ok: true;
|
|
15
|
+
readonly statement: AvAdapterSqlStatement;
|
|
16
|
+
} | {
|
|
17
|
+
readonly ok: false;
|
|
18
|
+
readonly issues: readonly AvValidationIssue[];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The statement a validated SQL step hands the Adapter: every `$ref` value read from
|
|
22
|
+
* the results ledger, exactly as an operation's slot is — the source's final data,
|
|
23
|
+
* copied by the source field's own codec — and then bound like any other value. A
|
|
24
|
+
* source row lacking the field is `V1018` at the value, before the statement runs.
|
|
25
|
+
* Issue paths are relative to the step (`["values", k, "$ref", "path"]`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveSqlStatement(statement: ValidatedSqlStatement, results: readonly unknown[]): ResolvedSqlStatement;
|
|
11
28
|
/**
|
|
12
29
|
* Substitutes every validated `$ref` placeholder of one operation from the results
|
|
13
30
|
* ledger: each earlier operation's final `data`, exactly the value at its index in the
|
|
@@ -1,32 +1,44 @@
|
|
|
1
1
|
import { validationIssue } from "../operations/validation-code.js";
|
|
2
|
-
import { copyScalarFieldValue
|
|
2
|
+
import { copyScalarFieldValue } from "../runtime/scalar-runtime.js";
|
|
3
3
|
import { replaceTransactionSlotValues } from "./transaction-slot-writer.js";
|
|
4
4
|
function isRecord(value) {
|
|
5
5
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
6
|
}
|
|
7
|
+
function unresolvedIssue(path) {
|
|
8
|
+
return validationIssue("V1018", [...path, "$ref", "path"], "Transaction reference resolved to no value.");
|
|
9
|
+
}
|
|
10
|
+
export function resolveSqlStatement(statement, results) {
|
|
11
|
+
const values = [];
|
|
12
|
+
for (const [position, value] of statement.values.entries()) {
|
|
13
|
+
if (value.kind === "value") {
|
|
14
|
+
values.push(value.value);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
const row = results[value.operation];
|
|
18
|
+
if (!isRecord(row) || !Object.hasOwn(row, value.field)) {
|
|
19
|
+
return { ok: false, issues: [unresolvedIssue(["values", position])] };
|
|
20
|
+
}
|
|
21
|
+
values.push(copyScalarFieldValue(value.source, row[value.field]));
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
ok: true,
|
|
25
|
+
statement: Object.freeze({
|
|
26
|
+
strings: statement.strings,
|
|
27
|
+
values: Object.freeze(values),
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
7
31
|
export function resolveTransactionReferences(operation, results) {
|
|
8
32
|
const substitutions = [];
|
|
9
|
-
const shapeIssues = [];
|
|
10
33
|
for (const slot of operation.references) {
|
|
11
34
|
const { operation: source, path: [segment], } = slot.reference.$ref;
|
|
12
35
|
const row = results[source];
|
|
13
36
|
if (!isRecord(row) || !Object.hasOwn(row, segment)) {
|
|
14
|
-
return {
|
|
15
|
-
ok: false,
|
|
16
|
-
issues: [
|
|
17
|
-
validationIssue("V1018", [...slot.path, "$ref", "path"], "Transaction reference resolved to no value."),
|
|
18
|
-
],
|
|
19
|
-
};
|
|
37
|
+
return { ok: false, issues: [unresolvedIssue(slot.path)] };
|
|
20
38
|
}
|
|
21
39
|
const value = copyScalarFieldValue(slot.source, row[segment]);
|
|
22
|
-
if (slot.written) {
|
|
23
|
-
shapeIssues.push(...jsonShapeIssues(slot.field, value, slot.path));
|
|
24
|
-
}
|
|
25
40
|
substitutions.push({ path: slot.path, value });
|
|
26
41
|
}
|
|
27
|
-
if (shapeIssues.length > 0) {
|
|
28
|
-
return { ok: false, issues: shapeIssues };
|
|
29
|
-
}
|
|
30
42
|
return {
|
|
31
43
|
ok: true,
|
|
32
44
|
arguments: replaceTransactionSlotValues(operation.arguments, operation.index, substitutions),
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvContract } from "../contracts/contract.js";
|
|
2
|
+
import type { AvField } from "../contracts/field.js";
|
|
3
|
+
import type { AvValidationIssue } from "../operations/validation-code.js";
|
|
4
|
+
import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
|
|
5
|
+
import type { OperationFingerprint } from "./deferred-operation.js";
|
|
6
|
+
import type { CandidateTransactionOperation, TransactionReferenceSlot, ValidatedTransactionStep } from "./transaction-plan-validator.js";
|
|
7
|
+
import type { TransactionReferenceCandidateSlot } from "./transaction-reference-collector.js";
|
|
8
|
+
type Path = readonly (string | number)[];
|
|
3
9
|
type ReferenceValidationResult = {
|
|
4
10
|
readonly ok: true;
|
|
5
11
|
readonly references: readonly TransactionReferenceSlot[];
|
|
@@ -7,8 +13,74 @@ type ReferenceValidationResult = {
|
|
|
7
13
|
readonly requestArguments: unknown;
|
|
8
14
|
} | {
|
|
9
15
|
readonly ok: false;
|
|
10
|
-
readonly response:
|
|
16
|
+
readonly response: AvOperationFailureResponse;
|
|
11
17
|
};
|
|
18
|
+
/** The `V1016` refusal of a reference's source index, at its `operation` member. */
|
|
19
|
+
export declare function invalidSourceIndexIssue(operationPath: Path): AvValidationIssue;
|
|
20
|
+
/**
|
|
21
|
+
* The validated step a reference names, or `undefined` when its index is no
|
|
22
|
+
* integer naming a step before the referencing one (`V1016`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function referenceSourceAt(earlier: readonly ValidatedTransactionStep[], sourceIndex: unknown, referencingIndex: number): ValidatedTransactionStep | undefined;
|
|
25
|
+
/** The `V1010` refusal of a reference whose source is an `appTx.$sql` step. */
|
|
26
|
+
export declare function sqlSourceIssue(pathPath: Path): AvValidationIssue;
|
|
27
|
+
/** The field a reference reads from its source step, or why it cannot read one. */
|
|
28
|
+
export type ReferenceSourceRead = {
|
|
29
|
+
readonly ok: true;
|
|
30
|
+
readonly field: AvField<AvContract>;
|
|
31
|
+
} | {
|
|
32
|
+
readonly ok: false;
|
|
33
|
+
readonly issue: AvValidationIssue;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Reads the field a reference's one path segment names from its source step,
|
|
37
|
+
* holding the source to what a reference may read: one row (not a `many` or
|
|
38
|
+
* `count` result, not a SQL step's rows), and a field in its actual projection,
|
|
39
|
+
* never a reducer. The field is read under the source's own Contract: in a plan
|
|
40
|
+
* that mixes origins, a source field the referencing step's layer hides is still
|
|
41
|
+
* the source's to read. Assignability to a destination is the caller's.
|
|
42
|
+
*/
|
|
43
|
+
export declare function referenceSourceField(source: ValidatedTransactionStep, segment: string, pathPath: Path): ReferenceSourceRead;
|
|
44
|
+
/** A `$ref` control object read through: its source step, field and fingerprint. */
|
|
45
|
+
export type ReferenceCandidateInspection = {
|
|
46
|
+
readonly ok: true;
|
|
47
|
+
readonly source: Extract<ValidatedTransactionStep, {
|
|
48
|
+
kind: "operation";
|
|
49
|
+
}>;
|
|
50
|
+
readonly segment: string;
|
|
51
|
+
readonly fingerprint: OperationFingerprint;
|
|
52
|
+
readonly field: AvField<AvContract>;
|
|
53
|
+
/** The candidate's `path` member's own path, where a type refusal stands. */
|
|
54
|
+
readonly pathPath: Path;
|
|
55
|
+
} | {
|
|
56
|
+
readonly ok: false;
|
|
57
|
+
readonly issue: AvValidationIssue;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Inspects one `$ref` control object standing at `slotPath` of step
|
|
61
|
+
* `referencingIndex`, through property descriptors only: its shape, its source
|
|
62
|
+
* step (an earlier one, never a SQL step), the source's fingerprint and the one
|
|
63
|
+
* field its path reads from the source's projection. Assignability to the
|
|
64
|
+
* destination is the caller's. Shared by an operation step's slots and an
|
|
65
|
+
* `appTx.$sql` value, so both refuse a malformed reference alike.
|
|
66
|
+
*/
|
|
67
|
+
export declare function inspectReferenceCandidate(candidate: unknown, slotPath: Path, earlier: readonly ValidatedTransactionStep[], referencingIndex: number): ReferenceCandidateInspection;
|
|
68
|
+
/** The validated slots of a step's candidates, or the first one's refusal. */
|
|
69
|
+
export type ReferenceSlotsValidation = {
|
|
70
|
+
readonly ok: true;
|
|
71
|
+
readonly references: readonly TransactionReferenceSlot[];
|
|
72
|
+
} | {
|
|
73
|
+
readonly ok: false;
|
|
74
|
+
readonly issue: AvValidationIssue;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Judges every `$ref` candidate of step `index` by the Framework Validation
|
|
78
|
+
* Layer's reference rules — its shape, an earlier non-SQL source step, that
|
|
79
|
+
* step's fingerprint, a field of its single-row projection, and type
|
|
80
|
+
* compatibility with the slot it stands in — and answers the validated slots,
|
|
81
|
+
* or the first refusal.
|
|
82
|
+
*/
|
|
83
|
+
export declare function validateReferenceSlots(candidates: readonly TransactionReferenceCandidateSlot[], earlier: readonly ValidatedTransactionStep[], index: number): ReferenceSlotsValidation;
|
|
12
84
|
/** Validates every passive reference candidate before operation fingerprinting. */
|
|
13
|
-
export declare function validateTransactionReferences(operation: CandidateTransactionOperation, earlier: readonly
|
|
85
|
+
export declare function validateTransactionReferences(operation: CandidateTransactionOperation, earlier: readonly ValidatedTransactionStep[]): ReferenceValidationResult;
|
|
14
86
|
export {};
|