@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":"pipelineRequest.js","sourceRoot":"","sources":["../../src/pipelineRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAYlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"pipelineRequest.js","sourceRoot":"","sources":["../../src/pipelineRequest.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAYlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA8GjD,MAAM,mBAAmB;IAqBvB,YAAY,OAA+B;;QACzC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,iBAAiB,EAAE,CAAC;QACtD,IAAI,CAAC,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,KAAK,CAAC;QACtC,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,CAAC,CAAC;QACpC,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,gBAAgB,GAAG,MAAA,OAAO,CAAC,gBAAgB,mCAAI,KAAK,CAAC;QAC1D,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,yBAAyB,GAAG,OAAO,CAAC,yBAAyB,CAAC;QACnE,IAAI,CAAC,eAAe,GAAG,MAAA,OAAO,CAAC,eAAe,mCAAI,KAAK,CAAC;QACxD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,UAAU,EAAE,CAAC;QACnD,IAAI,CAAC,uBAAuB,GAAG,MAAA,OAAO,CAAC,uBAAuB,mCAAI,KAAK,CAAC;QACxE,IAAI,CAAC,oBAAoB,GAAG,MAAA,OAAO,CAAC,oBAAoB,mCAAI,KAAK,CAAC;QAClE,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACnD,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACnE,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n PipelineRequest,\n ProxySettings,\n RequestBodyType,\n TransferProgressEvent,\n} from \"./interfaces.js\";\nimport { createHttpHeaders } from \"./httpHeaders.js\";\nimport { randomUUID } from \"./util/uuidUtils.js\";\n\n/**\n * Settings to initialize a request.\n * Almost equivalent to Partial<PipelineRequest>, but url is mandatory.\n */\nexport interface PipelineRequestOptions {\n /**\n * The URL to make the request to.\n */\n url: string;\n\n /**\n * The HTTP method to use when making the request.\n */\n method?: HttpMethods;\n\n /**\n * The HTTP headers to use when making the request.\n */\n headers?: HttpHeaders;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n * If the request is terminated, an `AbortError` is thrown.\n * Defaults to 0, which disables the timeout.\n */\n timeout?: number;\n\n /**\n * If credentials (cookies) should be sent along during an XHR.\n * Defaults to false.\n */\n withCredentials?: boolean;\n\n /**\n * A unique identifier for the request. Used for logging and tracing.\n */\n requestId?: string;\n\n /**\n * The HTTP body content (if any)\n */\n body?: RequestBodyType;\n\n /**\n * Body for a multipart request.\n */\n multipartBody?: MultipartRequestBody;\n\n /**\n * To simulate a browser form post\n */\n formData?: FormDataMap;\n\n /**\n * A list of response status codes whose corresponding PipelineResponse body should be treated as a stream.\n */\n streamResponseStatusCodes?: Set<number>;\n\n /**\n * BROWSER ONLY\n *\n * A browser only option to enable use of the Streams API. If this option is set and streaming is used\n * (see `streamResponseStatusCodes`), the response will have a property `browserStream` instead of\n * `blobBody` which will be undefined.\n *\n * Default value is false\n */\n enableBrowserStreams?: boolean;\n\n /**\n * Proxy configuration.\n */\n proxySettings?: ProxySettings;\n\n /**\n * If the connection should not be reused.\n */\n disableKeepAlive?: boolean;\n\n /**\n * Used to abort the request later.\n */\n abortSignal?: AbortSignal;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Callback which fires upon download progress. */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n\n /**\n * Additional options to set on the request. This provides a way to override\n * existing ones or provide request properties that are not declared.\n *\n * For possible valid properties, see\n * - NodeJS https.request options: https://nodejs.org/api/http.html#httprequestoptions-callback\n * - Browser RequestInit: https://developer.mozilla.org/en-US/docs/Web/API/RequestInit\n *\n * WARNING: Options specified here will override any properties of same names when request is sent by {@link HttpClient}.\n */\n requestOverrides?: Record<string, unknown>;\n}\n\nclass PipelineRequestImpl implements PipelineRequest {\n public url: string;\n public method: HttpMethods;\n public headers: HttpHeaders;\n public timeout: number;\n public withCredentials: boolean;\n public body?: RequestBodyType;\n public multipartBody?: MultipartRequestBody;\n public formData?: FormDataMap;\n public streamResponseStatusCodes?: Set<number>;\n public enableBrowserStreams: boolean;\n\n public proxySettings?: ProxySettings;\n public disableKeepAlive: boolean;\n public abortSignal?: AbortSignal;\n public requestId: string;\n public allowInsecureConnection?: boolean;\n public onUploadProgress?: (progress: TransferProgressEvent) => void;\n public onDownloadProgress?: (progress: TransferProgressEvent) => void;\n public requestOverrides?: Record<string, unknown>;\n\n constructor(options: PipelineRequestOptions) {\n this.url = options.url;\n this.body = options.body;\n this.headers = options.headers ?? createHttpHeaders();\n this.method = options.method ?? \"GET\";\n this.timeout = options.timeout ?? 0;\n this.multipartBody = options.multipartBody;\n this.formData = options.formData;\n this.disableKeepAlive = options.disableKeepAlive ?? false;\n this.proxySettings = options.proxySettings;\n this.streamResponseStatusCodes = options.streamResponseStatusCodes;\n this.withCredentials = options.withCredentials ?? false;\n this.abortSignal = options.abortSignal;\n this.onUploadProgress = options.onUploadProgress;\n this.onDownloadProgress = options.onDownloadProgress;\n this.requestId = options.requestId || randomUUID();\n this.allowInsecureConnection = options.allowInsecureConnection ?? false;\n this.enableBrowserStreams = options.enableBrowserStreams ?? false;\n this.requestOverrides = options.requestOverrides;\n }\n}\n\n/**\n * Creates a new pipeline request with the given options.\n * This method is to allow for the easy setting of default values and not required.\n * @param options - The options to create the request with.\n */\nexport function createPipelineRequest(options: PipelineRequestOptions): PipelineRequest {\n return new PipelineRequestImpl(options);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { agentPolicy, agentPolicyName } from "./agentPolicy.js";
|
|
2
|
+
export { decompressResponsePolicy, decompressResponsePolicyName, } from "./decompressResponsePolicy.js";
|
|
3
|
+
export { defaultRetryPolicy, defaultRetryPolicyName, DefaultRetryPolicyOptions, } from "./defaultRetryPolicy.js";
|
|
4
|
+
export { exponentialRetryPolicy, exponentialRetryPolicyName, ExponentialRetryPolicyOptions, } from "./exponentialRetryPolicy.js";
|
|
5
|
+
export { retryPolicy, RetryPolicyOptions } from "./retryPolicy.js";
|
|
6
|
+
export { RetryInformation, RetryModifiers, RetryStrategy, } from "../retryStrategies/retryStrategy.js";
|
|
7
|
+
export { systemErrorRetryPolicy, systemErrorRetryPolicyName } from "./systemErrorRetryPolicy.js";
|
|
8
|
+
export { throttlingRetryPolicy, throttlingRetryPolicyName } from "./throttlingRetryPolicy.js";
|
|
9
|
+
export { formDataPolicy, formDataPolicyName } from "./formDataPolicy.js";
|
|
10
|
+
export { logPolicy, logPolicyName, LogPolicyOptions } from "./logPolicy.js";
|
|
11
|
+
export { multipartPolicy, multipartPolicyName } from "./multipartPolicy.js";
|
|
12
|
+
export { proxyPolicy, proxyPolicyName, getDefaultProxySettings } from "./proxyPolicy.js";
|
|
13
|
+
export { redirectPolicy, redirectPolicyName, RedirectPolicyOptions } from "./redirectPolicy.js";
|
|
14
|
+
export { tlsPolicy, tlsPolicyName } from "./tlsPolicy.js";
|
|
15
|
+
export { userAgentPolicy, userAgentPolicyName, UserAgentPolicyOptions } from "./userAgentPolicy.js";
|
|
16
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export { agentPolicy, agentPolicyName } from "./agentPolicy.js";
|
|
4
|
+
export { decompressResponsePolicy, decompressResponsePolicyName, } from "./decompressResponsePolicy.js";
|
|
5
|
+
export { defaultRetryPolicy, defaultRetryPolicyName, } from "./defaultRetryPolicy.js";
|
|
6
|
+
export { exponentialRetryPolicy, exponentialRetryPolicyName, } from "./exponentialRetryPolicy.js";
|
|
7
|
+
export { retryPolicy } from "./retryPolicy.js";
|
|
8
|
+
export { systemErrorRetryPolicy, systemErrorRetryPolicyName } from "./systemErrorRetryPolicy.js";
|
|
9
|
+
export { throttlingRetryPolicy, throttlingRetryPolicyName } from "./throttlingRetryPolicy.js";
|
|
10
|
+
export { formDataPolicy, formDataPolicyName } from "./formDataPolicy.js";
|
|
11
|
+
export { logPolicy, logPolicyName } from "./logPolicy.js";
|
|
12
|
+
export { multipartPolicy, multipartPolicyName } from "./multipartPolicy.js";
|
|
13
|
+
export { proxyPolicy, proxyPolicyName, getDefaultProxySettings } from "./proxyPolicy.js";
|
|
14
|
+
export { redirectPolicy, redirectPolicyName } from "./redirectPolicy.js";
|
|
15
|
+
export { tlsPolicy, tlsPolicyName } from "./tlsPolicy.js";
|
|
16
|
+
export { userAgentPolicy, userAgentPolicyName } from "./userAgentPolicy.js";
|
|
17
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/policies/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,kBAAkB,EAClB,sBAAsB,GAEvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,sBAAsB,EACtB,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,WAAW,EAAsB,MAAM,kBAAkB,CAAC;AAMnE,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAyB,MAAM,qBAAqB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAA0B,MAAM,sBAAsB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport { agentPolicy, agentPolicyName } from \"./agentPolicy.js\";\nexport {\n decompressResponsePolicy,\n decompressResponsePolicyName,\n} from \"./decompressResponsePolicy.js\";\nexport {\n defaultRetryPolicy,\n defaultRetryPolicyName,\n DefaultRetryPolicyOptions,\n} from \"./defaultRetryPolicy.js\";\nexport {\n exponentialRetryPolicy,\n exponentialRetryPolicyName,\n ExponentialRetryPolicyOptions,\n} from \"./exponentialRetryPolicy.js\";\nexport { retryPolicy, RetryPolicyOptions } from \"./retryPolicy.js\";\nexport {\n RetryInformation,\n RetryModifiers,\n RetryStrategy,\n} from \"../retryStrategies/retryStrategy.js\";\nexport { systemErrorRetryPolicy, systemErrorRetryPolicyName } from \"./systemErrorRetryPolicy.js\";\nexport { throttlingRetryPolicy, throttlingRetryPolicyName } from \"./throttlingRetryPolicy.js\";\nexport { formDataPolicy, formDataPolicyName } from \"./formDataPolicy.js\";\nexport { logPolicy, logPolicyName, LogPolicyOptions } from \"./logPolicy.js\";\nexport { multipartPolicy, multipartPolicyName } from \"./multipartPolicy.js\";\nexport { proxyPolicy, proxyPolicyName, getDefaultProxySettings } from \"./proxyPolicy.js\";\nexport { redirectPolicy, redirectPolicyName, RedirectPolicyOptions } from \"./redirectPolicy.js\";\nexport { tlsPolicy, tlsPolicyName } from \"./tlsPolicy.js\";\nexport { userAgentPolicy, userAgentPolicyName, UserAgentPolicyOptions } from \"./userAgentPolicy.js\";\n"]}
|
|
@@ -4,7 +4,7 @@ import { delay } from "../util/helpers.js";
|
|
|
4
4
|
import { AbortError } from "../abort-controller/AbortError.js";
|
|
5
5
|
import { createClientLogger } from "../logger/logger.js";
|
|
6
6
|
import { DEFAULT_RETRY_POLICY_COUNT } from "../constants.js";
|
|
7
|
-
const retryPolicyLogger = createClientLogger("
|
|
7
|
+
const retryPolicyLogger = createClientLogger("ts-http-runtime retryPolicy");
|
|
8
8
|
/**
|
|
9
9
|
* The programmatic identifier of the retryPolicy.
|
|
10
10
|
*/
|
|
@@ -60,7 +60,7 @@ export function retryPolicy(strategies, options = { maxRetries: DEFAULT_RETRY_PO
|
|
|
60
60
|
}
|
|
61
61
|
logger.info(`Retry ${retryCount}: Processing ${strategies.length} retry strategies.`);
|
|
62
62
|
strategiesLoop: for (const strategy of strategies) {
|
|
63
|
-
const strategyLogger = strategy.logger ||
|
|
63
|
+
const strategyLogger = strategy.logger || logger;
|
|
64
64
|
strategyLogger.info(`Retry ${retryCount}: Processing retry strategy ${strategy.name}.`);
|
|
65
65
|
const modifiers = strategy.retry({
|
|
66
66
|
retryCount,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryPolicy.js","sourceRoot":"","sources":["../../../src/policies/retryPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"retryPolicy.js","sourceRoot":"","sources":["../../../src/policies/retryPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,iBAAiB,GAAG,kBAAkB,CA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AAC,KAAK,CAClB,SAAS,UAAU,oBAAoB,QAAQ,CAAC,IAAI,gBAAgB,EACpE,YAAY,CACb,CAAC;wBACF,MAAM,YAAY,CAAC;oBACrB,CAAC;oBAED,IAAI,cAAc,IAAI,cAAc,KAAK,CAAC,EAAE,CAAC;wBAC3C,cAAc,CAAC,IAAI,CACjB,SAAS,UAAU,oBAAoB,QAAQ,CAAC,IAAI,kBAAkB,cAAc,EAAE,CACvF,CAAC;wBACF,MAAM,KAAK,CAAC,cAAc,EAAE,SAAS,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;wBAC7E,SAAS,YAAY,CAAC;oBACxB,CAAC;oBAED,IAAI,UAAU,EAAE,CAAC;wBACf,cAAc,CAAC,IAAI,CACjB,SAAS,UAAU,oBAAoB,QAAQ,CAAC,IAAI,iBAAiB,UAAU,EAAE,CAClF,CAAC;wBACF,OAAO,CAAC,GAAG,GAAG,UAAU,CAAC;wBACzB,SAAS,YAAY,CAAC;oBACxB,CAAC;gBACH,CAAC;gBAED,IAAI,aAAa,EAAE,CAAC;oBAClB,MAAM,CAAC,IAAI,CACT,+EAA+E,CAChF,CAAC;oBACF,MAAM,aAAa,CAAC;gBACtB,CAAC;gBACD,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,CAAC,IAAI,CACT,mFAAmF,CACpF,CAAC;oBACF,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBAED,mDAAmD;gBACnD,+DAA+D;gBAC/D,iCAAiC;YACnC,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { delay } from \"../util/helpers.js\";\nimport type { RetryStrategy } from \"../retryStrategies/retryStrategy.js\";\nimport type { RestError } from \"../restError.js\";\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport type { TypeSpecRuntimeLogger } from \"../logger/logger.js\";\nimport { createClientLogger } from \"../logger/logger.js\";\nimport { DEFAULT_RETRY_POLICY_COUNT } from \"../constants.js\";\n\nconst retryPolicyLogger = createClientLogger(\"ts-http-runtime retryPolicy\");\n\n/**\n * The programmatic identifier of the retryPolicy.\n */\nconst retryPolicyName = \"retryPolicy\";\n\n/**\n * Options to the {@link retryPolicy}\n */\nexport interface RetryPolicyOptions {\n /**\n * Maximum number of retries. If not specified, it will limit to 3 retries.\n */\n maxRetries?: number;\n /**\n * Logger. If it's not provided, a default logger is used.\n */\n logger?: TypeSpecRuntimeLogger;\n}\n\n/**\n * retryPolicy is a generic policy to enable retrying requests when certain conditions are met\n */\nexport function retryPolicy(\n strategies: RetryStrategy[],\n options: RetryPolicyOptions = { maxRetries: DEFAULT_RETRY_POLICY_COUNT },\n): PipelinePolicy {\n const logger = options.logger || retryPolicyLogger;\n return {\n name: retryPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n let response: PipelineResponse | undefined;\n let responseError: RestError | undefined;\n let retryCount = -1;\n\n retryRequest: while (true) {\n retryCount += 1;\n response = undefined;\n responseError = undefined;\n\n try {\n logger.info(`Retry ${retryCount}: Attempting to send request`, request.requestId);\n response = await next(request);\n logger.info(`Retry ${retryCount}: Received a response from request`, request.requestId);\n } catch (e: any) {\n logger.error(`Retry ${retryCount}: Received an error from request`, request.requestId);\n\n // RestErrors are valid targets for the retry strategies.\n // If none of the retry strategies can work with them, they will be thrown later in this policy.\n // If the received error is not a RestError, it is immediately thrown.\n responseError = e as RestError;\n if (!e || responseError.name !== \"RestError\") {\n throw e;\n }\n\n response = responseError.response;\n }\n\n if (request.abortSignal?.aborted) {\n logger.error(`Retry ${retryCount}: Request aborted.`);\n const abortError = new AbortError();\n throw abortError;\n }\n\n if (retryCount >= (options.maxRetries ?? DEFAULT_RETRY_POLICY_COUNT)) {\n logger.info(\n `Retry ${retryCount}: Maximum retries reached. Returning the last received response, or throwing the last received error.`,\n );\n if (responseError) {\n throw responseError;\n } else if (response) {\n return response;\n } else {\n throw new Error(\"Maximum retries reached with no response or error to throw\");\n }\n }\n\n logger.info(`Retry ${retryCount}: Processing ${strategies.length} retry strategies.`);\n\n strategiesLoop: for (const strategy of strategies) {\n const strategyLogger = strategy.logger || logger;\n strategyLogger.info(`Retry ${retryCount}: Processing retry strategy ${strategy.name}.`);\n\n const modifiers = strategy.retry({\n retryCount,\n response,\n responseError,\n });\n\n if (modifiers.skipStrategy) {\n strategyLogger.info(`Retry ${retryCount}: Skipped.`);\n continue strategiesLoop;\n }\n\n const { errorToThrow, retryAfterInMs, redirectTo } = modifiers;\n\n if (errorToThrow) {\n strategyLogger.error(\n `Retry ${retryCount}: Retry strategy ${strategy.name} throws error:`,\n errorToThrow,\n );\n throw errorToThrow;\n }\n\n if (retryAfterInMs || retryAfterInMs === 0) {\n strategyLogger.info(\n `Retry ${retryCount}: Retry strategy ${strategy.name} retries after ${retryAfterInMs}`,\n );\n await delay(retryAfterInMs, undefined, { abortSignal: request.abortSignal });\n continue retryRequest;\n }\n\n if (redirectTo) {\n strategyLogger.info(\n `Retry ${retryCount}: Retry strategy ${strategy.name} redirects to ${redirectTo}`,\n );\n request.url = redirectTo;\n continue retryRequest;\n }\n }\n\n if (responseError) {\n logger.info(\n `None of the retry strategies could work with the received error. Throwing it.`,\n );\n throw responseError;\n }\n if (response) {\n logger.info(\n `None of the retry strategies could work with the received response. Returning it.`,\n );\n return response;\n }\n\n // If all the retries skip and there's no response,\n // we're still in the retry loop, so a new request will be sent\n // until `maxRetries` is reached.\n }\n },\n };\n}\n"]}
|
|
@@ -18,11 +18,6 @@ export declare const isBun: boolean;
|
|
|
18
18
|
* A constant that indicates whether the environment the code is running is a Node.js compatible environment.
|
|
19
19
|
*/
|
|
20
20
|
export declare const isNodeLike: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* A constant that indicates whether the environment the code is running is a Node.js compatible environment.
|
|
23
|
-
* @deprecated Use `isNodeLike` instead.
|
|
24
|
-
*/
|
|
25
|
-
export declare const isNode: boolean;
|
|
26
21
|
/**
|
|
27
22
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
28
23
|
*/
|
|
@@ -30,11 +30,6 @@ export const isBun = typeof Bun !== "undefined" && typeof Bun.version !== "undef
|
|
|
30
30
|
export const isNodeLike = typeof globalThis.process !== "undefined" &&
|
|
31
31
|
Boolean(globalThis.process.version) &&
|
|
32
32
|
Boolean((_d = globalThis.process.versions) === null || _d === void 0 ? void 0 : _d.node);
|
|
33
|
-
/**
|
|
34
|
-
* A constant that indicates whether the environment the code is running is a Node.js compatible environment.
|
|
35
|
-
* @deprecated Use `isNodeLike` instead.
|
|
36
|
-
*/
|
|
37
|
-
export const isNode = isNodeLike;
|
|
38
33
|
/**
|
|
39
34
|
* A constant that indicates whether the environment the code is running is Node.JS.
|
|
40
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checkEnvironment.js","sourceRoot":"","sources":["../../../src/util/checkEnvironment.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAmClC;;GAEG;AACH,yDAAyD;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC;AAEjG;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GACtB,OAAO,IAAI,KAAK,QAAQ;IACxB,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,aAAa,CAAA,KAAK,UAAU;IACzC,CAAC,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,4BAA4B;QACtD,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,0BAA0B;QACrD,CAAA,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,MAAK,yBAAyB,CAAC,CAAC;AAE1D;;GAEG;AACH,M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AAK,WAAW;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,WAAW,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,WAAW,CAAC;AAEtF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GACrB,OAAO,UAAU,CAAC,OAAO,KAAK,WAAW;IACzC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC;IACnC,OAAO,CAAC,MAAA,UAAU,CAAC,OAAO,CAAC,QAAQ,0CAAE,IAAI,CAAC,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC;AAE7D;;GAEG;AACH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,aAAa,GACxB,OAAO,SAAS,KAAK,WAAW,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,MAAK,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ninterface Window {\n document: unknown;\n}\n\ninterface DedicatedWorkerGlobalScope {\n constructor: {\n name: string;\n };\n\n importScripts: (...paths: string[]) => void;\n}\n\ninterface Navigator {\n product: string;\n}\n\ninterface DenoGlobal {\n version: {\n deno: string;\n };\n}\n\ninterface BunGlobal {\n version: string;\n}\n\n// eslint-disable-next-line @azure/azure-sdk/ts-no-window\ndeclare const window: Window;\ndeclare const self: DedicatedWorkerGlobalScope;\ndeclare const Deno: DenoGlobal;\ndeclare const Bun: BunGlobal;\ndeclare const navigator: Navigator;\n\n/**\n * A constant that indicates whether the environment the code is running is a Web Browser.\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-no-window\nexport const isBrowser = typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is a Web Worker.\n */\nexport const isWebWorker =\n typeof self === \"object\" &&\n typeof self?.importScripts === \"function\" &&\n (self.constructor?.name === \"DedicatedWorkerGlobalScope\" ||\n self.constructor?.name === \"ServiceWorkerGlobalScope\" ||\n self.constructor?.name === \"SharedWorkerGlobalScope\");\n\n/**\n * A constant that indicates whether the environment the code is running is Deno.\n */\nexport const isDeno =\n typeof Deno !== \"undefined\" &&\n typeof Deno.version !== \"undefined\" &&\n typeof Deno.version.deno !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is Bun.sh.\n */\nexport const isBun = typeof Bun !== \"undefined\" && typeof Bun.version !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is a Node.js compatible environment.\n */\nexport const isNodeLike =\n typeof globalThis.process !== \"undefined\" &&\n Boolean(globalThis.process.version) &&\n Boolean(globalThis.process.versions?.node);\n\n/**\n * A constant that indicates whether the environment the code is running is Node.JS.\n */\nexport const isNodeRuntime = isNodeLike && !isBun && !isDeno;\n\n/**\n * A constant that indicates whether the environment the code is running is in React-Native.\n */\n// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js\nexport const isReactNative =\n typeof navigator !== \"undefined\" && navigator?.product === \"ReactNative\";\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import {
|
|
4
|
-
import { isNodeReadableStream, isWebReadableStream } from "./typeGuards.js";
|
|
3
|
+
import { isWebReadableStream } from "./typeGuards.js";
|
|
5
4
|
/**
|
|
6
5
|
* Drain the content of the given ReadableStream into a Blob.
|
|
7
6
|
* The blob's content may end up in memory or on disk dependent on size.
|
|
@@ -16,15 +15,9 @@ async function toBlobPart(source) {
|
|
|
16
15
|
if (isWebReadableStream(source)) {
|
|
17
16
|
return drain(source);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// using getRawContent.
|
|
22
|
-
const rawContent = getRawContent(source);
|
|
23
|
-
// Shouldn't happen but guard for it anyway
|
|
24
|
-
if (isNodeReadableStream(rawContent)) {
|
|
25
|
-
throw new Error("Encountered unexpected type. In the browser, `concat` supports Web ReadableStream, Blob, Uint8Array, and files created using `createFile` only.");
|
|
18
|
+
else {
|
|
19
|
+
throw new Error("Unsupported source type. Only Blob, Uint8Array, and ReadableStream are supported in browser.");
|
|
26
20
|
}
|
|
27
|
-
return toBlobPart(rawContent);
|
|
28
21
|
}
|
|
29
22
|
/**
|
|
30
23
|
* Utility function that concatenates a set of binary inputs into one combined output.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat.common.js","sourceRoot":"","sources":["../../../src/util/concat.common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"concat.common.js","sourceRoot":"","sources":["../../../src/util/concat.common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;GAGG;AACH,SAAS,KAAK,CAAC,MAAkC;IAC/C,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AACrC,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,MAAsD;IAEtD,IAAI,MAAM,YAAY,IAAI,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QAC3D,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,8FAA8F,CAC/F,CAAC;IACJ,CAAC;AACH,CAAC;AASD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAgD;IAEhD,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isWebReadableStream } from \"./typeGuards.js\";\n\n/**\n * Drain the content of the given ReadableStream into a Blob.\n * The blob's content may end up in memory or on disk dependent on size.\n */\nfunction drain(stream: ReadableStream<Uint8Array>): Promise<Blob> {\n return new Response(stream).blob();\n}\n\nasync function toBlobPart(\n source: ReadableStream<Uint8Array> | Blob | Uint8Array,\n): Promise<BlobPart> {\n if (source instanceof Blob || source instanceof Uint8Array) {\n return source;\n }\n\n if (isWebReadableStream(source)) {\n return drain(source);\n } else {\n throw new Error(\n \"Unsupported source type. Only Blob, Uint8Array, and ReadableStream are supported in browser.\",\n );\n }\n}\n\n/**\n * Accepted binary data types for concat\n *\n * @internal\n */\ntype ConcatSource = ReadableStream<Uint8Array> | Blob | Uint8Array;\n\n/**\n * Utility function that concatenates a set of binary inputs into one combined output.\n *\n * @param sources - array of sources for the concatenation\n * @returns - in Node, a (() =\\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.\n * In browser, returns a `Blob` representing all the concatenated inputs.\n *\n * @internal\n */\nexport async function concat(\n sources: (ConcatSource | (() => ConcatSource))[],\n): Promise<(() => NodeJS.ReadableStream) | Blob> {\n const parts = [];\n for (const source of sources) {\n parts.push(await toBlobPart(typeof source === \"function\" ? source() : source));\n }\n\n return new Blob(parts);\n}\n"]}
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { AbortOptions } from "./aborterUtils.js";
|
|
2
|
-
/**
|
|
3
|
-
* Options for support abort functionality for the delay method
|
|
4
|
-
*/
|
|
5
|
-
export interface DelayOptions extends AbortOptions {
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.
|
|
9
|
-
* @param timeInMs - The number of milliseconds to be delayed.
|
|
10
|
-
* @param options - The options for delay - currently abort options
|
|
11
|
-
* @returns Promise that is resolved after timeInMs
|
|
12
|
-
*/
|
|
13
|
-
export declare function delay(timeInMs: number, options?: DelayOptions): Promise<void>;
|
|
14
1
|
/**
|
|
15
2
|
* Calculates the delay interval for retry attempts using exponential delay with jitter.
|
|
16
3
|
* @param retryAttempt - The current retry attempt number.
|
|
@@ -1,25 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { createAbortablePromise } from "./createAbortablePromise.js";
|
|
4
3
|
import { getRandomIntegerInclusive } from "./random.js";
|
|
5
|
-
const StandardAbortMessage = "The delay was aborted.";
|
|
6
|
-
/**
|
|
7
|
-
* A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.
|
|
8
|
-
* @param timeInMs - The number of milliseconds to be delayed.
|
|
9
|
-
* @param options - The options for delay - currently abort options
|
|
10
|
-
* @returns Promise that is resolved after timeInMs
|
|
11
|
-
*/
|
|
12
|
-
export function delay(timeInMs, options) {
|
|
13
|
-
let token;
|
|
14
|
-
const { abortSignal, abortErrorMsg } = options !== null && options !== void 0 ? options : {};
|
|
15
|
-
return createAbortablePromise((resolve) => {
|
|
16
|
-
token = setTimeout(resolve, timeInMs);
|
|
17
|
-
}, {
|
|
18
|
-
cleanupBeforeAbort: () => clearTimeout(token),
|
|
19
|
-
abortSignal,
|
|
20
|
-
abortErrorMsg: abortErrorMsg !== null && abortErrorMsg !== void 0 ? abortErrorMsg : StandardAbortMessage,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
4
|
/**
|
|
24
5
|
* Calculates the delay interval for retry attempts using exponential delay with jitter.
|
|
25
6
|
* @param retryAttempt - The current retry attempt number.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../src/util/delay.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;
|
|
1
|
+
{"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../src/util/delay.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAoB,EACpB,MAGC;IAED,6CAA6C;IAC7C,MAAM,gBAAgB,GAAG,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;IAE3E,yCAAyC;IACzC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;IAE1E,gFAAgF;IAChF,mEAAmE;IACnE,MAAM,cAAc,GAAG,YAAY,GAAG,CAAC,GAAG,yBAAyB,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;IAEzF,OAAO,EAAE,cAAc,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { getRandomIntegerInclusive } from \"./random.js\";\n\n/**\n * Calculates the delay interval for retry attempts using exponential delay with jitter.\n * @param retryAttempt - The current retry attempt number.\n * @param config - The exponential retry configuration.\n * @returns An object containing the calculated retry delay.\n */\nexport function calculateRetryDelay(\n retryAttempt: number,\n config: {\n retryDelayInMs: number;\n maxRetryDelayInMs: number;\n },\n): { retryAfterInMs: number } {\n // Exponentially increase the delay each time\n const exponentialDelay = config.retryDelayInMs * Math.pow(2, retryAttempt);\n\n // Don't let the delay exceed the maximum\n const clampedDelay = Math.min(config.maxRetryDelayInMs, exponentialDelay);\n\n // Allow the final value to have some \"jitter\" (within 50% of the delay size) so\n // that retries across multiple clients don't occur simultaneously.\n const retryAfterInMs = clampedDelay / 2 + getRandomIntegerInclusive(0, clampedDelay / 2);\n\n return { retryAfterInMs };\n}\n"]}
|
|
@@ -3,11 +3,4 @@
|
|
|
3
3
|
* @param e - Something caught by a catch clause.
|
|
4
4
|
*/
|
|
5
5
|
export declare function isError(e: unknown): e is Error;
|
|
6
|
-
/**
|
|
7
|
-
* Given what is thought to be an error object, return the message if possible.
|
|
8
|
-
* If the message is missing, returns a stringified version of the input.
|
|
9
|
-
* @param e - Something thrown from a try block
|
|
10
|
-
* @returns The error message or a string of the input
|
|
11
|
-
*/
|
|
12
|
-
export declare function getErrorMessage(e: unknown): string;
|
|
13
6
|
//# sourceMappingURL=error.d.ts.map
|
|
@@ -13,30 +13,4 @@ export function isError(e) {
|
|
|
13
13
|
}
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Given what is thought to be an error object, return the message if possible.
|
|
18
|
-
* If the message is missing, returns a stringified version of the input.
|
|
19
|
-
* @param e - Something thrown from a try block
|
|
20
|
-
* @returns The error message or a string of the input
|
|
21
|
-
*/
|
|
22
|
-
export function getErrorMessage(e) {
|
|
23
|
-
if (isError(e)) {
|
|
24
|
-
return e.message;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
let stringified;
|
|
28
|
-
try {
|
|
29
|
-
if (typeof e === "object" && e) {
|
|
30
|
-
stringified = JSON.stringify(e);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
stringified = String(e);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
stringified = "[unable to stringify input]";
|
|
38
|
-
}
|
|
39
|
-
return `Unknown error ${stringified}`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
16
|
//# sourceMappingURL=error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/util/error.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,CAAU;IAChC,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;QAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC;QACjD,OAAO,OAAO,IAAI,UAAU,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/util/error.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,CAAU;IAChC,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;QAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ,CAAC;QACjD,OAAO,OAAO,IAAI,UAAU,CAAC;IAC/B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isObject } from \"./object.js\";\n\n/**\n * Typeguard for an error object shape (has name and message)\n * @param e - Something caught by a catch clause.\n */\nexport function isError(e: unknown): e is Error {\n if (isObject(e)) {\n const hasName = typeof e.name === \"string\";\n const hasMessage = typeof e.message === \"string\";\n return hasName && hasMessage;\n }\n return false;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { calculateRetryDelay } from "./delay.js";
|
|
2
|
+
export { getRandomIntegerInclusive } from "./random.js";
|
|
3
|
+
export { isObject, type UnknownObject } from "./object.js";
|
|
4
|
+
export { isError } from "./error.js";
|
|
5
|
+
export { computeSha256Hash, computeSha256Hmac } from "./sha256.js";
|
|
6
|
+
export { randomUUID } from "./uuidUtils.js";
|
|
7
|
+
export { isBrowser, isBun, isNodeLike, isNodeRuntime, isDeno, isReactNative, isWebWorker, } from "./checkEnvironment.js";
|
|
8
|
+
export { stringToUint8Array, uint8ArrayToString, type EncodingType } from "./bytesEncoding.js";
|
|
9
|
+
export { Sanitizer, type SanitizerOptions } from "./sanitizer.js";
|
|
10
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
export { calculateRetryDelay } from "./delay.js";
|
|
4
|
+
export { getRandomIntegerInclusive } from "./random.js";
|
|
5
|
+
export { isObject } from "./object.js";
|
|
6
|
+
export { isError } from "./error.js";
|
|
7
|
+
export { computeSha256Hash, computeSha256Hmac } from "./sha256.js";
|
|
8
|
+
export { randomUUID } from "./uuidUtils.js";
|
|
9
|
+
export { isBrowser, isBun, isNodeLike, isNodeRuntime, isDeno, isReactNative, isWebWorker, } from "./checkEnvironment.js";
|
|
10
|
+
export { stringToUint8Array, uint8ArrayToString } from "./bytesEncoding.js";
|
|
11
|
+
export { Sanitizer } from "./sanitizer.js";
|
|
12
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/util/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAsB,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,KAAK,EACL,UAAU,EACV,aAAa,EACb,MAAM,EACN,aAAa,EACb,WAAW,GACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAyB,MAAM,gBAAgB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport { calculateRetryDelay } from \"./delay.js\";\nexport { getRandomIntegerInclusive } from \"./random.js\";\nexport { isObject, type UnknownObject } from \"./object.js\";\nexport { isError } from \"./error.js\";\nexport { computeSha256Hash, computeSha256Hmac } from \"./sha256.js\";\nexport { randomUUID } from \"./uuidUtils.js\";\nexport {\n isBrowser,\n isBun,\n isNodeLike,\n isNodeRuntime,\n isDeno,\n isReactNative,\n isWebWorker,\n} from \"./checkEnvironment.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./bytesEncoding.js\";\nexport { Sanitizer, type SanitizerOptions } from \"./sanitizer.js\";\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Sanitizer options
|
|
3
3
|
*/
|
|
4
4
|
export interface SanitizerOptions {
|
|
5
5
|
/**
|
|
@@ -16,13 +16,23 @@ export interface SanitizerOptions {
|
|
|
16
16
|
additionalAllowedQueryParameters?: string[];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* A utility class to sanitize objects for logging.
|
|
20
20
|
*/
|
|
21
21
|
export declare class Sanitizer {
|
|
22
22
|
private allowedHeaderNames;
|
|
23
23
|
private allowedQueryParameters;
|
|
24
24
|
constructor({ additionalAllowedHeaderNames: allowedHeaderNames, additionalAllowedQueryParameters: allowedQueryParameters, }?: SanitizerOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Sanitizes an object for logging.
|
|
27
|
+
* @param obj - The object to sanitize
|
|
28
|
+
* @returns - The sanitized object as a string
|
|
29
|
+
*/
|
|
25
30
|
sanitize(obj: unknown): string;
|
|
31
|
+
/**
|
|
32
|
+
* Sanitizes a URL for logging.
|
|
33
|
+
* @param value - The URL to sanitize
|
|
34
|
+
* @returns - The sanitized URL as a string
|
|
35
|
+
*/
|
|
26
36
|
sanitizeUrl(value: string): string;
|
|
27
37
|
private sanitizeHeaders;
|
|
28
38
|
private sanitizeQuery;
|
|
@@ -46,7 +46,7 @@ const defaultAllowedHeaderNames = [
|
|
|
46
46
|
];
|
|
47
47
|
const defaultAllowedQueryParameters = ["api-version"];
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* A utility class to sanitize objects for logging.
|
|
50
50
|
*/
|
|
51
51
|
export class Sanitizer {
|
|
52
52
|
constructor({ additionalAllowedHeaderNames: allowedHeaderNames = [], additionalAllowedQueryParameters: allowedQueryParameters = [], } = {}) {
|
|
@@ -55,6 +55,11 @@ export class Sanitizer {
|
|
|
55
55
|
this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));
|
|
56
56
|
this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Sanitizes an object for logging.
|
|
60
|
+
* @param obj - The object to sanitize
|
|
61
|
+
* @returns - The sanitized object as a string
|
|
62
|
+
*/
|
|
58
63
|
sanitize(obj) {
|
|
59
64
|
const seen = new Set();
|
|
60
65
|
return JSON.stringify(obj, (key, value) => {
|
|
@@ -93,6 +98,11 @@ export class Sanitizer {
|
|
|
93
98
|
return value;
|
|
94
99
|
}, 2);
|
|
95
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Sanitizes a URL for logging.
|
|
103
|
+
* @param value - The URL to sanitize
|
|
104
|
+
* @returns - The sanitized URL as a string
|
|
105
|
+
*/
|
|
96
106
|
sanitizeUrl(value) {
|
|
97
107
|
if (typeof value !== "string" || value === null || value === "") {
|
|
98
108
|
return value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizer.js","sourceRoot":"","sources":["../../../src/util/sanitizer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAsB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqB3D,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC,sFAAsF;AACtF,MAAM,yBAAyB,GAAG;IAChC,wBAAwB;IACxB,+BAA+B;IAC/B,gBAAgB;IAChB,6BAA6B;IAC7B,iBAAiB;IACjB,mBAAmB;IACnB,OAAO;IACP,0BAA0B;IAC1B,aAAa;IAEb,kCAAkC;IAClC,8BAA8B;IAC9B,8BAA8B;IAC9B,6BAA6B;IAC7B,+BAA+B;IAC/B,wBAAwB;IACxB,gCAAgC;IAChC,+BAA+B;IAC/B,QAAQ;IAER,QAAQ;IACR,iBAAiB;IACjB,eAAe;IACf,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,MAAM;IACN,MAAM;IACN,SAAS;IACT,UAAU;IACV,mBAAmB;IACnB,eAAe;IACf,qBAAqB;IACrB,eAAe;IACf,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,QAAQ;IACR,mBAAmB;IACnB,YAAY;IACZ,kBAAkB;CACnB,CAAC;AAEF,MAAM,6BAA6B,GAAa,CAAC,aAAa,CAAC,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,SAAS;IAIpB,YAAY,EACV,4BAA4B,EAAE,kBAAkB,GAAG,EAAE,EACrD,gCAAgC,EAAE,sBAAsB,GAAG,EAAE,MACzC,EAAE;QACtB,kBAAkB,GAAG,yBAAyB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC1E,sBAAsB,GAAG,6BAA6B,CAA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AC;IAEO,eAAe,CAAC,GAAkB;QACxC,MAAM,SAAS,GAAkB,EAAE,CAAC;QACpC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;gBACnD,SAAS,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YAC5B,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,GAAG,CAAC,GAAG,cAAc,CAAC;YAClC,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,aAAa,CAAC,KAAoB;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,SAAS,GAAkB,EAAE,CAAC;QAEpC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;gBACrD,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC;YAChC,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type UnknownObject, isObject } from \"./object.js\";\n\n/**\n * Sanitizer options\n */\nexport interface SanitizerOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\nconst RedactedString = \"REDACTED\";\n\n// Make sure this list is up-to-date with the one under core/logger/Readme#Keyconcepts\nconst defaultAllowedHeaderNames = [\n \"x-ms-client-request-id\",\n \"x-ms-return-client-request-id\",\n \"x-ms-useragent\",\n \"x-ms-correlation-request-id\",\n \"x-ms-request-id\",\n \"client-request-id\",\n \"ms-cv\",\n \"return-client-request-id\",\n \"traceparent\",\n\n \"Access-Control-Allow-Credentials\",\n \"Access-Control-Allow-Headers\",\n \"Access-Control-Allow-Methods\",\n \"Access-Control-Allow-Origin\",\n \"Access-Control-Expose-Headers\",\n \"Access-Control-Max-Age\",\n \"Access-Control-Request-Headers\",\n \"Access-Control-Request-Method\",\n \"Origin\",\n\n \"Accept\",\n \"Accept-Encoding\",\n \"Cache-Control\",\n \"Connection\",\n \"Content-Length\",\n \"Content-Type\",\n \"Date\",\n \"ETag\",\n \"Expires\",\n \"If-Match\",\n \"If-Modified-Since\",\n \"If-None-Match\",\n \"If-Unmodified-Since\",\n \"Last-Modified\",\n \"Pragma\",\n \"Request-Id\",\n \"Retry-After\",\n \"Server\",\n \"Transfer-Encoding\",\n \"User-Agent\",\n \"WWW-Authenticate\",\n];\n\nconst defaultAllowedQueryParameters: string[] = [\"api-version\"];\n\n/**\n * A utility class to sanitize objects for logging.\n */\nexport class Sanitizer {\n private allowedHeaderNames: Set<string>;\n private allowedQueryParameters: Set<string>;\n\n constructor({\n additionalAllowedHeaderNames: allowedHeaderNames = [],\n additionalAllowedQueryParameters: allowedQueryParameters = [],\n }: SanitizerOptions = {}) {\n allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);\n allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);\n\n this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));\n this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));\n }\n\n /**\n * Sanitizes an object for logging.\n * @param obj - The object to sanitize\n * @returns - The sanitized object as a string\n */\n public sanitize(obj: unknown): string {\n const seen = new Set<unknown>();\n return JSON.stringify(\n obj,\n (key: string, value: unknown) => {\n // Ensure Errors include their interesting non-enumerable members\n if (value instanceof Error) {\n return {\n ...value,\n name: value.name,\n message: value.message,\n };\n }\n\n if (key === \"headers\") {\n return this.sanitizeHeaders(value as UnknownObject);\n } else if (key === \"url\") {\n return this.sanitizeUrl(value as string);\n } else if (key === \"query\") {\n return this.sanitizeQuery(value as UnknownObject);\n } else if (key === \"body\") {\n // Don't log the request body\n return undefined;\n } else if (key === \"response\") {\n // Don't log response again\n return undefined;\n } else if (key === \"operationSpec\") {\n // When using sendOperationRequest, the request carries a massive\n // field with the autorest spec. No need to log it.\n return undefined;\n } else if (Array.isArray(value) || isObject(value)) {\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n seen.add(value);\n }\n\n return value;\n },\n 2,\n );\n }\n\n /**\n * Sanitizes a URL for logging.\n * @param value - The URL to sanitize\n * @returns - The sanitized URL as a string\n */\n public sanitizeUrl(value: string): string {\n if (typeof value !== \"string\" || value === null || value === \"\") {\n return value;\n }\n\n const url = new URL(value);\n\n if (!url.search) {\n return value;\n }\n\n for (const [key] of url.searchParams) {\n if (!this.allowedQueryParameters.has(key.toLowerCase())) {\n url.searchParams.set(key, RedactedString);\n }\n }\n\n return url.toString();\n }\n\n private sanitizeHeaders(obj: UnknownObject): UnknownObject {\n const sanitized: UnknownObject = {};\n for (const key of Object.keys(obj)) {\n if (this.allowedHeaderNames.has(key.toLowerCase())) {\n sanitized[key] = obj[key];\n } else {\n sanitized[key] = RedactedString;\n }\n }\n return sanitized;\n }\n\n private sanitizeQuery(value: UnknownObject): UnknownObject {\n if (typeof value !== \"object\" || value === null) {\n return value;\n }\n\n const sanitized: UnknownObject = {};\n\n for (const k of Object.keys(value)) {\n if (this.allowedQueryParameters.has(k.toLowerCase())) {\n sanitized[k] = value[k];\n } else {\n sanitized[k] = RedactedString;\n }\n }\n\n return sanitized;\n }\n}\n"]}
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Helper TypeGuard that checks if something is defined or not.
|
|
3
|
-
* @param thing - Anything
|
|
4
|
-
*/
|
|
5
|
-
export declare function isDefined<T>(thing: T | undefined | null): thing is T;
|
|
6
|
-
/**
|
|
7
|
-
* Helper TypeGuard that checks if the input is an object with the specified properties.
|
|
8
|
-
* @param thing - Anything.
|
|
9
|
-
* @param properties - The name of the properties that should appear in the object.
|
|
10
|
-
*/
|
|
11
|
-
export declare function isObjectWithProperties<Thing, PropertyName extends string>(thing: Thing, properties: PropertyName[]): thing is Thing & Record<PropertyName, unknown>;
|
|
12
|
-
/**
|
|
13
|
-
* Helper TypeGuard that checks if the input is an object with the specified property.
|
|
14
|
-
* @param thing - Any object.
|
|
15
|
-
* @param property - The name of the property that should appear in the object.
|
|
16
|
-
*/
|
|
17
|
-
export declare function objectHasProperty<Thing, PropertyName extends string>(thing: Thing, property: PropertyName): thing is Thing & Record<PropertyName, unknown>;
|
|
18
1
|
export declare function isNodeReadableStream(x: unknown): x is NodeJS.ReadableStream;
|
|
19
2
|
export declare function isWebReadableStream(x: unknown): x is ReadableStream;
|
|
20
3
|
export declare function isBinaryBody(body: unknown): body is Uint8Array | NodeJS.ReadableStream | ReadableStream<Uint8Array> | (() => NodeJS.ReadableStream) | (() => ReadableStream<Uint8Array>) | Blob;
|
|
@@ -1,36 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
/**
|
|
4
|
-
* Helper TypeGuard that checks if something is defined or not.
|
|
5
|
-
* @param thing - Anything
|
|
6
|
-
*/
|
|
7
|
-
export function isDefined(thing) {
|
|
8
|
-
return typeof thing !== "undefined" && thing !== null;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Helper TypeGuard that checks if the input is an object with the specified properties.
|
|
12
|
-
* @param thing - Anything.
|
|
13
|
-
* @param properties - The name of the properties that should appear in the object.
|
|
14
|
-
*/
|
|
15
|
-
export function isObjectWithProperties(thing, properties) {
|
|
16
|
-
if (!isDefined(thing) || typeof thing !== "object") {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
for (const property of properties) {
|
|
20
|
-
if (!objectHasProperty(thing, property)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Helper TypeGuard that checks if the input is an object with the specified property.
|
|
28
|
-
* @param thing - Any object.
|
|
29
|
-
* @param property - The name of the property that should appear in the object.
|
|
30
|
-
*/
|
|
31
|
-
export function objectHasProperty(thing, property) {
|
|
32
|
-
return (isDefined(thing) && typeof thing === "object" && property in thing);
|
|
33
|
-
}
|
|
34
3
|
export function isNodeReadableStream(x) {
|
|
35
4
|
return Boolean(x && typeof x["pipe"] === "function");
|
|
36
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../../src/util/typeGuards.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC
|
|
1
|
+
{"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../../src/util/typeGuards.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,UAAU,oBAAoB,CAAC,CAAU;IAC7C,OAAO,OAAO,CAAC,CAAC,IAAI,OAAQ,CAA2B,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,CAAU;IAC5C,OAAO,OAAO,CACZ,CAAC;QACC,OAAQ,CAAoB,CAAC,SAAS,KAAK,UAAU;QACrD,OAAQ,CAAoB,CAAC,GAAG,KAAK,UAAU,CAClD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,IAAa;IAQb,OAAO,CACL,IAAI,KAAK,SAAS;QAClB,CAAC,IAAI,YAAY,UAAU;YACzB,gBAAgB,CAAC,IAAI,CAAC;YACtB,OAAO,IAAI,KAAK,UAAU;YAC1B,IAAI,YAAY,IAAI,CAAC,CACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAU;IACzC,OAAO,oBAAoB,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,CAAU;IAC/B,OAAO,OAAQ,CAAU,CAAC,MAAM,KAAK,UAAU,CAAC;AAClD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport function isNodeReadableStream(x: unknown): x is NodeJS.ReadableStream {\n return Boolean(x && typeof (x as NodeJS.ReadableStream)[\"pipe\"] === \"function\");\n}\n\nexport function isWebReadableStream(x: unknown): x is ReadableStream {\n return Boolean(\n x &&\n typeof (x as ReadableStream).getReader === \"function\" &&\n typeof (x as ReadableStream).tee === \"function\",\n );\n}\n\nexport function isBinaryBody(\n body: unknown,\n): body is\n | Uint8Array\n | NodeJS.ReadableStream\n | ReadableStream<Uint8Array>\n | (() => NodeJS.ReadableStream)\n | (() => ReadableStream<Uint8Array>)\n | Blob {\n return (\n body !== undefined &&\n (body instanceof Uint8Array ||\n isReadableStream(body) ||\n typeof body === \"function\" ||\n body instanceof Blob)\n );\n}\n\nexport function isReadableStream(x: unknown): x is ReadableStream | NodeJS.ReadableStream {\n return isNodeReadableStream(x) || isWebReadableStream(x);\n}\n\nexport function isBlob(x: unknown): x is Blob {\n return typeof (x as Blob).stream === \"function\";\n}\n"]}
|