Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientModel: Updates to paging types to support sub-client enumerator pattern #44825

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

annelo-msft
Copy link
Member

@annelo-msft annelo-msft commented Jul 1, 2024

Overview

In response to feedback on the System.ClientModel collection and paging types from Azure SDK architects, we are making changes to these APIs to address the following considerations:

  1. Improve the user experience for the two primary use cases: enumerating all items and rendering a single page of results
  2. Improve alignment across convenience and protocol methods for SCM-based clients -- in SCM-based clients, convenience method return types inherit from protocol method return types
  3. Be able to generate a subclient that can be returned from both convenience and protocol methods
  4. Be able to rehydrate a collection subclient from a persisted rehydration token
  5. Make the "continuation token" concept more opaque

This PR addresses the above considerations in the following ways:

  1. SCM-based clients now return PageCollection<T> (or AsyncPageCollection<T>) from service methods that request a collection of values from paginated endpoints. These types have two methods: GetAllValues and GetCurrentPage (and corresponding async methods) that can be called by users to implement the primary scenarios.
  2. In SCM-based clients, protocol methods return IEnumerable<ClientResult> or IAsyncEnumerable<ClientResult>. Each ClientResult in these collections represents a page of values returned by a single service response. PageCollection<T> and AsyncPageCollection<T> inherit from IEnumerable<ClientResult> and IAsyncEnumerable<ClientResult>, respectively.
  3. Internal enumerator types will be generated in SCM-based clients. These will hold the service-specific methods needed to get the first page of values from user-provided parameters, and any next pages of values from a combination of user-provided parameters and the prior service response. Emitted helper types provide internal methods used to wrap the generated enumerators in PageCollection<T> and AsyncPageCollection<T> to return from service methods.
  4. PageResult<T> has two ContinuationToken properties that can be used by generated subclients to obtain either the same page or the next page in the collection. These tokens can be passed to service methods to obtain a page collection subclient that starts from the page the token represents.
  5. ContinuationToken is an opaque wrapper around some bytes instead of a string as it was before.

What's in this PR

This PR contains the following:

  • Renames to CollectionResult<T>. AsyncCollectionResult<T>, and PageResult<T> to align with the convention that the Result suffix indicates the type inherits from ClientResult -- users can call GetRawResponse on these types to obtain the raw response backing the return type.
  • Implementations of the new PageCollection<T>, AsyncPageCollection<T> and ContinuationToken types as described above.
  • Internal helper types used to create client-specific implementations of PageCollection<T>, AsyncPageCollection<T> and ContinuationToken corresponding to a paginated service operation. These types are intended to be emitted by the generator into individual client libraries.
  • Mock PagingClient and PagingProtocolClient implementations illustrating the patterns intended to be used by SCM-based clients for clients that have both convenience methods and protocol methods, and clients that have only protocol methods, respectively.
  • Unit tests of type implementations and scenario tests implemented using PagingClient and PagingProtocolClient.

@azure-sdk
Copy link
Collaborator

API change check

APIView has identified API level changes in this PR and created following API reviews.

System.ClientModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants