@typespec/ts-http-runtime 0.2.1 → 0.2.2

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 (247) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/client/common.d.ts +6 -0
  3. package/dist/browser/client/common.js.map +1 -1
  4. package/dist/browser/client/getClient.js +4 -4
  5. package/dist/browser/client/getClient.js.map +1 -1
  6. package/dist/browser/client/restError.js +1 -1
  7. package/dist/browser/client/restError.js.map +1 -1
  8. package/dist/browser/constants.js +1 -1
  9. package/dist/browser/constants.js.map +1 -1
  10. package/dist/browser/fetchHttpClient.js +1 -1
  11. package/dist/browser/fetchHttpClient.js.map +1 -1
  12. package/dist/browser/index.d.ts +3 -2
  13. package/dist/browser/index.js +3 -1
  14. package/dist/browser/index.js.map +1 -1
  15. package/dist/browser/interfaces.d.ts +11 -0
  16. package/dist/browser/interfaces.js.map +1 -1
  17. package/dist/browser/logger/internal.d.ts +2 -0
  18. package/dist/browser/logger/internal.js +4 -0
  19. package/dist/browser/logger/internal.js.map +1 -0
  20. package/dist/browser/logger/logger.d.ts +70 -22
  21. package/dist/browser/logger/logger.js +91 -68
  22. package/dist/browser/logger/logger.js.map +1 -1
  23. package/dist/browser/nodeHttpClient.js +1 -8
  24. package/dist/browser/nodeHttpClient.js.map +1 -1
  25. package/dist/browser/pipelineRequest.d.ts +11 -0
  26. package/dist/browser/pipelineRequest.js +1 -0
  27. package/dist/browser/pipelineRequest.js.map +1 -1
  28. package/dist/browser/policies/internal.d.ts +16 -0
  29. package/dist/browser/policies/internal.js +17 -0
  30. package/dist/browser/policies/internal.js.map +1 -0
  31. package/dist/browser/policies/retryPolicy.js +2 -2
  32. package/dist/browser/policies/retryPolicy.js.map +1 -1
  33. package/dist/browser/util/checkEnvironment.d.ts +0 -5
  34. package/dist/browser/util/checkEnvironment.js +0 -5
  35. package/dist/browser/util/checkEnvironment.js.map +1 -1
  36. package/dist/browser/util/concat.common.js +3 -10
  37. package/dist/browser/util/concat.common.js.map +1 -1
  38. package/dist/browser/util/delay.d.ts +0 -13
  39. package/dist/browser/util/delay.js +0 -19
  40. package/dist/browser/util/delay.js.map +1 -1
  41. package/dist/browser/util/error.d.ts +0 -7
  42. package/dist/browser/util/error.js +0 -26
  43. package/dist/browser/util/error.js.map +1 -1
  44. package/dist/browser/util/internal.d.ts +10 -0
  45. package/dist/browser/util/internal.js +12 -0
  46. package/dist/browser/util/internal.js.map +1 -0
  47. package/dist/browser/util/sanitizer.d.ts +12 -2
  48. package/dist/browser/util/sanitizer.js +11 -1
  49. package/dist/browser/util/sanitizer.js.map +1 -1
  50. package/dist/browser/util/typeGuards.d.ts +0 -17
  51. package/dist/browser/util/typeGuards.js +0 -31
  52. package/dist/browser/util/typeGuards.js.map +1 -1
  53. package/dist/commonjs/client/common.d.ts +6 -0
  54. package/dist/commonjs/client/common.js.map +1 -1
  55. package/dist/commonjs/client/getClient.js +4 -4
  56. package/dist/commonjs/client/getClient.js.map +1 -1
  57. package/dist/commonjs/client/restError.js +1 -1
  58. package/dist/commonjs/client/restError.js.map +1 -1
  59. package/dist/commonjs/constants.js +1 -1
  60. package/dist/commonjs/constants.js.map +1 -1
  61. package/dist/commonjs/fetchHttpClient.js +1 -1
  62. package/dist/commonjs/fetchHttpClient.js.map +1 -1
  63. package/dist/commonjs/index.d.ts +3 -2
  64. package/dist/commonjs/index.js +7 -1
  65. package/dist/commonjs/index.js.map +1 -1
  66. package/dist/commonjs/interfaces.d.ts +11 -0
  67. package/dist/commonjs/interfaces.js.map +1 -1
  68. package/dist/commonjs/logger/internal.d.ts +2 -0
  69. package/dist/commonjs/logger/internal.js +8 -0
  70. package/dist/commonjs/logger/internal.js.map +1 -0
  71. package/dist/commonjs/logger/logger.d.ts +70 -22
  72. package/dist/commonjs/logger/logger.js +92 -68
  73. package/dist/commonjs/logger/logger.js.map +1 -1
  74. package/dist/commonjs/nodeHttpClient.js +1 -8
  75. package/dist/commonjs/nodeHttpClient.js.map +1 -1
  76. package/dist/commonjs/pipelineRequest.d.ts +11 -0
  77. package/dist/commonjs/pipelineRequest.js +1 -0
  78. package/dist/commonjs/pipelineRequest.js.map +1 -1
  79. package/dist/commonjs/policies/internal.d.ts +16 -0
  80. package/dist/commonjs/policies/internal.js +48 -0
  81. package/dist/commonjs/policies/internal.js.map +1 -0
  82. package/dist/commonjs/policies/retryPolicy.js +2 -2
  83. package/dist/commonjs/policies/retryPolicy.js.map +1 -1
  84. package/dist/commonjs/tsdoc-metadata.json +1 -1
  85. package/dist/commonjs/util/checkEnvironment.d.ts +0 -5
  86. package/dist/commonjs/util/checkEnvironment.js +1 -6
  87. package/dist/commonjs/util/checkEnvironment.js.map +1 -1
  88. package/dist/commonjs/util/concat.common.js +2 -9
  89. package/dist/commonjs/util/concat.common.js.map +1 -1
  90. package/dist/commonjs/util/concat.js +1 -2
  91. package/dist/commonjs/util/concat.js.map +1 -1
  92. package/dist/commonjs/util/delay.d.ts +0 -13
  93. package/dist/commonjs/util/delay.js +0 -20
  94. package/dist/commonjs/util/delay.js.map +1 -1
  95. package/dist/commonjs/util/error.d.ts +0 -7
  96. package/dist/commonjs/util/error.js +0 -27
  97. package/dist/commonjs/util/error.js.map +1 -1
  98. package/dist/commonjs/util/internal.d.ts +10 -0
  99. package/dist/commonjs/util/internal.js +32 -0
  100. package/dist/commonjs/util/internal.js.map +1 -0
  101. package/dist/commonjs/util/sanitizer.d.ts +12 -2
  102. package/dist/commonjs/util/sanitizer.js +11 -1
  103. package/dist/commonjs/util/sanitizer.js.map +1 -1
  104. package/dist/commonjs/util/typeGuards.d.ts +0 -17
  105. package/dist/commonjs/util/typeGuards.js +0 -34
  106. package/dist/commonjs/util/typeGuards.js.map +1 -1
  107. package/dist/esm/client/common.d.ts +6 -0
  108. package/dist/esm/client/common.js.map +1 -1
  109. package/dist/esm/client/getClient.js +4 -4
  110. package/dist/esm/client/getClient.js.map +1 -1
  111. package/dist/esm/client/restError.js +1 -1
  112. package/dist/esm/client/restError.js.map +1 -1
  113. package/dist/esm/constants.js +1 -1
  114. package/dist/esm/constants.js.map +1 -1
  115. package/dist/esm/fetchHttpClient.js +1 -1
  116. package/dist/esm/fetchHttpClient.js.map +1 -1
  117. package/dist/esm/index.d.ts +3 -2
  118. package/dist/esm/index.js +3 -1
  119. package/dist/esm/index.js.map +1 -1
  120. package/dist/esm/interfaces.d.ts +11 -0
  121. package/dist/esm/interfaces.js.map +1 -1
  122. package/dist/esm/logger/internal.d.ts +2 -0
  123. package/dist/esm/logger/internal.js +4 -0
  124. package/dist/esm/logger/internal.js.map +1 -0
  125. package/dist/esm/logger/logger.d.ts +70 -22
  126. package/dist/esm/logger/logger.js +91 -68
  127. package/dist/esm/logger/logger.js.map +1 -1
  128. package/dist/esm/nodeHttpClient.js +1 -8
  129. package/dist/esm/nodeHttpClient.js.map +1 -1
  130. package/dist/esm/pipelineRequest.d.ts +11 -0
  131. package/dist/esm/pipelineRequest.js +1 -0
  132. package/dist/esm/pipelineRequest.js.map +1 -1
  133. package/dist/esm/policies/internal.d.ts +16 -0
  134. package/dist/esm/policies/internal.js +17 -0
  135. package/dist/esm/policies/internal.js.map +1 -0
  136. package/dist/esm/policies/retryPolicy.js +2 -2
  137. package/dist/esm/policies/retryPolicy.js.map +1 -1
  138. package/dist/esm/util/checkEnvironment.d.ts +0 -5
  139. package/dist/esm/util/checkEnvironment.js +0 -5
  140. package/dist/esm/util/checkEnvironment.js.map +1 -1
  141. package/dist/esm/util/concat.common.js +3 -10
  142. package/dist/esm/util/concat.common.js.map +1 -1
  143. package/dist/esm/util/concat.js +1 -2
  144. package/dist/esm/util/concat.js.map +1 -1
  145. package/dist/esm/util/delay.d.ts +0 -13
  146. package/dist/esm/util/delay.js +0 -19
  147. package/dist/esm/util/delay.js.map +1 -1
  148. package/dist/esm/util/error.d.ts +0 -7
  149. package/dist/esm/util/error.js +0 -26
  150. package/dist/esm/util/error.js.map +1 -1
  151. package/dist/esm/util/internal.d.ts +10 -0
  152. package/dist/esm/util/internal.js +12 -0
  153. package/dist/esm/util/internal.js.map +1 -0
  154. package/dist/esm/util/sanitizer.d.ts +12 -2
  155. package/dist/esm/util/sanitizer.js +11 -1
  156. package/dist/esm/util/sanitizer.js.map +1 -1
  157. package/dist/esm/util/typeGuards.d.ts +0 -17
  158. package/dist/esm/util/typeGuards.js +0 -31
  159. package/dist/esm/util/typeGuards.js.map +1 -1
  160. package/dist/react-native/client/common.d.ts +6 -0
  161. package/dist/react-native/client/common.js.map +1 -1
  162. package/dist/react-native/client/getClient.js +4 -4
  163. package/dist/react-native/client/getClient.js.map +1 -1
  164. package/dist/react-native/client/restError.js +1 -1
  165. package/dist/react-native/client/restError.js.map +1 -1
  166. package/dist/react-native/constants.js +1 -1
  167. package/dist/react-native/constants.js.map +1 -1
  168. package/dist/react-native/fetchHttpClient.js +1 -1
  169. package/dist/react-native/fetchHttpClient.js.map +1 -1
  170. package/dist/react-native/index.d.ts +3 -2
  171. package/dist/react-native/index.js +3 -1
  172. package/dist/react-native/index.js.map +1 -1
  173. package/dist/react-native/interfaces.d.ts +11 -0
  174. package/dist/react-native/interfaces.js.map +1 -1
  175. package/dist/react-native/logger/internal.d.ts +2 -0
  176. package/dist/react-native/logger/internal.js +4 -0
  177. package/dist/react-native/logger/internal.js.map +1 -0
  178. package/dist/react-native/logger/logger.d.ts +70 -22
  179. package/dist/react-native/logger/logger.js +91 -68
  180. package/dist/react-native/logger/logger.js.map +1 -1
  181. package/dist/react-native/nodeHttpClient.js +1 -8
  182. package/dist/react-native/nodeHttpClient.js.map +1 -1
  183. package/dist/react-native/pipelineRequest.d.ts +11 -0
  184. package/dist/react-native/pipelineRequest.js +1 -0
  185. package/dist/react-native/pipelineRequest.js.map +1 -1
  186. package/dist/react-native/policies/internal.d.ts +16 -0
  187. package/dist/react-native/policies/internal.js +17 -0
  188. package/dist/react-native/policies/internal.js.map +1 -0
  189. package/dist/react-native/policies/retryPolicy.js +2 -2
  190. package/dist/react-native/policies/retryPolicy.js.map +1 -1
  191. package/dist/react-native/util/checkEnvironment.d.ts +0 -5
  192. package/dist/react-native/util/checkEnvironment.js +0 -5
  193. package/dist/react-native/util/checkEnvironment.js.map +1 -1
  194. package/dist/react-native/util/concat.common.js +3 -10
  195. package/dist/react-native/util/concat.common.js.map +1 -1
  196. package/dist/react-native/util/delay.d.ts +0 -13
  197. package/dist/react-native/util/delay.js +0 -19
  198. package/dist/react-native/util/delay.js.map +1 -1
  199. package/dist/react-native/util/error.d.ts +0 -7
  200. package/dist/react-native/util/error.js +0 -26
  201. package/dist/react-native/util/error.js.map +1 -1
  202. package/dist/react-native/util/internal.d.ts +10 -0
  203. package/dist/react-native/util/internal.js +12 -0
  204. package/dist/react-native/util/internal.js.map +1 -0
  205. package/dist/react-native/util/sanitizer.d.ts +12 -2
  206. package/dist/react-native/util/sanitizer.js +11 -1
  207. package/dist/react-native/util/sanitizer.js.map +1 -1
  208. package/dist/react-native/util/typeGuards.d.ts +0 -17
  209. package/dist/react-native/util/typeGuards.js +0 -31
  210. package/dist/react-native/util/typeGuards.js.map +1 -1
  211. package/package.json +62 -5
  212. package/dist/browser/util/aborterUtils.d.ts +0 -26
  213. package/dist/browser/util/aborterUtils.js +0 -21
  214. package/dist/browser/util/aborterUtils.js.map +0 -1
  215. package/dist/browser/util/createAbortablePromise.d.ts +0 -16
  216. package/dist/browser/util/createAbortablePromise.js +0 -42
  217. package/dist/browser/util/createAbortablePromise.js.map +0 -1
  218. package/dist/browser/util/file.d.ts +0 -69
  219. package/dist/browser/util/file.js +0 -99
  220. package/dist/browser/util/file.js.map +0 -1
  221. package/dist/commonjs/util/aborterUtils.d.ts +0 -26
  222. package/dist/commonjs/util/aborterUtils.js +0 -24
  223. package/dist/commonjs/util/aborterUtils.js.map +0 -1
  224. package/dist/commonjs/util/createAbortablePromise.d.ts +0 -16
  225. package/dist/commonjs/util/createAbortablePromise.js +0 -45
  226. package/dist/commonjs/util/createAbortablePromise.js.map +0 -1
  227. package/dist/commonjs/util/file.d.ts +0 -69
  228. package/dist/commonjs/util/file.js +0 -104
  229. package/dist/commonjs/util/file.js.map +0 -1
  230. package/dist/esm/util/aborterUtils.d.ts +0 -26
  231. package/dist/esm/util/aborterUtils.js +0 -21
  232. package/dist/esm/util/aborterUtils.js.map +0 -1
  233. package/dist/esm/util/createAbortablePromise.d.ts +0 -16
  234. package/dist/esm/util/createAbortablePromise.js +0 -42
  235. package/dist/esm/util/createAbortablePromise.js.map +0 -1
  236. package/dist/esm/util/file.d.ts +0 -69
  237. package/dist/esm/util/file.js +0 -99
  238. package/dist/esm/util/file.js.map +0 -1
  239. package/dist/react-native/util/aborterUtils.d.ts +0 -26
  240. package/dist/react-native/util/aborterUtils.js +0 -21
  241. package/dist/react-native/util/aborterUtils.js.map +0 -1
  242. package/dist/react-native/util/createAbortablePromise.d.ts +0 -16
  243. package/dist/react-native/util/createAbortablePromise.js +0 -42
  244. package/dist/react-native/util/createAbortablePromise.js.map +0 -1
  245. package/dist/react-native/util/file.d.ts +0 -69
  246. package/dist/react-native/util/file.js +0 -99
  247. package/dist/react-native/util/file.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"fetchHttpClient.js","sourceRoot":"","sources":["../../src/fetchHttpClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAQ9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEjF;;GAEG;AACH,SAAS,MAAM,CAAC,IAAa;IAC3B,gFAAgF;IAChF,OAAO,CAAC,OAAO,IAAI,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,YAAY,IAAI,CAAC;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM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,KAAK,aAAL,KAAK,uBAAL,KAAK,EAAI,CAAC;gBACV,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,eAAe,EAAE,CAAC;AAC/B,CAAC;AAED,SAAS,0BAA0B,CAAC,cAA8B;IAChE,OAAO,cAAc,CAAC,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,CAAC;AACxF,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 as PipelineHeaders,\n PipelineRequest,\n PipelineResponse,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { RestError } from \"./restError.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { isNodeReadableStream, isWebReadableStream } from \"./util/typeGuards.js\";\n\n/**\n * Checks if the body is a Blob or Blob-like\n */\nfunction isBlob(body: unknown): body is Blob {\n // File objects count as a type of Blob, so we want to use instanceof explicitly\n return (typeof Blob === \"function\" || typeof Blob === \"object\") && body instanceof Blob;\n}\n\n/**\n * A HttpClient implementation that uses window.fetch to send HTTP requests.\n * @internal\n */\nclass FetchHttpClient 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 if (request.proxySettings) {\n throw new Error(\"HTTP proxy is not supported in browser environment\");\n }\n\n try {\n return await makeRequest(request);\n } catch (e: any) {\n throw getError(e, request);\n }\n }\n}\n\n/**\n * Sends a request\n */\nasync function makeRequest(request: PipelineRequest): Promise<PipelineResponse> {\n const { abortController, abortControllerCleanup } = setupAbortSignal(request);\n try {\n const headers = buildFetchHeaders(request.headers);\n const { streaming, body: requestBody } = buildRequestBody(request);\n const requestInit: RequestInit = {\n body: requestBody,\n method: request.method,\n headers: headers,\n signal: abortController.signal,\n // Cloudflare doesn't implement the full Fetch API spec\n // because of some of it doesn't make sense in the edge.\n // See https://github.com/cloudflare/workerd/issues/902\n ...(\"credentials\" in Request.prototype\n ? { credentials: request.withCredentials ? \"include\" : \"same-origin\" }\n : {}),\n ...(\"cache\" in Request.prototype ? { cache: \"no-store\" } : {}),\n };\n\n // According to https://fetch.spec.whatwg.org/#fetch-method,\n // init.duplex must be set when body is a ReadableStream object.\n // currently \"half\" is the only valid value.\n if (streaming) {\n (requestInit as any).duplex = \"half\";\n }\n /**\n * Developers of the future:\n * Do not set redirect: \"manual\" as part\n * of request options.\n * It will not work as you expect.\n */\n const response = await fetch(request.url, requestInit);\n // If we're uploading a blob, we need to fire the progress event manually\n if (isBlob(request.body) && request.onUploadProgress) {\n request.onUploadProgress({ loadedBytes: request.body.size });\n }\n return buildPipelineResponse(response, request, abortControllerCleanup);\n } catch (e) {\n abortControllerCleanup?.();\n throw e;\n }\n}\n\n/**\n * Creates a pipeline response from a Fetch response;\n */\nasync function buildPipelineResponse(\n httpResponse: Response,\n request: PipelineRequest,\n abortControllerCleanup?: () => void,\n): Promise<PipelineResponse> {\n const headers = buildPipelineHeaders(httpResponse);\n const response: PipelineResponse = {\n request,\n headers,\n status: httpResponse.status,\n };\n\n const bodyStream = isWebReadableStream(httpResponse.body)\n ? buildBodyStream(httpResponse.body, {\n onProgress: request.onDownloadProgress,\n onEnd: abortControllerCleanup,\n })\n : httpResponse.body;\n\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(response.status)\n ) {\n if (request.enableBrowserStreams) {\n response.browserStreamBody = bodyStream ?? undefined;\n } else {\n const responseStream = new Response(bodyStream);\n response.blobBody = responseStream.blob();\n abortControllerCleanup?.();\n }\n } else {\n const responseStream = new Response(bodyStream);\n\n response.bodyAsText = await responseStream.text();\n abortControllerCleanup?.();\n }\n\n return response;\n}\n\nfunction setupAbortSignal(request: PipelineRequest): {\n abortController: AbortController;\n abortControllerCleanup: (() => void) | undefined;\n} {\n const abortController = new AbortController();\n\n // Cleanup function\n let abortControllerCleanup: (() => void) | undefined;\n\n /**\n * Attach an abort listener to the request\n */\n let abortListener: ((event: any) => void) | undefined;\n if (request.abortSignal) {\n if (request.abortSignal.aborted) {\n throw new AbortError(\"The operation was aborted. Request has already been canceled.\");\n }\n\n abortListener = (event: Event) => {\n if (event.type === \"abort\") {\n abortController.abort();\n }\n };\n request.abortSignal.addEventListener(\"abort\", abortListener);\n abortControllerCleanup = () => {\n if (abortListener) {\n request.abortSignal?.removeEventListener(\"abort\", abortListener);\n }\n };\n }\n\n // If a timeout was passed, call the abort signal once the time elapses\n if (request.timeout > 0) {\n setTimeout(() => {\n abortController.abort();\n }, request.timeout);\n }\n\n return { abortController, abortControllerCleanup };\n}\n\n/**\n * Gets the specific error\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\nfunction getError(e: RestError, request: PipelineRequest): RestError {\n if (e && e?.name === \"AbortError\") {\n return e;\n } else {\n return new RestError(`Error sending request: ${e.message}`, {\n code: e?.code ?? RestError.REQUEST_SEND_ERROR,\n request,\n });\n }\n}\n\n/**\n * Converts PipelineRequest headers to Fetch headers\n */\nfunction buildFetchHeaders(pipelineHeaders: PipelineHeaders): Headers {\n const headers = new Headers();\n for (const [name, value] of pipelineHeaders) {\n headers.append(name, value);\n }\n\n return headers;\n}\n\nfunction buildPipelineHeaders(httpResponse: Response): PipelineHeaders {\n const responseHeaders = createHttpHeaders();\n for (const [name, value] of httpResponse.headers) {\n responseHeaders.set(name, value);\n }\n\n return responseHeaders;\n}\n\ninterface BuildRequestBodyResponse {\n body:\n | string\n | Blob\n | ReadableStream<Uint8Array>\n | ArrayBuffer\n | ArrayBufferView\n | FormData\n | null\n | undefined;\n streaming: boolean;\n}\n\nfunction buildRequestBody(request: PipelineRequest): BuildRequestBodyResponse {\n const body = typeof request.body === \"function\" ? request.body() : request.body;\n if (isNodeReadableStream(body)) {\n throw new Error(\"Node streams are not supported in browser environment.\");\n }\n\n return isWebReadableStream(body)\n ? { streaming: true, body: buildBodyStream(body, { onProgress: request.onUploadProgress }) }\n : { streaming: false, body };\n}\n\n/**\n * Reads the request/response original stream and stream it through a new\n * ReadableStream, this is done to be able to report progress in a way that\n * all modern browsers support. TransformStreams would be an alternative,\n * however they are not yet supported by all browsers i.e Firefox\n */\nfunction buildBodyStream(\n readableStream: ReadableStream<Uint8Array>,\n options: { onProgress?: (progress: TransferProgressEvent) => void; onEnd?: () => void } = {},\n): ReadableStream<Uint8Array> {\n let loadedBytes = 0;\n const { onProgress, onEnd } = options;\n\n // If the current browser supports pipeThrough we use a TransformStream\n // to report progress\n if (isTransformStreamSupported(readableStream)) {\n return readableStream.pipeThrough(\n new TransformStream({\n transform(chunk, controller) {\n if (chunk === null) {\n controller.terminate();\n return;\n }\n\n controller.enqueue(chunk);\n loadedBytes += chunk.length;\n if (onProgress) {\n onProgress({ loadedBytes });\n }\n },\n flush() {\n onEnd?.();\n },\n }),\n );\n } else {\n // If we can't use transform streams, wrap the original stream in a new readable stream\n // and use pull to enqueue each chunk and report progress.\n const reader = readableStream.getReader();\n return new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n // When no more data needs to be consumed, break the reading\n if (done || !value) {\n onEnd?.();\n // Close the stream\n controller.close();\n reader.releaseLock();\n return;\n }\n\n loadedBytes += value?.length ?? 0;\n\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n\n if (onProgress) {\n onProgress({ loadedBytes });\n }\n },\n cancel(reason?: string) {\n onEnd?.();\n return reader.cancel(reason);\n },\n });\n }\n}\n\n/**\n * Create a new HttpClient instance for the browser environment.\n * @internal\n */\nexport function createFetchHttpClient(): HttpClient {\n return new FetchHttpClient();\n}\n\nfunction isTransformStreamSupported(readableStream: ReadableStream): boolean {\n return readableStream.pipeThrough !== undefined && self.TransformStream !== undefined;\n}\n"]}
1
+ {"version":3,"file":"fetchHttpClient.js","sourceRoot":"","sources":["../../src/fetchHttpClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAQ9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEjF;;GAEG;AACH,SAAS,MAAM,CAAC,IAAa;IAC3B,gFAAgF;IAChF,OAAO,CAAC,OAAO,IAAI,KAAK,UAAU,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,YAAY,IAAI,CAAC;AAC1F,CAAC;AAED;;;GAGG;AACH,MAAM,eAAe;IACnB;;;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,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,CAAC;QACp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F,0DAA0D;QAC1D,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,CAAC;QAC1C,OAAO,IAAI,cAAc,CAAC;YACxB,KAAK,CAAC,IAAI,CAAC,UAAU;;gBACnB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC5C,4DAA4D;gBAC5D,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;oBACnB,KAAK,aAAL,KAAK,uBAAL,KAAK,EAAI,CAAC;oBACV,mBAAmB;oBACnB,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,MAAM,CAAC,WAAW,EAAE,CAAC;oBACrB,OAAO;gBACT,CAAC;gBAED,WAAW,IAAI,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,mCAAI,CAAC,CAAC;gBAElC,qDAAqD;gBACrD,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAE1B,IAAI,UAAU,EAAE,CAAC;oBACf,UAAU,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC;YACD,MAAM,CAAC,MAAe;gBACpB,KAAK,aAAL,KAAK,uBAAL,KAAK,EAAI,CAAC;gBACV,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,eAAe,EAAE,CAAC;AAC/B,CAAC;AAED,SAAS,0BAA0B,CAAC,cAA8B;IAChE,OAAO,cAAc,CAAC,WAAW,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,CAAC;AACxF,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 as PipelineHeaders,\n PipelineRequest,\n PipelineResponse,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { RestError } from \"./restError.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { isNodeReadableStream, isWebReadableStream } from \"./util/typeGuards.js\";\n\n/**\n * Checks if the body is a Blob or Blob-like\n */\nfunction isBlob(body: unknown): body is Blob {\n // File objects count as a type of Blob, so we want to use instanceof explicitly\n return (typeof Blob === \"function\" || typeof Blob === \"object\") && body instanceof Blob;\n}\n\n/**\n * A HttpClient implementation that uses window.fetch to send HTTP requests.\n * @internal\n */\nclass FetchHttpClient 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 if (request.proxySettings) {\n throw new Error(\"HTTP proxy is not supported in browser environment\");\n }\n\n try {\n return await makeRequest(request);\n } catch (e: any) {\n throw getError(e, request);\n }\n }\n}\n\n/**\n * Sends a request\n */\nasync function makeRequest(request: PipelineRequest): Promise<PipelineResponse> {\n const { abortController, abortControllerCleanup } = setupAbortSignal(request);\n try {\n const headers = buildFetchHeaders(request.headers);\n const { streaming, body: requestBody } = buildRequestBody(request);\n const requestInit: RequestInit = {\n body: requestBody,\n method: request.method,\n headers: headers,\n signal: abortController.signal,\n // Cloudflare doesn't implement the full Fetch API spec\n // because of some of it doesn't make sense in the edge.\n // See https://github.com/cloudflare/workerd/issues/902\n ...(\"credentials\" in Request.prototype\n ? { credentials: request.withCredentials ? \"include\" : \"same-origin\" }\n : {}),\n ...(\"cache\" in Request.prototype ? { cache: \"no-store\" } : {}),\n };\n\n // According to https://fetch.spec.whatwg.org/#fetch-method,\n // init.duplex must be set when body is a ReadableStream object.\n // currently \"half\" is the only valid value.\n if (streaming) {\n (requestInit as any).duplex = \"half\";\n }\n /**\n * Developers of the future:\n * Do not set redirect: \"manual\" as part\n * of request options.\n * It will not work as you expect.\n */\n const response = await fetch(request.url, {\n ...requestInit,\n ...request.requestOverrides,\n });\n // If we're uploading a blob, we need to fire the progress event manually\n if (isBlob(request.body) && request.onUploadProgress) {\n request.onUploadProgress({ loadedBytes: request.body.size });\n }\n return buildPipelineResponse(response, request, abortControllerCleanup);\n } catch (e) {\n abortControllerCleanup?.();\n throw e;\n }\n}\n\n/**\n * Creates a pipeline response from a Fetch response;\n */\nasync function buildPipelineResponse(\n httpResponse: Response,\n request: PipelineRequest,\n abortControllerCleanup?: () => void,\n): Promise<PipelineResponse> {\n const headers = buildPipelineHeaders(httpResponse);\n const response: PipelineResponse = {\n request,\n headers,\n status: httpResponse.status,\n };\n\n const bodyStream = isWebReadableStream(httpResponse.body)\n ? buildBodyStream(httpResponse.body, {\n onProgress: request.onDownloadProgress,\n onEnd: abortControllerCleanup,\n })\n : httpResponse.body;\n\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(response.status)\n ) {\n if (request.enableBrowserStreams) {\n response.browserStreamBody = bodyStream ?? undefined;\n } else {\n const responseStream = new Response(bodyStream);\n response.blobBody = responseStream.blob();\n abortControllerCleanup?.();\n }\n } else {\n const responseStream = new Response(bodyStream);\n\n response.bodyAsText = await responseStream.text();\n abortControllerCleanup?.();\n }\n\n return response;\n}\n\nfunction setupAbortSignal(request: PipelineRequest): {\n abortController: AbortController;\n abortControllerCleanup: (() => void) | undefined;\n} {\n const abortController = new AbortController();\n\n // Cleanup function\n let abortControllerCleanup: (() => void) | undefined;\n\n /**\n * Attach an abort listener to the request\n */\n let abortListener: ((event: any) => void) | undefined;\n if (request.abortSignal) {\n if (request.abortSignal.aborted) {\n throw new AbortError(\"The operation was aborted. Request has already been canceled.\");\n }\n\n abortListener = (event: Event) => {\n if (event.type === \"abort\") {\n abortController.abort();\n }\n };\n request.abortSignal.addEventListener(\"abort\", abortListener);\n abortControllerCleanup = () => {\n if (abortListener) {\n request.abortSignal?.removeEventListener(\"abort\", abortListener);\n }\n };\n }\n\n // If a timeout was passed, call the abort signal once the time elapses\n if (request.timeout > 0) {\n setTimeout(() => {\n abortController.abort();\n }, request.timeout);\n }\n\n return { abortController, abortControllerCleanup };\n}\n\n/**\n * Gets the specific error\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-use-interface-parameters\nfunction getError(e: RestError, request: PipelineRequest): RestError {\n if (e && e?.name === \"AbortError\") {\n return e;\n } else {\n return new RestError(`Error sending request: ${e.message}`, {\n code: e?.code ?? RestError.REQUEST_SEND_ERROR,\n request,\n });\n }\n}\n\n/**\n * Converts PipelineRequest headers to Fetch headers\n */\nfunction buildFetchHeaders(pipelineHeaders: PipelineHeaders): Headers {\n const headers = new Headers();\n for (const [name, value] of pipelineHeaders) {\n headers.append(name, value);\n }\n\n return headers;\n}\n\nfunction buildPipelineHeaders(httpResponse: Response): PipelineHeaders {\n const responseHeaders = createHttpHeaders();\n for (const [name, value] of httpResponse.headers) {\n responseHeaders.set(name, value);\n }\n\n return responseHeaders;\n}\n\ninterface BuildRequestBodyResponse {\n body:\n | string\n | Blob\n | ReadableStream<Uint8Array>\n | ArrayBuffer\n | ArrayBufferView\n | FormData\n | null\n | undefined;\n streaming: boolean;\n}\n\nfunction buildRequestBody(request: PipelineRequest): BuildRequestBodyResponse {\n const body = typeof request.body === \"function\" ? request.body() : request.body;\n if (isNodeReadableStream(body)) {\n throw new Error(\"Node streams are not supported in browser environment.\");\n }\n\n return isWebReadableStream(body)\n ? { streaming: true, body: buildBodyStream(body, { onProgress: request.onUploadProgress }) }\n : { streaming: false, body };\n}\n\n/**\n * Reads the request/response original stream and stream it through a new\n * ReadableStream, this is done to be able to report progress in a way that\n * all modern browsers support. TransformStreams would be an alternative,\n * however they are not yet supported by all browsers i.e Firefox\n */\nfunction buildBodyStream(\n readableStream: ReadableStream<Uint8Array>,\n options: { onProgress?: (progress: TransferProgressEvent) => void; onEnd?: () => void } = {},\n): ReadableStream<Uint8Array> {\n let loadedBytes = 0;\n const { onProgress, onEnd } = options;\n\n // If the current browser supports pipeThrough we use a TransformStream\n // to report progress\n if (isTransformStreamSupported(readableStream)) {\n return readableStream.pipeThrough(\n new TransformStream({\n transform(chunk, controller) {\n if (chunk === null) {\n controller.terminate();\n return;\n }\n\n controller.enqueue(chunk);\n loadedBytes += chunk.length;\n if (onProgress) {\n onProgress({ loadedBytes });\n }\n },\n flush() {\n onEnd?.();\n },\n }),\n );\n } else {\n // If we can't use transform streams, wrap the original stream in a new readable stream\n // and use pull to enqueue each chunk and report progress.\n const reader = readableStream.getReader();\n return new ReadableStream({\n async pull(controller) {\n const { done, value } = await reader.read();\n // When no more data needs to be consumed, break the reading\n if (done || !value) {\n onEnd?.();\n // Close the stream\n controller.close();\n reader.releaseLock();\n return;\n }\n\n loadedBytes += value?.length ?? 0;\n\n // Enqueue the next data chunk into our target stream\n controller.enqueue(value);\n\n if (onProgress) {\n onProgress({ loadedBytes });\n }\n },\n cancel(reason?: string) {\n onEnd?.();\n return reader.cancel(reason);\n },\n });\n }\n}\n\n/**\n * Create a new HttpClient instance for the browser environment.\n * @internal\n */\nexport function createFetchHttpClient(): HttpClient {\n return new FetchHttpClient();\n}\n\nfunction isTransformStreamSupported(readableStream: ReadableStream): boolean {\n return readableStream.pipeThrough !== undefined && self.TransformStream !== undefined;\n}\n"]}
@@ -11,16 +11,17 @@ declare global {
11
11
  }
12
12
  }
13
13
  export { AbortError } from "./abort-controller/AbortError.js";
14
- export { createClientLogger, TypeSpecRuntimeLogger, type TypeSpecRuntimeClientLogger, type Debugger, } from "./logger/logger.js";
14
+ export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, type Debugger, type TypeSpecRuntimeClientLogger, type TypeSpecRuntimeLogLevel, } from "./logger/logger.js";
15
15
  export type { BodyPart, FormDataValue, RawHttpHeaders, KeyObject, PxfObject, HttpClient, PipelineRequest, PipelineResponse, SendRequest, TlsSettings, Agent, RequestBodyType, FormDataMap, HttpHeaders, HttpMethods, MultipartRequestBody, TransferProgressEvent, ProxySettings, RawHttpHeadersInput, PipelineRetryOptions, } from "./interfaces.js";
16
16
  export { createHttpHeaders } from "./httpHeaders.js";
17
17
  export * from "./auth/schemes.js";
18
18
  export * from "./auth/oauth2Flows.js";
19
19
  export { type BasicCredential, type BearerTokenCredential, type OAuth2TokenCredential, type GetOAuth2TokenOptions, type GetBearerTokenOptions, type ApiKeyCredential, type ClientCredential, } from "./auth/credentials.js";
20
20
  export { createPipelineRequest, type PipelineRequestOptions } from "./pipelineRequest.js";
21
- export type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from "./pipeline.js";
21
+ export { type Pipeline, type PipelinePolicy, type AddPolicyOptions, type PipelinePhase, createEmptyPipeline, } from "./pipeline.js";
22
22
  export { RestError, isRestError, type RestErrorOptions } from "./restError.js";
23
23
  export { stringToUint8Array, uint8ArrayToString, type EncodingType } from "./util/bytesEncoding.js";
24
+ export { createDefaultHttpClient } from "./defaultHttpClient.js";
24
25
  export { getClient } from "./client/getClient.js";
25
26
  export { operationOptionsToRequestParameters } from "./client/operationOptionHelpers.js";
26
27
  export { createRestError } from "./client/restError.js";
package/dist/esm/index.js CHANGED
@@ -1,13 +1,15 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  export { AbortError } from "./abort-controller/AbortError.js";
4
- export { createClientLogger, TypeSpecRuntimeLogger, } from "./logger/logger.js";
4
+ export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, } from "./logger/logger.js";
5
5
  export { createHttpHeaders } from "./httpHeaders.js";
6
6
  export * from "./auth/schemes.js";
7
7
  export * from "./auth/oauth2Flows.js";
8
8
  export { createPipelineRequest } from "./pipelineRequest.js";
9
+ export { createEmptyPipeline, } from "./pipeline.js";
9
10
  export { RestError, isRestError } from "./restError.js";
10
11
  export { stringToUint8Array, uint8ArrayToString } from "./util/bytesEncoding.js";
12
+ export { createDefaultHttpClient } from "./defaultHttpClient.js";
11
13
  export { getClient } from "./client/getClient.js";
12
14
  export { operationOptionsToRequestParameters } from "./client/operationOptionHelpers.js";
13
15
  export { createRestError } from "./client/restError.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC;AAuB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAUtC,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAE1F,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n TypeSpecRuntimeLogger,\n type TypeSpecRuntimeClientLogger,\n type Debugger,\n} from \"./logger/logger.js\";\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAUtC,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAKL,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n getLogLevel,\n setLogLevel,\n TypeSpecRuntimeLogger,\n type Debugger,\n type TypeSpecRuntimeClientLogger,\n type TypeSpecRuntimeLogLevel,\n} from \"./logger/logger.js\";\n\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport {\n type Pipeline,\n type PipelinePolicy,\n type AddPolicyOptions,\n type PipelinePhase,\n createEmptyPipeline,\n} from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { createDefaultHttpClient } from \"./defaultHttpClient.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
@@ -199,6 +199,17 @@ export interface PipelineRequest {
199
199
  enableBrowserStreams?: boolean;
200
200
  /** Settings for configuring TLS authentication */
201
201
  tlsSettings?: TlsSettings;
202
+ /**
203
+ * Additional options to set on the request. This provides a way to override
204
+ * existing ones or provide request properties that are not declared.
205
+ *
206
+ * For possible valid properties, see
207
+ * - NodeJS https.request options: https://nodejs.org/api/http.html#httprequestoptions-callback
208
+ * - Browser RequestInit: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit
209
+ *
210
+ * WARNING: Options specified here will override any properties of same names when request is sent by {@link HttpClient}.
211
+ */
212
+ requestOverrides?: Record<string, unknown>;
202
213
  }
203
214
  /**
204
215
  * Metadata about a response received by the pipeline.
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AuthScheme } from \"./auth/schemes.js\";\n\n/**\n * A HttpHeaders collection represented as a simple JSON object.\n */\nexport type RawHttpHeaders = { [headerName: string]: string };\n\n/**\n * A HttpHeaders collection for input, represented as a simple JSON object.\n */\nexport type RawHttpHeadersInput = Record<string, string | number | boolean>;\n\n/**\n * Represents a set of HTTP headers on a request/response.\n * Header names are treated as case insensitive.\n */\nexport interface HttpHeaders extends Iterable<[string, string]> {\n /**\n * Returns the value of a specific header or undefined if not set.\n * @param name - The name of the header to retrieve.\n */\n get(name: string): string | undefined;\n /**\n * Returns true if the specified header exists.\n * @param name - The name of the header to check.\n */\n has(name: string): boolean;\n /**\n * Sets a specific header with a given value.\n * @param name - The name of the header to set.\n * @param value - The value to use for the header.\n */\n set(name: string, value: string | number | boolean): void;\n /**\n * Removes a specific header from the collection.\n * @param name - The name of the header to delete.\n */\n delete(name: string): void;\n /**\n * Accesses a raw JS object that acts as a simple map\n * of header names to values.\n */\n toJSON(options?: { preserveCase?: boolean }): RawHttpHeaders;\n}\n\n/**\n * A part of the request body in a multipart request.\n */\nexport interface BodyPart {\n /**\n * The headers for this part of the multipart request.\n */\n headers: HttpHeaders;\n\n /**\n * The body of this part of the multipart request.\n */\n body:\n | ((() => ReadableStream<Uint8Array>) | (() => NodeJS.ReadableStream))\n | ReadableStream<Uint8Array>\n | NodeJS.ReadableStream\n | Uint8Array\n | Blob;\n}\n\n/**\n * A request body consisting of multiple parts.\n */\nexport interface MultipartRequestBody {\n /**\n * The parts of the request body.\n */\n parts: BodyPart[];\n\n /**\n * The boundary separating each part of the request body.\n * If not specified, a random boundary will be generated.\n *\n * When specified, '--' will be prepended to the boundary in the request to ensure the boundary follows the specification.\n */\n boundary?: string;\n}\n\n/**\n * Types of bodies supported on the request.\n * NodeJS.ReadableStream and () =\\> NodeJS.ReadableStream is Node only.\n * Blob, ReadableStream<Uint8Array>, and () =\\> ReadableStream<Uint8Array> are browser only.\n */\nexport type RequestBodyType =\n | NodeJS.ReadableStream\n | (() => NodeJS.ReadableStream)\n | ReadableStream<Uint8Array>\n | (() => ReadableStream<Uint8Array>)\n | Blob\n | ArrayBuffer\n | ArrayBufferView\n | FormData\n | string\n | null;\n\n/**\n * An interface compatible with NodeJS's `http.Agent`.\n * We want to avoid publicly re-exporting the actual interface,\n * since it might vary across runtime versions.\n */\nexport interface Agent {\n /**\n * Destroy any sockets that are currently in use by the agent.\n */\n destroy(): void;\n /**\n * For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state.\n */\n maxFreeSockets: number;\n /**\n * Determines how many concurrent sockets the agent can have open per origin.\n */\n maxSockets: number;\n /**\n * An object which contains queues of requests that have not yet been assigned to sockets.\n */\n requests: unknown;\n /**\n * An object which contains arrays of sockets currently in use by the agent.\n */\n sockets: unknown;\n}\n\n/**\n * Metadata about a request being made by the pipeline.\n */\nexport interface PipelineRequest {\n /**\n * List of authentication schemes used for this specific request.\n * These schemes define how the request will be authenticated.\n * If provided, these schemes override the client level authentication schemes.\n *\n * If no auth schemes are provided at client or request level, defaults to no auth.\n */\n authSchemes?: AuthScheme[];\n\n /**\n * The URL to make the request to.\n */\n url: string;\n\n /**\n * The HTTP method to use when making the request.\n */\n method: HttpMethods;\n\n /**\n * The HTTP headers to use when making the request.\n */\n headers: HttpHeaders;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n * If the request is terminated, an `AbortError` is thrown.\n * Defaults to 0, which disables the timeout.\n */\n timeout: number;\n\n /**\n * Indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests.\n * Defaults to false.\n */\n withCredentials: boolean;\n\n /**\n * A unique identifier for the request. Used for logging and tracing.\n */\n requestId: string;\n\n /**\n * The HTTP body content (if any)\n */\n body?: RequestBodyType;\n\n /**\n * Body for a multipart request.\n */\n multipartBody?: MultipartRequestBody;\n\n /**\n * To simulate a browser form post\n */\n formData?: FormDataMap;\n\n /**\n * A list of response status codes whose corresponding PipelineResponse body should be treated as a stream.\n * When streamResponseStatusCodes contains the value Number.POSITIVE_INFINITY any status would be treated as a stream.\n */\n streamResponseStatusCodes?: Set<number>;\n\n /**\n * Proxy configuration.\n */\n proxySettings?: ProxySettings;\n\n /**\n * If the connection should not be reused.\n */\n disableKeepAlive?: boolean;\n\n /**\n * Used to abort the request later.\n */\n abortSignal?: AbortSignal;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Callback which fires upon download progress. */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n\n /**\n * NODEJS ONLY\n *\n * A Node-only option to provide a custom `http.Agent`/`https.Agent`.\n * Does nothing when running in the browser.\n */\n agent?: Agent;\n\n /**\n * BROWSER ONLY\n *\n * A browser only option to enable browser Streams. If this option is set and a response is a stream\n * the response will have a property `browserStream` instead of `blobBody` which will be undefined.\n *\n * Default value is false\n */\n enableBrowserStreams?: boolean;\n\n /** Settings for configuring TLS authentication */\n tlsSettings?: TlsSettings;\n}\n\n/**\n * Metadata about a response received by the pipeline.\n */\nexport interface PipelineResponse {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP status code of the response.\n */\n status: number;\n /**\n * The HTTP response headers.\n */\n headers: HttpHeaders;\n\n /**\n * The response body as text (string format)\n */\n bodyAsText?: string | null;\n\n /**\n * BROWSER ONLY\n *\n * The response body as a browser Blob.\n * Always undefined in node.js.\n */\n blobBody?: Promise<Blob>;\n\n /**\n * BROWSER ONLY\n *\n * The response body as a browser ReadableStream.\n * Always undefined in node.js.\n */\n browserStreamBody?: ReadableStream<Uint8Array>;\n\n /**\n * NODEJS ONLY\n *\n * The response body as a node.js Readable stream.\n * Always undefined in the browser.\n */\n readableStreamBody?: NodeJS.ReadableStream;\n}\n\n/**\n * A simple interface for making a pipeline request and receiving a response.\n */\nexport type SendRequest = (request: PipelineRequest) => Promise<PipelineResponse>;\n\n/**\n * The required interface for a client that makes HTTP requests\n * on behalf of a pipeline.\n */\nexport interface HttpClient {\n /**\n * The method that makes the request and returns a response.\n */\n sendRequest: SendRequest;\n}\n\n/**\n * Fired in response to upload or download progress.\n */\nexport type TransferProgressEvent = {\n /**\n * The number of bytes loaded so far.\n */\n loadedBytes: number;\n};\n\n// UNBRANDED DIFFERENCE: HttpMethods are defined at the top level in unbranded instead of core-util since we don't\n// need to worry about creating a cyclic dependency\n/**\n * Supported HTTP methods to use when making requests.\n */\nexport type HttpMethods =\n | \"GET\"\n | \"PUT\"\n | \"POST\"\n | \"DELETE\"\n | \"PATCH\"\n | \"HEAD\"\n | \"OPTIONS\"\n | \"TRACE\";\n\n/**\n * Options to configure a proxy for outgoing requests (Node.js only).\n */\nexport interface ProxySettings {\n /**\n * The proxy's host address.\n * Must include the protocol (e.g., http:// or https://).\n */\n host: string;\n\n /**\n * The proxy host's port.\n */\n port: number;\n\n /**\n * The user name to authenticate with the proxy, if required.\n */\n username?: string;\n\n /**\n * The password to authenticate with the proxy, if required.\n */\n password?: string;\n}\n\n/**\n * Each form data entry can be a string, Blob, or a File. If you wish to pass a file with a name but do not have\n * access to the File class, you can use the createFile helper to create one.\n */\nexport type FormDataValue = string | Blob | File;\n\n/**\n * A simple object that provides form data, as if from a browser form.\n */\nexport type FormDataMap = { [key: string]: FormDataValue | FormDataValue[] };\n\n/**\n * Options that control how to retry failed requests.\n */\nexport interface PipelineRetryOptions {\n /**\n * The maximum number of retry attempts. Defaults to 3.\n */\n maxRetries?: number;\n\n /**\n * The amount of delay in milliseconds between retry attempts. Defaults to 1000\n * (1 second). The delay increases exponentially with each retry up to a maximum\n * specified by maxRetryDelayInMs.\n */\n retryDelayInMs?: number;\n\n /**\n * The maximum delay in milliseconds allowed before retrying an operation. Defaults\n * to 64000 (64 seconds).\n */\n maxRetryDelayInMs?: number;\n}\n\n/**\n * Represents a certificate credential for authentication.\n */\nexport interface CertificateCredential {\n /**\n * Optionally override the trusted CA certificates. Default is to trust\n * the well-known CAs curated by Mozilla. Mozilla's CAs are completely\n * replaced when CAs are explicitly specified using this option.\n */\n ca?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Cert chains in PEM format. One cert chain should be provided per\n * private key. Each cert chain should consist of the PEM formatted\n * certificate for a provided private key, followed by the PEM\n * formatted intermediate certificates (if any), in order, and not\n * including the root CA (the root CA must be pre-known to the peer,\n * see ca). When providing multiple cert chains, they do not have to\n * be in the same order as their private keys in key. If the\n * intermediate certificates are not provided, the peer will not be\n * able to validate the certificate, and the handshake will fail.\n */\n cert?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Private keys in PEM format. PEM allows the option of private keys\n * being encrypted. Encrypted keys will be decrypted with\n * options.passphrase. Multiple keys using different algorithms can be\n * provided either as an array of unencrypted key strings or buffers,\n * or an array of objects in the form `{pem: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n key?: string | Buffer | Array<Buffer | KeyObject> | undefined;\n /**\n * Shared passphrase used for a single private key and/or a PFX.\n */\n passphrase?: string | undefined;\n /**\n * PFX or PKCS12 encoded private key and certificate chain. pfx is an\n * alternative to providing key and cert individually. PFX is usually\n * encrypted, if it is, passphrase will be used to decrypt it. Multiple\n * PFX can be provided either as an array of unencrypted PFX buffers,\n * or an array of objects in the form `{buf: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;\n}\n\n/**\n * Represents a certificate for TLS authentication.\n */\nexport interface TlsSettings {\n /**\n * Optionally override the trusted CA certificates. Default is to trust\n * the well-known CAs curated by Mozilla. Mozilla's CAs are completely\n * replaced when CAs are explicitly specified using this option.\n */\n ca?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Cert chains in PEM format. One cert chain should be provided per\n * private key. Each cert chain should consist of the PEM formatted\n * certificate for a provided private key, followed by the PEM\n * formatted intermediate certificates (if any), in order, and not\n * including the root CA (the root CA must be pre-known to the peer,\n * see ca). When providing multiple cert chains, they do not have to\n * be in the same order as their private keys in key. If the\n * intermediate certificates are not provided, the peer will not be\n * able to validate the certificate, and the handshake will fail.\n */\n cert?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Private keys in PEM format. PEM allows the option of private keys\n * being encrypted. Encrypted keys will be decrypted with\n * options.passphrase. Multiple keys using different algorithms can be\n * provided either as an array of unencrypted key strings or buffers,\n * or an array of objects in the form `{pem: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n key?: string | Buffer | Array<Buffer | KeyObject> | undefined;\n /**\n * Shared passphrase used for a single private key and/or a PFX.\n */\n passphrase?: string | undefined;\n /**\n * PFX or PKCS12 encoded private key and certificate chain. pfx is an\n * alternative to providing key and cert individually. PFX is usually\n * encrypted, if it is, passphrase will be used to decrypt it. Multiple\n * PFX can be provided either as an array of unencrypted PFX buffers,\n * or an array of objects in the form `{buf: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;\n}\n\n/**\n * An interface compatible with NodeJS's `tls.KeyObject`.\n * We want to avoid publicly re-exporting the actual interface,\n * since it might vary across runtime versions.\n */\nexport interface KeyObject {\n /**\n * Private keys in PEM format.\n */\n pem: string | Buffer;\n /**\n * Optional passphrase.\n */\n passphrase?: string | undefined;\n}\n\n/**\n * An interface compatible with NodeJS's `tls.PxfObject`.\n * We want to avoid publicly re-exporting the actual interface,\n * since it might vary across runtime versions.\n */\nexport interface PxfObject {\n /**\n * PFX or PKCS12 encoded private key and certificate chain.\n */\n buf: string | Buffer;\n /**\n * Optional passphrase.\n */\n passphrase?: string | undefined;\n}\n"]}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AuthScheme } from \"./auth/schemes.js\";\n\n/**\n * A HttpHeaders collection represented as a simple JSON object.\n */\nexport type RawHttpHeaders = { [headerName: string]: string };\n\n/**\n * A HttpHeaders collection for input, represented as a simple JSON object.\n */\nexport type RawHttpHeadersInput = Record<string, string | number | boolean>;\n\n/**\n * Represents a set of HTTP headers on a request/response.\n * Header names are treated as case insensitive.\n */\nexport interface HttpHeaders extends Iterable<[string, string]> {\n /**\n * Returns the value of a specific header or undefined if not set.\n * @param name - The name of the header to retrieve.\n */\n get(name: string): string | undefined;\n /**\n * Returns true if the specified header exists.\n * @param name - The name of the header to check.\n */\n has(name: string): boolean;\n /**\n * Sets a specific header with a given value.\n * @param name - The name of the header to set.\n * @param value - The value to use for the header.\n */\n set(name: string, value: string | number | boolean): void;\n /**\n * Removes a specific header from the collection.\n * @param name - The name of the header to delete.\n */\n delete(name: string): void;\n /**\n * Accesses a raw JS object that acts as a simple map\n * of header names to values.\n */\n toJSON(options?: { preserveCase?: boolean }): RawHttpHeaders;\n}\n\n/**\n * A part of the request body in a multipart request.\n */\nexport interface BodyPart {\n /**\n * The headers for this part of the multipart request.\n */\n headers: HttpHeaders;\n\n /**\n * The body of this part of the multipart request.\n */\n body:\n | ((() => ReadableStream<Uint8Array>) | (() => NodeJS.ReadableStream))\n | ReadableStream<Uint8Array>\n | NodeJS.ReadableStream\n | Uint8Array\n | Blob;\n}\n\n/**\n * A request body consisting of multiple parts.\n */\nexport interface MultipartRequestBody {\n /**\n * The parts of the request body.\n */\n parts: BodyPart[];\n\n /**\n * The boundary separating each part of the request body.\n * If not specified, a random boundary will be generated.\n *\n * When specified, '--' will be prepended to the boundary in the request to ensure the boundary follows the specification.\n */\n boundary?: string;\n}\n\n/**\n * Types of bodies supported on the request.\n * NodeJS.ReadableStream and () =\\> NodeJS.ReadableStream is Node only.\n * Blob, ReadableStream<Uint8Array>, and () =\\> ReadableStream<Uint8Array> are browser only.\n */\nexport type RequestBodyType =\n | NodeJS.ReadableStream\n | (() => NodeJS.ReadableStream)\n | ReadableStream<Uint8Array>\n | (() => ReadableStream<Uint8Array>)\n | Blob\n | ArrayBuffer\n | ArrayBufferView\n | FormData\n | string\n | null;\n\n/**\n * An interface compatible with NodeJS's `http.Agent`.\n * We want to avoid publicly re-exporting the actual interface,\n * since it might vary across runtime versions.\n */\nexport interface Agent {\n /**\n * Destroy any sockets that are currently in use by the agent.\n */\n destroy(): void;\n /**\n * For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state.\n */\n maxFreeSockets: number;\n /**\n * Determines how many concurrent sockets the agent can have open per origin.\n */\n maxSockets: number;\n /**\n * An object which contains queues of requests that have not yet been assigned to sockets.\n */\n requests: unknown;\n /**\n * An object which contains arrays of sockets currently in use by the agent.\n */\n sockets: unknown;\n}\n\n/**\n * Metadata about a request being made by the pipeline.\n */\nexport interface PipelineRequest {\n /**\n * List of authentication schemes used for this specific request.\n * These schemes define how the request will be authenticated.\n * If provided, these schemes override the client level authentication schemes.\n *\n * If no auth schemes are provided at client or request level, defaults to no auth.\n */\n authSchemes?: AuthScheme[];\n\n /**\n * The URL to make the request to.\n */\n url: string;\n\n /**\n * The HTTP method to use when making the request.\n */\n method: HttpMethods;\n\n /**\n * The HTTP headers to use when making the request.\n */\n headers: HttpHeaders;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n * If the request is terminated, an `AbortError` is thrown.\n * Defaults to 0, which disables the timeout.\n */\n timeout: number;\n\n /**\n * Indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests.\n * Defaults to false.\n */\n withCredentials: boolean;\n\n /**\n * A unique identifier for the request. Used for logging and tracing.\n */\n requestId: string;\n\n /**\n * The HTTP body content (if any)\n */\n body?: RequestBodyType;\n\n /**\n * Body for a multipart request.\n */\n multipartBody?: MultipartRequestBody;\n\n /**\n * To simulate a browser form post\n */\n formData?: FormDataMap;\n\n /**\n * A list of response status codes whose corresponding PipelineResponse body should be treated as a stream.\n * When streamResponseStatusCodes contains the value Number.POSITIVE_INFINITY any status would be treated as a stream.\n */\n streamResponseStatusCodes?: Set<number>;\n\n /**\n * Proxy configuration.\n */\n proxySettings?: ProxySettings;\n\n /**\n * If the connection should not be reused.\n */\n disableKeepAlive?: boolean;\n\n /**\n * Used to abort the request later.\n */\n abortSignal?: AbortSignal;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Callback which fires upon download progress. */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n\n /**\n * NODEJS ONLY\n *\n * A Node-only option to provide a custom `http.Agent`/`https.Agent`.\n * Does nothing when running in the browser.\n */\n agent?: Agent;\n\n /**\n * BROWSER ONLY\n *\n * A browser only option to enable browser Streams. If this option is set and a response is a stream\n * the response will have a property `browserStream` instead of `blobBody` which will be undefined.\n *\n * Default value is false\n */\n enableBrowserStreams?: boolean;\n\n /** Settings for configuring TLS authentication */\n tlsSettings?: TlsSettings;\n\n /**\n * Additional options to set on the request. This provides a way to override\n * existing ones or provide request properties that are not declared.\n *\n * For possible valid properties, see\n * - NodeJS https.request options: https://nodejs.org/api/http.html#httprequestoptions-callback\n * - Browser RequestInit: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit\n *\n * WARNING: Options specified here will override any properties of same names when request is sent by {@link HttpClient}.\n */\n requestOverrides?: Record<string, unknown>;\n}\n\n/**\n * Metadata about a response received by the pipeline.\n */\nexport interface PipelineResponse {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP status code of the response.\n */\n status: number;\n /**\n * The HTTP response headers.\n */\n headers: HttpHeaders;\n\n /**\n * The response body as text (string format)\n */\n bodyAsText?: string | null;\n\n /**\n * BROWSER ONLY\n *\n * The response body as a browser Blob.\n * Always undefined in node.js.\n */\n blobBody?: Promise<Blob>;\n\n /**\n * BROWSER ONLY\n *\n * The response body as a browser ReadableStream.\n * Always undefined in node.js.\n */\n browserStreamBody?: ReadableStream<Uint8Array>;\n\n /**\n * NODEJS ONLY\n *\n * The response body as a node.js Readable stream.\n * Always undefined in the browser.\n */\n readableStreamBody?: NodeJS.ReadableStream;\n}\n\n/**\n * A simple interface for making a pipeline request and receiving a response.\n */\nexport type SendRequest = (request: PipelineRequest) => Promise<PipelineResponse>;\n\n/**\n * The required interface for a client that makes HTTP requests\n * on behalf of a pipeline.\n */\nexport interface HttpClient {\n /**\n * The method that makes the request and returns a response.\n */\n sendRequest: SendRequest;\n}\n\n/**\n * Fired in response to upload or download progress.\n */\nexport type TransferProgressEvent = {\n /**\n * The number of bytes loaded so far.\n */\n loadedBytes: number;\n};\n\n// UNBRANDED DIFFERENCE: HttpMethods are defined at the top level in unbranded instead of core-util since we don't\n// need to worry about creating a cyclic dependency\n/**\n * Supported HTTP methods to use when making requests.\n */\nexport type HttpMethods =\n | \"GET\"\n | \"PUT\"\n | \"POST\"\n | \"DELETE\"\n | \"PATCH\"\n | \"HEAD\"\n | \"OPTIONS\"\n | \"TRACE\";\n\n/**\n * Options to configure a proxy for outgoing requests (Node.js only).\n */\nexport interface ProxySettings {\n /**\n * The proxy's host address.\n * Must include the protocol (e.g., http:// or https://).\n */\n host: string;\n\n /**\n * The proxy host's port.\n */\n port: number;\n\n /**\n * The user name to authenticate with the proxy, if required.\n */\n username?: string;\n\n /**\n * The password to authenticate with the proxy, if required.\n */\n password?: string;\n}\n\n/**\n * Each form data entry can be a string, Blob, or a File. If you wish to pass a file with a name but do not have\n * access to the File class, you can use the createFile helper to create one.\n */\nexport type FormDataValue = string | Blob | File;\n\n/**\n * A simple object that provides form data, as if from a browser form.\n */\nexport type FormDataMap = { [key: string]: FormDataValue | FormDataValue[] };\n\n/**\n * Options that control how to retry failed requests.\n */\nexport interface PipelineRetryOptions {\n /**\n * The maximum number of retry attempts. Defaults to 3.\n */\n maxRetries?: number;\n\n /**\n * The amount of delay in milliseconds between retry attempts. Defaults to 1000\n * (1 second). The delay increases exponentially with each retry up to a maximum\n * specified by maxRetryDelayInMs.\n */\n retryDelayInMs?: number;\n\n /**\n * The maximum delay in milliseconds allowed before retrying an operation. Defaults\n * to 64000 (64 seconds).\n */\n maxRetryDelayInMs?: number;\n}\n\n/**\n * Represents a certificate credential for authentication.\n */\nexport interface CertificateCredential {\n /**\n * Optionally override the trusted CA certificates. Default is to trust\n * the well-known CAs curated by Mozilla. Mozilla's CAs are completely\n * replaced when CAs are explicitly specified using this option.\n */\n ca?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Cert chains in PEM format. One cert chain should be provided per\n * private key. Each cert chain should consist of the PEM formatted\n * certificate for a provided private key, followed by the PEM\n * formatted intermediate certificates (if any), in order, and not\n * including the root CA (the root CA must be pre-known to the peer,\n * see ca). When providing multiple cert chains, they do not have to\n * be in the same order as their private keys in key. If the\n * intermediate certificates are not provided, the peer will not be\n * able to validate the certificate, and the handshake will fail.\n */\n cert?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Private keys in PEM format. PEM allows the option of private keys\n * being encrypted. Encrypted keys will be decrypted with\n * options.passphrase. Multiple keys using different algorithms can be\n * provided either as an array of unencrypted key strings or buffers,\n * or an array of objects in the form `{pem: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n key?: string | Buffer | Array<Buffer | KeyObject> | undefined;\n /**\n * Shared passphrase used for a single private key and/or a PFX.\n */\n passphrase?: string | undefined;\n /**\n * PFX or PKCS12 encoded private key and certificate chain. pfx is an\n * alternative to providing key and cert individually. PFX is usually\n * encrypted, if it is, passphrase will be used to decrypt it. Multiple\n * PFX can be provided either as an array of unencrypted PFX buffers,\n * or an array of objects in the form `{buf: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;\n}\n\n/**\n * Represents a certificate for TLS authentication.\n */\nexport interface TlsSettings {\n /**\n * Optionally override the trusted CA certificates. Default is to trust\n * the well-known CAs curated by Mozilla. Mozilla's CAs are completely\n * replaced when CAs are explicitly specified using this option.\n */\n ca?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Cert chains in PEM format. One cert chain should be provided per\n * private key. Each cert chain should consist of the PEM formatted\n * certificate for a provided private key, followed by the PEM\n * formatted intermediate certificates (if any), in order, and not\n * including the root CA (the root CA must be pre-known to the peer,\n * see ca). When providing multiple cert chains, they do not have to\n * be in the same order as their private keys in key. If the\n * intermediate certificates are not provided, the peer will not be\n * able to validate the certificate, and the handshake will fail.\n */\n cert?: string | Buffer | Array<string | Buffer> | undefined;\n /**\n * Private keys in PEM format. PEM allows the option of private keys\n * being encrypted. Encrypted keys will be decrypted with\n * options.passphrase. Multiple keys using different algorithms can be\n * provided either as an array of unencrypted key strings or buffers,\n * or an array of objects in the form `{pem: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n key?: string | Buffer | Array<Buffer | KeyObject> | undefined;\n /**\n * Shared passphrase used for a single private key and/or a PFX.\n */\n passphrase?: string | undefined;\n /**\n * PFX or PKCS12 encoded private key and certificate chain. pfx is an\n * alternative to providing key and cert individually. PFX is usually\n * encrypted, if it is, passphrase will be used to decrypt it. Multiple\n * PFX can be provided either as an array of unencrypted PFX buffers,\n * or an array of objects in the form `{buf: <string|buffer>[,passphrase: <string>]}`.\n * The object form can only occur in an array.object.passphrase is optional.\n * Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.\n */\n pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;\n}\n\n/**\n * An interface compatible with NodeJS's `tls.KeyObject`.\n * We want to avoid publicly re-exporting the actual interface,\n * since it might vary across runtime versions.\n */\nexport interface KeyObject {\n /**\n * Private keys in PEM format.\n */\n pem: string | Buffer;\n /**\n * Optional passphrase.\n */\n passphrase?: string | undefined;\n}\n\n/**\n * An interface compatible with NodeJS's `tls.PxfObject`.\n * We want to avoid publicly re-exporting the actual interface,\n * since it might vary across runtime versions.\n */\nexport interface PxfObject {\n /**\n * PFX or PKCS12 encoded private key and certificate chain.\n */\n buf: string | Buffer;\n /**\n * Optional passphrase.\n */\n passphrase?: string | undefined;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export { createLoggerContext, type CreateLoggerContextOptions, type LoggerContext, } from "./logger.js";
2
+ //# sourceMappingURL=internal.d.ts.map
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ export { createLoggerContext, } from "./logger.js";
4
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/logger/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,mBAAmB,GAGpB,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n createLoggerContext,\n type CreateLoggerContextOptions,\n type LoggerContext,\n} from \"./logger.js\";\n"]}
@@ -1,11 +1,5 @@
1
1
  import type { Debugger } from "./debug.js";
2
- export { Debugger } from "./debug.js";
3
- /**
4
- * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.
5
- * By default, logs are sent to stderr.
6
- * Override the `log` method to redirect logs to another location.
7
- */
8
- export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
2
+ export type { Debugger };
9
3
  /**
10
4
  * The log levels supported by the logger.
11
5
  * The log levels in order of most verbose to least verbose are:
@@ -16,23 +10,9 @@ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
16
10
  */
17
11
  export type TypeSpecRuntimeLogLevel = "verbose" | "info" | "warning" | "error";
18
12
  /**
19
- * An TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
13
+ * A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
20
14
  */
21
15
  export type TypeSpecRuntimeClientLogger = Debugger;
22
- /**
23
- * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
24
- * @param level - The log level to enable for logging.
25
- * Options from most verbose to least verbose are:
26
- * - verbose
27
- * - info
28
- * - warning
29
- * - error
30
- */
31
- export declare function setLogLevel(level?: TypeSpecRuntimeLogLevel): void;
32
- /**
33
- * Retrieves the currently specified log level.
34
- */
35
- export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
36
16
  /**
37
17
  * Defines the methods available on the SDK-facing logger.
38
18
  */
@@ -59,6 +39,74 @@ export interface TypeSpecRuntimeLogger {
59
39
  */
60
40
  verbose: Debugger;
61
41
  }
42
+ /**
43
+ * todo doc
44
+ */
45
+ export interface LoggerContext {
46
+ /**
47
+ * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
48
+ * @param level - The log level to enable for logging.
49
+ * Options from most verbose to least verbose are:
50
+ * - verbose
51
+ * - info
52
+ * - warning
53
+ * - error
54
+ */
55
+ setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
56
+ /**
57
+ * Retrieves the currently specified log level.
58
+ */
59
+ getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
60
+ /**
61
+ * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
62
+ * @param namespace - The name of the SDK package.
63
+ * @hidden
64
+ */
65
+ createClientLogger(namespace: string): TypeSpecRuntimeLogger;
66
+ /**
67
+ * The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.
68
+ * By default, logs are sent to stderr.
69
+ * Override the `log` method to redirect logs to another location.
70
+ */
71
+ logger: TypeSpecRuntimeClientLogger;
72
+ }
73
+ /**
74
+ * Option for creating a TypeSpecRuntimeLoggerContext.
75
+ */
76
+ export interface CreateLoggerContextOptions {
77
+ /**
78
+ * The name of the environment variable to check for the log level.
79
+ */
80
+ logLevelEnvVarName: string;
81
+ /**
82
+ * The namespace of the logger.
83
+ */
84
+ namespace: string;
85
+ }
86
+ /**
87
+ * Creates a logger context base on the provided options.
88
+ * @param options - The options for creating a logger context.
89
+ * @returns The logger context.
90
+ */
91
+ export declare function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext;
92
+ /**
93
+ * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
94
+ * @param level - The log level to enable for logging.
95
+ * Options from most verbose to least verbose are:
96
+ * - verbose
97
+ * - info
98
+ * - warning
99
+ * - error
100
+ */
101
+ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
102
+ /**
103
+ * Retrieves the currently specified log level.
104
+ */
105
+ export declare function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
106
+ /**
107
+ * Retrieves the currently specified log level.
108
+ */
109
+ export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
62
110
  /**
63
111
  * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
64
112
  * @param namespace - The name of the SDK package.
@@ -1,29 +1,93 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  import debug from "./debug.js";
4
- const registeredLoggers = new Set();
5
- const logLevelFromEnv = (typeof process !== "undefined" && process.env && process.env.TYPESPEC_RUNTIME_LOG_LEVEL) ||
6
- undefined;
7
- let typeSpecRuntimeLogLevel;
4
+ const TYPESPEC_RUNTIME_LOG_LEVELS = ["verbose", "info", "warning", "error"];
5
+ const levelMap = {
6
+ verbose: 400,
7
+ info: 300,
8
+ warning: 200,
9
+ error: 100,
10
+ };
11
+ function patchLogMethod(parent, child) {
12
+ child.log = (...args) => {
13
+ parent.log(...args);
14
+ };
15
+ }
16
+ function isTypeSpecRuntimeLogLevel(level) {
17
+ return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level);
18
+ }
8
19
  /**
9
- * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.
10
- * By default, logs are sent to stderr.
11
- * Override the `log` method to redirect logs to another location.
20
+ * Creates a logger context base on the provided options.
21
+ * @param options - The options for creating a logger context.
22
+ * @returns The logger context.
12
23
  */
13
- export const TypeSpecRuntimeLogger = debug("typeSpecRuntime");
14
- TypeSpecRuntimeLogger.log = (...args) => {
15
- debug.log(...args);
16
- };
17
- const TYPESPEC_RUNTIME_LOG_LEVELS = ["verbose", "info", "warning", "error"];
18
- if (logLevelFromEnv) {
19
- // avoid calling setLogLevel because we don't want a mis-set environment variable to crash
20
- if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {
21
- setLogLevel(logLevelFromEnv);
24
+ export function createLoggerContext(options) {
25
+ const registeredLoggers = new Set();
26
+ const logLevelFromEnv = (typeof process !== "undefined" && process.env && process.env[options.logLevelEnvVarName]) ||
27
+ undefined;
28
+ let logLevel;
29
+ const clientLogger = debug(options.namespace);
30
+ clientLogger.log = (...args) => {
31
+ debug.log(...args);
32
+ };
33
+ if (logLevelFromEnv) {
34
+ // avoid calling setLogLevel because we don't want a mis-set environment variable to crash
35
+ if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {
36
+ setLogLevel(logLevelFromEnv);
37
+ }
38
+ else {
39
+ console.error(`${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
40
+ }
22
41
  }
23
- else {
24
- console.error(`TYPESPEC_RUNTIME_LOG_LEVEL set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
42
+ function shouldEnable(logger) {
43
+ return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);
25
44
  }
45
+ function createLogger(parent, level) {
46
+ const logger = Object.assign(parent.extend(level), {
47
+ level,
48
+ });
49
+ patchLogMethod(parent, logger);
50
+ if (shouldEnable(logger)) {
51
+ const enabledNamespaces = debug.disable();
52
+ debug.enable(enabledNamespaces + "," + logger.namespace);
53
+ }
54
+ registeredLoggers.add(logger);
55
+ return logger;
56
+ }
57
+ return {
58
+ setLogLevel(level) {
59
+ if (level && !isTypeSpecRuntimeLogLevel(level)) {
60
+ throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
61
+ }
62
+ logLevel = level;
63
+ const enabledNamespaces = [];
64
+ for (const logger of registeredLoggers) {
65
+ if (shouldEnable(logger)) {
66
+ enabledNamespaces.push(logger.namespace);
67
+ }
68
+ }
69
+ debug.enable(enabledNamespaces.join(","));
70
+ },
71
+ getLogLevel() {
72
+ return logLevel;
73
+ },
74
+ createClientLogger(namespace) {
75
+ const clientRootLogger = clientLogger.extend(namespace);
76
+ patchLogMethod(clientLogger, clientRootLogger);
77
+ return {
78
+ error: createLogger(clientRootLogger, "error"),
79
+ warning: createLogger(clientRootLogger, "warning"),
80
+ info: createLogger(clientRootLogger, "info"),
81
+ verbose: createLogger(clientRootLogger, "verbose"),
82
+ };
83
+ },
84
+ logger: clientLogger,
85
+ };
26
86
  }
87
+ const context = createLoggerContext({
88
+ logLevelEnvVarName: "TYPESPEC_RUNTIME_LOG_LEVEL",
89
+ namespace: "typeSpecRuntime",
90
+ });
27
91
  /**
28
92
  * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
29
93
  * @param level - The log level to enable for logging.
@@ -33,67 +97,26 @@ if (logLevelFromEnv) {
33
97
  * - warning
34
98
  * - error
35
99
  */
36
- export function setLogLevel(level) {
37
- if (level && !isTypeSpecRuntimeLogLevel(level)) {
38
- throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
39
- }
40
- typeSpecRuntimeLogLevel = level;
41
- const enabledNamespaces = [];
42
- for (const logger of registeredLoggers) {
43
- if (shouldEnable(logger)) {
44
- enabledNamespaces.push(logger.namespace);
45
- }
46
- }
47
- debug.enable(enabledNamespaces.join(","));
100
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
101
+ export const TypeSpecRuntimeLogger = context.logger;
102
+ /**
103
+ * Retrieves the currently specified log level.
104
+ */
105
+ export function setLogLevel(logLevel) {
106
+ context.setLogLevel(logLevel);
48
107
  }
49
108
  /**
50
109
  * Retrieves the currently specified log level.
51
110
  */
52
111
  export function getLogLevel() {
53
- return typeSpecRuntimeLogLevel;
112
+ return context.getLogLevel();
54
113
  }
55
- const levelMap = {
56
- verbose: 400,
57
- info: 300,
58
- warning: 200,
59
- error: 100,
60
- };
61
114
  /**
62
115
  * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
63
116
  * @param namespace - The name of the SDK package.
64
117
  * @hidden
65
118
  */
66
119
  export function createClientLogger(namespace) {
67
- const clientRootLogger = TypeSpecRuntimeLogger.extend(namespace);
68
- patchLogMethod(TypeSpecRuntimeLogger, clientRootLogger);
69
- return {
70
- error: createLogger(clientRootLogger, "error"),
71
- warning: createLogger(clientRootLogger, "warning"),
72
- info: createLogger(clientRootLogger, "info"),
73
- verbose: createLogger(clientRootLogger, "verbose"),
74
- };
75
- }
76
- function patchLogMethod(parent, child) {
77
- child.log = (...args) => {
78
- parent.log(...args);
79
- };
80
- }
81
- function createLogger(parent, level) {
82
- const logger = Object.assign(parent.extend(level), {
83
- level,
84
- });
85
- patchLogMethod(parent, logger);
86
- if (shouldEnable(logger)) {
87
- const enabledNamespaces = debug.disable();
88
- debug.enable(enabledNamespaces + "," + logger.namespace);
89
- }
90
- registeredLoggers.add(logger);
91
- return logger;
92
- }
93
- function shouldEnable(logger) {
94
- return Boolean(typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel]);
95
- }
96
- function isTypeSpecRuntimeLogLevel(logLevel) {
97
- return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel);
120
+ return context.createClientLogger(namespace);
98
121
  }
99
122
  //# sourceMappingURL=logger.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA2B,CAAC;AAC7D,MAAM,eAAe,GACnB,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;IACzF,SAAS,CAAC;AAEZ,IAAI,uBAA4D,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAgC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAC3F,qBAAqB,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;IACtC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC;AAWF,MAAM,2BAA2B,GAAG,CAAC,SAAS,EAAE,MAA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IACjD,OAAO,2BAA2B,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Debugger } from \"./debug.js\";\nimport debug from \"./debug.js\";\nexport { Debugger } from \"./debug.js\";\n\nconst registeredLoggers = new Set<TypeSpecRuntimeDebugger>();\nconst logLevelFromEnv =\n (typeof process !== \"undefined\" && process.env && process.env.TYPESPEC_RUNTIME_LOG_LEVEL) ||\n undefined;\n\nlet typeSpecRuntimeLogLevel: TypeSpecRuntimeLogLevel | undefined;\n\n/**\n * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.\n * By default, logs are sent to stderr.\n * Override the `log` method to redirect logs to another location.\n */\nexport const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger = debug(\"typeSpecRuntime\");\nTypeSpecRuntimeLogger.log = (...args) => {\n debug.log(...args);\n};\n\n/**\n * The log levels supported by the logger.\n * The log levels in order of most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport type TypeSpecRuntimeLogLevel = \"verbose\" | \"info\" | \"warning\" | \"error\";\nconst TYPESPEC_RUNTIME_LOG_LEVELS = [\"verbose\", \"info\", \"warning\", \"error\"];\n\ntype TypeSpecRuntimeDebugger = Debugger & { level: TypeSpecRuntimeLogLevel };\n\n/**\n * An TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.\n */\nexport type TypeSpecRuntimeClientLogger = Debugger;\n\nif (logLevelFromEnv) {\n // avoid calling setLogLevel because we don't want a mis-set environment variable to crash\n if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {\n setLogLevel(logLevelFromEnv);\n } else {\n console.error(\n `TYPESPEC_RUNTIME_LOG_LEVEL set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\n \", \",\n )}.`,\n );\n }\n}\n\n/**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport function setLogLevel(level?: TypeSpecRuntimeLogLevel): void {\n if (level && !isTypeSpecRuntimeLogLevel(level)) {\n throw new Error(\n `Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\",\")}`,\n );\n }\n typeSpecRuntimeLogLevel = level;\n\n const enabledNamespaces = [];\n for (const logger of registeredLoggers) {\n if (shouldEnable(logger)) {\n enabledNamespaces.push(logger.namespace);\n }\n }\n\n debug.enable(enabledNamespaces.join(\",\"));\n}\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return typeSpecRuntimeLogLevel;\n}\n\nconst levelMap = {\n verbose: 400,\n info: 300,\n warning: 200,\n error: 100,\n};\n\n/**\n * Defines the methods available on the SDK-facing logger.\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport interface TypeSpecRuntimeLogger {\n /**\n * Used for failures the program is unlikely to recover from,\n * such as Out of Memory.\n */\n error: Debugger;\n /**\n * Used when a function fails to perform its intended task.\n * Usually this means the function will throw an exception.\n * Not used for self-healing events (e.g. automatic retry)\n */\n warning: Debugger;\n /**\n * Used when a function operates normally.\n */\n info: Debugger;\n /**\n * Used for detailed troubleshooting scenarios. This is\n * intended for use by developers / system administrators\n * for diagnosing specific failures.\n */\n verbose: Debugger;\n}\n\n/**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\nexport function createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n const clientRootLogger: TypeSpecRuntimeClientLogger = TypeSpecRuntimeLogger.extend(namespace);\n patchLogMethod(TypeSpecRuntimeLogger, clientRootLogger);\n return {\n error: createLogger(clientRootLogger, \"error\"),\n warning: createLogger(clientRootLogger, \"warning\"),\n info: createLogger(clientRootLogger, \"info\"),\n verbose: createLogger(clientRootLogger, \"verbose\"),\n };\n}\n\nfunction patchLogMethod(\n parent: TypeSpecRuntimeClientLogger,\n child: TypeSpecRuntimeClientLogger | TypeSpecRuntimeDebugger,\n): void {\n child.log = (...args) => {\n parent.log(...args);\n };\n}\n\nfunction createLogger(\n parent: TypeSpecRuntimeClientLogger,\n level: TypeSpecRuntimeLogLevel,\n): TypeSpecRuntimeDebugger {\n const logger: TypeSpecRuntimeDebugger = Object.assign(parent.extend(level), {\n level,\n });\n\n patchLogMethod(parent, logger);\n\n if (shouldEnable(logger)) {\n const enabledNamespaces = debug.disable();\n debug.enable(enabledNamespaces + \",\" + logger.namespace);\n }\n\n registeredLoggers.add(logger);\n\n return logger;\n}\n\nfunction shouldEnable(logger: TypeSpecRuntimeDebugger): boolean {\n return Boolean(\n typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel],\n );\n}\n\nfunction isTypeSpecRuntimeLogLevel(logLevel: string): logLevel is TypeSpecRuntimeLogLevel {\n return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel as any);\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,KAAK,MAAM,YAAY,CAAC;AAiG/B,MAAM,2BAA2B,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAI5E,MAAM,QAAQ,GAAG;IACf,OAAO,EAAE,GAAG;IACZ,IAAI,EAAE,GAAG;IACT,OAAO,EAAE,GAAG;IACZ,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,SAAS,cAAc,CACrB,MAAmC,EACnC,KAAyD;IAEzD,KAAK,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;IACtB,CAAC,CAAC;AACJ,CAAC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B,EAAE,SAAS,CAAC;gBAClD,IAAI,EAAE,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC;gBAC5C,OAAO,EAAE,YAAY,CAAC,gBAAgB,EAAE,SAAS,CAAC;aACnD,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,YAAY;KACrB,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,GAAG,mBAAmB,CAAC;IAClC,kBAAkB,EAAE,4BAA4B;IAChD,SAAS,EAAE,iBAAiB;CAC7B,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,qBAAqB,GAAgC,OAAO,CAAC,MAAM,CAAC;AAEjF;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,QAAkC;IAC5D,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,OAAO,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport debug from \"./debug.js\";\n\nimport type { Debugger } from \"./debug.js\";\nexport type { Debugger };\n\n/**\n * The log levels supported by the logger.\n * The log levels in order of most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport type TypeSpecRuntimeLogLevel = \"verbose\" | \"info\" | \"warning\" | \"error\";\n\n/**\n * A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.\n */\nexport type TypeSpecRuntimeClientLogger = Debugger;\n\n/**\n * Defines the methods available on the SDK-facing logger.\n */\nexport interface TypeSpecRuntimeLogger {\n /**\n * Used for failures the program is unlikely to recover from,\n * such as Out of Memory.\n */\n error: Debugger;\n /**\n * Used when a function fails to perform its intended task.\n * Usually this means the function will throw an exception.\n * Not used for self-healing events (e.g. automatic retry)\n */\n warning: Debugger;\n /**\n * Used when a function operates normally.\n */\n info: Debugger;\n /**\n * Used for detailed troubleshooting scenarios. This is\n * intended for use by developers / system administrators\n * for diagnosing specific failures.\n */\n verbose: Debugger;\n}\n\n/**\n * todo doc\n */\nexport interface LoggerContext {\n /**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\n setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;\n\n /**\n * Retrieves the currently specified log level.\n */\n getLogLevel(): TypeSpecRuntimeLogLevel | undefined;\n\n /**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\n createClientLogger(namespace: string): TypeSpecRuntimeLogger;\n\n /**\n * The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.\n * By default, logs are sent to stderr.\n * Override the `log` method to redirect logs to another location.\n */\n logger: TypeSpecRuntimeClientLogger;\n}\n\n/**\n * Option for creating a TypeSpecRuntimeLoggerContext.\n */\nexport interface CreateLoggerContextOptions {\n /**\n * The name of the environment variable to check for the log level.\n */\n logLevelEnvVarName: string;\n\n /**\n * The namespace of the logger.\n */\n namespace: string;\n}\n\nconst TYPESPEC_RUNTIME_LOG_LEVELS = [\"verbose\", \"info\", \"warning\", \"error\"];\n\ntype DebuggerWithLogLevel = Debugger & { level: TypeSpecRuntimeLogLevel };\n\nconst levelMap = {\n verbose: 400,\n info: 300,\n warning: 200,\n error: 100,\n};\n\nfunction patchLogMethod(\n parent: TypeSpecRuntimeClientLogger,\n child: TypeSpecRuntimeClientLogger | DebuggerWithLogLevel,\n): void {\n child.log = (...args) => {\n parent.log(...args);\n };\n}\n\nfunction isTypeSpecRuntimeLogLevel(level: string): level is TypeSpecRuntimeLogLevel {\n return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level as any);\n}\n\n/**\n * Creates a logger context base on the provided options.\n * @param options - The options for creating a logger context.\n * @returns The logger context.\n */\nexport function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext {\n const registeredLoggers = new Set<DebuggerWithLogLevel>();\n const logLevelFromEnv =\n (typeof process !== \"undefined\" && process.env && process.env[options.logLevelEnvVarName]) ||\n undefined;\n\n let logLevel: TypeSpecRuntimeLogLevel | undefined;\n\n const clientLogger: TypeSpecRuntimeClientLogger = debug(options.namespace);\n clientLogger.log = (...args) => {\n debug.log(...args);\n };\n\n if (logLevelFromEnv) {\n // avoid calling setLogLevel because we don't want a mis-set environment variable to crash\n if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {\n setLogLevel(logLevelFromEnv);\n } else {\n console.error(\n `${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\n \", \",\n )}.`,\n );\n }\n }\n\n function shouldEnable(logger: DebuggerWithLogLevel): boolean {\n return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);\n }\n\n function createLogger(\n parent: TypeSpecRuntimeClientLogger,\n level: TypeSpecRuntimeLogLevel,\n ): DebuggerWithLogLevel {\n const logger: DebuggerWithLogLevel = Object.assign(parent.extend(level), {\n level,\n });\n\n patchLogMethod(parent, logger);\n\n if (shouldEnable(logger)) {\n const enabledNamespaces = debug.disable();\n debug.enable(enabledNamespaces + \",\" + logger.namespace);\n }\n\n registeredLoggers.add(logger);\n\n return logger;\n }\n\n return {\n setLogLevel(level?: TypeSpecRuntimeLogLevel): void {\n if (level && !isTypeSpecRuntimeLogLevel(level)) {\n throw new Error(\n `Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\",\")}`,\n );\n }\n logLevel = level;\n\n const enabledNamespaces = [];\n for (const logger of registeredLoggers) {\n if (shouldEnable(logger)) {\n enabledNamespaces.push(logger.namespace);\n }\n }\n\n debug.enable(enabledNamespaces.join(\",\"));\n },\n getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return logLevel;\n },\n createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n const clientRootLogger: TypeSpecRuntimeClientLogger = clientLogger.extend(namespace);\n patchLogMethod(clientLogger, clientRootLogger);\n return {\n error: createLogger(clientRootLogger, \"error\"),\n warning: createLogger(clientRootLogger, \"warning\"),\n info: createLogger(clientRootLogger, \"info\"),\n verbose: createLogger(clientRootLogger, \"verbose\"),\n };\n },\n logger: clientLogger,\n };\n}\n\nconst context = createLoggerContext({\n logLevelEnvVarName: \"TYPESPEC_RUNTIME_LOG_LEVEL\",\n namespace: \"typeSpecRuntime\",\n});\n\n/**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger = context.logger;\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void {\n context.setLogLevel(logLevel);\n}\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return context.getLogLevel();\n}\n\n/**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\nexport function createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n return context.createClientLogger(namespace);\n}\n"]}