Skip to content

Commit

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

## 1.0.0-beta.2 (Unreleased)
## 1.0.0-beta.2 (2024-12-16)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- refresh @azure-rest/purview-workflow

## 1.0.0-beta.1 (2023-03-09)

Expand Down
1 change: 0 additions & 1 deletion sdk/purview/purview-workflow-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"dependencies": {
"@azure-rest/core-client": "^2.3.1",
"@azure/core-auth": "^1.9.0",
"@azure/core-paging": "^1.6.2",
"@azure/core-rest-pipeline": "^1.18.0",
"@azure/logger": "^1.1.4",
"tslib": "^2.8.1"
Expand Down
32 changes: 19 additions & 13 deletions sdk/purview/purview-workflow-rest/review/purview-workflow.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import type { Client } from '@azure-rest/core-client';
import type { ClientOptions } from '@azure-rest/core-client';
import type { HttpResponse } from '@azure-rest/core-client';
import type { PagedAsyncIterableIterator } from '@azure/core-paging';
import type { PathUncheckedResponse } from '@azure-rest/core-client';
import type { RequestParameters } from '@azure-rest/core-client';
import type { StreamableMethod } from '@azure-rest/core-client';
Expand Down Expand Up @@ -39,8 +38,6 @@ export interface ApproveApprovalTask {

// @public
export interface ApproveApprovalTask200Response extends HttpResponse {
// (undocumented)
body: Record<string, unknown>;
// (undocumented)
status: "200";
}
Expand Down Expand Up @@ -80,8 +77,6 @@ export interface CancelWorkflowRun {

// @public
export interface CancelWorkflowRun200Response extends HttpResponse {
// (undocumented)
body: Record<string, unknown>;
// (undocumented)
status: "200";
}
Expand All @@ -108,7 +103,7 @@ export interface CancelWorkflowRunMediaTypesParam {
export type CancelWorkflowRunParameters = CancelWorkflowRunMediaTypesParam & CancelWorkflowRunBodyParam & RequestParameters;

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

// @public
Expand Down Expand Up @@ -174,7 +169,7 @@ export interface ErrorResponseOutput {
export type GetArrayType<T> = T extends Array<infer TData> ? TData : never;

// @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 @@ -406,6 +401,18 @@ export interface Operation {
type: "CreateTerm" | "UpdateTerm" | "DeleteTerm" | "ImportTerms" | "UpdateAsset" | "GrantDataAccess";
}

// @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 All @@ -426,6 +433,11 @@ export type PurviewWorkflowClient = Client & {
path: Routes;
};

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

// @public
export interface ReassignCommand {
reassignments?: Array<ReassignCommandReassignmentsItem>;
Expand All @@ -444,8 +456,6 @@ export interface ReassignWorkflowTask {

// @public
export interface ReassignWorkflowTask200Response extends HttpResponse {
// (undocumented)
body: Record<string, unknown>;
// (undocumented)
status: "200";
}
Expand Down Expand Up @@ -478,8 +488,6 @@ export interface RejectApprovalTask {

// @public
export interface RejectApprovalTask200Response extends HttpResponse {
// (undocumented)
body: Record<string, unknown>;
// (undocumented)
status: "200";
}
Expand Down Expand Up @@ -615,8 +623,6 @@ export interface UpdateTaskStatus {

// @public
export interface UpdateTaskStatus200Response extends HttpResponse {
// (undocumented)
body: Record<string, unknown>;
// (undocumented)
status: "200";
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/purview/purview-workflow-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-workflow");
146 changes: 140 additions & 6 deletions sdk/purview/purview-workflow-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
49 changes: 35 additions & 14 deletions sdk/purview/purview-workflow-rest/src/purviewWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@

import type { ClientOptions } from "@azure-rest/core-client";
import { getClient } from "@azure-rest/core-client";
import { logger } from "./logger.js";
import type { TokenCredential } from "@azure/core-auth";
import type { PurviewWorkflowClient } from "./clientDefinitions.js";

/** The optional parameters for the client */
export interface PurviewWorkflowClientOptions extends ClientOptions {
/** The api version option of the client */
apiVersion?: string;
}

/**
* Initialize a new instance of `PurviewWorkflowClient`
* @param endpoint type: string, The account endpoint of your Purview account. Example: https://{accountName}.purview.azure.com/
* @param credentials type: TokenCredential, uniquely identify client credential
* @param options type: ClientOptions, the parameter for all optional parameters
* @param endpoint - The account endpoint of your Purview account. Example: https://{accountName}.purview.azure.com/
* @param credentials - uniquely identify client credential
* @param options - the parameter for all optional parameters
*/
export default function createClient(
endpoint: string,
credentials: TokenCredential,
options: ClientOptions = {},
{ apiVersion = "2022-05-01-preview", ...options }: PurviewWorkflowClientOptions = {},
): PurviewWorkflowClient {
const baseUrl = options.baseUrl ?? `${endpoint}/workflow`;
options.apiVersion = options.apiVersion ?? "2022-05-01-preview";
options = {
...options,
credentials: {
scopes: ["https://purview.azure.net/.default"],
},
};

const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpoint}/workflow`;
const userAgentInfo = `azsdk-js-purview-workflow-rest/1.0.0-beta.2`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
Expand All @@ -36,9 +35,31 @@ export default function createClient(
userAgentOptions: {
userAgentPrefix,
},
loggingOptions: {
logger: options.loggingOptions?.logger ?? logger.info,
},
credentials: {
scopes: ["https://purview.azure.net/.default"],
},
};
const client = getClient(endpointUrl, credentials, options) as PurviewWorkflowClient;

client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
client.pipeline.addPolicy({
name: "ClientApiVersionPolicy",
sendRequest: (req, next) => {
// Use the apiVersion defined in request url directly
// Append one if there is no apiVersion and we have one at client options
const url = new URL(req.url);
if (!url.searchParams.get("api-version") && apiVersion) {
req.url = `${req.url}${
Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"
}api-version=${apiVersion}`;
}

const client = getClient(baseUrl, credentials, options) as PurviewWorkflowClient;
return next(req);
},
});

return client;
}
Loading

0 comments on commit f301c0f

Please sign in to comment.