Skip to main content

Module wire_contract

Module wire_contract 

Source
Expand description

#855: the wire-contract peek — the model behind “hover a service handler” and “Show Wire Contract”. Renders bynk_check::wire::WireModel (the same IR bynk-emit’s codec generation consumes) narrowed to one handler, plus the facts the IR does not carry: the request envelope shape, the cross-context contract form + hash (on call only), and the HTTP response set a route can actually answer with.

Handler resolution mirrors bynk-lsp/src/sequence_request.rs’s sequence_model_at: re-parse the committed snapshot with parse_unit_with_recovery, find the Handler whose span contains the cursor. The re-parsed Handler supplies spans/body; the retained ContextBoundaryInfo supplies the type table — a single-file re-parse cannot see a uses target’s types, which is the whole reason that table is retained project-wide (Phase 3).

Provenance. bynk_check::wire::Provenance distinguishes a type this module owns from one reached through another unit. ContextBoundaryInfo‘s types table is contract_types_for(unit, …) — this unit’s own type namespace: own declarations, its uses targets’, and (#2073) the types of the contexts it consumes, which its own signatures may name — the exact table own_contract_hashes (bynk-driver/src/project.rs) hashes a service’s contract through. Every name resolvable through it is this unit’s own view of its boundary, so the peek reports Provenance::Owned throughout, a borrowed consumed type included. A caller’s view of another unit’s boundary is out of scope for a peek that answers “what does this handler send and receive”.

Scope. Service handlers only. An agent’s on call handler crosses a Durable-Object RPC boundary too, but the issue’s worked examples (an HTTP route, a cross-context on call) are both service handlers, and ContextBoundaryInfo does not retain agents’ own handler bodies in a form this module needs. Left for a later slice if an agent peek is wanted.

Structs§

ContractForm
The canonical form + hash of an on call handler’s contract — the same projection bynk-driver/src/project.rs’s own_contract_hashes builds, so the hash this peek shows is provably the hash the emitted X-Bynk-Contract constant stamps.
HttpResponse
One reachable HTTP outcome.
WireContractModel
The wire contract of one handler: its request envelope, its reachable response set (HTTP handlers only), its cross-context contract form + hash (on call only), and the boundary type shapes both reference.

Enums§

BoundaryKind
Which protocol hosts the hovered handler: the system model’s own bynk_model::IrHandlerKind, read through bynk_model::lower_handler_kind_ir.
Envelope
The request shape a handler’s caller sends. Three cases, not two — bynk-emit/src/emitter/workers_entry.rs’s h.params.len() == 1 branch is the only bare-value case; everything else, including zero params, takes the object branch. Rendering only Bare/Keyed would misstate a zero-arg service as accepting an (empty) object body it never inspects, when what actually happens is the body is not read at all.
IrHttpMethod
BoundaryKind::Http’s method: the model’s bynk_model::IrHttpMethod. IrHandlerKind::Http’s own method field — a field-for-field mirror of bynk_syntax::ast::HttpMethod, same reasoning as IrHandlerKind itself.
NoCrossContextReason
Why there is no cross-context contract to show for this handler. Rendered on the panel only — hover stays quiet about an absence (Part 4).
ResponseBody
What a response’s body is (#3632): the classification bynk openapi’s responses_of makes per HttpVariantPayload, as data a client can read.
ResponseOrigin
Why a response was reachable — so a renderer can tell an author-declared outcome from one the boundary injects on their behalf without their having written a line for it.

Constants§

REDIRECT_HEADER
The header a ResponseBody::Redirect carries its target in.

Functions§

http_result_inner
Effect[HttpResult[T]] / HttpResult[T] → T; None when the declared return is not an HttpResult. The one place the payload type is read, shared with bynk openapi so the two cannot drift.
real_context_count
How many real contexts/adapters a project has — the input wire_contract_at/wire_contract_for_service’s context_count wants, deciding NoCrossContextReason::SingleContext.
response_body
The body of one response, or None when it has none to describe: a no-payload variant, a () value payload, or a boundary-implicit response (the boundary shapes those bodies, not the handler).
response_payload
The wire shape of the body one response carries (#3609), given the model’s WireContractModel::success: T for a value variant, None for everything else. A message variant’s body is { "error": String } and a redirect’s location travels in a header with no body (as bynk openapi describes them); neither is a ref into types, so they are left None here and described by response_body instead (#3632). Boundary-implicit responses are None too — the boundary shapes their bodies, not the handler.
wire_contract_at
Locate the Handler enclosing offset in text and build its wire contract. Mirrors sequence_request::sequence_model_at’s re-parse convention. info is the owning unit’s retained boundary table (Phase 3); expr_types is that same file’s checked expression types (empty for a file with errors — the Ok-overload disambiguation then falls back to the declared return type, see ResponseWalk::is_http_result_expr below).
wire_contract_for_service
Build the wire contract for one already-located handler. The pure half of wire_contract_at — the part that never touches the offset/re-parse machinery — split out the same way sequence_model_at delegates to sequence::sequence_model.