@typespec/ts-http-runtime 0.2.1-alpha.20250408.2 → 0.2.1-alpha.20250418.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.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/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/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 +9 -0
- package/dist/browser/util/internal.js +11 -0
- package/dist/browser/util/internal.js.map +1 -0
- 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/index.d.ts +1 -1
- package/dist/commonjs/index.js +3 -1
- package/dist/commonjs/index.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/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/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 +9 -0
- package/dist/commonjs/util/internal.js +30 -0
- package/dist/commonjs/util/internal.js.map +1 -0
- 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/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.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/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/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 +9 -0
- package/dist/esm/util/internal.js +11 -0
- package/dist/esm/util/internal.js.map +1 -0
- 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/index.d.ts +1 -1
- package/dist/react-native/index.js +1 -1
- package/dist/react-native/index.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/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/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 +9 -0
- package/dist/react-native/util/internal.js +11 -0
- package/dist/react-native/util/internal.js.map +1 -0
- 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 +41 -3
- 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/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/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/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/README.md
CHANGED
|
@@ -15,7 +15,7 @@ See our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUP
|
|
|
15
15
|
|
|
16
16
|
### Installation
|
|
17
17
|
|
|
18
|
-
This package is primarily used in generated code and not meant to be consumed directly by end users.
|
|
18
|
+
This package is primarily used in generated code and not meant to be consumed directly by end users. Only top-level exports from this package should be used. Any exports under the `internal` subpath are for private use and stability is not guaranteed.
|
|
19
19
|
|
|
20
20
|
## Key concepts
|
|
21
21
|
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare global {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
export { AbortError } from "./abort-controller/AbortError.js";
|
|
14
|
-
export { createClientLogger, TypeSpecRuntimeLogger, type TypeSpecRuntimeClientLogger, type
|
|
14
|
+
export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, type Debugger, type TypeSpecRuntimeClientLogger, type TypeSpecRuntimeLogLevel, } from "./logger/logger.js";
|
|
15
15
|
export type { BodyPart, FormDataValue, RawHttpHeaders, KeyObject, PxfObject, HttpClient, PipelineRequest, PipelineResponse, SendRequest, TlsSettings, Agent, RequestBodyType, FormDataMap, HttpHeaders, HttpMethods, MultipartRequestBody, TransferProgressEvent, ProxySettings, RawHttpHeadersInput, PipelineRetryOptions, } from "./interfaces.js";
|
|
16
16
|
export { createHttpHeaders } from "./httpHeaders.js";
|
|
17
17
|
export * from "./auth/schemes.js";
|
package/dist/browser/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
export { AbortError } from "./abort-controller/AbortError.js";
|
|
4
|
-
export { createClientLogger, TypeSpecRuntimeLogger, } from "./logger/logger.js";
|
|
4
|
+
export { createClientLogger, getLogLevel, setLogLevel, TypeSpecRuntimeLogger, } from "./logger/logger.js";
|
|
5
5
|
export { createHttpHeaders } from "./httpHeaders.js";
|
|
6
6
|
export * from "./auth/schemes.js";
|
|
7
7
|
export * from "./auth/oauth2Flows.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAwB5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAUtC,OAAO,EAAE,qBAAqB,EAA+B,MAAM,sBAAsB,CAAC;AAE1F,OAAO,EAAE,SAAS,EAAE,WAAW,EAAyB,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,yBAAyB,CAAC;AACpG,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,mCAAmC,EAAE,MAAM,oCAAoC,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\ndeclare global {\n interface FormData {}\n interface Blob {}\n interface File {}\n interface ReadableStream<R = any> {}\n interface TransformStream<I = any, O = any> {}\n}\n\nexport { AbortError } from \"./abort-controller/AbortError.js\";\nexport {\n createClientLogger,\n getLogLevel,\n setLogLevel,\n TypeSpecRuntimeLogger,\n type Debugger,\n type TypeSpecRuntimeClientLogger,\n type TypeSpecRuntimeLogLevel,\n} from \"./logger/logger.js\";\n\nexport type {\n BodyPart,\n FormDataValue,\n RawHttpHeaders,\n KeyObject,\n PxfObject,\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n TlsSettings,\n Agent,\n RequestBodyType,\n FormDataMap,\n HttpHeaders,\n HttpMethods,\n MultipartRequestBody,\n TransferProgressEvent,\n ProxySettings,\n RawHttpHeadersInput,\n PipelineRetryOptions,\n} from \"./interfaces.js\";\nexport { createHttpHeaders } from \"./httpHeaders.js\";\nexport * from \"./auth/schemes.js\";\nexport * from \"./auth/oauth2Flows.js\";\nexport {\n type BasicCredential,\n type BearerTokenCredential,\n type OAuth2TokenCredential,\n type GetOAuth2TokenOptions,\n type GetBearerTokenOptions,\n type ApiKeyCredential,\n type ClientCredential,\n} from \"./auth/credentials.js\";\nexport { createPipelineRequest, type PipelineRequestOptions } from \"./pipelineRequest.js\";\nexport type { Pipeline, PipelinePolicy, AddPolicyOptions, PipelinePhase } from \"./pipeline.js\";\nexport { RestError, isRestError, type RestErrorOptions } from \"./restError.js\";\nexport { stringToUint8Array, uint8ArrayToString, type EncodingType } from \"./util/bytesEncoding.js\";\nexport { getClient } from \"./client/getClient.js\";\nexport { operationOptionsToRequestParameters } from \"./client/operationOptionHelpers.js\";\nexport { createRestError } from \"./client/restError.js\";\nexport type {\n Client,\n ClientOptions,\n OperationOptions,\n AdditionalPolicyConfig,\n PathUnchecked,\n PathUncheckedResponse,\n HttpResponse,\n RawResponseCallback,\n OperationRequestOptions,\n PathParameters,\n ResourceMethods,\n PathParameterWithOptions,\n StreamableMethod,\n RequestParameters,\n HttpNodeStreamResponse,\n HttpBrowserStreamResponse,\n FullOperationResponse,\n} from \"./client/common.js\";\nexport type { PipelineOptions, TelemetryOptions } from \"./createPipelineFromOptions.js\";\nexport type { LogPolicyOptions } from \"./policies/logPolicy.js\";\nexport type { RedirectPolicyOptions } from \"./policies/redirectPolicy.js\";\nexport type { UserAgentPolicyOptions } from \"./policies/userAgentPolicy.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/logger/internal.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EACL,mBAAmB,GAGpB,MAAM,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport {\n createLoggerContext,\n type CreateLoggerContextOptions,\n type LoggerContext,\n} from \"./logger.js\";\n"]}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { Debugger } from "./debug.js";
|
|
2
|
-
export { Debugger }
|
|
3
|
-
/**
|
|
4
|
-
* The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.
|
|
5
|
-
* By default, logs are sent to stderr.
|
|
6
|
-
* Override the `log` method to redirect logs to another location.
|
|
7
|
-
*/
|
|
8
|
-
export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
|
|
2
|
+
export type { Debugger };
|
|
9
3
|
/**
|
|
10
4
|
* The log levels supported by the logger.
|
|
11
5
|
* The log levels in order of most verbose to least verbose are:
|
|
@@ -16,23 +10,9 @@ export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
|
|
|
16
10
|
*/
|
|
17
11
|
export type TypeSpecRuntimeLogLevel = "verbose" | "info" | "warning" | "error";
|
|
18
12
|
/**
|
|
19
|
-
*
|
|
13
|
+
* A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.
|
|
20
14
|
*/
|
|
21
15
|
export type TypeSpecRuntimeClientLogger = Debugger;
|
|
22
|
-
/**
|
|
23
|
-
* Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
|
|
24
|
-
* @param level - The log level to enable for logging.
|
|
25
|
-
* Options from most verbose to least verbose are:
|
|
26
|
-
* - verbose
|
|
27
|
-
* - info
|
|
28
|
-
* - warning
|
|
29
|
-
* - error
|
|
30
|
-
*/
|
|
31
|
-
export declare function setLogLevel(level?: TypeSpecRuntimeLogLevel): void;
|
|
32
|
-
/**
|
|
33
|
-
* Retrieves the currently specified log level.
|
|
34
|
-
*/
|
|
35
|
-
export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
|
|
36
16
|
/**
|
|
37
17
|
* Defines the methods available on the SDK-facing logger.
|
|
38
18
|
*/
|
|
@@ -59,6 +39,74 @@ export interface TypeSpecRuntimeLogger {
|
|
|
59
39
|
*/
|
|
60
40
|
verbose: Debugger;
|
|
61
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* todo doc
|
|
44
|
+
*/
|
|
45
|
+
export interface LoggerContext {
|
|
46
|
+
/**
|
|
47
|
+
* Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
|
|
48
|
+
* @param level - The log level to enable for logging.
|
|
49
|
+
* Options from most verbose to least verbose are:
|
|
50
|
+
* - verbose
|
|
51
|
+
* - info
|
|
52
|
+
* - warning
|
|
53
|
+
* - error
|
|
54
|
+
*/
|
|
55
|
+
setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves the currently specified log level.
|
|
58
|
+
*/
|
|
59
|
+
getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
|
|
62
|
+
* @param namespace - The name of the SDK package.
|
|
63
|
+
* @hidden
|
|
64
|
+
*/
|
|
65
|
+
createClientLogger(namespace: string): TypeSpecRuntimeLogger;
|
|
66
|
+
/**
|
|
67
|
+
* The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.
|
|
68
|
+
* By default, logs are sent to stderr.
|
|
69
|
+
* Override the `log` method to redirect logs to another location.
|
|
70
|
+
*/
|
|
71
|
+
logger: TypeSpecRuntimeClientLogger;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Option for creating a TypeSpecRuntimeLoggerContext.
|
|
75
|
+
*/
|
|
76
|
+
export interface CreateLoggerContextOptions {
|
|
77
|
+
/**
|
|
78
|
+
* The name of the environment variable to check for the log level.
|
|
79
|
+
*/
|
|
80
|
+
logLevelEnvVarName: string;
|
|
81
|
+
/**
|
|
82
|
+
* The namespace of the logger.
|
|
83
|
+
*/
|
|
84
|
+
namespace: string;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a logger context base on the provided options.
|
|
88
|
+
* @param options - The options for creating a logger context.
|
|
89
|
+
* @returns The logger context.
|
|
90
|
+
*/
|
|
91
|
+
export declare function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext;
|
|
92
|
+
/**
|
|
93
|
+
* Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
|
|
94
|
+
* @param level - The log level to enable for logging.
|
|
95
|
+
* Options from most verbose to least verbose are:
|
|
96
|
+
* - verbose
|
|
97
|
+
* - info
|
|
98
|
+
* - warning
|
|
99
|
+
* - error
|
|
100
|
+
*/
|
|
101
|
+
export declare const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves the currently specified log level.
|
|
104
|
+
*/
|
|
105
|
+
export declare function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves the currently specified log level.
|
|
108
|
+
*/
|
|
109
|
+
export declare function getLogLevel(): TypeSpecRuntimeLogLevel | undefined;
|
|
62
110
|
/**
|
|
63
111
|
* Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
|
|
64
112
|
* @param namespace - The name of the SDK package.
|
|
@@ -1,29 +1,93 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import debug from "./debug.js";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const TYPESPEC_RUNTIME_LOG_LEVELS = ["verbose", "info", "warning", "error"];
|
|
5
|
+
const levelMap = {
|
|
6
|
+
verbose: 400,
|
|
7
|
+
info: 300,
|
|
8
|
+
warning: 200,
|
|
9
|
+
error: 100,
|
|
10
|
+
};
|
|
11
|
+
function patchLogMethod(parent, child) {
|
|
12
|
+
child.log = (...args) => {
|
|
13
|
+
parent.log(...args);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function isTypeSpecRuntimeLogLevel(level) {
|
|
17
|
+
return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level);
|
|
18
|
+
}
|
|
8
19
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
20
|
+
* Creates a logger context base on the provided options.
|
|
21
|
+
* @param options - The options for creating a logger context.
|
|
22
|
+
* @returns The logger context.
|
|
12
23
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
export function createLoggerContext(options) {
|
|
25
|
+
const registeredLoggers = new Set();
|
|
26
|
+
const logLevelFromEnv = (typeof process !== "undefined" && process.env && process.env[options.logLevelEnvVarName]) ||
|
|
27
|
+
undefined;
|
|
28
|
+
let logLevel;
|
|
29
|
+
const clientLogger = debug(options.namespace);
|
|
30
|
+
clientLogger.log = (...args) => {
|
|
31
|
+
debug.log(...args);
|
|
32
|
+
};
|
|
33
|
+
if (logLevelFromEnv) {
|
|
34
|
+
// avoid calling setLogLevel because we don't want a mis-set environment variable to crash
|
|
35
|
+
if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {
|
|
36
|
+
setLogLevel(logLevelFromEnv);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.error(`${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(", ")}.`);
|
|
40
|
+
}
|
|
22
41
|
}
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
function shouldEnable(logger) {
|
|
43
|
+
return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);
|
|
25
44
|
}
|
|
45
|
+
function createLogger(parent, level) {
|
|
46
|
+
const logger = Object.assign(parent.extend(level), {
|
|
47
|
+
level,
|
|
48
|
+
});
|
|
49
|
+
patchLogMethod(parent, logger);
|
|
50
|
+
if (shouldEnable(logger)) {
|
|
51
|
+
const enabledNamespaces = debug.disable();
|
|
52
|
+
debug.enable(enabledNamespaces + "," + logger.namespace);
|
|
53
|
+
}
|
|
54
|
+
registeredLoggers.add(logger);
|
|
55
|
+
return logger;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
setLogLevel(level) {
|
|
59
|
+
if (level && !isTypeSpecRuntimeLogLevel(level)) {
|
|
60
|
+
throw new Error(`Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(",")}`);
|
|
61
|
+
}
|
|
62
|
+
logLevel = level;
|
|
63
|
+
const enabledNamespaces = [];
|
|
64
|
+
for (const logger of registeredLoggers) {
|
|
65
|
+
if (shouldEnable(logger)) {
|
|
66
|
+
enabledNamespaces.push(logger.namespace);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
debug.enable(enabledNamespaces.join(","));
|
|
70
|
+
},
|
|
71
|
+
getLogLevel() {
|
|
72
|
+
return logLevel;
|
|
73
|
+
},
|
|
74
|
+
createClientLogger(namespace) {
|
|
75
|
+
const clientRootLogger = clientLogger.extend(namespace);
|
|
76
|
+
patchLogMethod(clientLogger, clientRootLogger);
|
|
77
|
+
return {
|
|
78
|
+
error: createLogger(clientRootLogger, "error"),
|
|
79
|
+
warning: createLogger(clientRootLogger, "warning"),
|
|
80
|
+
info: createLogger(clientRootLogger, "info"),
|
|
81
|
+
verbose: createLogger(clientRootLogger, "verbose"),
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
logger: clientLogger,
|
|
85
|
+
};
|
|
26
86
|
}
|
|
87
|
+
const context = createLoggerContext({
|
|
88
|
+
logLevelEnvVarName: "TYPESPEC_RUNTIME_LOG_LEVEL",
|
|
89
|
+
namespace: "typeSpecRuntime",
|
|
90
|
+
});
|
|
27
91
|
/**
|
|
28
92
|
* Immediately enables logging at the specified log level. If no level is specified, logging is disabled.
|
|
29
93
|
* @param level - The log level to enable for logging.
|
|
@@ -33,67 +97,26 @@ if (logLevelFromEnv) {
|
|
|
33
97
|
* - warning
|
|
34
98
|
* - error
|
|
35
99
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (shouldEnable(logger)) {
|
|
44
|
-
enabledNamespaces.push(logger.namespace);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
debug.enable(enabledNamespaces.join(","));
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
101
|
+
export const TypeSpecRuntimeLogger = context.logger;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves the currently specified log level.
|
|
104
|
+
*/
|
|
105
|
+
export function setLogLevel(logLevel) {
|
|
106
|
+
context.setLogLevel(logLevel);
|
|
48
107
|
}
|
|
49
108
|
/**
|
|
50
109
|
* Retrieves the currently specified log level.
|
|
51
110
|
*/
|
|
52
111
|
export function getLogLevel() {
|
|
53
|
-
return
|
|
112
|
+
return context.getLogLevel();
|
|
54
113
|
}
|
|
55
|
-
const levelMap = {
|
|
56
|
-
verbose: 400,
|
|
57
|
-
info: 300,
|
|
58
|
-
warning: 200,
|
|
59
|
-
error: 100,
|
|
60
|
-
};
|
|
61
114
|
/**
|
|
62
115
|
* Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.
|
|
63
116
|
* @param namespace - The name of the SDK package.
|
|
64
117
|
* @hidden
|
|
65
118
|
*/
|
|
66
119
|
export function createClientLogger(namespace) {
|
|
67
|
-
|
|
68
|
-
patchLogMethod(TypeSpecRuntimeLogger, clientRootLogger);
|
|
69
|
-
return {
|
|
70
|
-
error: createLogger(clientRootLogger, "error"),
|
|
71
|
-
warning: createLogger(clientRootLogger, "warning"),
|
|
72
|
-
info: createLogger(clientRootLogger, "info"),
|
|
73
|
-
verbose: createLogger(clientRootLogger, "verbose"),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function patchLogMethod(parent, child) {
|
|
77
|
-
child.log = (...args) => {
|
|
78
|
-
parent.log(...args);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function createLogger(parent, level) {
|
|
82
|
-
const logger = Object.assign(parent.extend(level), {
|
|
83
|
-
level,
|
|
84
|
-
});
|
|
85
|
-
patchLogMethod(parent, logger);
|
|
86
|
-
if (shouldEnable(logger)) {
|
|
87
|
-
const enabledNamespaces = debug.disable();
|
|
88
|
-
debug.enable(enabledNamespaces + "," + logger.namespace);
|
|
89
|
-
}
|
|
90
|
-
registeredLoggers.add(logger);
|
|
91
|
-
return logger;
|
|
92
|
-
}
|
|
93
|
-
function shouldEnable(logger) {
|
|
94
|
-
return Boolean(typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel]);
|
|
95
|
-
}
|
|
96
|
-
function isTypeSpecRuntimeLogLevel(logLevel) {
|
|
97
|
-
return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel);
|
|
120
|
+
return context.createClientLogger(namespace);
|
|
98
121
|
}
|
|
99
122
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,KAAK,MAAM,YAAY,CAAC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CAAC;IAE/B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;QACzB,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;QAC1C,KAAK,CAAC,MAAM,CAAC,iBAAiB,GAAG,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAED,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE9B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,MAA+B;IACnD,OAAO,OAAO,CACZ,uBAAuB,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,uBAAuB,CAAC,CACvF,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,QAAgB;IACjD,OAAO,2BAA2B,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Debugger } from \"./debug.js\";\nimport debug from \"./debug.js\";\nexport { Debugger } from \"./debug.js\";\n\nconst registeredLoggers = new Set<TypeSpecRuntimeDebugger>();\nconst logLevelFromEnv =\n (typeof process !== \"undefined\" && process.env && process.env.TYPESPEC_RUNTIME_LOG_LEVEL) ||\n undefined;\n\nlet typeSpecRuntimeLogLevel: TypeSpecRuntimeLogLevel | undefined;\n\n/**\n * The TypeSpecRuntimeLogger provides a mechanism for overriding where logs are output to.\n * By default, logs are sent to stderr.\n * Override the `log` method to redirect logs to another location.\n */\nexport const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger = debug(\"typeSpecRuntime\");\nTypeSpecRuntimeLogger.log = (...args) => {\n debug.log(...args);\n};\n\n/**\n * The log levels supported by the logger.\n * The log levels in order of most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport type TypeSpecRuntimeLogLevel = \"verbose\" | \"info\" | \"warning\" | \"error\";\nconst TYPESPEC_RUNTIME_LOG_LEVELS = [\"verbose\", \"info\", \"warning\", \"error\"];\n\ntype TypeSpecRuntimeDebugger = Debugger & { level: TypeSpecRuntimeLogLevel };\n\n/**\n * An TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.\n */\nexport type TypeSpecRuntimeClientLogger = Debugger;\n\nif (logLevelFromEnv) {\n // avoid calling setLogLevel because we don't want a mis-set environment variable to crash\n if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {\n setLogLevel(logLevelFromEnv);\n } else {\n console.error(\n `TYPESPEC_RUNTIME_LOG_LEVEL set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\n \", \",\n )}.`,\n );\n }\n}\n\n/**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport function setLogLevel(level?: TypeSpecRuntimeLogLevel): void {\n if (level && !isTypeSpecRuntimeLogLevel(level)) {\n throw new Error(\n `Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\",\")}`,\n );\n }\n typeSpecRuntimeLogLevel = level;\n\n const enabledNamespaces = [];\n for (const logger of registeredLoggers) {\n if (shouldEnable(logger)) {\n enabledNamespaces.push(logger.namespace);\n }\n }\n\n debug.enable(enabledNamespaces.join(\",\"));\n}\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return typeSpecRuntimeLogLevel;\n}\n\nconst levelMap = {\n verbose: 400,\n info: 300,\n warning: 200,\n error: 100,\n};\n\n/**\n * Defines the methods available on the SDK-facing logger.\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport interface TypeSpecRuntimeLogger {\n /**\n * Used for failures the program is unlikely to recover from,\n * such as Out of Memory.\n */\n error: Debugger;\n /**\n * Used when a function fails to perform its intended task.\n * Usually this means the function will throw an exception.\n * Not used for self-healing events (e.g. automatic retry)\n */\n warning: Debugger;\n /**\n * Used when a function operates normally.\n */\n info: Debugger;\n /**\n * Used for detailed troubleshooting scenarios. This is\n * intended for use by developers / system administrators\n * for diagnosing specific failures.\n */\n verbose: Debugger;\n}\n\n/**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\nexport function createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n const clientRootLogger: TypeSpecRuntimeClientLogger = TypeSpecRuntimeLogger.extend(namespace);\n patchLogMethod(TypeSpecRuntimeLogger, clientRootLogger);\n return {\n error: createLogger(clientRootLogger, \"error\"),\n warning: createLogger(clientRootLogger, \"warning\"),\n info: createLogger(clientRootLogger, \"info\"),\n verbose: createLogger(clientRootLogger, \"verbose\"),\n };\n}\n\nfunction patchLogMethod(\n parent: TypeSpecRuntimeClientLogger,\n child: TypeSpecRuntimeClientLogger | TypeSpecRuntimeDebugger,\n): void {\n child.log = (...args) => {\n parent.log(...args);\n };\n}\n\nfunction createLogger(\n parent: TypeSpecRuntimeClientLogger,\n level: TypeSpecRuntimeLogLevel,\n): TypeSpecRuntimeDebugger {\n const logger: TypeSpecRuntimeDebugger = Object.assign(parent.extend(level), {\n level,\n });\n\n patchLogMethod(parent, logger);\n\n if (shouldEnable(logger)) {\n const enabledNamespaces = debug.disable();\n debug.enable(enabledNamespaces + \",\" + logger.namespace);\n }\n\n registeredLoggers.add(logger);\n\n return logger;\n}\n\nfunction shouldEnable(logger: TypeSpecRuntimeDebugger): boolean {\n return Boolean(\n typeSpecRuntimeLogLevel && levelMap[logger.level] <= levelMap[typeSpecRuntimeLogLevel],\n );\n}\n\nfunction isTypeSpecRuntimeLogLevel(logLevel: string): logLevel is TypeSpecRuntimeLogLevel {\n return TYPESPEC_RUNTIME_LOG_LEVELS.includes(logLevel as any);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../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C;AAC/C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport debug from \"./debug.js\";\n\nimport type { Debugger } from \"./debug.js\";\nexport type { Debugger };\n\n/**\n * The log levels supported by the logger.\n * The log levels in order of most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\nexport type TypeSpecRuntimeLogLevel = \"verbose\" | \"info\" | \"warning\" | \"error\";\n\n/**\n * A TypeSpecRuntimeClientLogger is a function that can log to an appropriate severity level.\n */\nexport type TypeSpecRuntimeClientLogger = Debugger;\n\n/**\n * Defines the methods available on the SDK-facing logger.\n */\nexport interface TypeSpecRuntimeLogger {\n /**\n * Used for failures the program is unlikely to recover from,\n * such as Out of Memory.\n */\n error: Debugger;\n /**\n * Used when a function fails to perform its intended task.\n * Usually this means the function will throw an exception.\n * Not used for self-healing events (e.g. automatic retry)\n */\n warning: Debugger;\n /**\n * Used when a function operates normally.\n */\n info: Debugger;\n /**\n * Used for detailed troubleshooting scenarios. This is\n * intended for use by developers / system administrators\n * for diagnosing specific failures.\n */\n verbose: Debugger;\n}\n\n/**\n * todo doc\n */\nexport interface LoggerContext {\n /**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\n setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void;\n\n /**\n * Retrieves the currently specified log level.\n */\n getLogLevel(): TypeSpecRuntimeLogLevel | undefined;\n\n /**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\n createClientLogger(namespace: string): TypeSpecRuntimeLogger;\n\n /**\n * The TypeSpecRuntimeClientLogger provides a mechanism for overriding where logs are output to.\n * By default, logs are sent to stderr.\n * Override the `log` method to redirect logs to another location.\n */\n logger: TypeSpecRuntimeClientLogger;\n}\n\n/**\n * Option for creating a TypeSpecRuntimeLoggerContext.\n */\nexport interface CreateLoggerContextOptions {\n /**\n * The name of the environment variable to check for the log level.\n */\n logLevelEnvVarName: string;\n\n /**\n * The namespace of the logger.\n */\n namespace: string;\n}\n\nconst TYPESPEC_RUNTIME_LOG_LEVELS = [\"verbose\", \"info\", \"warning\", \"error\"];\n\ntype DebuggerWithLogLevel = Debugger & { level: TypeSpecRuntimeLogLevel };\n\nconst levelMap = {\n verbose: 400,\n info: 300,\n warning: 200,\n error: 100,\n};\n\nfunction patchLogMethod(\n parent: TypeSpecRuntimeClientLogger,\n child: TypeSpecRuntimeClientLogger | DebuggerWithLogLevel,\n): void {\n child.log = (...args) => {\n parent.log(...args);\n };\n}\n\nfunction isTypeSpecRuntimeLogLevel(level: string): level is TypeSpecRuntimeLogLevel {\n return TYPESPEC_RUNTIME_LOG_LEVELS.includes(level as any);\n}\n\n/**\n * Creates a logger context base on the provided options.\n * @param options - The options for creating a logger context.\n * @returns The logger context.\n */\nexport function createLoggerContext(options: CreateLoggerContextOptions): LoggerContext {\n const registeredLoggers = new Set<DebuggerWithLogLevel>();\n const logLevelFromEnv =\n (typeof process !== \"undefined\" && process.env && process.env[options.logLevelEnvVarName]) ||\n undefined;\n\n let logLevel: TypeSpecRuntimeLogLevel | undefined;\n\n const clientLogger: TypeSpecRuntimeClientLogger = debug(options.namespace);\n clientLogger.log = (...args) => {\n debug.log(...args);\n };\n\n if (logLevelFromEnv) {\n // avoid calling setLogLevel because we don't want a mis-set environment variable to crash\n if (isTypeSpecRuntimeLogLevel(logLevelFromEnv)) {\n setLogLevel(logLevelFromEnv);\n } else {\n console.error(\n `${options.logLevelEnvVarName} set to unknown log level '${logLevelFromEnv}'; logging is not enabled. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\n \", \",\n )}.`,\n );\n }\n }\n\n function shouldEnable(logger: DebuggerWithLogLevel): boolean {\n return Boolean(logLevel && levelMap[logger.level] <= levelMap[logLevel]);\n }\n\n function createLogger(\n parent: TypeSpecRuntimeClientLogger,\n level: TypeSpecRuntimeLogLevel,\n ): DebuggerWithLogLevel {\n const logger: DebuggerWithLogLevel = Object.assign(parent.extend(level), {\n level,\n });\n\n patchLogMethod(parent, logger);\n\n if (shouldEnable(logger)) {\n const enabledNamespaces = debug.disable();\n debug.enable(enabledNamespaces + \",\" + logger.namespace);\n }\n\n registeredLoggers.add(logger);\n\n return logger;\n }\n\n return {\n setLogLevel(level?: TypeSpecRuntimeLogLevel): void {\n if (level && !isTypeSpecRuntimeLogLevel(level)) {\n throw new Error(\n `Unknown log level '${level}'. Acceptable values: ${TYPESPEC_RUNTIME_LOG_LEVELS.join(\",\")}`,\n );\n }\n logLevel = level;\n\n const enabledNamespaces = [];\n for (const logger of registeredLoggers) {\n if (shouldEnable(logger)) {\n enabledNamespaces.push(logger.namespace);\n }\n }\n\n debug.enable(enabledNamespaces.join(\",\"));\n },\n getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return logLevel;\n },\n createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n const clientRootLogger: TypeSpecRuntimeClientLogger = clientLogger.extend(namespace);\n patchLogMethod(clientLogger, clientRootLogger);\n return {\n error: createLogger(clientRootLogger, \"error\"),\n warning: createLogger(clientRootLogger, \"warning\"),\n info: createLogger(clientRootLogger, \"info\"),\n verbose: createLogger(clientRootLogger, \"verbose\"),\n };\n },\n logger: clientLogger,\n };\n}\n\nconst context = createLoggerContext({\n logLevelEnvVarName: \"TYPESPEC_RUNTIME_LOG_LEVEL\",\n namespace: \"typeSpecRuntime\",\n});\n\n/**\n * Immediately enables logging at the specified log level. If no level is specified, logging is disabled.\n * @param level - The log level to enable for logging.\n * Options from most verbose to least verbose are:\n * - verbose\n * - info\n * - warning\n * - error\n */\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport const TypeSpecRuntimeLogger: TypeSpecRuntimeClientLogger = context.logger;\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function setLogLevel(logLevel?: TypeSpecRuntimeLogLevel): void {\n context.setLogLevel(logLevel);\n}\n\n/**\n * Retrieves the currently specified log level.\n */\nexport function getLogLevel(): TypeSpecRuntimeLogLevel | undefined {\n return context.getLogLevel();\n}\n\n/**\n * Creates a logger for use by the SDKs that inherits from `TypeSpecRuntimeLogger`.\n * @param namespace - The name of the SDK package.\n * @hidden\n */\nexport function createClientLogger(namespace: string): TypeSpecRuntimeLogger {\n return context.createClientLogger(namespace);\n}\n"]}
|
|
@@ -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,S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AEjG;;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,MAAM,CAAC,MAAM,MAAM,GACjB,OAAO,IAAI,KAAK,WAAW;IAC3B,OAAO,IAAI,CAAC,OAAO,KAAK,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,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,9 @@
|
|
|
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
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
//# 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","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\";\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;
|