@s2-dev/streamstore - v0.22.0
    Preparing search index...

    Function paginate

    • Creates a lazy async iterable that automatically paginates through all results.

      Type Parameters

      • TItem

        The type of items being paginated

      • TArgs

        The query arguments type

      Parameters

      • fetcher: PageFetcher<TItem, TArgs>

        Function that fetches a single page of results

      • args: TArgs

        Query arguments (startAfter is managed internally)

      • getCursor: (item: TItem) => string

        Function to extract the cursor value from an item for the next page

      Returns AsyncIterable<TItem>

      An async iterable that yields items one at a time, fetching pages as needed

      const allBasins = paginate(
      (args) => this.list(args).then(r => ({ items: r.basins, hasMore: r.hasMore })),
      { prefix: "my-" },
      (basin) => basin.name
      );

      for await (const basin of allBasins) {
      console.log(basin.name);
      }