Skip to content

Commit

Permalink
fix: lister return type
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniAkash committed Feb 28, 2024
1 parent b2aae46 commit 9fb12e4
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/client/lister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ export class Lister extends BaseClient {
requestData: TRequest,
pageNo: number = 1,
perPage: number = this.defaultPageSize,
) {
// Initial setup
): AsyncGenerator<TResponse, void, unknown> {
let page = pageNo;

while (true) {
Expand All @@ -52,28 +51,18 @@ export class Lister extends BaseClient {

// Perform gRPC request
const response = await this.grpcRequest(endpoint, requestData);
const responseObject = response.toObject();

// Check response status
if (response.toObject().status?.code !== StatusCode.SUCCESS) {
if (responseObject.status?.code !== StatusCode.SUCCESS) {
throw new Error(`Listing failed with response ${response}`);
}

// Process and yield response items
if (Object.keys(response).length === 1) {
if (Object.keys(responseObject).length === 1) {
break;
} else {
yield response;
// const listingResource = Object.keys(response)[1];
// for (const item of response[listingResource]) {
// if (listingResource === "dataset_inputs") {
// yield this.processResponseKeys(
// item["input"],
// listingResource.slice(0, -1),
// );
// } else {
// yield this.processResponseKeys(item, listingResource.slice(0, -1));
// }
// }
}

// Exit loop if pagination is not to be continued
Expand Down

0 comments on commit 9fb12e4

Please sign in to comment.