Skip to content

Commit 2691c27

Browse files
committed
fix: Fix search API to return paginator
1 parent e886410 commit 2691c27

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/mastodon/rest/v1/search-repository.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ export interface SearchParams extends DefaultPaginationParams {
1717
}
1818

1919
export interface SearchRepository {
20+
/**
21+
* @deprecated Use `list` instead
22+
*/
23+
fetch(params: SearchParams, meta?: HttpMetaParams): Search;
24+
2025
/**
2126
* Search, but hashtags is an array of strings instead of an array of Tag.
2227
* @param params Parameters
2328
* @return Results
2429
* @see https://docs.joinmastodon.org/methods/search/
2530
*/
26-
fetch(
31+
list(
2732
params: SearchParams,
2833
meta?: HttpMetaParams,
2934
): Paginator<Search, SearchParams>;

src/mastodon/rest/v2/search-repository.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ export interface SearchParams extends DefaultPaginationParams {
2121
}
2222

2323
export interface SearchRepository {
24+
/**
25+
* @deprecated Use `list` instead
26+
*/
27+
fetch(params: SearchParams, meta?: HttpMetaParams): Search;
28+
2429
/**
2530
* Perform a search
2631
* @param params Parameters
2732
* @return Results
2833
* @see https://docs.joinmastodon.org/methods/search/
2934
*/
30-
fetch(
35+
list(
3136
params: SearchParams,
3237
meta?: HttpMetaParams,
3338
): Paginator<Search, SearchParams>;

tests/rest/v2/search.spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
it("searches", async () => {
22
await using session = await sessions.acquire();
3-
const results = await session.rest.v2.search.fetch({
3+
const results = await session.rest.v2.search.list({
44
q: "mastodon",
55
});
66

@@ -10,3 +10,19 @@ it("searches", async () => {
1010
hashtags: expect.any(Array),
1111
});
1212
});
13+
14+
it("can be iterated over", async () => {
15+
await using session = await sessions.acquire();
16+
const results = session.rest.v2.search.list({
17+
q: "mastodon",
18+
});
19+
20+
const p1 = await results.next();
21+
22+
expect(typeof p1.done).toBe("boolean");
23+
expect(p1.value).toMatchObject({
24+
accounts: expect.any(Array),
25+
statuses: expect.any(Array),
26+
hashtags: expect.any(Array),
27+
});
28+
});

0 commit comments

Comments
 (0)