Change ServiceClient constructor to take ServiceClientOptions instead of HttpPipeline

This commit is contained in:
Dan Schulte 2018-05-02 10:51:15 -07:00
Родитель 4ce1c845ec
Коммит 86a4aecb8f
3 изменённых файлов: 29 добавлений и 17 удалений

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

@ -61,7 +61,7 @@ import uuidSpec from "./serialization/uuidSpec";
import { WebResource, RequestPrepareOptions, HttpMethods, ParameterValue, RequestOptionsBase } from "./webResource";
import { HttpOperationResponse } from "./httpOperationResponse";
import { RestError } from "./restError";
import { ServiceClient } from "./serviceClient";
import { ServiceClient, ServiceClientOptions } from "./serviceClient";
import { Constants } from "./util/constants";
import { RequestPipeline, RequestFunction } from "./requestPipeline";
import { LogFilter } from "./filters/logFilter";
@ -107,11 +107,13 @@ export {
SerializationOptions, streamSpec, stringSpec, timeSpanSpec, TypeSpec, unixTimeSpec, uuidSpec,
// Legacy
BaseMapperType, CompositeMapper, DictionaryMapper, EnumMapper, Mapper, MapperConstraints, MapperType,
PolymorphicDiscriminator, SequenceMapper, UrlParameterValue, Serializer, serializeObject,
WebResource, RequestPrepareOptions, HttpMethods, ParameterValue, HttpOperationResponse, ServiceClient, Constants, RequestPipeline,
BaseMapperType, CompositeMapper, DictionaryMapper, EnumMapper, Mapper, MapperConstraints,
MapperType, PolymorphicDiscriminator, SequenceMapper, UrlParameterValue, Serializer,
serializeObject, WebResource, RequestPrepareOptions, HttpMethods, ParameterValue,
HttpOperationResponse, ServiceClient, ServiceClientOptions, Constants, RequestPipeline,
ServiceClientCredentials, BaseFilter, LogFilter, ExponentialRetryPolicyFilter,
SystemErrorRetryPolicyFilter, SigningFilter, MsRestUserAgentFilter, stripResponse, delay, executePromisesSequentially,
generateUuid, isValidUuid, encodeUri, RestError, RequestOptionsBase, RequestFunction, ServiceCallback, promiseToCallback,
promiseToServiceCallback, isStream, dispatchRequest, RedirectFilter, applyMixins, isNode, stringifyXML, prepareXMLRootList
SystemErrorRetryPolicyFilter, SigningFilter, MsRestUserAgentFilter, stripResponse, delay,
executePromisesSequentially, generateUuid, isValidUuid, encodeUri, RestError, RequestOptionsBase,
RequestFunction, ServiceCallback, promiseToCallback, promiseToServiceCallback, isStream,
dispatchRequest, RedirectFilter, applyMixins, isNode, stringifyXML, prepareXMLRootList
};

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

@ -4,6 +4,17 @@ import { DefaultHttpPipelineOptions, HttpPipeline, createDefaultHttpPipeline } f
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
/**
* Options that can be used to configure a ServiceClient.
*/
export interface ServiceClientOptions {
/**
* The HttpPipeline that this ServiceClient will use, or the options that will be used to create
* the default HttpPipeline.
*/
httpPipeline?: HttpPipeline | DefaultHttpPipelineOptions;
}
/**
* An abstract type that encapsulates a HttpPipeline for derived ServiceClient types.
*/
@ -12,15 +23,14 @@ export abstract class ServiceClient {
/**
* The ServiceClient constructor
* @param httpPipeline The HttpPipeline that this ServiceClient will use, or the options that will
* be used to create the default HttpPipeline.
* @param httpPipeline
*/
constructor(httpPipeline?: HttpPipeline | DefaultHttpPipelineOptions) {
if (httpPipeline) {
if (httpPipeline instanceof HttpPipeline) {
this._httpPipeline = httpPipeline;
constructor(options?: ServiceClientOptions) {
if (options && options.httpPipeline) {
if (options.httpPipeline instanceof HttpPipeline) {
this._httpPipeline = options.httpPipeline;
} else {
this._httpPipeline = createDefaultHttpPipeline(httpPipeline);
this._httpPipeline = createDefaultHttpPipeline(options.httpPipeline);
}
} else {
this._httpPipeline = createDefaultHttpPipeline();

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

@ -39,8 +39,8 @@ class TestClient extends msRest.ServiceClient {
acceptLanguage?: string;
models?: any;
serializer: msRest.Serializer;
constructor(baseUri: string, httpPipeline?: msRest.HttpPipeline | msRest.DefaultHttpPipelineOptions) {
super(httpPipeline);
constructor(baseUri: string, options?: msRest.ServiceClientOptions) {
super(options);
this.baseUri = baseUri;
if (!this.baseUri) {