@aventara/core 1.0.0-rc.0 → 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 +1140 -0
- package/README.md +224 -57
- 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 +9 -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 -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.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +548 -441
- 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 +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 +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 +110 -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 +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 +323 -28
- package/dist/contracts/client-contract-structure.validator.js +152 -8
- package/dist/contracts/contract-canonicalizer.d.ts +19 -3
- package/dist/contracts/contract-canonicalizer.js +141 -28
- 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 +52 -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 +10 -10
- package/dist/framework/framework-construction.error.js +2 -2
- package/dist/framework/framework.d.ts +47 -23
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +40 -20
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +55 -50
- package/dist/index.js +6 -6
- package/dist/internal.d.ts +15 -10
- package/dist/internal.js +3 -1
- package/dist/operations/operation-arguments.d.ts +267 -202
- 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 +13 -2
- 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.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +6 -6
- 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 +44 -9
- 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 +5 -5
- package/dist/runtime/caller-data.copier.js +13 -13
- package/dist/runtime/caller-data.door.d.ts +6 -6
- 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 +61 -48
- package/dist/runtime/computed-value.error.d.ts +6 -6
- package/dist/runtime/computed-value.error.js +3 -3
- 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 +10 -81
- package/dist/runtime/create-requirement.js +80 -57
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +53 -27
- package/dist/runtime/diagnostics-reporter.js +24 -0
- package/dist/runtime/error-boundary.d.ts +65 -8
- package/dist/runtime/error-boundary.js +45 -19
- 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 +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 +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 +12 -12
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +54 -30
- 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 +33 -6
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +113 -25
- package/dist/runtime/operation-runtime.js +395 -74
- 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 +6 -6
- 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 +196 -34
- package/dist/runtime/readonly-value.d.ts +32 -0
- package/dist/runtime/readonly-value.js +141 -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 +31 -16
- package/dist/runtime/scalar-runtime.js +16 -18
- 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 +21 -11
- package/dist/transactions/transaction-plan-assembler.js +148 -34
- package/dist/transactions/transaction-plan-validator.d.ts +29 -20
- package/dist/transactions/transaction-plan-validator.js +70 -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 +34 -4
- package/dist/transactions/transaction-reference-validator.js +58 -26
- package/dist/transactions/transaction-reference.d.ts +13 -13
- 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 +166 -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 +6 -5
- 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, } 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";
|
|
@@ -24,7 +26,13 @@ const STEP_ARGUMENTS_POLICY = {
|
|
|
24
26
|
};
|
|
25
27
|
function captureSteps(operations, operationCount, planArguments) {
|
|
26
28
|
const steps = [];
|
|
29
|
+
const statements = planArguments.source === "owned" ? planArguments.statements : undefined;
|
|
27
30
|
for (let index = 0; index < operationCount; index += 1) {
|
|
31
|
+
const statement = statements?.get(index);
|
|
32
|
+
if (statement !== undefined) {
|
|
33
|
+
steps.push({ ok: true, kind: "sql", statement });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
28
36
|
const operationEntry = inspectTransactionOperationEntry(operations, index);
|
|
29
37
|
if (!operationEntry.ok) {
|
|
30
38
|
steps.push({
|
|
@@ -55,7 +63,7 @@ function captureSteps(operations, operationCount, planArguments) {
|
|
|
55
63
|
: planArguments.source === "owned"
|
|
56
64
|
? { ok: true, value: args }
|
|
57
65
|
: copyAtDoor(args, STEP_ARGUMENTS_POLICY);
|
|
58
|
-
steps.push({ ok: true, node, args: copy });
|
|
66
|
+
steps.push({ ok: true, kind: "operation", node, args: copy });
|
|
59
67
|
if (!copy.ok) {
|
|
60
68
|
break;
|
|
61
69
|
}
|
|
@@ -73,11 +81,16 @@ const OPERATION_KEYS = [
|
|
|
73
81
|
function isObject(value) {
|
|
74
82
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
83
|
}
|
|
76
|
-
function operationKeyFailure(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
function operationKeyFailure(contract, step, operation) {
|
|
85
|
+
const { resource, family, variant } = step;
|
|
86
|
+
const issue = typeof family === "string" && typeof variant === "string"
|
|
87
|
+
? operationUnavailableIssue(contract, { resource, family, variant })
|
|
88
|
+
: validationIssue("V1006", [
|
|
89
|
+
typeof family === "string"
|
|
90
|
+
? unavailableOperationKey(contract, { resource, family })
|
|
91
|
+
: "family",
|
|
92
|
+
], `Operation is not available on Resource "${resource}".`);
|
|
93
|
+
return transactionOperationFailure(mapValidationOutcome([issue]), operation);
|
|
81
94
|
}
|
|
82
95
|
function structuralFailure(rejection, operation) {
|
|
83
96
|
return operationFailure("A2004", {
|
|
@@ -93,9 +106,10 @@ function structuralFailure(rejection, operation) {
|
|
|
93
106
|
...(operation === undefined ? {} : { operation }),
|
|
94
107
|
});
|
|
95
108
|
}
|
|
96
|
-
function syntheticRequest(origin,
|
|
109
|
+
function syntheticRequest(origin, request, resource, identity, args) {
|
|
97
110
|
const common = {
|
|
98
|
-
requestId,
|
|
111
|
+
requestId: request.requestId,
|
|
112
|
+
...(request.state === undefined ? {} : { state: request.state }),
|
|
99
113
|
resource,
|
|
100
114
|
...identity,
|
|
101
115
|
arguments: args,
|
|
@@ -104,7 +118,7 @@ function syntheticRequest(origin, requestId, resource, identity, args) {
|
|
|
104
118
|
? { ...common, origin: "application" }
|
|
105
119
|
: {
|
|
106
120
|
...common,
|
|
107
|
-
origin:
|
|
121
|
+
origin: origin.origin,
|
|
108
122
|
protocol: origin.protocol,
|
|
109
123
|
...(origin.transport === undefined
|
|
110
124
|
? {}
|
|
@@ -115,7 +129,7 @@ function requestOrigin(request) {
|
|
|
115
129
|
return request.origin === "application"
|
|
116
130
|
? { origin: "application" }
|
|
117
131
|
: {
|
|
118
|
-
origin:
|
|
132
|
+
origin: request.origin,
|
|
119
133
|
protocol: request.protocol,
|
|
120
134
|
...(request.transport === undefined
|
|
121
135
|
? {}
|
|
@@ -124,7 +138,21 @@ function requestOrigin(request) {
|
|
|
124
138
|
}
|
|
125
139
|
function originContracts(contracts, origins) {
|
|
126
140
|
const layers = new Set(origins.map(({ origin }) => origin));
|
|
127
|
-
return [...layers].map((origin) => origin
|
|
141
|
+
return [...layers].map((origin) => contracts[origin]);
|
|
142
|
+
}
|
|
143
|
+
function mixedOriginFailure(origins) {
|
|
144
|
+
const [first] = origins ?? [];
|
|
145
|
+
const other = first === undefined
|
|
146
|
+
? -1
|
|
147
|
+
: (origins ?? []).findIndex(({ origin }) => origin !== first.origin);
|
|
148
|
+
return other === -1
|
|
149
|
+
? undefined
|
|
150
|
+
: transactionOperationFailure(operationFailure("A2004", {
|
|
151
|
+
message: "Transaction plan failed framework validation.",
|
|
152
|
+
issues: [
|
|
153
|
+
validationIssue("V1020", [], VALIDATION_CODE_MESSAGES.V1020),
|
|
154
|
+
],
|
|
155
|
+
}), other);
|
|
128
156
|
}
|
|
129
157
|
function* relationTraversals(contract, resourceName, value, path) {
|
|
130
158
|
const resource = lookupResource(contract, resourceName);
|
|
@@ -208,6 +236,10 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
208
236
|
if (protocolFailure !== undefined) {
|
|
209
237
|
return { ok: false, response: protocolFailure };
|
|
210
238
|
}
|
|
239
|
+
const mixed = mixedOriginFailure(origins);
|
|
240
|
+
if (mixed !== undefined) {
|
|
241
|
+
return { ok: false, response: mixed };
|
|
242
|
+
}
|
|
211
243
|
const ownOrigin = requestOrigin(request);
|
|
212
244
|
const originOf = (index) => origins?.[index] ?? ownOrigin;
|
|
213
245
|
const planContracts = origins === undefined || origins.length === 0
|
|
@@ -259,17 +291,28 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
259
291
|
if (!step.ok) {
|
|
260
292
|
return { ok: false, response: step.response };
|
|
261
293
|
}
|
|
294
|
+
if (step.kind === "sql") {
|
|
295
|
+
const statement = validateSqlStatement(step.statement, {
|
|
296
|
+
index,
|
|
297
|
+
earlier: validated,
|
|
298
|
+
available: dependencies.sqlStatements,
|
|
299
|
+
misuse,
|
|
300
|
+
});
|
|
301
|
+
if (!statement.ok) {
|
|
302
|
+
return statement;
|
|
303
|
+
}
|
|
304
|
+
validated.push(statement.statement);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
262
307
|
const node = step.node;
|
|
263
308
|
const origin = originOf(index);
|
|
264
|
-
const contract = origin.origin
|
|
265
|
-
? dependencies.contracts.application
|
|
266
|
-
: dependencies.contracts.client;
|
|
309
|
+
const contract = dependencies.contracts[origin.origin];
|
|
267
310
|
const resourceValue = node.get("resource");
|
|
268
311
|
if (typeof resourceValue !== "string") {
|
|
269
312
|
return {
|
|
270
313
|
ok: false,
|
|
271
314
|
response: transactionOperationFailure(operationFailure("A2001", {
|
|
272
|
-
message:
|
|
315
|
+
message: VALIDATION_OUTCOME_MESSAGES.A2001,
|
|
273
316
|
issues: [
|
|
274
317
|
validationIssue("V1001", ["resource"], "resource must be a string."),
|
|
275
318
|
],
|
|
@@ -279,12 +322,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
279
322
|
if (lookupResource(contract, resourceValue) === undefined) {
|
|
280
323
|
return {
|
|
281
324
|
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),
|
|
325
|
+
response: transactionOperationFailure(mapValidationOutcome([resourceUnavailableIssue(resourceValue)]), index),
|
|
288
326
|
};
|
|
289
327
|
}
|
|
290
328
|
const family = node.get("family");
|
|
@@ -295,12 +333,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
295
333
|
if (identity === undefined) {
|
|
296
334
|
return {
|
|
297
335
|
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),
|
|
336
|
+
response: operationKeyFailure(contract, { resource: resourceValue, family, variant }, index),
|
|
304
337
|
};
|
|
305
338
|
}
|
|
306
339
|
const stepRequest = { resource: resourceValue, ...identity };
|
|
@@ -326,7 +359,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
326
359
|
};
|
|
327
360
|
}
|
|
328
361
|
try {
|
|
329
|
-
const operationRequest = syntheticRequest(origin, request
|
|
362
|
+
const operationRequest = syntheticRequest(origin, request, resourceValue, identity, step.args.value);
|
|
330
363
|
const operationValidation = validateOperationRequest(contract, operationRequest, { transactionReferences: true });
|
|
331
364
|
if (!operationValidation.ok) {
|
|
332
365
|
return {
|
|
@@ -338,9 +371,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
338
371
|
index,
|
|
339
372
|
request: operationRequest,
|
|
340
373
|
arguments: operationValidation.arguments,
|
|
341
|
-
projection: planReadOperation(dependencies.contracts.core, contract,
|
|
342
|
-
? dependencies.config.application
|
|
343
|
-
: dependencies.config.client).behaviors, operationRequest, operationValidation.arguments).projection,
|
|
374
|
+
projection: planReadOperation(dependencies.contracts.core, dependencies.config.adapter.model, contract, dependencies.config[origin.origin].compute, operationRequest, operationValidation.arguments).projection,
|
|
344
375
|
declaredFingerprint: node.get("fingerprint"),
|
|
345
376
|
candidates: collectTransactionReferenceCandidates(contract, operationRequest, index, operationValidation.arguments),
|
|
346
377
|
};
|
|
@@ -353,7 +384,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
353
384
|
arguments: referenceValidation.requestArguments,
|
|
354
385
|
};
|
|
355
386
|
const validatedArguments = referenceValidation.arguments;
|
|
356
|
-
const wireArguments = origin.origin
|
|
387
|
+
const wireArguments = origin.origin !== "application"
|
|
357
388
|
? validatedRequest.arguments
|
|
358
389
|
: encodeOperationArgumentsForWire(contract, validatedRequest, validatedArguments);
|
|
359
390
|
let fingerprint;
|
|
@@ -366,7 +397,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
366
397
|
});
|
|
367
398
|
}
|
|
368
399
|
catch (error) {
|
|
369
|
-
if (!(error instanceof
|
|
400
|
+
if (!(error instanceof AvCanonicalJsonError)) {
|
|
370
401
|
throw error;
|
|
371
402
|
}
|
|
372
403
|
return {
|
|
@@ -404,6 +435,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
404
435
|
}
|
|
405
436
|
}
|
|
406
437
|
validated.push({
|
|
438
|
+
kind: "operation",
|
|
407
439
|
index: candidate.index,
|
|
408
440
|
request: validatedRequest,
|
|
409
441
|
contract,
|
|
@@ -414,7 +446,7 @@ export async function validateTransactionPlan(dependencies, request, origins, pl
|
|
|
414
446
|
});
|
|
415
447
|
}
|
|
416
448
|
catch (error) {
|
|
417
|
-
if (!(error instanceof
|
|
449
|
+
if (!(error instanceof AvCallerDataError)) {
|
|
418
450
|
throw error;
|
|
419
451
|
}
|
|
420
452
|
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,9 @@
|
|
|
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 { CandidateTransactionOperation, TransactionReferenceSlot, ValidatedTransactionStep } from "./transaction-plan-validator.js";
|
|
6
|
+
type Path = readonly (string | number)[];
|
|
3
7
|
type ReferenceValidationResult = {
|
|
4
8
|
readonly ok: true;
|
|
5
9
|
readonly references: readonly TransactionReferenceSlot[];
|
|
@@ -7,8 +11,34 @@ type ReferenceValidationResult = {
|
|
|
7
11
|
readonly requestArguments: unknown;
|
|
8
12
|
} | {
|
|
9
13
|
readonly ok: false;
|
|
10
|
-
readonly response:
|
|
14
|
+
readonly response: AvOperationFailureResponse;
|
|
11
15
|
};
|
|
16
|
+
/** The `V1016` refusal of a reference's source index, at its `operation` member. */
|
|
17
|
+
export declare function invalidSourceIndexIssue(operationPath: Path): AvValidationIssue;
|
|
18
|
+
/**
|
|
19
|
+
* The validated step a reference names, or `undefined` when its index is no
|
|
20
|
+
* integer naming a step before the referencing one (`V1016`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function referenceSourceAt(earlier: readonly ValidatedTransactionStep[], sourceIndex: unknown, referencingIndex: number): ValidatedTransactionStep | undefined;
|
|
23
|
+
/** The `V1010` refusal of a reference whose source is an `appTx.$sql` step. */
|
|
24
|
+
export declare function sqlSourceIssue(pathPath: Path): AvValidationIssue;
|
|
25
|
+
/** The field a reference reads from its source step, or why it cannot read one. */
|
|
26
|
+
export type ReferenceSourceRead = {
|
|
27
|
+
readonly ok: true;
|
|
28
|
+
readonly field: AvField<AvContract>;
|
|
29
|
+
} | {
|
|
30
|
+
readonly ok: false;
|
|
31
|
+
readonly issue: AvValidationIssue;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Reads the field a reference's one path segment names from its source step,
|
|
35
|
+
* holding the source to what a reference may read: one row (not a `many` or
|
|
36
|
+
* `count` result, not a SQL step's rows), and a field in its actual projection,
|
|
37
|
+
* never a reducer. The field is read under the source's own Contract: in a plan
|
|
38
|
+
* that mixes origins, a source field the referencing step's layer hides is still
|
|
39
|
+
* the source's to read. Assignability to a destination is the caller's.
|
|
40
|
+
*/
|
|
41
|
+
export declare function referenceSourceField(source: ValidatedTransactionStep, segment: string, pathPath: Path): ReferenceSourceRead;
|
|
12
42
|
/** Validates every passive reference candidate before operation fingerprinting. */
|
|
13
|
-
export declare function validateTransactionReferences(operation: CandidateTransactionOperation, earlier: readonly
|
|
43
|
+
export declare function validateTransactionReferences(operation: CandidateTransactionOperation, earlier: readonly ValidatedTransactionStep[]): ReferenceValidationResult;
|
|
14
44
|
export {};
|
|
@@ -164,6 +164,52 @@ function isAssignable(source, destination, shape) {
|
|
|
164
164
|
return source.list && !source.nullable;
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
+
export function invalidSourceIndexIssue(operationPath) {
|
|
168
|
+
return validationIssue("V1016", operationPath, "Transaction reference operation index is invalid.");
|
|
169
|
+
}
|
|
170
|
+
export function referenceSourceAt(earlier, sourceIndex, referencingIndex) {
|
|
171
|
+
if (typeof sourceIndex !== "number" ||
|
|
172
|
+
!Number.isInteger(sourceIndex) ||
|
|
173
|
+
sourceIndex < 0 ||
|
|
174
|
+
sourceIndex >= referencingIndex) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
const source = earlier[sourceIndex];
|
|
178
|
+
return source !== undefined && source.index === sourceIndex
|
|
179
|
+
? source
|
|
180
|
+
: undefined;
|
|
181
|
+
}
|
|
182
|
+
export function sqlSourceIssue(pathPath) {
|
|
183
|
+
return validationIssue("V1010", pathPath, "Transaction reference source is a SQL step, whose rows cannot be referenced.");
|
|
184
|
+
}
|
|
185
|
+
export function referenceSourceField(source, segment, pathPath) {
|
|
186
|
+
if (source.kind === "sql") {
|
|
187
|
+
return { ok: false, issue: sqlSourceIssue(pathPath) };
|
|
188
|
+
}
|
|
189
|
+
if (source.request.variant === "many" || source.request.variant === "count") {
|
|
190
|
+
return {
|
|
191
|
+
ok: false,
|
|
192
|
+
issue: validationIssue("V1010", pathPath, "Transaction reference source has no addressable single-row projection."),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const projection = source.projection;
|
|
196
|
+
if (projection?.reducers.some((reducer) => reducer === segment)) {
|
|
197
|
+
return {
|
|
198
|
+
ok: false,
|
|
199
|
+
issue: validationIssue("V1011", pathPath, "Transaction reference source is not a scalar field."),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const field = projection === undefined || !projection.requested.includes(segment)
|
|
203
|
+
? undefined
|
|
204
|
+
: lookupField(lookupResource(source.contract, projection.resource), segment);
|
|
205
|
+
if (field === undefined) {
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
issue: validationIssue("V1010", pathPath, "Transaction reference path is not present in the source projection."),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return { ok: true, field };
|
|
212
|
+
}
|
|
167
213
|
const CANDIDATE_KEYS = new Set(["$ref"]);
|
|
168
214
|
const REFERENCE_KEYS = new Set(["operation", "fingerprint", "path"]);
|
|
169
215
|
export function validateTransactionReferences(operation, earlier) {
|
|
@@ -188,19 +234,15 @@ export function validateTransactionReferences(operation, earlier) {
|
|
|
188
234
|
return failure(sourceIndexProperty.issue, operation.index);
|
|
189
235
|
}
|
|
190
236
|
const sourceIndex = sourceIndexProperty.value;
|
|
191
|
-
const source =
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
sourceIndex >= operation.index ||
|
|
198
|
-
source === undefined ||
|
|
199
|
-
source.index !== sourceIndex) {
|
|
200
|
-
return failure(validationIssue("V1016", operationPath, "Transaction reference operation index is invalid."), operation.index);
|
|
237
|
+
const source = referenceSourceAt(earlier, sourceIndex, operation.index);
|
|
238
|
+
if (source === undefined) {
|
|
239
|
+
return failure(invalidSourceIndexIssue(operationPath), operation.index);
|
|
240
|
+
}
|
|
241
|
+
if (source.kind === "sql") {
|
|
242
|
+
return failure(sqlSourceIssue([...refPath, "path"]), operation.index);
|
|
201
243
|
}
|
|
202
244
|
const fingerprintPath = [...refPath, "fingerprint"];
|
|
203
|
-
const fingerprintProperty = inspectOwnDataProperty(referenceInspection.value, "fingerprint", fingerprintPath, "
|
|
245
|
+
const fingerprintProperty = inspectOwnDataProperty(referenceInspection.value, "fingerprint", fingerprintPath, "V1000", refPath);
|
|
204
246
|
if (!fingerprintProperty.ok) {
|
|
205
247
|
return failure(fingerprintProperty.issue, operation.index);
|
|
206
248
|
}
|
|
@@ -222,28 +264,18 @@ export function validateTransactionReferences(operation, earlier) {
|
|
|
222
264
|
if (containsUnpairedSurrogate(segment)) {
|
|
223
265
|
return failure(validationIssue("V1010", pathPath, "Transaction reference path contains invalid Unicode."), operation.index);
|
|
224
266
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return failure(
|
|
228
|
-
}
|
|
229
|
-
const projection = source.projection;
|
|
230
|
-
if (projection?.reducers.some((reducer) => reducer === segment)) {
|
|
231
|
-
return failure(validationIssue("V1011", pathPath, "Transaction reference source is not a scalar field."), operation.index);
|
|
232
|
-
}
|
|
233
|
-
if (projection === undefined || !projection.requested.includes(segment)) {
|
|
234
|
-
return failure(validationIssue("V1010", pathPath, "Transaction reference path is not present in the source projection."), operation.index);
|
|
235
|
-
}
|
|
236
|
-
const sourceField = lookupField(lookupResource(source.contract, projection.resource), segment);
|
|
237
|
-
if (sourceField === undefined) {
|
|
238
|
-
return failure(validationIssue("V1010", pathPath, "Transaction reference path is not present in the source projection."), operation.index);
|
|
267
|
+
const sourceRead = referenceSourceField(source, segment, pathPath);
|
|
268
|
+
if (!sourceRead.ok) {
|
|
269
|
+
return failure(sourceRead.issue, operation.index);
|
|
239
270
|
}
|
|
271
|
+
const sourceField = sourceRead.field;
|
|
240
272
|
if (sourceField.kind !== "scalar" ||
|
|
241
273
|
!isAssignable(sourceField, slot.field, slot.shape)) {
|
|
242
274
|
return failure(validationIssue("V1011", pathPath, "Transaction reference source type is not assignable to its destination."), operation.index);
|
|
243
275
|
}
|
|
244
276
|
const reference = Object.freeze({
|
|
245
277
|
$ref: Object.freeze({
|
|
246
|
-
operation:
|
|
278
|
+
operation: source.index,
|
|
247
279
|
fingerprint,
|
|
248
280
|
path: Object.freeze([segment]),
|
|
249
281
|
}),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvWriteScope } from "../contracts/capability.js";
|
|
2
|
+
import type { AvContract } from "../contracts/contract.js";
|
|
3
3
|
import type { ScalarForms } from "../contracts/scalar-value-type.js";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { AvCreateDataInput, AvOperationArgumentsFor, AvResourceKey, AvUpdateDataInput } from "../operations/operation-arguments.js";
|
|
5
|
+
import type { AvOperationIdentity } from "../operations/operation-identity.js";
|
|
6
6
|
import type { OperationFingerprint } from "./deferred-operation.js";
|
|
7
7
|
declare const REFERENCE_VALUE: unique symbol;
|
|
8
8
|
/** Any object with a `$ref` key, before it is validated as a reference. */
|
|
@@ -13,7 +13,7 @@ export type TransactionReferenceCandidate = {
|
|
|
13
13
|
* A reference to a field of an earlier operation's result in the same
|
|
14
14
|
* transaction plan: `{ $ref: { operation, fingerprint, path } }`.
|
|
15
15
|
*/
|
|
16
|
-
export type
|
|
16
|
+
export type AvTransactionReference<Value = unknown> = {
|
|
17
17
|
readonly $ref: {
|
|
18
18
|
readonly operation: number;
|
|
19
19
|
readonly fingerprint: OperationFingerprint;
|
|
@@ -38,12 +38,12 @@ export declare function routeTransactionReferenceCandidate(value: unknown): Tran
|
|
|
38
38
|
/** Whether `value` is an object with a `$ref` key; it is not validated here. */
|
|
39
39
|
export declare function isTransactionReferenceCandidate(value: unknown): value is TransactionReferenceCandidate;
|
|
40
40
|
/** Whether `value` is a complete `$ref` object. */
|
|
41
|
-
export declare function isTransactionReferenceObject(value: unknown): value is
|
|
41
|
+
export declare function isTransactionReferenceObject(value: unknown): value is AvTransactionReference;
|
|
42
42
|
/**
|
|
43
43
|
* A scalar mutation value inside a plan: the value itself, or a reference to an
|
|
44
44
|
* earlier operation's field of that same type.
|
|
45
45
|
*/
|
|
46
|
-
export type TransactionScalarValue<Value> = Value |
|
|
46
|
+
export type TransactionScalarValue<Value> = Value | AvTransactionReference<Value>;
|
|
47
47
|
/**
|
|
48
48
|
* What a Transaction Slot holds of its destination field, which decides the source
|
|
49
49
|
* fields a reference there accepts — always the same scalar or enum, no coercion:
|
|
@@ -62,16 +62,16 @@ export type TransactionSlotShape = "value" | "nonNullValue" | "entry" | "entries
|
|
|
62
62
|
/**
|
|
63
63
|
* Create data inside a transaction plan, at one write position: its scalar values
|
|
64
64
|
* and the unique keys its relation directives name may hold a `$ref`. The default
|
|
65
|
-
* is the unrestricted position, as on `
|
|
65
|
+
* is the unrestricted position, as on `AvCreateDataInput`.
|
|
66
66
|
*/
|
|
67
|
-
export type TransactionCreateDataInput<C extends
|
|
67
|
+
export type TransactionCreateDataInput<C extends AvContract, K extends AvResourceKey<C>, Scope extends AvWriteScope = "nested"> = AvCreateDataInput<C, K, Scope, ScalarForms, ScalarForms>;
|
|
68
68
|
/** Update data inside a transaction plan. See {@link TransactionCreateDataInput}. */
|
|
69
|
-
export type TransactionUpdateDataInput<C extends
|
|
69
|
+
export type TransactionUpdateDataInput<C extends AvContract, K extends AvResourceKey<C>, Scope extends AvWriteScope = "nested"> = AvUpdateDataInput<C, K, Scope, ScalarForms, ScalarForms>;
|
|
70
70
|
/**
|
|
71
71
|
* Operation arguments inside a transaction plan, under one value form and one
|
|
72
|
-
* reference form: `
|
|
72
|
+
* reference form: `AvOperationArgumentsFor` with its reference positions opened.
|
|
73
73
|
*/
|
|
74
|
-
export type ReferenceableArgumentsFor<C extends
|
|
74
|
+
export type ReferenceableArgumentsFor<C extends AvContract, K extends AvResourceKey<C>, I extends AvOperationIdentity, Forms extends ScalarForms, ReferenceForms extends ScalarForms> = AvOperationArgumentsFor<C, K, I, Forms, ReferenceForms>;
|
|
75
75
|
/** Operation arguments inside a transaction plan, no scalar form stated. */
|
|
76
|
-
export type TransactionOperationArgumentsFor<C extends
|
|
76
|
+
export type TransactionOperationArgumentsFor<C extends AvContract, K extends AvResourceKey<C>, I extends AvOperationIdentity> = ReferenceableArgumentsFor<C, K, I, ScalarForms, ScalarForms>;
|
|
77
77
|
export {};
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { ClientProtocolIdentity } from "../runtime/operation-request.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AvTransportContext } from "../runtime/pipeline.js";
|
|
3
|
+
import type { AvState } from "../runtime/request-state.js";
|
|
3
4
|
type TransactionRequestBase = {
|
|
4
5
|
readonly requestId: string;
|
|
5
6
|
readonly plan: unknown;
|
|
7
|
+
/**
|
|
8
|
+
* The run's `ctx.$state`: every step's stages and the transaction stages share
|
|
9
|
+
* this one object. Omitted, it is a fresh `{}`.
|
|
10
|
+
*/
|
|
11
|
+
readonly state?: AvState;
|
|
6
12
|
};
|
|
7
13
|
/** An in-process transaction request, run under the Application Contract. */
|
|
8
14
|
export type ApplicationTransactionRequest = TransactionRequestBase & {
|
|
@@ -14,13 +20,20 @@ export type ApplicationTransactionRequest = TransactionRequestBase & {
|
|
|
14
20
|
export type ClientTransactionRequest = TransactionRequestBase & {
|
|
15
21
|
readonly origin: "client";
|
|
16
22
|
readonly protocol: ClientProtocolIdentity;
|
|
17
|
-
readonly transport?:
|
|
23
|
+
readonly transport?: AvTransportContext;
|
|
24
|
+
};
|
|
25
|
+
/** An AI agent's transaction request, run under the Agent Contract. */
|
|
26
|
+
export type AgentTransactionRequest = TransactionRequestBase & {
|
|
27
|
+
readonly origin: "agent";
|
|
28
|
+
readonly protocol: ClientProtocolIdentity;
|
|
29
|
+
readonly transport?: AvTransportContext;
|
|
18
30
|
};
|
|
19
31
|
/** One transaction request, as `framework.executeTransaction` takes it. */
|
|
20
|
-
export type FrameworkTransactionRequest = ApplicationTransactionRequest | ClientTransactionRequest;
|
|
32
|
+
export type FrameworkTransactionRequest = ApplicationTransactionRequest | ClientTransactionRequest | AgentTransactionRequest;
|
|
21
33
|
/**
|
|
22
34
|
* The origin one plan operation runs under: its own layer's Contract, its own
|
|
23
|
-
* pipelines, and — for a client step — the protocol identity it is
|
|
35
|
+
* pipelines, and — for a client or agent step — the protocol identity it is
|
|
36
|
+
* accepted with.
|
|
24
37
|
*/
|
|
25
|
-
export type TransactionOperationOrigin = Pick<ApplicationTransactionRequest, "origin"> | Pick<ClientTransactionRequest, "origin" | "protocol" | "transport">;
|
|
38
|
+
export type TransactionOperationOrigin = Pick<ApplicationTransactionRequest, "origin"> | Pick<ClientTransactionRequest, "origin" | "protocol" | "transport"> | Pick<AgentTransactionRequest, "origin" | "protocol" | "transport">;
|
|
26
39
|
export {};
|