/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { GalleryImages } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { DevTestLabsClient } from "../devTestLabsClient"; import { GalleryImage, GalleryImagesListNextOptionalParams, GalleryImagesListOptionalParams, GalleryImagesListResponse, GalleryImagesListNextResponse } from "../models"; /// /** Class containing GalleryImages operations. */ export class GalleryImagesImpl implements GalleryImages { private readonly client: DevTestLabsClient; /** * Initialize a new instance of the class GalleryImages class. * @param client Reference to the service client */ constructor(client: DevTestLabsClient) { this.client = client; } /** * List gallery images in a given lab. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param options The options parameters. */ public list( resourceGroupName: string, labName: string, options?: GalleryImagesListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll(resourceGroupName, labName, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listPagingPage( resourceGroupName, labName, options, settings ); } }; } private async *listPagingPage( resourceGroupName: string, labName: string, options?: GalleryImagesListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: GalleryImagesListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list(resourceGroupName, labName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( resourceGroupName, labName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( resourceGroupName: string, labName: string, options?: GalleryImagesListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( resourceGroupName, labName, options )) { yield* page; } } /** * List gallery images in a given lab. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param options The options parameters. */ private _list( resourceGroupName: string, labName: string, options?: GalleryImagesListOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, options }, listOperationSpec ); } /** * ListNext * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( resourceGroupName: string, labName: string, nextLink: string, options?: GalleryImagesListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/galleryimages", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GalleryImageList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GalleryImageList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName ], headerParameters: [Parameters.accept], serializer };