diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/review/arm-networkanalytics.api.md b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/review/arm-networkanalytics.api.md index 8232a1473a..7705850420 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/review/arm-networkanalytics.api.md +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/review/arm-networkanalytics.api.md @@ -5,6 +5,7 @@ ```ts import { AbortSignalLike } from '@azure/abort-controller'; +import type { CancelOnProgress } from '@azure/core-lro'; import { ClientOptions } from '@azure-rest/core-client'; import { OperationOptions } from '@azure-rest/core-client'; import { OperationState } from '@azure/core-lro'; @@ -183,6 +184,12 @@ export interface DataProductsListRolesAssignmentsOptionalParams extends Operatio // @public export interface DataProductsOperations { addUserRole: (resourceGroupName: string, dataProductName: string, body: RoleAssignmentCommonProperties, options?: DataProductsAddUserRoleOptionalParams) => Promise; + // Warning: (ae-forgotten-export) The symbol "SimplePollerLike" needs to be exported by the entry point index.d.ts + // + // @deprecated (undocumented) + beginCreate: (resourceGroupName: string, dataProductName: string, resource: DataProduct, options?: DataProductsCreateOptionalParams) => Promise, DataProduct>>; + // @deprecated (undocumented) + beginCreateAndWait: (resourceGroupName: string, dataProductName: string, resource: DataProduct, options?: DataProductsCreateOptionalParams) => Promise; create: (resourceGroupName: string, dataProductName: string, resource: DataProduct, options?: DataProductsCreateOptionalParams) => PollerLike, DataProduct>; delete: (resourceGroupName: string, dataProductName: string, options?: DataProductsDeleteOptionalParams) => PollerLike, void>; generateStorageAccountSasToken: (resourceGroupName: string, dataProductName: string, body: AccountSas, options?: DataProductsGenerateStorageAccountSasTokenOptionalParams) => Promise; diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/classic/dataProducts/index.ts b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/classic/dataProducts/index.ts index 430bdaaf3b..a000774e46 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/classic/dataProducts/index.ts +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/classic/dataProducts/index.ts @@ -40,52 +40,53 @@ import { } from "../../models/models.js"; import { PagedAsyncIterableIterator } from "../../static-helpers/pagingHelpers.js"; import { PollerLike, OperationState } from "@azure/core-lro"; +import { createSimplePoller, SimplePollerLike } from "../../static-helpers/pollingHelpers.js"; /** Interface representing a DataProducts operations. */ export interface DataProductsOperations { /** List data products by subscription. */ listBySubscription: ( - options?: DataProductsListBySubscriptionOptionalParams, + options?: DataProductsListBySubscriptionOptionalParams ) => PagedAsyncIterableIterator; /** List data products by resource group. */ listByResourceGroup: ( resourceGroupName: string, - options?: DataProductsListByResourceGroupOptionalParams, + options?: DataProductsListByResourceGroupOptionalParams ) => PagedAsyncIterableIterator; /** List user roles associated with the data product. */ listRolesAssignments: ( resourceGroupName: string, dataProductName: string, body: Record, - options?: DataProductsListRolesAssignmentsOptionalParams, + options?: DataProductsListRolesAssignmentsOptionalParams ) => Promise; /** Remove role from the data product. */ removeUserRole: ( resourceGroupName: string, dataProductName: string, body: RoleAssignmentDetail, - options?: DataProductsRemoveUserRoleOptionalParams, + options?: DataProductsRemoveUserRoleOptionalParams ) => Promise; /** Assign role to the data product. */ addUserRole: ( resourceGroupName: string, dataProductName: string, body: RoleAssignmentCommonProperties, - options?: DataProductsAddUserRoleOptionalParams, + options?: DataProductsAddUserRoleOptionalParams ) => Promise; /** Initiate key rotation on Data Product. */ rotateKey: ( resourceGroupName: string, dataProductName: string, body: KeyVaultInfo, - options?: DataProductsRotateKeyOptionalParams, + options?: DataProductsRotateKeyOptionalParams ) => Promise; /** Generate sas token for storage account. */ generateStorageAccountSasToken: ( resourceGroupName: string, dataProductName: string, body: AccountSas, - options?: DataProductsGenerateStorageAccountSasTokenOptionalParams, + options?: DataProductsGenerateStorageAccountSasTokenOptionalParams ) => Promise; /** Delete data product resource. */ /** @@ -96,119 +97,163 @@ export interface DataProductsOperations { delete: ( resourceGroupName: string, dataProductName: string, - options?: DataProductsDeleteOptionalParams, + options?: DataProductsDeleteOptionalParams ) => PollerLike, void>; /** Update data product resource. */ update: ( resourceGroupName: string, dataProductName: string, properties: DataProductUpdate, - options?: DataProductsUpdateOptionalParams, + options?: DataProductsUpdateOptionalParams ) => PollerLike, DataProduct>; /** Retrieve data product resource. */ get: ( resourceGroupName: string, dataProductName: string, - options?: DataProductsGetOptionalParams, + options?: DataProductsGetOptionalParams ) => Promise; /** Create data product resource. */ create: ( resourceGroupName: string, dataProductName: string, resource: DataProduct, - options?: DataProductsCreateOptionalParams, + options?: DataProductsCreateOptionalParams ) => PollerLike, DataProduct>; + /** @deprecated use create instead */ + beginCreate: ( + resourceGroupName: string, + dataProductName: string, + resource: DataProduct, + options?: DataProductsCreateOptionalParams + ) => Promise, DataProduct>>; + /** @deprecated use create instead */ + beginCreateAndWait: ( + resourceGroupName: string, + dataProductName: string, + resource: DataProduct, + options?: DataProductsCreateOptionalParams + ) => Promise; } function _getDataProducts(context: NetworkAnalyticsApiContext) { return { listBySubscription: ( - options?: DataProductsListBySubscriptionOptionalParams, + options?: DataProductsListBySubscriptionOptionalParams ) => listBySubscription(context, options), listByResourceGroup: ( resourceGroupName: string, - options?: DataProductsListByResourceGroupOptionalParams, + options?: DataProductsListByResourceGroupOptionalParams ) => listByResourceGroup(context, resourceGroupName, options), listRolesAssignments: ( resourceGroupName: string, dataProductName: string, body: Record, - options?: DataProductsListRolesAssignmentsOptionalParams, + options?: DataProductsListRolesAssignmentsOptionalParams ) => listRolesAssignments( context, resourceGroupName, dataProductName, body, - options, + options ), removeUserRole: ( resourceGroupName: string, dataProductName: string, body: RoleAssignmentDetail, - options?: DataProductsRemoveUserRoleOptionalParams, + options?: DataProductsRemoveUserRoleOptionalParams ) => removeUserRole( context, resourceGroupName, dataProductName, body, - options, + options ), addUserRole: ( resourceGroupName: string, dataProductName: string, body: RoleAssignmentCommonProperties, - options?: DataProductsAddUserRoleOptionalParams, + options?: DataProductsAddUserRoleOptionalParams ) => addUserRole(context, resourceGroupName, dataProductName, body, options), rotateKey: ( resourceGroupName: string, dataProductName: string, body: KeyVaultInfo, - options?: DataProductsRotateKeyOptionalParams, + options?: DataProductsRotateKeyOptionalParams ) => rotateKey(context, resourceGroupName, dataProductName, body, options), generateStorageAccountSasToken: ( resourceGroupName: string, dataProductName: string, body: AccountSas, - options?: DataProductsGenerateStorageAccountSasTokenOptionalParams, + options?: DataProductsGenerateStorageAccountSasTokenOptionalParams ) => generateStorageAccountSasToken( context, resourceGroupName, dataProductName, body, - options, + options ), delete: ( resourceGroupName: string, dataProductName: string, - options?: DataProductsDeleteOptionalParams, + options?: DataProductsDeleteOptionalParams ) => $delete(context, resourceGroupName, dataProductName, options), update: ( resourceGroupName: string, dataProductName: string, properties: DataProductUpdate, - options?: DataProductsUpdateOptionalParams, + options?: DataProductsUpdateOptionalParams ) => update(context, resourceGroupName, dataProductName, properties, options), get: ( resourceGroupName: string, dataProductName: string, - options?: DataProductsGetOptionalParams, + options?: DataProductsGetOptionalParams ) => get(context, resourceGroupName, dataProductName, options), create: ( resourceGroupName: string, dataProductName: string, resource: DataProduct, - options?: DataProductsCreateOptionalParams, + options?: DataProductsCreateOptionalParams ) => create(context, resourceGroupName, dataProductName, resource, options), + beginCreate: async ( + resourceGroupName: string, + dataProductName: string, + resource: DataProduct, + options?: DataProductsCreateOptionalParams + ): Promise, DataProduct>> => { + const poller = create( + context, + resourceGroupName, + dataProductName, + resource, + options + ); + await poller.submitted(); + return createSimplePoller(poller); + }, + beginCreateAndWait: async ( + resourceGroupName: string, + dataProductName: string, + resource: DataProduct, + options?: DataProductsCreateOptionalParams + ) => { + return await create( + context, + resourceGroupName, + dataProductName, + resource, + options + ); + }, }; } export function _getDataProductsOperations( - context: NetworkAnalyticsApiContext, + context: NetworkAnalyticsApiContext ): DataProductsOperations { return { ..._getDataProducts(context), diff --git a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/static-helpers/pollingHelpers.ts b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/static-helpers/pollingHelpers.ts index 2edbf783be..33b69f81b2 100644 --- a/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/static-helpers/pollingHelpers.ts +++ b/packages/typespec-test/test/NetworkAnalytics.Management/generated/typespec-ts/sdk/test/arm-test/src/static-helpers/pollingHelpers.ts @@ -1,21 +1,142 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { - PollerLike, - OperationState, - ResourceLocationConfig, - RunningOperation, - createHttpPoller, - OperationResponse, -} from "@azure/core-lro"; - import { Client, PathUncheckedResponse, createRestError, } from "@azure-rest/core-client"; import { AbortSignalLike } from "@azure/abort-controller"; +import type { + CancelOnProgress, + RunningOperation, + OperationResponse, + OperationState, + PollerLike, + ResourceLocationConfig, +} from "@azure/core-lro"; +import { createHttpPoller } from "@azure/core-lro"; + +/** + * A simple poller that can be used to poll a long running operation. + */ +export interface SimplePollerLike< + TState extends OperationState, + TResult, +> { + /** + * Returns true if the poller has finished polling. + */ + isDone(): boolean; + /** + * Returns the state of the operation. + */ + getOperationState(): TState; + /** + * Returns the result value of the operation, + * regardless of the state of the poller. + * It can return undefined or an incomplete form of the final TResult value + * depending on the implementation. + */ + getResult(): TResult | undefined; + /** + * Returns a promise that will resolve once a single polling request finishes. + * It does this by calling the update method of the Poller's operation. + */ + poll(options?: { abortSignal?: AbortSignalLike }): Promise; + /** + * Returns a promise that will resolve once the underlying operation is completed. + */ + pollUntilDone(pollOptions?: { + abortSignal?: AbortSignalLike; + }): Promise; + /** + * Invokes the provided callback after each polling is completed, + * sending the current state of the poller's operation. + * + * It returns a method that can be used to stop receiving updates on the given callback function. + */ + onProgress(callback: (state: TState) => void): CancelOnProgress; + + /** + * Returns a promise that could be used for serialized version of the poller's operation + * by invoking the operation's serialize method. + */ + serialize(): Promise; + + /** + * Wait the poller to be submitted. + */ + submitted(): Promise; + + /** + * Returns a string representation of the poller's operation. Similar to serialize but returns a string. + * @deprecated Use serialize() instead. + */ + toString(): string; + + /** + * Stops the poller from continuing to poll. Please note this will only stop the client-side polling + * @deprecated Use abortSignal to stop polling instead. + */ + stopPolling(): void; + + /** + * Returns true if the poller is stopped. + * @deprecated Use abortSignal status to track this instead. + */ + isStopped(): boolean; +} + +/** + * Create the deprecated SimplePollerLike from PollerLike + * @param poller PollerLike to convert + * @returns SimplePollerLike + */ +export function createSimplePoller(poller: PollerLike, TResult>): SimplePollerLike, TResult> { + const simplePoller: SimplePollerLike, TResult> = { + isDone() { + return poller.isDone; + }, + isStopped() { + throw new Error( + "isStopped is deprecated. Use abortSignal status to track this instead.", + ); + }, + getOperationState() { + if (!poller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return poller.operationState; + }, + getResult() { + return poller.result; + }, + toString() { + if (!poller.operationState) { + throw new Error( + "Operation state is not available. The poller may not have been started and you could await submitted() before calling getOperationState().", + ); + } + return JSON.stringify({ + state: poller.operationState, + }); + }, + stopPolling() { + throw new Error( + "stopPolling is deprecated. Use abortSignal to stop polling instead.", + ); + }, + onProgress: poller.onProgress, + poll: poller.poll, + pollUntilDone: poller.pollUntilDone, + serialize: poller.serialize, + submitted: poller.submitted, + }; + return simplePoller; +} export interface GetLongRunningPollerOptions { /** Delay to wait until next poll, in milliseconds. */ diff --git a/packages/typespec-ts/static/static-helpers/pagingHelpers.ts b/packages/typespec-ts/static/static-helpers/pagingHelpers.ts index cfd3ab0223..09922dfd5f 100644 --- a/packages/typespec-ts/static/static-helpers/pagingHelpers.ts +++ b/packages/typespec-ts/static/static-helpers/pagingHelpers.ts @@ -90,6 +90,7 @@ export interface PagedResult< export interface BuildPagedAsyncIteratorOptions { itemName?: string; nextLinkName?: string; + nextLinkMethod?: "POST" | "GET"; // the default is GET } /** @@ -114,7 +115,9 @@ export function buildPagedAsyncIterator< const result = pageLink === undefined ? await getInitialResponse() - : await client.pathUnchecked(pageLink).get(); + : (options.nextLinkMethod === "POST" + ? await client.pathUnchecked(pageLink).post() + : await client.pathUnchecked(pageLink).get()); checkPagingRequest(result, expectedStatuses); const results = await processResponseBody(result as TResponse); const nextLink = getNextLink(results, nextLinkName); diff --git a/packages/typespec-ts/static/static-helpers/pollingHelpers.ts b/packages/typespec-ts/static/static-helpers/pollingHelpers.ts index b72f3db8f4..fed4360f2f 100644 --- a/packages/typespec-ts/static/static-helpers/pollingHelpers.ts +++ b/packages/typespec-ts/static/static-helpers/pollingHelpers.ts @@ -38,6 +38,7 @@ export interface GetLongRunningPollerOptions { * The function to get the initial response */ getInitialResponse?: () => PromiseLike; + pollingMethod?: "POST" | "GET"; } export function getLongRunningPoller< TResponse extends PathUncheckedResponse, @@ -91,7 +92,11 @@ export function getLongRunningPoller< } let response; try { - response = await client.pathUnchecked(path).get({ abortSignal }); + if(options.pollingMethod === "POST") { + response = await client.pathUnchecked(path).post({ abortSignal }); + } else { + response = await client.pathUnchecked(path).get({ abortSignal }); + } } finally { options.abortSignal?.removeEventListener("abort", abortListener); pollOptions?.abortSignal?.removeEventListener("abort", abortListener);