diff --git a/.changeset/rare-timers-care.md b/.changeset/rare-timers-care.md new file mode 100644 index 000000000..7d0883140 --- /dev/null +++ b/.changeset/rare-timers-care.md @@ -0,0 +1,5 @@ +--- +"@osdk/client": patch +--- + +Fix asyncIter to fetch subsequent pages diff --git a/packages/client/src/objectSet/createObjectSet.ts b/packages/client/src/objectSet/createObjectSet.ts index f9c63fa31..d04243ba3 100644 --- a/packages/client/src/objectSet/createObjectSet.ts +++ b/packages/client/src/objectSet/createObjectSet.ts @@ -16,10 +16,12 @@ import type { ObjectOrInterfaceDefinition, + ObjectOrInterfacePropertyKeysFrom2, ObjectTypeDefinition, } from "@osdk/api"; import type { BaseObjectSet, + FetchPageResult, LinkedType, LinkNames, MinimalObjectSet, @@ -141,11 +143,15 @@ export function createObjectSet( asyncIter: async function*(): AsyncIterableIterator> { let $nextPageToken: string | undefined = undefined; do { - const result = await base.fetchPage({ $nextPageToken }); - - for ( - const obj of result.data - ) { + const result: FetchPageResult< + Q, + ObjectOrInterfacePropertyKeysFrom2, + boolean, + "throw" + > = await base.fetchPage({ $nextPageToken }); + $nextPageToken = result.nextPageToken; + + for (const obj of result.data) { yield obj as Osdk; } } while ($nextPageToken != null); diff --git a/packages/legacy-client/src/client/net/loadObjectsPage.ts b/packages/legacy-client/src/client/net/loadObjectsPage.ts index dfe5077ca..66085abdd 100644 --- a/packages/legacy-client/src/client/net/loadObjectsPage.ts +++ b/packages/legacy-client/src/client/net/loadObjectsPage.ts @@ -115,7 +115,7 @@ export async function* loadObjectsIterator< ): AsyncIterableIterator { let pageToken: string | undefined = undefined; do { - const result = await loadObjectsPage( + const result: Result, LoadObjectSetError> = await loadObjectsPage( client, objectApiName, objectSetDefinition, @@ -124,6 +124,7 @@ export async function* loadObjectsIterator< { pageToken }, ); if (result.type === "ok") { + pageToken = result.value.nextPageToken; for ( const obj of result.value.data ) {