@typespec/ts-http-runtime 0.3.4-alpha.20260227.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/client/sendRequest.d.ts +10 -1
- package/dist/browser/client/sendRequest.js +8 -2
- package/dist/browser/client/sendRequest.js.map +1 -1
- package/dist/browser/defaultHttpClient.d.ts +1 -1
- package/dist/browser/defaultHttpClient.js +1 -1
- package/dist/browser/defaultHttpClient.js.map +1 -0
- package/dist/browser/index.d.ts +2 -2
- package/dist/browser/index.js +0 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/logger/log.d.ts +1 -1
- package/dist/browser/logger/log.js +1 -1
- package/dist/browser/logger/log.js.map +1 -0
- package/dist/browser/pipelineRequest.d.ts +1 -1
- package/dist/browser/pipelineRequest.js.map +1 -1
- package/dist/browser/policies/decompressResponsePolicy.d.ts +3 -2
- package/dist/browser/policies/decompressResponsePolicy.js +1 -4
- package/dist/browser/policies/decompressResponsePolicy.js.map +1 -0
- package/dist/browser/policies/internal.d.ts +7 -7
- package/dist/browser/policies/internal.js +2 -2
- package/dist/browser/policies/internal.js.map +1 -1
- package/dist/browser/policies/proxyPolicy.common.d.ts +7 -3
- package/dist/browser/policies/proxyPolicy.common.js +2 -2
- package/dist/browser/policies/proxyPolicy.common.js.map +1 -1
- package/dist/browser/policies/proxyPolicy.d.ts +1 -1
- package/dist/browser/policies/proxyPolicy.js +1 -1
- package/dist/browser/policies/proxyPolicy.js.map +1 -0
- package/dist/browser/policies/redirectPolicy.d.ts +7 -0
- package/dist/browser/policies/redirectPolicy.js +13 -4
- package/dist/browser/policies/redirectPolicy.js.map +1 -1
- package/dist/browser/util/bytesEncoding.d.ts +1 -1
- package/dist/browser/util/bytesEncoding.js +1 -1
- package/dist/browser/util/bytesEncoding.js.map +1 -0
- package/dist/browser/util/concat.common.d.ts +1 -2
- package/dist/browser/util/concat.common.js.map +1 -1
- package/dist/browser/util/concat.d.ts +1 -1
- package/dist/browser/util/concat.js +1 -1
- package/dist/browser/util/concat.js.map +1 -0
- package/dist/browser/util/inspect.d.ts +1 -1
- package/dist/browser/util/inspect.js +1 -1
- package/dist/browser/util/inspect.js.map +1 -0
- package/dist/browser/util/sha256.d.ts +1 -1
- package/dist/browser/util/sha256.js +1 -1
- package/dist/browser/util/sha256.js.map +1 -0
- package/dist/browser/util/userAgentPlatform.d.ts +1 -1
- package/dist/browser/util/userAgentPlatform.js +1 -1
- package/dist/browser/util/userAgentPlatform.js.map +1 -0
- package/dist/browser/util/uuidUtils.d.ts +1 -1
- package/dist/browser/util/uuidUtils.js +1 -1
- package/dist/browser/util/uuidUtils.js.map +1 -0
- package/dist/commonjs/abort-controller/AbortError.js +30 -40
- package/dist/commonjs/abort-controller/AbortError.js.map +7 -1
- package/dist/commonjs/auth/credentials.js +36 -25
- package/dist/commonjs/auth/credentials.js.map +7 -1
- package/dist/commonjs/auth/oauth2Flows.js +15 -5
- package/dist/commonjs/auth/oauth2Flows.js.map +7 -1
- package/dist/commonjs/auth/schemes.js +15 -5
- package/dist/commonjs/auth/schemes.js.map +7 -1
- package/dist/commonjs/client/apiVersionPolicy.js +39 -25
- package/dist/commonjs/client/apiVersionPolicy.js.map +7 -1
- package/dist/commonjs/client/clientHelpers.js +62 -39
- package/dist/commonjs/client/clientHelpers.js.map +7 -1
- package/dist/commonjs/client/common.js +15 -5
- package/dist/commonjs/client/common.js.map +7 -1
- package/dist/commonjs/client/getClient.js +170 -82
- package/dist/commonjs/client/getClient.js.map +7 -1
- package/dist/commonjs/client/multipart.js +119 -110
- package/dist/commonjs/client/multipart.js.map +7 -1
- package/dist/commonjs/client/operationOptionHelpers.js +36 -21
- package/dist/commonjs/client/operationOptionHelpers.js.map +7 -1
- package/dist/commonjs/client/restError.js +44 -26
- package/dist/commonjs/client/restError.js.map +7 -1
- package/dist/commonjs/client/sendRequest.d.ts +10 -1
- package/dist/commonjs/client/sendRequest.js +150 -164
- package/dist/commonjs/client/sendRequest.js.map +7 -1
- package/dist/commonjs/client/urlHelpers.js +124 -131
- package/dist/commonjs/client/urlHelpers.js.map +7 -1
- package/dist/commonjs/constants.js +30 -8
- package/dist/commonjs/constants.js.map +7 -1
- package/dist/commonjs/createPipelineFromOptions.js +56 -45
- package/dist/commonjs/createPipelineFromOptions.js.map +7 -1
- package/dist/commonjs/defaultHttpClient.js +28 -11
- package/dist/commonjs/defaultHttpClient.js.map +7 -1
- package/dist/commonjs/fetchHttpClient.js +211 -256
- package/dist/commonjs/fetchHttpClient.js.map +7 -1
- package/dist/commonjs/httpHeaders.js +97 -82
- package/dist/commonjs/httpHeaders.js.map +7 -1
- package/dist/commonjs/index.d.ts +2 -2
- package/dist/commonjs/index.js +67 -36
- package/dist/commonjs/index.js.map +7 -1
- package/dist/commonjs/interfaces.js +15 -5
- package/dist/commonjs/interfaces.js.map +7 -1
- package/dist/commonjs/log.js +28 -8
- package/dist/commonjs/log.js.map +7 -1
- package/dist/commonjs/logger/debug.js +150 -155
- package/dist/commonjs/logger/debug.js.map +7 -1
- package/dist/commonjs/logger/internal.js +27 -8
- package/dist/commonjs/logger/internal.js.map +7 -1
- package/dist/commonjs/logger/log.common.js +39 -23
- package/dist/commonjs/logger/log.common.js.map +7 -1
- package/dist/commonjs/logger/log.js +40 -11
- package/dist/commonjs/logger/log.js.map +7 -1
- package/dist/commonjs/logger/logger.js +120 -110
- package/dist/commonjs/logger/logger.js.map +7 -1
- package/dist/commonjs/nodeHttpClient.js +313 -321
- package/dist/commonjs/nodeHttpClient.js.map +7 -1
- package/dist/commonjs/pipeline.js +190 -247
- package/dist/commonjs/pipeline.js.map +7 -1
- package/dist/commonjs/pipelineRequest.d.ts +1 -1
- package/dist/commonjs/pipelineRequest.js +69 -54
- package/dist/commonjs/pipelineRequest.js.map +7 -1
- package/dist/commonjs/policies/agentPolicy.js +38 -24
- package/dist/commonjs/policies/agentPolicy.js.map +7 -1
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +45 -32
- package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +7 -1
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +50 -32
- package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +7 -1
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +47 -32
- package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +7 -1
- package/dist/commonjs/policies/auth/checkInsecureConnection.js +47 -44
- package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +7 -1
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +45 -32
- package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +7 -1
- package/dist/commonjs/policies/decompressResponsePolicy.js +38 -25
- package/dist/commonjs/policies/decompressResponsePolicy.js.map +7 -1
- package/dist/commonjs/policies/defaultRetryPolicy.js +39 -27
- package/dist/commonjs/policies/defaultRetryPolicy.js.map +7 -1
- package/dist/commonjs/policies/exponentialRetryPolicy.js +43 -26
- package/dist/commonjs/policies/exponentialRetryPolicy.js.map +7 -1
- package/dist/commonjs/policies/formDataPolicy.js +101 -90
- package/dist/commonjs/policies/formDataPolicy.js.map +7 -1
- package/dist/commonjs/policies/internal.d.ts +7 -7
- package/dist/commonjs/policies/internal.js +94 -48
- package/dist/commonjs/policies/internal.js.map +7 -1
- package/dist/commonjs/policies/logPolicy.js +49 -35
- package/dist/commonjs/policies/logPolicy.js.map +7 -1
- package/dist/commonjs/policies/multipartPolicy.js +117 -99
- package/dist/commonjs/policies/multipartPolicy.js.map +7 -1
- package/dist/commonjs/policies/proxyPolicy.common.d.ts +7 -3
- package/dist/commonjs/policies/proxyPolicy.common.js +38 -25
- package/dist/commonjs/policies/proxyPolicy.common.js.map +7 -1
- package/dist/commonjs/policies/proxyPolicy.js +160 -171
- package/dist/commonjs/policies/proxyPolicy.js.map +7 -1
- package/dist/commonjs/policies/redirectPolicy.d.ts +7 -0
- package/dist/commonjs/policies/redirectPolicy.js +62 -51
- package/dist/commonjs/policies/redirectPolicy.js.map +7 -1
- package/dist/commonjs/policies/retryPolicy.js +123 -105
- package/dist/commonjs/policies/retryPolicy.js.map +7 -1
- package/dist/commonjs/policies/systemErrorRetryPolicy.js +46 -31
- package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +7 -1
- package/dist/commonjs/policies/throttlingRetryPolicy.js +38 -30
- package/dist/commonjs/policies/throttlingRetryPolicy.js.map +7 -1
- package/dist/commonjs/policies/tlsPolicy.js +38 -24
- package/dist/commonjs/policies/tlsPolicy.js.map +7 -1
- package/dist/commonjs/policies/userAgentPolicy.js +41 -28
- package/dist/commonjs/policies/userAgentPolicy.js.map +7 -1
- package/dist/commonjs/restError.js +93 -90
- package/dist/commonjs/restError.js.map +7 -1
- package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +63 -62
- package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +7 -1
- package/dist/commonjs/retryStrategies/retryStrategy.js +15 -5
- package/dist/commonjs/retryStrategies/retryStrategy.js.map +7 -1
- package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +58 -69
- package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +7 -1
- package/dist/commonjs/util/arrayBuffer.js +34 -21
- package/dist/commonjs/util/arrayBuffer.js.map +7 -1
- package/dist/commonjs/util/bytesEncoding.common.js +83 -100
- package/dist/commonjs/util/bytesEncoding.common.js.map +7 -1
- package/dist/commonjs/util/bytesEncoding.js +30 -21
- package/dist/commonjs/util/bytesEncoding.js.map +7 -1
- package/dist/commonjs/util/checkEnvironment.js +45 -44
- package/dist/commonjs/util/checkEnvironment.js.map +7 -1
- package/dist/commonjs/util/concat.common.d.ts +1 -2
- package/dist/commonjs/util/concat.common.js +51 -52
- package/dist/commonjs/util/concat.common.js.map +7 -1
- package/dist/commonjs/util/concat.js +70 -61
- package/dist/commonjs/util/concat.js.map +7 -1
- package/dist/commonjs/util/delay.js +31 -21
- package/dist/commonjs/util/delay.js.map +7 -1
- package/dist/commonjs/util/error.js +33 -17
- package/dist/commonjs/util/error.js.map +7 -1
- package/dist/commonjs/util/helpers.js +65 -57
- package/dist/commonjs/util/helpers.js.map +7 -1
- package/dist/commonjs/util/inspect.common.js +27 -7
- package/dist/commonjs/util/inspect.common.js.map +7 -1
- package/dist/commonjs/util/inspect.js +28 -8
- package/dist/commonjs/util/inspect.js.map +7 -1
- package/dist/commonjs/util/internal.js +67 -32
- package/dist/commonjs/util/internal.js.map +7 -1
- package/dist/commonjs/util/object.js +27 -15
- package/dist/commonjs/util/object.js.map +7 -1
- package/dist/commonjs/util/random.js +30 -22
- package/dist/commonjs/util/random.js.map +7 -1
- package/dist/commonjs/util/sanitizer.js +157 -148
- package/dist/commonjs/util/sanitizer.js.map +7 -1
- package/dist/commonjs/util/sha256.common.js +61 -45
- package/dist/commonjs/util/sha256.common.js.map +7 -1
- package/dist/commonjs/util/sha256.js +32 -22
- package/dist/commonjs/util/sha256.js.map +7 -1
- package/dist/commonjs/util/typeGuards.js +41 -21
- package/dist/commonjs/util/typeGuards.js.map +7 -1
- package/dist/commonjs/util/userAgent.js +43 -28
- package/dist/commonjs/util/userAgent.js.map +7 -1
- package/dist/commonjs/util/userAgentPlatform.js +51 -29
- package/dist/commonjs/util/userAgentPlatform.js.map +7 -1
- package/dist/commonjs/util/uuidUtils.common.js +43 -39
- package/dist/commonjs/util/uuidUtils.common.js.map +7 -1
- package/dist/commonjs/util/uuidUtils.js +27 -12
- package/dist/commonjs/util/uuidUtils.js.map +7 -1
- package/dist/commonjs/xhrHttpClient.js +171 -163
- package/dist/commonjs/xhrHttpClient.js.map +7 -1
- package/dist/esm/client/sendRequest.d.ts +10 -1
- package/dist/esm/client/sendRequest.js +8 -2
- package/dist/esm/client/sendRequest.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pipelineRequest.d.ts +1 -1
- package/dist/esm/pipelineRequest.js.map +1 -1
- package/dist/esm/policies/internal.d.ts +7 -7
- package/dist/esm/policies/internal.js +2 -2
- package/dist/esm/policies/internal.js.map +1 -1
- package/dist/esm/policies/proxyPolicy.common.d.ts +7 -3
- package/dist/esm/policies/proxyPolicy.common.js +2 -2
- package/dist/esm/policies/proxyPolicy.common.js.map +1 -1
- package/dist/esm/policies/redirectPolicy.d.ts +7 -0
- package/dist/esm/policies/redirectPolicy.js +13 -4
- package/dist/esm/policies/redirectPolicy.js.map +1 -1
- package/dist/esm/util/concat.common.d.ts +1 -2
- package/dist/esm/util/concat.common.js.map +1 -1
- package/dist/react-native/client/sendRequest.d.ts +10 -1
- package/dist/react-native/client/sendRequest.js +8 -2
- package/dist/react-native/client/sendRequest.js.map +1 -1
- package/dist/react-native/defaultHttpClient.d.ts +1 -1
- package/dist/react-native/defaultHttpClient.js +1 -1
- package/dist/react-native/defaultHttpClient.js.map +1 -0
- package/dist/react-native/index.d.ts +2 -2
- package/dist/react-native/index.js +0 -2
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/logger/log.d.ts +1 -1
- package/dist/react-native/logger/log.js +1 -1
- package/dist/react-native/logger/log.js.map +1 -0
- package/dist/react-native/pipelineRequest.d.ts +1 -1
- package/dist/react-native/pipelineRequest.js.map +1 -1
- package/dist/react-native/policies/internal.d.ts +7 -7
- package/dist/react-native/policies/internal.js +2 -2
- package/dist/react-native/policies/internal.js.map +1 -1
- package/dist/react-native/policies/proxyPolicy.common.d.ts +7 -3
- package/dist/react-native/policies/proxyPolicy.common.js +2 -2
- package/dist/react-native/policies/proxyPolicy.common.js.map +1 -1
- package/dist/react-native/policies/proxyPolicy.d.ts +1 -1
- package/dist/react-native/policies/proxyPolicy.js +1 -1
- package/dist/react-native/policies/proxyPolicy.js.map +1 -0
- package/dist/react-native/policies/redirectPolicy.d.ts +7 -0
- package/dist/react-native/policies/redirectPolicy.js +13 -4
- package/dist/react-native/policies/redirectPolicy.js.map +1 -1
- package/dist/react-native/util/bytesEncoding.d.ts +1 -1
- package/dist/react-native/util/bytesEncoding.js +1 -1
- package/dist/react-native/util/bytesEncoding.js.map +1 -0
- package/dist/react-native/util/concat.common.d.ts +1 -2
- package/dist/react-native/util/concat.common.js.map +1 -1
- package/dist/react-native/util/concat.d.ts +1 -1
- package/dist/react-native/util/concat.js +1 -1
- package/dist/react-native/util/concat.js.map +1 -0
- package/dist/react-native/util/inspect.d.ts +1 -1
- package/dist/react-native/util/inspect.js +1 -1
- package/dist/react-native/util/inspect.js.map +1 -0
- package/dist/react-native/util/sha256.d.ts +1 -1
- package/dist/react-native/util/sha256.js +1 -1
- package/dist/react-native/util/sha256.js.map +1 -0
- package/dist/react-native/util/userAgentPlatform.d.ts +1 -1
- package/dist/react-native/util/userAgentPlatform.js +1 -1
- package/dist/react-native/util/userAgentPlatform.js.map +1 -0
- package/dist/react-native/util/uuidUtils.d.ts +1 -1
- package/dist/react-native/util/uuidUtils.js +1 -1
- package/dist/react-native/util/uuidUtils.js.map +1 -0
- package/package.json +1 -21
- package/dist/browser/defaultHttpClient-browser.mjs.map +0 -1
- package/dist/browser/logger/log-browser.mjs.map +0 -1
- package/dist/browser/policies/decompressResponsePolicy-browser.mjs.map +0 -1
- package/dist/browser/policies/proxyPolicy-browser.mjs.map +0 -1
- package/dist/browser/util/bytesEncoding-browser.mjs.map +0 -1
- package/dist/browser/util/concat-browser.mjs.map +0 -1
- package/dist/browser/util/inspect-browser.mjs.map +0 -1
- package/dist/browser/util/sha256-browser.mjs.map +0 -1
- package/dist/browser/util/userAgentPlatform-browser.mjs.map +0 -1
- package/dist/browser/util/uuidUtils-browser.mjs.map +0 -1
- package/dist/react-native/defaultHttpClient-react-native.mjs.map +0 -1
- package/dist/react-native/logger/log-react-native.mjs.map +0 -1
- package/dist/react-native/policies/proxyPolicy-react-native.mjs.map +0 -1
- package/dist/react-native/util/bytesEncoding-react-native.mjs.map +0 -1
- package/dist/react-native/util/concat-react-native.mjs.map +0 -1
- package/dist/react-native/util/inspect-react-native.mjs.map +0 -1
- package/dist/react-native/util/sha256-react-native.mjs.map +0 -1
- package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +0 -1
- package/dist/react-native/util/uuidUtils-react-native.mjs.map +0 -1
|
@@ -1,78 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var throttlingRetryStrategy_exports = {};
|
|
19
|
+
__export(throttlingRetryStrategy_exports, {
|
|
20
|
+
isThrottlingRetryResponse: () => isThrottlingRetryResponse,
|
|
21
|
+
throttlingRetryStrategy: () => throttlingRetryStrategy
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(throttlingRetryStrategy_exports);
|
|
24
|
+
var import_helpers = require("../util/helpers.js");
|
|
12
25
|
const RetryAfterHeader = "Retry-After";
|
|
13
|
-
/**
|
|
14
|
-
* The headers that come back from services representing
|
|
15
|
-
* the amount of time (minimum) to wait to retry.
|
|
16
|
-
*
|
|
17
|
-
* "retry-after-ms", "x-ms-retry-after-ms" : milliseconds
|
|
18
|
-
* "Retry-After" : seconds or timestamp
|
|
19
|
-
*/
|
|
20
26
|
const AllRetryAfterHeaders = ["retry-after-ms", "x-ms-retry-after-ms", RetryAfterHeader];
|
|
21
|
-
/**
|
|
22
|
-
* A response is a throttling retry response if it has a throttling status code (429 or 503),
|
|
23
|
-
* as long as one of the [ "Retry-After" or "retry-after-ms" or "x-ms-retry-after-ms" ] headers has a valid value.
|
|
24
|
-
*
|
|
25
|
-
* Returns the `retryAfterInMs` value if the response is a throttling retry response.
|
|
26
|
-
* If not throttling retry response, returns `undefined`.
|
|
27
|
-
*
|
|
28
|
-
* @internal
|
|
29
|
-
*/
|
|
30
27
|
function getRetryAfterInMs(response) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// "retry-after-ms", "x-ms-retry-after-ms" headers ==> milli-seconds
|
|
40
|
-
const multiplyingFactor = header === RetryAfterHeader ? 1000 : 1;
|
|
41
|
-
return retryAfterValue * multiplyingFactor; // in milli-seconds
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
// RetryAfterHeader ("Retry-After") has a special case where it might be formatted as a date instead of a number of seconds
|
|
45
|
-
const retryAfterHeader = response.headers.get(RetryAfterHeader);
|
|
46
|
-
if (!retryAfterHeader)
|
|
47
|
-
return;
|
|
48
|
-
const date = Date.parse(retryAfterHeader);
|
|
49
|
-
const diff = date - Date.now();
|
|
50
|
-
// negative diff would mean a date in the past, so retry asap with 0 milliseconds
|
|
51
|
-
return Number.isFinite(diff) ? Math.max(0, diff) : undefined;
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return undefined;
|
|
28
|
+
if (!(response && [429, 503].includes(response.status))) return void 0;
|
|
29
|
+
try {
|
|
30
|
+
for (const header of AllRetryAfterHeaders) {
|
|
31
|
+
const retryAfterValue = (0, import_helpers.parseHeaderValueAsNumber)(response, header);
|
|
32
|
+
if (retryAfterValue === 0 || retryAfterValue) {
|
|
33
|
+
const multiplyingFactor = header === RetryAfterHeader ? 1e3 : 1;
|
|
34
|
+
return retryAfterValue * multiplyingFactor;
|
|
35
|
+
}
|
|
55
36
|
}
|
|
37
|
+
const retryAfterHeader = response.headers.get(RetryAfterHeader);
|
|
38
|
+
if (!retryAfterHeader) return;
|
|
39
|
+
const date = Date.parse(retryAfterHeader);
|
|
40
|
+
const diff = date - Date.now();
|
|
41
|
+
return Number.isFinite(diff) ? Math.max(0, diff) : void 0;
|
|
42
|
+
} catch {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
56
45
|
}
|
|
57
|
-
/**
|
|
58
|
-
* A response is a retry response if it has a throttling status code (429 or 503),
|
|
59
|
-
* as long as one of the [ "Retry-After" or "retry-after-ms" or "x-ms-retry-after-ms" ] headers has a valid value.
|
|
60
|
-
*/
|
|
61
46
|
function isThrottlingRetryResponse(response) {
|
|
62
|
-
|
|
47
|
+
return Number.isFinite(getRetryAfterInMs(response));
|
|
63
48
|
}
|
|
64
49
|
function throttlingRetryStrategy() {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
50
|
+
return {
|
|
51
|
+
name: "throttlingRetryStrategy",
|
|
52
|
+
retry({ response }) {
|
|
53
|
+
const retryAfterInMs = getRetryAfterInMs(response);
|
|
54
|
+
if (!Number.isFinite(retryAfterInMs)) {
|
|
55
|
+
return { skipStrategy: true };
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
retryAfterInMs
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
77
62
|
}
|
|
78
|
-
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
isThrottlingRetryResponse,
|
|
66
|
+
throttlingRetryStrategy
|
|
67
|
+
});
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["/mnt/vss/_work/1/s/sdk/core/ts-http-runtime/src/retryStrategies/throttlingRetryStrategy.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineResponse } from \"../interfaces.js\";\nimport { parseHeaderValueAsNumber } from \"../util/helpers.js\";\nimport type { RetryStrategy } from \"./retryStrategy.js\";\n\n/**\n * The header that comes back from services representing\n * the amount of time (minimum) to wait to retry (in seconds or timestamp after which we can retry).\n */\nconst RetryAfterHeader = \"Retry-After\";\n/**\n * The headers that come back from services representing\n * the amount of time (minimum) to wait to retry.\n *\n * \"retry-after-ms\", \"x-ms-retry-after-ms\" : milliseconds\n * \"Retry-After\" : seconds or timestamp\n */\nconst AllRetryAfterHeaders: string[] = [\"retry-after-ms\", \"x-ms-retry-after-ms\", RetryAfterHeader];\n\n/**\n * A response is a throttling retry response if it has a throttling status code (429 or 503),\n * as long as one of the [ \"Retry-After\" or \"retry-after-ms\" or \"x-ms-retry-after-ms\" ] headers has a valid value.\n *\n * Returns the `retryAfterInMs` value if the response is a throttling retry response.\n * If not throttling retry response, returns `undefined`.\n *\n * @internal\n */\nfunction getRetryAfterInMs(response?: PipelineResponse): number | undefined {\n if (!(response && [429, 503].includes(response.status))) return undefined;\n try {\n // Headers: \"retry-after-ms\", \"x-ms-retry-after-ms\", \"Retry-After\"\n for (const header of AllRetryAfterHeaders) {\n const retryAfterValue = parseHeaderValueAsNumber(response, header);\n if (retryAfterValue === 0 || retryAfterValue) {\n // \"Retry-After\" header ==> seconds\n // \"retry-after-ms\", \"x-ms-retry-after-ms\" headers ==> milli-seconds\n const multiplyingFactor = header === RetryAfterHeader ? 1000 : 1;\n return retryAfterValue * multiplyingFactor; // in milli-seconds\n }\n }\n\n // RetryAfterHeader (\"Retry-After\") has a special case where it might be formatted as a date instead of a number of seconds\n const retryAfterHeader = response.headers.get(RetryAfterHeader);\n if (!retryAfterHeader) return;\n\n const date = Date.parse(retryAfterHeader);\n const diff = date - Date.now();\n // negative diff would mean a date in the past, so retry asap with 0 milliseconds\n return Number.isFinite(diff) ? Math.max(0, diff) : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * A response is a retry response if it has a throttling status code (429 or 503),\n * as long as one of the [ \"Retry-After\" or \"retry-after-ms\" or \"x-ms-retry-after-ms\" ] headers has a valid value.\n */\nexport function isThrottlingRetryResponse(response?: PipelineResponse): boolean {\n return Number.isFinite(getRetryAfterInMs(response));\n}\n\nexport function throttlingRetryStrategy(): RetryStrategy {\n return {\n name: \"throttlingRetryStrategy\",\n retry({ response }) {\n const retryAfterInMs = getRetryAfterInMs(response);\n if (!Number.isFinite(retryAfterInMs)) {\n return { skipStrategy: true };\n }\n return {\n retryAfterInMs,\n };\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAAyC;AAOzC,MAAM,mBAAmB;AAQzB,MAAM,uBAAiC,CAAC,kBAAkB,uBAAuB,gBAAgB;AAWjG,SAAS,kBAAkB,UAAiD;AAC1E,MAAI,EAAE,YAAY,CAAC,KAAK,GAAG,EAAE,SAAS,SAAS,MAAM,GAAI,QAAO;AAChE,MAAI;AAEF,eAAW,UAAU,sBAAsB;AACzC,YAAM,sBAAkB,yCAAyB,UAAU,MAAM;AACjE,UAAI,oBAAoB,KAAK,iBAAiB;AAG5C,cAAM,oBAAoB,WAAW,mBAAmB,MAAO;AAC/D,eAAO,kBAAkB;AAAA,MAC3B;AAAA,IACF;AAGA,UAAM,mBAAmB,SAAS,QAAQ,IAAI,gBAAgB;AAC9D,QAAI,CAAC,iBAAkB;AAEvB,UAAM,OAAO,KAAK,MAAM,gBAAgB;AACxC,UAAM,OAAO,OAAO,KAAK,IAAI;AAE7B,WAAO,OAAO,SAAS,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,IAAI;AAAA,EACrD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,0BAA0B,UAAsC;AAC9E,SAAO,OAAO,SAAS,kBAAkB,QAAQ,CAAC;AACpD;AAEO,SAAS,0BAAyC;AACvD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,EAAE,SAAS,GAAG;AAClB,YAAM,iBAAiB,kBAAkB,QAAQ;AACjD,UAAI,CAAC,OAAO,SAAS,cAAc,GAAG;AACpC,eAAO,EAAE,cAAc,KAAK;AAAA,MAC9B;AACA,aAAO;AAAA,QACL;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var arrayBuffer_exports = {};
|
|
19
|
+
__export(arrayBuffer_exports, {
|
|
20
|
+
arrayBufferViewToArrayBuffer: () => arrayBufferViewToArrayBuffer
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(arrayBuffer_exports);
|
|
11
23
|
function arrayBufferViewToArrayBuffer(source) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
view.set(sourceView);
|
|
21
|
-
return view.buffer;
|
|
24
|
+
if (source.buffer instanceof ArrayBuffer && source.byteOffset === 0 && source.byteLength === source.buffer.byteLength) {
|
|
25
|
+
return source.buffer;
|
|
26
|
+
}
|
|
27
|
+
const arrayBuffer = new ArrayBuffer(source.byteLength);
|
|
28
|
+
const view = new Uint8Array(arrayBuffer);
|
|
29
|
+
const sourceView = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
30
|
+
view.set(sourceView);
|
|
31
|
+
return view.buffer;
|
|
22
32
|
}
|
|
23
|
-
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
arrayBufferViewToArrayBuffer
|
|
36
|
+
});
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["/mnt/vss/_work/1/s/sdk/core/ts-http-runtime/src/util/arrayBuffer.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Converts an ArrayBufferView to an ArrayBuffer.\n * @param source - The source ArrayBufferView.\n * @returns The resulting ArrayBuffer.\n */\nexport function arrayBufferViewToArrayBuffer(source: ArrayBufferView): ArrayBuffer {\n if (\n source.buffer instanceof ArrayBuffer &&\n source.byteOffset === 0 &&\n source.byteLength === source.buffer.byteLength\n ) {\n return source.buffer;\n }\n\n const arrayBuffer = new ArrayBuffer(source.byteLength);\n const view = new Uint8Array(arrayBuffer);\n const sourceView = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);\n view.set(sourceView);\n return view.buffer;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,SAAS,6BAA6B,QAAsC;AACjF,MACE,OAAO,kBAAkB,eACzB,OAAO,eAAe,KACtB,OAAO,eAAe,OAAO,OAAO,YACpC;AACA,WAAO,OAAO;AAAA,EAChB;AAEA,QAAM,cAAc,IAAI,YAAY,OAAO,UAAU;AACrD,QAAM,OAAO,IAAI,WAAW,WAAW;AACvC,QAAM,aAAa,IAAI,WAAW,OAAO,QAAQ,OAAO,YAAY,OAAO,UAAU;AACrF,OAAK,IAAI,UAAU;AACnB,SAAO,KAAK;AACd;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,122 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var bytesEncoding_common_exports = {};
|
|
19
|
+
__export(bytesEncoding_common_exports, {
|
|
20
|
+
base64ToUint8Array: () => base64ToUint8Array,
|
|
21
|
+
base64UrlToUint8Array: () => base64UrlToUint8Array,
|
|
22
|
+
hexStringToUint8Array: () => hexStringToUint8Array,
|
|
23
|
+
stringToUint8Array: () => stringToUint8Array,
|
|
24
|
+
uint8ArrayToBase64: () => uint8ArrayToBase64,
|
|
25
|
+
uint8ArrayToBase64Url: () => uint8ArrayToBase64Url,
|
|
26
|
+
uint8ArrayToHexString: () => uint8ArrayToHexString,
|
|
27
|
+
uint8ArrayToString: () => uint8ArrayToString,
|
|
28
|
+
uint8ArrayToUtf8String: () => uint8ArrayToUtf8String,
|
|
29
|
+
utf8StringToUint8Array: () => utf8StringToUint8Array
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(bytesEncoding_common_exports);
|
|
21
32
|
function uint8ArrayToString(bytes, format) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
switch (format) {
|
|
34
|
+
case "utf-8":
|
|
35
|
+
return uint8ArrayToUtf8String(bytes);
|
|
36
|
+
case "base64":
|
|
37
|
+
return uint8ArrayToBase64(bytes);
|
|
38
|
+
case "base64url":
|
|
39
|
+
return uint8ArrayToBase64Url(bytes);
|
|
40
|
+
case "hex":
|
|
41
|
+
return uint8ArrayToHexString(bytes);
|
|
42
|
+
}
|
|
32
43
|
}
|
|
33
|
-
/**
|
|
34
|
-
* The helper that transforms string to specific character encoded bytes array.
|
|
35
|
-
* @param value - the string to be converted
|
|
36
|
-
* @param format - the format we use to decode the value
|
|
37
|
-
* @returns a uint8array
|
|
38
|
-
*/
|
|
39
44
|
function stringToUint8Array(value, format) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
switch (format) {
|
|
46
|
+
case "utf-8":
|
|
47
|
+
return utf8StringToUint8Array(value);
|
|
48
|
+
case "base64":
|
|
49
|
+
return base64ToUint8Array(value);
|
|
50
|
+
case "base64url":
|
|
51
|
+
return base64UrlToUint8Array(value);
|
|
52
|
+
case "hex":
|
|
53
|
+
return hexStringToUint8Array(value);
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Decodes a Uint8Array into a Base64 string.
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
56
|
function uint8ArrayToBase64(bytes) {
|
|
56
|
-
|
|
57
|
+
return btoa([...bytes].map((x) => String.fromCharCode(x)).join(""));
|
|
57
58
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Decodes a Uint8Array into a Base64Url string.
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
59
|
function uint8ArrayToBase64Url(bytes) {
|
|
63
|
-
|
|
60
|
+
return uint8ArrayToBase64(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
64
61
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Decodes a Uint8Array into a javascript string.
|
|
67
|
-
* @internal
|
|
68
|
-
*/
|
|
69
62
|
function uint8ArrayToUtf8String(bytes) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
const decoder = new TextDecoder();
|
|
64
|
+
const dataString = decoder.decode(bytes);
|
|
65
|
+
return dataString;
|
|
73
66
|
}
|
|
74
|
-
/**
|
|
75
|
-
* Decodes a Uint8Array into a hex string
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
67
|
function uint8ArrayToHexString(bytes) {
|
|
79
|
-
|
|
68
|
+
return [...bytes].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
80
69
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Encodes a JavaScript string into a Uint8Array.
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
70
|
function utf8StringToUint8Array(value) {
|
|
86
|
-
|
|
71
|
+
return new TextEncoder().encode(value);
|
|
87
72
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Encodes a Base64 string into a Uint8Array.
|
|
90
|
-
* @internal
|
|
91
|
-
*/
|
|
92
73
|
function base64ToUint8Array(value) {
|
|
93
|
-
|
|
74
|
+
return new Uint8Array([...atob(value)].map((x) => x.charCodeAt(0)));
|
|
94
75
|
}
|
|
95
|
-
/**
|
|
96
|
-
* Encodes a Base64Url string into a Uint8Array.
|
|
97
|
-
* @internal
|
|
98
|
-
*/
|
|
99
76
|
function base64UrlToUint8Array(value) {
|
|
100
|
-
|
|
101
|
-
|
|
77
|
+
const base64String = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
78
|
+
return base64ToUint8Array(base64String);
|
|
102
79
|
}
|
|
103
80
|
const hexDigits = new Set("0123456789abcdefABCDEF");
|
|
104
|
-
/**
|
|
105
|
-
* Encodes a hex string into a Uint8Array
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
81
|
function hexStringToUint8Array(value) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
// Replicate Node Buffer behavior by exiting early when we encounter an invalid byte
|
|
116
|
-
return bytes.slice(0, i);
|
|
117
|
-
}
|
|
118
|
-
bytes[i] = parseInt(`${highNibble}${lowNibble}`, 16);
|
|
82
|
+
const bytes = new Uint8Array(value.length / 2);
|
|
83
|
+
for (let i = 0; i < value.length / 2; ++i) {
|
|
84
|
+
const highNibble = value[2 * i];
|
|
85
|
+
const lowNibble = value[2 * i + 1];
|
|
86
|
+
if (!hexDigits.has(highNibble) || !hexDigits.has(lowNibble)) {
|
|
87
|
+
return bytes.slice(0, i);
|
|
119
88
|
}
|
|
120
|
-
|
|
89
|
+
bytes[i] = parseInt(`${highNibble}${lowNibble}`, 16);
|
|
90
|
+
}
|
|
91
|
+
return bytes;
|
|
121
92
|
}
|
|
122
|
-
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
base64ToUint8Array,
|
|
96
|
+
base64UrlToUint8Array,
|
|
97
|
+
hexStringToUint8Array,
|
|
98
|
+
stringToUint8Array,
|
|
99
|
+
uint8ArrayToBase64,
|
|
100
|
+
uint8ArrayToBase64Url,
|
|
101
|
+
uint8ArrayToHexString,
|
|
102
|
+
uint8ArrayToString,
|
|
103
|
+
uint8ArrayToUtf8String,
|
|
104
|
+
utf8StringToUint8Array
|
|
105
|
+
});
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["/mnt/vss/_work/1/s/sdk/core/ts-http-runtime/src/util/bytesEncoding.common.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n // stub these out for the browser\n function btoa(input: string): string;\n function atob(input: string): string;\n}\n\n/** The supported character encoding type */\nexport type EncodingType = \"utf-8\" | \"base64\" | \"base64url\" | \"hex\";\n\n/**\n * The helper that transforms bytes with specific character encoding into string\n * @param bytes - the uint8array bytes\n * @param format - the format we use to encode the byte\n * @returns a string of the encoded string\n */\nexport function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string {\n switch (format) {\n case \"utf-8\":\n return uint8ArrayToUtf8String(bytes);\n case \"base64\":\n return uint8ArrayToBase64(bytes);\n case \"base64url\":\n return uint8ArrayToBase64Url(bytes);\n case \"hex\":\n return uint8ArrayToHexString(bytes);\n }\n}\n\n/**\n * The helper that transforms string to specific character encoded bytes array.\n * @param value - the string to be converted\n * @param format - the format we use to decode the value\n * @returns a uint8array\n */\nexport function stringToUint8Array(value: string, format: EncodingType): Uint8Array {\n switch (format) {\n case \"utf-8\":\n return utf8StringToUint8Array(value);\n case \"base64\":\n return base64ToUint8Array(value);\n case \"base64url\":\n return base64UrlToUint8Array(value);\n case \"hex\":\n return hexStringToUint8Array(value);\n }\n}\n\n/**\n * Decodes a Uint8Array into a Base64 string.\n * @internal\n */\nexport function uint8ArrayToBase64(bytes: Uint8Array): string {\n return btoa([...bytes].map((x) => String.fromCharCode(x)).join(\"\"));\n}\n\n/**\n * Decodes a Uint8Array into a Base64Url string.\n * @internal\n */\nexport function uint8ArrayToBase64Url(bytes: Uint8Array): string {\n return uint8ArrayToBase64(bytes).replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=/g, \"\");\n}\n\n/**\n * Decodes a Uint8Array into a javascript string.\n * @internal\n */\nexport function uint8ArrayToUtf8String(bytes: Uint8Array): string {\n const decoder = new TextDecoder();\n const dataString = decoder.decode(bytes);\n return dataString;\n}\n\n/**\n * Decodes a Uint8Array into a hex string\n * @internal\n */\nexport function uint8ArrayToHexString(bytes: Uint8Array): string {\n return [...bytes].map((x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/**\n * Encodes a JavaScript string into a Uint8Array.\n * @internal\n */\nexport function utf8StringToUint8Array(value: string): Uint8Array {\n return new TextEncoder().encode(value);\n}\n\n/**\n * Encodes a Base64 string into a Uint8Array.\n * @internal\n */\nexport function base64ToUint8Array(value: string): Uint8Array {\n return new Uint8Array([...atob(value)].map((x) => x.charCodeAt(0)));\n}\n\n/**\n * Encodes a Base64Url string into a Uint8Array.\n * @internal\n */\nexport function base64UrlToUint8Array(value: string): Uint8Array {\n const base64String = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n return base64ToUint8Array(base64String);\n}\n\nconst hexDigits = new Set(\"0123456789abcdefABCDEF\");\n\n/**\n * Encodes a hex string into a Uint8Array\n * @internal\n */\nexport function hexStringToUint8Array(value: string): Uint8Array {\n // If value has odd length, the last character will be ignored, consistent with NodeJS Buffer behavior\n const bytes = new Uint8Array(value.length / 2);\n for (let i = 0; i < value.length / 2; ++i) {\n const highNibble = value[2 * i];\n const lowNibble = value[2 * i + 1];\n if (!hexDigits.has(highNibble) || !hexDigits.has(lowNibble)) {\n // Replicate Node Buffer behavior by exiting early when we encounter an invalid byte\n return bytes.slice(0, i);\n }\n\n bytes[i] = parseInt(`${highNibble}${lowNibble}`, 16);\n }\n\n return bytes;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,mBAAmB,OAAmB,QAA8B;AAClF,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,uBAAuB,KAAK;AAAA,IACrC,KAAK;AACH,aAAO,mBAAmB,KAAK;AAAA,IACjC,KAAK;AACH,aAAO,sBAAsB,KAAK;AAAA,IACpC,KAAK;AACH,aAAO,sBAAsB,KAAK;AAAA,EACtC;AACF;AAQO,SAAS,mBAAmB,OAAe,QAAkC;AAClF,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO,uBAAuB,KAAK;AAAA,IACrC,KAAK;AACH,aAAO,mBAAmB,KAAK;AAAA,IACjC,KAAK;AACH,aAAO,sBAAsB,KAAK;AAAA,IACpC,KAAK;AACH,aAAO,sBAAsB,KAAK;AAAA,EACtC;AACF;AAMO,SAAS,mBAAmB,OAA2B;AAC5D,SAAO,KAAK,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;AACpE;AAMO,SAAS,sBAAsB,OAA2B;AAC/D,SAAO,mBAAmB,KAAK,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,MAAM,EAAE;AAC3F;AAMO,SAAS,uBAAuB,OAA2B;AAChE,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,aAAa,QAAQ,OAAO,KAAK;AACvC,SAAO;AACT;AAMO,SAAS,sBAAsB,OAA2B;AAC/D,SAAO,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACvE;AAMO,SAAS,uBAAuB,OAA2B;AAChE,SAAO,IAAI,YAAY,EAAE,OAAO,KAAK;AACvC;AAMO,SAAS,mBAAmB,OAA2B;AAC5D,SAAO,IAAI,WAAW,CAAC,GAAG,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AACpE;AAMO,SAAS,sBAAsB,OAA2B;AAC/D,QAAM,eAAe,MAAM,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AAC/D,SAAO,mBAAmB,YAAY;AACxC;AAEA,MAAM,YAAY,IAAI,IAAI,wBAAwB;AAM3C,SAAS,sBAAsB,OAA2B;AAE/D,QAAM,QAAQ,IAAI,WAAW,MAAM,SAAS,CAAC;AAC7C,WAAS,IAAI,GAAG,IAAI,MAAM,SAAS,GAAG,EAAE,GAAG;AACzC,UAAM,aAAa,MAAM,IAAI,CAAC;AAC9B,UAAM,YAAY,MAAM,IAAI,IAAI,CAAC;AACjC,QAAI,CAAC,UAAU,IAAI,UAAU,KAAK,CAAC,UAAU,IAAI,SAAS,GAAG;AAE3D,aAAO,MAAM,MAAM,GAAG,CAAC;AAAA,IACzB;AAEA,UAAM,CAAC,IAAI,SAAS,GAAG,UAAU,GAAG,SAAS,IAAI,EAAE;AAAA,EACrD;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var bytesEncoding_exports = {};
|
|
19
|
+
__export(bytesEncoding_exports, {
|
|
20
|
+
stringToUint8Array: () => stringToUint8Array,
|
|
21
|
+
uint8ArrayToString: () => uint8ArrayToString
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(bytesEncoding_exports);
|
|
13
24
|
function uint8ArrayToString(bytes, format) {
|
|
14
|
-
|
|
25
|
+
return Buffer.from(bytes).toString(format);
|
|
15
26
|
}
|
|
16
|
-
/**
|
|
17
|
-
* The helper that transforms string to specific character encoded bytes array.
|
|
18
|
-
* @param value - the string to be converted
|
|
19
|
-
* @param format - the format we use to decode the value
|
|
20
|
-
* @returns a uint8array
|
|
21
|
-
*/
|
|
22
27
|
function stringToUint8Array(value, format) {
|
|
23
|
-
|
|
28
|
+
return Buffer.from(value, format);
|
|
24
29
|
}
|
|
25
|
-
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
stringToUint8Array,
|
|
33
|
+
uint8ArrayToString
|
|
34
|
+
});
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["/mnt/vss/_work/1/s/sdk/core/ts-http-runtime/src/util/bytesEncoding.ts"],
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/** The supported character encoding type */\nexport type EncodingType = \"utf-8\" | \"base64\" | \"base64url\" | \"hex\";\n\n/**\n * The helper that transforms bytes with specific character encoding into string\n * @param bytes - the uint8array bytes\n * @param format - the format we use to encode the byte\n * @returns a string of the encoded string\n */\nexport function uint8ArrayToString(bytes: Uint8Array, format: EncodingType): string {\n return Buffer.from(bytes).toString(format);\n}\n\n/**\n * The helper that transforms string to specific character encoded bytes array.\n * @param value - the string to be converted\n * @param format - the format we use to decode the value\n * @returns a uint8array\n */\nexport function stringToUint8Array(value: string, format: EncodingType): Uint8Array {\n return Buffer.from(value, format);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,mBAAmB,OAAmB,QAA8B;AAClF,SAAO,OAAO,KAAK,KAAK,EAAE,SAAS,MAAM;AAC3C;AAQO,SAAS,mBAAmB,OAAe,QAAkC;AAClF,SAAO,OAAO,KAAK,OAAO,MAAM;AAClC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|