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 combined_types_for(unit, …)this unit’s own type namespace, own declarations plus its uses targets’ — the exact table own_contract_hashes (bynk-emit/src/project.rs) hashes a service’s contract through. Every name resolvable through it is therefore this unit’s own view of its boundary: Provenance::Owned throughout. A genuinely Consumed type (reached through a consumes <other context>, not a uses <commons>) never appears here — that is a caller’s view of another unit’s boundary, not this handler’s own, and 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-emit/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 header facts discriminator (bynk-ide/src/sequence.rs) also renders, kept here as their own IDE-shaped type rather than re-exporting HandlerKind directly, so a future field this peek needs (that HandlerKind has no room for) is a local addition, not an upstream one.
Envelope
The request shape a handler’s caller sends. Three cases, not twobynk-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.
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).
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.

Functions§

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.
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.