diff --git a/src/adapters/action/paginator-http.ts b/src/adapters/action/paginator-http.ts index fa59ef77..d7bff0d7 100644 --- a/src/adapters/action/paginator-http.ts +++ b/src/adapters/action/paginator-http.ts @@ -7,13 +7,12 @@ import { type mastodon } from "../../mastodon"; export class PaginatorHttp implements mastodon.Paginator { - private direction: mastodon.Direction = "next"; - constructor( private readonly http: Http, private nextPath?: string, private nextParams?: Params | string, private readonly meta?: HttpMetaParams, + private readonly direction: mastodon.Direction = "next", ) {} async next(): Promise> { @@ -76,9 +75,13 @@ export class PaginatorHttp } setDirection(direction: mastodon.Direction): PaginatorHttp { - const that = this.clone(); - that.direction = direction; - return that; + return new PaginatorHttp( + this.http, + this.nextPath, + this.nextParams, + this.meta, + direction, + ); } [Symbol.asyncIterator](): AsyncIterator< @@ -117,6 +120,7 @@ export class PaginatorHttp this.nextPath, this.nextParams, this.meta, + this.direction, ); } } diff --git a/src/mastodon/paginator.ts b/src/mastodon/paginator.ts index f2d49b43..eba34334 100644 --- a/src/mastodon/paginator.ts +++ b/src/mastodon/paginator.ts @@ -2,17 +2,29 @@ export type Direction = "next" | "prev"; // eslint-disable-next-line prettier/prettier export interface Paginator extends PromiseLike { + /** + * Get the current direction of the paginator. + * @returns The current direction of the paginator. + */ getDirection(): Direction; - setDirection(direction: Direction): void; + /** + * Creates a new paginator with the given direction. + * @param direction New direction of the paginator. + * @returns A new paginator with the given direction. + */ + setDirection(direction: Direction): Paginator; + + /** + * Clones the paginator. + * @returns A new paginator with the same direction and parameters. + */ clone(): Paginator; next(params?: Params | string): Promise>; - return( value: undefined | PromiseLike, ): Promise>; - throw(e?: unknown): Promise>; values(): AsyncIterableIterator;