Skip to content

Commit

Permalink
Fix asyncIter to actually fetch next pages (#483)
Browse files Browse the repository at this point in the history
* Fix asyncIter to actually fetch next pages

* Add changeset

* Fix asyncIter in legacy-client

Tested changes
  • Loading branch information
bryantpark04 authored Jul 16, 2024
1 parent 8b91726 commit 4824449
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-timers-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@osdk/client": patch
---

Fix asyncIter to fetch subsequent pages
16 changes: 11 additions & 5 deletions packages/client/src/objectSet/createObjectSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

import type {
ObjectOrInterfaceDefinition,
ObjectOrInterfacePropertyKeysFrom2,
ObjectTypeDefinition,
} from "@osdk/api";
import type {
BaseObjectSet,
FetchPageResult,
LinkedType,
LinkNames,
MinimalObjectSet,
Expand Down Expand Up @@ -141,11 +143,15 @@ export function createObjectSet<Q extends ObjectOrInterfaceDefinition>(
asyncIter: async function*(): AsyncIterableIterator<Osdk<Q, "$all">> {
let $nextPageToken: string | undefined = undefined;
do {
const result = await base.fetchPage({ $nextPageToken });

for (
const obj of result.data
) {
const result: FetchPageResult<
Q,
ObjectOrInterfacePropertyKeysFrom2<Q>,
boolean,
"throw"
> = await base.fetchPage({ $nextPageToken });
$nextPageToken = result.nextPageToken;

for (const obj of result.data) {
yield obj as Osdk<Q, "$all">;
}
} while ($nextPageToken != null);
Expand Down
3 changes: 2 additions & 1 deletion packages/legacy-client/src/client/net/loadObjectsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export async function* loadObjectsIterator<
): AsyncIterableIterator<T> {
let pageToken: string | undefined = undefined;
do {
const result = await loadObjectsPage(
const result: Result<Page<T>, LoadObjectSetError> = await loadObjectsPage(
client,
objectApiName,
objectSetDefinition,
Expand All @@ -124,6 +124,7 @@ export async function* loadObjectsIterator<
{ pageToken },
);
if (result.type === "ok") {
pageToken = result.value.nextPageToken;
for (
const obj of result.value.data
) {
Expand Down

0 comments on commit 4824449

Please sign in to comment.