@typespec/ts-http-runtime 0.3.1-alpha.20250716.3 → 0.3.1-alpha.20250730.1

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 (268) hide show
  1. package/dist/browser/client/getClient.js +8 -10
  2. package/dist/browser/client/getClient.js.map +1 -1
  3. package/dist/browser/client/multipart.js +2 -4
  4. package/dist/browser/client/multipart.js.map +1 -1
  5. package/dist/browser/client/operationOptionHelpers.js +6 -7
  6. package/dist/browser/client/operationOptionHelpers.js.map +1 -1
  7. package/dist/browser/client/restError.js +4 -6
  8. package/dist/browser/client/restError.js.map +1 -1
  9. package/dist/browser/client/sendRequest.js +20 -19
  10. package/dist/browser/client/sendRequest.js.map +1 -1
  11. package/dist/browser/client/urlHelpers.js +6 -9
  12. package/dist/browser/client/urlHelpers.js.map +1 -1
  13. package/dist/browser/fetchHttpClient.js +30 -21
  14. package/dist/browser/fetchHttpClient.js.map +1 -1
  15. package/dist/browser/httpHeaders.js +2 -2
  16. package/dist/browser/httpHeaders.js.map +1 -1
  17. package/dist/browser/nodeHttpClient.js +27 -21
  18. package/dist/browser/nodeHttpClient.js.map +1 -1
  19. package/dist/browser/pipeline.js +3 -3
  20. package/dist/browser/pipeline.js.map +1 -1
  21. package/dist/browser/pipelineRequest.js +26 -8
  22. package/dist/browser/pipelineRequest.js.map +1 -1
  23. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
  24. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
  25. package/dist/browser/policies/auth/basicAuthenticationPolicy.js +1 -2
  26. package/dist/browser/policies/auth/basicAuthenticationPolicy.js.map +1 -1
  27. package/dist/browser/policies/auth/bearerAuthenticationPolicy.js +1 -2
  28. package/dist/browser/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
  29. package/dist/browser/policies/auth/checkInsecureConnection.js +1 -1
  30. package/dist/browser/policies/auth/checkInsecureConnection.js.map +1 -1
  31. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js +1 -2
  32. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
  33. package/dist/browser/policies/defaultRetryPolicy.js +1 -2
  34. package/dist/browser/policies/defaultRetryPolicy.js.map +1 -1
  35. package/dist/browser/policies/exponentialRetryPolicy.js +5 -3
  36. package/dist/browser/policies/exponentialRetryPolicy.js.map +1 -1
  37. package/dist/browser/policies/formDataPolicy.js +2 -3
  38. package/dist/browser/policies/formDataPolicy.js.map +1 -1
  39. package/dist/browser/policies/logPolicy.js +1 -2
  40. package/dist/browser/policies/logPolicy.js.map +1 -1
  41. package/dist/browser/policies/multipartPolicy.js +2 -3
  42. package/dist/browser/policies/multipartPolicy.js.map +1 -1
  43. package/dist/browser/policies/retryPolicy.js +2 -3
  44. package/dist/browser/policies/retryPolicy.js.map +1 -1
  45. package/dist/browser/policies/systemErrorRetryPolicy.js +5 -3
  46. package/dist/browser/policies/systemErrorRetryPolicy.js.map +1 -1
  47. package/dist/browser/policies/throttlingRetryPolicy.js +1 -2
  48. package/dist/browser/policies/throttlingRetryPolicy.js.map +1 -1
  49. package/dist/browser/restError.js +38 -12
  50. package/dist/browser/restError.js.map +1 -1
  51. package/dist/browser/retryStrategies/exponentialRetryStrategy.js +2 -3
  52. package/dist/browser/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  53. package/dist/browser/retryStrategies/throttlingRetryStrategy.js +1 -1
  54. package/dist/browser/retryStrategies/throttlingRetryStrategy.js.map +1 -1
  55. package/dist/browser/util/checkEnvironment.js +6 -7
  56. package/dist/browser/util/checkEnvironment.js.map +1 -1
  57. package/dist/browser/util/helpers.js +4 -4
  58. package/dist/browser/util/helpers.js.map +1 -1
  59. package/dist/browser/util/sanitizer.js +7 -1
  60. package/dist/browser/util/sanitizer.js.map +1 -1
  61. package/dist/browser/util/userAgentPlatform-browser.mjs.map +1 -1
  62. package/dist/browser/util/userAgentPlatform.js +2 -2
  63. package/dist/browser/util/uuidUtils-browser.mjs.map +1 -1
  64. package/dist/browser/util/uuidUtils.js +1 -2
  65. package/dist/browser/xhrHttpClient.js +3 -5
  66. package/dist/browser/xhrHttpClient.js.map +1 -1
  67. package/dist/commonjs/client/getClient.js +8 -10
  68. package/dist/commonjs/client/getClient.js.map +1 -1
  69. package/dist/commonjs/client/multipart.js +2 -4
  70. package/dist/commonjs/client/multipart.js.map +1 -1
  71. package/dist/commonjs/client/operationOptionHelpers.js +6 -7
  72. package/dist/commonjs/client/operationOptionHelpers.js.map +1 -1
  73. package/dist/commonjs/client/restError.js +4 -6
  74. package/dist/commonjs/client/restError.js.map +1 -1
  75. package/dist/commonjs/client/sendRequest.js +20 -19
  76. package/dist/commonjs/client/sendRequest.js.map +1 -1
  77. package/dist/commonjs/client/urlHelpers.js +6 -9
  78. package/dist/commonjs/client/urlHelpers.js.map +1 -1
  79. package/dist/commonjs/fetchHttpClient.js +30 -21
  80. package/dist/commonjs/fetchHttpClient.js.map +1 -1
  81. package/dist/commonjs/httpHeaders.js +2 -2
  82. package/dist/commonjs/httpHeaders.js.map +1 -1
  83. package/dist/commonjs/nodeHttpClient.js +27 -21
  84. package/dist/commonjs/nodeHttpClient.js.map +1 -1
  85. package/dist/commonjs/pipeline.js +3 -3
  86. package/dist/commonjs/pipeline.js.map +1 -1
  87. package/dist/commonjs/pipelineRequest.js +26 -8
  88. package/dist/commonjs/pipelineRequest.js.map +1 -1
  89. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
  90. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
  91. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +1 -2
  92. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +1 -1
  93. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +1 -2
  94. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
  95. package/dist/commonjs/policies/auth/checkInsecureConnection.js +1 -1
  96. package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +1 -1
  97. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +1 -2
  98. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
  99. package/dist/commonjs/policies/defaultRetryPolicy.js +1 -2
  100. package/dist/commonjs/policies/defaultRetryPolicy.js.map +1 -1
  101. package/dist/commonjs/policies/exponentialRetryPolicy.js +5 -3
  102. package/dist/commonjs/policies/exponentialRetryPolicy.js.map +1 -1
  103. package/dist/commonjs/policies/formDataPolicy.js +2 -3
  104. package/dist/commonjs/policies/formDataPolicy.js.map +1 -1
  105. package/dist/commonjs/policies/logPolicy.js +1 -2
  106. package/dist/commonjs/policies/logPolicy.js.map +1 -1
  107. package/dist/commonjs/policies/multipartPolicy.js +2 -3
  108. package/dist/commonjs/policies/multipartPolicy.js.map +1 -1
  109. package/dist/commonjs/policies/proxyPolicy.js +4 -5
  110. package/dist/commonjs/policies/proxyPolicy.js.map +1 -1
  111. package/dist/commonjs/policies/retryPolicy.js +2 -3
  112. package/dist/commonjs/policies/retryPolicy.js.map +1 -1
  113. package/dist/commonjs/policies/systemErrorRetryPolicy.js +5 -3
  114. package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +1 -1
  115. package/dist/commonjs/policies/throttlingRetryPolicy.js +1 -2
  116. package/dist/commonjs/policies/throttlingRetryPolicy.js.map +1 -1
  117. package/dist/commonjs/restError.js +38 -12
  118. package/dist/commonjs/restError.js.map +1 -1
  119. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +2 -3
  120. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  121. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +1 -1
  122. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +1 -1
  123. package/dist/commonjs/tsdoc-metadata.json +11 -11
  124. package/dist/commonjs/util/checkEnvironment.js +6 -7
  125. package/dist/commonjs/util/checkEnvironment.js.map +1 -1
  126. package/dist/commonjs/util/concat.js +17 -35
  127. package/dist/commonjs/util/concat.js.map +1 -1
  128. package/dist/commonjs/util/helpers.js +4 -4
  129. package/dist/commonjs/util/helpers.js.map +1 -1
  130. package/dist/commonjs/util/sanitizer.js +7 -1
  131. package/dist/commonjs/util/sanitizer.js.map +1 -1
  132. package/dist/commonjs/util/uuidUtils.js +1 -2
  133. package/dist/commonjs/util/uuidUtils.js.map +1 -1
  134. package/dist/commonjs/xhrHttpClient.js +3 -5
  135. package/dist/commonjs/xhrHttpClient.js.map +1 -1
  136. package/dist/esm/client/getClient.js +8 -10
  137. package/dist/esm/client/getClient.js.map +1 -1
  138. package/dist/esm/client/multipart.js +2 -4
  139. package/dist/esm/client/multipart.js.map +1 -1
  140. package/dist/esm/client/operationOptionHelpers.js +6 -7
  141. package/dist/esm/client/operationOptionHelpers.js.map +1 -1
  142. package/dist/esm/client/restError.js +4 -6
  143. package/dist/esm/client/restError.js.map +1 -1
  144. package/dist/esm/client/sendRequest.js +20 -19
  145. package/dist/esm/client/sendRequest.js.map +1 -1
  146. package/dist/esm/client/urlHelpers.js +6 -9
  147. package/dist/esm/client/urlHelpers.js.map +1 -1
  148. package/dist/esm/fetchHttpClient.js +30 -21
  149. package/dist/esm/fetchHttpClient.js.map +1 -1
  150. package/dist/esm/httpHeaders.js +2 -2
  151. package/dist/esm/httpHeaders.js.map +1 -1
  152. package/dist/esm/nodeHttpClient.js +27 -21
  153. package/dist/esm/nodeHttpClient.js.map +1 -1
  154. package/dist/esm/pipeline.js +3 -3
  155. package/dist/esm/pipeline.js.map +1 -1
  156. package/dist/esm/pipelineRequest.js +26 -8
  157. package/dist/esm/pipelineRequest.js.map +1 -1
  158. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
  159. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
  160. package/dist/esm/policies/auth/basicAuthenticationPolicy.js +1 -2
  161. package/dist/esm/policies/auth/basicAuthenticationPolicy.js.map +1 -1
  162. package/dist/esm/policies/auth/bearerAuthenticationPolicy.js +1 -2
  163. package/dist/esm/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
  164. package/dist/esm/policies/auth/checkInsecureConnection.js +1 -1
  165. package/dist/esm/policies/auth/checkInsecureConnection.js.map +1 -1
  166. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js +1 -2
  167. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
  168. package/dist/esm/policies/defaultRetryPolicy.js +1 -2
  169. package/dist/esm/policies/defaultRetryPolicy.js.map +1 -1
  170. package/dist/esm/policies/exponentialRetryPolicy.js +5 -3
  171. package/dist/esm/policies/exponentialRetryPolicy.js.map +1 -1
  172. package/dist/esm/policies/formDataPolicy.js +2 -3
  173. package/dist/esm/policies/formDataPolicy.js.map +1 -1
  174. package/dist/esm/policies/logPolicy.js +1 -2
  175. package/dist/esm/policies/logPolicy.js.map +1 -1
  176. package/dist/esm/policies/multipartPolicy.js +2 -3
  177. package/dist/esm/policies/multipartPolicy.js.map +1 -1
  178. package/dist/esm/policies/proxyPolicy.js +4 -5
  179. package/dist/esm/policies/proxyPolicy.js.map +1 -1
  180. package/dist/esm/policies/retryPolicy.js +2 -3
  181. package/dist/esm/policies/retryPolicy.js.map +1 -1
  182. package/dist/esm/policies/systemErrorRetryPolicy.js +5 -3
  183. package/dist/esm/policies/systemErrorRetryPolicy.js.map +1 -1
  184. package/dist/esm/policies/throttlingRetryPolicy.js +1 -2
  185. package/dist/esm/policies/throttlingRetryPolicy.js.map +1 -1
  186. package/dist/esm/restError.js +38 -12
  187. package/dist/esm/restError.js.map +1 -1
  188. package/dist/esm/retryStrategies/exponentialRetryStrategy.js +2 -3
  189. package/dist/esm/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  190. package/dist/esm/retryStrategies/throttlingRetryStrategy.js +1 -1
  191. package/dist/esm/retryStrategies/throttlingRetryStrategy.js.map +1 -1
  192. package/dist/esm/util/checkEnvironment.js +6 -7
  193. package/dist/esm/util/checkEnvironment.js.map +1 -1
  194. package/dist/esm/util/concat.js +17 -35
  195. package/dist/esm/util/concat.js.map +1 -1
  196. package/dist/esm/util/helpers.js +4 -4
  197. package/dist/esm/util/helpers.js.map +1 -1
  198. package/dist/esm/util/sanitizer.js +7 -1
  199. package/dist/esm/util/sanitizer.js.map +1 -1
  200. package/dist/esm/util/uuidUtils.js +1 -2
  201. package/dist/esm/util/uuidUtils.js.map +1 -1
  202. package/dist/esm/xhrHttpClient.js +3 -5
  203. package/dist/esm/xhrHttpClient.js.map +1 -1
  204. package/dist/react-native/client/getClient.js +8 -10
  205. package/dist/react-native/client/getClient.js.map +1 -1
  206. package/dist/react-native/client/multipart.js +2 -4
  207. package/dist/react-native/client/multipart.js.map +1 -1
  208. package/dist/react-native/client/operationOptionHelpers.js +6 -7
  209. package/dist/react-native/client/operationOptionHelpers.js.map +1 -1
  210. package/dist/react-native/client/restError.js +4 -6
  211. package/dist/react-native/client/restError.js.map +1 -1
  212. package/dist/react-native/client/sendRequest.js +20 -19
  213. package/dist/react-native/client/sendRequest.js.map +1 -1
  214. package/dist/react-native/client/urlHelpers.js +6 -9
  215. package/dist/react-native/client/urlHelpers.js.map +1 -1
  216. package/dist/react-native/fetchHttpClient.js +30 -21
  217. package/dist/react-native/fetchHttpClient.js.map +1 -1
  218. package/dist/react-native/httpHeaders.js +2 -2
  219. package/dist/react-native/httpHeaders.js.map +1 -1
  220. package/dist/react-native/nodeHttpClient.js +27 -21
  221. package/dist/react-native/nodeHttpClient.js.map +1 -1
  222. package/dist/react-native/pipeline.js +3 -3
  223. package/dist/react-native/pipeline.js.map +1 -1
  224. package/dist/react-native/pipelineRequest.js +26 -8
  225. package/dist/react-native/pipelineRequest.js.map +1 -1
  226. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js +1 -2
  227. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -1
  228. package/dist/react-native/policies/auth/basicAuthenticationPolicy.js +1 -2
  229. package/dist/react-native/policies/auth/basicAuthenticationPolicy.js.map +1 -1
  230. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js +1 -2
  231. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js.map +1 -1
  232. package/dist/react-native/policies/auth/checkInsecureConnection.js +1 -1
  233. package/dist/react-native/policies/auth/checkInsecureConnection.js.map +1 -1
  234. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js +1 -2
  235. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js.map +1 -1
  236. package/dist/react-native/policies/defaultRetryPolicy.js +1 -2
  237. package/dist/react-native/policies/defaultRetryPolicy.js.map +1 -1
  238. package/dist/react-native/policies/exponentialRetryPolicy.js +5 -3
  239. package/dist/react-native/policies/exponentialRetryPolicy.js.map +1 -1
  240. package/dist/react-native/policies/formDataPolicy.js +2 -3
  241. package/dist/react-native/policies/formDataPolicy.js.map +1 -1
  242. package/dist/react-native/policies/logPolicy.js +1 -2
  243. package/dist/react-native/policies/logPolicy.js.map +1 -1
  244. package/dist/react-native/policies/multipartPolicy.js +2 -3
  245. package/dist/react-native/policies/multipartPolicy.js.map +1 -1
  246. package/dist/react-native/policies/retryPolicy.js +2 -3
  247. package/dist/react-native/policies/retryPolicy.js.map +1 -1
  248. package/dist/react-native/policies/systemErrorRetryPolicy.js +5 -3
  249. package/dist/react-native/policies/systemErrorRetryPolicy.js.map +1 -1
  250. package/dist/react-native/policies/throttlingRetryPolicy.js +1 -2
  251. package/dist/react-native/policies/throttlingRetryPolicy.js.map +1 -1
  252. package/dist/react-native/restError.js +38 -12
  253. package/dist/react-native/restError.js.map +1 -1
  254. package/dist/react-native/retryStrategies/exponentialRetryStrategy.js +2 -3
  255. package/dist/react-native/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  256. package/dist/react-native/retryStrategies/throttlingRetryStrategy.js +1 -1
  257. package/dist/react-native/retryStrategies/throttlingRetryStrategy.js.map +1 -1
  258. package/dist/react-native/util/checkEnvironment.js +6 -7
  259. package/dist/react-native/util/checkEnvironment.js.map +1 -1
  260. package/dist/react-native/util/helpers.js +4 -4
  261. package/dist/react-native/util/helpers.js.map +1 -1
  262. package/dist/react-native/util/sanitizer.js +7 -1
  263. package/dist/react-native/util/sanitizer.js.map +1 -1
  264. package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +1 -1
  265. package/dist/react-native/util/userAgentPlatform.js +1 -2
  266. package/dist/react-native/xhrHttpClient.js +3 -5
  267. package/dist/react-native/xhrHttpClient.js.map +1 -1
  268. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"xhrHttpClient.js","sourceRoot":"","sources":["../../src/xhrHttpClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAQ9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;;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,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACx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,CAAC,kBAAkB;QAClC,OAAO;KACR,CAAC,CACH,CACF,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,UAAU,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,MAAM,UAAU,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\";\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 xhr.send(body === undefined ? null : body);\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
+ {"version":3,"file":"xhrHttpClient.js","sourceRoot":"","sources":["../../src/xhrHttpClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAQ9D,OA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W,GAAG,GAAG;SACpB,qBAAqB,EAAE;SACvB,IAAI,EAAE;SACN,KAAK,CAAC,SAAS,CAAC,CAAC;IACpB,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;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,SAAS,CAAC,6BAA6B,OAAO,CAAC,GAAG,EAAE,EAAE;QACxD,IAAI,EAAE,SAAS,CAAC,kBAAkB;QAClC,OAAO;KACR,CAAC,CACH,CACF,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,UAAU,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,MAAM,UAAU,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\";\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 xhr.send(body === undefined ? null : body);\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"]}
@@ -14,9 +14,8 @@ const checkEnvironment_js_1 = require("../util/checkEnvironment.js");
14
14
  * @param options - Client options
15
15
  */
16
16
  function getClient(endpoint, clientOptions = {}) {
17
- var _a, _b, _c;
18
- const pipeline = (_a = clientOptions.pipeline) !== null && _a !== void 0 ? _a : (0, clientHelpers_js_1.createDefaultPipeline)(clientOptions);
19
- if ((_b = clientOptions.additionalPolicies) === null || _b === void 0 ? void 0 : _b.length) {
17
+ const pipeline = clientOptions.pipeline ?? (0, clientHelpers_js_1.createDefaultPipeline)(clientOptions);
18
+ if (clientOptions.additionalPolicies?.length) {
20
19
  for (const { policy, position } of clientOptions.additionalPolicies) {
21
20
  // Sign happens after Retry and is commonly needed to occur
22
21
  // before policies that intercept post-retry.
@@ -27,9 +26,9 @@ function getClient(endpoint, clientOptions = {}) {
27
26
  }
28
27
  }
29
28
  const { allowInsecureConnection, httpClient } = clientOptions;
30
- const endpointUrl = (_c = clientOptions.endpoint) !== null && _c !== void 0 ? _c : endpoint;
29
+ const endpointUrl = clientOptions.endpoint ?? endpoint;
31
30
  const client = (path, ...args) => {
32
- const getUrl = (requestOptions) => (0, urlHelpers_js_1.buildRequestUrl)(endpointUrl, path, args, Object.assign({ allowInsecureConnection }, requestOptions));
31
+ const getUrl = (requestOptions) => (0, urlHelpers_js_1.buildRequestUrl)(endpointUrl, path, args, { allowInsecureConnection, ...requestOptions });
33
32
  return {
34
33
  get: (requestOptions = {}) => {
35
34
  return buildOperation("GET", getUrl(requestOptions), pipeline, requestOptions, allowInsecureConnection, httpClient);
@@ -64,23 +63,22 @@ function getClient(endpoint, clientOptions = {}) {
64
63
  };
65
64
  }
66
65
  function buildOperation(method, url, pipeline, options, allowInsecureConnection, httpClient) {
67
- var _a;
68
- allowInsecureConnection = (_a = options.allowInsecureConnection) !== null && _a !== void 0 ? _a : allowInsecureConnection;
66
+ allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection;
69
67
  return {
70
68
  then: function (onFulfilled, onrejected) {
71
- return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection }), httpClient).then(onFulfilled, onrejected);
69
+ return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, { ...options, allowInsecureConnection }, httpClient).then(onFulfilled, onrejected);
72
70
  },
73
71
  async asBrowserStream() {
74
72
  if (checkEnvironment_js_1.isNodeLike) {
75
73
  throw new Error("`asBrowserStream` is supported only in the browser environment. Use `asNodeStream` instead to obtain the response body stream. If you require a Web stream of the response in Node, consider using `Readable.toWeb` on the result of `asNodeStream`.");
76
74
  }
77
75
  else {
78
- return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection, responseAsStream: true }), httpClient);
76
+ return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, { ...options, allowInsecureConnection, responseAsStream: true }, httpClient);
79
77
  }
80
78
  },
81
79
  async asNodeStream() {
82
80
  if (checkEnvironment_js_1.isNodeLike) {
83
- return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, Object.assign(Object.assign({}, options), { allowInsecureConnection, responseAsStream: true }), httpClient);
81
+ return (0, sendRequest_js_1.sendRequest)(method, url, pipeline, { ...options, allowInsecureConnection, responseAsStream: true }, httpClient);
84
82
  }
85
83
  else {
86
84
  throw new Error("`isNodeStream` is not supported in the browser environment. Use `asBrowserStream` to obtain the response body stream.");
@@ -1 +1 @@
1
- {"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwBlC,8BA4GC;AAhID,yDAA2D;AAU3D,qDAA+C;AAC/C,mDAAkD;AAClD,qEAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,QAAgB,EAAE,gBAA+B,EAAE;;IAC3E,MAAM,QAAQ,GAAG,MAAA,aAAa,CAAC,QAAQ,mCAAI,IAAA,wCAAqB,EAAC,aAAa,CAAC,CAAC;IAChF,IAAI,MAAA,aAAa,CAAC,kBAAkB,0CAAE,MAAM,EAAE,CAAC;QAC7C,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,aAAa,CAAC,kBAAkB,EAAE,CAAC;YACpE,2DAA2D;YAC3D,6CAA6C;YAC7C,MAAM,UAAU,GAAG,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;YAChE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE;gBACzB,UAAU;aACX,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,EAAE,uBAAuB,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IAC9D,MAAM,WAAW,GAAG,MAAA,aAAa,CAAC,QAAQ,mCAAI,QAAQ,CAAC;IACvD,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,GAAG,IAAgB,EAAqC,EAAE;QACtF,MAAM,MAAM,GAAG,CAAC,cAAiC,EAAU,EAAE,CAC3D,IAAA,+BAAe,EAAC,WAAW,EAAE,IAAI,EAAE,IAAI,kBAAI,uBAAuB,IAAK,cAAc,EAAG,CAAC;QAE3F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YACvC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uHAAuH,CACxH,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, HttpMethods } from \"../interfaces.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport type {\n Client,\n ClientOptions,\n HttpBrowserStreamResponse,\n HttpNodeStreamResponse,\n RequestParameters,\n ResourceMethods,\n StreamableMethod,\n} from \"./common.js\";\nimport { sendRequest } from \"./sendRequest.js\";\nimport { buildRequestUrl } from \"./urlHelpers.js\";\nimport { isNodeLike } from \"../util/checkEnvironment.js\";\n\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param credentials - Credentials to authenticate the requests\n * @param options - Client options\n */\nexport function getClient(endpoint: string, clientOptions: ClientOptions = {}): Client {\n const pipeline = clientOptions.pipeline ?? createDefaultPipeline(clientOptions);\n if (clientOptions.additionalPolicies?.length) {\n for (const { policy, position } of clientOptions.additionalPolicies) {\n // Sign happens after Retry and is commonly needed to occur\n // before policies that intercept post-retry.\n const afterPhase = position === \"perRetry\" ? \"Sign\" : undefined;\n pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n\n const { allowInsecureConnection, httpClient } = clientOptions;\n const endpointUrl = clientOptions.endpoint ?? endpoint;\n const client = (path: string, ...args: Array<any>): ResourceMethods<StreamableMethod> => {\n const getUrl = (requestOptions: RequestParameters): string =>\n buildRequestUrl(endpointUrl, path, args, { allowInsecureConnection, ...requestOptions });\n\n return {\n get: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"GET\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n post: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"POST\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n put: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PUT\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n patch: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PATCH\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n delete: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"DELETE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n head: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"HEAD\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n options: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"OPTIONS\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n trace: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"TRACE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n };\n };\n\n return {\n path: client,\n pathUnchecked: client,\n pipeline,\n };\n}\n\nfunction buildOperation(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: RequestParameters,\n allowInsecureConnection?: boolean,\n httpClient?: HttpClient,\n): StreamableMethod {\n allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection;\n return {\n then: function (onFulfilled, onrejected) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection },\n httpClient,\n ).then(onFulfilled, onrejected);\n },\n async asBrowserStream() {\n if (isNodeLike) {\n throw new Error(\n \"`asBrowserStream` is supported only in the browser environment. Use `asNodeStream` instead to obtain the response body stream. If you require a Web stream of the response in Node, consider using `Readable.toWeb` on the result of `asNodeStream`.\",\n );\n } else {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpBrowserStreamResponse>;\n }\n },\n async asNodeStream() {\n if (isNodeLike) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpNodeStreamResponse>;\n } else {\n throw new Error(\n \"`isNodeStream` is not supported in the browser environment. Use `asBrowserStream` to obtain the response body stream.\",\n );\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"getClient.js","sourceRoot":"","sources":["../../../src/client/getClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwBlC,8BA4GC;AAhID,yDAA2D;AAU3D,qDAA+C;AAC/C,mDAAkD;AAClD,qEAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,QAAgB,EAAE,gBAA+B,EAAE;IAC3E,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,IAAI,IAAA,wCAAqB,EAAC,aAAa,CAAC,CAAC;IAChF,IAAI,aAAa,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC;QAC7C,KAAK,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,aAAa,CAAC,kBAAkB,EAAE,CAAC;YACpE,2DAA2D;YAC3D,6CAA6C;YAC7C,MAAM,UAAU,GAAG,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;YAChE,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE;gBACzB,UAAU;aACX,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,EAAE,uBAAuB,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC;IAC9D,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,IAAI,QAAQ,CAAC;IACvD,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE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AAC;YAC1C,CAAC;QACH,CAAC;QACD,KAAK,CAAC,YAAY;YAChB,IAAI,gCAAU,EAAE,CAAC;gBACf,OAAO,IAAA,4BAAW,EAChB,MAAM,EACN,GAAG,EACH,QAAQ,EACR,EAAE,GAAG,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAC/D,UAAU,CACwB,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CACb,uHAAuH,CACxH,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, HttpMethods } from \"../interfaces.js\";\nimport type { Pipeline } from \"../pipeline.js\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport type {\n Client,\n ClientOptions,\n HttpBrowserStreamResponse,\n HttpNodeStreamResponse,\n RequestParameters,\n ResourceMethods,\n StreamableMethod,\n} from \"./common.js\";\nimport { sendRequest } from \"./sendRequest.js\";\nimport { buildRequestUrl } from \"./urlHelpers.js\";\nimport { isNodeLike } from \"../util/checkEnvironment.js\";\n\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param credentials - Credentials to authenticate the requests\n * @param options - Client options\n */\nexport function getClient(endpoint: string, clientOptions: ClientOptions = {}): Client {\n const pipeline = clientOptions.pipeline ?? createDefaultPipeline(clientOptions);\n if (clientOptions.additionalPolicies?.length) {\n for (const { policy, position } of clientOptions.additionalPolicies) {\n // Sign happens after Retry and is commonly needed to occur\n // before policies that intercept post-retry.\n const afterPhase = position === \"perRetry\" ? \"Sign\" : undefined;\n pipeline.addPolicy(policy, {\n afterPhase,\n });\n }\n }\n\n const { allowInsecureConnection, httpClient } = clientOptions;\n const endpointUrl = clientOptions.endpoint ?? endpoint;\n const client = (path: string, ...args: Array<any>): ResourceMethods<StreamableMethod> => {\n const getUrl = (requestOptions: RequestParameters): string =>\n buildRequestUrl(endpointUrl, path, args, { allowInsecureConnection, ...requestOptions });\n\n return {\n get: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"GET\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n post: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"POST\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n put: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PUT\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n patch: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"PATCH\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n delete: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"DELETE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n head: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"HEAD\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n options: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"OPTIONS\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n trace: (requestOptions: RequestParameters = {}): StreamableMethod => {\n return buildOperation(\n \"TRACE\",\n getUrl(requestOptions),\n pipeline,\n requestOptions,\n allowInsecureConnection,\n httpClient,\n );\n },\n };\n };\n\n return {\n path: client,\n pathUnchecked: client,\n pipeline,\n };\n}\n\nfunction buildOperation(\n method: HttpMethods,\n url: string,\n pipeline: Pipeline,\n options: RequestParameters,\n allowInsecureConnection?: boolean,\n httpClient?: HttpClient,\n): StreamableMethod {\n allowInsecureConnection = options.allowInsecureConnection ?? allowInsecureConnection;\n return {\n then: function (onFulfilled, onrejected) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection },\n httpClient,\n ).then(onFulfilled, onrejected);\n },\n async asBrowserStream() {\n if (isNodeLike) {\n throw new Error(\n \"`asBrowserStream` is supported only in the browser environment. Use `asNodeStream` instead to obtain the response body stream. If you require a Web stream of the response in Node, consider using `Readable.toWeb` on the result of `asNodeStream`.\",\n );\n } else {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpBrowserStreamResponse>;\n }\n },\n async asNodeStream() {\n if (isNodeLike) {\n return sendRequest(\n method,\n url,\n pipeline,\n { ...options, allowInsecureConnection, responseAsStream: true },\n httpClient,\n ) as Promise<HttpNodeStreamResponse>;\n } else {\n throw new Error(\n \"`isNodeStream` is not supported in the browser environment. Use `asBrowserStream` to obtain the response body stream.\",\n );\n }\n },\n };\n}\n"]}
@@ -55,7 +55,6 @@ function escapeDispositionField(value) {
55
55
  return JSON.stringify(value);
56
56
  }
57
57
  function getContentDisposition(descriptor) {
58
- var _a;
59
58
  const contentDispositionHeader = getHeaderValue(descriptor, "content-disposition");
60
59
  if (contentDispositionHeader) {
61
60
  return contentDispositionHeader;
@@ -65,7 +64,7 @@ function getContentDisposition(descriptor) {
65
64
  descriptor.filename === undefined) {
66
65
  return undefined;
67
66
  }
68
- const dispositionType = (_a = descriptor.dispositionType) !== null && _a !== void 0 ? _a : "form-data";
67
+ const dispositionType = descriptor.dispositionType ?? "form-data";
69
68
  let disposition = dispositionType;
70
69
  if (descriptor.name) {
71
70
  disposition += `; name=${escapeDispositionField(descriptor.name)}`;
@@ -104,10 +103,9 @@ function normalizeBody(body, contentType) {
104
103
  throw new restError_js_1.RestError(`Unsupported body/content-type combination: ${body}, ${contentType}`);
105
104
  }
106
105
  function buildBodyPart(descriptor) {
107
- var _a;
108
106
  const contentType = getPartContentType(descriptor);
109
107
  const contentDisposition = getContentDisposition(descriptor);
110
- const headers = (0, httpHeaders_js_1.createHttpHeaders)((_a = descriptor.headers) !== null && _a !== void 0 ? _a : {});
108
+ const headers = (0, httpHeaders_js_1.createHttpHeaders)(descriptor.headers ?? {});
111
109
  if (contentType) {
112
110
  headers.set("content-type", contentType);
113
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/client/multipart.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAgLlC,sCAkBC;AAED,gDAEC;AAnMD,kDAA4C;AAC5C,sDAAsD;AACtD,+DAA8D;AAC9D,yDAAqD;AAkDrD;;GAEG;AACH,SAAS,cAAc,CAAC,UAA0B,EAAE,UAAkB;IACpE,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAC3D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,WAAW,EAAE,CACpD,CAAC;QACF,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,kBAAkB,CAAC,UAA0B;IACpD,MAAM,iBAAiB,GAAG,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,4DAA4D;IAC5D,IAAI,UAAU,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,EAAE,CAAC;QAC3B,OAAO,UAAU,CAAC,WAAW,CAAC;IAChC,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,UA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,CAAC,CAAC;AAC5F,CAAC;AAED,SAAgB,aAAa,CAAC,UAA0B;;IACtD,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACnD,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAA,kCAAiB,EAAC,MAAA,UAAU,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAuB;IACxD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BodyPart, MultipartRequestBody, RawHttpHeadersInput } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { stringToUint8Array } from \"../util/bytesEncoding.js\";\nimport { isBinaryBody } from \"../util/typeGuards.js\";\n\n/**\n * Describes a single part in a multipart body.\n */\nexport interface PartDescriptor {\n /**\n * Content type of this part. If set, this value will be used to set the Content-Type MIME header for this part, although explicitly\n * setting the Content-Type header in the headers bag will override this value. If set to `null`, no content type will be inferred from\n * the body field. Otherwise, the value of the Content-Type MIME header will be inferred based on the type of the body.\n */\n contentType?: string | null;\n\n /**\n * The disposition type of this part (for example, \"form-data\" for parts making up a multipart/form-data request). If set, this value\n * will be used to set the Content-Disposition MIME header for this part, in addition to the `name` and `filename` properties.\n * If the `name` or `filename` properties are set while `dispositionType` is left undefined, `dispositionType` will default to \"form-data\".\n *\n * Explicitly setting the Content-Disposition header in the headers bag will override this value.\n */\n dispositionType?: string;\n\n /**\n * The field name associated with this part. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `filename` properties, if the header has not been set in the `headers` bag.\n */\n name?: string;\n\n /**\n * The file name of the content if it is a file. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `name` properties, if the header has not been set in the `headers` bag.\n */\n filename?: string;\n\n /**\n * The multipart headers for this part of the multipart body. Values of the Content-Type and Content-Disposition headers set in the headers bag\n * will take precedence over those computed from the request body or the contentType, dispositionType, name, and filename fields on this object.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The body of this part of the multipart request.\n */\n body?: unknown;\n}\n\ntype MultipartBodyType = BodyPart[\"body\"];\n\ntype HeaderValue = RawHttpHeadersInput[string];\n\n/**\n * Get value of a header in the part descriptor ignoring case\n */\nfunction getHeaderValue(descriptor: PartDescriptor, headerName: string): HeaderValue | undefined {\n if (descriptor.headers) {\n const actualHeaderName = Object.keys(descriptor.headers).find(\n (x) => x.toLowerCase() === headerName.toLowerCase(),\n );\n if (actualHeaderName) {\n return descriptor.headers[actualHeaderName];\n }\n }\n\n return undefined;\n}\n\nfunction getPartContentType(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentTypeHeader = getHeaderValue(descriptor, \"content-type\");\n if (contentTypeHeader) {\n return contentTypeHeader;\n }\n\n // Special value of null means content type is to be omitted\n if (descriptor.contentType === null) {\n return undefined;\n }\n\n if (descriptor.contentType) {\n return descriptor.contentType;\n }\n\n const { body } = descriptor;\n\n if (body === null || body === undefined) {\n return undefined;\n }\n\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return \"text/plain; charset=UTF-8\";\n }\n\n if (body instanceof Blob) {\n return body.type || \"application/octet-stream\";\n }\n\n if (isBinaryBody(body)) {\n return \"application/octet-stream\";\n }\n\n // arbitrary non-text object -> generic JSON content type by default. We will try to JSON.stringify the body.\n return \"application/json\";\n}\n\n/**\n * Enclose value in quotes and escape special characters, for use in the Content-Disposition header\n */\nfunction escapeDispositionField(value: string): string {\n return JSON.stringify(value);\n}\n\nfunction getContentDisposition(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentDispositionHeader = getHeaderValue(descriptor, \"content-disposition\");\n if (contentDispositionHeader) {\n return contentDispositionHeader;\n }\n\n if (\n descriptor.dispositionType === undefined &&\n descriptor.name === undefined &&\n descriptor.filename === undefined\n ) {\n return undefined;\n }\n\n const dispositionType = descriptor.dispositionType ?? \"form-data\";\n\n let disposition = dispositionType;\n if (descriptor.name) {\n disposition += `; name=${escapeDispositionField(descriptor.name)}`;\n }\n\n let filename: string | undefined = undefined;\n if (descriptor.filename) {\n filename = descriptor.filename;\n } else if (typeof File !== \"undefined\" && descriptor.body instanceof File) {\n const filenameFromFile = (descriptor.body as File).name;\n if (filenameFromFile !== \"\") {\n filename = filenameFromFile;\n }\n }\n\n if (filename) {\n disposition += `; filename=${escapeDispositionField(filename)}`;\n }\n\n return disposition;\n}\n\nfunction normalizeBody(body?: unknown, contentType?: HeaderValue): MultipartBodyType {\n if (body === undefined) {\n // zero-length body\n return new Uint8Array([]);\n }\n\n // binary and primitives should go straight on the wire regardless of content type\n if (isBinaryBody(body)) {\n return body;\n }\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return stringToUint8Array(String(body), \"utf-8\");\n }\n\n // stringify objects for JSON-ish content types e.g. application/json, application/merge-patch+json, application/vnd.oci.manifest.v1+json, application.json; charset=UTF-8\n if (contentType && /application\\/(.+\\+)?json(;.+)?/i.test(String(contentType))) {\n return stringToUint8Array(JSON.stringify(body), \"utf-8\");\n }\n\n throw new RestError(`Unsupported body/content-type combination: ${body}, ${contentType}`);\n}\n\nexport function buildBodyPart(descriptor: PartDescriptor): BodyPart {\n const contentType = getPartContentType(descriptor);\n const contentDisposition = getContentDisposition(descriptor);\n const headers = createHttpHeaders(descriptor.headers ?? {});\n\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n if (contentDisposition) {\n headers.set(\"content-disposition\", contentDisposition);\n }\n\n const body = normalizeBody(descriptor.body, contentType);\n\n return {\n headers,\n body,\n };\n}\n\nexport function buildMultipartBody(parts: PartDescriptor[]): MultipartRequestBody {\n return { parts: parts.map(buildBodyPart) };\n}\n"]}
1
+ {"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/client/multipart.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAgLlC,sCAkBC;AAED,gDAEC;AAnMD,kDAA4C;AAC5C,sDAAsD;AACtD,+DAA8D;AAC9D,yDAAqD;AAkDrD;;GAEG;AACH,SAAS,cAAc,CAAC,UAA0B,EAAE,UAAkB;IACpE,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAC3D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,WAAW,EAAE,CACpD,CAAC;QACF,IAAI,gBAAgB,EAAE,CAAC;YACrB,OAAO,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,kBAAkB,CAAC,UAA0B;IACpD,MAAM,iBAAiB,GAAG,cAAc,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IACrE,IAAI,iBAAiB,EAAE,CAAC;QACtB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,4DAA4D;IAC5D,IAAI,UAAU,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;QACpC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,UAAU,CA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,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,IAAI,wBAAS,CAAC,8CAA8C,IAAI,KAAK,WAAW,EAAE,CAAC,CAAC;AAC5F,CAAC;AAED,SAAgB,aAAa,CAAC,UAA0B;IACtD,MAAM,WAAW,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACnD,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAA,kCAAiB,EAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAE5D,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,kBAAkB,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IAEzD,OAAO;QACL,OAAO;QACP,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAuB;IACxD,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BodyPart, MultipartRequestBody, RawHttpHeadersInput } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport { stringToUint8Array } from \"../util/bytesEncoding.js\";\nimport { isBinaryBody } from \"../util/typeGuards.js\";\n\n/**\n * Describes a single part in a multipart body.\n */\nexport interface PartDescriptor {\n /**\n * Content type of this part. If set, this value will be used to set the Content-Type MIME header for this part, although explicitly\n * setting the Content-Type header in the headers bag will override this value. If set to `null`, no content type will be inferred from\n * the body field. Otherwise, the value of the Content-Type MIME header will be inferred based on the type of the body.\n */\n contentType?: string | null;\n\n /**\n * The disposition type of this part (for example, \"form-data\" for parts making up a multipart/form-data request). If set, this value\n * will be used to set the Content-Disposition MIME header for this part, in addition to the `name` and `filename` properties.\n * If the `name` or `filename` properties are set while `dispositionType` is left undefined, `dispositionType` will default to \"form-data\".\n *\n * Explicitly setting the Content-Disposition header in the headers bag will override this value.\n */\n dispositionType?: string;\n\n /**\n * The field name associated with this part. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `filename` properties, if the header has not been set in the `headers` bag.\n */\n name?: string;\n\n /**\n * The file name of the content if it is a file. This value will be used to construct the Content-Disposition header,\n * along with the `dispositionType` and `name` properties, if the header has not been set in the `headers` bag.\n */\n filename?: string;\n\n /**\n * The multipart headers for this part of the multipart body. Values of the Content-Type and Content-Disposition headers set in the headers bag\n * will take precedence over those computed from the request body or the contentType, dispositionType, name, and filename fields on this object.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The body of this part of the multipart request.\n */\n body?: unknown;\n}\n\ntype MultipartBodyType = BodyPart[\"body\"];\n\ntype HeaderValue = RawHttpHeadersInput[string];\n\n/**\n * Get value of a header in the part descriptor ignoring case\n */\nfunction getHeaderValue(descriptor: PartDescriptor, headerName: string): HeaderValue | undefined {\n if (descriptor.headers) {\n const actualHeaderName = Object.keys(descriptor.headers).find(\n (x) => x.toLowerCase() === headerName.toLowerCase(),\n );\n if (actualHeaderName) {\n return descriptor.headers[actualHeaderName];\n }\n }\n\n return undefined;\n}\n\nfunction getPartContentType(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentTypeHeader = getHeaderValue(descriptor, \"content-type\");\n if (contentTypeHeader) {\n return contentTypeHeader;\n }\n\n // Special value of null means content type is to be omitted\n if (descriptor.contentType === null) {\n return undefined;\n }\n\n if (descriptor.contentType) {\n return descriptor.contentType;\n }\n\n const { body } = descriptor;\n\n if (body === null || body === undefined) {\n return undefined;\n }\n\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return \"text/plain; charset=UTF-8\";\n }\n\n if (body instanceof Blob) {\n return body.type || \"application/octet-stream\";\n }\n\n if (isBinaryBody(body)) {\n return \"application/octet-stream\";\n }\n\n // arbitrary non-text object -> generic JSON content type by default. We will try to JSON.stringify the body.\n return \"application/json\";\n}\n\n/**\n * Enclose value in quotes and escape special characters, for use in the Content-Disposition header\n */\nfunction escapeDispositionField(value: string): string {\n return JSON.stringify(value);\n}\n\nfunction getContentDisposition(descriptor: PartDescriptor): HeaderValue | undefined {\n const contentDispositionHeader = getHeaderValue(descriptor, \"content-disposition\");\n if (contentDispositionHeader) {\n return contentDispositionHeader;\n }\n\n if (\n descriptor.dispositionType === undefined &&\n descriptor.name === undefined &&\n descriptor.filename === undefined\n ) {\n return undefined;\n }\n\n const dispositionType = descriptor.dispositionType ?? \"form-data\";\n\n let disposition = dispositionType;\n if (descriptor.name) {\n disposition += `; name=${escapeDispositionField(descriptor.name)}`;\n }\n\n let filename: string | undefined = undefined;\n if (descriptor.filename) {\n filename = descriptor.filename;\n } else if (typeof File !== \"undefined\" && descriptor.body instanceof File) {\n const filenameFromFile = (descriptor.body as File).name;\n if (filenameFromFile !== \"\") {\n filename = filenameFromFile;\n }\n }\n\n if (filename) {\n disposition += `; filename=${escapeDispositionField(filename)}`;\n }\n\n return disposition;\n}\n\nfunction normalizeBody(body?: unknown, contentType?: HeaderValue): MultipartBodyType {\n if (body === undefined) {\n // zero-length body\n return new Uint8Array([]);\n }\n\n // binary and primitives should go straight on the wire regardless of content type\n if (isBinaryBody(body)) {\n return body;\n }\n if (typeof body === \"string\" || typeof body === \"number\" || typeof body === \"boolean\") {\n return stringToUint8Array(String(body), \"utf-8\");\n }\n\n // stringify objects for JSON-ish content types e.g. application/json, application/merge-patch+json, application/vnd.oci.manifest.v1+json, application.json; charset=UTF-8\n if (contentType && /application\\/(.+\\+)?json(;.+)?/i.test(String(contentType))) {\n return stringToUint8Array(JSON.stringify(body), \"utf-8\");\n }\n\n throw new RestError(`Unsupported body/content-type combination: ${body}, ${contentType}`);\n}\n\nexport function buildBodyPart(descriptor: PartDescriptor): BodyPart {\n const contentType = getPartContentType(descriptor);\n const contentDisposition = getContentDisposition(descriptor);\n const headers = createHttpHeaders(descriptor.headers ?? {});\n\n if (contentType) {\n headers.set(\"content-type\", contentType);\n }\n if (contentDisposition) {\n headers.set(\"content-disposition\", contentDisposition);\n }\n\n const body = normalizeBody(descriptor.body, contentType);\n\n return {\n headers,\n body,\n };\n}\n\nexport function buildMultipartBody(parts: PartDescriptor[]): MultipartRequestBody {\n return { parts: parts.map(buildBodyPart) };\n}\n"]}
@@ -9,15 +9,14 @@ exports.operationOptionsToRequestParameters = operationOptionsToRequestParameter
9
9
  * @returns the result of the conversion in RequestParameters of RLC layer
10
10
  */
11
11
  function operationOptionsToRequestParameters(options) {
12
- var _a, _b, _c, _d, _e, _f;
13
12
  return {
14
- allowInsecureConnection: (_a = options.requestOptions) === null || _a === void 0 ? void 0 : _a.allowInsecureConnection,
15
- timeout: (_b = options.requestOptions) === null || _b === void 0 ? void 0 : _b.timeout,
16
- skipUrlEncoding: (_c = options.requestOptions) === null || _c === void 0 ? void 0 : _c.skipUrlEncoding,
13
+ allowInsecureConnection: options.requestOptions?.allowInsecureConnection,
14
+ timeout: options.requestOptions?.timeout,
15
+ skipUrlEncoding: options.requestOptions?.skipUrlEncoding,
17
16
  abortSignal: options.abortSignal,
18
- onUploadProgress: (_d = options.requestOptions) === null || _d === void 0 ? void 0 : _d.onUploadProgress,
19
- onDownloadProgress: (_e = options.requestOptions) === null || _e === void 0 ? void 0 : _e.onDownloadProgress,
20
- headers: Object.assign({}, (_f = options.requestOptions) === null || _f === void 0 ? void 0 : _f.headers),
17
+ onUploadProgress: options.requestOptions?.onUploadProgress,
18
+ onDownloadProgress: options.requestOptions?.onDownloadProgress,
19
+ headers: { ...options.requestOptions?.headers },
21
20
  onResponse: options.onResponse,
22
21
  };
23
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"operationOptionHelpers.js","sourceRoot":"","sources":["../../../src/client/operationOptionHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AASlC,kFAWC;AAhBD;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,OAAyB;;IAC3E,OAAO;QACL,uBAAuB,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,uBAAuB;QACxE,OAAO,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,OAAO;QACxC,eAAe,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,eAAe;QACxD,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,gBAAgB,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,gBAAgB;QAC1D,kBAAkB,EAAE,MAAA,OAAO,CAAC,cAAc,0CAAE,kBAAkB;QAC9D,OAAO,oBAAO,MAAA,OAAO,CAAC,cAAc,0CAAE,OAAO,CAAE;QAC/C,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, RequestParameters } from \"./common.js\";\n\n/**\n * Helper function to convert OperationOptions to RequestParameters\n * @param options - the options that are used by Modular layer to send the request\n * @returns the result of the conversion in RequestParameters of RLC layer\n */\nexport function operationOptionsToRequestParameters(options: OperationOptions): RequestParameters {\n return {\n allowInsecureConnection: options.requestOptions?.allowInsecureConnection,\n timeout: options.requestOptions?.timeout,\n skipUrlEncoding: options.requestOptions?.skipUrlEncoding,\n abortSignal: options.abortSignal,\n onUploadProgress: options.requestOptions?.onUploadProgress,\n onDownloadProgress: options.requestOptions?.onDownloadProgress,\n headers: { ...options.requestOptions?.headers },\n onResponse: options.onResponse,\n };\n}\n"]}
1
+ {"version":3,"file":"operationOptionHelpers.js","sourceRoot":"","sources":["../../../src/client/operationOptionHelpers.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AASlC,kFAWC;AAhBD;;;;GAIG;AACH,SAAgB,mCAAmC,CAAC,OAAyB;IAC3E,OAAO;QACL,uBAAuB,EAAE,OAAO,CAAC,cAAc,EAAE,uBAAuB;QACxE,OAAO,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO;QACxC,eAAe,EAAE,OAAO,CAAC,cAAc,EAAE,eAAe;QACxD,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,gBAAgB,EAAE,OAAO,CAAC,cAAc,EAAE,gBAAgB;QAC1D,kBAAkB,EAAE,OAAO,CAAC,cAAc,EAAE,kBAAkB;QAC9D,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,OAAO,EAAE;QAC/C,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, RequestParameters } from \"./common.js\";\n\n/**\n * Helper function to convert OperationOptions to RequestParameters\n * @param options - the options that are used by Modular layer to send the request\n * @returns the result of the conversion in RequestParameters of RLC layer\n */\nexport function operationOptionsToRequestParameters(options: OperationOptions): RequestParameters {\n return {\n allowInsecureConnection: options.requestOptions?.allowInsecureConnection,\n timeout: options.requestOptions?.timeout,\n skipUrlEncoding: options.requestOptions?.skipUrlEncoding,\n abortSignal: options.abortSignal,\n onUploadProgress: options.requestOptions?.onUploadProgress,\n onDownloadProgress: options.requestOptions?.onDownloadProgress,\n headers: { ...options.requestOptions?.headers },\n onResponse: options.onResponse,\n };\n}\n"]}
@@ -6,25 +6,23 @@ exports.createRestError = createRestError;
6
6
  const restError_js_1 = require("../restError.js");
7
7
  const httpHeaders_js_1 = require("../httpHeaders.js");
8
8
  function createRestError(messageOrResponse, response) {
9
- var _a, _b, _c;
10
9
  const resp = typeof messageOrResponse === "string" ? response : messageOrResponse;
11
- const internalError = (_b = (_a = resp.body) === null || _a === void 0 ? void 0 : _a.error) !== null && _b !== void 0 ? _b : resp.body;
10
+ const internalError = resp.body?.error ?? resp.body;
12
11
  const message = typeof messageOrResponse === "string"
13
12
  ? messageOrResponse
14
- : ((_c = internalError === null || internalError === void 0 ? void 0 : internalError.message) !== null && _c !== void 0 ? _c : `Unexpected status code: ${resp.status}`);
13
+ : (internalError?.message ?? `Unexpected status code: ${resp.status}`);
15
14
  return new restError_js_1.RestError(message, {
16
15
  statusCode: statusCodeToNumber(resp.status),
17
- code: internalError === null || internalError === void 0 ? void 0 : internalError.code,
16
+ code: internalError?.code,
18
17
  request: resp.request,
19
18
  response: toPipelineResponse(resp),
20
19
  });
21
20
  }
22
21
  function toPipelineResponse(response) {
23
- var _a;
24
22
  return {
25
23
  headers: (0, httpHeaders_js_1.createHttpHeaders)(response.headers),
26
24
  request: response.request,
27
- status: (_a = statusCodeToNumber(response.status)) !== null && _a !== void 0 ? _a : -1,
25
+ status: statusCodeToNumber(response.status) ?? -1,
28
26
  };
29
27
  }
30
28
  function statusCodeToNumber(statusCode) {
@@ -1 +1 @@
1
- {"version":3,"file":"restError.js","sourceRoot":"","sources":["../../../src/client/restError.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAelC,0CAgBC;AA5BD,kDAA4C;AAC5C,sDAAsD;AAWtD,SAAgB,eAAe,CAC7B,iBAAiD,EACjD,QAAgC;;IAEhC,MAAM,IAAI,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACnF,MAAM,aAAa,GAAG,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,mCAAI,IAAI,CAAC,IAAI,CAAC;IACpD,MAAM,OAAO,GACX,OAAO,iBAAiB,KAAK,QAAQ;QACnC,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,CAAC,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,OAAO,mCAAI,2BAA2B,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3E,OAAO,IAAI,wBAAS,CAAC,OAAO,EAAE;QAC5B,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3C,IAAI,EAAE,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI;QACzB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACnC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA+B;;IACzD,OAAO;QACL,OAAO,EAAE,IAAA,kCAAiB,EAAC,QAAQ,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,MAAA,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,mCAAI,CAAC,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineResponse } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport type { PathUncheckedResponse } from \"./common.js\";\n\n/**\n * Creates a rest error from a PathUnchecked response\n */\nexport function createRestError(response: PathUncheckedResponse): RestError;\n/**\n * Creates a rest error from an error message and a PathUnchecked response\n */\nexport function createRestError(message: string, response: PathUncheckedResponse): RestError;\nexport function createRestError(\n messageOrResponse: string | PathUncheckedResponse,\n response?: PathUncheckedResponse,\n): RestError {\n const resp = typeof messageOrResponse === \"string\" ? response! : messageOrResponse;\n const internalError = resp.body?.error ?? resp.body;\n const message =\n typeof messageOrResponse === \"string\"\n ? messageOrResponse\n : (internalError?.message ?? `Unexpected status code: ${resp.status}`);\n return new RestError(message, {\n statusCode: statusCodeToNumber(resp.status),\n code: internalError?.code,\n request: resp.request,\n response: toPipelineResponse(resp),\n });\n}\n\nfunction toPipelineResponse(response: PathUncheckedResponse): PipelineResponse {\n return {\n headers: createHttpHeaders(response.headers),\n request: response.request,\n status: statusCodeToNumber(response.status) ?? -1,\n };\n}\n\nfunction statusCodeToNumber(statusCode: string): number | undefined {\n const status = Number.parseInt(statusCode);\n\n return Number.isNaN(status) ? undefined : status;\n}\n"]}
1
+ {"version":3,"file":"restError.js","sourceRoot":"","sources":["../../../src/client/restError.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAelC,0CAgBC;AA5BD,kDAA4C;AAC5C,sDAAsD;AAWtD,SAAgB,eAAe,CAC7B,iBAAiD,EACjD,QAAgC;IAEhC,MAAM,IAAI,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACnF,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC;IACpD,MAAM,OAAO,GACX,OAAO,iBAAiB,KAAK,QAAQ;QACnC,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,CAAC,aAAa,EAAE,OAAO,IAAI,2BAA2B,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC3E,OAAO,IAAI,wBAAS,CAAC,OAAO,EAAE;QAC5B,UAAU,EAAE,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3C,IAAI,EAAE,aAAa,EAAE,IAAI;QACzB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,QAAQ,EAAE,kBAAkB,CAAC,IAAI,CAAC;KACnC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,QAA+B;IACzD,OAAO;QACL,OAAO,EAAE,IAAA,kCAAiB,EAAC,QAAQ,CAAC,OAAO,CAAC;QAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineResponse } from \"../interfaces.js\";\nimport { RestError } from \"../restError.js\";\nimport { createHttpHeaders } from \"../httpHeaders.js\";\nimport type { PathUncheckedResponse } from \"./common.js\";\n\n/**\n * Creates a rest error from a PathUnchecked response\n */\nexport function createRestError(response: PathUncheckedResponse): RestError;\n/**\n * Creates a rest error from an error message and a PathUnchecked response\n */\nexport function createRestError(message: string, response: PathUncheckedResponse): RestError;\nexport function createRestError(\n messageOrResponse: string | PathUncheckedResponse,\n response?: PathUncheckedResponse,\n): RestError {\n const resp = typeof messageOrResponse === \"string\" ? response! : messageOrResponse;\n const internalError = resp.body?.error ?? resp.body;\n const message =\n typeof messageOrResponse === \"string\"\n ? messageOrResponse\n : (internalError?.message ?? `Unexpected status code: ${resp.status}`);\n return new RestError(message, {\n statusCode: statusCodeToNumber(resp.status),\n code: internalError?.code,\n request: resp.request,\n response: toPipelineResponse(resp),\n });\n}\n\nfunction toPipelineResponse(response: PathUncheckedResponse): PipelineResponse {\n return {\n headers: createHttpHeaders(response.headers),\n request: response.request,\n status: statusCodeToNumber(response.status) ?? -1,\n };\n}\n\nfunction statusCodeToNumber(statusCode: string): number | undefined {\n const status = Number.parseInt(statusCode);\n\n return Number.isNaN(status) ? undefined : status;\n}\n"]}
@@ -19,17 +19,16 @@ const multipart_js_1 = require("./multipart.js");
19
19
  * @returns returns and HttpResponse
20
20
  */
21
21
  async function sendRequest(method, url, pipeline, options = {}, customHttpClient) {
22
- var _a;
23
- const httpClient = customHttpClient !== null && customHttpClient !== void 0 ? customHttpClient : (0, clientHelpers_js_1.getCachedDefaultHttpsClient)();
22
+ const httpClient = customHttpClient ?? (0, clientHelpers_js_1.getCachedDefaultHttpsClient)();
24
23
  const request = buildPipelineRequest(method, url, options);
25
24
  try {
26
25
  const response = await pipeline.sendRequest(httpClient, request);
27
26
  const headers = response.headers.toJSON();
28
- const stream = (_a = response.readableStreamBody) !== null && _a !== void 0 ? _a : response.browserStreamBody;
27
+ const stream = response.readableStreamBody ?? response.browserStreamBody;
29
28
  const parsedBody = options.responseAsStream || stream !== undefined ? undefined : getResponseBody(response);
30
- const body = stream !== null && stream !== void 0 ? stream : parsedBody;
31
- if (options === null || options === void 0 ? void 0 : options.onResponse) {
32
- options.onResponse(Object.assign(Object.assign({}, response), { request, rawHeaders: headers, parsedBody }));
29
+ const body = stream ?? parsedBody;
30
+ if (options?.onResponse) {
31
+ options.onResponse({ ...response, request, rawHeaders: headers, parsedBody });
33
32
  }
34
33
  return {
35
34
  request,
@@ -43,7 +42,7 @@ async function sendRequest(method, url, pipeline, options = {}, customHttpClient
43
42
  const { response } = e;
44
43
  const rawHeaders = response.headers.toJSON();
45
44
  // UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError property
46
- options === null || options === void 0 ? void 0 : options.onResponse(Object.assign(Object.assign({}, response), { request, rawHeaders }), e);
45
+ options?.onResponse({ ...response, request, rawHeaders }, e);
47
46
  }
48
47
  throw e;
49
48
  }
@@ -54,8 +53,9 @@ async function sendRequest(method, url, pipeline, options = {}, customHttpClient
54
53
  * @returns returns the content-type
55
54
  */
56
55
  function getRequestContentType(options = {}) {
57
- var _a, _b, _c;
58
- return ((_c = (_a = options.contentType) !== null && _a !== void 0 ? _a : (_b = options.headers) === null || _b === void 0 ? void 0 : _b["content-type"]) !== null && _c !== void 0 ? _c : getContentType(options.body));
56
+ return (options.contentType ??
57
+ options.headers?.["content-type"] ??
58
+ getContentType(options.body));
59
59
  }
60
60
  /**
61
61
  * Function to determine the content-type of a body
@@ -81,14 +81,17 @@ function getContentType(body) {
81
81
  return "application/json";
82
82
  }
83
83
  function buildPipelineRequest(method, url, options = {}) {
84
- var _a, _b, _c;
85
84
  const requestContentType = getRequestContentType(options);
86
85
  const { body, multipartBody } = getRequestBody(options.body, requestContentType);
87
86
  const hasContent = body !== undefined || multipartBody !== undefined;
88
- const headers = (0, httpHeaders_js_1.createHttpHeaders)(Object.assign(Object.assign(Object.assign({}, (options.headers ? options.headers : {})), { accept: (_c = (_a = options.accept) !== null && _a !== void 0 ? _a : (_b = options.headers) === null || _b === void 0 ? void 0 : _b.accept) !== null && _c !== void 0 ? _c : "application/json" }), (hasContent &&
89
- requestContentType && {
90
- "content-type": requestContentType,
91
- })));
87
+ const headers = (0, httpHeaders_js_1.createHttpHeaders)({
88
+ ...(options.headers ? options.headers : {}),
89
+ accept: options.accept ?? options.headers?.accept ?? "application/json",
90
+ ...(hasContent &&
91
+ requestContentType && {
92
+ "content-type": requestContentType,
93
+ }),
94
+ });
92
95
  return (0, pipelineRequest_js_1.createPipelineRequest)({
93
96
  url,
94
97
  method,
@@ -144,11 +147,10 @@ function getRequestBody(body, contentType = "") {
144
147
  * Prepares the response body
145
148
  */
146
149
  function getResponseBody(response) {
147
- var _a, _b;
148
150
  // Set the default response type
149
- const contentType = (_a = response.headers.get("content-type")) !== null && _a !== void 0 ? _a : "";
151
+ const contentType = response.headers.get("content-type") ?? "";
150
152
  const firstType = contentType.split(";")[0];
151
- const bodyToParse = (_b = response.bodyAsText) !== null && _b !== void 0 ? _b : "";
153
+ const bodyToParse = response.bodyAsText ?? "";
152
154
  if (firstType === "text/plain") {
153
155
  return String(bodyToParse);
154
156
  }
@@ -168,9 +170,8 @@ function getResponseBody(response) {
168
170
  }
169
171
  }
170
172
  function createParseError(response, err) {
171
- var _a;
172
173
  const msg = `Error "${err}" occurred while parsing the response body - ${response.bodyAsText}.`;
173
- const errCode = (_a = err.code) !== null && _a !== void 0 ? _a : restError_js_1.RestError.PARSE_ERROR;
174
+ const errCode = err.code ?? restError_js_1.RestError.PARSE_ERROR;
174
175
  return new restError_js_1.RestError(msg, {
175
176
  code: errCode,
176
177
  statusCode: response.status,
@@ -1 +1 @@
1
- {"version":3,"file":"sendRequest.js","sourceRoot":"","sources":["../../../src/client/sendRequest.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA6BlC,kCAsCC;AAzDD,kDAAyD;AAEzD,sDAAsD;AACtD,8DAA8D;AAC9D,yDAAiE;AACjE,yDAAyD;AAGzD,iDAAoD;AAEpD;;;;;;;;GAQG;AACI,KAAK,UAAU,WAAW,CAC/B,MAAmB,EACnB,GAAW,EACX,QAAkB,EAClB,UAAqC,EAAE,EACvC,gBAA6B;;IAE7B,MAAM,UAAU,GAAG,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAA,8CAA2B,GAAE,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,MAAA,QAAQ,CAAC,kBAAkB,mCAAI,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,aAAN,MAAM,cAAN,MAAM,GAAI,UAAU,CAAC;QAElC,IAAI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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 {\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 (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 const hasContent = body !== undefined || multipartBody !== undefined;\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(hasContent &&\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)) {\n return { body };\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;;AA6BlC,kCAsCC;AAzDD,kDAAyD;AAEzD,s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AAK,YAAY,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;IACD,wDAAwD;IACxD,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,yDAAyD;QACzD,6BAA6B;QAC7B,IAAI,SAAS,KAAK,kBAAkB,EAAE,CAAC;YACrC,MAAM,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;QAED,gEAAgE;QAChE,cAAc;QACd,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,QAA0B,EAAE,GAAQ;IAC5D,MAAM,GAAG,GAAG,UAAU,GAAG,gDAAgD,QAAQ,CAAC,UAAU,GAAG,CAAC;IAChG,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,IAAI,wBAAS,CAAC,WAAW,CAAC;IAClD,OAAO,IAAI,wBAAS,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 {\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 (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 const hasContent = body !== undefined || multipartBody !== undefined;\n\n const headers = createHttpHeaders({\n ...(options.headers ? options.headers : {}),\n accept: options.accept ?? options.headers?.accept ?? \"application/json\",\n ...(hasContent &&\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)) {\n return { body };\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"]}
@@ -68,7 +68,6 @@ function getQueryParamValue(key, allowReserved, style, param) {
68
68
  return `${allowReserved ? key : encodeURIComponent(key)}=${value}`;
69
69
  }
70
70
  function appendQueryParams(url, options = {}) {
71
- var _a, _b, _c, _d;
72
71
  if (!options.queryParameters) {
73
72
  return url;
74
73
  }
@@ -82,18 +81,18 @@ function appendQueryParams(url, options = {}) {
82
81
  }
83
82
  const hasMetadata = isQueryParameterWithOptions(param);
84
83
  const rawValue = hasMetadata ? param.value : param;
85
- const explode = hasMetadata ? ((_a = param.explode) !== null && _a !== void 0 ? _a : false) : false;
84
+ const explode = hasMetadata ? (param.explode ?? false) : false;
86
85
  const style = hasMetadata && param.style ? param.style : "form";
87
86
  if (explode) {
88
87
  if (Array.isArray(rawValue)) {
89
88
  for (const item of rawValue) {
90
- paramStrings.push(getQueryParamValue(key, (_b = options.skipUrlEncoding) !== null && _b !== void 0 ? _b : false, style, item));
89
+ paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, item));
91
90
  }
92
91
  }
93
92
  else if (typeof rawValue === "object") {
94
93
  // For object explode, the name of the query parameter is ignored and we use the object key instead
95
94
  for (const [actualKey, value] of Object.entries(rawValue)) {
96
- paramStrings.push(getQueryParamValue(actualKey, (_c = options.skipUrlEncoding) !== null && _c !== void 0 ? _c : false, style, value));
95
+ paramStrings.push(getQueryParamValue(actualKey, options.skipUrlEncoding ?? false, style, value));
97
96
  }
98
97
  }
99
98
  else {
@@ -102,7 +101,7 @@ function appendQueryParams(url, options = {}) {
102
101
  }
103
102
  }
104
103
  else {
105
- paramStrings.push(getQueryParamValue(key, (_d = options.skipUrlEncoding) !== null && _d !== void 0 ? _d : false, style, rawValue));
104
+ paramStrings.push(getQueryParamValue(key, options.skipUrlEncoding ?? false, style, rawValue));
106
105
  }
107
106
  }
108
107
  if (parsedUrl.search !== "") {
@@ -112,7 +111,6 @@ function appendQueryParams(url, options = {}) {
112
111
  return parsedUrl.toString();
113
112
  }
114
113
  function buildBaseUrl(endpoint, options) {
115
- var _a;
116
114
  if (!options.pathParameters) {
117
115
  return endpoint;
118
116
  }
@@ -128,14 +126,13 @@ function buildBaseUrl(endpoint, options) {
128
126
  if (!options.skipUrlEncoding) {
129
127
  value = encodeURIComponent(param);
130
128
  }
131
- endpoint = (_a = replaceAll(endpoint, `{${key}}`, value)) !== null && _a !== void 0 ? _a : "";
129
+ endpoint = replaceAll(endpoint, `{${key}}`, value) ?? "";
132
130
  }
133
131
  return endpoint;
134
132
  }
135
133
  function buildRoutePath(routePath, pathParameters, options = {}) {
136
- var _a;
137
134
  for (const pathParam of pathParameters) {
138
- const allowReserved = typeof pathParam === "object" && ((_a = pathParam.allowReserved) !== null && _a !== void 0 ? _a : false);
135
+ const allowReserved = typeof pathParam === "object" && (pathParam.allowReserved ?? false);
139
136
  let value = typeof pathParam === "object" ? pathParam.value : pathParam;
140
137
  if (!options.skipUrlEncoding && !allowReserved) {
141
138
  value = encodeURIComponent(value);