Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re generate cadl ranch tests #8

Open
wants to merge 1 commit into
base: improve-static-file-handling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
_PagedUser,
_UserListResults,
} from "../models/models.js";
import { PagedAsyncIterableIterator } from "../models/pagingTypes.js";
import { buildPagedAsyncIterator } from "./pagingHelpers.js";
import {
isUnexpected,
BasicContext as Client,
Expand Down Expand Up @@ -48,6 +46,10 @@ import {
operationOptionsToRequestParameters,
createRestError,
} from "@azure-rest/core-client";
import {
PagedAsyncIterableIterator,
buildPagedAsyncIterator,
} from "../static-helpers/pagingHelpers.js";
import {
CreateOrUpdateOptionalParams,
CreateOrReplaceOptionalParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
ListFirstItemOptionalParams,
ListSecondItemOptionalParams,
} from "./models/options.js";
import { PagedAsyncIterableIterator } from "./models/pagingTypes.js";
import {
createBasic,
BasicClientOptionalParams,
Expand All @@ -38,6 +37,7 @@ import {
listFirstItem,
listSecondItem,
} from "./api/index.js";
import { PagedAsyncIterableIterator } from "./static-helpers/pagingHelpers.js";

export { BasicClientOptionalParams } from "./api/basicContext.js";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import {
PageSettings,
ContinuablePage,
PagedAsyncIterableIterator,
} from "./static-helpers/pagingHelpers.js";

export { BasicClient, BasicClientOptionalParams } from "./basicClient.js";
export {
User,
Expand All @@ -21,7 +27,5 @@ export {
ExportOptionalParams,
ListFirstItemOptionalParams,
ListSecondItemOptionalParams,
PageSettings,
ContinuablePage,
PagedAsyncIterableIterator,
} from "./models/index.js";
export { PageSettings, ContinuablePage, PagedAsyncIterableIterator };
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,3 @@ export {
ListFirstItemOptionalParams,
ListSecondItemOptionalParams,
} from "./options.js";
export {
PageSettings,
ContinuablePage,
PagedAsyncIterableIterator,
} from "./pagingTypes.js";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,105 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

Comment on lines +4 to +6
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this duplicated?

import {
Client,
createRestError,
PathUncheckedResponse,
} from "@azure-rest/core-client";
import { RestError } from "@azure/core-rest-pipeline";
import {
BuildPagedAsyncIteratorOptions,
ContinuablePage,
PageSettings,
PagedAsyncIterableIterator,
PagedResult,
} from "../models/pagingTypes.js";
import { isUnexpected } from "../rest/index.js";

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/**
* Options for the byPage method
*/
export interface PageSettings {
/**
* A reference to a specific page to start iterating from.
*/
continuationToken?: string;
}

/**
* An interface that describes a page of results.
*/
export type ContinuablePage<TElement, TPage = TElement[]> = TPage & {
/**
* 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 extends PageSettings = 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<ContinuablePage<TElement, TPage>>;
}

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

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

/**
* Options for the paging helper
*/
export interface BuildPagedAsyncIteratorOptions {
itemName?: string;
nextLinkName?: string;
}

/**
* Helper to paginate results in a generic way and return a PagedAsyncIterableIterator
Expand Down Expand Up @@ -182,10 +267,23 @@ function getElements<T = unknown>(body: unknown, itemName: string): T[] {
* Checks if a request failed
*/
function checkPagingRequest(response: PathUncheckedResponse): void {
if (isUnexpected(response)) {
throw createRestError(
`Pagination failed with unexpected statusCode ${response.status}`,
response,
);
const statusCode = Number(response.status);
if (statusCode < 200 || statusCode >= 300) {
if (statusCode >= 400 && statusCode < 500) {
throw createRestError(
`Pagination failed with client error statusCode ${response.status}`,
response,
);
} else if (statusCode >= 500) {
throw createRestError(
`Pagination failed with server error statusCode ${response.status}`,
response,
);
} else {
throw createRestError(
`Pagination failed with unexpected statusCode ${response.status}`,
response,
);
}
Comment on lines -185 to +287
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite sure why we remove isUnexpected helper ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it part of the removing rlc types change?

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { getLongRunningPoller } from "./pollingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import { GenerationOptions, GenerationResult } from "../models/models.js";
import {
isUnexpected,
Expand All @@ -16,6 +14,8 @@ import {
operationOptionsToRequestParameters,
createRestError,
} from "@azure-rest/core-client";
import { getLongRunningPoller } from "../static-helpers/pollingHelpers.js";
import { PollerLike, OperationState } from "@azure/core-lro";
import { LongRunningRpcOptionalParams } from "../models/options.js";

export function _longRunningRpcSend(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import {
PollerLike,
OperationState,
deserializeState,
ResourceLocationConfig,
} from "@azure/core-lro";
import { RpcClient } from "./rpcClient.js";
import { getLongRunningPoller } from "./api/pollingHelpers.js";
import { _longRunningRpcDeserialize } from "./api/operations.js";
import { getLongRunningPoller } from "./static-helpers/pollingHelpers.js";
import {
PathUncheckedResponse,
OperationOptions,
PathUncheckedResponse,
} from "@azure-rest/core-client";
import { AbortSignalLike } from "@azure/abort-controller";
import {
PollerLike,
OperationState,
deserializeState,
ResourceLocationConfig,
} from "@azure/core-lro";

export interface RestorePollerOptions<
TResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { PollerLike, OperationState } from "@azure/core-lro";
import { Pipeline } from "@azure/core-rest-pipeline";
import { GenerationOptions, GenerationResult } from "./models/models.js";
import { LongRunningRpcOptionalParams } from "./models/options.js";
Expand All @@ -11,6 +10,7 @@ import {
RpcClientOptionalParams,
RpcContext,
} from "./api/index.js";
import { PollerLike, OperationState } from "@azure/core-lro";

export { RpcClientOptionalParams } from "./api/rpcContext.js";

Expand Down
Loading