Skip to content

feat(query): accept lazy peer.Resolve in query builders#1780

Merged
ernado merged 1 commit into
mainfrom
feat/283-resolve-input
Jun 15, 2026
Merged

feat(query): accept lazy peer.Resolve in query builders#1780
ernado merged 1 commit into
mainfrom
feat/283-resolve-input

Conversation

@ernado

@ernado ernado commented Jun 15, 2026

Copy link
Copy Markdown
Member

Reworks the peer-resolve ergonomics to match the API in #283 directly, replacing the generated GetHistoryResolve-style helpers merged in #1779.

Before

p, err := peer.Resolve(resolver, "durov")(ctx)
if err != nil {
    // ...
}
query.NewQuery(raw).Messages().GetHistory(p).ForEach(ctx, cb)

After (as per the issue)

query.NewQuery(raw).Messages().GetHistory(peer.Resolve("durov")).ForEach(ctx, cb)

How

  • Peer-taking query builders now accept peer.InputPeer instead of tg.InputPeerClass.
    • peer.InputPeer is a small interface (Zero/String) satisfied both by concrete tg.InputPeerClass values and by lazy references, so existing GetHistory(&tg.InputPeerUser{...}) calls keep compiling.
    • tg.InputPeerClass is a sealed interface (unexported construct()), 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 inside Query using the builder's resolver, wrapping errors per the repo's context-error semantics.
  • The package QueryBuilder carries a peer.Resolver (peer.DefaultResolver by default, overridable via WithResolver).
  • peer.ResolveInputPeer(ctx, resolver, input) resolves a peer.InputPeer to a concrete peer; (*Resolved).Bind(resolver) yields a peer.Promise.

Breaking change

peer.Resolve(resolver, from)peer.Resolve(from). Use peer.Resolve(from).Bind(resolver) for the previous behavior. message.Sender is updated accordingly; peer.ResolveDomain/ResolvePhone/ResolveDeeplink are unchanged.

Generator-only edits

Per CLAUDE.md, only the itergen generator was hand-edited; messages/queries.gen.go is regenerated. make generate is stable.

Testing

  • go test -race ./telegram/message/... ./telegram/query/... — green.
  • New tests: peer.ResolveInputPeer/Resolved.Bind (concrete, lazy, nil, unsupported paths) and messages query builder with both peer.Resolve(...) and a concrete peer, plus a custom WithResolver.
  • Updated ExampleQuery_resolveHistory.

🤖 Generated with Claude Code

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>
@ernado ernado merged commit 4793972 into main Jun 15, 2026
13 checks passed
@ernado ernado deleted the feat/283-resolve-input branch June 15, 2026 04:24
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.32%. Comparing base (f74d0d1) to head (15a4668).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
telegram/message/peer/input.go 82.60% 3 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant