Skip to content

Commit

Permalink
[data-plane] refresh purview-sharing-rest (#31620)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazrael2119 authored Dec 20, 2024
1 parent 9a80672 commit 5e59a73
Show file tree
Hide file tree
Showing 9 changed files with 390 additions and 43 deletions.
5 changes: 5 additions & 0 deletions sdk/purview/purview-sharing-rest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release History

## 1.0.0-beta.3 (2024-12-16)

### Features Added
- refresh @azure-rest/purview-sharing

## 1.0.0-beta.2 (2023-06-23)

### Features Added
Expand Down
5 changes: 2 additions & 3 deletions sdk/purview/purview-sharing-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@azure-rest/purview-sharing",
"sdk-type": "client",
"author": "Microsoft Corporation",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "A generated SDK for PurviewSharing.",
"keywords": [
"node",
Expand Down Expand Up @@ -61,8 +61,7 @@
"@azure-rest/core-client": "^2.3.1",
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.9.0",
"@azure/core-lro": "^2.7.2",
"@azure/core-paging": "^1.6.2",
"@azure/core-lro": "^3.0.0",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
Expand Down
47 changes: 43 additions & 4 deletions sdk/purview/purview-sharing-rest/review/purview-sharing.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
```ts

import type { AbortSignalLike } from '@azure/abort-controller';
import type { CancelOnProgress } from '@azure/core-lro';
import type { Client } from '@azure-rest/core-client';
import type { ClientOptions } from '@azure-rest/core-client';
import type { CreateHttpPollerOptions } from '@azure/core-lro';
import type { HttpResponse } from '@azure-rest/core-client';
import type { OperationState } from '@azure/core-lro';
import type { PagedAsyncIterableIterator } from '@azure/core-paging';
import type { PathUncheckedResponse } from '@azure-rest/core-client';
import type { RawHttpHeaders } from '@azure/core-rest-pipeline';
import type { RawHttpHeadersInput } from '@azure/core-rest-pipeline';
import type { RequestParameters } from '@azure-rest/core-client';
import type { SimplePollerLike } from '@azure/core-lro';
import type { StreamableMethod } from '@azure-rest/core-client';
import type { TokenCredential } from '@azure/core-auth';

Expand Down Expand Up @@ -147,7 +147,7 @@ export interface BlobStorageArtifactPropertiesOutput {
}

// @public
function createClient(endpoint: string, credentials: TokenCredential, options?: ClientOptions): PurviewSharingClient;
function createClient(endpoint: string, credentials: TokenCredential, { apiVersion, ...options }?: PurviewSharingClientOptions): PurviewSharingClient;
export default createClient;

// @public
Expand All @@ -157,7 +157,7 @@ export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
export function getLongRunningPoller<TResult extends HttpResponse>(client: Client, initialResponse: TResult, options?: CreateHttpPollerOptions<TResult, OperationState<TResult>>): Promise<SimplePollerLike<OperationState<TResult>, TResult>>;

// @public
export type GetPage<TPage> = (pageLink: string, maxPageSize?: number) => Promise<{
export type GetPage<TPage> = (pageLink: string) => Promise<{
page: TPage;
nextPageLink?: string;
}>;
Expand Down Expand Up @@ -298,6 +298,18 @@ export interface OperationResponseOutput {
status: "Running" | "TransientFailure" | "Succeeded" | "Failed" | "NotStarted";
}

// @public
export interface PagedAsyncIterableIterator<TElement, TPage = TElement[], TPageSettings = PageSettings> {
[Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;
byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;
next(): Promise<IteratorResult<TElement>>;
}

// @public
export interface PageSettings {
continuationToken?: string;
}

// @public
export function paginate<TResponse extends PathUncheckedResponse>(client: Client, initialResponse: TResponse, options?: PagingOptions<TResponse>): PagedAsyncIterableIterator<PaginateReturn<TResponse>>;

Expand Down Expand Up @@ -341,6 +353,11 @@ export type PurviewSharingClient = Client & {
path: Routes;
};

// @public
export interface PurviewSharingClientOptions extends ClientOptions {
apiVersion?: string;
}

// @public
export type ReceivedShare = InPlaceReceivedShare;

Expand Down Expand Up @@ -1188,6 +1205,28 @@ export interface ShareResourcesGetAllShareResourcesQueryParamProperties {
orderby?: string;
}

// @public
export interface SimplePollerLike<TState extends OperationState<TResult>, TResult> {
getOperationState(): TState;
getResult(): TResult | undefined;
isDone(): boolean;
// @deprecated
isStopped(): boolean;
onProgress(callback: (state: TState) => void): CancelOnProgress;
poll(options?: {
abortSignal?: AbortSignalLike;
}): Promise<TState>;
pollUntilDone(pollOptions?: {
abortSignal?: AbortSignalLike;
}): Promise<TResult>;
serialize(): Promise<string>;
// @deprecated
stopPolling(): void;
submitted(): Promise<void>;
// @deprecated
toString(): string;
}

// @public
export type Sink = AdlsGen2AccountSink | BlobAccountSink;

Expand Down
5 changes: 5 additions & 0 deletions sdk/purview/purview-sharing-rest/src/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { createClientLogger } from "@azure/logger";
export const logger = createClientLogger("purview-sharing");
24 changes: 20 additions & 4 deletions sdk/purview/purview-sharing-rest/src/outputModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,23 @@ export interface OperationResponseOutput {

/** List of received shares. */
export interface ReceivedShareListOutput {
/** The Url of next result page. */
/**
* The Url of next result page.
*
* Value may contain a URL
*/
nextLink?: string;
/** Collection of items of type ReceivedShare */
value: Array<ReceivedShareOutput>;
}

/** List of sent shares. */
export interface SentShareListOutput {
/** The Url of next result page. */
/**
* The Url of next result page.
*
* Value may contain a URL
*/
nextLink?: string;
/** Collection of items of type SentShare */
value: Array<SentShareOutput>;
Expand All @@ -69,7 +77,11 @@ export interface SentShareOutputParent extends ProxyResourceOutput {

/** List of the sent share invitations */
export interface SentShareInvitationListOutput {
/** The Url of next result page. */
/**
* The Url of next result page.
*
* Value may contain a URL
*/
nextLink?: string;
/** Collection of items of type SentShareInvitation */
value: Array<SentShareInvitationOutput>;
Expand All @@ -82,7 +94,11 @@ export interface SentShareInvitationOutputParent extends ProxyResourceOutput {

/** A page of ShareResource results. */
export interface ShareResourceListOutput {
/** The Url of next result page. */
/**
* The Url of next result page.
*
* Value may contain a URL
*/
nextLink?: string;
/** Collection of items of type ShareResource */
value: Array<ShareResourceOutput>;
Expand Down
146 changes: 140 additions & 6 deletions sdk/purview/purview-sharing-rest/src/paginateHelper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,148 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import type { PagedAsyncIterableIterator, PagedResult } from "@azure/core-paging";
import { getPagedAsyncIterator } from "@azure/core-paging";
import type { Client, PathUncheckedResponse } from "@azure-rest/core-client";
import { createRestError } from "@azure-rest/core-client";

/**
* returns an async iterator that iterates over results. It also has a `byPage`
* method that returns pages of items at once.
*
* @param pagedResult - an object that specifies how to get pages.
* @returns a paged async iterator that iterates over results.
*/
function getPagedAsyncIterator<
TElement,
TPage = TElement[],
TPageSettings = PageSettings,
TLink = string,
>(
pagedResult: PagedResult<TPage, TPageSettings, TLink>,
): PagedAsyncIterableIterator<TElement, TPage, TPageSettings> {
const iter = getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(pagedResult);
return {
next() {
return iter.next();
},
[Symbol.asyncIterator]() {
return this;
},
byPage:
pagedResult?.byPage ??
(((settings?: PageSettings) => {
const { continuationToken } = settings ?? {};
return getPageAsyncIterator(pagedResult, {
pageLink: continuationToken as unknown as TLink | undefined,
});
}) as unknown as (settings?: TPageSettings) => AsyncIterableIterator<TPage>),
};
}

async function* getItemAsyncIterator<TElement, TPage, TLink, TPageSettings>(
pagedResult: PagedResult<TPage, TPageSettings, TLink>,
): AsyncIterableIterator<TElement> {
const pages = getPageAsyncIterator(pagedResult);
const firstVal = await pages.next();
// if the result does not have an array shape, i.e. TPage = TElement, then we return it as is
if (!Array.isArray(firstVal.value)) {
// can extract elements from this page
const { toElements } = pagedResult;
if (toElements) {
yield* toElements(firstVal.value) as TElement[];
for await (const page of pages) {
yield* toElements(page) as TElement[];
}
} else {
yield firstVal.value;
// `pages` is of type `AsyncIterableIterator<TPage>` but TPage = TElement in this case
yield* pages as unknown as AsyncIterableIterator<TElement>;
}
} else {
yield* firstVal.value;
for await (const page of pages) {
// pages is of type `AsyncIterableIterator<TPage>` so `page` is of type `TPage`. In this branch,
// it must be the case that `TPage = TElement[]`
yield* page as unknown as TElement[];
}
}
}

async function* getPageAsyncIterator<TPage, TLink, TPageSettings>(
pagedResult: PagedResult<TPage, TPageSettings, TLink>,
options: {
pageLink?: TLink;
} = {},
): AsyncIterableIterator<TPage> {
const { pageLink } = options;
let response = await pagedResult.getPage(pageLink ?? pagedResult.firstPageLink);
if (!response) {
return;
}
yield response.page;
while (response.nextPageLink) {
response = await pagedResult.getPage(response.nextPageLink);
if (!response) {
return;
}
yield response.page;
}
}

/**
* An interface that tracks the settings for paged iteration
*/
export interface PageSettings {
/**
* The token that keeps track of where to continue the iterator
*/
continuationToken?: string;
}

/**
* An interface that allows async iterable iteration both to completion and by page.
*/
export interface PagedAsyncIterableIterator<
TElement,
TPage = TElement[],
TPageSettings = PageSettings,
> {
/**
* The next method, part of the iteration protocol
*/
next(): Promise<IteratorResult<TElement>>;
/**
* The connection to the async iterator, part of the iteration protocol
*/
[Symbol.asyncIterator](): PagedAsyncIterableIterator<TElement, TPage, TPageSettings>;
/**
* Return an AsyncIterableIterator that works a page at a time
*/
byPage: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;
}

/**
* An interface that describes how to communicate with the service.
*/
interface PagedResult<TPage, TPageSettings = PageSettings, TLink = string> {
/**
* Link to the first page of results.
*/
firstPageLink: TLink;
/**
* A method that returns a page of results.
*/
getPage: (pageLink: TLink) => Promise<{ page: TPage; nextPageLink?: TLink } | undefined>;
/**
* a function to implement the `byPage` method on the paged async iterator.
*/
byPage?: (settings?: TPageSettings) => AsyncIterableIterator<TPage>;

/**
* A function to extract elements from a page.
*/
toElements?: (page: TPage) => unknown[];
}

/**
* Helper type to extract the type of an array
*/
Expand All @@ -14,10 +151,7 @@ export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;
/**
* The type of a custom function that defines how to get a page and a link to the next one if any.
*/
export type GetPage<TPage> = (
pageLink: string,
maxPageSize?: number,
) => Promise<{
export type GetPage<TPage> = (pageLink: string) => Promise<{
page: TPage;
nextPageLink?: string;
}>;
Expand Down
Loading

0 comments on commit 5e59a73

Please sign in to comment.