add Events.Typed for registry-backed typed event access#8
Merged
Conversation
The events container has held its members as raw json.RawMessage since the wire-shape phase, and the event-type registry (Event, EventDecoder, RegisterEventType, LookupEventType) landed alongside it. This connects the two: Events.Typed decodes a single events-claim member through the registry, turning a recognized event type's raw payload into the typed Event its vocabulary registered. The method distinguishes four outcomes, and the returned bool is true in exactly one of them. An absent member and a present-but-unregistered member both report (nil, false, nil) — an event type this build does not recognize is the expected forward-compatibility case (RFC 8417 §2.2), not an error, and its bytes stay reachable through Raw so the byte-stable round-trip is preserved. A present member whose registered decoder succeeds returns (event, true, nil). A present member whose decoder fails returns (nil, false, err), wrapping the decoder's error with %w and the event-type URI so errors.Is/As reach the cause and the message names which event failed. No enumeration helper is added: ranging the keys of Raw and calling Typed per URI reads cleanly and needs no new surface, so the godoc documents that pattern rather than introducing a URIs method. Decoding is left zero-copy — the raw bytes are handed to the decoder as-is, per the decoder contract that forbids mutating them — to keep the no-deserialization-cost property of unread events. Tests register distinct event-type URIs per case so they stay order-independent under -shuffle against the process-wide registry, and cover all four documented outcomes plus a nil receiver, errors.Is matching on a decoder sentinel, errors.As unwrapping to a concrete JSON error, and the documented range-over-Raw iteration. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
Events.Typed(uri string) (Event, bool, error)— registry-backedtyped access to a single events-claim member, completing the consumer
half of the event-type registry seam (the
Eventinterface plusRegisterEventType/LookupEventTypelanded previously).Behaviour — four cases,
booltrue in exactly one(nil, false, nil)(nil, false, nil)— stays raw, reachable viaRaw()[uri](event, true, nil)(nil, false, err)— wrapped%wwith the event-type URIAn unregistered URI is the expected forward-compatibility case
(RFC 8417 §2.2), not an error — its bytes round-trip byte-stably, which
CAEP, RISC, and other event vocabularies depend on.
Notes
Raw()andcalling
Typedper URI reads cleanly without new surface, so thegodoc documents that pattern instead of introducing a
URIsmethod.per the decoder contract that forbids mutating them, preserving the
no-deserialization-cost property of unread events.
%wsoerrors.Is/errors.Asreachthe cause; the message names the failing event-type URI.
Tests
Distinct event-type URIs per case keep the suite order-independent under
-shuffleagainst the process-wide registry. Coverage: all fourdocumented outcomes, a nil receiver,
errors.Ison a decoder sentinel,errors.Asunwrapping to a concrete JSON error, and the documentedrange-over-
Rawiteration.Local CI
gofmt -lclean ·go vet ./...clean ·go mod tidy -diffno drift ·go test -race -shuffle=on ./...pass ·golangci-lint run ./...0 issues.🤖 Generated with Claude Code