Skip to content

Conversation

Copy link

Copilot AI commented Oct 9, 2025

Overview

This PR adds async generator methods to the OnspringClient class, enabling developers to easily iterate over paged API responses using modern JavaScript for await...of syntax. This addresses issue #[issue_number] by providing a more ergonomic way to work with large datasets without manual pagination management.

What's Changed

Added five new async iterable methods that automatically handle pagination:

  • getAppsIterable(pageSize = 50) - Iterate over all apps/surveys
  • getFieldsByAppIdIterable(appId, pageSize = 50) - Iterate over fields in an app
  • getRecordsByAppIdIterable(appId, fieldIds = [], dataFormat = DataFormat.Raw, pageSize = 50) - Iterate over records in an app
  • queryRecordsIterable(appId, filter, fieldIds = [], dataFormat = DataFormat.Raw, pageSize = 50) - Iterate over query results
  • getReportsByAppIdIterable(appId, pageSize = 50) - Iterate over reports in an app

Usage Example

Before (manual pagination):

let pageNumber = 1;
let hasMorePages = true;

while (hasMorePages) {
  const response = await client.getRecordsByAppId(
    new GetRecordsByAppIdRequest(appId, [], DataFormat.Raw, new PagingRequest(pageNumber, 50))
  );
  
  if (!response.isSuccessful) break;
  
  for (const record of response.data.items) {
    console.log(record);
  }
  
  hasMorePages = pageNumber < response.data.totalPages;
  pageNumber++;
}

After (async iteration):

for await (const record of client.getRecordsByAppIdIterable(appId)) {
  console.log(record);
}

Implementation Details

  • Each method is an async generator function that yields individual items from paginated responses
  • Pagination is handled automatically - methods continue fetching pages until all data is retrieved
  • Iteration stops gracefully on API errors or when all pages are exhausted
  • All methods support optional pageSize parameter (default: 50) for controlling request sizes
  • Methods maintain consistency with existing SDK patterns and parameter defaults

Testing

  • Added 25 comprehensive test cases covering:
    • Multi-page iteration scenarios
    • Error handling and early termination
    • Default parameter usage
    • Edge cases
  • Achieved 100% test coverage across all metrics (statements, branches, functions, lines)
  • All 858 tests passing (833 existing + 25 new)

Documentation

  • Added JSDoc comments with parameter descriptions and return types
  • Included usage examples in method documentation
  • Methods follow TypeScript async iterable conventions for IDE autocomplete support

Breaking Changes

None. This is a purely additive change that introduces new methods without modifying any existing functionality.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.onspring.dev
    • Triggering command: node /home/REDACTED/work/onspring-api-sdk-javascript/onspring-api-sdk-javascript/node_modules/.bin/mocha -R progress -r ts-node/register ./tests/**/*.spec.ts (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[FEAT]: Add client methods to support async iterables</issue_title>
<issue_description>The OnspringClient should expose methods that allow the user to asynchronously iterate over all the pages of items that support paged responses.

So should be able to do something like this:

for await (const record of client.getRecords()) {
}
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #17


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add client methods to support async iterables feat: Add async iterable methods for paged API responses Oct 10, 2025
Copilot finished work on behalf of StevanFreeborn October 10, 2025 00:02
Copilot AI requested a review from StevanFreeborn October 10, 2025 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Add client methods to support async iterables

2 participants