@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.
- package/README.md +1 -1
- package/dist/browser/client/common.d.ts +6 -0
- package/dist/browser/client/common.js.map +1 -1
- package/dist/browser/client/getClient.js +4 -4
- package/dist/browser/client/getClient.js.map +1 -1
- package/dist/browser/client/restError.js +1 -1
- package/dist/browser/client/restError.js.map +1 -1
- package/dist/browser/constants.js +1 -1
- package/dist/browser/constants.js.map +1 -1
- package/dist/browser/fetchHttpClient.js +1 -1
- package/dist/browser/fetchHttpClient.js.map +1 -1
- package/dist/browser/index.d.ts +3 -2
- package/dist/browser/index.js +3 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/interfaces.d.ts +11 -0
- package/dist/browser/interfaces.js.map +1 -1
- package/dist/browser/logger/internal.d.ts +2 -0
- package/dist/browser/logger/internal.js +4 -0
- package/dist/browser/logger/internal.js.map +1 -0
- package/dist/browser/logger/logger.d.ts +70 -22
- package/dist/browser/logger/logger.js +91 -68
- package/dist/browser/logger/logger.js.map +1 -1
- package/dist/browser/nodeHttpClient.js +1 -8
- package/dist/browser/nodeHttpClient.js.map +1 -1
- package/dist/browser/pipelineRequest.d.ts +11 -0
- package/dist/browser/pipelineRequest.js +1 -0
- package/dist/browser/pipelineRequest.js.map +1 -1
- package/dist/browser/policies/internal.d.ts +16 -0
- package/dist/browser/policies/internal.js +17 -0
- package/dist/browser/policies/internal.js.map +1 -0
- package/dist/browser/policies/retryPolicy.js +2 -2
- package/dist/browser/policies/retryPolicy.js.map +1 -1
- package/dist/browser/util/checkEnvironment.d.ts +0 -5
- package/dist/browser/util/checkEnvironment.js +0 -5
- package/dist/browser/util/checkEnvironment.js.map +1 -1
- package/dist/browser/util/concat.common.js +3 -10
- package/dist/browser/util/concat.common.js.map +1 -1
- package/dist/browser/util/delay.d.ts +0 -13
- package/dist/browser/util/delay.js +0 -19
- package/dist/browser/util/delay.js.map +1 -1
- package/dist/browser/util/error.d.ts +0 -7
- package/dist/browser/util/error.js +0 -26
- package/dist/browser/util/error.js.map +1 -1
- package/dist/browser/util/internal.d.ts +10 -0
- package/dist/browser/util/internal.js +12 -0
- package/dist/browser/util/internal.js.map +1 -0
- package/dist/browser/util/sanitizer.d.ts +12 -2
- package/dist/browser/util/sanitizer.js +11 -1
- package/dist/browser/util/sanitizer.js.map +1 -1
- package/dist/browser/util/typeGuards.d.ts +0 -17
- package/dist/browser/util/typeGuards.js +0 -31
- package/dist/browser/util/typeGuards.js.map +1 -1
- package/dist/commonjs/client/common.d.ts +6 -0
- package/dist/commonjs/client/common.js.map +1 -1
- package/dist/commonjs/client/getClient.js +4 -4
- package/dist/commonjs/client/getClient.js.map +1 -1
- package/dist/commonjs/client/restError.js +1 -1
- package/dist/commonjs/client/restError.js.map +1 -1
- package/dist/commonjs/constants.js +1 -1
- package/dist/commonjs/constants.js.map +1 -1
- package/dist/commonjs/fetchHttpClient.js +1 -1
- package/dist/commonjs/fetchHttpClient.js.map +1 -1
- package/dist/commonjs/index.d.ts +3 -2
- package/dist/commonjs/index.js +7 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/interfaces.d.ts +11 -0
- package/dist/commonjs/interfaces.js.map +1 -1
- package/dist/commonjs/logger/internal.d.ts +2 -0
- package/dist/commonjs/logger/internal.js +8 -0
- package/dist/commonjs/logger/internal.js.map +1 -0
- package/dist/commonjs/logger/logger.d.ts +70 -22
- package/dist/commonjs/logger/logger.js +92 -68
- package/dist/commonjs/logger/logger.js.map +1 -1
- package/dist/commonjs/nodeHttpClient.js +1 -8
- package/dist/commonjs/nodeHttpClient.js.map +1 -1
- package/dist/commonjs/pipelineRequest.d.ts +11 -0
- package/dist/commonjs/pipelineRequest.js +1 -0
- package/dist/commonjs/pipelineRequest.js.map +1 -1
- package/dist/commonjs/policies/internal.d.ts +16 -0
- package/dist/commonjs/policies/internal.js +48 -0
- package/dist/commonjs/policies/internal.js.map +1 -0
- package/dist/commonjs/policies/retryPolicy.js +2 -2
- package/dist/commonjs/policies/retryPolicy.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +1 -1
- package/dist/commonjs/util/checkEnvironment.d.ts +0 -5
- package/dist/commonjs/util/checkEnvironment.js +1 -6
- package/dist/commonjs/util/checkEnvironment.js.map +1 -1
- package/dist/commonjs/util/concat.common.js +2 -9
- package/dist/commonjs/util/concat.common.js.map +1 -1
- package/dist/commonjs/util/concat.js +1 -2
- package/dist/commonjs/util/concat.js.map +1 -1
- package/dist/commonjs/util/delay.d.ts +0 -13
- package/dist/commonjs/util/delay.js +0 -20
- package/dist/commonjs/util/delay.js.map +1 -1
- package/dist/commonjs/util/error.d.ts +0 -7
- package/dist/commonjs/util/error.js +0 -27
- package/dist/commonjs/util/error.js.map +1 -1
- package/dist/commonjs/util/internal.d.ts +10 -0
- package/dist/commonjs/util/internal.js +32 -0
- package/dist/commonjs/util/internal.js.map +1 -0
- package/dist/commonjs/util/sanitizer.d.ts +12 -2
- package/dist/commonjs/util/sanitizer.js +11 -1
- package/dist/commonjs/util/sanitizer.js.map +1 -1
- package/dist/commonjs/util/typeGuards.d.ts +0 -17
- package/dist/commonjs/util/typeGuards.js +0 -34
- package/dist/commonjs/util/typeGuards.js.map +1 -1
- package/dist/esm/client/common.d.ts +6 -0
- package/dist/esm/client/common.js.map +1 -1
- package/dist/esm/client/getClient.js +4 -4
- package/dist/esm/client/getClient.js.map +1 -1
- package/dist/esm/client/restError.js +1 -1
- package/dist/esm/client/restError.js.map +1 -1
- package/dist/esm/constants.js +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/fetchHttpClient.js +1 -1
- package/dist/esm/fetchHttpClient.js.map +1 -1
- package/dist/esm/index.d.ts +3 -2
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces.d.ts +11 -0
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/logger/internal.d.ts +2 -0
- package/dist/esm/logger/internal.js +4 -0
- package/dist/esm/logger/internal.js.map +1 -0
- package/dist/esm/logger/logger.d.ts +70 -22
- package/dist/esm/logger/logger.js +91 -68
- package/dist/esm/logger/logger.js.map +1 -1
- package/dist/esm/nodeHttpClient.js +1 -8
- package/dist/esm/nodeHttpClient.js.map +1 -1
- package/dist/esm/pipelineRequest.d.ts +11 -0
- package/dist/esm/pipelineRequest.js +1 -0
- package/dist/esm/pipelineRequest.js.map +1 -1
- package/dist/esm/policies/internal.d.ts +16 -0
- package/dist/esm/policies/internal.js +17 -0
- package/dist/esm/policies/internal.js.map +1 -0
- package/dist/esm/policies/retryPolicy.js +2 -2
- package/dist/esm/policies/retryPolicy.js.map +1 -1
- package/dist/esm/util/checkEnvironment.d.ts +0 -5
- package/dist/esm/util/checkEnvironment.js +0 -5
- package/dist/esm/util/checkEnvironment.js.map +1 -1
- package/dist/esm/util/concat.common.js +3 -10
- package/dist/esm/util/concat.common.js.map +1 -1
- package/dist/esm/util/concat.js +1 -2
- package/dist/esm/util/concat.js.map +1 -1
- package/dist/esm/util/delay.d.ts +0 -13
- package/dist/esm/util/delay.js +0 -19
- package/dist/esm/util/delay.js.map +1 -1
- package/dist/esm/util/error.d.ts +0 -7
- package/dist/esm/util/error.js +0 -26
- package/dist/esm/util/error.js.map +1 -1
- package/dist/esm/util/internal.d.ts +10 -0
- package/dist/esm/util/internal.js +12 -0
- package/dist/esm/util/internal.js.map +1 -0
- package/dist/esm/util/sanitizer.d.ts +12 -2
- package/dist/esm/util/sanitizer.js +11 -1
- package/dist/esm/util/sanitizer.js.map +1 -1
- package/dist/esm/util/typeGuards.d.ts +0 -17
- package/dist/esm/util/typeGuards.js +0 -31
- package/dist/esm/util/typeGuards.js.map +1 -1
- package/dist/react-native/client/common.d.ts +6 -0
- package/dist/react-native/client/common.js.map +1 -1
- package/dist/react-native/client/getClient.js +4 -4
- package/dist/react-native/client/getClient.js.map +1 -1
- package/dist/react-native/client/restError.js +1 -1
- package/dist/react-native/client/restError.js.map +1 -1
- package/dist/react-native/constants.js +1 -1
- package/dist/react-native/constants.js.map +1 -1
- package/dist/react-native/fetchHttpClient.js +1 -1
- package/dist/react-native/fetchHttpClient.js.map +1 -1
- package/dist/react-native/index.d.ts +3 -2
- package/dist/react-native/index.js +3 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/interfaces.d.ts +11 -0
- package/dist/react-native/interfaces.js.map +1 -1
- package/dist/react-native/logger/internal.d.ts +2 -0
- package/dist/react-native/logger/internal.js +4 -0
- package/dist/react-native/logger/internal.js.map +1 -0
- package/dist/react-native/logger/logger.d.ts +70 -22
- package/dist/react-native/logger/logger.js +91 -68
- package/dist/react-native/logger/logger.js.map +1 -1
- package/dist/react-native/nodeHttpClient.js +1 -8
- package/dist/react-native/nodeHttpClient.js.map +1 -1
- package/dist/react-native/pipelineRequest.d.ts +11 -0
- package/dist/react-native/pipelineRequest.js +1 -0
- package/dist/react-native/pipelineRequest.js.map +1 -1
- package/dist/react-native/policies/internal.d.ts +16 -0
- package/dist/react-native/policies/internal.js +17 -0
- package/dist/react-native/policies/internal.js.map +1 -0
- package/dist/react-native/policies/retryPolicy.js +2 -2
- package/dist/react-native/policies/retryPolicy.js.map +1 -1
- package/dist/react-native/util/checkEnvironment.d.ts +0 -5
- package/dist/react-native/util/checkEnvironment.js +0 -5
- package/dist/react-native/util/checkEnvironment.js.map +1 -1
- package/dist/react-native/util/concat.common.js +3 -10
- package/dist/react-native/util/concat.common.js.map +1 -1
- package/dist/react-native/util/delay.d.ts +0 -13
- package/dist/react-native/util/delay.js +0 -19
- package/dist/react-native/util/delay.js.map +1 -1
- package/dist/react-native/util/error.d.ts +0 -7
- package/dist/react-native/util/error.js +0 -26
- package/dist/react-native/util/error.js.map +1 -1
- package/dist/react-native/util/internal.d.ts +10 -0
- package/dist/react-native/util/internal.js +12 -0
- package/dist/react-native/util/internal.js.map +1 -0
- package/dist/react-native/util/sanitizer.d.ts +12 -2
- package/dist/react-native/util/sanitizer.js +11 -1
- package/dist/react-native/util/sanitizer.js.map +1 -1
- package/dist/react-native/util/typeGuards.d.ts +0 -17
- package/dist/react-native/util/typeGuards.js +0 -31
- package/dist/react-native/util/typeGuards.js.map +1 -1
- package/package.json +62 -5
- package/dist/browser/util/aborterUtils.d.ts +0 -26
- package/dist/browser/util/aborterUtils.js +0 -21
- package/dist/browser/util/aborterUtils.js.map +0 -1
- package/dist/browser/util/createAbortablePromise.d.ts +0 -16
- package/dist/browser/util/createAbortablePromise.js +0 -42
- package/dist/browser/util/createAbortablePromise.js.map +0 -1
- package/dist/browser/util/file.d.ts +0 -69
- package/dist/browser/util/file.js +0 -99
- package/dist/browser/util/file.js.map +0 -1
- package/dist/commonjs/util/aborterUtils.d.ts +0 -26
- package/dist/commonjs/util/aborterUtils.js +0 -24
- package/dist/commonjs/util/aborterUtils.js.map +0 -1
- package/dist/commonjs/util/createAbortablePromise.d.ts +0 -16
- package/dist/commonjs/util/createAbortablePromise.js +0 -45
- package/dist/commonjs/util/createAbortablePromise.js.map +0 -1
- package/dist/commonjs/util/file.d.ts +0 -69
- package/dist/commonjs/util/file.js +0 -104
- package/dist/commonjs/util/file.js.map +0 -1
- package/dist/esm/util/aborterUtils.d.ts +0 -26
- package/dist/esm/util/aborterUtils.js +0 -21
- package/dist/esm/util/aborterUtils.js.map +0 -1
- package/dist/esm/util/createAbortablePromise.d.ts +0 -16
- package/dist/esm/util/createAbortablePromise.js +0 -42
- package/dist/esm/util/createAbortablePromise.js.map +0 -1
- package/dist/esm/util/file.d.ts +0 -69
- package/dist/esm/util/file.js +0 -99
- package/dist/esm/util/file.js.map +0 -1
- package/dist/react-native/util/aborterUtils.d.ts +0 -26
- package/dist/react-native/util/aborterUtils.js +0 -21
- package/dist/react-native/util/aborterUtils.js.map +0 -1
- package/dist/react-native/util/createAbortablePromise.d.ts +0 -16
- package/dist/react-native/util/createAbortablePromise.js +0 -42
- package/dist/react-native/util/createAbortablePromise.js.map +0 -1
- package/dist/react-native/util/file.d.ts +0 -69
- package/dist/react-native/util/file.js +0 -99
- 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;;AA0TlC,sDAEC;AA1TD,oEAA8D;AAQ9D,iDAA2C;AAC3C,qDAAqD;AACrD,wDAAiF;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;QACpC,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,KAAK,UAAU,WAAW,CAAC,OAAwB;IACjD,MAAM,EAAE,eAAe,EAAE,sBAAsB,EAAE,GAAG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;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,SAAgB,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;;AA6TlC,sDAEC;AA7TD,oEAA8D;AAQ9D,iDAA2C;AAC3C,qDAAqD;AACrD,wDAAiF;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,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AC,CAAC;YAC/B,CAAC;SACF,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,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"]}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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/commonjs/index.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.createRestError = exports.operationOptionsToRequestParameters = exports.getClient = exports.uint8ArrayToString = exports.stringToUint8Array = exports.isRestError = exports.RestError = exports.createPipelineRequest = exports.createHttpHeaders = exports.TypeSpecRuntimeLogger = exports.createClientLogger = exports.AbortError = void 0;
|
|
5
|
+
exports.createRestError = exports.operationOptionsToRequestParameters = exports.getClient = exports.createDefaultHttpClient = exports.uint8ArrayToString = exports.stringToUint8Array = exports.isRestError = exports.RestError = exports.createEmptyPipeline = exports.createPipelineRequest = exports.createHttpHeaders = exports.TypeSpecRuntimeLogger = exports.setLogLevel = exports.getLogLevel = exports.createClientLogger = exports.AbortError = void 0;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
var AbortError_js_1 = require("./abort-controller/AbortError.js");
|
|
8
8
|
Object.defineProperty(exports, "AbortError", { enumerable: true, get: function () { return AbortError_js_1.AbortError; } });
|
|
9
9
|
var logger_js_1 = require("./logger/logger.js");
|
|
10
10
|
Object.defineProperty(exports, "createClientLogger", { enumerable: true, get: function () { return logger_js_1.createClientLogger; } });
|
|
11
|
+
Object.defineProperty(exports, "getLogLevel", { enumerable: true, get: function () { return logger_js_1.getLogLevel; } });
|
|
12
|
+
Object.defineProperty(exports, "setLogLevel", { enumerable: true, get: function () { return logger_js_1.setLogLevel; } });
|
|
11
13
|
Object.defineProperty(exports, "TypeSpecRuntimeLogger", { enumerable: true, get: function () { return logger_js_1.TypeSpecRuntimeLogger; } });
|
|
12
14
|
var httpHeaders_js_1 = require("./httpHeaders.js");
|
|
13
15
|
Object.defineProperty(exports, "createHttpHeaders", { enumerable: true, get: function () { return httpHeaders_js_1.createHttpHeaders; } });
|
|
@@ -15,12 +17,16 @@ tslib_1.__exportStar(require("./auth/schemes.js"), exports);
|
|
|
15
17
|
tslib_1.__exportStar(require("./auth/oauth2Flows.js"), exports);
|
|
16
18
|
var pipelineRequest_js_1 = require("./pipelineRequest.js");
|
|
17
19
|
Object.defineProperty(exports, "createPipelineRequest", { enumerable: true, get: function () { return pipelineRequest_js_1.createPipelineRequest; } });
|
|
20
|
+
var pipeline_js_1 = require("./pipeline.js");
|
|
21
|
+
Object.defineProperty(exports, "createEmptyPipeline", { enumerable: true, get: function () { return pipeline_js_1.createEmptyPipeline; } });
|
|
18
22
|
var restError_js_1 = require("./restError.js");
|
|
19
23
|
Object.defineProperty(exports, "RestError", { enumerable: true, get: function () { return restError_js_1.RestError; } });
|
|
20
24
|
Object.defineProperty(exports, "isRestError", { enumerable: true, get: function () { return restError_js_1.isRestError; } });
|
|
21
25
|
var bytesEncoding_js_1 = require("./util/bytesEncoding.js");
|
|
22
26
|
Object.defineProperty(exports, "stringToUint8Array", { enumerable: true, get: function () { return bytesEncoding_js_1.stringToUint8Array; } });
|
|
23
27
|
Object.defineProperty(exports, "uint8ArrayToString", { enumerable: true, get: function () { return bytesEncoding_js_1.uint8ArrayToString; } });
|
|
28
|
+
var defaultHttpClient_js_1 = require("./defaultHttpClient.js");
|
|
29
|
+
Object.defineProperty(exports, "createDefaultHttpClient", { enumerable: true, get: function () { return defaultHttpClient_js_1.createDefaultHttpClient; } });
|
|
24
30
|
var getClient_js_1 = require("./client/getClient.js");
|
|
25
31
|
Object.defineProperty(exports, "getClient", { enumerable: true, get: function () { return getClient_js_1.getClient; } });
|
|
26
32
|
var operationOptionHelpers_js_1 = require("./client/operationOptionHelpers.js");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAUlC,kEAA8D;AAArD,2GAAA,UAAU,OAAA;AACnB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;;AAUlC,kEAA8D;AAArD,2GAAA,UAAU,OAAA;AACnB,gDAQ4B;AAP1B,+GAAA,kBAAkB,OAAA;AAClB,wGAAA,WAAW,OAAA;AACX,wGAAA,WAAW,OAAA;AACX,kHAAA,qBAAqB,OAAA;AA4BvB,mDAAqD;AAA5C,mHAAA,iBAAiB,OAAA;AAC1B,4DAAkC;AAClC,gEAAsC;AAUtC,2DAA0F;AAAjF,2HAAA,qBAAqB,OAAA;AAC9B,6CAMuB;AADrB,kHAAA,mBAAmB,OAAA;AAErB,+CAA+E;AAAtE,yGAAA,SAAS,OAAA;AAAE,2GAAA,WAAW,OAAA;AAC/B,4DAAoG;AAA3F,sHAAA,kBAAkB,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAC/C,+DAAiE;AAAxD,+HAAA,uBAAuB,OAAA;AAChC,sDAAkD;AAAzC,yGAAA,SAAS,OAAA;AAClB,gFAAyF;AAAhF,gJAAA,mCAAmC,OAAA;AAC5C,sDAAwD;AAA/C,+GAAA,eAAe,OAAA","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,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createLoggerContext = void 0;
|
|
6
|
+
var logger_js_1 = require("./logger.js");
|
|
7
|
+
Object.defineProperty(exports, "createLoggerContext", { enumerable: true, get: function () { return logger_js_1.createLoggerContext; } });
|
|
8
|
+
//# 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,yCAIqB;AAHnB,gHAAA,mBAAmB,OAAA","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 }
|
|
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
|
-
*
|
|
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.
|
|
@@ -3,34 +3,99 @@
|
|
|
3
3
|
// Licensed under the MIT License.
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.TypeSpecRuntimeLogger = void 0;
|
|
6
|
+
exports.createLoggerContext = createLoggerContext;
|
|
6
7
|
exports.setLogLevel = setLogLevel;
|
|
7
8
|
exports.getLogLevel = getLogLevel;
|
|
8
9
|
exports.createClientLogger = createClientLogger;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
const debug_js_1 = tslib_1.__importDefault(require("./debug.js"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const TYPESPEC_RUNTIME_LOG_LEVELS = ["verbose", "info", "warning", "error"];
|
|
13
|
+
const levelMap = {
|
|
14
|
+
verbose: 400,
|
|
15
|
+
info: 300,
|
|
16
|
+
warning: 200,
|
|
17
|
+
error: 100,
|
|
18
|
+
};
|
|
19
|
+
function patchLogMethod(parent, child) {
|
|
20
|
+
child.log = (...args) => {
|
|
21
|
+
parent.log(...args);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function isTypeSpecRuntimeLogLevel(level) {
|
|
25
|
+
return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level);
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
28
|
+
* Creates a logger context base on the provided options.
|
|
29
|
+
* @param options - The options for creating a logger context.
|
|
30
|
+
* @returns The logger context.
|
|
19
31
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
function createLoggerContext(options) {
|
|
33
|
+
const registeredLoggers = new Set();
|
|
34
|
+
const logLevelFromEnv = (typeof process !== "undefined" && process.env && process.env[options.logLevelEnvVarName]) ||
|
|
35
|
+
undefined;
|
|
36
|
+
let logLevel;
|
|
37
|
+
const clientLogger = (0, debug_js_1.default)(options.namespace);
|
|
38
|
+
clientLogger.log = (...args) => {
|
|
39
|
+
debug_js_1.default.log(...args);
|
|
40
|
+
};
|
|
41
|
+
if (logLevelFromEnv) {
|
|
42
|
+
// avoid calling setLogLevel because we don't want a mis-set environment variable to crash
|
|
43
|
+
if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {
|
|
44
|
+
setLogLevel(logLevelFromEnv);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.error(`${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
|
|
48
|
+
}
|
|
29
49
|
}
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
function shouldEnable(logger) {
|
|
51
|
+
return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);
|
|
32
52
|
}
|
|
53
|
+
function createLogger(parent, level) {
|
|
54
|
+
const logger = Object.assign(parent.extend(level), {
|
|
55
|
+
level,
|
|
56
|
+
});
|
|
57
|
+
patchLogMethod(parent, logger);
|
|
58
|
+
if (shouldEnable(logger)) {
|
|
59
|
+
const enabledNamespaces = debug_js_1.default.disable();
|
|
60
|
+
debug_js_1.default.enable(enabledNamespaces + "," + logger.namespace);
|
|
61
|
+
}
|
|
62
|
+
registeredLoggers.add(logger);
|
|
63
|
+
return logger;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
setLogLevel(level) {
|
|
67
|
+
if (level && !isTypeSpecRuntimeLogLevel(level)) {
|
|
68
|
+
throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
|
|
69
|
+
}
|
|
70
|
+
logLevel = level;
|
|
71
|
+
const enabledNamespaces = [];
|
|
72
|
+
for (const logger of registeredLoggers) {
|
|
73
|
+
if (shouldEnable(logger)) {
|
|
74
|
+
enabledNamespaces.push(logger.namespace);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
debug_js_1.default.enable(enabledNamespaces.join(","));
|
|
78
|
+
},
|
|
79
|
+
getLogLevel() {
|
|
80
|
+
return logLevel;
|
|
81
|
+
},
|
|
82
|
+
createClientLogger(namespace) {
|
|
83
|
+
const clientRootLogger = clientLogger.extend(namespace);
|
|
84
|
+
patchLogMethod(clientLogger, clientRootLogger);
|
|
85
|
+
return {
|
|
86
|
+
error: createLogger(clientRootLogger, "error"),
|
|
87
|
+
warning: createLogger(clientRootLogger, "warning"),
|
|
88
|
+
info: createLogger(clientRootLogger, "info"),
|
|
89
|
+
verbose: createLogger(clientRootLogger, "verbose"),
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
logger: clientLogger,
|
|
93
|
+
};
|
|
33
94
|
}
|
|
95
|
+
const context = createLoggerContext({
|
|
96
|
+
logLevelEnvVarName: "TYPESPEC_RUNTIME_LOG_LEVEL",
|
|
97
|
+
namespace: "typeSpecRuntime",
|
|
98
|
+
});
|
|
34
99
|
/**
|
|
35
100
|
* Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
|
|
36
101
|
* @param level - The log level to enable for logging.
|
|
@@ -40,67 +105,26 @@ if (logLevelFromEnv) {
|
|
|
40
105
|
* - warning
|
|
41
106
|
* - error
|
|
42
107
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (shouldEnable(logger)) {
|
|
51
|
-
enabledNamespaces.push(logger.namespace);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
debug_js_1.default.enable(enabledNamespaces.join(","));
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
109
|
+
exports.TypeSpecRuntimeLogger = context.logger;
|
|
110
|
+
/**
|
|
111
|
+
* Retrieves the currently specified log level.
|
|
112
|
+
*/
|
|
113
|
+
function setLogLevel(logLevel) {
|
|
114
|
+
context.setLogLevel(logLevel);
|
|
55
115
|
}
|
|
56
116
|
/**
|
|
57
117
|
* Retrieves the currently specified log level.
|
|
58
118
|
*/
|
|
59
119
|
function getLogLevel() {
|
|
60
|
-
return
|
|
120
|
+
return context.getLogLevel();
|
|
61
121
|
}
|
|
62
|
-
const levelMap = {
|
|
63
|
-
verbose: 400,
|
|
64
|
-
info: 300,
|
|
65
|
-
warning: 200,
|
|
66
|
-
error: 100,
|
|
67
|
-
};
|
|
68
122
|
/**
|
|
69
123
|
* Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
|
|
70
124
|
* @param namespace - The name of the SDK package.
|
|
71
125
|
* @hidden
|
|
72
126
|
*/
|
|
73
127
|
function createClientLogger(namespace) {
|
|
74
|
-
|
|
75
|
-
patchLogMethod(exports.TypeSpecRuntimeLogger, clientRootLogger);
|
|
76
|
-
return {
|
|
77
|
-
error: createLogger(clientRootLogger, "error"),
|
|
78
|
-
warning: createLogger(clientRootLogger, "warning"),
|
|
79
|
-
info: createLogger(clientRootLogger, "info"),
|
|
80
|
-
verbose: createLogger(clientRootLogger, "verbose"),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function patchLogMethod(parent, child) {
|
|
84
|
-
child.log = (...args) => {
|
|
85
|
-
parent.log(...args);
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function createLogger(parent, level) {
|
|
89
|
-
const logger = Object.assign(parent.extend(level), {
|
|
90
|
-
level,
|
|
91
|
-
});
|
|
92
|
-
patchLogMethod(parent, logger);
|
|
93
|
-
if (shouldEnable(logger)) {
|
|
94
|
-
const enabledNamespaces = debug_js_1.default.disable();
|
|
95
|
-
debug_js_1.default.enable(enabledNamespaces + "," + logger.namespace);
|
|
96
|
-
}
|
|
97
|
-
registeredLoggers.add(logger);
|
|
98
|
-
return logger;
|
|
99
|
-
}
|
|
100
|
-
function shouldEnable(logger) {
|
|
101
|
-
return Boolean(typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel]);
|
|
102
|
-
}
|
|
103
|
-
function isTypeSpecRuntimeLogLevel(logLevel) {
|
|
104
|
-
return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel);
|
|
128
|
+
return context.createClientLogger(namespace);
|
|
105
129
|
}
|
|
106
130
|
//# sourceMappingURL=logger.js.map
|