Add prepareXMLRootList function

This commit is contained in:
Rikki Gibson 2018-03-28 12:03:10 -07:00
Родитель 97d6b9980a
Коммит 6dd9295ce2
2 изменённых файлов: 10 добавлений и 3 удалений

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

@ -23,7 +23,7 @@ import {
stripRequest, stripResponse, delay, stripRequest, stripResponse, delay,
executePromisesSequentially, generateUuid, encodeUri, ServiceCallback, executePromisesSequentially, generateUuid, encodeUri, ServiceCallback,
promiseToCallback, promiseToServiceCallback, isValidUuid, dispatchRequest, promiseToCallback, promiseToServiceCallback, isValidUuid, dispatchRequest,
applyMixins, isNode, stringifyXML applyMixins, isNode, stringifyXML, prepareXMLRootList
} from "./util/utils"; } from "./util/utils";
// Credentials // Credentials
@ -40,5 +40,5 @@ export {
BasicAuthenticationCredentials, ApiKeyCredentials, ApiKeyCredentialOptions, ServiceClientCredentials, BaseFilter, LogFilter, ServiceClientOptions, ExponentialRetryPolicyFilter, BasicAuthenticationCredentials, ApiKeyCredentials, ApiKeyCredentialOptions, ServiceClientCredentials, BaseFilter, LogFilter, ServiceClientOptions, ExponentialRetryPolicyFilter,
SystemErrorRetryPolicyFilter, SigningFilter, MsRestUserAgentFilter, stripRequest, stripResponse, delay, executePromisesSequentially, SystemErrorRetryPolicyFilter, SigningFilter, MsRestUserAgentFilter, stripRequest, stripResponse, delay, executePromisesSequentially,
generateUuid, isValidUuid, encodeUri, RestError, RequestOptionsBase, RequestFunction, ServiceCallback, promiseToCallback, generateUuid, isValidUuid, encodeUri, RestError, RequestOptionsBase, RequestFunction, ServiceCallback, promiseToCallback,
promiseToServiceCallback, isStream, dispatchRequest, RedirectFilter, applyMixins, isNode, stringifyXML promiseToServiceCallback, isStream, dispatchRequest, RedirectFilter, applyMixins, isNode, stringifyXML, prepareXMLRootList
}; };

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

@ -8,7 +8,7 @@ import { Constants } from "./constants";
import { RestError } from "../restError"; import { RestError } from "../restError";
import { HttpOperationResponse } from "../httpOperationResponse"; import { HttpOperationResponse } from "../httpOperationResponse";
import * as xml2js from "xml2js"; import * as xml2js from "xml2js";
import { promisify } from "util"; import { promisify, isArray } from "util";
/** /**
* Provides the fetch() method based on the environment. * Provides the fetch() method based on the environment.
@ -279,6 +279,13 @@ export function stringifyXML(obj: any, opts?: { rootName?: string }) {
return builder.buildObject(obj); return builder.buildObject(obj);
} }
export function prepareXMLRootList(obj: any, elementName: string) {
if (!isArray(obj)) {
obj = [obj];
}
return { [elementName]: obj };
}
/** /**
* Sends the request and returns the received response. * Sends the request and returns the received response.
* @param {WebResource} options - The request to be sent. * @param {WebResource} options - The request to be sent.