This commit is contained in:
Jeff Fisher 2020-04-30 13:49:58 -07:00
Родитель d2e72add9d
Коммит cc05a18630
18 изменённых файлов: 69 добавлений и 45 удалений

Просмотреть файл

@ -1,4 +1,8 @@
# Changelog
## 2.0.8
- Replace public usage of `RequestPolicyOptions` to an interface `RequestPolicyOptionsLike` to avoid compatibility issues with private members.
## 2.0.7 - 2020-04-27
- Fixes encoding query parameters in an array before joining them.(PR [#382](https://github.com/Azure/ms-rest-js/pull/382))

Просмотреть файл

@ -17,7 +17,7 @@ export { ServiceClient, ServiceClientOptions, flattenResponse } from "./serviceC
export { QueryCollectionFormat } from "./queryCollectionFormat";
export { Constants } from "./util/constants";
export { logPolicy } from "./policies/logPolicy";
export { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./policies/requestPolicy";
export { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions, RequestPolicyOptionsLike } from "./policies/requestPolicy";
export { generateClientRequestIdPolicy } from "./policies/generateClientRequestIdPolicy";
export { exponentialRetryPolicy } from "./policies/exponentialRetryPolicy";
export { systemErrorRetryPolicy } from "./policies/systemErrorRetryPolicy";

Просмотреть файл

@ -9,7 +9,7 @@ import { Mapper, MapperType } from "../serializer";
import * as utils from "../util/utils";
import { parseXML } from "../util/xml";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
/**
* The content-types that will indicate that an operation response should be deserialized in a
@ -35,7 +35,7 @@ export interface DeserializationContentTypes {
*/
export function deserializationPolicy(deserializationContentTypes?: DeserializationContentTypes): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new DeserializationPolicy(nextPolicy, deserializationContentTypes, options);
}
};
@ -52,7 +52,7 @@ export class DeserializationPolicy extends BaseRequestPolicy {
public readonly jsonContentTypes: string[];
public readonly xmlContentTypes: string[];
constructor(nextPolicy: RequestPolicy, deserializationContentTypes: DeserializationContentTypes | undefined, options: RequestPolicyOptions) {
constructor(nextPolicy: RequestPolicy, deserializationContentTypes: DeserializationContentTypes | undefined, options: RequestPolicyOptionsLike) {
super(nextPolicy, options);
this.jsonContentTypes = deserializationContentTypes && deserializationContentTypes.json || defaultJsonContentTypes;

Просмотреть файл

@ -4,7 +4,7 @@
import { HttpOperationResponse } from "../httpOperationResponse";
import * as utils from "../util/utils";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
import { RestError } from "../restError";
export interface RetryData {
@ -21,7 +21,7 @@ export interface RetryError extends Error {
export function exponentialRetryPolicy(retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new ExponentialRetryPolicy(nextPolicy, options, retryCount, retryInterval, minRetryInterval, maxRetryInterval);
}
};
@ -57,13 +57,13 @@ export class ExponentialRetryPolicy extends BaseRequestPolicy {
/**
* @constructor
* @param {RequestPolicy} nextPolicy The next RequestPolicy in the pipeline chain.
* @param {RequestPolicyOptions} options The options for this RequestPolicy.
* @param {RequestPolicyOptionsLike} options The options for this RequestPolicy.
* @param {number} [retryCount] The client retry count.
* @param {number} [retryInterval] The client retry interval, in milliseconds.
* @param {number} [minRetryInterval] The minimum retry interval, in milliseconds.
* @param {number} [maxRetryInterval] The maximum retry interval, in milliseconds.
*/
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number) {
super(nextPolicy, options);
function isNumber(n: any): n is number { return typeof n === "number"; }
this.retryCount = isNumber(retryCount) ? retryCount : DEFAULT_CLIENT_RETRY_COUNT;

Просмотреть файл

@ -4,18 +4,18 @@
import { HttpOperationResponse } from "../httpOperationResponse";
import * as utils from "../util/utils";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
export function generateClientRequestIdPolicy(requestIdHeaderName = "x-ms-client-request-id"): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new GenerateClientRequestIdPolicy(nextPolicy, options, requestIdHeaderName);
}
};
}
export class GenerateClientRequestIdPolicy extends BaseRequestPolicy {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, private _requestIdHeaderName: string) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, private _requestIdHeaderName: string) {
super(nextPolicy, options);
}

Просмотреть файл

@ -3,11 +3,11 @@
import { HttpOperationResponse } from "../httpOperationResponse";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
export function logPolicy(logger: any = console.log): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new LogPolicy(nextPolicy, options, logger);
}
};
@ -16,7 +16,7 @@ export function logPolicy(logger: any = console.log): RequestPolicyFactory {
export class LogPolicy extends BaseRequestPolicy {
logger?: any;
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, logger: any = console.log) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, logger: any = console.log) {
super(nextPolicy, options);
this.logger = logger;
}

Просмотреть файл

@ -2,7 +2,7 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
import { ProxySettings } from "../serviceClient";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
import { HttpOperationResponse } from "../httpOperationResponse";
import { WebResourceLike } from "../webResource";
@ -14,14 +14,14 @@ export function getDefaultProxySettings(_proxyUrl?: string): ProxySettings | und
export function proxyPolicy(_proxySettings?: ProxySettings): RequestPolicyFactory {
return {
create: (_nextPolicy: RequestPolicy, _options: RequestPolicyOptions) => {
create: (_nextPolicy: RequestPolicy, _options: RequestPolicyOptionsLike) => {
throw proxyNotSupportedInBrowser;
}
};
}
export class ProxyPolicy extends BaseRequestPolicy {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) {
super(nextPolicy, options);
throw proxyNotSupportedInBrowser;
}

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
import { HttpOperationResponse } from "../httpOperationResponse";
import { ProxySettings } from "../serviceClient";
import { WebResourceLike } from "../webResource";
@ -44,7 +44,7 @@ export function getDefaultProxySettings(proxyUrl?: string): ProxySettings | unde
export function proxyPolicy(proxySettings?: ProxySettings): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new ProxyPolicy(nextPolicy, options, proxySettings!);
}
};
@ -53,7 +53,7 @@ export function proxyPolicy(proxySettings?: ProxySettings): RequestPolicyFactory
export class ProxyPolicy extends BaseRequestPolicy {
proxySettings: ProxySettings;
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, proxySettings: ProxySettings) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, proxySettings: ProxySettings) {
super(nextPolicy, options);
this.proxySettings = proxySettings;
}

Просмотреть файл

@ -4,18 +4,18 @@
import { HttpOperationResponse } from "../httpOperationResponse";
import { URLBuilder } from "../url";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
export function redirectPolicy(maximumRetries = 20): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new RedirectPolicy(nextPolicy, options, maximumRetries);
}
};
}
export class RedirectPolicy extends BaseRequestPolicy {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, readonly maxRetries = 20) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, readonly maxRetries = 20) {
super(nextPolicy, options);
}

Просмотреть файл

@ -10,7 +10,7 @@ import { WebResourceLike } from "../webResource";
* Creates a new RequestPolicy per-request that uses the provided nextPolicy.
*/
export type RequestPolicyFactory = {
create(nextPolicy: RequestPolicy, options: RequestPolicyOptions): RequestPolicy
create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy
};
export interface RequestPolicy {
@ -18,7 +18,7 @@ export interface RequestPolicy {
}
export abstract class BaseRequestPolicy implements RequestPolicy {
protected constructor(readonly _nextPolicy: RequestPolicy, readonly _options: RequestPolicyOptions) {
protected constructor(readonly _nextPolicy: RequestPolicy, readonly _options: RequestPolicyOptionsLike) {
}
public abstract sendRequest(webResource: WebResourceLike): Promise<HttpOperationResponse>;
@ -46,7 +46,27 @@ export abstract class BaseRequestPolicy implements RequestPolicy {
/**
* Optional properties that can be used when creating a RequestPolicy.
*/
export class RequestPolicyOptions {
export interface RequestPolicyOptionsLike {
/**
* Get whether or not a log with the provided log level should be logged.
* @param logLevel The log level of the log that will be logged.
* @returns Whether or not a log with the provided log level should be logged.
*/
shouldLog(logLevel: HttpPipelineLogLevel): boolean;
/**
* Attempt to log the provided message to the provided logger. If no logger was provided or if
* the log level does not meet the logger's threshold, then nothing will be logged.
* @param logLevel The log level of this log.
* @param message The message of this log.
*/
log(logLevel: HttpPipelineLogLevel, message: string): void;
}
/**
* Optional properties that can be used when creating a RequestPolicy.
*/
export class RequestPolicyOptions implements RequestPolicyOptionsLike {
constructor(private _logger?: HttpPipelineLogger) {
}

Просмотреть файл

@ -3,18 +3,18 @@
import { HttpOperationResponse } from "../httpOperationResponse";
import * as utils from "../util/utils";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
export function rpRegistrationPolicy(retryTimeout = 30): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new RPRegistrationPolicy(nextPolicy, options, retryTimeout);
}
};
}
export class RPRegistrationPolicy extends BaseRequestPolicy {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, readonly _retryTimeout = 30) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, readonly _retryTimeout = 30) {
super(nextPolicy, options);
}

Просмотреть файл

@ -4,11 +4,11 @@
import { ServiceClientCredentials } from "../credentials/serviceClientCredentials";
import { HttpOperationResponse } from "../httpOperationResponse";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicyFactory, RequestPolicy, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicyFactory, RequestPolicy, RequestPolicyOptionsLike } from "./requestPolicy";
export function signingPolicy(authenticationProvider: ServiceClientCredentials): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new SigningPolicy(nextPolicy, options, authenticationProvider);
}
};
@ -16,7 +16,7 @@ export function signingPolicy(authenticationProvider: ServiceClientCredentials):
export class SigningPolicy extends BaseRequestPolicy {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, public authenticationProvider: ServiceClientCredentials) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, public authenticationProvider: ServiceClientCredentials) {
super(nextPolicy, options);
}

Просмотреть файл

@ -4,7 +4,7 @@
import { HttpOperationResponse } from "../httpOperationResponse";
import * as utils from "../util/utils";
import { WebResourceLike } from "../webResource";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
export interface RetryData {
retryCount: number;
@ -20,7 +20,7 @@ export interface RetryError extends Error {
export function systemErrorRetryPolicy(retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new SystemErrorRetryPolicy(nextPolicy, options, retryCount, retryInterval, minRetryInterval, maxRetryInterval);
}
};
@ -46,7 +46,7 @@ export class SystemErrorRetryPolicy extends BaseRequestPolicy {
DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 90;
DEFAULT_CLIENT_MIN_RETRY_INTERVAL = 1000 * 3;
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, retryCount?: number, retryInterval?: number, minRetryInterval?: number, maxRetryInterval?: number) {
super(nextPolicy, options);
this.retryCount = typeof retryCount === "number" ? retryCount : this.DEFAULT_CLIENT_RETRY_COUNT;
this.retryInterval = typeof retryInterval === "number" ? retryInterval : this.DEFAULT_CLIENT_RETRY_INTERVAL;

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { BaseRequestPolicy, RequestPolicy, RequestPolicyOptions, RequestPolicyFactory } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyOptionsLike, RequestPolicyFactory } from "./requestPolicy";
import { WebResourceLike } from "../webResource";
import { HttpOperationResponse } from "../httpOperationResponse";
import { Constants } from "../util/constants";
@ -12,7 +12,7 @@ const StatusCodes = Constants.HttpConstants.StatusCodes;
export function throttlingRetryPolicy(): RequestPolicyFactory {
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new ThrottlingRetryPolicy(nextPolicy, options);
}
};
@ -27,7 +27,7 @@ export function throttlingRetryPolicy(): RequestPolicyFactory {
export class ThrottlingRetryPolicy extends BaseRequestPolicy {
private _handleResponse: ResponseHandler;
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions, _handleResponse?: ResponseHandler) {
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike, _handleResponse?: ResponseHandler) {
super(nextPolicy, options);
this._handleResponse = _handleResponse || this._defaultResponseHandler;
}

Просмотреть файл

@ -6,7 +6,7 @@ import { HttpOperationResponse } from "../httpOperationResponse";
import { Constants } from "../util/constants";
import { WebResourceLike } from "../webResource";
import { getDefaultUserAgentKey, getPlatformSpecificData } from "./msRestUserAgentPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./requestPolicy";
import { BaseRequestPolicy, RequestPolicy, RequestPolicyFactory, RequestPolicyOptionsLike } from "./requestPolicy";
export type TelemetryInfo = { key?: string; value?: string };
@ -40,14 +40,14 @@ export function userAgentPolicy(userAgentData?: TelemetryInfo): RequestPolicyFac
const value: string = (!userAgentData || userAgentData.value == undefined) ? getDefaultUserAgentValue() : userAgentData.value;
return {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
create: (nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike) => {
return new UserAgentPolicy(nextPolicy, options, key, value);
}
};
}
export class UserAgentPolicy extends BaseRequestPolicy {
constructor(readonly _nextPolicy: RequestPolicy, readonly _options: RequestPolicyOptions, protected headerKey: string, protected headerValue: string) {
constructor(readonly _nextPolicy: RequestPolicy, readonly _options: RequestPolicyOptionsLike, protected headerKey: string, protected headerValue: string) {
super(_nextPolicy, _options);
}

Просмотреть файл

@ -14,7 +14,7 @@ import { exponentialRetryPolicy } from "./policies/exponentialRetryPolicy";
import { generateClientRequestIdPolicy } from "./policies/generateClientRequestIdPolicy";
import { userAgentPolicy, getDefaultUserAgentHeaderName, getDefaultUserAgentValue } from "./policies/userAgentPolicy";
import { redirectPolicy } from "./policies/redirectPolicy";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions } from "./policies/requestPolicy";
import { RequestPolicy, RequestPolicyFactory, RequestPolicyOptions, RequestPolicyOptionsLike } from "./policies/requestPolicy";
import { rpRegistrationPolicy } from "./policies/rpRegistrationPolicy";
import { signingPolicy } from "./policies/signingPolicy";
import { systemErrorRetryPolicy } from "./policies/systemErrorRetryPolicy";
@ -123,7 +123,7 @@ export class ServiceClient {
* The HTTP client that will be used to send requests.
*/
private readonly _httpClient: HttpClient;
private readonly _requestPolicyOptions: RequestPolicyOptions;
private readonly _requestPolicyOptions: RequestPolicyOptionsLike;
private readonly _requestPolicyFactories: RequestPolicyFactory[];
private readonly _withCredentials: boolean;

Просмотреть файл

@ -7,7 +7,7 @@ export const Constants = {
* @const
* @type {string}
*/
msRestVersion: "2.0.7",
msRestVersion: "2.0.8",
/**
* Specifies HTTP.

Просмотреть файл

@ -5,7 +5,7 @@
"email": "azsdkteam@microsoft.com",
"url": "https://github.com/Azure/ms-rest-js"
},
"version": "2.0.7",
"version": "2.0.8",
"description": "Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest",
"tags": [
"isomorphic",