diff --git a/sdk/notificationhubs/notification-hubs/CHANGELOG.md b/sdk/notificationhubs/notification-hubs/CHANGELOG.md index ee3223bf13cc..b08016d5a0a2 100644 --- a/sdk/notificationhubs/notification-hubs/CHANGELOG.md +++ b/sdk/notificationhubs/notification-hubs/CHANGELOG.md @@ -1,11 +1,15 @@ # Release History -## 1.2.4 (Unreleased) +## 2.0.0 (Unreleased) ### Features Added +- Moved to `@azure/core-lro` v3 for long running operations. + ### Breaking Changes +- Moving from `@azure/core-lro` v2 to v3 for long running operations. For APIs such as `beginSubmitNotificationHubJob`, this is a breaking change as it uses the new `PollerLike` interface instead of the old `SimplePollerLike` interface. See the [Polling API](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/core/core-lro/docs/MIGRATION.md#poller-api) migration guide for more information. + ### Bugs Fixed - Added `pushChannelExpired` and `pushVariables` to the `Installation` type. diff --git a/sdk/notificationhubs/notification-hubs/package.json b/sdk/notificationhubs/notification-hubs/package.json index 4e74fd0bf97a..5ca49112c04f 100644 --- a/sdk/notificationhubs/notification-hubs/package.json +++ b/sdk/notificationhubs/notification-hubs/package.json @@ -1,6 +1,6 @@ { "name": "@azure/notification-hubs", - "version": "1.2.4", + "version": "2.0.0", "description": "Azure Notification Hubs SDK for JavaScript", "sdk-type": "client", "main": "./dist/commonjs/index.js", @@ -80,7 +80,7 @@ "dependencies": { "@azure/core-auth": "^1.7.2", "@azure/abort-controller": "^2.1.2", - "@azure/core-lro": "^2.7.2", + "@azure/core-lro": "^3.0.0", "@azure/core-paging": "^1.6.2", "@azure/core-rest-pipeline": "^1.15.2", "@azure/core-tracing": "^1.1.2", diff --git a/sdk/notificationhubs/notification-hubs/review/notification-hubs-api.api.md b/sdk/notificationhubs/notification-hubs/review/notification-hubs-api.api.md index 2f05fae50700..ee66d5b0e63c 100644 --- a/sdk/notificationhubs/notification-hubs/review/notification-hubs-api.api.md +++ b/sdk/notificationhubs/notification-hubs/review/notification-hubs-api.api.md @@ -11,7 +11,7 @@ import { OperationState } from '@azure/core-lro'; import { PagedAsyncIterableIterator } from '@azure/core-paging'; import { PipelineRequest } from '@azure/core-rest-pipeline'; import { PipelineResponse } from '@azure/core-rest-pipeline'; -import { SimplePollerLike } from '@azure/core-lro'; +import { PollerLike } from '@azure/core-lro'; // @public export function beginSubmitNotificationHubJob(context: NotificationHubsClientContext, notificationHubJob: NotificationHubJob, polledOperationOptions?: PolledOperationOptions): Promise; diff --git a/sdk/notificationhubs/notification-hubs/review/notification-hubs-models.api.md b/sdk/notificationhubs/notification-hubs/review/notification-hubs-models.api.md index a820ec10e233..4d86ac419f2f 100644 --- a/sdk/notificationhubs/notification-hubs/review/notification-hubs-models.api.md +++ b/sdk/notificationhubs/notification-hubs/review/notification-hubs-models.api.md @@ -7,7 +7,7 @@ import { ClientOptions } from '@azure-rest/core-client'; import { OperationOptions } from '@azure-rest/core-client'; import { OperationState } from '@azure/core-lro'; -import { SimplePollerLike } from '@azure/core-lro'; +import { PollerLike } from '@azure/core-lro'; // @public export interface AdmInstallation extends DeviceTokenInstallation { @@ -835,7 +835,7 @@ export interface NotificationHubJob { } // @public -export type NotificationHubJobPoller = SimplePollerLike, NotificationHubJob>; +export type NotificationHubJobPoller = PollerLike, NotificationHubJob>; // @public export type NotificationHubJobStatus = diff --git a/sdk/notificationhubs/notification-hubs/review/notification-hubs.api.md b/sdk/notificationhubs/notification-hubs/review/notification-hubs.api.md index 4489eb7b9876..be27d33ab5d6 100644 --- a/sdk/notificationhubs/notification-hubs/review/notification-hubs.api.md +++ b/sdk/notificationhubs/notification-hubs/review/notification-hubs.api.md @@ -8,7 +8,7 @@ import { ClientOptions } from '@azure-rest/core-client'; import { OperationOptions } from '@azure-rest/core-client'; import { OperationState } from '@azure/core-lro'; import { PagedAsyncIterableIterator } from '@azure/core-paging'; -import { SimplePollerLike } from '@azure/core-lro'; +import { PollerLike } from '@azure/core-lro'; // @public export interface AdmInstallation extends DeviceTokenInstallation { @@ -836,7 +836,7 @@ export interface NotificationHubJob { } // @public -export type NotificationHubJobPoller = SimplePollerLike, NotificationHubJob>; +export type NotificationHubJobPoller = PollerLike, NotificationHubJob>; // @public export type NotificationHubJobStatus = diff --git a/sdk/notificationhubs/notification-hubs/src/api/beginSubmitNotificationHubJob.ts b/sdk/notificationhubs/notification-hubs/src/api/beginSubmitNotificationHubJob.ts index 702b561c734b..dcf131f942ae 100644 --- a/sdk/notificationhubs/notification-hubs/src/api/beginSubmitNotificationHubJob.ts +++ b/sdk/notificationhubs/notification-hubs/src/api/beginSubmitNotificationHubJob.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { AbortSignalLike } from "@azure/abort-controller"; -import { CancelOnProgress, OperationState, SimplePollerLike } from "@azure/core-lro"; +import { CancelOnProgress, OperationState, PollerLike } from "@azure/core-lro"; import { NotificationHubJob, NotificationHubJobPoller } from "../models/notificationHubJob.js"; import { NotificationHubsClientContext } from "./index.js"; import { PolledOperationOptions } from "../models/options.js"; @@ -38,12 +38,13 @@ export async function beginSubmitNotificationHubJob( const processProgressCallbacks = async (): Promise => progressCallbacks.forEach((h) => h(state)); let resultPromise: Promise | undefined; - let cancelJob: (() => void) | undefined; const abortController = new AbortController(); const currentPollIntervalInMs = polledOperationOptions.updateIntervalInMs ?? 2000; - const poller: SimplePollerLike, NotificationHubJob> = { - async poll(options?: { abortSignal?: AbortSignalLike }): Promise { + const poller: PollerLike, NotificationHubJob> = { + async poll(options?: { + abortSignal?: AbortSignalLike; + }): Promise> { submittedJob = await getNotificationHubJob(context, submittedJob.jobId!, options); if (submittedJob.status === "Running" || submittedJob.status === "Started") { state.status = "running"; @@ -67,6 +68,8 @@ export async function beginSubmitNotificationHubJob( if (state.status === "failed") { throw state.error; } + + return state; }, pollUntilDone(pollOptions?: { abortSignal?: AbortSignalLike }): Promise { @@ -84,9 +87,9 @@ export async function beginSubmitNotificationHubJob( } try { - if (!poller.isDone()) { + if (!poller.isDone) { await poller.poll({ abortSignal }); - while (!poller.isDone()) { + while (!poller.isDone) { await delay(currentPollIntervalInMs, { abortSignal }); await poller.poll({ abortSignal }); } @@ -96,7 +99,7 @@ export async function beginSubmitNotificationHubJob( } switch (state.status) { case "succeeded": - return poller.getResult() as NotificationHubJob; + return poller.result as NotificationHubJob; case "canceled": throw new Error("Operation was canceled"); case "failed": @@ -117,30 +120,45 @@ export async function beginSubmitNotificationHubJob( return () => progressCallbacks.delete(s); }, - isDone(): boolean { + get isDone(): boolean { return ["succeeded", "failed", "canceled"].includes(state.status); }, - stopPolling(): void { - abortController.abort(); - cancelJob?.(); + get operationState(): OperationState | undefined { + return state; }, - isStopped(): boolean { - return resultPromise === undefined; + get result(): NotificationHubJob | undefined { + return state.result; }, - getOperationState(): OperationState { - return state; + async serialize(): Promise { + return JSON.stringify({ state }); }, - getResult(): NotificationHubJob | undefined { - return state.result; + async submitted() { + // No-op + return; }, - toString() { - return JSON.stringify({ state }); + then( + onfulfilled?: + | ((value: NotificationHubJob) => TResult1 | PromiseLike) + | undefined + | null, + onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null, + ): Promise { + return poller.pollUntilDone().then(onfulfilled, onrejected); + }, + catch( + onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null, + ): Promise { + return poller.pollUntilDone().catch(onrejected); + }, + finally(onfinally?: (() => void) | undefined | null): Promise { + return poller.pollUntilDone().finally(onfinally); }, + [Symbol.toStringTag]: "Poller", }; return poller; diff --git a/sdk/notificationhubs/notification-hubs/src/models/notificationHubJob.ts b/sdk/notificationhubs/notification-hubs/src/models/notificationHubJob.ts index 671592e18b22..fa428dfc4d5b 100644 --- a/sdk/notificationhubs/notification-hubs/src/models/notificationHubJob.ts +++ b/sdk/notificationhubs/notification-hubs/src/models/notificationHubJob.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { OperationState, SimplePollerLike } from "@azure/core-lro"; +import { OperationState, PollerLike } from "@azure/core-lro"; /** * Describes the types of notification hub jobs. @@ -131,7 +131,7 @@ export interface NotificationHubJob { /** * Describes a poller for NotificationHubJob types. */ -export type NotificationHubJobPoller = SimplePollerLike< +export type NotificationHubJobPoller = PollerLike< OperationState, NotificationHubJob >;