/* * 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 { Projects } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { DevCenterClient } from "../devCenterClient"; import { SimplePollerLike, OperationState, createHttpPoller, } from "@azure/core-lro"; import { createLroSpec } from "../lroImpl"; import { Project, ProjectsListBySubscriptionNextOptionalParams, ProjectsListBySubscriptionOptionalParams, ProjectsListBySubscriptionResponse, ProjectsListByResourceGroupNextOptionalParams, ProjectsListByResourceGroupOptionalParams, ProjectsListByResourceGroupResponse, ProjectsGetOptionalParams, ProjectsGetResponse, ProjectsCreateOrUpdateOptionalParams, ProjectsCreateOrUpdateResponse, ProjectUpdate, ProjectsUpdateOptionalParams, ProjectsUpdateResponse, ProjectsDeleteOptionalParams, ProjectsDeleteResponse, ProjectsListBySubscriptionNextResponse, ProjectsListByResourceGroupNextResponse, } from "../models"; /// /** Class containing Projects operations. */ export class ProjectsImpl implements Projects { private readonly client: DevCenterClient; /** * Initialize a new instance of the class Projects class. * @param client Reference to the service client */ constructor(client: DevCenterClient) { this.client = client; } /** * Lists all projects in the subscription. * @param options The options parameters. */ public listBySubscription( options?: ProjectsListBySubscriptionOptionalParams, ): PagedAsyncIterableIterator { const iter = this.listBySubscriptionPagingAll(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.listBySubscriptionPagingPage(options, settings); }, }; } private async *listBySubscriptionPagingPage( options?: ProjectsListBySubscriptionOptionalParams, settings?: PageSettings, ): AsyncIterableIterator { let result: ProjectsListBySubscriptionResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listBySubscription(options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listBySubscriptionNext(continuationToken, options); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listBySubscriptionPagingAll( options?: ProjectsListBySubscriptionOptionalParams, ): AsyncIterableIterator { for await (const page of this.listBySubscriptionPagingPage(options)) { yield* page; } } /** * Lists all projects in the resource group. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param options The options parameters. */ public listByResourceGroup( resourceGroupName: string, options?: ProjectsListByResourceGroupOptionalParams, ): PagedAsyncIterableIterator { const iter = this.listByResourceGroupPagingAll(resourceGroupName, 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.listByResourceGroupPagingPage( resourceGroupName, options, settings, ); }, }; } private async *listByResourceGroupPagingPage( resourceGroupName: string, options?: ProjectsListByResourceGroupOptionalParams, settings?: PageSettings, ): AsyncIterableIterator { let result: ProjectsListByResourceGroupResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByResourceGroup(resourceGroupName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByResourceGroupNext( resourceGroupName, continuationToken, options, ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByResourceGroupPagingAll( resourceGroupName: string, options?: ProjectsListByResourceGroupOptionalParams, ): AsyncIterableIterator { for await (const page of this.listByResourceGroupPagingPage( resourceGroupName, options, )) { yield* page; } } /** * Lists all projects in the subscription. * @param options The options parameters. */ private _listBySubscription( options?: ProjectsListBySubscriptionOptionalParams, ): Promise { return this.client.sendOperationRequest( { options }, listBySubscriptionOperationSpec, ); } /** * Lists all projects in the resource group. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param options The options parameters. */ private _listByResourceGroup( resourceGroupName: string, options?: ProjectsListByResourceGroupOptionalParams, ): Promise { return this.client.sendOperationRequest( { resourceGroupName, options }, listByResourceGroupOperationSpec, ); } /** * Gets a specific project. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param options The options parameters. */ get( resourceGroupName: string, projectName: string, options?: ProjectsGetOptionalParams, ): Promise { return this.client.sendOperationRequest( { resourceGroupName, projectName, options }, getOperationSpec, ); } /** * Creates or updates a project. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param body Represents a project. * @param options The options parameters. */ async beginCreateOrUpdate( resourceGroupName: string, projectName: string, body: Project, options?: ProjectsCreateOrUpdateOptionalParams, ): Promise< SimplePollerLike< OperationState, ProjectsCreateOrUpdateResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, body, options }, spec: createOrUpdateOperationSpec, }); const poller = await createHttpPoller< ProjectsCreateOrUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Creates or updates a project. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param body Represents a project. * @param options The options parameters. */ async beginCreateOrUpdateAndWait( resourceGroupName: string, projectName: string, body: Project, options?: ProjectsCreateOrUpdateOptionalParams, ): Promise { const poller = await this.beginCreateOrUpdate( resourceGroupName, projectName, body, options, ); return poller.pollUntilDone(); } /** * Partially updates a project. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param body Updatable project properties. * @param options The options parameters. */ async beginUpdate( resourceGroupName: string, projectName: string, body: ProjectUpdate, options?: ProjectsUpdateOptionalParams, ): Promise< SimplePollerLike< OperationState, ProjectsUpdateResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, body, options }, spec: updateOperationSpec, }); const poller = await createHttpPoller< ProjectsUpdateResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Partially updates a project. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param body Updatable project properties. * @param options The options parameters. */ async beginUpdateAndWait( resourceGroupName: string, projectName: string, body: ProjectUpdate, options?: ProjectsUpdateOptionalParams, ): Promise { const poller = await this.beginUpdate( resourceGroupName, projectName, body, options, ); return poller.pollUntilDone(); } /** * Deletes a project resource. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param options The options parameters. */ async beginDelete( resourceGroupName: string, projectName: string, options?: ProjectsDeleteOptionalParams, ): Promise< SimplePollerLike< OperationState, ProjectsDeleteResponse > > { const directSendOperation = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ): Promise => { return this.client.sendOperationRequest(args, spec); }; const sendOperationFn = async ( args: coreClient.OperationArguments, spec: coreClient.OperationSpec, ) => { let currentRawResponse: coreClient.FullOperationResponse | undefined = undefined; const providedCallback = args.options?.onResponse; const callback: coreClient.RawResponseCallback = ( rawResponse: coreClient.FullOperationResponse, flatResponse: unknown, ) => { currentRawResponse = rawResponse; providedCallback?.(rawResponse, flatResponse); }; const updatedArgs = { ...args, options: { ...args.options, onResponse: callback, }, }; const flatResponse = await directSendOperation(updatedArgs, spec); return { flatResponse, rawResponse: { statusCode: currentRawResponse!.status, body: currentRawResponse!.parsedBody, headers: currentRawResponse!.headers.toJSON(), }, }; }; const lro = createLroSpec({ sendOperationFn, args: { resourceGroupName, projectName, options }, spec: deleteOperationSpec, }); const poller = await createHttpPoller< ProjectsDeleteResponse, OperationState >(lro, { restoreFrom: options?.resumeFrom, intervalInMs: options?.updateIntervalInMs, resourceLocationConfig: "azure-async-operation", }); await poller.poll(); return poller; } /** * Deletes a project resource. * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param projectName The name of the project. * @param options The options parameters. */ async beginDeleteAndWait( resourceGroupName: string, projectName: string, options?: ProjectsDeleteOptionalParams, ): Promise { const poller = await this.beginDelete( resourceGroupName, projectName, options, ); return poller.pollUntilDone(); } /** * ListBySubscriptionNext * @param nextLink The nextLink from the previous successful call to the ListBySubscription method. * @param options The options parameters. */ private _listBySubscriptionNext( nextLink: string, options?: ProjectsListBySubscriptionNextOptionalParams, ): Promise { return this.client.sendOperationRequest( { nextLink, options }, listBySubscriptionNextOperationSpec, ); } /** * ListByResourceGroupNext * @param resourceGroupName The name of the resource group. The name is case insensitive. * @param nextLink The nextLink from the previous successful call to the ListByResourceGroup method. * @param options The options parameters. */ private _listByResourceGroupNext( resourceGroupName: string, nextLink: string, options?: ProjectsListByResourceGroupNextOptionalParams, ): Promise { return this.client.sendOperationRequest( { resourceGroupName, nextLink, options }, listByResourceGroupNextOperationSpec, ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listBySubscriptionOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/providers/Microsoft.DevCenter/projects", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ProjectListResult, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion, Parameters.top], urlParameters: [Parameters.$host, Parameters.subscriptionId], headerParameters: [Parameters.accept], serializer, }; const listByResourceGroupOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ProjectListResult, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion, Parameters.top], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, ], headerParameters: [Parameters.accept], serializer, }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.Project, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, ], headerParameters: [Parameters.accept], serializer, }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.Project, }, 201: { bodyMapper: Mappers.Project, }, 202: { bodyMapper: Mappers.Project, }, 204: { bodyMapper: Mappers.Project, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, requestBody: Parameters.body2, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.Project, }, 201: { bodyMapper: Mappers.Project, }, 202: { bodyMapper: Mappers.Project, }, 204: { bodyMapper: Mappers.Project, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, requestBody: Parameters.body3, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer, }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevCenter/projects/{projectName}", httpMethod: "DELETE", responses: { 200: { headersMapper: Mappers.ProjectsDeleteHeaders, }, 201: { headersMapper: Mappers.ProjectsDeleteHeaders, }, 202: { headersMapper: Mappers.ProjectsDeleteHeaders, }, 204: { headersMapper: Mappers.ProjectsDeleteHeaders, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.projectName, ], headerParameters: [Parameters.accept], serializer, }; const listBySubscriptionNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ProjectListResult, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.nextLink, ], headerParameters: [Parameters.accept], serializer, }; const listByResourceGroupNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ProjectListResult, }, default: { bodyMapper: Mappers.ErrorResponse, }, }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.nextLink, ], headerParameters: [Parameters.accept], serializer, };