@aventara/core 1.0.0-rc.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1140 -0
- package/README.md +224 -57
- package/dist/adapters/adapter-discovery-diagnostic.d.ts +4 -4
- package/dist/adapters/adapter-field.d.ts +11 -11
- package/dist/adapters/adapter-identifier.d.ts +6 -6
- package/dist/adapters/adapter-model.d.ts +9 -9
- package/dist/adapters/adapter-operation-executor.interface.d.ts +4 -4
- package/dist/adapters/adapter-operation.d.ts +3 -3
- package/dist/adapters/adapter-resource.d.ts +18 -9
- package/dist/adapters/adapter-sql-statement.d.ts +19 -0
- package/dist/adapters/adapter-transaction-executor.interface.d.ts +19 -0
- package/dist/adapters/adapter.interface.d.ts +49 -29
- package/dist/avz/avz-check.factory.d.ts +83 -0
- package/dist/avz/avz-check.factory.js +116 -0
- package/dist/avz/avz-check.registry.d.ts +35 -0
- package/dist/avz/avz-check.registry.js +9 -0
- package/dist/avz/avz.d.ts +203 -0
- package/dist/{json → avz}/avz.js +150 -8
- package/dist/{json → avz}/index.d.ts +2 -1
- package/dist/{json → avz}/json-shape.registry.d.ts +7 -7
- package/dist/{json → avz}/zod-issue.translator.d.ts +8 -2
- package/dist/{json → avz}/zod-issue.translator.js +7 -0
- package/dist/compiler/contract-compiler-diagnostic.d.ts +31 -5
- package/dist/compiler/contract.compiler.d.ts +18 -18
- package/dist/compiler/contract.compiler.js +548 -441
- package/dist/compiler/create-requirements.projector.d.ts +49 -0
- package/dist/compiler/create-requirements.projector.js +423 -0
- package/dist/compiler/field-validator.compiler.d.ts +47 -0
- package/dist/compiler/field-validator.compiler.js +238 -0
- package/dist/config/any-framework-config.d.ts +19 -12
- package/dist/config/config-diagnostic.d.ts +11 -4
- package/dist/config/config-layer.d.ts +15 -6
- package/dist/config/config.resolver.d.ts +74 -31
- package/dist/config/config.resolver.js +108 -44
- package/dist/config/config.validator.d.ts +7 -7
- package/dist/config/config.validator.js +581 -72
- package/dist/config/define-resource.d.ts +57 -0
- package/dist/config/define-resource.js +14 -0
- package/dist/config/effective-fields.d.ts +19 -23
- package/dist/config/entrypoint.normalizer.d.ts +1 -1
- package/dist/config/exact-framework-config.d.ts +280 -0
- package/dist/config/field-compute.resolver.d.ts +19 -0
- package/dist/config/field-compute.resolver.js +115 -0
- package/dist/config/field-pipeline-config.d.ts +47 -0
- package/dist/config/forced-operation.validator.d.ts +10 -0
- package/dist/config/forced-operation.validator.js +66 -0
- package/dist/config/framework-config.d.ts +110 -39
- package/dist/config/framework-exemptions-config.d.ts +91 -0
- package/dist/config/framework-exemptions-config.js +1 -0
- package/dist/config/framework-field-definition.d.ts +78 -0
- package/dist/config/framework-field-definition.js +28 -0
- package/dist/config/framework-resources-config.d.ts +116 -0
- package/dist/config/framework-resources-config.js +1 -0
- package/dist/config/pipeline-config.d.ts +56 -20
- package/dist/config/pipeline-tree.resolver.d.ts +79 -0
- package/dist/config/pipeline-tree.resolver.js +220 -0
- package/dist/config/stage-type.eraser.d.ts +65 -0
- package/dist/config/stage-type.eraser.js +1 -0
- package/dist/contracts/capability.d.ts +11 -11
- package/dist/contracts/client-contract-structure.validator.d.ts +323 -28
- package/dist/contracts/client-contract-structure.validator.js +152 -8
- package/dist/contracts/contract-canonicalizer.d.ts +19 -3
- package/dist/contracts/contract-canonicalizer.js +141 -28
- package/dist/contracts/contract-hash.d.ts +12 -7
- package/dist/contracts/contract-hash.js +3 -2
- package/dist/contracts/contract-limits.d.ts +4 -1
- package/dist/contracts/contract-limits.js +1 -0
- package/dist/contracts/contract-lookup.d.ts +5 -5
- package/dist/contracts/contract-protocol.d.ts +4 -4
- package/dist/contracts/contract.d.ts +24 -16
- package/dist/contracts/create-requirements.d.ts +35 -0
- package/dist/contracts/create-requirements.js +1 -0
- package/dist/contracts/enum-definition.d.ts +1 -1
- package/dist/contracts/field-check.d.ts +101 -0
- package/dist/contracts/field-check.js +1 -0
- package/dist/contracts/field.d.ts +52 -42
- package/dist/contracts/identifier.d.ts +4 -4
- package/dist/contracts/json-shape.d.ts +12 -1
- package/dist/contracts/lifecycle-trait.d.ts +2 -2
- package/dist/contracts/resource-operations.d.ts +28 -28
- package/dist/contracts/resource.d.ts +15 -9
- package/dist/contracts/scalar-value-type.d.ts +15 -15
- package/dist/contracts/scalar.d.ts +3 -3
- package/dist/contracts/transaction-capability.d.ts +1 -1
- package/dist/contracts/wire-scalar-format.d.ts +4 -4
- package/dist/framework/contract-view.d.ts +213 -147
- package/dist/framework/framework-construction.error.d.ts +10 -10
- package/dist/framework/framework-construction.error.js +2 -2
- package/dist/framework/framework.d.ts +47 -23
- package/dist/framework/framework.factory.d.ts +8 -6
- package/dist/framework/framework.factory.js +40 -20
- package/dist/framework/operation-facade.d.ts +123 -52
- package/dist/framework/operation-facade.js +9 -1
- package/dist/index.d.ts +55 -50
- package/dist/index.js +6 -6
- package/dist/internal.d.ts +15 -10
- package/dist/internal.js +3 -1
- package/dist/operations/operation-arguments.d.ts +267 -202
- package/dist/operations/operation-call.d.ts +27 -28
- package/dist/operations/operation-identity.d.ts +10 -10
- package/dist/operations/operation-result.d.ts +21 -21
- package/dist/operations/operation-validator-core.d.ts +6 -6
- package/dist/operations/operation-validator-core.js +13 -2
- package/dist/operations/operation-validator.d.ts +9 -9
- package/dist/operations/projection-scope.resolver.d.ts +6 -6
- package/dist/operations/structural-limits.walker.d.ts +6 -6
- package/dist/operations/structural-limits.walker.js +145 -0
- package/dist/operations/validation-code.d.ts +11 -6
- package/dist/operations/validation-code.js +4 -0
- package/dist/operations/write-scope.resolver.d.ts +6 -6
- package/dist/protocol/absent-route.responder.d.ts +13 -12
- package/dist/protocol/absent-route.responder.js +19 -19
- package/dist/protocol/contract-document.responder.d.ts +3 -3
- package/dist/protocol/contract-document.responder.js +2 -2
- package/dist/protocol/http-request.decoder.d.ts +17 -13
- package/dist/protocol/http-request.decoder.js +10 -10
- package/dist/protocol/http-request.reader.d.ts +3 -3
- package/dist/protocol/http-response.encoder.d.ts +4 -4
- package/dist/protocol/http-response.encoder.js +94 -55
- package/dist/protocol/http-status.table.d.ts +2 -2
- package/dist/protocol/operation-response.guard.d.ts +2 -2
- package/dist/protocol/protocol-surface.d.ts +4 -4
- package/dist/protocol/protocol.binder.d.ts +50 -27
- package/dist/protocol/protocol.binder.js +12 -9
- package/dist/protocol/protocol.handler.d.ts +22 -13
- package/dist/protocol/protocol.handler.js +44 -9
- package/dist/protocol/unmounted-route.error.d.ts +4 -4
- package/dist/protocol/unmounted-route.error.js +2 -2
- package/dist/runtime/caller-data.copier.d.ts +5 -5
- package/dist/runtime/caller-data.copier.js +13 -13
- package/dist/runtime/caller-data.door.d.ts +6 -6
- package/dist/runtime/caller-data.door.js +6 -4
- package/dist/runtime/computed-read-runtime.d.ts +7 -6
- package/dist/runtime/computed-read-runtime.js +61 -48
- package/dist/runtime/computed-value.error.d.ts +6 -6
- package/dist/runtime/computed-value.error.js +3 -3
- package/dist/runtime/context-executor.runtime.d.ts +59 -0
- package/dist/runtime/context-executor.runtime.js +275 -0
- package/dist/runtime/create-requirement.d.ts +10 -81
- package/dist/runtime/create-requirement.js +80 -57
- package/dist/runtime/decimal.d.ts +2 -2
- package/dist/runtime/decimal.js +1 -1
- package/dist/runtime/diagnostics-reporter.d.ts +53 -27
- package/dist/runtime/diagnostics-reporter.js +24 -0
- package/dist/runtime/error-boundary.d.ts +65 -8
- package/dist/runtime/error-boundary.js +45 -19
- package/dist/runtime/execution-options.d.ts +10 -2
- package/dist/runtime/field-check.evaluator.d.ts +29 -0
- package/dist/runtime/field-check.evaluator.js +521 -0
- package/dist/runtime/field-compute.d.ts +64 -0
- package/dist/runtime/field-compute.js +1 -0
- package/dist/runtime/field-stage.plan.d.ts +15 -0
- package/dist/runtime/field-stage.plan.js +27 -0
- package/dist/runtime/field-stage.runtime.d.ts +35 -0
- package/dist/runtime/field-stage.runtime.js +143 -0
- package/dist/runtime/field-validator.runtime.d.ts +11 -0
- package/dist/runtime/field-validator.runtime.js +87 -0
- package/dist/runtime/framework-error-class.table.d.ts +33 -0
- package/dist/runtime/framework-error-class.table.js +25 -0
- package/dist/runtime/framework-error.d.ts +68 -8
- package/dist/runtime/framework-error.factory.d.ts +4 -0
- package/dist/runtime/framework-error.factory.js +15 -0
- package/dist/runtime/framework-error.js +23 -2
- package/dist/runtime/interceptor-next.error.d.ts +5 -0
- package/dist/runtime/interceptor-next.error.js +6 -0
- package/dist/runtime/json-value.d.ts +3 -3
- package/dist/runtime/level-lifecycle.runtime.d.ts +25 -0
- package/dist/runtime/level-lifecycle.runtime.js +42 -0
- package/dist/runtime/misuse-reporter.d.ts +12 -12
- package/dist/runtime/mutation-planner.d.ts +19 -10
- package/dist/runtime/mutation-planner.js +54 -30
- package/dist/runtime/nested-write.walker.d.ts +32 -0
- package/dist/runtime/nested-write.walker.js +73 -0
- package/dist/runtime/operation-request.d.ts +33 -6
- package/dist/runtime/operation-response.d.ts +17 -17
- package/dist/runtime/operation-runtime.d.ts +113 -25
- package/dist/runtime/operation-runtime.js +395 -74
- package/dist/runtime/outcome-mapper.d.ts +16 -5
- package/dist/runtime/outcome-mapper.js +23 -6
- package/dist/runtime/output-validator.d.ts +10 -10
- package/dist/runtime/output-validator.js +3 -3
- package/dist/runtime/owned-execution.registry.d.ts +6 -6
- package/dist/runtime/pipe-output.validator.d.ts +33 -18
- package/dist/runtime/pipe-output.validator.js +12 -12
- package/dist/runtime/pipeline.d.ts +196 -34
- package/dist/runtime/readonly-value.d.ts +32 -0
- package/dist/runtime/readonly-value.js +141 -0
- package/dist/runtime/request-envelope.validator.d.ts +3 -3
- package/dist/runtime/request-envelope.validator.js +12 -7
- package/dist/runtime/request-id.d.ts +1 -1
- package/dist/runtime/request-state.d.ts +14 -0
- package/dist/runtime/request-state.js +1 -0
- package/dist/runtime/request-state.resolver.d.ts +12 -0
- package/dist/runtime/request-state.resolver.js +20 -0
- package/dist/runtime/scalar-runtime.d.ts +31 -16
- package/dist/runtime/scalar-runtime.js +16 -18
- package/dist/transactions/deferred-operation.d.ts +35 -20
- package/dist/transactions/operation-arguments-encoder.d.ts +3 -3
- package/dist/transactions/operation-arguments-encoder.js +2 -2
- package/dist/transactions/sql-statement.d.ts +77 -0
- package/dist/transactions/sql-statement.js +47 -0
- package/dist/transactions/sql-statement.validator.d.ts +44 -0
- package/dist/transactions/sql-statement.validator.js +134 -0
- package/dist/transactions/transaction-envelope.d.ts +4 -4
- package/dist/transactions/transaction-integrity-error.d.ts +6 -6
- package/dist/transactions/transaction-integrity-error.js +5 -2
- package/dist/transactions/transaction-plan-assembler.d.ts +21 -11
- package/dist/transactions/transaction-plan-assembler.js +148 -34
- package/dist/transactions/transaction-plan-validator.d.ts +29 -20
- package/dist/transactions/transaction-plan-validator.js +70 -38
- package/dist/transactions/transaction-reference-collector.d.ts +5 -5
- package/dist/transactions/transaction-reference-resolver.d.ts +19 -2
- package/dist/transactions/transaction-reference-resolver.js +26 -14
- package/dist/transactions/transaction-reference-validator.d.ts +34 -4
- package/dist/transactions/transaction-reference-validator.js +58 -26
- package/dist/transactions/transaction-reference.d.ts +13 -13
- package/dist/transactions/transaction-request.d.ts +18 -5
- package/dist/transactions/transaction-response.d.ts +6 -6
- package/dist/transactions/transaction-runtime.d.ts +8 -7
- package/dist/transactions/transaction-runtime.js +166 -50
- package/dist/transactions/transaction-settlement.runtime.d.ts +51 -0
- package/dist/transactions/transaction-settlement.runtime.js +120 -0
- package/dist/transactions/transaction-slot-path-error.d.ts +4 -4
- package/dist/transactions/transaction-slot-path-error.js +2 -2
- package/dist/transactions/transaction-slot-writer.js +2 -2
- package/dist/transactions/transaction-stage.runtime.d.ts +81 -0
- package/dist/transactions/transaction-stage.runtime.js +123 -0
- package/package.json +6 -5
- package/src/runtime/field-check.evaluator.ts +720 -0
- package/dist/config/define-fields.d.ts +0 -42
- package/dist/config/define-fields.js +0 -3
- package/dist/config/framework-behaviors-config.d.ts +0 -30
- package/dist/config/framework-fields-config.d.ts +0 -42
- package/dist/config/framework-restrictions-config.d.ts +0 -142
- package/dist/json/avz.d.ts +0 -96
- package/dist/runtime/field-behavior.d.ts +0 -48
- /package/dist/{config/framework-behaviors-config.js → adapters/adapter-sql-statement.js} +0 -0
- /package/dist/{config/framework-fields-config.js → adapters/adapter-transaction-executor.interface.js} +0 -0
- /package/dist/{json → avz}/index.js +0 -0
- /package/dist/{json → avz}/json-shape.registry.js +0 -0
- /package/dist/config/{framework-restrictions-config.js → exact-framework-config.js} +0 -0
- /package/dist/{runtime/field-behavior.js → config/field-pipeline-config.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { type
|
|
1
|
+
import type { AvContractClient } from "../contracts/contract.js";
|
|
2
|
+
import { type AvOperationIdentity } from "../operations/operation-identity.js";
|
|
3
3
|
/**
|
|
4
4
|
* One route of the protocol surface: a route a host mounts for the bound
|
|
5
5
|
* ClientContract, tagged by `kind`.
|
|
@@ -9,7 +9,7 @@ export type SurfaceRoute = ({
|
|
|
9
9
|
readonly method: "POST";
|
|
10
10
|
readonly path: `/_resources/${string}`;
|
|
11
11
|
readonly resource: string;
|
|
12
|
-
} &
|
|
12
|
+
} & AvOperationIdentity) | {
|
|
13
13
|
readonly kind: "contract";
|
|
14
14
|
readonly method: "GET";
|
|
15
15
|
readonly path: "/_contract";
|
|
@@ -24,4 +24,4 @@ export type SurfaceRoute = ({
|
|
|
24
24
|
* order, then `GET /_contract`, then `POST /_transactions` when, and only when,
|
|
25
25
|
* `transactions === "interactive"`.
|
|
26
26
|
*/
|
|
27
|
-
export declare function surfaceOf(client:
|
|
27
|
+
export declare function surfaceOf(client: AvContractClient): readonly SurfaceRoute[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvFramework } from "../framework/framework.js";
|
|
2
|
+
import type { AvOperationResponse } from "../runtime/operation-response.js";
|
|
3
|
+
import type { AvState } from "../runtime/request-state.js";
|
|
4
|
+
import type { AvTransactionResponse } from "../transactions/transaction-response.js";
|
|
4
5
|
import { type AvProtocolRequest, type DecodedOperation, type DecodedOperationRequest, type DecodedTransaction } from "./http-request.decoder.js";
|
|
5
6
|
import { type AvProtocolResponse } from "./http-response.encoder.js";
|
|
6
7
|
import { transportFailure } from "./protocol-failure.js";
|
|
@@ -11,49 +12,51 @@ import { type SurfaceRoute } from "./protocol-surface.js";
|
|
|
11
12
|
*/
|
|
12
13
|
export type AvProtocolBinding = {
|
|
13
14
|
/**
|
|
14
|
-
* Every route a host mounts for the bound
|
|
15
|
+
* Every route a host mounts for the bound Contract (the Client Contract, or the
|
|
16
|
+
* Agent Contract under `{ origin: "agent" }`), from one list, each
|
|
15
17
|
* tagged by `kind`: one `POST` `operation` route per `(resource, family, variant)`
|
|
16
|
-
* it advertises
|
|
18
|
+
* it advertises and no other, then the `contract` route `GET /_contract`
|
|
17
19
|
* (always), then the `transactions` route `POST /_transactions` exactly when its
|
|
18
20
|
* `transactions` is `"interactive"`. Each path is relative to
|
|
19
|
-
* `framework.
|
|
21
|
+
* `framework.api`. Read once at bind time: every call answers the same
|
|
20
22
|
* deep-frozen list, which is passive data a host may serialize.
|
|
21
23
|
*/
|
|
22
24
|
readonly surface: () => readonly SurfaceRoute[];
|
|
23
25
|
/**
|
|
24
|
-
* An operation route's HTTP request → the client-origin
|
|
26
|
+
* An operation route's HTTP request → the client-origin (or the binding's
|
|
27
|
+
* agent-origin) request
|
|
25
28
|
* `framework.execute` takes, or the framework response that answers it instead,
|
|
26
29
|
* with the request id either way. Answers absence for an unadvertised triple
|
|
27
30
|
* without executing it, so a catch-all host is safe. Raw body: size, content type,
|
|
28
|
-
* JSON and shape enforced; parsed body: shape only
|
|
29
|
-
* parser's.
|
|
31
|
+
* JSON and shape enforced; parsed body: shape only, since the rest was the
|
|
32
|
+
* host's parser's job.
|
|
30
33
|
*/
|
|
31
34
|
readonly decodeOperation: (request: AvProtocolRequest) => DecodedOperation;
|
|
32
35
|
/**
|
|
33
|
-
* The same for `/_transactions` → the
|
|
34
|
-
* `framework.executeTransaction` takes; absent unless the
|
|
36
|
+
* The same for `/_transactions` → the binding's origin's plan request
|
|
37
|
+
* `framework.executeTransaction` takes; absent unless the bound Contract's
|
|
35
38
|
* transactions are `"interactive"`.
|
|
36
39
|
*/
|
|
37
40
|
readonly decodeTransaction: (request: AvProtocolRequest) => DecodedTransaction;
|
|
38
41
|
/**
|
|
39
|
-
* One operation's framework response
|
|
42
|
+
* One operation's framework response (what `framework.execute` answered) as the
|
|
40
43
|
* HTTP response a host writes: the code's status, `data` in wire forms, `Aventara-
|
|
41
44
|
* Request-Id` echoed. A result with no wire form answers `A3003` → 500. A
|
|
42
45
|
* diagnostic of one operation names it (`resource`, `family`, `variant`), so the
|
|
43
|
-
* `A3003` reaches the diagnostics sink only when the host passes `decoded`
|
|
44
|
-
* `decodeOperation`'s success value
|
|
46
|
+
* `A3003` reaches the diagnostics sink only when the host passes `decoded`
|
|
47
|
+
* (`decodeOperation`'s success value), as `handleOperation` does; without it the
|
|
45
48
|
* answer is the same and nothing is reported.
|
|
46
49
|
*/
|
|
47
|
-
readonly encodeOperation: (response:
|
|
50
|
+
readonly encodeOperation: (response: AvOperationResponse, requestId: string, decoded?: DecodedOperationRequest) => AvProtocolResponse;
|
|
48
51
|
/**
|
|
49
|
-
* The same for `/_transactions
|
|
52
|
+
* The same for `/_transactions`: what `framework.executeTransaction` answered. An
|
|
50
53
|
* `A3003` is reported to the Framework's diagnostics sink as a `"transaction"`
|
|
51
|
-
* diagnostic
|
|
54
|
+
* diagnostic (client origin, this `requestId`, the step it blames as `operation`)
|
|
52
55
|
* with the value that had no wire form (or what its getter threw) as `error`.
|
|
53
56
|
*/
|
|
54
|
-
readonly encodeTransaction: (response:
|
|
57
|
+
readonly encodeTransaction: (response: AvTransactionResponse, requestId: string) => AvProtocolResponse;
|
|
55
58
|
/**
|
|
56
|
-
* A transport code
|
|
59
|
+
* A transport code (`A2000`, `A2010`, `A2011` or `A2012`) as the complete
|
|
57
60
|
* framework response. For a host that parses the body itself and must answer
|
|
58
61
|
* its parser's failure. `A2012` requires the methods its route allows, so
|
|
59
62
|
* every 405 carries `Allow`.
|
|
@@ -67,20 +70,30 @@ export type AvProtocolBinding = {
|
|
|
67
70
|
* host hands it: one that is not an `AvProtocolRequest` answers `400 A2000`; it
|
|
68
71
|
* never rejects.
|
|
69
72
|
*/
|
|
70
|
-
readonly handleOperation: (request: AvProtocolRequest
|
|
73
|
+
readonly handleOperation: (request: AvProtocolRequest, options?: {
|
|
74
|
+
/**
|
|
75
|
+
* Seeds the request's `ctx.$state` (a host reads its platform request
|
|
76
|
+
* here, Passport's `req.user`, say). Called once, after decoding; a
|
|
77
|
+
* throw is answered like any developer failure. Omitted, the state is `{}`.
|
|
78
|
+
*/
|
|
79
|
+
readonly state?: () => AvState | Promise<AvState>;
|
|
80
|
+
}) => Promise<AvProtocolResponse>;
|
|
71
81
|
/**
|
|
72
82
|
* The same for `/_transactions`: `decodeTransaction` →
|
|
73
83
|
* `framework.executeTransaction` → `encodeTransaction`. Every step runs under
|
|
74
84
|
* ClientContract rules; a committed plan is `200 A1009`, a rolled-back one its
|
|
75
85
|
* failing step's own status.
|
|
76
86
|
*/
|
|
77
|
-
readonly handleTransaction: (request: AvProtocolRequest
|
|
87
|
+
readonly handleTransaction: (request: AvProtocolRequest, options?: {
|
|
88
|
+
/** Seeds the plan's one `ctx.$state`, as for `handleOperation`. */
|
|
89
|
+
readonly state?: () => AvState | Promise<AvState>;
|
|
90
|
+
}) => Promise<AvProtocolResponse>;
|
|
78
91
|
/**
|
|
79
92
|
* The `GET /_contract` responder: the bound ClientContract's JCS-canonical bytes,
|
|
80
93
|
* `ETag` its quoted hash, `Cache-Control: no-cache`, and `304` with no body when
|
|
81
94
|
* `If-None-Match` matches (weak comparison, a list, `*`). Requires no identity
|
|
82
|
-
* header; any other method is `405 A2012` with `Allow: GET`. The bytes are
|
|
83
|
-
* once, at
|
|
95
|
+
* header; any other method is `405 A2012` with `Allow: GET`. The bytes are the ones
|
|
96
|
+
* the Contract's hash was taken over, written once, at construction.
|
|
84
97
|
*/
|
|
85
98
|
readonly encodeContract: (request: AvProtocolRequest) => AvProtocolResponse;
|
|
86
99
|
/**
|
|
@@ -91,12 +104,22 @@ export type AvProtocolBinding = {
|
|
|
91
104
|
* `undefined` for a path outside the protocol's namespace, which the host
|
|
92
105
|
* answers itself. An operation or `/_transactions` route answered `500 A3000`
|
|
93
106
|
* is also reported once to the Framework's diagnostics sink, as an
|
|
94
|
-
* `
|
|
107
|
+
* `AvUnmountedRouteError` naming the route the host did not mount.
|
|
95
108
|
*/
|
|
96
109
|
readonly answerAbsent: (request: AvProtocolRequest) => AvProtocolResponse | undefined;
|
|
97
110
|
};
|
|
98
111
|
/**
|
|
99
|
-
* `AvProtocol.bind(framework)`: reads the instance's compiled
|
|
100
|
-
*
|
|
112
|
+
* `AvProtocol.bind(framework, options?)`: reads the instance's compiled Client
|
|
113
|
+
* Contract (or, with `{ origin: "agent" }`, its Agent Contract) once and returns
|
|
114
|
+
* the bound members, frozen. Every request decoded through it runs under that
|
|
115
|
+
* origin.
|
|
101
116
|
*/
|
|
102
|
-
export declare function bind(framework:
|
|
117
|
+
export declare function bind(framework: AvFramework, options?: {
|
|
118
|
+
/**
|
|
119
|
+
* The origin every request through this binding runs under: `"client"`
|
|
120
|
+
* (the default: the Client Contract, `/_contract`'s document) or `"agent"`
|
|
121
|
+
* (the Agent Contract, its hash and its layer's pipelines), for a host
|
|
122
|
+
* that serves an AI agent — an MCP server.
|
|
123
|
+
*/
|
|
124
|
+
readonly origin?: "client" | "agent";
|
|
125
|
+
}): AvProtocolBinding;
|
|
@@ -7,13 +7,16 @@ import { encodeOperationResponse, encodeTransactionResponse, } from "./http-resp
|
|
|
7
7
|
import { handleOperationRequest, handleTransactionRequest, operationUnencodableReport, planUnencodableReport, } from "./protocol.handler.js";
|
|
8
8
|
import { transportFailure } from "./protocol-failure.js";
|
|
9
9
|
import { surfaceOf } from "./protocol-surface.js";
|
|
10
|
-
export function bind(framework) {
|
|
10
|
+
export function bind(framework, options) {
|
|
11
11
|
const { contracts } = framework;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const origin = options?.origin === "agent" ? "agent" : "client";
|
|
13
|
+
const contract = contracts[origin];
|
|
14
|
+
const surface = surfaceOf(contract);
|
|
15
|
+
const document = contractDocumentOf(contract);
|
|
14
16
|
const sink = diagnosticsSinkOf(framework);
|
|
15
17
|
const handler = {
|
|
16
18
|
contracts,
|
|
19
|
+
origin,
|
|
17
20
|
execute: (request) => framework.execute(request),
|
|
18
21
|
executeTransaction: (request) => framework.executeTransaction(request),
|
|
19
22
|
owned: ownedExecutionOf(framework),
|
|
@@ -21,16 +24,16 @@ export function bind(framework) {
|
|
|
21
24
|
};
|
|
22
25
|
return Object.freeze({
|
|
23
26
|
surface: () => surface,
|
|
24
|
-
decodeOperation: (request) => decodeOperationRequest(contracts, request),
|
|
25
|
-
decodeTransaction: (request) => decodeTransactionRequest(contracts, request),
|
|
27
|
+
decodeOperation: (request) => decodeOperationRequest(contracts, request, origin),
|
|
28
|
+
decodeTransaction: (request) => decodeTransactionRequest(contracts, request, origin),
|
|
26
29
|
encodeOperation: (response, requestId, decoded) => encodeOperationResponse(response, requestId, decoded === undefined
|
|
27
30
|
? undefined
|
|
28
31
|
: operationUnencodableReport(sink, decoded.request)),
|
|
29
|
-
encodeTransaction: (response, requestId) => encodeTransactionResponse(response, requestId, planUnencodableReport(sink, requestId)),
|
|
32
|
+
encodeTransaction: (response, requestId) => encodeTransactionResponse(response, requestId, planUnencodableReport(sink, requestId, origin)),
|
|
30
33
|
failure: transportFailure,
|
|
31
|
-
handleOperation: (request) => handleOperationRequest(handler, request),
|
|
32
|
-
handleTransaction: (request) => handleTransactionRequest(handler, request),
|
|
34
|
+
handleOperation: (request, options) => handleOperationRequest(handler, request, options),
|
|
35
|
+
handleTransaction: (request, options) => handleTransactionRequest(handler, request, options),
|
|
33
36
|
encodeContract: (request) => encodeContractRequest(document, request),
|
|
34
|
-
answerAbsent: (request) => answerAbsentRequest(contracts, request, sink),
|
|
37
|
+
answerAbsent: (request) => answerAbsentRequest(contracts, request, sink, origin),
|
|
35
38
|
});
|
|
36
39
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import type
|
|
1
|
+
import type { AvContracts } from "../compiler/contract.compiler.js";
|
|
2
|
+
import type { RemoteRequestOrigin } from "../config/config-layer.js";
|
|
3
|
+
import type { AvFramework } from "../framework/framework.js";
|
|
4
|
+
import { type AvDiagnosticsSink } from "../runtime/diagnostics-reporter.js";
|
|
5
|
+
import type { RemoteOperationRequest } from "../runtime/operation-request.js";
|
|
5
6
|
import type { OwnedExecution } from "../runtime/owned-execution.registry.js";
|
|
7
|
+
import type { AvState } from "../runtime/request-state.js";
|
|
6
8
|
import { type AvProtocolRequest } from "./http-request.decoder.js";
|
|
7
9
|
import { type AvProtocolResponse, type UnencodableReport } from "./http-response.encoder.js";
|
|
8
10
|
/**
|
|
@@ -12,11 +14,18 @@ import { type AvProtocolResponse, type UnencodableReport } from "./http-response
|
|
|
12
14
|
* constructed Framework) — and its configured diagnostics sink.
|
|
13
15
|
*/
|
|
14
16
|
export type HandlerContext = {
|
|
15
|
-
readonly contracts:
|
|
16
|
-
|
|
17
|
-
readonly
|
|
17
|
+
readonly contracts: AvContracts;
|
|
18
|
+
/** The origin every request the binding decodes runs under. */
|
|
19
|
+
readonly origin: RemoteRequestOrigin;
|
|
20
|
+
readonly execute: AvFramework["execute"];
|
|
21
|
+
readonly executeTransaction: AvFramework["executeTransaction"];
|
|
18
22
|
readonly owned: OwnedExecution | undefined;
|
|
19
|
-
readonly sink:
|
|
23
|
+
readonly sink: AvDiagnosticsSink | undefined;
|
|
24
|
+
};
|
|
25
|
+
/** What a host passes beside one protocol request. */
|
|
26
|
+
export type ProtocolCallOptions = {
|
|
27
|
+
/** Seeds the request's `ctx.$state`; called once, after decoding. Omitted, the state is `{}`. */
|
|
28
|
+
readonly state?: () => AvState | Promise<AvState>;
|
|
20
29
|
};
|
|
21
30
|
/**
|
|
22
31
|
* Where a plan's `A3003` goes: the Framework's diagnostics sink, as a `"transaction"`
|
|
@@ -24,15 +33,15 @@ export type HandlerContext = {
|
|
|
24
33
|
* encoder blames as `operation` when it blames one. One spelling for both
|
|
25
34
|
* `protocol.encodeTransaction` and `protocol.handleTransaction`.
|
|
26
35
|
*/
|
|
27
|
-
export declare function planUnencodableReport(sink:
|
|
36
|
+
export declare function planUnencodableReport(sink: AvDiagnosticsSink | undefined, requestId: string, origin?: RemoteRequestOrigin): UnencodableReport;
|
|
28
37
|
/**
|
|
29
38
|
* Where one operation's `A3003` goes: the Framework's diagnostics sink, as an
|
|
30
39
|
* `"operation"` diagnostic carrying the decoded request's identity and id — the shape
|
|
31
|
-
* the public `
|
|
40
|
+
* the public `AvOperationDiagnostic` already has. One spelling for
|
|
32
41
|
* `protocol.handleOperation` and for `protocol.encodeOperation` given the decoded
|
|
33
42
|
* request.
|
|
34
43
|
*/
|
|
35
|
-
export declare function operationUnencodableReport(sink:
|
|
44
|
+
export declare function operationUnencodableReport(sink: AvDiagnosticsSink | undefined, request: RemoteOperationRequest): UnencodableReport;
|
|
36
45
|
/**
|
|
37
46
|
* `protocol.handleOperation(request)`: the three steps a host would otherwise spell
|
|
38
47
|
* out — `decodeOperation` → `framework.execute` → `encodeOperation` — in one call,
|
|
@@ -40,7 +49,7 @@ export declare function operationUnencodableReport(sink: FrameworkDiagnosticsSin
|
|
|
40
49
|
* itself (a transport failure, an identity mismatch, an unadvertised route) is
|
|
41
50
|
* answered without executing.
|
|
42
51
|
*/
|
|
43
|
-
export declare function handleOperationRequest(context: HandlerContext, request: AvProtocolRequest): Promise<AvProtocolResponse>;
|
|
52
|
+
export declare function handleOperationRequest(context: HandlerContext, request: AvProtocolRequest, options?: ProtocolCallOptions): Promise<AvProtocolResponse>;
|
|
44
53
|
/**
|
|
45
54
|
* `protocol.handleTransaction(request)`: the same shortcut for `/_transactions` —
|
|
46
55
|
* `decodeTransaction` → `framework.executeTransaction` → `encodeTransaction`. The
|
|
@@ -52,4 +61,4 @@ export declare function handleOperationRequest(context: HandlerContext, request:
|
|
|
52
61
|
* handleOperationRequest} is; an `A3003` is reported through {@link
|
|
53
62
|
* planUnencodableReport}.
|
|
54
63
|
*/
|
|
55
|
-
export declare function handleTransactionRequest(context: HandlerContext, request: AvProtocolRequest): Promise<AvProtocolResponse>;
|
|
64
|
+
export declare function handleTransactionRequest(context: HandlerContext, request: AvProtocolRequest, options?: ProtocolCallOptions): Promise<AvProtocolResponse>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createDiagnosticsReporter, createReporter, } from "../runtime/diagnostics-reporter.js";
|
|
2
|
+
import { sanitizeOperationFailure } from "../runtime/error-boundary.js";
|
|
2
3
|
import { decodeOperationRequest, decodeTransactionRequest, isParsedByDecoder, } from "./http-request.decoder.js";
|
|
3
4
|
import { encodeOperationResponse, encodeTransactionResponse, } from "./http-response.encoder.js";
|
|
4
5
|
function operationEntry(context, request) {
|
|
@@ -11,10 +12,30 @@ function transactionEntry(context, request) {
|
|
|
11
12
|
? context.owned.executeTransaction
|
|
12
13
|
: context.executeTransaction;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
+
async function seededState(options, report, view) {
|
|
16
|
+
if (options?.state === undefined) {
|
|
17
|
+
return { ok: true, state: undefined };
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const state = await options.state();
|
|
21
|
+
return {
|
|
22
|
+
ok: true,
|
|
23
|
+
state: typeof state === "object" && state !== null && !Array.isArray(state)
|
|
24
|
+
? state
|
|
25
|
+
: undefined,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
response: sanitizeOperationFailure(error, "runtime", report, view),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function planUnencodableReport(sink, requestId, origin = "client") {
|
|
15
36
|
return (error, operation) => createReporter(sink, {
|
|
16
37
|
kind: "transaction",
|
|
17
|
-
origin
|
|
38
|
+
origin,
|
|
18
39
|
requestId,
|
|
19
40
|
...(operation === undefined ? {} : { operation }),
|
|
20
41
|
})(error, "A3003");
|
|
@@ -22,19 +43,33 @@ export function planUnencodableReport(sink, requestId) {
|
|
|
22
43
|
export function operationUnencodableReport(sink, request) {
|
|
23
44
|
return (error) => createDiagnosticsReporter(sink, request)(error, "A3003");
|
|
24
45
|
}
|
|
25
|
-
export async function handleOperationRequest(context, request) {
|
|
26
|
-
const decoded = decodeOperationRequest(context.contracts, request);
|
|
46
|
+
export async function handleOperationRequest(context, request, options) {
|
|
47
|
+
const decoded = decodeOperationRequest(context.contracts, request, context.origin);
|
|
27
48
|
if (!decoded.ok) {
|
|
28
49
|
return decoded.response;
|
|
29
50
|
}
|
|
30
|
-
const
|
|
51
|
+
const seeded = await seededState(options, createDiagnosticsReporter(context.sink, decoded.request), { path: ["arguments"], arguments: decoded.request.arguments });
|
|
52
|
+
const response = seeded.ok
|
|
53
|
+
? await operationEntry(context, decoded.request)(seeded.state === undefined
|
|
54
|
+
? decoded.request
|
|
55
|
+
: { ...decoded.request, state: seeded.state })
|
|
56
|
+
: seeded.response;
|
|
31
57
|
return encodeOperationResponse(response, decoded.requestId, operationUnencodableReport(context.sink, decoded.request));
|
|
32
58
|
}
|
|
33
|
-
export async function handleTransactionRequest(context, request) {
|
|
34
|
-
const decoded = decodeTransactionRequest(context.contracts, request);
|
|
59
|
+
export async function handleTransactionRequest(context, request, options) {
|
|
60
|
+
const decoded = decodeTransactionRequest(context.contracts, request, context.origin);
|
|
35
61
|
if (!decoded.ok) {
|
|
36
62
|
return decoded.response;
|
|
37
63
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
64
|
+
const seeded = await seededState(options, createReporter(context.sink, {
|
|
65
|
+
kind: "transaction",
|
|
66
|
+
origin: context.origin,
|
|
67
|
+
requestId: decoded.requestId,
|
|
68
|
+
}), { path: ["plan"], arguments: decoded.request.plan });
|
|
69
|
+
const response = seeded.ok
|
|
70
|
+
? await transactionEntry(context, decoded.request)(seeded.state === undefined
|
|
71
|
+
? decoded.request
|
|
72
|
+
: { ...decoded.request, state: seeded.state })
|
|
73
|
+
: seeded.response;
|
|
74
|
+
return encodeTransactionResponse(response, decoded.requestId, planUnencodableReport(context.sink, decoded.requestId, context.origin));
|
|
40
75
|
}
|
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
* `500 A3000` is unchanged; this error names the route the host left out, so the
|
|
6
6
|
* server's diagnostics show it too. It is never sent to the caller.
|
|
7
7
|
*/
|
|
8
|
-
export declare class
|
|
8
|
+
export declare class AvUnmountedRouteError extends Error {
|
|
9
9
|
/** What the ClientContract advertises: `resource.family.variant`, or `transactions`. */
|
|
10
10
|
readonly advertised: string;
|
|
11
|
-
/** The route as the request reached it: method and
|
|
11
|
+
/** The route as the request reached it: method and api-relative path. */
|
|
12
12
|
readonly route: string;
|
|
13
|
-
readonly name = "
|
|
13
|
+
readonly name = "AvUnmountedRouteError";
|
|
14
14
|
constructor(
|
|
15
15
|
/** What the ClientContract advertises: `resource.family.variant`, or `transactions`. */
|
|
16
16
|
advertised: string,
|
|
17
|
-
/** The route as the request reached it: method and
|
|
17
|
+
/** The route as the request reached it: method and api-relative path. */
|
|
18
18
|
route: string);
|
|
19
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class AvUnmountedRouteError extends Error {
|
|
2
2
|
advertised;
|
|
3
3
|
route;
|
|
4
|
-
name = "
|
|
4
|
+
name = "AvUnmountedRouteError";
|
|
5
5
|
constructor(advertised, route) {
|
|
6
6
|
super(`The ClientContract advertises ${advertised}, but the host mounted no route for ${route}, so protocol.answerAbsent answered it 500 A3000. Mount every protocol.surface() entry.`);
|
|
7
7
|
this.advertised = advertised;
|
|
@@ -7,7 +7,7 @@ export type CallerDataPath = readonly (string | number)[];
|
|
|
7
7
|
* root. Thrown by {@link copyCallerData} and caught by every door, which answers it as
|
|
8
8
|
* the caller's `A2004`/`V1001` at its own address. It never carries the value.
|
|
9
9
|
*/
|
|
10
|
-
export declare class
|
|
10
|
+
export declare class AvCallerDataError extends Error {
|
|
11
11
|
readonly kind: CallerDataFailureKind;
|
|
12
12
|
readonly path: CallerDataPath;
|
|
13
13
|
/**
|
|
@@ -15,7 +15,7 @@ export declare class CallerDataError extends Error {
|
|
|
15
15
|
* tripwire read after the door; {@link locateCallerDataError} resolves it.
|
|
16
16
|
*/
|
|
17
17
|
readonly within?: object | undefined;
|
|
18
|
-
readonly name = "
|
|
18
|
+
readonly name = "AvCallerDataError";
|
|
19
19
|
constructor(kind: CallerDataFailureKind, path: CallerDataPath,
|
|
20
20
|
/**
|
|
21
21
|
* The control mirror `path` starts from, when the failure is a mirror's
|
|
@@ -46,14 +46,14 @@ export type CallerDataPolicy = {
|
|
|
46
46
|
* copy's root, where `error.path` started from the mirror. A failure that is not a
|
|
47
47
|
* tripwire's, or a mirror the copy does not hold, is returned as it is.
|
|
48
48
|
*/
|
|
49
|
-
export declare function locateCallerDataError(error:
|
|
49
|
+
export declare function locateCallerDataError(error: AvCallerDataError, copy: unknown): AvCallerDataError;
|
|
50
50
|
/**
|
|
51
51
|
* Copies a caller's value into fresh plain data (see the module note), reading the
|
|
52
52
|
* caller's objects exactly once.
|
|
53
53
|
*
|
|
54
|
-
* @throws {@link
|
|
54
|
+
* @throws {@link AvCallerDataError} when a value cannot be read or is not plain data,
|
|
55
55
|
* naming its path from `value`.
|
|
56
56
|
*/
|
|
57
57
|
export declare function copyCallerData(value: unknown, policy?: CallerDataPolicy): unknown;
|
|
58
|
-
/** The `V1001` message a door answers a {@link
|
|
58
|
+
/** The `V1001` message a door answers a {@link AvCallerDataError} with. */
|
|
59
59
|
export declare function callerDataFailureMessage(kind: CallerDataFailureKind): string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AvDecimal } from "./decimal.js";
|
|
2
2
|
const FAILURE_MESSAGES = {
|
|
3
3
|
"unreadable-value": "Value could not be read.",
|
|
4
4
|
"non-plain-value": "Value must be plain data.",
|
|
5
5
|
};
|
|
6
|
-
export class
|
|
6
|
+
export class AvCallerDataError extends Error {
|
|
7
7
|
kind;
|
|
8
8
|
path;
|
|
9
9
|
within;
|
|
10
|
-
name = "
|
|
10
|
+
name = "AvCallerDataError";
|
|
11
11
|
constructor(kind, path, within) {
|
|
12
12
|
super(FAILURE_MESSAGES[kind]);
|
|
13
13
|
this.kind = kind;
|
|
@@ -19,7 +19,7 @@ const NO_POLICY = {};
|
|
|
19
19
|
const OBJECT_PROTOTYPE = Object.prototype;
|
|
20
20
|
const DATE_PROTOTYPE = Date.prototype;
|
|
21
21
|
const dateValueOf = Date.prototype.getTime;
|
|
22
|
-
const decimalValueOf =
|
|
22
|
+
const decimalValueOf = AvDecimal.prototype.toString;
|
|
23
23
|
const FAST_WALK_DEPTH = 256;
|
|
24
24
|
const SLOW_WALK = Symbol("slow walk");
|
|
25
25
|
class FastWalkFailure {
|
|
@@ -33,8 +33,8 @@ function copyValueType(value, prototype) {
|
|
|
33
33
|
if (prototype === DATE_PROTOTYPE || value instanceof Date) {
|
|
34
34
|
return new Date(dateValueOf.call(value));
|
|
35
35
|
}
|
|
36
|
-
if (value instanceof
|
|
37
|
-
return new
|
|
36
|
+
if (value instanceof AvDecimal) {
|
|
37
|
+
return new AvDecimal(decimalValueOf.call(value));
|
|
38
38
|
}
|
|
39
39
|
if (value instanceof Uint8Array) {
|
|
40
40
|
return new Uint8Array(value);
|
|
@@ -134,7 +134,7 @@ function readAt(link, read) {
|
|
|
134
134
|
return read();
|
|
135
135
|
}
|
|
136
136
|
catch {
|
|
137
|
-
throw new
|
|
137
|
+
throw new AvCallerDataError("unreadable-value", pathOf(link));
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
function copySlow(value, policy, failedAt) {
|
|
@@ -154,7 +154,7 @@ function copySlow(value, policy, failedAt) {
|
|
|
154
154
|
const task = stack.pop();
|
|
155
155
|
if (task.kind === "leave") {
|
|
156
156
|
if (task.refuse !== false) {
|
|
157
|
-
throw new
|
|
157
|
+
throw new AvCallerDataError("unreadable-value", pathOf(task.refuse));
|
|
158
158
|
}
|
|
159
159
|
ancestors.delete(task.container);
|
|
160
160
|
continue;
|
|
@@ -172,7 +172,7 @@ function copySlow(value, policy, failedAt) {
|
|
|
172
172
|
const refuse = current === failedAt ? link : false;
|
|
173
173
|
const settle = (copy) => {
|
|
174
174
|
if (refuse !== false) {
|
|
175
|
-
throw new
|
|
175
|
+
throw new AvCallerDataError("unreadable-value", pathOf(refuse));
|
|
176
176
|
}
|
|
177
177
|
task.assign(copy);
|
|
178
178
|
};
|
|
@@ -209,7 +209,7 @@ function copySlow(value, policy, failedAt) {
|
|
|
209
209
|
if (!isPlainPrototype(prototype)) {
|
|
210
210
|
const copied = readAt(link, () => copyValueType(current, prototype));
|
|
211
211
|
if (copied === undefined) {
|
|
212
|
-
throw new
|
|
212
|
+
throw new AvCallerDataError("non-plain-value", pathOf(link));
|
|
213
213
|
}
|
|
214
214
|
settle(copied);
|
|
215
215
|
continue;
|
|
@@ -271,11 +271,11 @@ function pathSegment(array, key) {
|
|
|
271
271
|
function mirrorControlData(value) {
|
|
272
272
|
const shape = reflectNode(value);
|
|
273
273
|
if (shape === undefined) {
|
|
274
|
-
throw new
|
|
274
|
+
throw new AvCallerDataError("unreadable-value", []);
|
|
275
275
|
}
|
|
276
276
|
let root;
|
|
277
277
|
const refuse = (kind, path) => {
|
|
278
|
-
throw new
|
|
278
|
+
throw new AvCallerDataError(kind, path, root);
|
|
279
279
|
};
|
|
280
280
|
const mirrors = new Map();
|
|
281
281
|
const stack = [
|
|
@@ -416,7 +416,7 @@ export function locateCallerDataError(error, copy) {
|
|
|
416
416
|
const at = pathTo(copy, within);
|
|
417
417
|
return at === undefined
|
|
418
418
|
? error
|
|
419
|
-
: new
|
|
419
|
+
: new AvCallerDataError(error.kind, [...at, ...error.path]);
|
|
420
420
|
}
|
|
421
421
|
function pathTo(copy, target) {
|
|
422
422
|
const seen = new Set();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type { AvValidationIssue } from "../operations/validation-code.js";
|
|
2
|
+
import { AvCallerDataError, type CallerDataPath, type CallerDataPolicy } from "./caller-data.copier.js";
|
|
3
|
+
import type { AvMisuseEvent, MisuseReporter } from "./misuse-reporter.js";
|
|
4
4
|
/**
|
|
5
5
|
* Where the arguments an execution entry receives came from.
|
|
6
6
|
*
|
|
@@ -14,7 +14,7 @@ import type { FrameworkMisuseEvent, MisuseReporter } from "./misuse-reporter.js"
|
|
|
14
14
|
*/
|
|
15
15
|
export type ArgumentsSource = "caller" | "owned";
|
|
16
16
|
/** The operation identity a misuse event may name, as far as it could be read. */
|
|
17
|
-
export type MisuseIdentity = Omit<
|
|
17
|
+
export type MisuseIdentity = Omit<AvMisuseEvent, "kind" | "path">;
|
|
18
18
|
/**
|
|
19
19
|
* The identity of a request the framework holds a copy of, keeping only what is
|
|
20
20
|
* identity: an origin, a Resource name and a standard operation, each present only
|
|
@@ -30,7 +30,7 @@ export declare function misuseIdentityOf(request: {
|
|
|
30
30
|
* The caller's `V1001` for a refused value at `address` (the door's own spelling of
|
|
31
31
|
* where the copied value stands), reported once to the misuse hook.
|
|
32
32
|
*/
|
|
33
|
-
export declare function refuseCallerData(error:
|
|
33
|
+
export declare function refuseCallerData(error: AvCallerDataError, address: CallerDataPath, identity: MisuseIdentity, misuse: MisuseReporter): AvValidationIssue;
|
|
34
34
|
/**
|
|
35
35
|
* A door's copy of one caller value, or the failure it met. The door holds it until
|
|
36
36
|
* its answer is due — a plan answers its steps in order — so the failure is a value
|
|
@@ -41,7 +41,7 @@ export type CallerDataCopy = {
|
|
|
41
41
|
readonly value: unknown;
|
|
42
42
|
} | {
|
|
43
43
|
readonly ok: false;
|
|
44
|
-
readonly error:
|
|
44
|
+
readonly error: AvCallerDataError;
|
|
45
45
|
};
|
|
46
46
|
/** Copies `value` at a door, keeping {@link copyCallerData}'s refusal as a value. */
|
|
47
47
|
export declare function copyAtDoor(value: unknown, policy?: CallerDataPolicy): CallerDataCopy;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { parseOperationIdentity } from "../operations/operation-identity.js";
|
|
2
2
|
import { validationIssue } from "../operations/validation-code.js";
|
|
3
|
-
import {
|
|
3
|
+
import { AvCallerDataError, copyCallerData, } from "./caller-data.copier.js";
|
|
4
4
|
export function misuseIdentityOf(request) {
|
|
5
|
-
const origin = request.origin === "application" ||
|
|
5
|
+
const origin = request.origin === "application" ||
|
|
6
|
+
request.origin === "client" ||
|
|
7
|
+
request.origin === "agent"
|
|
6
8
|
? request.origin
|
|
7
9
|
: undefined;
|
|
8
10
|
const identity = typeof request.family === "string" && typeof request.variant === "string"
|
|
@@ -28,7 +30,7 @@ export function copyAtDoor(value, policy) {
|
|
|
28
30
|
return { ok: true, value: copyCallerData(value, policy) };
|
|
29
31
|
}
|
|
30
32
|
catch (error) {
|
|
31
|
-
if (error instanceof
|
|
33
|
+
if (error instanceof AvCallerDataError) {
|
|
32
34
|
return { ok: false, error };
|
|
33
35
|
}
|
|
34
36
|
throw error;
|
|
@@ -53,7 +55,7 @@ export function copyEnvelopeAtDoor(request, members) {
|
|
|
53
55
|
if (!copy.ok) {
|
|
54
56
|
return {
|
|
55
57
|
ok: false,
|
|
56
|
-
error: new
|
|
58
|
+
error: new AvCallerDataError(copy.error.kind, [
|
|
57
59
|
member,
|
|
58
60
|
...copy.error.path,
|
|
59
61
|
]),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { AvAdapterModel } from "../adapters/adapter-model.js";
|
|
2
|
+
import type { ResolvedComputeConfig } from "../config/field-compute.resolver.js";
|
|
3
|
+
import type { AvContract, AvContractCore } from "../contracts/contract.js";
|
|
4
|
+
import type { AvComputeContext } from "./field-compute.js";
|
|
3
5
|
import type { OperationExecutionRequest } from "./operation-request.js";
|
|
4
|
-
|
|
5
|
-
type ContextFactory = () => PipelineContext;
|
|
6
|
+
type ContextFactory = () => AvComputeContext;
|
|
6
7
|
export type RelationReadPlan = {
|
|
7
8
|
readonly field: string;
|
|
8
9
|
readonly cardinality: "one" | "many";
|
|
@@ -27,10 +28,10 @@ export type PlannedReadOperation = {
|
|
|
27
28
|
* are never mutated and hidden dependencies are resolved through the Core
|
|
28
29
|
* Contract.
|
|
29
30
|
*/
|
|
30
|
-
export declare function planReadOperation(core:
|
|
31
|
+
export declare function planReadOperation(core: AvContractCore, model: AvAdapterModel, active: AvContract, compute: ResolvedComputeConfig | undefined, request: OperationExecutionRequest, args: unknown): PlannedReadOperation;
|
|
31
32
|
/**
|
|
32
33
|
* Materialize computed scalar reads and remove internal dependency fields,
|
|
33
34
|
* against `active` — the Contract `planReadOperation` was given as `active`.
|
|
34
35
|
*/
|
|
35
|
-
export declare function materializeReadOperation(active:
|
|
36
|
+
export declare function materializeReadOperation(active: AvContract, compute: ResolvedComputeConfig | undefined, request: OperationExecutionRequest, plan: PlannedReadOperation, value: unknown, contextFactory: ContextFactory): Promise<unknown>;
|
|
36
37
|
export {};
|