Commit bc98b7e
feat: add generic search client traits and adapters (#994)
### Description
Introduce a family of search client traits with blanket implementations
and adapter utilities, replacing ad-hoc per-backend boilerplate with a
consistent, extensible design.
#### New traits (`stac::api`)
| Trait | Purpose | Required method |
| ----- | ------- | --------------- |
| `ItemsClient` | Single-page item search | `search` |
| `StreamItemsClient` | Stream items across all pages | `search_stream`
|
| `CollectionsClient` | Fetch all collections at once | `collections` |
| `PagedCollectionsClient` | Cursor-paginated collections
(future-proofing) | `collections_page` |
| `StreamCollectionsClient` | Stream all collections |
`collections_stream` |
| `ArrowItemsClient` *(geoarrow)* | Arrow record batch output |
`search_to_arrow` |
| `TransactionClient` | Write items and collections | `add_item`,
`add_collection` |
#### Blanket implementations
- `CollectionsClient + Clone + Sync → StreamCollectionsClient` — eagerly
fetches all collections and yields as a stream; no wrapper struct needed
- `ArrowItemsClient + Sync → ItemsClient + StreamItemsClient` *(geoarrow
feature)* — collects record batches synchronously and returns owned
items
#### Adapter utilities
- `PagedItemsStream\<T>` — wraps any `ItemsClient` to provide
`StreamItemsClient` via token/skip pagination (`ItemCollection::next`)
- `stream_pages_generic` — free function driving the items pagination
loop; used by `PagedItemsStream` and all server backends
- `stream_pages_collections_generic` — collections equivalent for
`PagedCollectionsClient` backends (ready for future paginated
`/collections` support)
- `RecordBatchReaderAdapter\<I>` *(geoarrow)* — bridges `Iterator<Item =
Result<RecordBatch, E>>` to `arrow_array::RecordBatchReader`
#### Backend implementations
All three server backends (memory, duckdb, pgstac) implement the full
trait family. `stac-duckdb` provides `HrefClient` (`ArrowItemsClient`)
and `SyncHrefClient` (`ItemsClient` + `CollectionsClient` +
`StreamItemsClient` via `Mutex`). `stac-io`'s `Client` implements
`StreamItemsClient` with HATEOAS link-following rather than token
pagination.
#### Design notes
- The `ItemsClient + Clone → StreamItemsClient` blanket cannot be added
because it would overlap with the `ArrowItemsClient` blanket under
Rust's coherence rules. Server backends use `stream_pages_generic`
directly in their explicit `StreamItemsClient` impls.
- `PagedCollectionsClient` has no blanket `StreamCollectionsClient` for
the same reason (would overlap with the `CollectionsClient` blanket).
Paginated backends call `stream_pages_collections_generic` in their own
impl.
### Related issues
- Groundwork for federated search / streaming backends
### Checklist
- [x] Unit tests
- [x] Documentation, including doctests
- [x] Pull request title follows [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/)
- [x] Pre-commit hooks pass (`prek run --all-files`)
---------
Co-authored-by: Pete Gadomski <pete.gadomski@gmail.com>1 parent 0f0158e commit bc98b7e
18 files changed
Lines changed: 1006 additions & 126 deletions
File tree
- .github
- crates
- core
- src
- api
- duckdb
- src
- io
- src
- pgstac/src
- server
- src
- backend
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
0 commit comments