@aventara/core 0.1.0-pilot.4 → 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 +1478 -0
- package/README.md +275 -11
- 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 +17 -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 -25
- 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/avz/avz.js +354 -0
- package/dist/avz/index.d.ts +7 -0
- package/dist/avz/index.js +1 -0
- package/dist/avz/json-shape.registry.d.ts +22 -0
- package/dist/avz/json-shape.registry.js +16 -0
- package/dist/avz/zod-issue.translator.d.ts +57 -0
- package/dist/avz/zod-issue.translator.js +149 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +37 -5
- package/dist/compiler/contract.compiler.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +595 -421
- 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 +75 -29
- package/dist/config/config.resolver.js +109 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +586 -71
- 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 +111 -37
- 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 +344 -29
- package/dist/contracts/client-contract-structure.validator.js +248 -7
- package/dist/contracts/contract-canonicalizer.d.ts +19 -3
- package/dist/contracts/contract-canonicalizer.js +172 -27
- 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 +31 -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 +61 -41
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-shape.d.ts +76 -0
- package/dist/contracts/json-shape.js +1 -0
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- package/dist/contracts/reference-write-limit.d.ts +7 -0
- package/dist/contracts/reference-write-limit.js +1 -0
- 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 +25 -14
- 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 +234 -63
- 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 +50 -24
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +95 -32
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +55 -82
- package/dist/index.js +6 -26
- package/dist/internal.d.ts +40 -0
- package/dist/internal.js +18 -0
- package/dist/operations/operation-arguments.d.ts +316 -201
- package/dist/operations/operation-call.d.ts +27 -28
- package/dist/operations/operation-identity.d.ts +12 -10
- package/dist/operations/operation-identity.js +3 -0
- 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 +41 -12
- package/dist/operations/operation-validator.d.ts +24 -9
- package/dist/operations/operation-validator.js +26 -10
- package/dist/operations/projection-scope.resolver.d.ts +7 -7
- package/dist/operations/structural-limits.walker.d.ts +19 -0
- package/dist/operations/structural-limits.walker.js +489 -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 -11
- package/dist/protocol/absent-route.responder.js +42 -16
- 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 +23 -13
- package/dist/protocol/http-request.decoder.js +19 -11
- 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 +52 -27
- package/dist/protocol/protocol.binder.js +14 -9
- package/dist/protocol/protocol.handler.d.ts +28 -15
- package/dist/protocol/protocol.handler.js +55 -10
- package/dist/protocol/unmounted-route.error.d.ts +19 -0
- package/dist/protocol/unmounted-route.error.js +10 -0
- package/dist/runtime/caller-data.copier.d.ts +59 -0
- package/dist/runtime/caller-data.copier.js +470 -0
- package/dist/runtime/caller-data.door.d.ts +56 -0
- package/dist/runtime/caller-data.door.js +67 -0
- package/dist/runtime/computed-read-runtime.d.ts +7 -6
- package/dist/runtime/computed-read-runtime.js +61 -55
- package/dist/runtime/computed-value.error.d.ts +13 -0
- package/dist/runtime/computed-value.error.js +9 -0
- 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 +22 -57
- package/dist/runtime/create-requirement.js +140 -37
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +64 -22
- package/dist/runtime/diagnostics-reporter.js +35 -4
- package/dist/runtime/error-boundary.d.ts +73 -8
- package/dist/runtime/error-boundary.js +104 -48
- 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 +79 -7
- 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 +32 -0
- package/dist/runtime/misuse-reporter.js +19 -0
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +62 -36
- 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 +35 -15
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +125 -30
- package/dist/runtime/operation-runtime.js +423 -83
- package/dist/runtime/outcome-mapper.d.ts +16 -5
- package/dist/runtime/outcome-mapper.js +35 -8
- package/dist/runtime/output-validator.d.ts +16 -6
- package/dist/runtime/output-validator.js +12 -1
- package/dist/runtime/owned-execution.registry.d.ts +13 -0
- package/dist/runtime/owned-execution.registry.js +7 -0
- 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 +202 -28
- package/dist/runtime/readonly-value.d.ts +32 -0
- package/dist/runtime/readonly-value.js +141 -0
- package/dist/runtime/referential-action.d.ts +7 -0
- package/dist/runtime/request-envelope.validator.d.ts +5 -0
- package/dist/runtime/request-envelope.validator.js +123 -0
- 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 +56 -13
- package/dist/runtime/scalar-runtime.js +167 -86
- 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 +23 -9
- package/dist/transactions/transaction-plan-assembler.js +195 -82
- package/dist/transactions/transaction-plan-validator.d.ts +53 -21
- package/dist/transactions/transaction-plan-validator.js +246 -163
- package/dist/transactions/transaction-reference-collector.d.ts +30 -0
- package/dist/transactions/transaction-reference-collector.js +204 -0
- package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
- package/dist/transactions/transaction-reference-resolver.js +27 -10
- package/dist/transactions/transaction-reference-validator.d.ts +34 -4
- package/dist/transactions/transaction-reference-validator.js +82 -43
- package/dist/transactions/transaction-reference.d.ts +30 -58
- package/dist/transactions/transaction-request.d.ts +20 -7
- package/dist/transactions/transaction-response.d.ts +12 -7
- package/dist/transactions/transaction-response.js +24 -1
- package/dist/transactions/transaction-runtime.d.ts +11 -8
- package/dist/transactions/transaction-runtime.js +167 -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 +18 -3
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -35
- 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 -36
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- package/dist/operations/operation-boolean-nodes.d.ts +0 -11
- package/dist/operations/operation-boolean-nodes.js +0 -283
- package/dist/operations/operation-nesting.d.ts +0 -8
- package/dist/operations/operation-nesting.js +0 -307
- 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/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
- /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ResolvedTransactionPipelineConfig } from "../config/pipeline-config.js";
|
|
2
|
+
import type { AvContract } from "../contracts/contract.js";
|
|
3
|
+
import type { ContextFacts } from "../runtime/context-executor.runtime.js";
|
|
4
|
+
import type { DiagnosticsReporter } from "../runtime/diagnostics-reporter.js";
|
|
5
|
+
import { type CallerArgumentsView } from "../runtime/error-boundary.js";
|
|
6
|
+
import type { OperationExecutionRequest } from "../runtime/operation-request.js";
|
|
7
|
+
import type { AvOperationFailureResponse } from "../runtime/operation-response.js";
|
|
8
|
+
import { type RefusedStageOutput } from "../runtime/pipe-output.validator.js";
|
|
9
|
+
import type { AvTransactionContext, AvTransactionStep } from "../runtime/pipeline.js";
|
|
10
|
+
import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
|
|
11
|
+
/**
|
|
12
|
+
* The framework-owned rollback request. It is thrown out of the Adapter transaction
|
|
13
|
+
* callback only after a failure is recorded, and a rejection is recognized as it
|
|
14
|
+
* solely by identity — never by message, shape or class. It is a control signal,
|
|
15
|
+
* not a failure, so it never reaches diagnostics.
|
|
16
|
+
*/
|
|
17
|
+
export declare const TRANSACTION_ABORT: Readonly<{
|
|
18
|
+
readonly reason: "aventara-transaction-abort";
|
|
19
|
+
}>;
|
|
20
|
+
/** One plan step as a transaction stage reads it (the erased {@link AvTransactionStep}). */
|
|
21
|
+
export type TransactionStepView = AvTransactionStep;
|
|
22
|
+
/** The subject a refused transaction pipe output is reported under. */
|
|
23
|
+
export declare const TRANSACTION_PIPES = "Transaction pipes";
|
|
24
|
+
/**
|
|
25
|
+
* The `$` facts a transaction stage is told: the plan as `$args`, not one
|
|
26
|
+
* operation (`$operation` is absent).
|
|
27
|
+
*/
|
|
28
|
+
export declare function transactionFacts(contract: AvContract, request: Pick<OperationExecutionRequest, "origin" | "requestId" | "transport">, plan: readonly TransactionStepView[]): ContextFacts;
|
|
29
|
+
/** How the transaction stages around a plan's steps ended. */
|
|
30
|
+
export type TransactionStagesOutcome =
|
|
31
|
+
/** Every stage and step ran; the steps' results, as the stages left them. */
|
|
32
|
+
{
|
|
33
|
+
readonly kind: "ran";
|
|
34
|
+
}
|
|
35
|
+
/** A transaction guard returned `false`: `A4001`. */
|
|
36
|
+
| {
|
|
37
|
+
readonly kind: "denied";
|
|
38
|
+
}
|
|
39
|
+
/** A transaction pipe returned something that is not the plan: `A3004`. */
|
|
40
|
+
| {
|
|
41
|
+
readonly kind: "refused";
|
|
42
|
+
readonly refusal: RefusedStageOutput;
|
|
43
|
+
}
|
|
44
|
+
/** A stage or a step threw (the rollback request included). */
|
|
45
|
+
| {
|
|
46
|
+
readonly kind: "failed";
|
|
47
|
+
readonly error: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A transaction interceptor broke the stages' contract: it called `next()`
|
|
51
|
+
* twice (whatever it then did with the refusal). Answered `A3002`, past every
|
|
52
|
+
* filter, and the transaction rolls back.
|
|
53
|
+
*/
|
|
54
|
+
| {
|
|
55
|
+
readonly kind: "broken";
|
|
56
|
+
readonly error: AvTransactionIntegrityError;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* What the steps see after the stages: the plan, and whether a transaction pipe
|
|
60
|
+
* changed it, in which case every operation step's arguments are held to the
|
|
61
|
+
* server's rules and its validators again before it runs.
|
|
62
|
+
*/
|
|
63
|
+
export type StagedPlan = {
|
|
64
|
+
readonly plan: readonly TransactionStepView[];
|
|
65
|
+
readonly piped: boolean;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Each touched Resource's transaction levels, root then overlay, Resources in the
|
|
69
|
+
* order their first top-level operation step appears. A SQL step touches nothing.
|
|
70
|
+
*/
|
|
71
|
+
export declare function touchedTransactionLevels(plan: readonly TransactionStepView[], levelsOf: (resource: string) => readonly ResolvedTransactionPipelineConfig[]): readonly ResolvedTransactionPipelineConfig[];
|
|
72
|
+
/**
|
|
73
|
+
* Runs the transaction stages of `levels` around `runSteps`, inside an open
|
|
74
|
+
* transaction. Never throws: every way the stages can end is the outcome.
|
|
75
|
+
*/
|
|
76
|
+
export declare function runTransactionStages(levels: readonly ResolvedTransactionPipelineConfig[], plan: readonly TransactionStepView[], contextOf: (plan: readonly TransactionStepView[]) => AvTransactionContext, runSteps: (staged: StagedPlan) => Promise<readonly unknown[]>): Promise<TransactionStagesOutcome>;
|
|
77
|
+
/**
|
|
78
|
+
* An error a transaction stage threw, through the touched Resources' filters in
|
|
79
|
+
* exact reverse (the first that handles it wins), then final sanitization.
|
|
80
|
+
*/
|
|
81
|
+
export declare function resolveTransactionStageFailure(error: unknown, levels: readonly ResolvedTransactionPipelineConfig[], context: AvTransactionContext, report: DiagnosticsReporter, view: CallerArgumentsView): Promise<AvOperationFailureResponse>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { AdapterBoundary, resolveOperationFailure, } from "../runtime/error-boundary.js";
|
|
2
|
+
import { runLevelLifecycle, } from "../runtime/level-lifecycle.runtime.js";
|
|
3
|
+
import { operationFailure } from "../runtime/operation-response.js";
|
|
4
|
+
import { AvPipeOutputError, PIPE_OUTPUT_FAILURE_MESSAGE, } from "../runtime/pipe-output.validator.js";
|
|
5
|
+
import { deepFreeze } from "../runtime/readonly-value.js";
|
|
6
|
+
import { AvTransactionIntegrityError } from "./transaction-integrity-error.js";
|
|
7
|
+
export const TRANSACTION_ABORT = Object.freeze({ reason: "aventara-transaction-abort" });
|
|
8
|
+
export const TRANSACTION_PIPES = "Transaction pipes";
|
|
9
|
+
export function transactionFacts(contract, request, plan) {
|
|
10
|
+
return {
|
|
11
|
+
$contract: contract,
|
|
12
|
+
$origin: request.origin,
|
|
13
|
+
$args: plan,
|
|
14
|
+
$requestId: request.requestId,
|
|
15
|
+
...(request.origin !== "application" && request.transport !== undefined
|
|
16
|
+
? { $transport: request.transport }
|
|
17
|
+
: {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function touchedTransactionLevels(plan, levelsOf) {
|
|
21
|
+
const touched = new Set();
|
|
22
|
+
for (const step of plan) {
|
|
23
|
+
if (step.resource !== undefined) {
|
|
24
|
+
touched.add(step.resource);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [...touched].flatMap((resource) => levelsOf(resource));
|
|
28
|
+
}
|
|
29
|
+
function isRecord(value) {
|
|
30
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
function sameStructure(left, right) {
|
|
33
|
+
if (Object.is(left, right)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
37
|
+
return (left.length === right.length &&
|
|
38
|
+
left.every((entry, index) => sameStructure(entry, right[index])));
|
|
39
|
+
}
|
|
40
|
+
if (isRecord(left) &&
|
|
41
|
+
isRecord(right) &&
|
|
42
|
+
Object.getPrototypeOf(left) === Object.prototype &&
|
|
43
|
+
Object.getPrototypeOf(right) === Object.prototype) {
|
|
44
|
+
const keys = Object.keys(left);
|
|
45
|
+
return (keys.length === Object.keys(right).length &&
|
|
46
|
+
keys.every((key) => Object.hasOwn(right, key) && sameStructure(left[key], right[key])));
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
function acceptPlan(original, returned, index) {
|
|
51
|
+
if (!Array.isArray(returned) || returned.length !== original.length) {
|
|
52
|
+
return `Transaction pipes[${index}] returned a plan that does not keep its ${original.length} step(s)`;
|
|
53
|
+
}
|
|
54
|
+
const accepted = [];
|
|
55
|
+
for (const [position, step] of original.entries()) {
|
|
56
|
+
const entry = returned[position];
|
|
57
|
+
if (step.sql !== undefined) {
|
|
58
|
+
if (!isRecord(entry) || !sameStructure(entry.sql, step.sql)) {
|
|
59
|
+
return `Transaction pipes[${index}] changed SQL step ${position}`;
|
|
60
|
+
}
|
|
61
|
+
accepted.push(step);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!isRecord(entry) ||
|
|
65
|
+
entry.resource !== step.resource ||
|
|
66
|
+
entry.family !== step.family ||
|
|
67
|
+
entry.variant !== step.variant) {
|
|
68
|
+
return `Transaction pipes[${index}] changed which operation step ${position} runs`;
|
|
69
|
+
}
|
|
70
|
+
accepted.push({ ...step, args: entry.args });
|
|
71
|
+
}
|
|
72
|
+
return accepted;
|
|
73
|
+
}
|
|
74
|
+
export async function runTransactionStages(levels, plan, contextOf, runSteps) {
|
|
75
|
+
let current = deepFreeze(plan);
|
|
76
|
+
const reuse = { refusal: undefined };
|
|
77
|
+
try {
|
|
78
|
+
for (const level of levels) {
|
|
79
|
+
for (const guard of level.guards) {
|
|
80
|
+
if ((await guard(contextOf(current))) === false) {
|
|
81
|
+
return { kind: "denied" };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let piped = false;
|
|
86
|
+
let pipeIndex = 0;
|
|
87
|
+
for (const level of levels) {
|
|
88
|
+
for (const pipe of level.pipes) {
|
|
89
|
+
const returned = await pipe(current, contextOf(current));
|
|
90
|
+
if (returned !== undefined && returned !== current) {
|
|
91
|
+
const accepted = acceptPlan(current, returned, pipeIndex);
|
|
92
|
+
if (typeof accepted === "string") {
|
|
93
|
+
return {
|
|
94
|
+
kind: "refused",
|
|
95
|
+
refusal: {
|
|
96
|
+
response: operationFailure("A3004", {
|
|
97
|
+
message: PIPE_OUTPUT_FAILURE_MESSAGE,
|
|
98
|
+
}),
|
|
99
|
+
error: new AvPipeOutputError(accepted, []),
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
current = deepFreeze(accepted);
|
|
104
|
+
piped = true;
|
|
105
|
+
}
|
|
106
|
+
pipeIndex += 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const staged = { plan: current, piped };
|
|
110
|
+
await runLevelLifecycle(levels, () => contextOf(current), () => runSteps(staged), async (results) => results, reuse, () => new AvTransactionIntegrityError("next-called-twice"));
|
|
111
|
+
return reuse.refusal === undefined
|
|
112
|
+
? { kind: "ran" }
|
|
113
|
+
: { kind: "broken", error: reuse.refusal };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
return reuse.refusal === undefined
|
|
117
|
+
? { kind: "failed", error }
|
|
118
|
+
: { kind: "broken", error: reuse.refusal };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export function resolveTransactionStageFailure(error, levels, context, report, view) {
|
|
122
|
+
return resolveOperationFailure(error, levels.flatMap((level) => level.filters), context, new AdapterBoundary(), report, view);
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aventara/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"description": "Core runtime, contract compiler, and extension APIs for Aventara.",
|
|
6
6
|
"type": "module",
|
|
@@ -19,17 +19,32 @@
|
|
|
19
19
|
"types": "./dist/protocol/index.d.ts",
|
|
20
20
|
"import": "./dist/protocol/index.js",
|
|
21
21
|
"default": "./dist/protocol/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./internal": {
|
|
24
|
+
"types": "./dist/internal.d.ts",
|
|
25
|
+
"import": "./dist/internal.js",
|
|
26
|
+
"default": "./dist/internal.js"
|
|
27
|
+
},
|
|
28
|
+
"./avz": {
|
|
29
|
+
"types": "./dist/avz/index.d.ts",
|
|
30
|
+
"import": "./dist/avz/index.js",
|
|
31
|
+
"default": "./dist/avz/index.js"
|
|
22
32
|
}
|
|
23
33
|
},
|
|
24
34
|
"files": [
|
|
25
35
|
"dist",
|
|
26
|
-
"
|
|
36
|
+
"src/runtime/field-check.evaluator.ts",
|
|
37
|
+
"LICENSE-ADDITIONAL-PERMISSION.md",
|
|
38
|
+
"CHANGELOG.md"
|
|
27
39
|
],
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"zod": "^4.6.5"
|
|
42
|
+
},
|
|
28
43
|
"publishConfig": {
|
|
29
44
|
"access": "public"
|
|
30
45
|
},
|
|
31
46
|
"scripts": {
|
|
32
|
-
"build": "tsc -p tsconfig.json --removeComments --declaration false && tsc -p tsconfig.json --emitDeclarationOnly && node ../../scripts/build/declaration-comments.sanitizer.ts dist",
|
|
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",
|
|
33
48
|
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
|
|
34
49
|
"test": "vitest run --typecheck --config ../../vitest.config.mts --root .",
|
|
35
50
|
"lint": "biome lint src"
|