@aventara/core 1.0.0-rc.1 → 1.0.0-rc.11
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 +1022 -16
- package/ERRORS.md +142 -0
- package/README.md +330 -16
- 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 +22 -0
- package/dist/adapters/adapter-identifier.d.ts +9 -0
- package/dist/adapters/adapter-identifier.js +6 -1
- package/dist/adapters/adapter-model.d.ts +9 -0
- package/dist/adapters/adapter-operation.d.ts +18 -3
- package/dist/adapters/adapter-resource.d.ts +5 -0
- package/dist/adapters/adapter.interface.d.ts +10 -0
- package/dist/avz/avz.d.ts +1 -1
- package/dist/avz/json-shape.registry.d.ts +2 -1
- 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 +6 -0
- package/dist/compiler/contract.compiler.js +281 -31
- package/dist/compiler/create-requirements.projector.js +1 -3
- package/dist/compiler/field-validator.compiler.js +1 -3
- package/dist/compiler/managed-elsewhere.projector.d.ts +52 -0
- package/dist/compiler/managed-elsewhere.projector.js +179 -0
- package/dist/compiler/managed-elsewhere.validator.d.ts +9 -0
- package/dist/compiler/managed-elsewhere.validator.js +74 -0
- package/dist/config/cache-stage.factory.d.ts +24 -0
- package/dist/config/cache-stage.factory.js +3 -0
- package/dist/config/computed-fields.d.ts +62 -0
- package/dist/config/computed-fields.js +73 -0
- package/dist/config/config-diagnostic.guidance.d.ts +6 -0
- package/dist/config/config-diagnostic.guidance.js +32 -0
- package/dist/config/config.resolver.d.ts +24 -0
- package/dist/config/config.resolver.js +66 -7
- package/dist/config/config.validator.js +283 -21
- package/dist/config/define-resource.d.ts +1 -5
- package/dist/config/entrypoint.normalizer.d.ts +3 -2
- package/dist/config/exact-framework-config.d.ts +73 -22
- package/dist/config/field-compute.resolver.d.ts +2 -0
- package/dist/config/field-compute.resolver.js +9 -3
- package/dist/config/framework-config.d.ts +53 -15
- package/dist/config/framework-resources-config.d.ts +25 -14
- package/dist/config/pipeline-config.d.ts +20 -4
- package/dist/config/pipeline-tree.resolver.d.ts +2 -2
- package/dist/config/pipeline-tree.resolver.js +2 -3
- package/dist/contracts/access-route.rules.d.ts +10 -0
- package/dist/contracts/access-route.rules.js +45 -0
- package/dist/contracts/canonical-json.writer.d.ts +7 -0
- package/dist/contracts/canonical-json.writer.js +55 -0
- package/dist/contracts/capability.d.ts +26 -1
- package/dist/contracts/capability.js +20 -0
- package/dist/contracts/client-contract-structure.validator.d.ts +365 -89
- package/dist/contracts/client-contract-structure.validator.js +49 -2
- package/dist/contracts/contract-access.d.ts +29 -0
- package/dist/contracts/contract-access.js +1 -0
- package/dist/contracts/contract-canonicalizer.d.ts +9 -1
- package/dist/contracts/contract-canonicalizer.js +35 -4
- package/dist/contracts/contract-hash.d.ts +0 -1
- package/dist/contracts/contract-hash.js +1 -1
- package/dist/contracts/contract-limits.d.ts +6 -0
- package/dist/contracts/contract-limits.js +2 -0
- package/dist/contracts/contract.d.ts +42 -1
- package/dist/contracts/field.d.ts +58 -1
- package/dist/contracts/json-schema.projector.d.ts +11 -0
- package/dist/contracts/json-schema.projector.js +76 -0
- package/dist/contracts/scalar-value-type.d.ts +3 -1
- package/dist/framework/access-facade.d.ts +116 -0
- package/dist/framework/access-facade.js +118 -0
- package/dist/framework/contract-view.d.ts +120 -16
- package/dist/framework/framework-construction.error.d.ts +14 -4
- package/dist/framework/framework-construction.error.js +18 -2
- package/dist/framework/framework.d.ts +26 -5
- package/dist/framework/framework.factory.d.ts +1 -1
- package/dist/framework/framework.factory.js +145 -24
- package/dist/framework/operation-facade.d.ts +141 -13
- package/dist/framework/operation-facade.js +9 -1
- package/dist/framework/operation-set.runner.d.ts +47 -0
- package/dist/framework/operation-set.runner.js +168 -0
- package/dist/index.d.ts +19 -5
- package/dist/index.js +3 -0
- package/dist/internal.d.ts +9 -2
- package/dist/internal.js +8 -0
- package/dist/operations/database-refusal.d.ts +51 -0
- package/dist/operations/database-refusal.js +45 -0
- package/dist/operations/operation-arguments.d.ts +148 -60
- package/dist/operations/operation-call.d.ts +9 -5
- package/dist/operations/operation-result.d.ts +6 -4
- package/dist/operations/operation-validator-core.js +160 -39
- package/dist/operations/operation-validator.d.ts +1 -1
- package/dist/operations/structural-limits.walker.d.ts +1 -1
- package/dist/operations/structural-limits.walker.js +1 -3
- package/dist/operations/validation-code.guidance.d.ts +6 -0
- package/dist/operations/validation-code.guidance.js +90 -0
- package/dist/operations/write-scope.resolver.d.ts +4 -0
- package/dist/operations/write-scope.resolver.js +2 -0
- package/dist/policy/access-provider.interface.d.ts +91 -0
- package/dist/policy/access-provider.interface.js +1 -0
- package/dist/policy/access-provider.registry.d.ts +17 -0
- package/dist/policy/access-provider.registry.js +15 -0
- package/dist/policy/access-question.d.ts +20 -0
- package/dist/policy/access-question.js +1 -0
- package/dist/policy/access-question.registry.d.ts +5 -0
- package/dist/policy/access-question.registry.js +19 -0
- package/dist/policy/access-question.runtime.d.ts +36 -0
- package/dist/policy/access-question.runtime.js +295 -0
- package/dist/policy/access-verb.table.d.ts +56 -0
- package/dist/policy/access-verb.table.js +21 -0
- package/dist/policy/access-verbs.d.ts +46 -0
- package/dist/policy/access-verbs.js +1 -0
- package/dist/policy/policy-admission.d.ts +20 -0
- package/dist/policy/policy-admission.js +407 -0
- package/dist/policy/policy-after-update.runtime.d.ts +79 -0
- package/dist/policy/policy-after-update.runtime.js +206 -0
- package/dist/policy/policy-condition.d.ts +15 -0
- package/dist/policy/policy-condition.js +36 -0
- package/dist/policy/policy-engine.d.ts +205 -0
- package/dist/policy/policy-engine.js +1 -0
- package/dist/policy/policy-named-rows.d.ts +18 -0
- package/dist/policy/policy-named-rows.js +51 -0
- package/dist/policy/policy-nested-write.runtime.d.ts +44 -0
- package/dist/policy/policy-nested-write.runtime.js +536 -0
- package/dist/policy/policy-read.runtime.d.ts +81 -0
- package/dist/policy/policy-read.runtime.js +501 -0
- package/dist/policy/policy-reference-write.runtime.d.ts +51 -0
- package/dist/policy/policy-reference-write.runtime.js +336 -0
- package/dist/policy/policy-request.d.ts +72 -0
- package/dist/policy/policy-request.js +115 -0
- package/dist/policy/policy-session.d.ts +106 -0
- package/dist/policy/policy-session.js +293 -0
- package/dist/policy/policy-startup.validator.d.ts +10 -0
- package/dist/policy/policy-startup.validator.js +112 -0
- package/dist/policy/policy-write.runtime.d.ts +39 -0
- package/dist/policy/policy-write.runtime.js +530 -0
- package/dist/prebuilt/core-version.generated.d.ts +2 -0
- package/dist/prebuilt/core-version.generated.js +1 -0
- package/dist/prebuilt/prebuilt-changes.d.ts +29 -0
- package/dist/prebuilt/prebuilt-changes.js +63 -0
- package/dist/prebuilt/prebuilt-contracts.d.ts +40 -0
- package/dist/prebuilt/prebuilt-contracts.emitter.d.ts +16 -0
- package/dist/prebuilt/prebuilt-contracts.emitter.js +50 -0
- package/dist/prebuilt/prebuilt-contracts.js +1 -0
- package/dist/prebuilt/prebuilt-contracts.loader.d.ts +19 -0
- package/dist/prebuilt/prebuilt-contracts.loader.js +75 -0
- package/dist/prebuilt/prebuilt-inputs.fingerprint.d.ts +16 -0
- package/dist/prebuilt/prebuilt-inputs.fingerprint.js +227 -0
- package/dist/protocol/absent-route.responder.d.ts +49 -14
- package/dist/protocol/absent-route.responder.js +92 -15
- package/dist/protocol/contract-document.responder.d.ts +9 -1
- package/dist/protocol/contract-document.responder.js +3 -2
- package/dist/protocol/http-request.decoder.d.ts +52 -3
- package/dist/protocol/http-request.decoder.js +45 -6
- package/dist/protocol/http-request.reader.d.ts +10 -3
- package/dist/protocol/http-request.reader.js +12 -2
- package/dist/protocol/http-response.encoder.d.ts +12 -0
- package/dist/protocol/http-response.encoder.js +17 -3
- package/dist/protocol/operation-response.guard.js +1 -3
- package/dist/protocol/operation-set.decoder.d.ts +48 -0
- package/dist/protocol/operation-set.decoder.js +185 -0
- package/dist/protocol/operation-set.handler.d.ts +27 -0
- package/dist/protocol/operation-set.handler.js +179 -0
- package/dist/protocol/protocol-headers.d.ts +12 -3
- package/dist/protocol/protocol-headers.js +12 -5
- package/dist/protocol/protocol-surface.d.ts +16 -3
- package/dist/protocol/protocol-surface.js +41 -1
- package/dist/protocol/protocol.binder.d.ts +52 -1
- package/dist/protocol/protocol.binder.js +6 -1
- package/dist/protocol/protocol.handler.d.ts +45 -1
- package/dist/protocol/protocol.handler.js +164 -19
- package/dist/protocol/read-cache.responder.d.ts +26 -0
- package/dist/protocol/read-cache.responder.js +47 -0
- package/dist/protocol/read-query.codec.d.ts +34 -0
- package/dist/protocol/read-query.codec.js +125 -0
- package/dist/runtime/caller-data.copier.d.ts +18 -3
- package/dist/runtime/caller-data.copier.js +21 -8
- package/dist/runtime/caller-data.door.d.ts +13 -6
- package/dist/runtime/computed-read-runtime.d.ts +6 -1
- package/dist/runtime/computed-read-runtime.js +229 -48
- package/dist/runtime/computed-value.error.d.ts +3 -2
- package/dist/runtime/computed-value.error.js +3 -2
- package/dist/runtime/context-executor.runtime.d.ts +4 -3
- package/dist/runtime/context-executor.runtime.js +4 -2
- package/dist/runtime/core-class.brand.d.ts +10 -0
- package/dist/runtime/core-class.brand.js +21 -0
- package/dist/runtime/create-requirement.d.ts +31 -5
- package/dist/runtime/create-requirement.js +130 -24
- package/dist/runtime/decimal.d.ts +14 -0
- package/dist/runtime/decimal.js +21 -0
- package/dist/runtime/diagnostics-reporter.d.ts +49 -9
- package/dist/runtime/diagnostics-reporter.js +16 -9
- package/dist/runtime/error-boundary.d.ts +9 -2
- package/dist/runtime/error-boundary.js +12 -0
- package/dist/runtime/error-guidance.d.ts +12 -0
- package/dist/runtime/error-guidance.js +1 -0
- package/dist/runtime/error.catalog.d.ts +49 -0
- package/dist/runtime/error.catalog.js +49 -0
- package/dist/runtime/execution-options.d.ts +8 -0
- package/dist/runtime/field-check.evaluator.d.ts +0 -2
- package/dist/runtime/field-check.evaluator.js +1 -1
- package/dist/runtime/field-compute.d.ts +11 -10
- package/dist/runtime/field-stage.runtime.d.ts +3 -3
- package/dist/runtime/field-stage.runtime.js +9 -11
- package/dist/runtime/field-validator.runtime.d.ts +19 -1
- package/dist/runtime/field-validator.runtime.js +49 -9
- package/dist/runtime/framework-error.js +9 -0
- package/dist/runtime/framework-warning.emitter.d.ts +6 -0
- package/dist/runtime/framework-warning.emitter.js +8 -0
- package/dist/runtime/json-value.d.ts +10 -5
- package/dist/runtime/level-lifecycle.runtime.d.ts +4 -3
- package/dist/runtime/level-lifecycle.runtime.js +3 -5
- package/dist/runtime/mutation-planner.d.ts +1 -6
- package/dist/runtime/mutation-planner.js +4 -17
- package/dist/runtime/nested-write.walker.js +2 -1
- 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 +16 -9
- package/dist/runtime/operation-runtime.d.ts +35 -17
- package/dist/runtime/operation-runtime.js +220 -49
- package/dist/runtime/outcome-mapper.d.ts +2 -1
- package/dist/runtime/output-validator.d.ts +1 -1
- package/dist/runtime/output-validator.js +1 -3
- package/dist/runtime/owned-execution.registry.d.ts +34 -4
- package/dist/runtime/pipe-output.validator.d.ts +10 -0
- package/dist/runtime/pipe-output.validator.js +4 -2
- package/dist/runtime/pipeline.d.ts +52 -23
- package/dist/runtime/readonly-value.d.ts +20 -5
- package/dist/runtime/readonly-value.js +74 -26
- package/dist/runtime/record.guard.d.ts +14 -0
- package/dist/runtime/record.guard.js +10 -0
- package/dist/runtime/referential-action.d.ts +1 -1
- package/dist/runtime/request-envelope.validator.js +13 -10
- package/dist/runtime/scalar-runtime.d.ts +4 -21
- package/dist/runtime/scalar-runtime.js +91 -31
- package/dist/runtime/thenable.guard.d.ts +7 -0
- package/dist/runtime/thenable.guard.js +5 -0
- package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
- package/dist/runtime/unsent-value.normalizer.js +129 -0
- package/dist/transactions/operation-arguments-encoder.js +9 -10
- package/dist/transactions/operation-fingerprint.js +2 -2
- package/dist/transactions/sql-statement.d.ts +10 -2
- package/dist/transactions/sql-statement.validator.d.ts +2 -2
- package/dist/transactions/sql-statement.validator.js +40 -6
- package/dist/transactions/transaction-envelope.d.ts +5 -4
- package/dist/transactions/transaction-integrity-error.js +2 -0
- package/dist/transactions/transaction-plan-assembler.d.ts +12 -5
- package/dist/transactions/transaction-plan-assembler.js +49 -17
- package/dist/transactions/transaction-plan-validator.d.ts +23 -7
- package/dist/transactions/transaction-plan-validator.js +31 -7
- package/dist/transactions/transaction-reference-collector.js +8 -10
- package/dist/transactions/transaction-reference-resolver.d.ts +3 -2
- package/dist/transactions/transaction-reference-resolver.js +1 -3
- package/dist/transactions/transaction-reference-validator.d.ts +43 -3
- package/dist/transactions/transaction-reference-validator.js +83 -57
- package/dist/transactions/transaction-reference.d.ts +1 -1
- package/dist/transactions/transaction-reference.js +5 -0
- package/dist/transactions/transaction-request.d.ts +8 -8
- package/dist/transactions/transaction-runtime.d.ts +5 -2
- package/dist/transactions/transaction-runtime.js +108 -27
- package/dist/transactions/transaction-settlement.runtime.d.ts +4 -3
- package/dist/transactions/transaction-slot-path-error.js +2 -0
- package/dist/transactions/transaction-stage.runtime.d.ts +5 -3
- package/dist/transactions/transaction-stage.runtime.js +8 -7
- package/package.json +6 -5
- package/src/runtime/field-check.evaluator.ts +1 -1
|
@@ -22,7 +22,7 @@ export type AvTransactionReference<Value = unknown> = {
|
|
|
22
22
|
readonly [REFERENCE_VALUE]?: Value;
|
|
23
23
|
};
|
|
24
24
|
/** Whether a value is an ordinary value or a `$ref` candidate. */
|
|
25
|
-
|
|
25
|
+
type TransactionReferenceCandidateRoute = {
|
|
26
26
|
readonly kind: "ordinary";
|
|
27
27
|
} | {
|
|
28
28
|
readonly kind: "candidate";
|
|
@@ -14,6 +14,11 @@ export function routeTransactionReferenceCandidate(value) {
|
|
|
14
14
|
if (!ownKeys.includes("$ref") || referenceDescriptor === undefined) {
|
|
15
15
|
return ORDINARY_ROUTE;
|
|
16
16
|
}
|
|
17
|
+
if ("value" in referenceDescriptor &&
|
|
18
|
+
(referenceDescriptor.value === null ||
|
|
19
|
+
typeof referenceDescriptor.value !== "object")) {
|
|
20
|
+
return ORDINARY_ROUTE;
|
|
21
|
+
}
|
|
17
22
|
return {
|
|
18
23
|
kind: "candidate",
|
|
19
24
|
candidate: value,
|
|
@@ -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 {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AvAdapterModel } from "../adapters/adapter-model.js";
|
|
2
|
+
import { type PolicyCaller } from "../policy/policy-request.js";
|
|
2
3
|
import type { TransactionDiagnosticsChannel } from "../runtime/diagnostics-reporter.js";
|
|
3
4
|
import type { OperationPipelineDependencies, OperationRuntimeDependencies } from "../runtime/operation-runtime.js";
|
|
4
5
|
import type { PlanArguments } from "./transaction-plan-validator.js";
|
|
5
|
-
import type {
|
|
6
|
+
import type { AvTransactionRequest, TransactionOperationOrigin } from "./transaction-request.js";
|
|
6
7
|
import type { AvTransactionResponse } from "./transaction-response.js";
|
|
7
8
|
/**
|
|
8
9
|
* The transaction executor core. Like the operation executor it owns no
|
|
@@ -13,7 +14,9 @@ import type { AvTransactionResponse } from "./transaction-response.js";
|
|
|
13
14
|
* runner's mixed plans), and `planArguments` whether the steps' arguments are
|
|
14
15
|
* copied at the door; see `validateTransactionPlan`.
|
|
15
16
|
*/
|
|
16
|
-
export type FrameworkTransactionExecutor = (request:
|
|
17
|
+
export type FrameworkTransactionExecutor = (request: AvTransactionRequest, diagnostics: TransactionDiagnosticsChannel, origins: readonly TransactionOperationOrigin[] | undefined, planArguments: PlanArguments,
|
|
18
|
+
/** The principal an application run's steps run as (`{ as }`), when it names one. */
|
|
19
|
+
caller?: PolicyCaller) => Promise<AvTransactionResponse>;
|
|
17
20
|
/**
|
|
18
21
|
* Validates a whole plan through the Framework Validation Layer, then runs it inside
|
|
19
22
|
* exactly one Adapter transaction. The touched Resources' transaction stages and
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { transactionLevelsOf } from "../config/pipeline-tree.resolver.js";
|
|
2
|
+
import { derivePolicyCaller, holdFirstPrincipal, openRequestPolicy, } from "../policy/policy-request.js";
|
|
2
3
|
import { AdapterBoundary, planOperationArgumentsPath, planStepPath, sanitizeOperationFailure, } from "../runtime/error-boundary.js";
|
|
3
|
-
import { isPlainRecord, valueAt } from "../runtime/field-stage.runtime.js";
|
|
4
4
|
import { internalFailure, operationSuccess, } from "../runtime/operation-response.js";
|
|
5
|
-
import { admitOperation, executeAdmittedOperation, prepareStep, withRequestState, } from "../runtime/operation-runtime.js";
|
|
5
|
+
import { admitOperation, EVERY_FIELD, executeAdmittedOperation, prepareStep, STEP_PIPES, withRequestState, } from "../runtime/operation-runtime.js";
|
|
6
6
|
import { mapValidationOutcome } from "../runtime/outcome-mapper.js";
|
|
7
|
+
import { refusedStageOutput, serverContractFor, } from "../runtime/pipe-output.validator.js";
|
|
7
8
|
import { resolveCascadeClosure } from "../runtime/referential-action.js";
|
|
8
9
|
import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
|
|
9
10
|
import { validateTransactionPlan } from "./transaction-plan-validator.js";
|
|
11
|
+
import { collectTransactionReferenceCandidates } from "./transaction-reference-collector.js";
|
|
10
12
|
import { resolveSqlStatement, resolveTransactionReferences, } from "./transaction-reference-resolver.js";
|
|
13
|
+
import { validateReferenceSlots } from "./transaction-reference-validator.js";
|
|
11
14
|
import { transactionCommitted, transactionInfrastructureFailure, transactionOperationFailure, } from "./transaction-response.js";
|
|
12
15
|
import { settleTransaction } from "./transaction-settlement.runtime.js";
|
|
13
|
-
import { touchedTransactionLevels, transactionFacts, } from "./transaction-stage.runtime.js";
|
|
16
|
+
import { TRANSACTION_PIPES, touchedTransactionLevels, transactionFacts, } from "./transaction-stage.runtime.js";
|
|
14
17
|
export function createTransactionRuntime(dependencies, pipelineDependencies) {
|
|
15
18
|
const { adapter } = dependencies;
|
|
16
19
|
const planDependencies = {
|
|
@@ -18,13 +21,13 @@ export function createTransactionRuntime(dependencies, pipelineDependencies) {
|
|
|
18
21
|
cascades: resolveCascadeClosure(adapter.referentialActions),
|
|
19
22
|
sqlStatements: adapter.sqlStatements === true,
|
|
20
23
|
};
|
|
21
|
-
return async (seeded, diagnostics, origins, planArguments) => {
|
|
24
|
+
return async (seeded, diagnostics, origins, planArguments, caller) => {
|
|
22
25
|
const request = withRequestState(seeded);
|
|
23
26
|
const validation = await validateTransactionPlan(planDependencies, request, origins, planArguments);
|
|
24
27
|
if (!validation.ok) {
|
|
25
28
|
return validation.response;
|
|
26
29
|
}
|
|
27
|
-
return executeTransactionPlan(
|
|
30
|
+
return executeTransactionPlan(dependencies, pipelineDependencies, request, validation.plan, request.state, diagnostics, caller);
|
|
28
31
|
};
|
|
29
32
|
}
|
|
30
33
|
function planOrigin(request, plan) {
|
|
@@ -59,39 +62,108 @@ function pathKey(path) {
|
|
|
59
62
|
function relativeSlotPath(operation, path) {
|
|
60
63
|
return path.slice(planOperationArgumentsPath(operation.index).length);
|
|
61
64
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
function standingReferences(core, operation, args, steps, subject) {
|
|
66
|
+
const candidates = collectTransactionReferenceCandidates(serverContractFor(core, operation.contract), operation.request, operation.index, args);
|
|
67
|
+
const validation = validateReferenceSlots(candidates, steps, operation.index);
|
|
68
|
+
if (validation.ok) {
|
|
69
|
+
return validation;
|
|
66
70
|
}
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
const { issue } = validation;
|
|
72
|
+
const refused = refusedStageOutput(operation.request, [
|
|
73
|
+
{
|
|
74
|
+
...issue,
|
|
75
|
+
path: ["arguments", ...relativeSlotPath(operation, issue.path ?? [])],
|
|
76
|
+
},
|
|
77
|
+
], subject);
|
|
78
|
+
if (refused === undefined) {
|
|
79
|
+
throw new TypeError("A refused reference produced no refusal.");
|
|
70
80
|
}
|
|
71
|
-
|
|
72
|
-
return (reference.operation === expected.operation &&
|
|
73
|
-
reference.path.length === 1 &&
|
|
74
|
-
reference.path[0] === expected.path[0]);
|
|
75
|
-
}
|
|
76
|
-
function slotKeys(operation) {
|
|
77
|
-
return new Set(operation.references.map((slot) => pathKey(relativeSlotPath(operation, slot.path))));
|
|
81
|
+
return { ok: false, ...refused };
|
|
78
82
|
}
|
|
79
|
-
async function executeTransactionPlan(
|
|
80
|
-
const
|
|
83
|
+
async function executeTransactionPlan(runtime, dependencies, request, plan, state, diagnostics, caller) {
|
|
84
|
+
const { adapter } = runtime;
|
|
85
|
+
const callers = new Map();
|
|
86
|
+
if (caller !== undefined) {
|
|
87
|
+
for (const step of plan.operations) {
|
|
88
|
+
if (step.kind === "operation") {
|
|
89
|
+
holdFirstPrincipal(runtime.config.policy, {
|
|
90
|
+
origin: step.request.origin,
|
|
91
|
+
state,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
for (const step of plan.operations) {
|
|
98
|
+
if (step.kind === "sql" || callers.has(step.request.origin)) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const derived = derivePolicyCaller(runtime.config.policy, {
|
|
103
|
+
origin: step.request.origin,
|
|
104
|
+
state,
|
|
105
|
+
});
|
|
106
|
+
callers.set(step.request.origin, derived instanceof Promise ? await derived : derived);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
diagnostics.operation(step.request, step.index)(error, "A3000");
|
|
110
|
+
return transactionOperationFailure(internalFailure(), step.index);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const steps = new Map();
|
|
115
|
+
const stateful = (operation) => {
|
|
116
|
+
const known = steps.get(operation);
|
|
117
|
+
if (known !== undefined) {
|
|
118
|
+
return known;
|
|
119
|
+
}
|
|
120
|
+
const settle = (policy) => {
|
|
121
|
+
const step = policy === undefined
|
|
122
|
+
? { ...operation.request, state }
|
|
123
|
+
: { ...operation.request, state, policy };
|
|
124
|
+
steps.set(operation, step);
|
|
125
|
+
return step;
|
|
126
|
+
};
|
|
127
|
+
const policy = openRequestPolicy(runtime.config.policy, runtime.contracts.core, { origin: operation.request.origin, state }, caller ?? callers.get(operation.request.origin), adapter);
|
|
128
|
+
return policy instanceof Promise ? policy.then(settle) : settle(policy);
|
|
129
|
+
};
|
|
81
130
|
const admitted = [];
|
|
131
|
+
const standing = [];
|
|
82
132
|
for (const step of plan.operations) {
|
|
83
133
|
if (step.kind === "sql") {
|
|
84
134
|
admitted.push({ ok: true, args: undefined, piped: false });
|
|
135
|
+
standing.push([]);
|
|
85
136
|
continue;
|
|
86
137
|
}
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
138
|
+
const report = diagnostics.operation(step.request, step.index);
|
|
139
|
+
let stepRequest;
|
|
140
|
+
try {
|
|
141
|
+
const opened = stateful(step);
|
|
142
|
+
stepRequest = opened instanceof Promise ? await opened : opened;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
report(error, "A3000");
|
|
146
|
+
return transactionOperationFailure(internalFailure(), step.index);
|
|
147
|
+
}
|
|
148
|
+
const admission = await admitOperation(dependencies, stepRequest, step.contract, step.arguments, planOperationArgumentsPath(step.index), report, { requestId: request.requestId, transaction: undefined, state }, {
|
|
149
|
+
select: EVERY_FIELD,
|
|
90
150
|
validation: { transactionReferences: true },
|
|
151
|
+
beforeBegin: true,
|
|
91
152
|
});
|
|
92
153
|
if (!admission.ok) {
|
|
93
154
|
return transactionOperationFailure(admission.response, step.index);
|
|
94
155
|
}
|
|
156
|
+
if (!admission.piped) {
|
|
157
|
+
standing.push(step.references);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const references = standingReferences(dependencies.contracts.core, step, admission.args, plan.operations, STEP_PIPES);
|
|
161
|
+
if (!references.ok) {
|
|
162
|
+
report(references.error, "A3004");
|
|
163
|
+
return transactionOperationFailure(references.response, step.index);
|
|
164
|
+
}
|
|
165
|
+
standing.push(references.references);
|
|
166
|
+
}
|
|
95
167
|
admitted.push(admission);
|
|
96
168
|
}
|
|
97
169
|
const origin = planOrigin(request, plan);
|
|
@@ -101,9 +173,18 @@ async function executeTransactionPlan(adapter, dependencies, request, plan, stat
|
|
|
101
173
|
const runPlanOperation = async (operation, args, transactionPiped, executor, results, outer) => {
|
|
102
174
|
const report = diagnostics.operation(operation.request, operation.index);
|
|
103
175
|
const argumentsPath = planOperationArgumentsPath(operation.index);
|
|
104
|
-
const
|
|
176
|
+
const opened = stateful(operation);
|
|
177
|
+
const stepRequest = opened instanceof Promise ? await opened : opened;
|
|
105
178
|
try {
|
|
106
|
-
|
|
179
|
+
let live = standing[operation.index] ?? operation.references;
|
|
180
|
+
if (transactionPiped) {
|
|
181
|
+
const references = standingReferences(dependencies.contracts.core, operation, args, plan.operations, TRANSACTION_PIPES);
|
|
182
|
+
if (!references.ok) {
|
|
183
|
+
report(references.error, "A3004");
|
|
184
|
+
return references.response;
|
|
185
|
+
}
|
|
186
|
+
live = references.references;
|
|
187
|
+
}
|
|
107
188
|
const resolved = resolveTransactionReferences({
|
|
108
189
|
...operation,
|
|
109
190
|
arguments: args,
|
|
@@ -119,7 +200,7 @@ async function executeTransactionPlan(adapter, dependencies, request, plan, stat
|
|
|
119
200
|
written: (path) => written.has(pathKey(path)),
|
|
120
201
|
transactionPiped,
|
|
121
202
|
pipedAroundReferences: admitted[operation.index]?.piped === true &&
|
|
122
|
-
operation.references.length > 0,
|
|
203
|
+
(live.length > 0 || operation.references.length > 0),
|
|
123
204
|
}, outer);
|
|
124
205
|
if (!prepared.ok) {
|
|
125
206
|
return prepared.response;
|
|
@@ -14,9 +14,9 @@ import { type TransactionStepView } from "./transaction-stage.runtime.js";
|
|
|
14
14
|
* the touched Resources' transaction filters answer it once the transaction
|
|
15
15
|
* interceptors have unwound. Its answer is the step's own outcome.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
type TransactionStepRunner<M extends AvAdapterModel> = (index: number, step: TransactionStepView, piped: boolean, executor: AvAdapterTransactionExecutor<M>, results: readonly unknown[], outer: OuterFailureLayer) => Promise<AvOperationResponse>;
|
|
18
18
|
/** How one transaction settled. */
|
|
19
|
-
|
|
19
|
+
type TransactionSettlement =
|
|
20
20
|
/** Committed: every step's own outcome, in plan order. */
|
|
21
21
|
{
|
|
22
22
|
readonly kind: "committed";
|
|
@@ -34,7 +34,7 @@ export type TransactionSettlement =
|
|
|
34
34
|
readonly error: unknown;
|
|
35
35
|
readonly operation: number | undefined;
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
type TransactionSettlementInput<M extends AvAdapterModel> = {
|
|
38
38
|
readonly adapter: AvAdapter<M>;
|
|
39
39
|
/** The touched Resources' transaction levels, outer to inner. */
|
|
40
40
|
readonly levels: readonly ResolvedTransactionPipelineConfig[];
|
|
@@ -49,3 +49,4 @@ export type TransactionSettlementInput<M extends AvAdapterModel> = {
|
|
|
49
49
|
};
|
|
50
50
|
/** Runs `plan` inside one Adapter transaction, its stages around its steps, and settles it. */
|
|
51
51
|
export declare function settleTransaction<M extends AvAdapterModel>(input: TransactionSettlementInput<M>): Promise<TransactionSettlement>;
|
|
52
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { brandCoreClass } from "../runtime/core-class.brand.js";
|
|
1
2
|
const TRANSACTION_SLOT_PATH_MESSAGES = {
|
|
2
3
|
"slot-prefix": "Transaction slot path does not name a member below the operation's arguments.",
|
|
3
4
|
"absent-member": "Transaction slot path names an absent member of the operation arguments.",
|
|
@@ -11,3 +12,4 @@ export class AvTransactionSlotPathError extends Error {
|
|
|
11
12
|
this.violation = violation;
|
|
12
13
|
}
|
|
13
14
|
}
|
|
15
|
+
brandCoreClass(AvTransactionSlotPathError, "AvTransactionSlotPathError");
|
|
@@ -23,11 +23,12 @@ export type TransactionStepView = AvTransactionStep;
|
|
|
23
23
|
export declare const TRANSACTION_PIPES = "Transaction pipes";
|
|
24
24
|
/**
|
|
25
25
|
* The `$` facts a transaction stage is told: the plan as `$args`, not one
|
|
26
|
-
* operation (`$operation` is absent).
|
|
26
|
+
* operation (`$operation` is absent). Each ctx holds its own frozen copy of the
|
|
27
|
+
* plan, a `Date` or a `Uint8Array` in a step's arguments fresh.
|
|
27
28
|
*/
|
|
28
29
|
export declare function transactionFacts(contract: AvContract, request: Pick<OperationExecutionRequest, "origin" | "requestId" | "transport">, plan: readonly TransactionStepView[]): ContextFacts;
|
|
29
30
|
/** How the transaction stages around a plan's steps ended. */
|
|
30
|
-
|
|
31
|
+
type TransactionStagesOutcome =
|
|
31
32
|
/** Every stage and step ran; the steps' results, as the stages left them. */
|
|
32
33
|
{
|
|
33
34
|
readonly kind: "ran";
|
|
@@ -60,7 +61,7 @@ export type TransactionStagesOutcome =
|
|
|
60
61
|
* changed it, in which case every operation step's arguments are held to the
|
|
61
62
|
* server's rules and its validators again before it runs.
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
+
type StagedPlan = {
|
|
64
65
|
readonly plan: readonly TransactionStepView[];
|
|
65
66
|
readonly piped: boolean;
|
|
66
67
|
};
|
|
@@ -79,3 +80,4 @@ export declare function runTransactionStages(levels: readonly ResolvedTransactio
|
|
|
79
80
|
* exact reverse (the first that handles it wins), then final sanitization.
|
|
80
81
|
*/
|
|
81
82
|
export declare function resolveTransactionStageFailure(error: unknown, levels: readonly ResolvedTransactionPipelineConfig[], context: AvTransactionContext, report: DiagnosticsReporter, view: CallerArgumentsView): Promise<AvOperationFailureResponse>;
|
|
83
|
+
export {};
|
|
@@ -2,7 +2,8 @@ import { AdapterBoundary, resolveOperationFailure, } from "../runtime/error-boun
|
|
|
2
2
|
import { runLevelLifecycle, } from "../runtime/level-lifecycle.runtime.js";
|
|
3
3
|
import { operationFailure } from "../runtime/operation-response.js";
|
|
4
4
|
import { AvPipeOutputError, PIPE_OUTPUT_FAILURE_MESSAGE, } from "../runtime/pipe-output.validator.js";
|
|
5
|
-
import { deepFreeze } from "../runtime/readonly-value.js";
|
|
5
|
+
import { deepFreeze, frozenCopy } from "../runtime/readonly-value.js";
|
|
6
|
+
import { isRecord } from "../runtime/record.guard.js";
|
|
6
7
|
import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
|
|
7
8
|
export const TRANSACTION_ABORT = Object.freeze({ reason: "aventara-transaction-abort" });
|
|
8
9
|
export const TRANSACTION_PIPES = "Transaction pipes";
|
|
@@ -10,7 +11,7 @@ export function transactionFacts(contract, request, plan) {
|
|
|
10
11
|
return {
|
|
11
12
|
$contract: contract,
|
|
12
13
|
$origin: request.origin,
|
|
13
|
-
$args: plan,
|
|
14
|
+
$args: frozenCopy(plan),
|
|
14
15
|
$requestId: request.requestId,
|
|
15
16
|
...(request.origin !== "application" && request.transport !== undefined
|
|
16
17
|
? { $transport: request.transport }
|
|
@@ -26,9 +27,6 @@ export function touchedTransactionLevels(plan, levelsOf) {
|
|
|
26
27
|
}
|
|
27
28
|
return [...touched].flatMap((resource) => levelsOf(resource));
|
|
28
29
|
}
|
|
29
|
-
function isRecord(value) {
|
|
30
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31
|
-
}
|
|
32
30
|
function sameStructure(left, right) {
|
|
33
31
|
if (Object.is(left, right)) {
|
|
34
32
|
return true;
|
|
@@ -86,8 +84,11 @@ export async function runTransactionStages(levels, plan, contextOf, runSteps) {
|
|
|
86
84
|
let pipeIndex = 0;
|
|
87
85
|
for (const level of levels) {
|
|
88
86
|
for (const pipe of level.pipes) {
|
|
89
|
-
const
|
|
90
|
-
|
|
87
|
+
const told = frozenCopy(current);
|
|
88
|
+
const returned = await pipe(told, contextOf(current));
|
|
89
|
+
if (returned !== undefined &&
|
|
90
|
+
returned !== told &&
|
|
91
|
+
returned !== current) {
|
|
91
92
|
const accepted = acceptPlan(current, returned, pipeIndex);
|
|
92
93
|
if (typeof accepted === "string") {
|
|
93
94
|
return {
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aventara/core",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.11",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "Core runtime, contract compiler, and extension APIs for Aventara.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "^22.
|
|
8
|
+
"node": "^22.23.4 || >=24.22.1"
|
|
9
9
|
},
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
@@ -34,19 +34,20 @@
|
|
|
34
34
|
"files": [
|
|
35
35
|
"dist",
|
|
36
36
|
"src/runtime/field-check.evaluator.ts",
|
|
37
|
+
"ERRORS.md",
|
|
37
38
|
"LICENSE-ADDITIONAL-PERMISSION.md",
|
|
38
39
|
"CHANGELOG.md"
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"zod": "^4.6.
|
|
42
|
+
"zod": "^4.6.7"
|
|
42
43
|
},
|
|
43
44
|
"publishConfig": {
|
|
44
45
|
"access": "public"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|
|
47
|
-
"build": "node ../../scripts/build/build-output.cleaner.ts dist && tsc -p tsconfig.json --removeComments --declaration false && tsc -p tsconfig.json --emitDeclarationOnly && node ../../scripts/build/declaration-comments.sanitizer.ts dist",
|
|
48
|
+
"build": "node ../../scripts/build/build-output.cleaner.ts dist && node scripts/core-version.generator.ts && tsc -p tsconfig.json --removeComments --declaration false && tsc -p tsconfig.json --emitDeclarationOnly && node ../../scripts/build/declaration-comments.sanitizer.ts dist && node scripts/errors-markdown.generator.ts",
|
|
48
49
|
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
|
|
49
50
|
"test": "vitest run --typecheck --config ../../vitest.config.mts --root .",
|
|
50
|
-
"lint": "biome lint src"
|
|
51
|
+
"lint": "biome lint src scripts"
|
|
51
52
|
}
|
|
52
53
|
}
|
|
@@ -712,7 +712,7 @@ export function entryCheckIssues(
|
|
|
712
712
|
}
|
|
713
713
|
|
|
714
714
|
/** Whether a check judges a list's own length (`AvZ.minItems`/`AvZ.maxItems`). */
|
|
715
|
-
|
|
715
|
+
function isListCheck(check: AvFieldCheck): boolean {
|
|
716
716
|
return (
|
|
717
717
|
(check.check === "max_length" || check.check === "min_length") &&
|
|
718
718
|
check.list === true
|