@aventara/core 1.0.0-rc.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1434 -0
- package/ERRORS.md +142 -0
- package/README.md +247 -57
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
- package/dist/adapters/adapter-discovery-diagnostic.guidance.d.ts +6 -0
- package/dist/adapters/adapter-discovery-diagnostic.guidance.js +7 -0
- package/dist/adapters/adapter-field.d.ts +25 -11
- package/dist/adapters/adapter-identifier.d.ts +6 -6
- package/dist/adapters/adapter-model.d.ts +18 -9
- package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
- package/dist/adapters/adapter-operation.d.ts +3 -3
- package/dist/adapters/adapter-resource.d.ts +18 -9
- package/dist/adapters/adapter-sql-statement.d.ts +19 -0
- package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
- package/dist/adapters/adapter.interface.d.ts +59 -29
- package/dist/avz/avz-check.factory.d.ts +83 -0
- package/dist/avz/avz-check.factory.js +116 -0
- package/dist/avz/avz-check.registry.d.ts +35 -0
- package/dist/avz/avz-check.registry.js +9 -0
- package/dist/avz/avz.d.ts +203 -0
- package/dist/{json → avz}/avz.js +150 -8
- package/dist/{json → avz}/index.d.ts +2 -1
- package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
- package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
- package/dist/{json → avz}/zod-issue.translator.js +7 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
- package/dist/compiler/contract-compiler-diagnostic.guidance.d.ts +6 -0
- package/dist/compiler/contract-compiler-diagnostic.guidance.js +97 -0
- package/dist/compiler/contract.compiler.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +637 -442
- package/dist/compiler/create-requirements.projector.d.ts +49 -0
- package/dist/compiler/create-requirements.projector.js +423 -0
- package/dist/compiler/field-validator.compiler.d.ts +47 -0
- package/dist/compiler/field-validator.compiler.js +238 -0
- package/dist/config/any-framework-config.d.ts +19 -12
- package/dist/config/computed-fields.d.ts +62 -0
- package/dist/config/computed-fields.js +80 -0
- package/dist/config/config-diagnostic.d.ts +11 -4
- package/dist/config/config-diagnostic.guidance.d.ts +6 -0
- package/dist/config/config-diagnostic.guidance.js +32 -0
- package/dist/config/config-layer.d.ts +15 -6
- package/dist/config/config.resolver.d.ts +74 -31
- package/dist/config/config.resolver.js +108 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +581 -72
- package/dist/config/define-resource.d.ts +57 -0
- package/dist/config/define-resource.js +14 -0
- package/dist/config/effective-fields.d.ts +19 -23
- package/dist/config/entrypoint.normalizer.d.ts +1 -1
- package/dist/config/exact-framework-config.d.ts +308 -0
- package/dist/config/field-compute.resolver.d.ts +21 -0
- package/dist/config/field-compute.resolver.js +123 -0
- package/dist/config/field-pipeline-config.d.ts +47 -0
- package/dist/config/forced-operation.validator.d.ts +10 -0
- package/dist/config/forced-operation.validator.js +66 -0
- package/dist/config/framework-config.d.ts +111 -39
- package/dist/config/framework-exemptions-config.d.ts +91 -0
- package/dist/config/framework-exemptions-config.js +1 -0
- package/dist/config/framework-field-definition.d.ts +78 -0
- package/dist/config/framework-field-definition.js +28 -0
- package/dist/config/framework-resources-config.d.ts +122 -0
- package/dist/config/framework-resources-config.js +1 -0
- package/dist/config/pipeline-config.d.ts +56 -20
- package/dist/config/pipeline-tree.resolver.d.ts +79 -0
- package/dist/config/pipeline-tree.resolver.js +220 -0
- package/dist/config/stage-type.eraser.d.ts +65 -0
- package/dist/config/stage-type.eraser.js +1 -0
- package/dist/contracts/capability.d.ts +21 -12
- package/dist/contracts/capability.js +2 -0
- package/dist/contracts/client-contract-structure.validator.d.ts +388 -63
- package/dist/contracts/client-contract-structure.validator.js +156 -10
- package/dist/contracts/contract-canonicalizer.d.ts +26 -3
- package/dist/contracts/contract-canonicalizer.js +156 -29
- package/dist/contracts/contract-hash.d.ts +12 -7
- package/dist/contracts/contract-hash.js +3 -2
- package/dist/contracts/contract-limits.d.ts +4 -1
- package/dist/contracts/contract-limits.js +1 -0
- package/dist/contracts/contract-lookup.d.ts +5 -5
- package/dist/contracts/contract-protocol.d.ts +4 -4
- package/dist/contracts/contract.d.ts +24 -16
- package/dist/contracts/create-requirements.d.ts +35 -0
- package/dist/contracts/create-requirements.js +1 -0
- package/dist/contracts/enum-definition.d.ts +1 -1
- package/dist/contracts/field-check.d.ts +101 -0
- package/dist/contracts/field-check.js +1 -0
- package/dist/contracts/field.d.ts +81 -42
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-shape.d.ts +12 -1
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- package/dist/contracts/resource-operations.d.ts +28 -28
- package/dist/contracts/resource.d.ts +15 -9
- package/dist/contracts/scalar-value-type.d.ts +15 -15
- package/dist/contracts/scalar.d.ts +3 -3
- package/dist/contracts/transaction-capability.d.ts +1 -1
- package/dist/contracts/wire-scalar-format.d.ts +4 -4
- package/dist/framework/contract-view.d.ts +213 -147
- package/dist/framework/framework-construction.error.d.ts +19 -10
- package/dist/framework/framework-construction.error.js +7 -3
- package/dist/framework/framework.d.ts +47 -23
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +49 -22
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +57 -50
- package/dist/index.js +7 -6
- package/dist/internal.d.ts +17 -10
- package/dist/internal.js +4 -1
- package/dist/operations/database-refusal.d.ts +51 -0
- package/dist/operations/database-refusal.js +45 -0
- package/dist/operations/operation-arguments.d.ts +343 -207
- package/dist/operations/operation-call.d.ts +27 -28
- package/dist/operations/operation-identity.d.ts +10 -10
- package/dist/operations/operation-result.d.ts +21 -21
- package/dist/operations/operation-validator-core.d.ts +6 -6
- package/dist/operations/operation-validator-core.js +99 -6
- package/dist/operations/operation-validator.d.ts +9 -9
- package/dist/operations/projection-scope.resolver.d.ts +6 -6
- package/dist/operations/structural-limits.walker.d.ts +6 -6
- package/dist/operations/structural-limits.walker.js +145 -0
- package/dist/operations/validation-code.d.ts +11 -6
- package/dist/operations/validation-code.guidance.d.ts +6 -0
- package/dist/operations/validation-code.guidance.js +90 -0
- package/dist/operations/validation-code.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +10 -6
- package/dist/operations/write-scope.resolver.js +2 -0
- package/dist/protocol/absent-route.responder.d.ts +13 -12
- package/dist/protocol/absent-route.responder.js +19 -19
- package/dist/protocol/contract-document.responder.d.ts +3 -3
- package/dist/protocol/contract-document.responder.js +2 -2
- package/dist/protocol/http-request.decoder.d.ts +17 -13
- package/dist/protocol/http-request.decoder.js +10 -10
- package/dist/protocol/http-request.reader.d.ts +3 -3
- package/dist/protocol/http-response.encoder.d.ts +4 -4
- package/dist/protocol/http-response.encoder.js +94 -55
- package/dist/protocol/http-status.table.d.ts +2 -2
- package/dist/protocol/operation-response.guard.d.ts +2 -2
- package/dist/protocol/protocol-surface.d.ts +4 -4
- package/dist/protocol/protocol.binder.d.ts +50 -27
- package/dist/protocol/protocol.binder.js +12 -9
- package/dist/protocol/protocol.handler.d.ts +22 -13
- package/dist/protocol/protocol.handler.js +91 -17
- package/dist/protocol/unmounted-route.error.d.ts +4 -4
- package/dist/protocol/unmounted-route.error.js +2 -2
- package/dist/runtime/caller-data.copier.d.ts +22 -5
- package/dist/runtime/caller-data.copier.js +31 -14
- package/dist/runtime/caller-data.door.d.ts +17 -11
- package/dist/runtime/caller-data.door.js +6 -4
- package/dist/runtime/computed-read-runtime.d.ts +7 -6
- package/dist/runtime/computed-read-runtime.js +76 -50
- package/dist/runtime/computed-value.error.d.ts +7 -6
- package/dist/runtime/computed-value.error.js +5 -4
- package/dist/runtime/context-executor.runtime.d.ts +59 -0
- package/dist/runtime/context-executor.runtime.js +275 -0
- package/dist/runtime/create-requirement.d.ts +44 -79
- package/dist/runtime/create-requirement.js +213 -73
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +54 -27
- package/dist/runtime/diagnostics-reporter.js +24 -0
- package/dist/runtime/error-boundary.d.ts +65 -8
- package/dist/runtime/error-boundary.js +49 -19
- package/dist/runtime/error-guidance.d.ts +12 -0
- package/dist/runtime/error-guidance.js +1 -0
- package/dist/runtime/error.catalog.d.ts +49 -0
- package/dist/runtime/error.catalog.js +49 -0
- package/dist/runtime/execution-options.d.ts +10 -2
- package/dist/runtime/field-check.evaluator.d.ts +29 -0
- package/dist/runtime/field-check.evaluator.js +521 -0
- package/dist/runtime/field-compute.d.ts +64 -0
- package/dist/runtime/field-compute.js +1 -0
- package/dist/runtime/field-stage.plan.d.ts +15 -0
- package/dist/runtime/field-stage.plan.js +27 -0
- package/dist/runtime/field-stage.runtime.d.ts +37 -0
- package/dist/runtime/field-stage.runtime.js +147 -0
- package/dist/runtime/field-validator.runtime.d.ts +19 -0
- package/dist/runtime/field-validator.runtime.js +92 -0
- package/dist/runtime/framework-error-class.table.d.ts +33 -0
- package/dist/runtime/framework-error-class.table.js +25 -0
- package/dist/runtime/framework-error.d.ts +68 -8
- package/dist/runtime/framework-error.factory.d.ts +4 -0
- package/dist/runtime/framework-error.factory.js +15 -0
- package/dist/runtime/framework-error.js +23 -2
- package/dist/runtime/interceptor-next.error.d.ts +5 -0
- package/dist/runtime/interceptor-next.error.js +6 -0
- package/dist/runtime/json-value.d.ts +11 -6
- package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
- package/dist/runtime/level-lifecycle.runtime.js +39 -0
- package/dist/runtime/misuse-reporter.d.ts +12 -12
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +48 -35
- package/dist/runtime/nested-write.walker.d.ts +32 -0
- package/dist/runtime/nested-write.walker.js +73 -0
- package/dist/runtime/operation-code.guidance.d.ts +6 -0
- package/dist/runtime/operation-code.guidance.js +167 -0
- package/dist/runtime/operation-request.d.ts +33 -6
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +127 -25
- package/dist/runtime/operation-runtime.js +441 -78
- package/dist/runtime/outcome-mapper.d.ts +16 -5
- package/dist/runtime/outcome-mapper.js +23 -6
- package/dist/runtime/output-validator.d.ts +10 -10
- package/dist/runtime/output-validator.js +3 -3
- package/dist/runtime/owned-execution.registry.d.ts +16 -6
- package/dist/runtime/pipe-output.validator.d.ts +43 -18
- package/dist/runtime/pipe-output.validator.js +15 -13
- package/dist/runtime/pipeline.d.ts +223 -34
- package/dist/runtime/readonly-value.d.ts +43 -0
- package/dist/runtime/readonly-value.js +150 -0
- package/dist/runtime/request-envelope.validator.d.ts +3 -3
- package/dist/runtime/request-envelope.validator.js +12 -7
- package/dist/runtime/request-id.d.ts +1 -1
- package/dist/runtime/request-state.d.ts +14 -0
- package/dist/runtime/request-state.js +1 -0
- package/dist/runtime/request-state.resolver.d.ts +12 -0
- package/dist/runtime/request-state.resolver.js +20 -0
- package/dist/runtime/scalar-runtime.d.ts +35 -16
- package/dist/runtime/scalar-runtime.js +102 -34
- package/dist/runtime/unsent-value.normalizer.d.ts +15 -0
- package/dist/runtime/unsent-value.normalizer.js +128 -0
- package/dist/transactions/deferred-operation.d.ts +35 -20
- package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
- package/dist/transactions/operation-arguments-encoder.js +2 -2
- package/dist/transactions/operation-fingerprint.js +2 -2
- package/dist/transactions/sql-statement.d.ts +85 -0
- package/dist/transactions/sql-statement.js +47 -0
- package/dist/transactions/sql-statement.validator.d.ts +44 -0
- package/dist/transactions/sql-statement.validator.js +167 -0
- package/dist/transactions/transaction-envelope.d.ts +4 -4
- package/dist/transactions/transaction-integrity-error.d.ts +6 -6
- package/dist/transactions/transaction-integrity-error.js +5 -2
- package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
- package/dist/transactions/transaction-plan-assembler.js +169 -32
- package/dist/transactions/transaction-plan-validator.d.ts +45 -20
- package/dist/transactions/transaction-plan-validator.js +96 -38
- package/dist/transactions/transaction-reference-collector.d.ts +5 -5
- package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
- package/dist/transactions/transaction-reference-resolver.js +26 -14
- package/dist/transactions/transaction-reference-validator.d.ts +76 -4
- package/dist/transactions/transaction-reference-validator.js +129 -71
- package/dist/transactions/transaction-reference.d.ts +13 -13
- package/dist/transactions/transaction-reference.js +5 -0
- package/dist/transactions/transaction-request.d.ts +18 -5
- package/dist/transactions/transaction-response.d.ts +6 -6
- package/dist/transactions/transaction-runtime.d.ts +8 -7
- package/dist/transactions/transaction-runtime.js +191 -50
- package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
- package/dist/transactions/transaction-settlement.runtime.js +120 -0
- package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
- package/dist/transactions/transaction-slot-path-error.js +2 -2
- package/dist/transactions/transaction-slot-writer.js +2 -2
- package/dist/transactions/transaction-stage.runtime.d.ts +82 -0
- package/dist/transactions/transaction-stage.runtime.js +126 -0
- package/package.json +9 -7
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -42
- package/dist/config/define-fields.js +0 -3
- package/dist/config/framework-behaviors-config.d.ts +0 -30
- package/dist/config/framework-fields-config.d.ts +0 -42
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- package/dist/json/avz.d.ts +0 -96
- package/dist/runtime/field-behavior.d.ts +0 -48
- /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
- /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
- /package/dist/{json → avz}/index.js +0 -0
- /package/dist/{json → avz}/json-shape.registry.js +0 -0
- /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
- /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
|
@@ -1,28 +1,41 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel } from "../adapters/adapter-model.js";
|
|
2
|
+
import type { AvContracts } from "../compiler/contract.compiler.js";
|
|
3
|
+
import type { AvConfigAny } from "../config/any-framework-config.js";
|
|
4
|
+
import type { AvMcpEndpoint } from "../config/config.resolver.js";
|
|
4
5
|
import type { FrameworkOperationRequest } from "../runtime/operation-request.js";
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
6
|
+
import type { AvOperationResponse } from "../runtime/operation-response.js";
|
|
7
|
+
import type { AvTransactionRunner } from "../transactions/deferred-operation.js";
|
|
7
8
|
import type { FrameworkTransactionRequest } from "../transactions/transaction-request.js";
|
|
8
|
-
import type {
|
|
9
|
+
import type { AvTransactionResponse } from "../transactions/transaction-response.js";
|
|
9
10
|
import type { ApplicationOperations, ApplicationTransactionBuilders, ClientOperations, ClientTransactionBuilders } from "./operation-facade.js";
|
|
10
11
|
/**
|
|
11
12
|
* One Aventara instance, as returned by {@link createFramework}: its compiled
|
|
12
13
|
* Contracts, typed in-process operations, transaction builders and the
|
|
13
14
|
* untyped `execute` entry a transport calls.
|
|
14
15
|
*/
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
export type AvFramework<M extends AvAdapterModel = AvAdapterModel, Cfg = AvConfigAny> = {
|
|
17
|
+
/**
|
|
18
|
+
* The protocol's mount path (`api`) in its canonical form: `""` at the
|
|
19
|
+
* root, otherwise `/seg(/seg)*`.
|
|
20
|
+
*/
|
|
21
|
+
readonly api: string;
|
|
22
|
+
/**
|
|
23
|
+
* The MCP endpoint `mcp` turns on — its canonical mount path and its
|
|
24
|
+
* authorization — for the host that serves it; `undefined` when MCP is off.
|
|
25
|
+
*/
|
|
26
|
+
readonly mcp: AvMcpEndpoint | undefined;
|
|
27
|
+
readonly contracts: AvContracts;
|
|
18
28
|
/**
|
|
19
29
|
* Typed in-process operations under the Application Contract:
|
|
20
30
|
* `framework.application.<resource>.<family>.<variant>(args, options?)`.
|
|
21
31
|
*
|
|
22
32
|
* Typed from the Application Contract as configured: what the application's
|
|
23
|
-
*
|
|
24
|
-
* validated like any other request.
|
|
25
|
-
*
|
|
33
|
+
* exposure hides, denies or turns off is absent from the types, and a call is
|
|
34
|
+
* validated like any other request. A call resolves the operation's data (a
|
|
35
|
+
* first-style miss is `null`) and throws every failure as the `AvError`
|
|
36
|
+
* subclass of its code's class (`AvValidationError`, `AvNotFoundError`, …).
|
|
37
|
+
* The optional second argument is
|
|
38
|
+
* {@link AvExecutionOptions}.
|
|
26
39
|
*/
|
|
27
40
|
readonly application: ApplicationOperations<M, Cfg>;
|
|
28
41
|
/**
|
|
@@ -33,25 +46,33 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
|
|
|
33
46
|
* as from a generated client, and arguments are read in the wire
|
|
34
47
|
* forms a decoded request body carries, so a transport can pass `req.body` as
|
|
35
48
|
* it is. Each call runs the client pipelines and the same validation as a
|
|
36
|
-
* remote request
|
|
49
|
+
* remote request, and settles like an application call: the data, or the
|
|
50
|
+
* failure thrown.
|
|
37
51
|
*/
|
|
38
52
|
readonly client: ClientOperations<M, Cfg>;
|
|
39
53
|
/**
|
|
40
54
|
* Transaction builders under application rules:
|
|
41
55
|
* `framework.appTx.<resource>.<family>.<variant>(args)` defers one operation
|
|
42
|
-
* into a handle typed `
|
|
56
|
+
* into a handle typed `AvOperation<AvOperationResultFor<…>>` from the Application
|
|
43
57
|
* Contract's view, and runs nothing. A handle exposes `$ref(field)` exactly
|
|
44
58
|
* where its result is one row; the reference is bound to the handle, and its
|
|
45
59
|
* index is bound when {@link transaction} runs the list it is in.
|
|
60
|
+
*
|
|
61
|
+
* `framework.appTx.$sql` defers a developer SQL step, written only as a tagged
|
|
62
|
+
* template whose every interpolated value is bound as a parameter (a `$ref`
|
|
63
|
+
* among them, resolved when the earlier steps have run). It runs in plan order
|
|
64
|
+
* in the same database transaction, with no pipelines around it; its entry in
|
|
65
|
+
* the committed data is its rows, typed by `appTx.$sql<Row>`. It exists only
|
|
66
|
+
* here: `clientTx`, the Client Contract and `/_transactions` have no SQL step.
|
|
46
67
|
*/
|
|
47
68
|
readonly appTx: ApplicationTransactionBuilders<M, Cfg>;
|
|
48
69
|
/**
|
|
49
70
|
* The same builders under ClientContract rules, taking wire-form arguments.
|
|
50
|
-
*
|
|
51
|
-
*
|
|
71
|
+
* A {@link transaction} has one origin: client and application handles never
|
|
72
|
+
* share one (`A2004`/`V1020` at the first step of the other origin).
|
|
52
73
|
*/
|
|
53
74
|
readonly clientTx: ClientTransactionBuilders<M, Cfg>;
|
|
54
|
-
execute(request: FrameworkOperationRequest): Promise<
|
|
75
|
+
execute(request: FrameworkOperationRequest): Promise<AvOperationResponse>;
|
|
55
76
|
/**
|
|
56
77
|
* Validates a whole transaction plan, then runs its operations one after
|
|
57
78
|
* another inside one Adapter transaction. Answers `A1009` with each
|
|
@@ -62,15 +83,18 @@ export type Framework<M extends AdapterModel = AdapterModel, Cfg = AnyFrameworkC
|
|
|
62
83
|
* Guards, pipes, hooks and interceptors run while the transaction is open, so
|
|
63
84
|
* they should not perform network I/O or other slow work.
|
|
64
85
|
*/
|
|
65
|
-
executeTransaction(request: FrameworkTransactionRequest): Promise<
|
|
86
|
+
executeTransaction(request: FrameworkTransactionRequest): Promise<AvTransactionResponse>;
|
|
66
87
|
/**
|
|
67
88
|
* Runs handles from `appTx`/`clientTx` as one transaction:
|
|
68
|
-
* `framework.transaction([h1, h2, …], options?)`. Resolves
|
|
69
|
-
*
|
|
89
|
+
* `framework.transaction([h1, h2, …], options?)`. Resolves each handle's
|
|
90
|
+
* result in plan order, typed per position, once the transaction committed,
|
|
91
|
+
* or throws the failure as the `AvError` subclass of its code's class, with
|
|
92
|
+
* `cause.operation` naming the failing step.
|
|
70
93
|
*
|
|
71
94
|
* Refused before anything runs: an entry that is not one of this Framework's
|
|
72
|
-
* handles, or the same handle twice (`A2004`/`V1001`);
|
|
73
|
-
*
|
|
95
|
+
* handles, or the same handle twice (`A2004`/`V1001`); `appTx` and `clientTx`
|
|
96
|
+
* handles in one list (`A2004`/`V1020`); a `$ref` to a handle not in the list
|
|
97
|
+
* (`A2007`/`V1010`).
|
|
74
98
|
*/
|
|
75
|
-
readonly transaction:
|
|
99
|
+
readonly transaction: AvTransactionRunner;
|
|
76
100
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel } from "../adapters/adapter-model.js";
|
|
2
|
+
import type { AvConfigAny } from "../config/any-framework-config.js";
|
|
3
|
+
import type { AvConfigExact } from "../config/exact-framework-config.js";
|
|
4
|
+
import type { AvConfig } from "../config/framework-config.js";
|
|
5
|
+
import type { ErasedConfig } from "../config/stage-type.eraser.js";
|
|
6
|
+
import type { AvFramework } from "./framework.js";
|
|
5
7
|
/**
|
|
6
8
|
* Creates a Framework: validates the configuration, reads the adapter's
|
|
7
9
|
* model and compiles the Contracts.
|
|
8
10
|
*
|
|
9
|
-
* @throws {@link
|
|
11
|
+
* @throws {@link AvConstructionError} when any of those steps fails.
|
|
10
12
|
*/
|
|
11
|
-
export declare function createFramework<M extends
|
|
13
|
+
export declare function createFramework<M extends AvAdapterModel, const Cfg = AvConfigAny>(config: Cfg & AvConfigExact<M, Cfg> & AvConfig<M, Cfg>): Promise<AvFramework<M, ErasedConfig<Cfg>>>;
|
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
import { compileContracts } from "../compiler/contract.compiler.js";
|
|
2
|
+
import { computedFieldsOf, warnOnStaleComputedFields, } from "../config/computed-fields.js";
|
|
2
3
|
import { resolveFrameworkConfig } from "../config/config.resolver.js";
|
|
3
4
|
import { validateFrameworkConfig } from "../config/config.validator.js";
|
|
5
|
+
import { validateForcedOperations } from "../config/forced-operation.validator.js";
|
|
4
6
|
import { AVENTARA_PROTOCOL_VERSION } from "../contracts/contract-protocol.js";
|
|
5
7
|
import { copyEnvelopeAtDoor, refuseCallerData, } from "../runtime/caller-data.door.js";
|
|
6
8
|
import { createDiagnosticsReporter, createTransactionDiagnosticsChannel, recordDiagnosticsSink, } from "../runtime/diagnostics-reporter.js";
|
|
7
9
|
import { createMisuseReporter, } from "../runtime/misuse-reporter.js";
|
|
8
10
|
import { internalFailure, operationFailure, } from "../runtime/operation-response.js";
|
|
9
|
-
import { createOperationRuntime } from "../runtime/operation-runtime.js";
|
|
11
|
+
import { createOperationRuntime, createPipelineDependencies, } from "../runtime/operation-runtime.js";
|
|
10
12
|
import { recordOwnedExecution } from "../runtime/owned-execution.registry.js";
|
|
11
13
|
import { validateOperationEnvelope, validateTransactionEnvelope, } from "../runtime/request-envelope.validator.js";
|
|
12
14
|
import { requestIdOf } from "../runtime/request-id.js";
|
|
15
|
+
import { stateOptionOf } from "../runtime/request-state.resolver.js";
|
|
13
16
|
import { createTransactionPlanAssembler } from "../transactions/transaction-plan-assembler.js";
|
|
14
17
|
import { createTransactionRuntime } from "../transactions/transaction-runtime.js";
|
|
15
|
-
import {
|
|
16
|
-
import { createOperationFacade, createOperationTree, } from "./operation-facade.js";
|
|
18
|
+
import { AvConstructionError } from "./framework-construction.error.js";
|
|
19
|
+
import { createOperationFacade, createOperationTree, settleOperation, } from "./operation-facade.js";
|
|
20
|
+
const APPLICATION_SQL_BUILDER = "$sql";
|
|
17
21
|
export async function createFramework(config) {
|
|
18
22
|
const configDiagnostics = validateFrameworkConfig(config);
|
|
19
23
|
if (configDiagnostics.length > 0) {
|
|
20
|
-
throw new
|
|
24
|
+
throw new AvConstructionError("configuration", configDiagnostics);
|
|
21
25
|
}
|
|
22
26
|
const model = config.adapter.model;
|
|
23
27
|
if (model.transactions === "interactive" &&
|
|
24
28
|
typeof config.adapter.transaction !== "function") {
|
|
25
|
-
throw new
|
|
29
|
+
throw new AvConstructionError("discovery", [
|
|
26
30
|
{
|
|
27
31
|
code: "DISCOVERY_TRANSACTION_CAPABILITY_MISMATCH",
|
|
28
32
|
path: "adapter.transactions",
|
|
@@ -31,20 +35,26 @@ export async function createFramework(config) {
|
|
|
31
35
|
]);
|
|
32
36
|
}
|
|
33
37
|
const resolvedConfig = resolveFrameworkConfig(config);
|
|
38
|
+
warnOnStaleComputedFields(config.adapter.computedFields, computedFieldsOf({
|
|
39
|
+
trees: resolvedConfig.trees,
|
|
40
|
+
agentExtends: resolvedConfig.agent.parent,
|
|
41
|
+
}));
|
|
34
42
|
const compilation = await compileContracts(model, resolvedConfig);
|
|
35
43
|
if (!compilation.ok) {
|
|
36
|
-
throw new
|
|
44
|
+
throw new AvConstructionError("contract-compilation", compilation.diagnostics);
|
|
37
45
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const executeTransaction = createTransactionRuntime({
|
|
46
|
+
const forcing = validateForcedOperations(config, compilation.contracts);
|
|
47
|
+
if (forcing.length > 0) {
|
|
48
|
+
throw new AvConstructionError("configuration", forcing);
|
|
49
|
+
}
|
|
50
|
+
const runtimeDependencies = {
|
|
44
51
|
adapter: config.adapter,
|
|
45
52
|
contracts: compilation.contracts,
|
|
46
53
|
config: resolvedConfig,
|
|
47
|
-
}
|
|
54
|
+
};
|
|
55
|
+
const pipelineDependencies = createPipelineDependencies(runtimeDependencies, model);
|
|
56
|
+
const execute = createOperationRuntime(runtimeDependencies, pipelineDependencies);
|
|
57
|
+
const executeTransaction = createTransactionRuntime(runtimeDependencies, pipelineDependencies);
|
|
48
58
|
const misuse = createMisuseReporter(resolvedConfig.misuse);
|
|
49
59
|
const executeOperation = (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "caller");
|
|
50
60
|
const protocol = {
|
|
@@ -53,33 +63,41 @@ export async function createFramework(config) {
|
|
|
53
63
|
};
|
|
54
64
|
const assembler = createTransactionPlanAssembler(compilation.contracts, protocol, misuse);
|
|
55
65
|
const framework = {
|
|
56
|
-
|
|
66
|
+
api: resolvedConfig.api,
|
|
67
|
+
mcp: resolvedConfig.mcp,
|
|
57
68
|
contracts: compilation.contracts,
|
|
58
|
-
application: createOperationFacade(model, (resource, identity, args, requestId) => ({
|
|
69
|
+
application: createOperationFacade(model, (resource, identity, args, requestId, state) => ({
|
|
59
70
|
...identity,
|
|
60
71
|
origin: "application",
|
|
61
72
|
requestId,
|
|
73
|
+
...(state === undefined ? {} : { state }),
|
|
62
74
|
resource,
|
|
63
75
|
arguments: args,
|
|
64
76
|
}), executeOperation),
|
|
65
|
-
client: createOperationFacade(model, (resource, identity, args, requestId) => ({
|
|
77
|
+
client: createOperationFacade(model, (resource, identity, args, requestId, state) => ({
|
|
66
78
|
...identity,
|
|
67
79
|
origin: "client",
|
|
68
80
|
protocol,
|
|
69
81
|
requestId,
|
|
82
|
+
...(state === undefined ? {} : { state }),
|
|
70
83
|
resource,
|
|
71
84
|
arguments: args,
|
|
72
85
|
}), executeOperation),
|
|
73
|
-
appTx:
|
|
86
|
+
appTx: Object.freeze({
|
|
87
|
+
...createOperationTree(model, (resource, identity) => (args) => assembler.defer("application", resource, identity, args === undefined ? {} : args)),
|
|
88
|
+
[APPLICATION_SQL_BUILDER]: (strings, ...values) => assembler.deferSql(strings, values),
|
|
89
|
+
}),
|
|
74
90
|
clientTx: createOperationTree(model, (resource, identity) => (args) => assembler.defer("client", resource, identity, args === undefined ? {} : args)),
|
|
75
91
|
execute: (request) => executeRequestTotally(execute, request, resolvedConfig.diagnostics, misuse),
|
|
76
92
|
executeTransaction: (request) => executeTransactionRequestTotally(executeTransaction, request, resolvedConfig.diagnostics, misuse),
|
|
77
|
-
transaction: ((operations, options) => runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), resolvedConfig.diagnostics)),
|
|
93
|
+
transaction: (async (operations, options) => settleOperation(await runTransactionTotally(executeTransaction, assembler, operations, requestIdOf(options), stateOptionOf(options), resolvedConfig.diagnostics))),
|
|
78
94
|
};
|
|
79
95
|
recordDiagnosticsSink(framework, resolvedConfig.diagnostics);
|
|
80
96
|
recordOwnedExecution(framework, {
|
|
81
|
-
execute: (request) => executeTotally(execute, request, resolvedConfig.diagnostics, "owned"),
|
|
82
|
-
executeTransaction: (request) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics, undefined,
|
|
97
|
+
execute: (request, refused) => executeTotally(execute, request, resolvedConfig.diagnostics, refused === undefined ? "owned" : { refused }),
|
|
98
|
+
executeTransaction: (request, refused) => executeTransactionTotally(executeTransaction, request, resolvedConfig.diagnostics, undefined, refused === undefined
|
|
99
|
+
? { source: "owned" }
|
|
100
|
+
: { source: "owned", refused }),
|
|
83
101
|
});
|
|
84
102
|
return framework;
|
|
85
103
|
}
|
|
@@ -138,7 +156,7 @@ async function executeTransactionTotally(execute, request, diagnostics, origins,
|
|
|
138
156
|
return internalFailure();
|
|
139
157
|
}
|
|
140
158
|
}
|
|
141
|
-
async function runTransactionTotally(execute, assembler, operations, requestId, diagnostics) {
|
|
159
|
+
async function runTransactionTotally(execute, assembler, operations, requestId, state, diagnostics) {
|
|
142
160
|
let assembled;
|
|
143
161
|
try {
|
|
144
162
|
assembled = await assembler.assemble(operations);
|
|
@@ -154,5 +172,14 @@ async function runTransactionTotally(execute, assembler, operations, requestId,
|
|
|
154
172
|
if (!assembled.ok) {
|
|
155
173
|
return assembled.response;
|
|
156
174
|
}
|
|
157
|
-
return executeTransactionTotally(execute, {
|
|
175
|
+
return executeTransactionTotally(execute, {
|
|
176
|
+
origin: "application",
|
|
177
|
+
requestId,
|
|
178
|
+
...(state === undefined ? {} : { state }),
|
|
179
|
+
plan: assembled.plan,
|
|
180
|
+
}, diagnostics, assembled.origins, {
|
|
181
|
+
source: "owned",
|
|
182
|
+
refused: assembled.refused,
|
|
183
|
+
statements: assembled.statements,
|
|
184
|
+
});
|
|
158
185
|
}
|
|
@@ -1,72 +1,137 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel } from "../adapters/adapter-model.js";
|
|
2
|
+
import type { AvContract } from "../contracts/contract.js";
|
|
3
|
+
import type { AvApplicationScalarForms, AvWireScalarForms } from "../contracts/scalar-value-type.js";
|
|
4
|
+
import type { AvResourceKey } from "../operations/operation-arguments.js";
|
|
5
|
+
import type { AvDeferredOperationCall, AvOperationCall, AvOperationGrammar } from "../operations/operation-call.js";
|
|
6
|
+
import type { AvOperationIdentity } from "../operations/operation-identity.js";
|
|
7
|
+
import type { AvExecutionOptions } from "../runtime/execution-options.js";
|
|
8
8
|
import type { FrameworkOperationRequest } from "../runtime/operation-request.js";
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
9
|
+
import type { AvOperationResponse } from "../runtime/operation-response.js";
|
|
10
|
+
import type { AvState } from "../runtime/request-state.js";
|
|
11
|
+
import type { SqlStatementBuilder } from "../transactions/sql-statement.js";
|
|
12
|
+
import type { AvTransactionResponse } from "../transactions/transaction-response.js";
|
|
13
|
+
import type { AvContractApplicationView, ClientContractView } from "./contract-view.js";
|
|
11
14
|
/**
|
|
12
|
-
* A model whose Resource names are not literal — the abstract `
|
|
13
|
-
* the default `
|
|
15
|
+
* A model whose Resource names are not literal — the abstract `AvAdapterModel` behind
|
|
16
|
+
* the default `AvFramework` — has no Contract to type a call against, so a surface over
|
|
14
17
|
* it is typed as the opaque object it is, and such a caller uses `execute`.
|
|
15
18
|
*/
|
|
16
19
|
type OpaqueSurface = {
|
|
17
20
|
readonly [resource: string]: unknown;
|
|
18
21
|
};
|
|
22
|
+
/** The four typed surfaces of an `AvFramework`, named by the member that holds each. */
|
|
23
|
+
type FacadeSurface = "application" | "client" | "appTx" | "clientTx";
|
|
19
24
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
25
|
+
* One variant on a surface: a direct call (application or wire forms), or a
|
|
26
|
+
* deferred one for a transaction (`appTx`, `clientTx`).
|
|
22
27
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
type SurfaceCall<C extends AvContract, R extends AvResourceKey<C>, I extends AvOperationIdentity, S extends FacadeSurface> = S extends "application" ? AvOperationCall<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms, AvExecutionOptions> : S extends "client" ? AvOperationCall<C, R, I, AvWireScalarForms, AvApplicationScalarForms, AvExecutionOptions> : S extends "appTx" ? AvDeferredOperationCall<C, R, I, AvApplicationScalarForms, AvApplicationScalarForms, "application"> : AvDeferredOperationCall<C, R, I, AvWireScalarForms, AvApplicationScalarForms, "client">;
|
|
29
|
+
/** The families view `C` advertises on Resource `R`. */
|
|
30
|
+
type FamilyKey<C extends AvContract, R extends AvResourceKey<C>> = keyof AvOperationGrammar<C>[R];
|
|
31
|
+
/** One family node of surface `S`; the public names below are its four instances. */
|
|
32
|
+
type FamilyNode<C extends AvContract, S extends FacadeSurface, R extends AvResourceKey<C>, F extends FamilyKey<C, R>> = {
|
|
33
|
+
readonly [V in keyof AvOperationGrammar<C>[R][F]]: SurfaceCall<C, R, AvOperationGrammar<C>[R][F][V] & AvOperationIdentity, S>;
|
|
34
|
+
};
|
|
35
|
+
/** `framework.application.<Resource>.<family>`: one direct call per variant, application forms. */
|
|
36
|
+
export type AvApplicationFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "application", R, F>;
|
|
37
|
+
/** `framework.client.<Resource>.<family>`: one direct call per variant, wire forms. */
|
|
38
|
+
export type AvClientFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "client", R, F>;
|
|
39
|
+
/** `framework.appTx.<Resource>.<family>`: one deferred operation per variant. */
|
|
40
|
+
export type AvAppTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "appTx", R, F>;
|
|
41
|
+
/** `framework.clientTx.<Resource>.<family>`: one deferred operation per variant. */
|
|
42
|
+
export type AvClientTxFamilyFacade<in out C extends AvContract, in out R extends AvResourceKey<C>, in out F extends FamilyKey<C, R>> = FamilyNode<C, "clientTx", R, F>;
|
|
43
|
+
/** `framework.application.<Resource>`: one {@link AvApplicationFamilyFacade} per family. */
|
|
44
|
+
export type AvApplicationResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
|
|
45
|
+
readonly [F in FamilyKey<C, R>]: AvApplicationFamilyFacade<C, R, F>;
|
|
46
|
+
};
|
|
47
|
+
/** `framework.client.<Resource>`: one {@link AvClientFamilyFacade} per family. */
|
|
48
|
+
export type AvClientResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
|
|
49
|
+
readonly [F in FamilyKey<C, R>]: AvClientFamilyFacade<C, R, F>;
|
|
50
|
+
};
|
|
51
|
+
/** `framework.appTx.<Resource>`: one {@link AvAppTxFamilyFacade} per family. */
|
|
52
|
+
export type AvAppTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
|
|
53
|
+
readonly [F in FamilyKey<C, R>]: AvAppTxFamilyFacade<C, R, F>;
|
|
54
|
+
};
|
|
55
|
+
/** `framework.clientTx.<Resource>`: one {@link AvClientTxFamilyFacade} per family. */
|
|
56
|
+
export type AvClientTxResourceFacade<in out C extends AvContract, in out R extends AvResourceKey<C>> = {
|
|
57
|
+
readonly [F in FamilyKey<C, R>]: AvClientTxFamilyFacade<C, R, F>;
|
|
58
|
+
};
|
|
31
59
|
/**
|
|
32
|
-
* `framework.
|
|
33
|
-
* the
|
|
60
|
+
* `framework.application`: one {@link AvApplicationResourceFacade} per Resource
|
|
61
|
+
* of `C`, the Application Contract's view.
|
|
34
62
|
*/
|
|
35
|
-
export type
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
readonly [F in keyof OperationGrammar<C>[R]]: {
|
|
39
|
-
readonly [V in keyof OperationGrammar<C>[R][F]]: OperationCall<C, R, OperationGrammar<C>[R][F][V] & OperationIdentity, WireScalarForms, ApplicationScalarForms, "response", ExecutionOptions>;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
} : never;
|
|
63
|
+
export type AvApplicationFacade<C extends AvContract> = {
|
|
64
|
+
readonly [R in AvResourceKey<C>]: AvApplicationResourceFacade<C, R>;
|
|
65
|
+
};
|
|
43
66
|
/**
|
|
44
|
-
* `framework.
|
|
45
|
-
* Contract's view
|
|
67
|
+
* `framework.client`: one {@link AvClientResourceFacade} per Resource of `C`,
|
|
68
|
+
* the Client Contract's view.
|
|
46
69
|
*/
|
|
47
|
-
export type
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
export type AvClientFacade<C extends AvContract> = {
|
|
71
|
+
readonly [R in AvResourceKey<C>]: AvClientResourceFacade<C, R>;
|
|
72
|
+
};
|
|
73
|
+
/** `framework.appTx.$sql`: the developer SQL step only an application transaction has. */
|
|
74
|
+
type ApplicationSqlStep = {
|
|
75
|
+
/**
|
|
76
|
+
* A developer SQL step, written only as a tagged template:
|
|
77
|
+
* ``framework.appTx.$sql<Row>`select … ${value}` ``. Every interpolated value
|
|
78
|
+
* is bound as a parameter. See {@link SqlStatementBuilder}.
|
|
79
|
+
*/
|
|
80
|
+
readonly $sql: SqlStatementBuilder;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* `framework.appTx`: one {@link AvAppTxResourceFacade} per Resource of `C`, the
|
|
84
|
+
* Application Contract's view, and `$sql`.
|
|
85
|
+
*/
|
|
86
|
+
export type AvAppTxFacade<C extends AvContract> = {
|
|
87
|
+
readonly [R in AvResourceKey<C>]: AvAppTxResourceFacade<C, R>;
|
|
88
|
+
} & ApplicationSqlStep;
|
|
89
|
+
/**
|
|
90
|
+
* `framework.clientTx`: one {@link AvClientTxResourceFacade} per Resource of
|
|
91
|
+
* `C`, the Client Contract's view.
|
|
92
|
+
*/
|
|
93
|
+
export type AvClientTxFacade<C extends AvContract> = {
|
|
94
|
+
readonly [R in AvResourceKey<C>]: AvClientTxResourceFacade<C, R>;
|
|
95
|
+
};
|
|
96
|
+
type ApplicationSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvApplicationFacade<C> : never;
|
|
97
|
+
type ClientSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvClientFacade<C> : never;
|
|
98
|
+
type ApplicationDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface & ApplicationSqlStep : AvAppTxFacade<C> : never;
|
|
99
|
+
type ClientDeferredSurface<C> = C extends AvContract ? string extends AvResourceKey<C> ? OpaqueSurface : AvClientTxFacade<C> : never;
|
|
100
|
+
/** `framework.application`'s type: {@link AvApplicationFacade}, or opaque. */
|
|
101
|
+
export type ApplicationOperations<M extends AvAdapterModel, Cfg> = ApplicationSurface<AvContractApplicationView<M, Cfg>>;
|
|
102
|
+
/** `framework.client`'s type: {@link AvClientFacade}, or opaque. */
|
|
103
|
+
export type ClientOperations<M extends AvAdapterModel, Cfg> = ClientSurface<ClientContractView<M, Cfg>>;
|
|
104
|
+
/** `framework.appTx`'s type: {@link AvAppTxFacade}, or opaque with `$sql`. */
|
|
105
|
+
export type ApplicationTransactionBuilders<M extends AvAdapterModel, Cfg> = ApplicationDeferredSurface<AvContractApplicationView<M, Cfg>>;
|
|
106
|
+
/** `framework.clientTx`'s type: {@link AvClientTxFacade}, or opaque. */
|
|
107
|
+
export type ClientTransactionBuilders<M extends AvAdapterModel, Cfg> = ClientDeferredSurface<ClientContractView<M, Cfg>>;
|
|
108
|
+
/**
|
|
109
|
+
* The Resources of a pipeline ctx: `ctx.<Resource>.<family>.<variant>(args)`,
|
|
110
|
+
* application-origin, resolving the operation's data.
|
|
111
|
+
*/
|
|
112
|
+
export type AvContextOperations<M extends AvAdapterModel> = ContextFacade<AvContractApplicationView<M>>;
|
|
113
|
+
type ContextFacade<C> = C extends AvContract ? string extends AvResourceKey<C> ? unknown : {
|
|
114
|
+
readonly [R in AvResourceKey<C>]: {
|
|
115
|
+
readonly [F in keyof AvOperationGrammar<C>[R]]: {
|
|
116
|
+
readonly [V in keyof AvOperationGrammar<C>[R][F]]: AvOperationCall<C, R, AvOperationGrammar<C>[R][F][V] & AvOperationIdentity, AvApplicationScalarForms, AvApplicationScalarForms, never>;
|
|
52
117
|
};
|
|
53
118
|
};
|
|
54
119
|
} : never;
|
|
55
120
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
121
|
+
* The Resources of compute's read-only ctx: `ctx.<Resource>.find.<variant>(args)`
|
|
122
|
+
* only (`find.count` included).
|
|
58
123
|
*/
|
|
59
|
-
export type
|
|
60
|
-
type
|
|
61
|
-
readonly [R in
|
|
62
|
-
readonly [F in keyof
|
|
63
|
-
readonly [V in keyof
|
|
124
|
+
export type AvComputeReads<M extends AvAdapterModel> = ComputeReadFacade<AvContractApplicationView<M>>;
|
|
125
|
+
type ComputeReadFacade<C> = C extends AvContract ? string extends AvResourceKey<C> ? unknown : {
|
|
126
|
+
readonly [R in AvResourceKey<C>]: {
|
|
127
|
+
readonly [F in Extract<keyof AvOperationGrammar<C>[R], "find">]: {
|
|
128
|
+
readonly [V in keyof AvOperationGrammar<C>[R][F]]: AvOperationCall<C, R, AvOperationGrammar<C>[R][F][V] & AvOperationIdentity, AvApplicationScalarForms, AvApplicationScalarForms, never>;
|
|
64
129
|
};
|
|
65
130
|
};
|
|
66
131
|
} : never;
|
|
67
|
-
/** Builds the request one façade call hands to `execute`, under its request id. */
|
|
68
|
-
export type FacadeRequest = (resource: string, identity:
|
|
69
|
-
type FacadeExecutor = (request: FrameworkOperationRequest) => Promise<
|
|
132
|
+
/** Builds the request one façade call hands to `execute`, under its request id and state. */
|
|
133
|
+
export type FacadeRequest = (resource: string, identity: AvOperationIdentity, args: unknown, requestId: string, state: AvState | undefined) => FrameworkOperationRequest;
|
|
134
|
+
type FacadeExecutor = (request: FrameworkOperationRequest) => Promise<AvOperationResponse>;
|
|
70
135
|
/**
|
|
71
136
|
* Builds a façade over `model`, the same object its types are read from, so a
|
|
72
137
|
* call that type-checks always reaches `execute`: a Resource, variant or field
|
|
@@ -74,20 +139,26 @@ type FacadeExecutor = (request: FrameworkOperationRequest) => Promise<OperationR
|
|
|
74
139
|
* validation layer answers it.
|
|
75
140
|
*
|
|
76
141
|
* Each call's request is `request`'s — its origin — under the caller's
|
|
77
|
-
* `
|
|
142
|
+
* `AvExecutionOptions.requestId`, or a freshly minted id when there is none, and
|
|
143
|
+
* with the caller's `AvExecutionOptions.state` when it gives one; an
|
|
78
144
|
* omitted argument is the empty argument object, which the type admits only
|
|
79
145
|
* when every member is optional.
|
|
80
146
|
*/
|
|
81
|
-
export declare function createOperationFacade<Facade>(model:
|
|
147
|
+
export declare function createOperationFacade<Facade>(model: AvAdapterModel, request: FacadeRequest, execute: FacadeExecutor): Facade;
|
|
148
|
+
/**
|
|
149
|
+
* An in-process call's settlement (a façade call or `framework.transaction`):
|
|
150
|
+
* the response's data, or its failure thrown.
|
|
151
|
+
*/
|
|
152
|
+
export declare function settleOperation(response: AvOperationResponse | AvTransactionResponse): unknown;
|
|
82
153
|
/**
|
|
83
154
|
* One leaf of an operation tree: the callable for one advertised variant. The
|
|
84
155
|
* second parameter is a façade call's options; a builder leaf ignores it.
|
|
85
156
|
*/
|
|
86
|
-
export type OperationLeaf = (resource: string, identity:
|
|
157
|
+
export type OperationLeaf = (resource: string, identity: AvOperationIdentity) => (args?: unknown, options?: unknown) => unknown;
|
|
87
158
|
/**
|
|
88
159
|
* The runtime shape every façade and builder shares: one frozen property per
|
|
89
160
|
* Resource of `model`, one per family under it, one leaf per variant the model
|
|
90
161
|
* advertises in the standard grammar.
|
|
91
162
|
*/
|
|
92
|
-
export declare function createOperationTree<Tree>(model:
|
|
163
|
+
export declare function createOperationTree<Tree>(model: AvAdapterModel, leaf: OperationLeaf): Tree;
|
|
93
164
|
export {};
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { isOperationVariantAvailable } from "../contracts/resource-operations.js";
|
|
2
2
|
import { parseOperationIdentity } from "../operations/operation-identity.js";
|
|
3
|
+
import { thrownFailure } from "../runtime/framework-error.factory.js";
|
|
3
4
|
import { requestIdOf } from "../runtime/request-id.js";
|
|
5
|
+
import { stateOptionOf } from "../runtime/request-state.resolver.js";
|
|
4
6
|
export function createOperationFacade(model, request, execute) {
|
|
5
|
-
return createOperationTree(model, (resource, identity) => (args, options) => execute(request(resource, identity, args === undefined ? {} : args, requestIdOf(options))));
|
|
7
|
+
return createOperationTree(model, (resource, identity) => async (args, options) => settleOperation(await execute(request(resource, identity, args === undefined ? {} : args, requestIdOf(options), stateOptionOf(options)))));
|
|
8
|
+
}
|
|
9
|
+
export function settleOperation(response) {
|
|
10
|
+
if (response.cause !== null) {
|
|
11
|
+
throw thrownFailure(response);
|
|
12
|
+
}
|
|
13
|
+
return response.data;
|
|
6
14
|
}
|
|
7
15
|
export function createOperationTree(model, leaf) {
|
|
8
16
|
const resources = Object.entries(model.resources).map(([resource, { operations }]) => {
|