@typespec/ts-http-runtime 0.3.4-alpha.20260227.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/dist/browser/client/sendRequest.d.ts +10 -1
  2. package/dist/browser/client/sendRequest.js +8 -2
  3. package/dist/browser/client/sendRequest.js.map +1 -1
  4. package/dist/browser/defaultHttpClient.d.ts +1 -1
  5. package/dist/browser/defaultHttpClient.js +1 -1
  6. package/dist/browser/defaultHttpClient.js.map +1 -0
  7. package/dist/browser/index.d.ts +2 -2
  8. package/dist/browser/index.js +0 -2
  9. package/dist/browser/index.js.map +1 -1
  10. package/dist/browser/logger/log.d.ts +1 -1
  11. package/dist/browser/logger/log.js +1 -1
  12. package/dist/browser/logger/log.js.map +1 -0
  13. package/dist/browser/pipelineRequest.d.ts +1 -1
  14. package/dist/browser/pipelineRequest.js.map +1 -1
  15. package/dist/browser/policies/decompressResponsePolicy.d.ts +3 -2
  16. package/dist/browser/policies/decompressResponsePolicy.js +1 -4
  17. package/dist/browser/policies/decompressResponsePolicy.js.map +1 -0
  18. package/dist/browser/policies/internal.d.ts +7 -7
  19. package/dist/browser/policies/internal.js +2 -2
  20. package/dist/browser/policies/internal.js.map +1 -1
  21. package/dist/browser/policies/proxyPolicy.common.d.ts +7 -3
  22. package/dist/browser/policies/proxyPolicy.common.js +2 -2
  23. package/dist/browser/policies/proxyPolicy.common.js.map +1 -1
  24. package/dist/browser/policies/proxyPolicy.d.ts +1 -1
  25. package/dist/browser/policies/proxyPolicy.js +1 -1
  26. package/dist/browser/policies/proxyPolicy.js.map +1 -0
  27. package/dist/browser/policies/redirectPolicy.d.ts +7 -0
  28. package/dist/browser/policies/redirectPolicy.js +13 -4
  29. package/dist/browser/policies/redirectPolicy.js.map +1 -1
  30. package/dist/browser/util/bytesEncoding.d.ts +1 -1
  31. package/dist/browser/util/bytesEncoding.js +1 -1
  32. package/dist/browser/util/bytesEncoding.js.map +1 -0
  33. package/dist/browser/util/concat.common.d.ts +1 -2
  34. package/dist/browser/util/concat.common.js.map +1 -1
  35. package/dist/browser/util/concat.d.ts +1 -1
  36. package/dist/browser/util/concat.js +1 -1
  37. package/dist/browser/util/concat.js.map +1 -0
  38. package/dist/browser/util/inspect.d.ts +1 -1
  39. package/dist/browser/util/inspect.js +1 -1
  40. package/dist/browser/util/inspect.js.map +1 -0
  41. package/dist/browser/util/sha256.d.ts +1 -1
  42. package/dist/browser/util/sha256.js +1 -1
  43. package/dist/browser/util/sha256.js.map +1 -0
  44. package/dist/browser/util/userAgentPlatform.d.ts +1 -1
  45. package/dist/browser/util/userAgentPlatform.js +1 -1
  46. package/dist/browser/util/userAgentPlatform.js.map +1 -0
  47. package/dist/browser/util/uuidUtils.d.ts +1 -1
  48. package/dist/browser/util/uuidUtils.js +1 -1
  49. package/dist/browser/util/uuidUtils.js.map +1 -0
  50. package/dist/commonjs/abort-controller/AbortError.js +30 -40
  51. package/dist/commonjs/abort-controller/AbortError.js.map +7 -1
  52. package/dist/commonjs/auth/credentials.js +36 -25
  53. package/dist/commonjs/auth/credentials.js.map +7 -1
  54. package/dist/commonjs/auth/oauth2Flows.js +15 -5
  55. package/dist/commonjs/auth/oauth2Flows.js.map +7 -1
  56. package/dist/commonjs/auth/schemes.js +15 -5
  57. package/dist/commonjs/auth/schemes.js.map +7 -1
  58. package/dist/commonjs/client/apiVersionPolicy.js +39 -25
  59. package/dist/commonjs/client/apiVersionPolicy.js.map +7 -1
  60. package/dist/commonjs/client/clientHelpers.js +62 -39
  61. package/dist/commonjs/client/clientHelpers.js.map +7 -1
  62. package/dist/commonjs/client/common.js +15 -5
  63. package/dist/commonjs/client/common.js.map +7 -1
  64. package/dist/commonjs/client/getClient.js +170 -82
  65. package/dist/commonjs/client/getClient.js.map +7 -1
  66. package/dist/commonjs/client/multipart.js +119 -110
  67. package/dist/commonjs/client/multipart.js.map +7 -1
  68. package/dist/commonjs/client/operationOptionHelpers.js +36 -21
  69. package/dist/commonjs/client/operationOptionHelpers.js.map +7 -1
  70. package/dist/commonjs/client/restError.js +44 -26
  71. package/dist/commonjs/client/restError.js.map +7 -1
  72. package/dist/commonjs/client/sendRequest.d.ts +10 -1
  73. package/dist/commonjs/client/sendRequest.js +150 -164
  74. package/dist/commonjs/client/sendRequest.js.map +7 -1
  75. package/dist/commonjs/client/urlHelpers.js +124 -131
  76. package/dist/commonjs/client/urlHelpers.js.map +7 -1
  77. package/dist/commonjs/constants.js +30 -8
  78. package/dist/commonjs/constants.js.map +7 -1
  79. package/dist/commonjs/createPipelineFromOptions.js +56 -45
  80. package/dist/commonjs/createPipelineFromOptions.js.map +7 -1
  81. package/dist/commonjs/defaultHttpClient.js +28 -11
  82. package/dist/commonjs/defaultHttpClient.js.map +7 -1
  83. package/dist/commonjs/fetchHttpClient.js +211 -256
  84. package/dist/commonjs/fetchHttpClient.js.map +7 -1
  85. package/dist/commonjs/httpHeaders.js +97 -82
  86. package/dist/commonjs/httpHeaders.js.map +7 -1
  87. package/dist/commonjs/index.d.ts +2 -2
  88. package/dist/commonjs/index.js +67 -36
  89. package/dist/commonjs/index.js.map +7 -1
  90. package/dist/commonjs/interfaces.js +15 -5
  91. package/dist/commonjs/interfaces.js.map +7 -1
  92. package/dist/commonjs/log.js +28 -8
  93. package/dist/commonjs/log.js.map +7 -1
  94. package/dist/commonjs/logger/debug.js +150 -155
  95. package/dist/commonjs/logger/debug.js.map +7 -1
  96. package/dist/commonjs/logger/internal.js +27 -8
  97. package/dist/commonjs/logger/internal.js.map +7 -1
  98. package/dist/commonjs/logger/log.common.js +39 -23
  99. package/dist/commonjs/logger/log.common.js.map +7 -1
  100. package/dist/commonjs/logger/log.js +40 -11
  101. package/dist/commonjs/logger/log.js.map +7 -1
  102. package/dist/commonjs/logger/logger.js +120 -110
  103. package/dist/commonjs/logger/logger.js.map +7 -1
  104. package/dist/commonjs/nodeHttpClient.js +313 -321
  105. package/dist/commonjs/nodeHttpClient.js.map +7 -1
  106. package/dist/commonjs/pipeline.js +190 -247
  107. package/dist/commonjs/pipeline.js.map +7 -1
  108. package/dist/commonjs/pipelineRequest.d.ts +1 -1
  109. package/dist/commonjs/pipelineRequest.js +69 -54
  110. package/dist/commonjs/pipelineRequest.js.map +7 -1
  111. package/dist/commonjs/policies/agentPolicy.js +38 -24
  112. package/dist/commonjs/policies/agentPolicy.js.map +7 -1
  113. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +45 -32
  114. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +7 -1
  115. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +50 -32
  116. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +7 -1
  117. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +47 -32
  118. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +7 -1
  119. package/dist/commonjs/policies/auth/checkInsecureConnection.js +47 -44
  120. package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +7 -1
  121. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +45 -32
  122. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +7 -1
  123. package/dist/commonjs/policies/decompressResponsePolicy.js +38 -25
  124. package/dist/commonjs/policies/decompressResponsePolicy.js.map +7 -1
  125. package/dist/commonjs/policies/defaultRetryPolicy.js +39 -27
  126. package/dist/commonjs/policies/defaultRetryPolicy.js.map +7 -1
  127. package/dist/commonjs/policies/exponentialRetryPolicy.js +43 -26
  128. package/dist/commonjs/policies/exponentialRetryPolicy.js.map +7 -1
  129. package/dist/commonjs/policies/formDataPolicy.js +101 -90
  130. package/dist/commonjs/policies/formDataPolicy.js.map +7 -1
  131. package/dist/commonjs/policies/internal.d.ts +7 -7
  132. package/dist/commonjs/policies/internal.js +94 -48
  133. package/dist/commonjs/policies/internal.js.map +7 -1
  134. package/dist/commonjs/policies/logPolicy.js +49 -35
  135. package/dist/commonjs/policies/logPolicy.js.map +7 -1
  136. package/dist/commonjs/policies/multipartPolicy.js +117 -99
  137. package/dist/commonjs/policies/multipartPolicy.js.map +7 -1
  138. package/dist/commonjs/policies/proxyPolicy.common.d.ts +7 -3
  139. package/dist/commonjs/policies/proxyPolicy.common.js +38 -25
  140. package/dist/commonjs/policies/proxyPolicy.common.js.map +7 -1
  141. package/dist/commonjs/policies/proxyPolicy.js +160 -171
  142. package/dist/commonjs/policies/proxyPolicy.js.map +7 -1
  143. package/dist/commonjs/policies/redirectPolicy.d.ts +7 -0
  144. package/dist/commonjs/policies/redirectPolicy.js +62 -51
  145. package/dist/commonjs/policies/redirectPolicy.js.map +7 -1
  146. package/dist/commonjs/policies/retryPolicy.js +123 -105
  147. package/dist/commonjs/policies/retryPolicy.js.map +7 -1
  148. package/dist/commonjs/policies/systemErrorRetryPolicy.js +46 -31
  149. package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +7 -1
  150. package/dist/commonjs/policies/throttlingRetryPolicy.js +38 -30
  151. package/dist/commonjs/policies/throttlingRetryPolicy.js.map +7 -1
  152. package/dist/commonjs/policies/tlsPolicy.js +38 -24
  153. package/dist/commonjs/policies/tlsPolicy.js.map +7 -1
  154. package/dist/commonjs/policies/userAgentPolicy.js +41 -28
  155. package/dist/commonjs/policies/userAgentPolicy.js.map +7 -1
  156. package/dist/commonjs/restError.js +93 -90
  157. package/dist/commonjs/restError.js.map +7 -1
  158. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +63 -62
  159. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +7 -1
  160. package/dist/commonjs/retryStrategies/retryStrategy.js +15 -5
  161. package/dist/commonjs/retryStrategies/retryStrategy.js.map +7 -1
  162. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +58 -69
  163. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +7 -1
  164. package/dist/commonjs/util/arrayBuffer.js +34 -21
  165. package/dist/commonjs/util/arrayBuffer.js.map +7 -1
  166. package/dist/commonjs/util/bytesEncoding.common.js +83 -100
  167. package/dist/commonjs/util/bytesEncoding.common.js.map +7 -1
  168. package/dist/commonjs/util/bytesEncoding.js +30 -21
  169. package/dist/commonjs/util/bytesEncoding.js.map +7 -1
  170. package/dist/commonjs/util/checkEnvironment.js +45 -44
  171. package/dist/commonjs/util/checkEnvironment.js.map +7 -1
  172. package/dist/commonjs/util/concat.common.d.ts +1 -2
  173. package/dist/commonjs/util/concat.common.js +51 -52
  174. package/dist/commonjs/util/concat.common.js.map +7 -1
  175. package/dist/commonjs/util/concat.js +70 -61
  176. package/dist/commonjs/util/concat.js.map +7 -1
  177. package/dist/commonjs/util/delay.js +31 -21
  178. package/dist/commonjs/util/delay.js.map +7 -1
  179. package/dist/commonjs/util/error.js +33 -17
  180. package/dist/commonjs/util/error.js.map +7 -1
  181. package/dist/commonjs/util/helpers.js +65 -57
  182. package/dist/commonjs/util/helpers.js.map +7 -1
  183. package/dist/commonjs/util/inspect.common.js +27 -7
  184. package/dist/commonjs/util/inspect.common.js.map +7 -1
  185. package/dist/commonjs/util/inspect.js +28 -8
  186. package/dist/commonjs/util/inspect.js.map +7 -1
  187. package/dist/commonjs/util/internal.js +67 -32
  188. package/dist/commonjs/util/internal.js.map +7 -1
  189. package/dist/commonjs/util/object.js +27 -15
  190. package/dist/commonjs/util/object.js.map +7 -1
  191. package/dist/commonjs/util/random.js +30 -22
  192. package/dist/commonjs/util/random.js.map +7 -1
  193. package/dist/commonjs/util/sanitizer.js +157 -148
  194. package/dist/commonjs/util/sanitizer.js.map +7 -1
  195. package/dist/commonjs/util/sha256.common.js +61 -45
  196. package/dist/commonjs/util/sha256.common.js.map +7 -1
  197. package/dist/commonjs/util/sha256.js +32 -22
  198. package/dist/commonjs/util/sha256.js.map +7 -1
  199. package/dist/commonjs/util/typeGuards.js +41 -21
  200. package/dist/commonjs/util/typeGuards.js.map +7 -1
  201. package/dist/commonjs/util/userAgent.js +43 -28
  202. package/dist/commonjs/util/userAgent.js.map +7 -1
  203. package/dist/commonjs/util/userAgentPlatform.js +51 -29
  204. package/dist/commonjs/util/userAgentPlatform.js.map +7 -1
  205. package/dist/commonjs/util/uuidUtils.common.js +43 -39
  206. package/dist/commonjs/util/uuidUtils.common.js.map +7 -1
  207. package/dist/commonjs/util/uuidUtils.js +27 -12
  208. package/dist/commonjs/util/uuidUtils.js.map +7 -1
  209. package/dist/commonjs/xhrHttpClient.js +171 -163
  210. package/dist/commonjs/xhrHttpClient.js.map +7 -1
  211. package/dist/esm/client/sendRequest.d.ts +10 -1
  212. package/dist/esm/client/sendRequest.js +8 -2
  213. package/dist/esm/client/sendRequest.js.map +1 -1
  214. package/dist/esm/index.d.ts +2 -2
  215. package/dist/esm/index.js +0 -2
  216. package/dist/esm/index.js.map +1 -1
  217. package/dist/esm/pipelineRequest.d.ts +1 -1
  218. package/dist/esm/pipelineRequest.js.map +1 -1
  219. package/dist/esm/policies/internal.d.ts +7 -7
  220. package/dist/esm/policies/internal.js +2 -2
  221. package/dist/esm/policies/internal.js.map +1 -1
  222. package/dist/esm/policies/proxyPolicy.common.d.ts +7 -3
  223. package/dist/esm/policies/proxyPolicy.common.js +2 -2
  224. package/dist/esm/policies/proxyPolicy.common.js.map +1 -1
  225. package/dist/esm/policies/redirectPolicy.d.ts +7 -0
  226. package/dist/esm/policies/redirectPolicy.js +13 -4
  227. package/dist/esm/policies/redirectPolicy.js.map +1 -1
  228. package/dist/esm/util/concat.common.d.ts +1 -2
  229. package/dist/esm/util/concat.common.js.map +1 -1
  230. package/dist/react-native/client/sendRequest.d.ts +10 -1
  231. package/dist/react-native/client/sendRequest.js +8 -2
  232. package/dist/react-native/client/sendRequest.js.map +1 -1
  233. package/dist/react-native/defaultHttpClient.d.ts +1 -1
  234. package/dist/react-native/defaultHttpClient.js +1 -1
  235. package/dist/react-native/defaultHttpClient.js.map +1 -0
  236. package/dist/react-native/index.d.ts +2 -2
  237. package/dist/react-native/index.js +0 -2
  238. package/dist/react-native/index.js.map +1 -1
  239. package/dist/react-native/logger/log.d.ts +1 -1
  240. package/dist/react-native/logger/log.js +1 -1
  241. package/dist/react-native/logger/log.js.map +1 -0
  242. package/dist/react-native/pipelineRequest.d.ts +1 -1
  243. package/dist/react-native/pipelineRequest.js.map +1 -1
  244. package/dist/react-native/policies/internal.d.ts +7 -7
  245. package/dist/react-native/policies/internal.js +2 -2
  246. package/dist/react-native/policies/internal.js.map +1 -1
  247. package/dist/react-native/policies/proxyPolicy.common.d.ts +7 -3
  248. package/dist/react-native/policies/proxyPolicy.common.js +2 -2
  249. package/dist/react-native/policies/proxyPolicy.common.js.map +1 -1
  250. package/dist/react-native/policies/proxyPolicy.d.ts +1 -1
  251. package/dist/react-native/policies/proxyPolicy.js +1 -1
  252. package/dist/react-native/policies/proxyPolicy.js.map +1 -0
  253. package/dist/react-native/policies/redirectPolicy.d.ts +7 -0
  254. package/dist/react-native/policies/redirectPolicy.js +13 -4
  255. package/dist/react-native/policies/redirectPolicy.js.map +1 -1
  256. package/dist/react-native/util/bytesEncoding.d.ts +1 -1
  257. package/dist/react-native/util/bytesEncoding.js +1 -1
  258. package/dist/react-native/util/bytesEncoding.js.map +1 -0
  259. package/dist/react-native/util/concat.common.d.ts +1 -2
  260. package/dist/react-native/util/concat.common.js.map +1 -1
  261. package/dist/react-native/util/concat.d.ts +1 -1
  262. package/dist/react-native/util/concat.js +1 -1
  263. package/dist/react-native/util/concat.js.map +1 -0
  264. package/dist/react-native/util/inspect.d.ts +1 -1
  265. package/dist/react-native/util/inspect.js +1 -1
  266. package/dist/react-native/util/inspect.js.map +1 -0
  267. package/dist/react-native/util/sha256.d.ts +1 -1
  268. package/dist/react-native/util/sha256.js +1 -1
  269. package/dist/react-native/util/sha256.js.map +1 -0
  270. package/dist/react-native/util/userAgentPlatform.d.ts +1 -1
  271. package/dist/react-native/util/userAgentPlatform.js +1 -1
  272. package/dist/react-native/util/userAgentPlatform.js.map +1 -0
  273. package/dist/react-native/util/uuidUtils.d.ts +1 -1
  274. package/dist/react-native/util/uuidUtils.js +1 -1
  275. package/dist/react-native/util/uuidUtils.js.map +1 -0
  276. package/package.json +1 -21
  277. package/dist/browser/defaultHttpClient-browser.mjs.map +0 -1
  278. package/dist/browser/logger/log-browser.mjs.map +0 -1
  279. package/dist/browser/policies/decompressResponsePolicy-browser.mjs.map +0 -1
  280. package/dist/browser/policies/proxyPolicy-browser.mjs.map +0 -1
  281. package/dist/browser/util/bytesEncoding-browser.mjs.map +0 -1
  282. package/dist/browser/util/concat-browser.mjs.map +0 -1
  283. package/dist/browser/util/inspect-browser.mjs.map +0 -1
  284. package/dist/browser/util/sha256-browser.mjs.map +0 -1
  285. package/dist/browser/util/userAgentPlatform-browser.mjs.map +0 -1
  286. package/dist/browser/util/uuidUtils-browser.mjs.map +0 -1
  287. package/dist/react-native/defaultHttpClient-react-native.mjs.map +0 -1
  288. package/dist/react-native/logger/log-react-native.mjs.map +0 -1
  289. package/dist/react-native/policies/proxyPolicy-react-native.mjs.map +0 -1
  290. package/dist/react-native/util/bytesEncoding-react-native.mjs.map +0 -1
  291. package/dist/react-native/util/concat-react-native.mjs.map +0 -1
  292. package/dist/react-native/util/inspect-react-native.mjs.map +0 -1
  293. package/dist/react-native/util/sha256-react-native.mjs.map +0 -1
  294. package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +0 -1
  295. package/dist/react-native/util/uuidUtils-react-native.mjs.map +0 -1
@@ -1,177 +1,185 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.createXhrHttpClient = createXhrHttpClient;
6
- const AbortError_js_1 = require("./abort-controller/AbortError.js");
7
- const httpHeaders_js_1 = require("./httpHeaders.js");
8
- const restError_js_1 = require("./restError.js");
9
- const typeGuards_js_1 = require("./util/typeGuards.js");
10
- const arrayBuffer_js_1 = require("./util/arrayBuffer.js");
11
- /**
12
- * A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.
13
- * @internal
14
- */
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var xhrHttpClient_exports = {};
19
+ __export(xhrHttpClient_exports, {
20
+ createXhrHttpClient: () => createXhrHttpClient
21
+ });
22
+ module.exports = __toCommonJS(xhrHttpClient_exports);
23
+ var import_AbortError = require("./abort-controller/AbortError.js");
24
+ var import_httpHeaders = require("./httpHeaders.js");
25
+ var import_restError = require("./restError.js");
26
+ var import_typeGuards = require("./util/typeGuards.js");
27
+ var import_arrayBuffer = require("./util/arrayBuffer.js");
15
28
  class XhrHttpClient {
16
- /**
17
- * Makes a request over an underlying transport layer and returns the response.
18
- * @param request - The request to be made.
19
- */
20
- async sendRequest(request) {
21
- const url = new URL(request.url);
22
- const isInsecure = url.protocol !== "https:";
23
- if (isInsecure && !request.allowInsecureConnection) {
24
- throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
25
- }
26
- const xhr = new XMLHttpRequest();
27
- if (request.proxySettings) {
28
- throw new Error("HTTP proxy is not supported in browser environment");
29
- }
30
- const abortSignal = request.abortSignal;
31
- if (abortSignal) {
32
- if (abortSignal.aborted) {
33
- throw new AbortError_js_1.AbortError("The operation was aborted. Request has already been canceled.");
34
- }
35
- const listener = () => {
36
- xhr.abort();
37
- };
38
- abortSignal.addEventListener("abort", listener);
39
- xhr.addEventListener("readystatechange", () => {
40
- if (xhr.readyState === XMLHttpRequest.DONE) {
41
- abortSignal.removeEventListener("abort", listener);
42
- }
43
- });
44
- }
45
- addProgressListener(xhr.upload, request.onUploadProgress);
46
- addProgressListener(xhr, request.onDownloadProgress);
47
- xhr.open(request.method, request.url);
48
- xhr.timeout = request.timeout;
49
- xhr.withCredentials = request.withCredentials;
50
- for (const [name, value] of request.headers) {
51
- xhr.setRequestHeader(name, value);
52
- }
53
- xhr.responseType = request.streamResponseStatusCodes?.size ? "blob" : "text";
54
- const body = typeof request.body === "function" ? request.body() : request.body;
55
- if ((0, typeGuards_js_1.isReadableStream)(body)) {
56
- throw new Error("streams are not supported in XhrHttpClient.");
57
- }
58
- if (body instanceof ArrayBuffer) {
59
- xhr.send(body);
60
- }
61
- else if (typeof body === "object" && body && "buffer" in body) {
62
- xhr.send((0, arrayBuffer_js_1.arrayBufferViewToArrayBuffer)(body));
63
- }
64
- else {
65
- xhr.send(body === undefined ? null : body);
66
- }
67
- if (xhr.responseType === "blob") {
68
- return new Promise((resolve, reject) => {
69
- handleBlobResponse(xhr, request, resolve, reject);
70
- rejectOnTerminalEvent(request, xhr, reject);
71
- });
72
- }
73
- else {
74
- return new Promise(function (resolve, reject) {
75
- xhr.addEventListener("load", () => resolve({
76
- request,
77
- status: xhr.status,
78
- headers: parseHeaders(xhr),
79
- bodyAsText: xhr.responseText,
80
- }));
81
- rejectOnTerminalEvent(request, xhr, reject);
82
- });
29
+ /**
30
+ * Makes a request over an underlying transport layer and returns the response.
31
+ * @param request - The request to be made.
32
+ */
33
+ async sendRequest(request) {
34
+ const url = new URL(request.url);
35
+ const isInsecure = url.protocol !== "https:";
36
+ if (isInsecure && !request.allowInsecureConnection) {
37
+ throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
38
+ }
39
+ const xhr = new XMLHttpRequest();
40
+ if (request.proxySettings) {
41
+ throw new Error("HTTP proxy is not supported in browser environment");
42
+ }
43
+ const abortSignal = request.abortSignal;
44
+ if (abortSignal) {
45
+ if (abortSignal.aborted) {
46
+ throw new import_AbortError.AbortError("The operation was aborted. Request has already been canceled.");
47
+ }
48
+ const listener = () => {
49
+ xhr.abort();
50
+ };
51
+ abortSignal.addEventListener("abort", listener);
52
+ xhr.addEventListener("readystatechange", () => {
53
+ if (xhr.readyState === XMLHttpRequest.DONE) {
54
+ abortSignal.removeEventListener("abort", listener);
83
55
  }
56
+ });
57
+ }
58
+ addProgressListener(xhr.upload, request.onUploadProgress);
59
+ addProgressListener(xhr, request.onDownloadProgress);
60
+ xhr.open(request.method, request.url);
61
+ xhr.timeout = request.timeout;
62
+ xhr.withCredentials = request.withCredentials;
63
+ for (const [name, value] of request.headers) {
64
+ xhr.setRequestHeader(name, value);
65
+ }
66
+ xhr.responseType = request.streamResponseStatusCodes?.size ? "blob" : "text";
67
+ const body = typeof request.body === "function" ? request.body() : request.body;
68
+ if ((0, import_typeGuards.isReadableStream)(body)) {
69
+ throw new Error("streams are not supported in XhrHttpClient.");
70
+ }
71
+ if (body instanceof ArrayBuffer) {
72
+ xhr.send(body);
73
+ } else if (typeof body === "object" && body && "buffer" in body) {
74
+ xhr.send((0, import_arrayBuffer.arrayBufferViewToArrayBuffer)(body));
75
+ } else {
76
+ xhr.send(body === void 0 ? null : body);
77
+ }
78
+ if (xhr.responseType === "blob") {
79
+ return new Promise((resolve, reject) => {
80
+ handleBlobResponse(xhr, request, resolve, reject);
81
+ rejectOnTerminalEvent(request, xhr, reject);
82
+ });
83
+ } else {
84
+ return new Promise(function(resolve, reject) {
85
+ xhr.addEventListener(
86
+ "load",
87
+ () => resolve({
88
+ request,
89
+ status: xhr.status,
90
+ headers: parseHeaders(xhr),
91
+ bodyAsText: xhr.responseText
92
+ })
93
+ );
94
+ rejectOnTerminalEvent(request, xhr, reject);
95
+ });
84
96
  }
97
+ }
85
98
  }
86
99
  function handleBlobResponse(xhr, request, res, rej) {
87
- xhr.addEventListener("readystatechange", () => {
88
- // Resolve as soon as headers are loaded
89
- if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
90
- if (
91
- // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
92
- request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) ||
93
- request.streamResponseStatusCodes?.has(xhr.status)) {
94
- const blobBody = new Promise((resolve, reject) => {
95
- xhr.addEventListener("load", () => {
96
- resolve(xhr.response);
97
- });
98
- rejectOnTerminalEvent(request, xhr, reject);
99
- });
100
- res({
101
- request,
102
- status: xhr.status,
103
- headers: parseHeaders(xhr),
104
- blobBody,
105
- });
106
- }
107
- else {
108
- xhr.addEventListener("load", () => {
109
- // xhr.response is of Blob type if the request is sent with xhr.responseType === "blob"
110
- // but the status code is not one of the stream response status codes,
111
- // so treat it as text and convert from Blob to text
112
- if (xhr.response) {
113
- xhr.response
114
- .text()
115
- .then((text) => {
116
- res({
117
- request: request,
118
- status: xhr.status,
119
- headers: parseHeaders(xhr),
120
- bodyAsText: text,
121
- });
122
- return;
123
- })
124
- .catch((e) => {
125
- rej(e);
126
- });
127
- }
128
- else {
129
- res({
130
- request,
131
- status: xhr.status,
132
- headers: parseHeaders(xhr),
133
- });
134
- }
135
- });
136
- }
137
- }
138
- });
100
+ xhr.addEventListener("readystatechange", () => {
101
+ if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
102
+ if (
103
+ // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
104
+ request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) || request.streamResponseStatusCodes?.has(xhr.status)
105
+ ) {
106
+ const blobBody = new Promise((resolve, reject) => {
107
+ xhr.addEventListener("load", () => {
108
+ resolve(xhr.response);
109
+ });
110
+ rejectOnTerminalEvent(request, xhr, reject);
111
+ });
112
+ res({
113
+ request,
114
+ status: xhr.status,
115
+ headers: parseHeaders(xhr),
116
+ blobBody
117
+ });
118
+ } else {
119
+ xhr.addEventListener("load", () => {
120
+ if (xhr.response) {
121
+ xhr.response.text().then((text) => {
122
+ res({
123
+ request,
124
+ status: xhr.status,
125
+ headers: parseHeaders(xhr),
126
+ bodyAsText: text
127
+ });
128
+ return;
129
+ }).catch((e) => {
130
+ rej(e);
131
+ });
132
+ } else {
133
+ res({
134
+ request,
135
+ status: xhr.status,
136
+ headers: parseHeaders(xhr)
137
+ });
138
+ }
139
+ });
140
+ }
141
+ }
142
+ });
139
143
  }
140
144
  function addProgressListener(xhr, listener) {
141
- if (listener) {
142
- xhr.addEventListener("progress", (rawEvent) => listener({
143
- loadedBytes: rawEvent.loaded,
144
- }));
145
- }
145
+ if (listener) {
146
+ xhr.addEventListener(
147
+ "progress",
148
+ (rawEvent) => listener({
149
+ loadedBytes: rawEvent.loaded
150
+ })
151
+ );
152
+ }
146
153
  }
147
154
  function parseHeaders(xhr) {
148
- const responseHeaders = (0, httpHeaders_js_1.createHttpHeaders)();
149
- const headerLines = xhr
150
- .getAllResponseHeaders()
151
- .trim()
152
- .split(/[\r\n]+/);
153
- for (const line of headerLines) {
154
- const index = line.indexOf(":");
155
- const headerName = line.slice(0, index);
156
- const headerValue = line.slice(index + 2);
157
- responseHeaders.set(headerName, headerValue);
158
- }
159
- return responseHeaders;
155
+ const responseHeaders = (0, import_httpHeaders.createHttpHeaders)();
156
+ const headerLines = xhr.getAllResponseHeaders().trim().split(/[\r\n]+/);
157
+ for (const line of headerLines) {
158
+ const index = line.indexOf(":");
159
+ const headerName = line.slice(0, index);
160
+ const headerValue = line.slice(index + 2);
161
+ responseHeaders.set(headerName, headerValue);
162
+ }
163
+ return responseHeaders;
160
164
  }
161
165
  function rejectOnTerminalEvent(request, xhr, reject) {
162
- xhr.addEventListener("error", () => reject(new restError_js_1.RestError(`Failed to send request to ${request.url}`, {
163
- code: restError_js_1.RestError.REQUEST_SEND_ERROR,
164
- request,
165
- })));
166
- const abortError = new AbortError_js_1.AbortError("The operation was aborted.");
167
- xhr.addEventListener("abort", () => reject(abortError));
168
- xhr.addEventListener("timeout", () => reject(abortError));
166
+ xhr.addEventListener(
167
+ "error",
168
+ () => reject(
169
+ new import_restError.RestError(`Failed to send request to ${request.url}`, {
170
+ code: import_restError.RestError.REQUEST_SEND_ERROR,
171
+ request
172
+ })
173
+ )
174
+ );
175
+ const abortError = new import_AbortError.AbortError("The operation was aborted.");
176
+ xhr.addEventListener("abort", () => reject(abortError));
177
+ xhr.addEventListener("timeout", () => reject(abortError));
169
178
  }
170
- /**
171
- * Create a new HttpClient instance for the browser environment.
172
- * @internal
173
- */
174
179
  function createXhrHttpClient() {
175
- return new XhrHttpClient();
180
+ return new XhrHttpClient();
176
181
  }
177
- //# sourceMappingURL=xhrHttpClient.js.map
182
+ // Annotate the CommonJS export names for ESM import in node:
183
+ 0 && (module.exports = {
184
+ createXhrHttpClient
185
+ });
@@ -1 +1,7 @@
1
- {"version":3,"file":"xhrHttpClient.js","sourceRoot":"","sources":["../../src/xhrHttpClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAkNlC,kDAEC;AAlND,oEAA8D;AAQ9D,qDAAqD;AACrD,iDAA2C;AAC3C,wDAAwD;AACxD,0DAAqE;AAErE;;;GAGG;AACH,MAAM,aAAa;IACjB;;;OAGG;IACI,KAAK,CAAC,WAAW,CAAC,OAAwB;QAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;QAE7C,IAAI,UAAU,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,qBAAqB,OAAO,CAAC,GAAG,0CAA0C,CAAC,CAAC;QAC9F,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,cAAc,EAAE,CAAC;QAEjC,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE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AC;QAC1C,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,qBAAqB,CAC5B,OAAwB,EACxB,GAAmB,EACnB,MAA0B;IAE1B,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CACjC,MAAM,CACJ,IAAI,wBAAS,CAAC,6BAA6B,OAAO,CAAC,GAAG,EAAE,EAAE;QACxD,IAAI,EAAE,wBAAS,CAAC,kBAAkB;QAClC,OAAO;KACR,CAAC,CACH,CACF,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,0BAAU,CAAC,4BAA4B,CAAC,CAAC;IAChE,GAAG,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACxD,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"./abort-controller/AbortError.js\";\nimport type {\n HttpClient,\n HttpHeaders,\n PipelineRequest,\n PipelineResponse,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { RestError } from \"./restError.js\";\nimport { isReadableStream } from \"./util/typeGuards.js\";\nimport { arrayBufferViewToArrayBuffer } from \"./util/arrayBuffer.js\";\n\n/**\n * A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.\n * @internal\n */\nclass XhrHttpClient implements HttpClient {\n /**\n * Makes a request over an underlying transport layer and returns the response.\n * @param request - The request to be made.\n */\n public async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n const url = new URL(request.url);\n const isInsecure = url.protocol !== \"https:\";\n\n if (isInsecure && !request.allowInsecureConnection) {\n throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);\n }\n\n const xhr = new XMLHttpRequest();\n\n if (request.proxySettings) {\n throw new Error(\"HTTP proxy is not supported in browser environment\");\n }\n\n const abortSignal = request.abortSignal;\n if (abortSignal) {\n if (abortSignal.aborted) {\n throw new AbortError(\"The operation was aborted. Request has already been canceled.\");\n }\n\n const listener = (): void => {\n xhr.abort();\n };\n abortSignal.addEventListener(\"abort\", listener);\n xhr.addEventListener(\"readystatechange\", () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n abortSignal.removeEventListener(\"abort\", listener);\n }\n });\n }\n\n addProgressListener(xhr.upload, request.onUploadProgress);\n addProgressListener(xhr, request.onDownloadProgress);\n\n xhr.open(request.method, request.url);\n xhr.timeout = request.timeout;\n xhr.withCredentials = request.withCredentials;\n for (const [name, value] of request.headers) {\n xhr.setRequestHeader(name, value);\n }\n\n xhr.responseType = request.streamResponseStatusCodes?.size ? \"blob\" : \"text\";\n\n const body = typeof request.body === \"function\" ? request.body() : request.body;\n if (isReadableStream(body)) {\n throw new Error(\"streams are not supported in XhrHttpClient.\");\n }\n\n if (body instanceof ArrayBuffer) {\n xhr.send(body);\n } else if (typeof body === \"object\" && body && \"buffer\" in body) {\n xhr.send(arrayBufferViewToArrayBuffer(body));\n } else {\n xhr.send(body === undefined ? null : body);\n }\n\n if (xhr.responseType === \"blob\") {\n return new Promise((resolve, reject) => {\n handleBlobResponse(xhr, request, resolve, reject);\n rejectOnTerminalEvent(request, xhr, reject);\n });\n } else {\n return new Promise(function (resolve, reject) {\n xhr.addEventListener(\"load\", () =>\n resolve({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: xhr.responseText,\n }),\n );\n rejectOnTerminalEvent(request, xhr, reject);\n });\n }\n }\n}\n\nfunction handleBlobResponse(\n xhr: XMLHttpRequest,\n request: PipelineRequest,\n res: (value: PipelineResponse | PromiseLike<PipelineResponse>) => void,\n rej: (reason?: any) => void,\n): void {\n xhr.addEventListener(\"readystatechange\", () => {\n // Resolve as soon as headers are loaded\n if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {\n if (\n // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code\n request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) ||\n request.streamResponseStatusCodes?.has(xhr.status)\n ) {\n const blobBody = new Promise<Blob>((resolve, reject) => {\n xhr.addEventListener(\"load\", () => {\n resolve(xhr.response);\n });\n rejectOnTerminalEvent(request, xhr, reject);\n });\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n blobBody,\n });\n } else {\n xhr.addEventListener(\"load\", () => {\n // xhr.response is of Blob type if the request is sent with xhr.responseType === \"blob\"\n // but the status code is not one of the stream response status codes,\n // so treat it as text and convert from Blob to text\n if (xhr.response) {\n xhr.response\n .text()\n .then((text: string) => {\n res({\n request: request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: text,\n });\n return;\n })\n .catch((e: any) => {\n rej(e);\n });\n } else {\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n });\n }\n });\n }\n }\n });\n}\n\nfunction addProgressListener(\n xhr: XMLHttpRequestEventTarget,\n listener?: (progress: TransferProgressEvent) => void,\n): void {\n if (listener) {\n xhr.addEventListener(\"progress\", (rawEvent) =>\n listener({\n loadedBytes: rawEvent.loaded,\n }),\n );\n }\n}\n\nfunction parseHeaders(xhr: XMLHttpRequest): HttpHeaders {\n const responseHeaders = createHttpHeaders();\n const headerLines = xhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/);\n for (const line of headerLines) {\n const index = line.indexOf(\":\");\n const headerName = line.slice(0, index);\n const headerValue = line.slice(index + 2);\n responseHeaders.set(headerName, headerValue);\n }\n return responseHeaders;\n}\n\nfunction rejectOnTerminalEvent(\n request: PipelineRequest,\n xhr: XMLHttpRequest,\n reject: (err: any) => void,\n): void {\n xhr.addEventListener(\"error\", () =>\n reject(\n new RestError(`Failed to send request to ${request.url}`, {\n code: RestError.REQUEST_SEND_ERROR,\n request,\n }),\n ),\n );\n const abortError = new AbortError(\"The operation was aborted.\");\n xhr.addEventListener(\"abort\", () => reject(abortError));\n xhr.addEventListener(\"timeout\", () => reject(abortError));\n}\n\n/**\n * Create a new HttpClient instance for the browser environment.\n * @internal\n */\nexport function createXhrHttpClient(): HttpClient {\n return new XhrHttpClient();\n}\n"]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["/mnt/vss/_work/1/s/sdk/core/ts-http-runtime/src/xhrHttpClient.ts"],
4
+ "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"./abort-controller/AbortError.js\";\nimport type {\n HttpClient,\n HttpHeaders,\n PipelineRequest,\n PipelineResponse,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { RestError } from \"./restError.js\";\nimport { isReadableStream } from \"./util/typeGuards.js\";\nimport { arrayBufferViewToArrayBuffer } from \"./util/arrayBuffer.js\";\n\n/**\n * A HttpClient implementation that uses XMLHttpRequest to send HTTP requests.\n * @internal\n */\nclass XhrHttpClient implements HttpClient {\n /**\n * Makes a request over an underlying transport layer and returns the response.\n * @param request - The request to be made.\n */\n public async sendRequest(request: PipelineRequest): Promise<PipelineResponse> {\n const url = new URL(request.url);\n const isInsecure = url.protocol !== \"https:\";\n\n if (isInsecure && !request.allowInsecureConnection) {\n throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);\n }\n\n const xhr = new XMLHttpRequest();\n\n if (request.proxySettings) {\n throw new Error(\"HTTP proxy is not supported in browser environment\");\n }\n\n const abortSignal = request.abortSignal;\n if (abortSignal) {\n if (abortSignal.aborted) {\n throw new AbortError(\"The operation was aborted. Request has already been canceled.\");\n }\n\n const listener = (): void => {\n xhr.abort();\n };\n abortSignal.addEventListener(\"abort\", listener);\n xhr.addEventListener(\"readystatechange\", () => {\n if (xhr.readyState === XMLHttpRequest.DONE) {\n abortSignal.removeEventListener(\"abort\", listener);\n }\n });\n }\n\n addProgressListener(xhr.upload, request.onUploadProgress);\n addProgressListener(xhr, request.onDownloadProgress);\n\n xhr.open(request.method, request.url);\n xhr.timeout = request.timeout;\n xhr.withCredentials = request.withCredentials;\n for (const [name, value] of request.headers) {\n xhr.setRequestHeader(name, value);\n }\n\n xhr.responseType = request.streamResponseStatusCodes?.size ? \"blob\" : \"text\";\n\n const body = typeof request.body === \"function\" ? request.body() : request.body;\n if (isReadableStream(body)) {\n throw new Error(\"streams are not supported in XhrHttpClient.\");\n }\n\n if (body instanceof ArrayBuffer) {\n xhr.send(body);\n } else if (typeof body === \"object\" && body && \"buffer\" in body) {\n xhr.send(arrayBufferViewToArrayBuffer(body));\n } else {\n xhr.send(body === undefined ? null : body);\n }\n\n if (xhr.responseType === \"blob\") {\n return new Promise((resolve, reject) => {\n handleBlobResponse(xhr, request, resolve, reject);\n rejectOnTerminalEvent(request, xhr, reject);\n });\n } else {\n return new Promise(function (resolve, reject) {\n xhr.addEventListener(\"load\", () =>\n resolve({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: xhr.responseText,\n }),\n );\n rejectOnTerminalEvent(request, xhr, reject);\n });\n }\n }\n}\n\nfunction handleBlobResponse(\n xhr: XMLHttpRequest,\n request: PipelineRequest,\n res: (value: PipelineResponse | PromiseLike<PipelineResponse>) => void,\n rej: (reason?: any) => void,\n): void {\n xhr.addEventListener(\"readystatechange\", () => {\n // Resolve as soon as headers are loaded\n if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {\n if (\n // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code\n request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) ||\n request.streamResponseStatusCodes?.has(xhr.status)\n ) {\n const blobBody = new Promise<Blob>((resolve, reject) => {\n xhr.addEventListener(\"load\", () => {\n resolve(xhr.response);\n });\n rejectOnTerminalEvent(request, xhr, reject);\n });\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n blobBody,\n });\n } else {\n xhr.addEventListener(\"load\", () => {\n // xhr.response is of Blob type if the request is sent with xhr.responseType === \"blob\"\n // but the status code is not one of the stream response status codes,\n // so treat it as text and convert from Blob to text\n if (xhr.response) {\n xhr.response\n .text()\n .then((text: string) => {\n res({\n request: request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n bodyAsText: text,\n });\n return;\n })\n .catch((e: any) => {\n rej(e);\n });\n } else {\n res({\n request,\n status: xhr.status,\n headers: parseHeaders(xhr),\n });\n }\n });\n }\n }\n });\n}\n\nfunction addProgressListener(\n xhr: XMLHttpRequestEventTarget,\n listener?: (progress: TransferProgressEvent) => void,\n): void {\n if (listener) {\n xhr.addEventListener(\"progress\", (rawEvent) =>\n listener({\n loadedBytes: rawEvent.loaded,\n }),\n );\n }\n}\n\nfunction parseHeaders(xhr: XMLHttpRequest): HttpHeaders {\n const responseHeaders = createHttpHeaders();\n const headerLines = xhr\n .getAllResponseHeaders()\n .trim()\n .split(/[\\r\\n]+/);\n for (const line of headerLines) {\n const index = line.indexOf(\":\");\n const headerName = line.slice(0, index);\n const headerValue = line.slice(index + 2);\n responseHeaders.set(headerName, headerValue);\n }\n return responseHeaders;\n}\n\nfunction rejectOnTerminalEvent(\n request: PipelineRequest,\n xhr: XMLHttpRequest,\n reject: (err: any) => void,\n): void {\n xhr.addEventListener(\"error\", () =>\n reject(\n new RestError(`Failed to send request to ${request.url}`, {\n code: RestError.REQUEST_SEND_ERROR,\n request,\n }),\n ),\n );\n const abortError = new AbortError(\"The operation was aborted.\");\n xhr.addEventListener(\"abort\", () => reject(abortError));\n xhr.addEventListener(\"timeout\", () => reject(abortError));\n}\n\n/**\n * Create a new HttpClient instance for the browser environment.\n * @internal\n */\nexport function createXhrHttpClient(): HttpClient {\n return new XhrHttpClient();\n}\n"],
5
+ "mappings": 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C;AAAA,IACH;AAAA,EACF;AACA,QAAM,aAAa,IAAI,6BAAW,4BAA4B;AAC9D,MAAI,iBAAiB,SAAS,MAAM,OAAO,UAAU,CAAC;AACtD,MAAI,iBAAiB,WAAW,MAAM,OAAO,UAAU,CAAC;AAC1D;AAMO,SAAS,sBAAkC;AAChD,SAAO,IAAI,cAAc;AAC3B;",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { HttpClient, HttpMethods } from "../interfaces.js";
1
+ import type { HttpClient, HttpMethods, MultipartRequestBody, RequestBodyType } from "../interfaces.js";
2
2
  import type { Pipeline } from "../pipeline.js";
3
3
  import type { HttpResponse, RequestParameters } from "./common.js";
4
4
  /**
@@ -14,4 +14,13 @@ export declare function sendRequest(method: HttpMethods, url: string, pipeline:
14
14
  export interface InternalRequestParameters extends RequestParameters {
15
15
  responseAsStream?: boolean;
16
16
  }
17
+ interface RequestBody {
18
+ body?: RequestBodyType;
19
+ multipartBody?: MultipartRequestBody;
20
+ }
21
+ /**
22
+ * Prepares the body before sending the request
23
+ */
24
+ export declare function getRequestBody(body?: unknown, contentType?: string): RequestBody;
25
+ export {};
17
26
  //# sourceMappingURL=sendRequest.d.ts.map
@@ -4,7 +4,7 @@ import { isRestError, RestError } from "../restError.js";
4
4
  import { createHttpHeaders } from "../httpHeaders.js";
5
5
  import { createPipelineRequest } from "../pipelineRequest.js";
6
6
  import { getCachedDefaultHttpsClient } from "./clientHelpers.js";
7
- import { isReadableStream } from "../util/typeGuards.js";
7
+ import { isBlob, isReadableStream } from "../util/typeGuards.js";
8
8
  import { buildMultipartBody } from "./multipart.js";
9
9
  /**
10
10
  * Helper function to send request used by the client
@@ -67,6 +67,9 @@ function getContentType(body) {
67
67
  if (ArrayBuffer.isView(body)) {
68
68
  return "application/octet-stream";
69
69
  }
70
+ if (isBlob(body) && body.type) {
71
+ return body.type;
72
+ }
70
73
  if (typeof body === "string") {
71
74
  try {
72
75
  JSON.parse(body);
@@ -110,13 +113,16 @@ function buildPipelineRequest(method, url, options = {}) {
110
113
  /**
111
114
  * Prepares the body before sending the request
112
115
  */
113
- function getRequestBody(body, contentType = "") {
116
+ export function getRequestBody(body, contentType = "") {
114
117
  if (body === undefined) {
115
118
  return { body: undefined };
116
119
  }
117
120
  if (typeof FormData !== "undefined" && body instanceof FormData) {
118
121
  return { body };
119
122
  }
123
+ if (isBlob(body)) {
124
+ return { body };
125
+ }
120
126
  if (isReadableStream(body) || typeof body === "function") {
121
127
  return { body };
122
128
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sendRequest.js","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAmB,EACnB,GAAW,EACX,QAAkB,EAClB,UAAqC,EAAE,EACvC,gBAA6B;IAE7B,MAAM,UAAU,GAAG,gBAAgB,IAAI,2BAA2B,EAAE,CAAC;IACrE,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,QAAQ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5D,MAAM,GAAG,GAAG,UAAU,GAAG,gDAAgD,QAAQ,CAAC,UAAU,GAAG,CAAC;IAChG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC,WAAW,CAAC;IAClD,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE;QACxB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n PipelineResponse,\n RequestBodyType,\n} from \"../interfaces.js\";\nimport { isRestError, RestError } from \"../restError.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { createPipelineRequest } from \"../pipelineRequest.js\";\nimport { getCachedDefaultHttpsClient } from \"./clientHelpers.js\";\nimport { isReadableStream } from \"../util/typeGuards.js\";\nimport type { HttpResponse, RequestParameters } from \"./common.js\";\nimport type { PartDescriptor } from \"./multipart.js\";\nimport { buildMultipartBody } from \"./multipart.js\";\n\n/**\n * Helper function to send request used by the client\n * @param method - method to use to send the request\n * @param url - url to send the request to\n * @param pipeline - pipeline with the policies to run when sending the request\n * @param options - request options\n * @param customHttpClient - a custom HttpClient to use when making the request\n * @returns returns and HttpResponse\n */\nexport async function sendRequest(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: InternalRequestParameters = {},\n customHttpClient?: HttpClient,\n): Promise<HttpResponse> {\n const httpClient = customHttpClient ?? getCachedDefaultHttpsClient();\n const request = buildPipelineRequest(method, url, options);\n\n try {\n const response = await pipeline.sendRequest(httpClient, request);\n const headers = response.headers.toJSON();\n const stream = response.readableStreamBody ?? response.browserStreamBody;\n const parsedBody =\n options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);\n const body = stream ?? parsedBody;\n\n if (options?.onResponse) {\n options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });\n }\n\n return {\n request,\n headers,\n status: `${response.status}`,\n body,\n };\n } catch (e: unknown) {\n if (isRestError(e) && e.response && options.onResponse) {\n const { response } = e;\n const rawHeaders = response.headers.toJSON();\n // UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError property\n options?.onResponse({ ...response, request, rawHeaders }, e);\n }\n\n throw e;\n }\n}\n\n/**\n * Function to determine the request content type\n * @param options - request options InternalRequestParameters\n * @returns returns the content-type\n */\nfunction getRequestContentType(options: InternalRequestParameters = {}): string | undefined {\n return (\n options.contentType ??\n (options.headers?.[\"content-type\"] as string) ??\n getContentType(options.body)\n );\n}\n\n/**\n * Function to determine the content-type of a body\n * this is used if an explicit content-type is not provided\n * @param body - body in the request\n * @returns returns the content-type\n */\nfunction getContentType(body: any): string | undefined {\n if (body === undefined) {\n return undefined;\n }\n\n if (ArrayBuffer.isView(body)) {\n return \"application/octet-stream\";\n }\n\n if (typeof body === \"string\") {\n try {\n JSON.parse(body);\n return \"application/json\";\n } catch (error: any) {\n // If we fail to parse the body, it is not json\n return undefined;\n }\n }\n // By default return json\n return \"application/json\";\n}\n\nexport interface InternalRequestParameters extends RequestParameters {\n responseAsStream?: boolean;\n}\n\nfunction buildPipelineRequest(\n method: HttpMethods,\n url: string,\n options: InternalRequestParameters = {},\n): PipelineRequest {\n const requestContentType = getRequestContentType(options);\n const { body, multipartBody } = getRequestBody(options.body, requestContentType);\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(requestContentType && {\n \"content-type\": requestContentType,\n }),\n });\n\n return createPipelineRequest({\n url,\n method,\n body,\n multipartBody,\n headers,\n allowInsecureConnection: options.allowInsecureConnection,\n abortSignal: options.abortSignal,\n onUploadProgress: options.onUploadProgress,\n onDownloadProgress: options.onDownloadProgress,\n timeout: options.timeout,\n enableBrowserStreams: true,\n streamResponseStatusCodes: options.responseAsStream\n ? new Set([Number.POSITIVE_INFINITY])\n : undefined,\n });\n}\n\ninterface RequestBody {\n body?: RequestBodyType;\n multipartBody?: MultipartRequestBody;\n}\n\n/**\n * Prepares the body before sending the request\n */\nfunction getRequestBody(body?: unknown, contentType: string = \"\"): RequestBody {\n if (body === undefined) {\n return { body: undefined };\n }\n\n if (typeof FormData !== \"undefined\" && body instanceof FormData) {\n return { body };\n }\n\n if (isReadableStream(body) || typeof body === \"function\") {\n return { body } as RequestBody;\n }\n\n if (ArrayBuffer.isView(body)) {\n return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };\n }\n\n const firstType = contentType.split(\";\")[0];\n\n switch (firstType) {\n case \"application/json\":\n return { body: JSON.stringify(body) };\n case \"multipart/form-data\":\n if (Array.isArray(body)) {\n return { multipartBody: buildMultipartBody(body as PartDescriptor[]) };\n }\n return { body: JSON.stringify(body) };\n case \"text/plain\":\n return { body: String(body) };\n default:\n if (typeof body === \"string\") {\n return { body };\n }\n return { body: JSON.stringify(body) };\n }\n}\n\n/**\n * Prepares the response body\n */\nfunction getResponseBody(response: PipelineResponse): RequestBodyType | undefined {\n // Set the default response type\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const firstType = contentType.split(\";\")[0];\n const bodyToParse = response.bodyAsText ?? \"\";\n\n if (firstType === \"text/plain\") {\n return String(bodyToParse);\n }\n // Default to \"application/json\" and fallback to string;\n try {\n return bodyToParse ? JSON.parse(bodyToParse) : undefined;\n } catch (error: any) {\n // If we were supposed to get a JSON object and failed to\n // parse, throw a parse error\n if (firstType === \"application/json\") {\n throw createParseError(response, error);\n }\n\n // We are not sure how to handle the response so we return it as\n // plain text.\n return String(bodyToParse);\n }\n}\n\nfunction createParseError(response: PipelineResponse, err: any): RestError {\n const msg = `Error \"${err}\" occurred while parsing the response body - ${response.bodyAsText}.`;\n const errCode = err.code ?? RestError.PARSE_ERROR;\n return new RestError(msg, {\n code: errCode,\n statusCode: response.status,\n request: response.request,\n response: response,\n });\n}\n"]}
1
+ {"version":3,"file":"sendRequest.js","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAmB,EACnB,GAAW,EACX,QAAkB,EAClB,UAAqC,EAAE,EACvC,gBAA6B;IAE7B,MAAM,UAAU,GAAG,gBAAgB,IAAI,2BAA2B,EAAE,CAAC;IACrE,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IAE3D,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC,kBAAkB,IAAI,QAAQ,CAAC,iBAAiB,CAAC;QACzE,MAAM,UAAU,GACd,OAAO,CAAC,gBAAgB,IAAI,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC3F,MAAM,IAAI,GAAG,MAAM,IAAI,UAAU,CAAC;QAElC,IAAI,OAAO,EAAE,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AQ,CAAC,UAAU,GAAG,CAAC;IAChG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC,WAAW,CAAC;IAClD,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE;QACxB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n PipelineResponse,\n RequestBodyType,\n} from \"../interfaces.js\";\nimport { isRestError, RestError } from \"../restError.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { createPipelineRequest } from \"../pipelineRequest.js\";\nimport { getCachedDefaultHttpsClient } from \"./clientHelpers.js\";\nimport { isBlob, isReadableStream } from \"../util/typeGuards.js\";\nimport type { HttpResponse, RequestParameters } from \"./common.js\";\nimport type { PartDescriptor } from \"./multipart.js\";\nimport { buildMultipartBody } from \"./multipart.js\";\n\n/**\n * Helper function to send request used by the client\n * @param method - method to use to send the request\n * @param url - url to send the request to\n * @param pipeline - pipeline with the policies to run when sending the request\n * @param options - request options\n * @param customHttpClient - a custom HttpClient to use when making the request\n * @returns returns and HttpResponse\n */\nexport async function sendRequest(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: InternalRequestParameters = {},\n customHttpClient?: HttpClient,\n): Promise<HttpResponse> {\n const httpClient = customHttpClient ?? getCachedDefaultHttpsClient();\n const request = buildPipelineRequest(method, url, options);\n\n try {\n const response = await pipeline.sendRequest(httpClient, request);\n const headers = response.headers.toJSON();\n const stream = response.readableStreamBody ?? response.browserStreamBody;\n const parsedBody =\n options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);\n const body = stream ?? parsedBody;\n\n if (options?.onResponse) {\n options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });\n }\n\n return {\n request,\n headers,\n status: `${response.status}`,\n body,\n };\n } catch (e: unknown) {\n if (isRestError(e) && e.response && options.onResponse) {\n const { response } = e;\n const rawHeaders = response.headers.toJSON();\n // UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError property\n options?.onResponse({ ...response, request, rawHeaders }, e);\n }\n\n throw e;\n }\n}\n\n/**\n * Function to determine the request content type\n * @param options - request options InternalRequestParameters\n * @returns returns the content-type\n */\nfunction getRequestContentType(options: InternalRequestParameters = {}): string | undefined {\n return (\n options.contentType ??\n (options.headers?.[\"content-type\"] as string) ??\n getContentType(options.body)\n );\n}\n\n/**\n * Function to determine the content-type of a body\n * this is used if an explicit content-type is not provided\n * @param body - body in the request\n * @returns returns the content-type\n */\nfunction getContentType(body: any): string | undefined {\n if (body === undefined) {\n return undefined;\n }\n\n if (ArrayBuffer.isView(body)) {\n return \"application/octet-stream\";\n }\n\n if (isBlob(body) && body.type) {\n return body.type;\n }\n\n if (typeof body === \"string\") {\n try {\n JSON.parse(body);\n return \"application/json\";\n } catch (error: any) {\n // If we fail to parse the body, it is not json\n return undefined;\n }\n }\n // By default return json\n return \"application/json\";\n}\n\nexport interface InternalRequestParameters extends RequestParameters {\n responseAsStream?: boolean;\n}\n\nfunction buildPipelineRequest(\n method: HttpMethods,\n url: string,\n options: InternalRequestParameters = {},\n): PipelineRequest {\n const requestContentType = getRequestContentType(options);\n const { body, multipartBody } = getRequestBody(options.body, requestContentType);\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(requestContentType && {\n \"content-type\": requestContentType,\n }),\n });\n\n return createPipelineRequest({\n url,\n method,\n body,\n multipartBody,\n headers,\n allowInsecureConnection: options.allowInsecureConnection,\n abortSignal: options.abortSignal,\n onUploadProgress: options.onUploadProgress,\n onDownloadProgress: options.onDownloadProgress,\n timeout: options.timeout,\n enableBrowserStreams: true,\n streamResponseStatusCodes: options.responseAsStream\n ? new Set([Number.POSITIVE_INFINITY])\n : undefined,\n });\n}\n\ninterface RequestBody {\n body?: RequestBodyType;\n multipartBody?: MultipartRequestBody;\n}\n\n/**\n * Prepares the body before sending the request\n */\nexport function getRequestBody(body?: unknown, contentType: string = \"\"): RequestBody {\n if (body === undefined) {\n return { body: undefined };\n }\n\n if (typeof FormData !== \"undefined\" && body instanceof FormData) {\n return { body };\n }\n\n if (isBlob(body)) {\n return { body };\n }\n\n if (isReadableStream(body) || typeof body === \"function\") {\n return { body } as RequestBody;\n }\n\n if (ArrayBuffer.isView(body)) {\n return { body: body instanceof Uint8Array ? body : JSON.stringify(body) };\n }\n\n const firstType = contentType.split(\";\")[0];\n\n switch (firstType) {\n case \"application/json\":\n return { body: JSON.stringify(body) };\n case \"multipart/form-data\":\n if (Array.isArray(body)) {\n return { multipartBody: buildMultipartBody(body as PartDescriptor[]) };\n }\n return { body: JSON.stringify(body) };\n case \"text/plain\":\n return { body: String(body) };\n default:\n if (typeof body === \"string\") {\n return { body };\n }\n return { body: JSON.stringify(body) };\n }\n}\n\n/**\n * Prepares the response body\n */\nfunction getResponseBody(response: PipelineResponse): RequestBodyType | undefined {\n // Set the default response type\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n const firstType = contentType.split(\";\")[0];\n const bodyToParse = response.bodyAsText ?? \"\";\n\n if (firstType === \"text/plain\") {\n return String(bodyToParse);\n }\n // Default to \"application/json\" and fallback to string;\n try {\n return bodyToParse ? JSON.parse(bodyToParse) : undefined;\n } catch (error: any) {\n // If we were supposed to get a JSON object and failed to\n // parse, throw a parse error\n if (firstType === \"application/json\") {\n throw createParseError(response, error);\n }\n\n // We are not sure how to handle the response so we return it as\n // plain text.\n return String(bodyToParse);\n }\n}\n\nfunction createParseError(response: PipelineResponse, err: any): RestError {\n const msg = `Error \"${err}\" occurred while parsing the response body - ${response.bodyAsText}.`;\n const errCode = err.code ?? RestError.PARSE_ERROR;\n return new RestError(msg, {\n code: errCode,\n statusCode: response.status,\n request: response.request,\n response: response,\n });\n}\n"]}
@@ -14,8 +14,8 @@ export { AbortError } from "./abort-controller/AbortError.js";
14
14
  export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, type Debugger, type TypeSpecRuntimeClientLogger, type TypeSpecRuntimeLogLevel, } from "./logger/logger.js";
15
15
  export type { BodyPart, FormDataValue, RawHttpHeaders, KeyObject, PxfObject, HttpClient, PipelineRequest, PipelineResponse, SendRequest, TlsSettings, Agent, RequestBodyType, FormDataMap, HttpHeaders, HttpMethods, MultipartRequestBody, TransferProgressEvent, ProxySettings, RawHttpHeadersInput, PipelineRetryOptions, } from "./interfaces.js";
16
16
  export { createHttpHeaders } from "./httpHeaders.js";
17
- export * from "./auth/schemes.js";
18
- export * from "./auth/oauth2Flows.js";
17
+ export type * from "./auth/schemes.js";
18
+ export type * from "./auth/oauth2Flows.js";
19
19
  export { type BasicCredential, type BearerTokenCredential, type OAuth2TokenCredential, type GetOAuth2TokenOptions, type GetBearerTokenOptions, type ApiKeyCredential, type ClientCredential, } from "./auth/credentials.js";
20
20
  export { createPipelineRequest, type PipelineRequestOptions } from "./pipelineRequest.js";
21
21
  export { type Pipeline, type PipelinePolicy, type AddPolicyOptions, type PipelinePhase, createEmptyPipeline, } from "./pipeline.js";
package/dist/esm/index.js CHANGED
@@ -3,8 +3,6 @@
3
3
  export { AbortError } from "./abort-controller/AbortError.js";
4
4
  export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, } from "./logger/logger.js";
5
5
  export { createHttpHeaders } from "./httpHeaders.js";
6
- export * from "./auth/schemes.js";
7
- export * from "./auth/oauth2Flows.js";
8
6
  export { createPipelineRequest } from "./pipelineRequest.js";
9
7
  export { createEmptyPipeline, } from "./pipeline.js";
10
8
  export { RestError, isRestError } from "./restError.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAUtC,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAKL,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n getLogLevel,\n setLogLevel,\n TypeSpecRuntimeLogger,\n type Debugger,\n type TypeSpecRuntimeClientLogger,\n type TypeSpecRuntimeLogLevel,\n} from \"./logger/logger.js\";\n\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport {\n type Pipeline,\n type PipelinePolicy,\n type AddPolicyOptions,\n type PipelinePhase,\n createEmptyPipeline,\n} from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { createDefaultHttpClient } from \"./defaultHttpClient.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAYrD,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAKL,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n getLogLevel,\n setLogLevel,\n TypeSpecRuntimeLogger,\n type Debugger,\n type TypeSpecRuntimeClientLogger,\n type TypeSpecRuntimeLogLevel,\n} from \"./logger/logger.js\";\n\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport type * from \"./auth/schemes.js\";\nexport type * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport {\n type Pipeline,\n type PipelinePolicy,\n type AddPolicyOptions,\n type PipelinePhase,\n createEmptyPipeline,\n} from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { createDefaultHttpClient } from \"./defaultHttpClient.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { FormDataMap, HttpHeaders, HttpMethods, MultipartRequestBody, PipelineRequest, ProxySettings, RequestBodyType, TransferProgressEvent } from "./interfaces.js";
2
- import { AuthScheme } from "./auth/schemes.js";
2
+ import type { AuthScheme } from "./auth/schemes.js";
3
3
  /**
4
4
  * Settings to initialize a request.
5
5
  * Almost equivalent to Partial<PipelineRequest>, but url is mandatory.
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AAO,CAAC,yBAAyB,CAAC;QACnE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,KAAK,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,UAAU,EAAE,CAAC;QACnD,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,KAAK,CAAC;QACxE,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,IAAI,KAAK,CAAC;QAClE,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACnE,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n ProxySettings,\n RequestBodyType,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { randomUUID } from \"./util/uuidUtils.js\";\nimport { AuthScheme } from \"./auth/schemes.js\";\n\n/**\n * Settings to initialize a request.\n * Almost equivalent to Partial<PipelineRequest>, but url is mandatory.\n */\nexport interface PipelineRequestOptions {\n /**\n * The URL to make the request to.\n */\n url: string;\n\n /**\n * The HTTP method to use when making the request.\n */\n method?: HttpMethods;\n\n /**\n * The HTTP headers to use when making the request.\n */\n headers?: HttpHeaders;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n * If the request is terminated, an `AbortError` is thrown.\n * Defaults to 0, which disables the timeout.\n */\n timeout?: number;\n\n /**\n * If credentials (cookies) should be sent along during an XHR.\n * Defaults to false.\n */\n withCredentials?: boolean;\n\n /**\n * A unique identifier for the request. Used for logging and tracing.\n */\n requestId?: string;\n\n /**\n * The HTTP body content (if any)\n */\n body?: RequestBodyType;\n\n /**\n * Body for a multipart request.\n */\n multipartBody?: MultipartRequestBody;\n\n /**\n * To simulate a browser form post\n */\n formData?: FormDataMap;\n\n /**\n * A list of response status codes whose corresponding PipelineResponse body should be treated as a stream.\n */\n streamResponseStatusCodes?: Set<number>;\n\n /**\n * BROWSER ONLY\n *\n * A browser only option to enable use of the Streams API. If this option is set and streaming is used\n * (see `streamResponseStatusCodes`), the response will have a property `browserStream` instead of\n * `blobBody` which will be undefined.\n *\n * Default value is false\n */\n enableBrowserStreams?: boolean;\n\n /**\n * Proxy configuration.\n */\n proxySettings?: ProxySettings;\n\n /**\n * If the connection should not be reused.\n */\n disableKeepAlive?: boolean;\n\n /**\n * Used to abort the request later.\n */\n abortSignal?: AbortSignal;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Callback which fires upon download progress. */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n\n /**\n * List of authentication schemes used for this specific request.\n * These schemes define how the request will be authenticated.\n *\n * If values are provided, these schemes override the client level authentication schemes.\n * If an empty array is provided, it explicitly specifies no authentication for the request.\n * If not provided at the request level, the client level authentication schemes will be used.\n */\n authSchemes?: AuthScheme[];\n\n /**\n * Additional options to set on the request. This provides a way to override\n * existing ones or provide request properties that are not declared.\n *\n * For possible valid properties, see\n * - NodeJS https.request options: https://nodejs.org/api/http.html#httprequestoptions-callback\n * - Browser RequestInit: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit\n *\n * WARNING: Options specified here will override any properties of same names when request is sent by {@link HttpClient}.\n */\n requestOverrides?: Record<string, unknown>;\n}\n\nclass PipelineRequestImpl implements PipelineRequest {\n public url: string;\n public method: HttpMethods;\n public headers: HttpHeaders;\n public timeout: number;\n public withCredentials: boolean;\n public body?: RequestBodyType;\n public multipartBody?: MultipartRequestBody;\n public formData?: FormDataMap;\n public streamResponseStatusCodes?: Set<number>;\n public enableBrowserStreams: boolean;\n\n public proxySettings?: ProxySettings;\n public disableKeepAlive: boolean;\n public abortSignal?: AbortSignal;\n public requestId: string;\n public allowInsecureConnection?: boolean;\n public onUploadProgress?: (progress: TransferProgressEvent) => void;\n public onDownloadProgress?: (progress: TransferProgressEvent) => void;\n public requestOverrides?: Record<string, unknown>;\n public authSchemes?: AuthScheme[];\n\n constructor(options: PipelineRequestOptions) {\n this.url = options.url;\n this.body = options.body;\n this.headers = options.headers ?? createHttpHeaders();\n this.method = options.method ?? \"GET\";\n this.timeout = options.timeout ?? 0;\n this.multipartBody = options.multipartBody;\n this.formData = options.formData;\n this.disableKeepAlive = options.disableKeepAlive ?? false;\n this.proxySettings = options.proxySettings;\n this.streamResponseStatusCodes = options.streamResponseStatusCodes;\n this.withCredentials = options.withCredentials ?? false;\n this.abortSignal = options.abortSignal;\n this.onUploadProgress = options.onUploadProgress;\n this.onDownloadProgress = options.onDownloadProgress;\n this.requestId = options.requestId || randomUUID();\n this.allowInsecureConnection = options.allowInsecureConnection ?? false;\n this.enableBrowserStreams = options.enableBrowserStreams ?? false;\n this.requestOverrides = options.requestOverrides;\n this.authSchemes = options.authSchemes;\n }\n}\n\n/**\n * Creates a new pipeline request with the given options.\n * This method is to allow for the easy setting of default values and not required.\n * @param options - The options to create the request with.\n */\nexport function createPipelineRequest(options: PipelineRequestOptions): PipelineRequest {\n return new PipelineRequestImpl(options);\n}\n"]}
1
+ {"version":3,"file":"pipelineRequest.js","sourceRoot":"","sources":["../../src/pipelineRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAY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AAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,UAAU,EAAE,CAAC;QACnD,IAAI,CAAC,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,IAAI,KAAK,CAAC;QACxE,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,IAAI,KAAK,CAAC;QAClE,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IACzC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACnE,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n ProxySettings,\n RequestBodyType,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { randomUUID } from \"./util/uuidUtils.js\";\nimport type { AuthScheme } from \"./auth/schemes.js\";\n\n/**\n * Settings to initialize a request.\n * Almost equivalent to Partial<PipelineRequest>, but url is mandatory.\n */\nexport interface PipelineRequestOptions {\n /**\n * The URL to make the request to.\n */\n url: string;\n\n /**\n * The HTTP method to use when making the request.\n */\n method?: HttpMethods;\n\n /**\n * The HTTP headers to use when making the request.\n */\n headers?: HttpHeaders;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n * If the request is terminated, an `AbortError` is thrown.\n * Defaults to 0, which disables the timeout.\n */\n timeout?: number;\n\n /**\n * If credentials (cookies) should be sent along during an XHR.\n * Defaults to false.\n */\n withCredentials?: boolean;\n\n /**\n * A unique identifier for the request. Used for logging and tracing.\n */\n requestId?: string;\n\n /**\n * The HTTP body content (if any)\n */\n body?: RequestBodyType;\n\n /**\n * Body for a multipart request.\n */\n multipartBody?: MultipartRequestBody;\n\n /**\n * To simulate a browser form post\n */\n formData?: FormDataMap;\n\n /**\n * A list of response status codes whose corresponding PipelineResponse body should be treated as a stream.\n */\n streamResponseStatusCodes?: Set<number>;\n\n /**\n * BROWSER ONLY\n *\n * A browser only option to enable use of the Streams API. If this option is set and streaming is used\n * (see `streamResponseStatusCodes`), the response will have a property `browserStream` instead of\n * `blobBody` which will be undefined.\n *\n * Default value is false\n */\n enableBrowserStreams?: boolean;\n\n /**\n * Proxy configuration.\n */\n proxySettings?: ProxySettings;\n\n /**\n * If the connection should not be reused.\n */\n disableKeepAlive?: boolean;\n\n /**\n * Used to abort the request later.\n */\n abortSignal?: AbortSignal;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Callback which fires upon download progress. */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n\n /**\n * List of authentication schemes used for this specific request.\n * These schemes define how the request will be authenticated.\n *\n * If values are provided, these schemes override the client level authentication schemes.\n * If an empty array is provided, it explicitly specifies no authentication for the request.\n * If not provided at the request level, the client level authentication schemes will be used.\n */\n authSchemes?: AuthScheme[];\n\n /**\n * Additional options to set on the request. This provides a way to override\n * existing ones or provide request properties that are not declared.\n *\n * For possible valid properties, see\n * - NodeJS https.request options: https://nodejs.org/api/http.html#httprequestoptions-callback\n * - Browser RequestInit: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit\n *\n * WARNING: Options specified here will override any properties of same names when request is sent by {@link HttpClient}.\n */\n requestOverrides?: Record<string, unknown>;\n}\n\nclass PipelineRequestImpl implements PipelineRequest {\n public url: string;\n public method: HttpMethods;\n public headers: HttpHeaders;\n public timeout: number;\n public withCredentials: boolean;\n public body?: RequestBodyType;\n public multipartBody?: MultipartRequestBody;\n public formData?: FormDataMap;\n public streamResponseStatusCodes?: Set<number>;\n public enableBrowserStreams: boolean;\n\n public proxySettings?: ProxySettings;\n public disableKeepAlive: boolean;\n public abortSignal?: AbortSignal;\n public requestId: string;\n public allowInsecureConnection?: boolean;\n public onUploadProgress?: (progress: TransferProgressEvent) => void;\n public onDownloadProgress?: (progress: TransferProgressEvent) => void;\n public requestOverrides?: Record<string, unknown>;\n public authSchemes?: AuthScheme[];\n\n constructor(options: PipelineRequestOptions) {\n this.url = options.url;\n this.body = options.body;\n this.headers = options.headers ?? createHttpHeaders();\n this.method = options.method ?? \"GET\";\n this.timeout = options.timeout ?? 0;\n this.multipartBody = options.multipartBody;\n this.formData = options.formData;\n this.disableKeepAlive = options.disableKeepAlive ?? false;\n this.proxySettings = options.proxySettings;\n this.streamResponseStatusCodes = options.streamResponseStatusCodes;\n this.withCredentials = options.withCredentials ?? false;\n this.abortSignal = options.abortSignal;\n this.onUploadProgress = options.onUploadProgress;\n this.onDownloadProgress = options.onDownloadProgress;\n this.requestId = options.requestId || randomUUID();\n this.allowInsecureConnection = options.allowInsecureConnection ?? false;\n this.enableBrowserStreams = options.enableBrowserStreams ?? false;\n this.requestOverrides = options.requestOverrides;\n this.authSchemes = options.authSchemes;\n }\n}\n\n/**\n * Creates a new pipeline request with the given options.\n * This method is to allow for the easy setting of default values and not required.\n * @param options - The options to create the request with.\n */\nexport function createPipelineRequest(options: PipelineRequestOptions): PipelineRequest {\n return new PipelineRequestImpl(options);\n}\n"]}