Repository navigation
Commit c024d0a
fix(fetchium): resolve TopicQuery adapter via subclass-aware lookup (#13)
* fix(fetchium): resolve TopicQuery adapter via subclass-aware lookup
TopicQuery declared `static adapter` as a type-only annotation with no
runtime value, so subclasses had to set it explicitly. That breaks two
patterns:
1. Generated TopicQuery classes that don't know which concrete adapter
a consumer will use — they can only target the abstract base.
2. Hand-authored subclasses had to write
`static adapter = MyAdapter as unknown as typeof TopicQueryAdapter`
to satisfy the override.
This change makes TopicQuery assign `static adapter = TopicQueryAdapter`
(mirroring the RESTQuery pattern) and teaches `QueryClient.getAdapter()`
to fall back to a subclass `instanceof` scan before auto-instantiating.
Why both changes are needed: RESTQueryAdapter is concrete, so the
registered instance's `.constructor` equals the static-adapter key on
the query and exact-match lookup hits. TopicQueryAdapter is abstract, so
consumers must register a subclass — the registered constructor is the
subclass, not the base, and exact-match misses. The new instanceof fallback
also makes the REST path correct in the (previously undefined) case where
a consumer registers a subclass of RESTQueryAdapter.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(fetchium): clarify how the generated-TopicQuery test resolves its adapter
The new test in `topic-query.test.ts` relies on the outer `beforeEach`
(~1800 lines above) registering a `MockTopicQueryAdapter` instance on the
QueryClient. Without that context the test reads as magic. Replace the
comment with one that names the inheritance + instanceof-scan path
explicitly and points at the outer registration.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(fetchium): add changeset for TopicQuery adapter resolution
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(streaming): update TopicQuery examples to drop unneeded adapter overrides
After the subclass-aware adapter resolution change, individual TopicQuery
subclasses no longer need to declare `static override adapter` for the
common case of one registered streaming adapter. Update the streaming
page so:
- Inline examples extend `TopicQuery` directly instead of an intermediate
`MyTopicQuery` base.
- The "Registering the adapter" section explains that the resolution
happens via inheritance + the QueryClient's instanceof lookup, with an
opt-in note for disambiguating between multiple registered subclasses.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(streaming): drop clunky em-dashed phrasing in adapter resolution note
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(streaming): trim hypothetical multi-adapter disambiguation guidance
In practice, apps register one streaming adapter per QueryClient — the
multi-adapter override pattern was over-engineering. Replace with a
one-liner pointing at "use a separate QueryClient" if you ever hit the
case.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(streaming): drop the dangling separate-QueryClient hint
The only justification for "use a separate QueryClient" is the adapter
resolution ambiguity case we already trimmed as hypothetical. Without
that reasoning, the sentence dangles. Remove it; the common-case
explanation stands on its own.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* feat(fetchium): throw in dev when adapter lookup is ambiguous
`QueryClient.getAdapter()`'s subclass-aware lookup picks the first
`instanceof` match in registration order. If a consumer registers two
adapters that both satisfy the same lookup base (e.g. two
`TopicQueryAdapter` subclasses on one client), the resolution is silent
and brittle.
In dev builds, scan all registered adapters and throw on more than one
match, naming the conflicting classes. In production, keep the original
fast path: first match wins, exit early. The dev-only branch is gated
behind `if (IS_DEV)` so it tree-shakes out of production bundles.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(fetchium): trim changeset to user-visible behavior
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(fetchium): simplify getAdapter loop and trim TopicQuery comment
- `getAdapter()`: collapse the four-case branch in the instanceof scan to
a single dev-mode ambiguity check plus `match ??= registered` for
first-match-wins. Also drop a now-redundant inline comment on the
auto-instantiate fallback (the JSDoc enumerates step 3 and the catch's
error message covers the failure mode).
- `TopicQuery.ts`: trim the five-line comment on `static override adapter`
to a single-line note about why the explicit type annotation is load-bearing.
No behavior change. All topic-query tests still pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(streaming): add callout warning about multi-adapter registration
Captures the "one TopicQueryAdapter subclass per QueryClient" design
intent and pre-warns about the dev-mode ambiguity error so users
structure their setup correctly the first time.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(streaming): trim multi-adapter callout to the load-bearing facts
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(fetchium): apply prettier formatting
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ee291d6 commit c024d0a
5 files changed
Lines changed: 130 additions & 27 deletions
File tree
- .changeset
- docs/src/app/core/streaming
- packages/fetchium/src
- __tests__
- topic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | 156 | | |
157 | 157 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
241 | 239 | | |
242 | 240 | | |
243 | 241 | | |
| |||
515 | 513 | | |
516 | 514 | | |
517 | 515 | | |
518 | | - | |
| 516 | + | |
519 | 517 | | |
520 | 518 | | |
521 | 519 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
128 | 142 | | |
129 | 143 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
143 | 159 | | |
144 | | - | |
145 | | - | |
146 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
147 | 177 | | |
148 | 178 | | |
149 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2071 | 2071 | | |
2072 | 2072 | | |
2073 | 2073 | | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
2074 | 2143 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
0 commit comments