/
operationOptions.ts
75 lines (65 loc) · 2.13 KB
/
operationOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { AbortSignalLike } from "@azure/abort-controller";
import { OperationTracingOptions } from "@azure/core-tracing";
import { TransferProgressEvent, RequestOptionsBase } from "./webResource";
import { HttpOperationResponse } from "./httpOperationResponse";
/**
* The base options type for all operations.
*/
export interface OperationOptions {
/**
* The signal which can be used to abort requests.
*/
abortSignal?: AbortSignalLike;
/**
* Options used when creating and sending HTTP requests for this operation.
*/
requestOptions?: OperationRequestOptions;
/**
* Options used when tracing is enabled.
*/
tracingOptions?: OperationTracingOptions;
}
export interface OperationRequestOptions {
/**
* @property {object} [customHeaders] User defined custom request headers that
* will be applied before the request is sent.
*/
customHeaders?: { [key: string]: string };
/**
* The number of milliseconds a request can take before automatically being terminated.
*/
timeout?: number;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/**
* Callback which fires upon download progress.
*/
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/**
* Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the
* HttpOperationResponse should be deserialized.
*/
shouldDeserialize?: boolean | ((response: HttpOperationResponse) => boolean);
}
/**
* Converts an OperationOptions to a RequestOptionsBase
*
* @param opts OperationOptions object to convert to RequestOptionsBase
*/
export function operationOptionsToRequestOptionsBase<T extends OperationOptions>(
opts: T
): RequestOptionsBase {
const { requestOptions, tracingOptions, ...additionalOptions } = opts;
let result: RequestOptionsBase = additionalOptions;
if (requestOptions) {
result = { ...result, ...requestOptions };
}
if (tracingOptions) {
result.spanOptions = tracingOptions.spanOptions;
}
return result;
}