feat(query): accept lazy peer.Resolve in query builders#1780
Merged
Conversation
Query builders that take a peer now accept peer.InputPeer, so a peer can
be addressed by username/phone/deeplink and resolved lazily instead of
being resolved by hand beforehand:
query.NewQuery(raw).Messages().GetHistory(peer.Resolve("durov")).ForEach(ctx, cb)
Concrete tg.InputPeerClass values still work unchanged, as they satisfy
peer.InputPeer. The package QueryBuilder carries a peer.Resolver
(peer.DefaultResolver by default, overridable via WithResolver) and the
peer is resolved inside Query, wrapping errors per context-error
semantics.
peer.Resolve is repurposed to take a single textual argument and return a
lazy *Resolved reference; bind a resolver with Resolved.Bind to get a
Promise. peer.ResolveInputPeer resolves a peer.InputPeer to a concrete
tg.InputPeerClass.
This replaces the generated GetHistoryResolve-style helpers (#1779) with
the API requested in the original issue.
BREAKING CHANGE: peer.Resolve(resolver, from) is now peer.Resolve(from);
use peer.Resolve(from).Bind(resolver) for the previous behavior.
Closes #283
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1780 +/- ##
==========================================
+ Coverage 71.26% 71.32% +0.06%
==========================================
Files 503 504 +1
Lines 23602 23625 +23
==========================================
+ Hits 16819 16851 +32
+ Misses 5552 5542 -10
- Partials 1231 1232 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Reworks the peer-resolve ergonomics to match the API in #283 directly, replacing the generated
GetHistoryResolve-style helpers merged in #1779.Before
After (as per the issue)
How
peer.InputPeerinstead oftg.InputPeerClass.peer.InputPeeris a small interface (Zero/String) satisfied both by concretetg.InputPeerClassvalues and by lazy references, so existingGetHistory(&tg.InputPeerUser{...})calls keep compiling.tg.InputPeerClassis a sealed interface (unexportedconstruct()), so a lazy type cannot masquerade as one — hence the new interface.peer.Resolve(from string)now returns a lazy*peer.Resolved(auto-detecting domain/phone/deeplink). It is resolved insideQueryusing the builder's resolver, wrapping errors per the repo's context-error semantics.QueryBuildercarries apeer.Resolver(peer.DefaultResolverby default, overridable viaWithResolver).peer.ResolveInputPeer(ctx, resolver, input)resolves apeer.InputPeerto a concrete peer;(*Resolved).Bind(resolver)yields apeer.Promise.Breaking change
peer.Resolve(resolver, from)→peer.Resolve(from). Usepeer.Resolve(from).Bind(resolver)for the previous behavior.message.Senderis updated accordingly;peer.ResolveDomain/ResolvePhone/ResolveDeeplinkare unchanged.Generator-only edits
Per
CLAUDE.md, only theitergengenerator was hand-edited;messages/queries.gen.gois regenerated.make generateis stable.Testing
go test -race ./telegram/message/... ./telegram/query/...— green.peer.ResolveInputPeer/Resolved.Bind(concrete, lazy, nil, unsupported paths) andmessagesquery builder with bothpeer.Resolve(...)and a concrete peer, plus a customWithResolver.ExampleQuery_resolveHistory.🤖 Generated with Claude Code