webResource.d.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /// <reference types="node" />
  2. import { HttpHeaders } from "./httpHeaders";
  3. import { OperationSpec } from "./operationSpec";
  4. import { Mapper } from "./serializer";
  5. import { HttpOperationResponse } from "./httpOperationResponse";
  6. import { OperationResponse } from "./operationResponse";
  7. import { ProxySettings } from "./serviceClient";
  8. export declare type HttpMethods = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";
  9. export declare type HttpRequestBody = Blob | string | ArrayBuffer | ArrayBufferView | (() => NodeJS.ReadableStream);
  10. /**
  11. * Fired in response to upload or download progress.
  12. */
  13. export declare type TransferProgressEvent = {
  14. /**
  15. * The number of bytes loaded so far.
  16. */
  17. loadedBytes: number;
  18. };
  19. /**
  20. * Allows the request to be aborted upon firing of the "abort" event.
  21. * Compatible with the browser built-in AbortSignal and common polyfills.
  22. */
  23. export interface AbortSignalLike {
  24. readonly aborted: boolean;
  25. addEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
  26. removeEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
  27. }
  28. /**
  29. * Creates a new WebResource object.
  30. *
  31. * This class provides an abstraction over a REST call by being library / implementation agnostic and wrapping the necessary
  32. * properties to initiate a request.
  33. *
  34. * @constructor
  35. */
  36. export declare class WebResource {
  37. url: string;
  38. method: HttpMethods;
  39. body?: any;
  40. headers: HttpHeaders;
  41. /**
  42. * Whether or not the body of the HttpOperationResponse should be treated as a stream.
  43. */
  44. streamResponseBody?: boolean;
  45. /**
  46. * Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the
  47. * HttpOperationResponse should be deserialized.
  48. */
  49. shouldDeserialize?: boolean | ((response: HttpOperationResponse) => boolean);
  50. /**
  51. * A function that returns the proper OperationResponse for the given OperationSpec and
  52. * HttpOperationResponse combination. If this is undefined, then a simple status code lookup will
  53. * be used.
  54. */
  55. operationResponseGetter?: (operationSpec: OperationSpec, response: HttpOperationResponse) => (undefined | OperationResponse);
  56. formData?: any;
  57. query?: {
  58. [key: string]: any;
  59. };
  60. operationSpec?: OperationSpec;
  61. withCredentials: boolean;
  62. timeout: number;
  63. proxySettings?: ProxySettings;
  64. abortSignal?: AbortSignalLike;
  65. /** Callback which fires upon upload progress. */
  66. onUploadProgress?: (progress: TransferProgressEvent) => void;
  67. /** Callback which fires upon download progress. */
  68. onDownloadProgress?: (progress: TransferProgressEvent) => void;
  69. constructor(url?: string, method?: HttpMethods, body?: any, query?: {
  70. [key: string]: any;
  71. }, headers?: {
  72. [key: string]: any;
  73. } | HttpHeaders, streamResponseBody?: boolean, withCredentials?: boolean, abortSignal?: AbortSignalLike, timeout?: number, onUploadProgress?: (progress: TransferProgressEvent) => void, onDownloadProgress?: (progress: TransferProgressEvent) => void, proxySettings?: ProxySettings);
  74. /**
  75. * Validates that the required properties such as method, url, headers["Content-Type"],
  76. * headers["accept-language"] are defined. It will throw an error if one of the above
  77. * mentioned properties are not defined.
  78. */
  79. validateRequestProperties(): void;
  80. /**
  81. * Prepares the request.
  82. * @param {RequestPrepareOptions} options Options to provide for preparing the request.
  83. * @returns {WebResource} Returns the prepared WebResource (HTTP Request) object that needs to be given to the request pipeline.
  84. */
  85. prepare(options: RequestPrepareOptions): WebResource;
  86. /**
  87. * Clone this WebResource HTTP request object.
  88. * @returns {WebResource} The clone of this WebResource HTTP request object.
  89. */
  90. clone(): WebResource;
  91. }
  92. export interface RequestPrepareOptions {
  93. /**
  94. * The HTTP request method. Valid values are "GET", "PUT", "HEAD", "DELETE", "OPTIONS", "POST",
  95. * or "PATCH".
  96. */
  97. method: HttpMethods;
  98. /**
  99. * The request url. It may or may not have query parameters in it. Either provide the "url" or
  100. * provide the "pathTemplate" in the options object. Both the options are mutually exclusive.
  101. */
  102. url?: string;
  103. /**
  104. * A dictionary of query parameters to be appended to the url, where
  105. * the "key" is the "query-parameter-name" and the "value" is the "query-parameter-value".
  106. * The "query-parameter-value" can be of type "string" or it can be of type "object".
  107. * The "object" format should be used when you want to skip url encoding. While using the object format,
  108. * the object must have a property named value which provides the "query-parameter-value".
  109. * Example:
  110. * - query-parameter-value in "object" format: { "query-parameter-name": { value: "query-parameter-value", skipUrlEncoding: true } }
  111. * - query-parameter-value in "string" format: { "query-parameter-name": "query-parameter-value"}.
  112. * Note: "If options.url already has some query parameters, then the value provided in options.queryParameters will be appended to the url.
  113. */
  114. queryParameters?: {
  115. [key: string]: any | ParameterValue;
  116. };
  117. /**
  118. * The path template of the request url. Either provide the "url" or provide the "pathTemplate" in
  119. * the options object. Both the options are mutually exclusive.
  120. * Example: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}"
  121. */
  122. pathTemplate?: string;
  123. /**
  124. * The base url of the request. Default value is: "https://management.azure.com". This is
  125. * applicable only with pathTemplate. If you are providing options.url then it is expected that
  126. * you provide the complete url.
  127. */
  128. baseUrl?: string;
  129. /**
  130. * A dictionary of path parameters that need to be replaced with actual values in the pathTemplate.
  131. * Here the key is the "path-parameter-name" and the value is the "path-parameter-value".
  132. * The "path-parameter-value" can be of type "string" or it can be of type "object".
  133. * The "object" format should be used when you want to skip url encoding. While using the object format,
  134. * the object must have a property named value which provides the "path-parameter-value".
  135. * Example:
  136. * - path-parameter-value in "object" format: { "path-parameter-name": { value: "path-parameter-value", skipUrlEncoding: true } }
  137. * - path-parameter-value in "string" format: { "path-parameter-name": "path-parameter-value" }.
  138. */
  139. pathParameters?: {
  140. [key: string]: any | ParameterValue;
  141. };
  142. formData?: {
  143. [key: string]: any;
  144. };
  145. /**
  146. * A dictionary of request headers that need to be applied to the request.
  147. * Here the key is the "header-name" and the value is the "header-value". The header-value MUST be of type string.
  148. * - ContentType must be provided with the key name as "Content-Type". Default value "application/json; charset=utf-8".
  149. * - "Transfer-Encoding" is set to "chunked" by default if "options.bodyIsStream" is set to true.
  150. * - "Content-Type" is set to "application/octet-stream" by default if "options.bodyIsStream" is set to true.
  151. * - "accept-language" by default is set to "en-US"
  152. * - "x-ms-client-request-id" by default is set to a new Guid. To not generate a guid for the request, please set options.disableClientRequestId to true
  153. */
  154. headers?: {
  155. [key: string]: any;
  156. };
  157. /**
  158. * When set to true, instructs the client to not set "x-ms-client-request-id" header to a new Guid().
  159. */
  160. disableClientRequestId?: boolean;
  161. /**
  162. * The request body. It can be of any type. This value will be serialized if it is not a stream.
  163. */
  164. body?: any;
  165. /**
  166. * Provides information on how to serialize the request body.
  167. */
  168. serializationMapper?: Mapper;
  169. /**
  170. * A dictionary of mappers that may be used while [de]serialization.
  171. */
  172. mappers?: {
  173. [x: string]: any;
  174. };
  175. /**
  176. * Provides information on how to deserialize the response body.
  177. */
  178. deserializationMapper?: object;
  179. /**
  180. * Indicates whether this method should JSON.stringify() the request body. Default value: false.
  181. */
  182. disableJsonStringifyOnBody?: boolean;
  183. /**
  184. * Indicates whether the request body is a stream (useful for file upload scenarios).
  185. */
  186. bodyIsStream?: boolean;
  187. abortSignal?: AbortSignalLike;
  188. onUploadProgress?: (progress: TransferProgressEvent) => void;
  189. onDownloadProgress?: (progress: TransferProgressEvent) => void;
  190. }
  191. /**
  192. * The Parameter value provided for path or query parameters in RequestPrepareOptions
  193. */
  194. export interface ParameterValue {
  195. value: any;
  196. skipUrlEncoding: boolean;
  197. [key: string]: any;
  198. }
  199. /**
  200. * Describes the base structure of the options object that will be used in every operation.
  201. */
  202. export interface RequestOptionsBase {
  203. /**
  204. * @property {object} [customHeaders] User defined custom request headers that
  205. * will be applied before the request is sent.
  206. */
  207. customHeaders?: {
  208. [key: string]: string;
  209. };
  210. /**
  211. * The signal which can be used to abort requests.
  212. */
  213. abortSignal?: AbortSignalLike;
  214. /**
  215. * The number of milliseconds a request can take before automatically being terminated.
  216. */
  217. timeout?: number;
  218. /**
  219. * Callback which fires upon upload progress.
  220. */
  221. onUploadProgress?: (progress: TransferProgressEvent) => void;
  222. /**
  223. * Callback which fires upon download progress.
  224. */
  225. onDownloadProgress?: (progress: TransferProgressEvent) => void;
  226. [key: string]: any;
  227. }
  228. //# sourceMappingURL=webResource.d.ts.map