Repository navigation
feat(topic): add getTopic() override for dynamic topic resolution - #30
Merged
Merged
Conversation
Mirrors the existing getPath() pattern on RESTQuery. The static `topic` template only supports fixed-shape topics, so consumers with variable-segment-count or conditionally-shaped topics had to hand-author one query class per shape. Subclasses can now override getTopic() to compute the topic at execution time from resolved params; when defined it takes precedence over the `topic` field, which becomes optional to match `path?` on RESTQuery. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pre-1.0 convention treats patch as backward-compatible (features and fixes) and minor as breaking. This change is purely additive. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
pzuraq
approved these changes
May 20, 2026
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.
Summary
getTopic?(): stringtoTopicQuery, mirroringgetPath?()onRESTQuery. When defined, it takes precedence over the statictopicfield and is evaluated at execution time against the resolved params, so a single class can express variable-segment-count or conditionally-shaped topics.topicfield optional (wasabstract topic: string), matchingpath?onRESTQuery. Existing queries that definetopicas a static template continue to work unchanged.TopicQueryAdapter.send()and theTopicQuery.getConfig()unsubscribe cleanup now resolve viagetTopic()when defined, otherwisetopic.send()throws a clear error if neither is set.Motivation
Consumers that need topics like
prefix:a:bvsprefix:a:b:cvsprefix:a:b:c:dhad to hand-author one class per shape because the static template is captured at extraction time and resolved via fixed[name]substitution, which can't express variable segment counts, optional trailing segments, or anything conditional on the actual param values.RESTQuery/RESTMutationalready solved the same problem withgetPath(). This bringsTopicQueryto parity.Example:
Test plan
npm run check-typescleannpm run test:unitall 1138 tests pass, including 3 new tests undergetTopic() override: basic resolution, variable-segment-count topics handled by one class, andgetTopic()taking precedence when both fields are definednpm run lintclean🤖 Generated with Claude Code