@aventara/core 1.0.0-rc.4 → 1.0.0-rc.8
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 +101 -0
- package/ERRORS.md +1 -1
- package/README.md +5 -1
- package/dist/adapters/adapter-field.d.ts +8 -0
- package/dist/adapters/adapter-identifier.d.ts +9 -0
- package/dist/adapters/adapter-identifier.js +6 -1
- package/dist/adapters/adapter-operation.d.ts +12 -6
- package/dist/compiler/contract.compiler.js +26 -3
- package/dist/config/framework-config.d.ts +5 -1
- package/dist/contracts/contract.d.ts +15 -1
- package/dist/contracts/field.d.ts +17 -0
- package/dist/contracts/scalar-value-type.d.ts +3 -1
- package/dist/framework/framework-construction.error.d.ts +2 -1
- package/dist/framework/framework-construction.error.js +11 -1
- package/dist/framework/framework.d.ts +4 -4
- package/dist/framework/operation-facade.d.ts +6 -6
- package/dist/index.d.ts +6 -3
- package/dist/internal.d.ts +1 -2
- package/dist/internal.js +1 -0
- package/dist/operations/operation-arguments.d.ts +43 -27
- package/dist/operations/operation-call.d.ts +2 -2
- package/dist/operations/operation-result.d.ts +1 -1
- package/dist/policy/policy-admission.js +12 -3
- package/dist/policy/policy-after-update.runtime.js +5 -4
- package/dist/policy/policy-engine.d.ts +11 -4
- package/dist/policy/policy-nested-write.runtime.js +11 -7
- package/dist/policy/policy-read.runtime.d.ts +0 -2
- package/dist/policy/policy-read.runtime.js +18 -9
- package/dist/policy/policy-request.d.ts +7 -3
- package/dist/policy/policy-request.js +14 -3
- package/dist/policy/policy-session.d.ts +14 -4
- package/dist/policy/policy-session.js +12 -11
- package/dist/policy/policy-startup.validator.js +3 -5
- package/dist/policy/policy-write.runtime.d.ts +7 -0
- package/dist/policy/policy-write.runtime.js +23 -8
- package/dist/prebuilt/core-version.generated.d.ts +1 -1
- package/dist/prebuilt/core-version.generated.js +1 -1
- package/dist/prebuilt/prebuilt-changes.d.ts +28 -0
- package/dist/prebuilt/prebuilt-changes.js +65 -0
- package/dist/prebuilt/prebuilt-contracts.loader.js +11 -56
- package/dist/protocol/absent-route.responder.d.ts +4 -4
- package/dist/protocol/http-request.decoder.d.ts +2 -2
- package/dist/protocol/http-request.reader.d.ts +2 -2
- package/dist/protocol/protocol-headers.d.ts +3 -3
- package/dist/runtime/computed-read-runtime.js +2 -7
- package/dist/runtime/context-executor.runtime.d.ts +2 -2
- package/dist/runtime/create-requirement.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +5 -5
- package/dist/runtime/operation-request.d.ts +9 -9
- package/dist/runtime/operation-runtime.d.ts +8 -8
- package/dist/runtime/operation-runtime.js +30 -9
- package/dist/runtime/owned-execution.registry.d.ts +2 -2
- package/dist/runtime/referential-action.d.ts +1 -1
- package/dist/transactions/sql-statement.d.ts +2 -2
- package/dist/transactions/transaction-plan-assembler.d.ts +2 -2
- package/dist/transactions/transaction-plan-validator.d.ts +5 -5
- package/dist/transactions/transaction-request.d.ts +8 -8
- package/dist/transactions/transaction-runtime.d.ts +2 -2
- package/dist/transactions/transaction-runtime.js +12 -7
- package/package.json +1 -1
|
@@ -8,14 +8,14 @@ import type { AvRequestOrigin, RemoteRequestOrigin } from "../config/config-laye
|
|
|
8
8
|
import type { AvContract } from "../contracts/contract.js";
|
|
9
9
|
import type { OperationValidationOptions, SemanticOperationArguments } from "../operations/operation-validator.js";
|
|
10
10
|
import { type PolicyCaller } from "../policy/policy-request.js";
|
|
11
|
-
import type {
|
|
11
|
+
import type { AvTransactionRequest } from "../transactions/transaction-request.js";
|
|
12
12
|
import { type ArgumentsSource } from "./caller-data.door.js";
|
|
13
13
|
import { type ContextExecutor, type ExecutorScope } from "./context-executor.runtime.js";
|
|
14
14
|
import { type RecordWriteFacts } from "./create-requirement.js";
|
|
15
15
|
import { type DiagnosticsReporter } from "./diagnostics-reporter.js";
|
|
16
16
|
import { type OuterFailureLayer } from "./error-boundary.js";
|
|
17
17
|
import { type FieldStagePlan } from "./field-stage.plan.js";
|
|
18
|
-
import type {
|
|
18
|
+
import type { AvOperationRequest, AvRequestProtocol, StatefulOperationRequest } from "./operation-request.js";
|
|
19
19
|
import type { AvOperationFailureResponse, AvOperationResponse } from "./operation-response.js";
|
|
20
20
|
import type { AvState } from "./request-state.js";
|
|
21
21
|
import { type NormalizationWrite } from "./scalar-runtime.js";
|
|
@@ -70,7 +70,7 @@ export declare function withRequestState<Request extends {
|
|
|
70
70
|
* `request` with its policy session when the policy checks it, or the failure
|
|
71
71
|
* deriving its principal answered.
|
|
72
72
|
*/
|
|
73
|
-
export declare function withRequestPolicy<M extends AvAdapterModel>(dependencies: Pick<OperationRuntimeDependencies<M>, "adapter" | "config" | "contracts">, request: StatefulOperationRequest, caller: PolicyCaller | undefined, report: DiagnosticsReporter): StatefulOperationRequest | AvOperationFailureResponse
|
|
73
|
+
export declare function withRequestPolicy<M extends AvAdapterModel>(dependencies: Pick<OperationRuntimeDependencies<M>, "adapter" | "config" | "contracts">, request: StatefulOperationRequest, caller: PolicyCaller | undefined, report: DiagnosticsReporter): StatefulOperationRequest | AvOperationFailureResponse | Promise<StatefulOperationRequest | AvOperationFailureResponse>;
|
|
74
74
|
/**
|
|
75
75
|
* Builds what every operation's pipeline shares, the ctx executor included: its
|
|
76
76
|
* raw calls run the application's operation path with every developer stage
|
|
@@ -85,15 +85,15 @@ export declare function createPipelineDependencies<M extends AvAdapterModel>(dep
|
|
|
85
85
|
* request's arguments are the caller's own objects, copied at the door, or data
|
|
86
86
|
* no caller holds (see {@link ArgumentsSource}).
|
|
87
87
|
*/
|
|
88
|
-
export type FrameworkOperationExecutor = (request:
|
|
88
|
+
export type FrameworkOperationExecutor = (request: AvOperationRequest, report: DiagnosticsReporter, source: ArgumentsSource,
|
|
89
89
|
/** The principal an application call runs as (`{ as }`), when it names one. */
|
|
90
90
|
caller?: PolicyCaller) => Promise<AvOperationResponse>;
|
|
91
91
|
/** Selects the Contract of the request's origin. */
|
|
92
|
-
export declare function activeContract(contracts: AvContracts, request:
|
|
92
|
+
export declare function activeContract(contracts: AvContracts, request: AvOperationRequest | AvTransactionRequest): AvContract;
|
|
93
93
|
/** Creates the transport-independent operation executor owned by core. */
|
|
94
94
|
export declare function createOperationRuntime<M extends AvAdapterModel>(dependencies: OperationRuntimeDependencies<M>, pipelineDependencies: OperationPipelineDependencies<M>): FrameworkOperationExecutor;
|
|
95
95
|
/** Validates the request-level protocol identity. */
|
|
96
|
-
export declare function validateProtocolIdentity(contracts: AvContracts, request:
|
|
96
|
+
export declare function validateProtocolIdentity(contracts: AvContracts, request: AvOperationRequest | AvTransactionRequest): AvOperationFailureResponse | undefined;
|
|
97
97
|
/**
|
|
98
98
|
* The stale-client check on one remote protocol identity: the protocol version first
|
|
99
99
|
* (`A2006`), then the hash of the origin's Contract (`A2005`): the ClientContract's
|
|
@@ -102,7 +102,7 @@ export declare function validateProtocolIdentity(contracts: AvContracts, request
|
|
|
102
102
|
* (`@aventara/core/protocol`) call it too, so a stale client hears the same envelope
|
|
103
103
|
* whichever layer answers.
|
|
104
104
|
*/
|
|
105
|
-
export declare function protocolIdentityFailure(contracts: AvContracts, protocol:
|
|
105
|
+
export declare function protocolIdentityFailure(contracts: AvContracts, protocol: AvRequestProtocol, origin: RemoteRequestOrigin): AvOperationFailureResponse | undefined;
|
|
106
106
|
export type ValidatedOperationArguments = {
|
|
107
107
|
readonly ok: true;
|
|
108
108
|
readonly arguments: SemanticOperationArguments;
|
|
@@ -111,7 +111,7 @@ export type ValidatedOperationArguments = {
|
|
|
111
111
|
readonly response: AvOperationFailureResponse;
|
|
112
112
|
};
|
|
113
113
|
/** Validates one operation's arguments through the Framework Validation Layer. */
|
|
114
|
-
export declare function validateOperationRequest(contract: AvContract, request:
|
|
114
|
+
export declare function validateOperationRequest(contract: AvContract, request: AvOperationRequest, options?: OperationValidationOptions, write?: NormalizationWrite): ValidatedOperationArguments;
|
|
115
115
|
/** The subject a refused output of an operation's pipes is reported under at a plan step. */
|
|
116
116
|
export declare const STEP_PIPES = "Pipes";
|
|
117
117
|
/**
|
|
@@ -44,13 +44,19 @@ export function withRequestState(request) {
|
|
|
44
44
|
return { ...request, state: requestStateOf(request.state) };
|
|
45
45
|
}
|
|
46
46
|
export function withRequestPolicy(dependencies, request, caller, report) {
|
|
47
|
+
const failed = (error) => {
|
|
48
|
+
report(error, "A3000");
|
|
49
|
+
return internalFailure();
|
|
50
|
+
};
|
|
51
|
+
const withPolicy = (policy) => policy === undefined ? request : { ...request, policy };
|
|
47
52
|
try {
|
|
48
53
|
const policy = openRequestPolicy(dependencies.config.policy, dependencies.contracts.core, request, caller, dependencies.adapter);
|
|
49
|
-
return policy
|
|
54
|
+
return policy instanceof Promise
|
|
55
|
+
? policy.then(withPolicy, failed)
|
|
56
|
+
: withPolicy(policy);
|
|
50
57
|
}
|
|
51
58
|
catch (error) {
|
|
52
|
-
|
|
53
|
-
return internalFailure();
|
|
59
|
+
return failed(error);
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
export function createPipelineDependencies(dependencies, model) {
|
|
@@ -197,7 +203,8 @@ export function createOperationRuntime(dependencies, pipelineDependencies) {
|
|
|
197
203
|
if (!validated.ok) {
|
|
198
204
|
return validated.response;
|
|
199
205
|
}
|
|
200
|
-
const
|
|
206
|
+
const opened = withRequestPolicy(dependencies, withRequestState(request), caller, report);
|
|
207
|
+
const stateful = opened instanceof Promise ? await opened : opened;
|
|
201
208
|
if (!("state" in stateful)) {
|
|
202
209
|
return stateful;
|
|
203
210
|
}
|
|
@@ -612,8 +619,10 @@ export async function executeAdmittedOperation(dependencies, request, contract,
|
|
|
612
619
|
let operation = request;
|
|
613
620
|
let settle;
|
|
614
621
|
let writeMiss;
|
|
622
|
+
let failedWriteMiss;
|
|
615
623
|
if (policyWrite !== undefined && policyWrite.kind !== "refused") {
|
|
616
624
|
writeMiss = policyWrite.miss;
|
|
625
|
+
failedWriteMiss = policyWrite.failedMiss;
|
|
617
626
|
if (policyWrite.kind === "empty") {
|
|
618
627
|
if (writeMiss !== undefined && policyWrite.data === null) {
|
|
619
628
|
refuseWrite(await writeMiss());
|
|
@@ -643,11 +652,23 @@ export async function executeAdmittedOperation(dependencies, request, contract,
|
|
|
643
652
|
settle = read.settle;
|
|
644
653
|
}
|
|
645
654
|
const { policy: _session, ...identity } = operation;
|
|
646
|
-
let adapterData
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
655
|
+
let adapterData;
|
|
656
|
+
try {
|
|
657
|
+
adapterData = await adapterBoundary.execute(() => executor.execute({
|
|
658
|
+
...identity,
|
|
659
|
+
resource: request.resource,
|
|
660
|
+
arguments: adapterArguments,
|
|
661
|
+
}));
|
|
662
|
+
}
|
|
663
|
+
catch (error) {
|
|
664
|
+
const missed = failedWriteMiss === undefined
|
|
665
|
+
? undefined
|
|
666
|
+
: await failedWriteMiss().catch(() => undefined);
|
|
667
|
+
if (missed !== undefined) {
|
|
668
|
+
refuseWrite(missed);
|
|
669
|
+
}
|
|
670
|
+
throw error;
|
|
671
|
+
}
|
|
651
672
|
if (writeMiss !== undefined && adapterData === null) {
|
|
652
673
|
refuseWrite(await writeMiss());
|
|
653
674
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvAgentTransactionRequest, AvClientTransactionRequest } from "../transactions/transaction-request.js";
|
|
2
2
|
import type { AvTransactionResponse } from "../transactions/transaction-response.js";
|
|
3
3
|
import type { AvCallerDataError } from "./caller-data.copier.js";
|
|
4
4
|
import type { RemoteOperationRequest } from "./operation-request.js";
|
|
@@ -15,7 +15,7 @@ export type OwnedExecution = {
|
|
|
15
15
|
* at the call, and these steps' arguments could not be copied there: each is
|
|
16
16
|
* answered at its turn as the door answers that failure.
|
|
17
17
|
*/
|
|
18
|
-
readonly executeTransaction: (request:
|
|
18
|
+
readonly executeTransaction: (request: AvClientTransactionRequest | AvAgentTransactionRequest, refused?: ReadonlyMap<number, AvCallerDataError>) => Promise<AvTransactionResponse>;
|
|
19
19
|
};
|
|
20
20
|
/** Records `framework`'s owned entries; called once, at construction. */
|
|
21
21
|
export declare function recordOwnedExecution(framework: object, execution: OwnedExecution): void;
|
|
@@ -29,7 +29,7 @@ export type ReferentialEdge = {
|
|
|
29
29
|
* relation `field` and any of these names the reference twice and is refused;
|
|
30
30
|
* a required relation may be written through all of them instead.
|
|
31
31
|
*/
|
|
32
|
-
readonly
|
|
32
|
+
readonly referenceFields: readonly string[];
|
|
33
33
|
/** What deleting a `target` row does to rows of the ENCLOSING Resource. */
|
|
34
34
|
readonly onDelete: ReferentialDeleteEffect;
|
|
35
35
|
};
|
|
@@ -10,7 +10,7 @@ import type { AvTransactionReference } from "./transaction-reference.js";
|
|
|
10
10
|
* `${value}::jsonb`), or a `$ref` to an earlier step's field, resolved when the
|
|
11
11
|
* earlier steps have run and then bound like any other value.
|
|
12
12
|
*/
|
|
13
|
-
export type
|
|
13
|
+
export type AvSqlStatementValue = AvAdapterSqlValue | AvTransactionReference;
|
|
14
14
|
/**
|
|
15
15
|
* `framework.appTx.$sql`: a developer SQL step, written only as a tagged template —
|
|
16
16
|
* ``framework.appTx.$sql`select pgmq.send('jobs', jsonb_build_object('id', ${ref}))` ``.
|
|
@@ -23,7 +23,7 @@ export type SqlStatementValue = AvAdapterSqlValue | AvTransactionReference;
|
|
|
23
23
|
* SQL step's rows. No guard, pipe, hook, interceptor or filter runs around it: it
|
|
24
24
|
* has no Resource or operation for one to wrap.
|
|
25
25
|
*/
|
|
26
|
-
export type
|
|
26
|
+
export type AvSqlStatementBuilder = <Row = unknown>(strings: TemplateStringsArray, ...values: readonly AvSqlStatementValue[]) => AvOperation<Row[], "application">;
|
|
27
27
|
/** One value of a planned SQL step, as the typed runner bound it. */
|
|
28
28
|
export type PlannedSqlValue = {
|
|
29
29
|
readonly kind: "value";
|
|
@@ -2,7 +2,7 @@ import type { AvContracts } from "../compiler/contract.compiler.js";
|
|
|
2
2
|
import type { AvOperationIdentity } from "../operations/operation-identity.js";
|
|
3
3
|
import { AvCallerDataError } from "../runtime/caller-data.copier.js";
|
|
4
4
|
import type { MisuseReporter } from "../runtime/misuse-reporter.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { AvRequestProtocol } from "../runtime/operation-request.js";
|
|
6
6
|
import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
|
|
7
7
|
import type { AvOperation, OperationFingerprint } from "./deferred-operation.js";
|
|
8
8
|
import type { PlannedSqlStatement } from "./sql-statement.js";
|
|
@@ -49,5 +49,5 @@ export type TransactionPlanAssembler = {
|
|
|
49
49
|
* handle, so a handle another instance built — typed against another model,
|
|
50
50
|
* bound to other Contracts — is refused rather than run.
|
|
51
51
|
*/
|
|
52
|
-
export declare function createTransactionPlanAssembler(contracts: AvContracts, protocol:
|
|
52
|
+
export declare function createTransactionPlanAssembler(contracts: AvContracts, protocol: AvRequestProtocol, misuse: MisuseReporter): TransactionPlanAssembler;
|
|
53
53
|
export {};
|
|
@@ -4,7 +4,7 @@ import type { AvScalarField } from "../contracts/field.js";
|
|
|
4
4
|
import type { SemanticOperationArguments } from "../operations/operation-validator.js";
|
|
5
5
|
import { AvCallerDataError } from "../runtime/caller-data.copier.js";
|
|
6
6
|
import { type ReadProjectionPlan } from "../runtime/computed-read-runtime.js";
|
|
7
|
-
import type {
|
|
7
|
+
import type { AvOperationRequest } from "../runtime/operation-request.js";
|
|
8
8
|
import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
|
|
9
9
|
import type { OperationPipelineDependencies } from "../runtime/operation-runtime.js";
|
|
10
10
|
import type { CascadeClosure } from "../runtime/referential-action.js";
|
|
@@ -13,7 +13,7 @@ import type { PlannedSqlStatement, ValidatedSqlStatement } from "./sql-statement
|
|
|
13
13
|
import type { AvTransactionReference } from "./transaction-reference.js";
|
|
14
14
|
import { type TransactionSlotShape } from "./transaction-reference.js";
|
|
15
15
|
import { type TransactionReferenceCandidateSlot } from "./transaction-reference-collector.js";
|
|
16
|
-
import type {
|
|
16
|
+
import type { AvTransactionRequest, TransactionOperationOrigin } from "./transaction-request.js";
|
|
17
17
|
/**
|
|
18
18
|
* Where a plan's step arguments came from, so the validator knows whether to copy
|
|
19
19
|
* them at the door (see `ArgumentsSource`):
|
|
@@ -65,7 +65,7 @@ export type TransactionReferenceSlot = {
|
|
|
65
65
|
};
|
|
66
66
|
export type CandidateTransactionOperation = {
|
|
67
67
|
readonly index: number;
|
|
68
|
-
readonly request:
|
|
68
|
+
readonly request: AvOperationRequest;
|
|
69
69
|
readonly arguments: SemanticOperationArguments;
|
|
70
70
|
readonly projection: ReadProjectionPlan | undefined;
|
|
71
71
|
readonly declaredFingerprint: unknown;
|
|
@@ -74,7 +74,7 @@ export type CandidateTransactionOperation = {
|
|
|
74
74
|
export type ValidatedTransactionOperation = {
|
|
75
75
|
readonly kind: "operation";
|
|
76
76
|
readonly index: number;
|
|
77
|
-
readonly request:
|
|
77
|
+
readonly request: AvOperationRequest;
|
|
78
78
|
/**
|
|
79
79
|
* The Contract of this operation's origin, which is the plan's: the one it was
|
|
80
80
|
* validated against, the one it runs under, and the one a later `$ref` reads its
|
|
@@ -118,4 +118,4 @@ export declare function transactionsUnavailableFailure(): AvOperationFailureResp
|
|
|
118
118
|
/**
|
|
119
119
|
* Whole-plan Framework Validation Layer for transaction structure and identity.
|
|
120
120
|
*/
|
|
121
|
-
export declare function validateTransactionPlan<M extends AvAdapterModel>(dependencies: TransactionPlanDependencies<M>, request:
|
|
121
|
+
export declare function validateTransactionPlan<M extends AvAdapterModel>(dependencies: TransactionPlanDependencies<M>, request: AvTransactionRequest, origins?: readonly TransactionOperationOrigin[], planArguments?: PlanArguments): Promise<TransactionPlanValidationResult>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AvRequestProtocol } from "../runtime/operation-request.js";
|
|
2
2
|
import type { AvTransportContext } from "../runtime/pipeline.js";
|
|
3
3
|
import type { AvState } from "../runtime/request-state.js";
|
|
4
4
|
type TransactionRequestBase = {
|
|
@@ -11,29 +11,29 @@ type TransactionRequestBase = {
|
|
|
11
11
|
readonly state?: AvState;
|
|
12
12
|
};
|
|
13
13
|
/** An in-process transaction request, run under the Application Contract. */
|
|
14
|
-
export type
|
|
14
|
+
export type AvApplicationTransactionRequest = TransactionRequestBase & {
|
|
15
15
|
readonly origin: "application";
|
|
16
16
|
readonly protocol?: never;
|
|
17
17
|
readonly transport?: never;
|
|
18
18
|
};
|
|
19
19
|
/** A remote transaction request, run under the Client Contract. */
|
|
20
|
-
export type
|
|
20
|
+
export type AvClientTransactionRequest = TransactionRequestBase & {
|
|
21
21
|
readonly origin: "client";
|
|
22
|
-
readonly protocol:
|
|
22
|
+
readonly protocol: AvRequestProtocol;
|
|
23
23
|
readonly transport?: AvTransportContext;
|
|
24
24
|
};
|
|
25
25
|
/** An AI agent's transaction request, run under the Agent Contract. */
|
|
26
|
-
export type
|
|
26
|
+
export type AvAgentTransactionRequest = TransactionRequestBase & {
|
|
27
27
|
readonly origin: "agent";
|
|
28
|
-
readonly protocol:
|
|
28
|
+
readonly protocol: AvRequestProtocol;
|
|
29
29
|
readonly transport?: AvTransportContext;
|
|
30
30
|
};
|
|
31
31
|
/** One transaction request, as `framework.executeTransaction` takes it. */
|
|
32
|
-
export type
|
|
32
|
+
export type AvTransactionRequest = AvApplicationTransactionRequest | AvClientTransactionRequest | AvAgentTransactionRequest;
|
|
33
33
|
/**
|
|
34
34
|
* The origin one plan operation runs under: its own layer's Contract, its own
|
|
35
35
|
* pipelines, and — for a client or agent step — the protocol identity it is
|
|
36
36
|
* accepted with.
|
|
37
37
|
*/
|
|
38
|
-
export type TransactionOperationOrigin = Pick<
|
|
38
|
+
export type TransactionOperationOrigin = Pick<AvApplicationTransactionRequest, "origin"> | Pick<AvClientTransactionRequest, "origin" | "protocol" | "transport"> | Pick<AvAgentTransactionRequest, "origin" | "protocol" | "transport">;
|
|
39
39
|
export {};
|
|
@@ -3,7 +3,7 @@ import { type PolicyCaller } from "../policy/policy-request.js";
|
|
|
3
3
|
import type { TransactionDiagnosticsChannel } from "../runtime/diagnostics-reporter.js";
|
|
4
4
|
import type { OperationPipelineDependencies, OperationRuntimeDependencies } from "../runtime/operation-runtime.js";
|
|
5
5
|
import type { PlanArguments } from "./transaction-plan-validator.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { AvTransactionRequest, TransactionOperationOrigin } from "./transaction-request.js";
|
|
7
7
|
import type { AvTransactionResponse } from "./transaction-response.js";
|
|
8
8
|
/**
|
|
9
9
|
* The transaction executor core. Like the operation executor it owns no
|
|
@@ -14,7 +14,7 @@ import type { AvTransactionResponse } from "./transaction-response.js";
|
|
|
14
14
|
* runner's mixed plans), and `planArguments` whether the steps' arguments are
|
|
15
15
|
* copied at the door; see `validateTransactionPlan`.
|
|
16
16
|
*/
|
|
17
|
-
export type FrameworkTransactionExecutor = (request:
|
|
17
|
+
export type FrameworkTransactionExecutor = (request: AvTransactionRequest, diagnostics: TransactionDiagnosticsChannel, origins: readonly TransactionOperationOrigin[] | undefined, planArguments: PlanArguments,
|
|
18
18
|
/** The principal an application run's steps run as (`{ as }`), when it names one. */
|
|
19
19
|
caller?: PolicyCaller) => Promise<AvTransactionResponse>;
|
|
20
20
|
/**
|
|
@@ -88,12 +88,15 @@ async function executeTransactionPlan(runtime, dependencies, request, plan, stat
|
|
|
88
88
|
if (known !== undefined) {
|
|
89
89
|
return known;
|
|
90
90
|
}
|
|
91
|
+
const settle = (policy) => {
|
|
92
|
+
const step = policy === undefined
|
|
93
|
+
? { ...operation.request, state }
|
|
94
|
+
: { ...operation.request, state, policy };
|
|
95
|
+
steps.set(operation, step);
|
|
96
|
+
return step;
|
|
97
|
+
};
|
|
91
98
|
const policy = openRequestPolicy(runtime.config.policy, runtime.contracts.core, { origin: operation.request.origin, state }, caller, adapter);
|
|
92
|
-
|
|
93
|
-
? { ...operation.request, state }
|
|
94
|
-
: { ...operation.request, state, policy };
|
|
95
|
-
steps.set(operation, step);
|
|
96
|
-
return step;
|
|
99
|
+
return policy instanceof Promise ? policy.then(settle) : settle(policy);
|
|
97
100
|
};
|
|
98
101
|
const admitted = [];
|
|
99
102
|
const standing = [];
|
|
@@ -106,7 +109,8 @@ async function executeTransactionPlan(runtime, dependencies, request, plan, stat
|
|
|
106
109
|
const report = diagnostics.operation(step.request, step.index);
|
|
107
110
|
let stepRequest;
|
|
108
111
|
try {
|
|
109
|
-
|
|
112
|
+
const opened = stateful(step);
|
|
113
|
+
stepRequest = opened instanceof Promise ? await opened : opened;
|
|
110
114
|
}
|
|
111
115
|
catch (error) {
|
|
112
116
|
report(error, "A3000");
|
|
@@ -140,7 +144,8 @@ async function executeTransactionPlan(runtime, dependencies, request, plan, stat
|
|
|
140
144
|
const runPlanOperation = async (operation, args, transactionPiped, executor, results, outer) => {
|
|
141
145
|
const report = diagnostics.operation(operation.request, operation.index);
|
|
142
146
|
const argumentsPath = planOperationArgumentsPath(operation.index);
|
|
143
|
-
const
|
|
147
|
+
const opened = stateful(operation);
|
|
148
|
+
const stepRequest = opened instanceof Promise ? await opened : opened;
|
|
144
149
|
try {
|
|
145
150
|
let live = standing[operation.index] ?? operation.references;
|
|
146
151
|
if (transactionPiped) {
|