Skip to content

feat(query): generate peer-resolve helpers for query builders#1779

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

feat(query): generate peer-resolve helpers for query builders#1779
ernado merged 1 commit into
mainfrom
feat/283-query-resolve-helpers

Conversation

@ernado

@ernado ernado commented Jun 15, 2026

Copy link
Copy Markdown
Member

Closes #283.

Problem

Query builders that take a peer required the caller to resolve the peer by hand first:

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

Change

The itergen generator now emits a <Method>Resolve(from string) sibling for every query builder that has a required tg.InputPeerClass parameter, so the peer can be addressed by domain / phone / deeplink directly:

query.NewQuery(raw).Messages().GetHistoryResolve("telegram").ForEach(ctx, cb)
  • The package QueryBuilder now carries a peer.Resolver, defaulting to peer.DefaultResolver(raw) and overridable via WithResolver(...) — mirroring message.Sender.
  • The peer is resolved lazily inside Query(ctx, …) and cached; resolve errors are wrapped so context cancellation surfaces correctly.
  • from accepts the same inputs as peer.Resolve (@telegram, telegram, t.me/telegram, tg://resolve?domain=…, phone numbers).
  • Generated for all 8 peer-taking messages builders: GetHistory, GetRecentLocations, GetReplies, GetSavedHistory, GetUnreadMentions, GetUnreadPollVotes, GetUnreadReactions, Search.
  • Packages without peer methods (photos, participants, dialogs, …) are unchanged.

Generator-only edits

Per CLAUDE.md, only the generator was hand-edited; messages/queries.gen.go is regenerated. make generate is stable (no further diff).

Testing

  • go test -race ./telegram/query/... — green, including new resolve_test.go covering the default-resolver path and a custom WithResolver path.
  • Added a runnable ExampleQuery_resolveHistory.
  • go build ./..., go vet ./telegram/query/... clean.

🤖 Generated with Claude Code

Generate `<Method>Resolve(from string)` helpers for query builders that
take a tg.InputPeerClass parameter, so callers can pass a domain, phone
or deeplink directly instead of resolving the peer by hand first:

	query.NewQuery(raw).Messages().GetHistoryResolve("telegram").ForEach(ctx, cb)

The package QueryBuilder now carries a peer.Resolver (defaulting to
peer.DefaultResolver, overridable via WithResolver). The peer is resolved
lazily inside Query, wrapping resolve errors per context-error semantics.

Closes #283

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.26%. Comparing base (38b2b54) to head (bf78fcb).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1779      +/-   ##
==========================================
+ Coverage   71.24%   71.26%   +0.01%     
==========================================
  Files         503      503              
  Lines       23593    23602       +9     
==========================================
+ Hits        16809    16819      +10     
- Misses       5551     5552       +1     
+ Partials     1233     1231       -2     

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

@ernado ernado merged commit f74d0d1 into main Jun 15, 2026
14 checks passed
@ernado ernado deleted the feat/283-query-resolve-helpers branch June 15, 2026 00:38
pull Bot pushed a commit to dumpmemory/td that referenced this pull request Jun 15, 2026
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 (gotd#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 gotd#283

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

query: generate resolve helpers, if query needs peer parameter

1 participant