Commit iniziale

This commit is contained in:
Paolo A
2025-02-18 22:59:07 +00:00
commit 4bbf35cefb
6879 changed files with 623784 additions and 0 deletions

21
node_modules/@azure/core-http-compat/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

31
node_modules/@azure/core-http-compat/README.md generated vendored Normal file
View File

@@ -0,0 +1,31 @@
# Azure Core HTTP Compatibility library for JavaScript
This library provides classes and interfaces to be used by Azure client libraries that want to move from using [@azure/core-http](https://www.npmjs.com/package/@azure/core-http) to [@azure/core-client](https://www.npmjs.com/package/@azure/core-client) & [@azure/core-rest-pipeline](https://www.npmjs.com/package/@azure/core-rest-pipeline) without causing breaking changes in their public API surface.
## Usage
### ExtendedCommonClientOptions
With `@azure/core-http` library, the `options` parameter to the custom client will look like:
```
export interface SearchClientOptions extends PipelineOptions {
apiVersion?: string;
}
```
With the `@azure/core-client` & `@azure/core-rest-pipeline` libraries, the `options` parameter to the custom client will look like:
```
export interface SearchClientOptions extends CommonClientOptions {
apiVersion?: string;
}
```
With the Core HTTP Compatibility library, the `options` parameter to the custom client will look like:
```
export interface SearchClientOptions extends ExtendedCommonClientOptions {
apiVersion?: string;
}
```

View File

@@ -0,0 +1,40 @@
import type { KeepAliveOptions } from "./policies/keepAliveOptions.js";
import type { RedirectOptions } from "./policies/redirectOptions.js";
import type { CommonClientOptions, OperationArguments, OperationSpec, ServiceClientOptions } from "@azure/core-client";
import { ServiceClient } from "@azure/core-client";
/**
* Options specific to Shim Clients.
*/
export interface ExtendedClientOptions {
/**
* Options to disable keep alive.
*/
keepAliveOptions?: KeepAliveOptions;
/**
* Options to redirect requests.
*/
redirectOptions?: RedirectOptions;
}
/**
* Options that shim clients are expected to expose.
*/
export type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;
/**
* The common set of options that custom shim clients are expected to expose.
*/
export type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;
/**
* Client to provide compatability between core V1 & V2.
*/
export declare class ExtendedServiceClient extends ServiceClient {
constructor(options: ExtendedServiceClientOptions);
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
sendOperationRequest<T>(operationArguments: OperationArguments, operationSpec: OperationSpec): Promise<T>;
}
//# sourceMappingURL=extendedClient.d.ts.map

View File

@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createDisableKeepAlivePolicy, pipelineContainsDisableKeepAlivePolicy, } from "./policies/disableKeepAlivePolicy.js";
import { redirectPolicyName } from "@azure/core-rest-pipeline";
import { ServiceClient } from "@azure/core-client";
import { toCompatResponse } from "./response.js";
/**
* Client to provide compatability between core V1 & V2.
*/
export class ExtendedServiceClient extends ServiceClient {
constructor(options) {
var _a, _b;
super(options);
if (((_a = options.keepAliveOptions) === null || _a === void 0 ? void 0 : _a.enable) === false &&
!pipelineContainsDisableKeepAlivePolicy(this.pipeline)) {
this.pipeline.addPolicy(createDisableKeepAlivePolicy());
}
if (((_b = options.redirectOptions) === null || _b === void 0 ? void 0 : _b.handleRedirects) === false) {
this.pipeline.removePolicy({
name: redirectPolicyName,
});
}
}
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
async sendOperationRequest(operationArguments, operationSpec) {
var _a;
const userProvidedCallBack = (_a = operationArguments === null || operationArguments === void 0 ? void 0 : operationArguments.options) === null || _a === void 0 ? void 0 : _a.onResponse;
let lastResponse;
function onResponse(rawResponse, flatResponse, error) {
lastResponse = rawResponse;
if (userProvidedCallBack) {
userProvidedCallBack(rawResponse, flatResponse, error);
}
}
operationArguments.options = Object.assign(Object.assign({}, operationArguments.options), { onResponse });
const result = await super.sendOperationRequest(operationArguments, operationSpec);
if (lastResponse) {
Object.defineProperty(result, "_response", {
value: toCompatResponse(lastResponse),
});
}
return result;
}
}
//# sourceMappingURL=extendedClient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extendedClient.js","sourceRoot":"","sources":["../../src/extendedClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAS/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA0BjD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAqC;;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IACE,CAAA,MAAA,OAAO,CAAC,gBAAgB,0CAAE,MAAM,MAAK,KAAK;YAC1C,CAAC,sCAAsC,CAAC,IAAI,CAAC,QAAQ,CAAC,EACtD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,4BAA4B,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAA,MAAA,OAAO,CAAC,eAAe,0CAAE,eAAe,MAAK,KAAK,EAAE,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;gBACzB,IAAI,EAAE,kBAAkB;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,oBAAoB,CACxB,kBAAsC,EACtC,aAA4B;;QAE5B,MAAM,oBAAoB,GACxB,MAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,OAAO,0CAAE,UAAU,CAAC;QAE1C,IAAI,YAA+C,CAAC;QAEpD,SAAS,UAAU,CACjB,WAAkC,EAClC,YAAqB,EACrB,KAAe;YAEf,YAAY,GAAG,WAAW,CAAC;YAC3B,IAAI,oBAAoB,EAAE,CAAC;gBACzB,oBAAoB,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,kBAAkB,CAAC,OAAO,mCACrB,kBAAkB,CAAC,OAAO,KAC7B,UAAU,GACX,CAAC;QAEF,MAAM,MAAM,GAAM,MAAM,KAAK,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;QAEtF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;gBACzC,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC;aACtC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nimport {\n createDisableKeepAlivePolicy,\n pipelineContainsDisableKeepAlivePolicy,\n} from \"./policies/disableKeepAlivePolicy.js\";\nimport type { RedirectOptions } from \"./policies/redirectOptions.js\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport type {\n CommonClientOptions,\n FullOperationResponse,\n OperationArguments,\n OperationSpec,\n RawResponseCallback,\n ServiceClientOptions,\n} from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { toCompatResponse } from \"./response.js\";\n\n/**\n * Options specific to Shim Clients.\n */\nexport interface ExtendedClientOptions {\n /**\n * Options to disable keep alive.\n */\n keepAliveOptions?: KeepAliveOptions;\n /**\n * Options to redirect requests.\n */\n redirectOptions?: RedirectOptions;\n}\n\n/**\n * Options that shim clients are expected to expose.\n */\nexport type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;\n\n/**\n * The common set of options that custom shim clients are expected to expose.\n */\nexport type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;\n\n/**\n * Client to provide compatability between core V1 & V2.\n */\nexport class ExtendedServiceClient extends ServiceClient {\n constructor(options: ExtendedServiceClientOptions) {\n super(options);\n\n if (\n options.keepAliveOptions?.enable === false &&\n !pipelineContainsDisableKeepAlivePolicy(this.pipeline)\n ) {\n this.pipeline.addPolicy(createDisableKeepAlivePolicy());\n }\n\n if (options.redirectOptions?.handleRedirects === false) {\n this.pipeline.removePolicy({\n name: redirectPolicyName,\n });\n }\n }\n\n /**\n * Compatible send operation request function.\n *\n * @param operationArguments - Operation arguments\n * @param operationSpec - Operation Spec\n * @returns\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<T> {\n const userProvidedCallBack: RawResponseCallback | undefined =\n operationArguments?.options?.onResponse;\n\n let lastResponse: FullOperationResponse | undefined;\n\n function onResponse(\n rawResponse: FullOperationResponse,\n flatResponse: unknown,\n error?: unknown,\n ): void {\n lastResponse = rawResponse;\n if (userProvidedCallBack) {\n userProvidedCallBack(rawResponse, flatResponse, error);\n }\n }\n\n operationArguments.options = {\n ...operationArguments.options,\n onResponse,\n };\n\n const result: T = await super.sendOperationRequest(operationArguments, operationSpec);\n\n if (lastResponse) {\n Object.defineProperty(result, \"_response\", {\n value: toCompatResponse(lastResponse),\n });\n }\n\n return result;\n }\n}\n"]}

View File

@@ -0,0 +1,9 @@
import type { HttpClient } from "@azure/core-rest-pipeline";
import type { RequestPolicy } from "./policies/requestPolicyFactoryPolicy.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export declare function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient;
//# sourceMappingURL=httpClientAdapter.d.ts.map

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toPipelineResponse } from "./response.js";
import { toWebResourceLike } from "./util.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export function convertHttpClient(requestPolicyClient) {
return {
sendRequest: async (request) => {
const response = await requestPolicyClient.sendRequest(toWebResourceLike(request, { createProxy: true }));
return toPipelineResponse(response);
},
};
}
//# sourceMappingURL=httpClientAdapter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"httpClientAdapter.js","sourceRoot":"","sources":["../../src/httpClientAdapter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,mBAAkC;IAClE,OAAO;QACL,WAAW,EAAE,KAAK,EAAE,OAAwB,EAA6B,EAAE;YACzE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,WAAW,CACpD,iBAAiB,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAClD,CAAC;YACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, PipelineRequest, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport type { RequestPolicy } from \"./policies/requestPolicyFactoryPolicy.js\";\nimport { toPipelineResponse } from \"./response.js\";\nimport { toWebResourceLike } from \"./util.js\";\n\n/**\n * Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.\n * @param requestPolicyClient - A HttpClient compatible with core-http\n * @returns A HttpClient compatible with core-rest-pipeline\n */\nexport function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient {\n return {\n sendRequest: async (request: PipelineRequest): Promise<PipelineResponse> => {\n const response = await requestPolicyClient.sendRequest(\n toWebResourceLike(request, { createProxy: true }),\n );\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,14 @@
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, ExtendedServiceClientOptions, ExtendedCommonClientOptions, ExtendedClientOptions, } from "./extendedClient.js";
export { CompatResponse } from "./response.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, RequestPolicyFactory, RequestPolicy, RequestPolicyOptionsLike, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { KeepAliveOptions } from "./policies/keepAliveOptions.js";
export { RedirectOptions } from "./policies/redirectOptions.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { Agent, WebResourceLike, HttpHeadersLike, RawHttpHeaders, HttpHeader, TransferProgressEvent, toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, } from "./extendedClient.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;GAIG;AACH,OAAO,EACL,qBAAqB,GAItB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAIhC,oBAAoB,GACrB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAOL,iBAAiB,GAClB,MAAM,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A Shim Library that provides compatibility between Core V1 & V2 Packages.\n *\n * @packageDocumentation\n */\nexport {\n ExtendedServiceClient,\n ExtendedServiceClientOptions,\n ExtendedCommonClientOptions,\n ExtendedClientOptions,\n} from \"./extendedClient.js\";\nexport { CompatResponse } from \"./response.js\";\nexport {\n requestPolicyFactoryPolicyName,\n createRequestPolicyFactoryPolicy,\n RequestPolicyFactory,\n RequestPolicy,\n RequestPolicyOptionsLike,\n HttpPipelineLogLevel,\n} from \"./policies/requestPolicyFactoryPolicy.js\";\nexport { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nexport { RedirectOptions } from \"./policies/redirectOptions.js\";\nexport { disableKeepAlivePolicyName } from \"./policies/disableKeepAlivePolicy.js\";\nexport { convertHttpClient } from \"./httpClientAdapter.js\";\nexport {\n Agent,\n WebResourceLike,\n HttpHeadersLike,\n RawHttpHeaders,\n HttpHeader,\n TransferProgressEvent,\n toHttpHeadersLike,\n} from \"./util.js\";\n"]}

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,8 @@
import type { Pipeline, PipelinePolicy } from "@azure/core-rest-pipeline";
export declare const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export declare function createDisableKeepAlivePolicy(): PipelinePolicy;
/**
* @internal
*/
export declare function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean;
//# sourceMappingURL=disableKeepAlivePolicy.d.ts.map

View File

@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export function createDisableKeepAlivePolicy() {
return {
name: disableKeepAlivePolicyName,
async sendRequest(request, next) {
request.disableKeepAlive = true;
return next(request);
},
};
}
/**
* @internal
*/
export function pipelineContainsDisableKeepAlivePolicy(pipeline) {
return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);
}
//# sourceMappingURL=disableKeepAlivePolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"disableKeepAlivePolicy.js","sourceRoot":"","sources":["../../../src/policies/disableKeepAlivePolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,MAAM,CAAC,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAEnE,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAChC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sCAAsC,CAAC,QAAkB;IACvE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,0BAA0B,CAAC,CAAC;AACpG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n Pipeline,\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\nexport const disableKeepAlivePolicyName = \"DisableKeepAlivePolicy\";\n\nexport function createDisableKeepAlivePolicy(): PipelinePolicy {\n return {\n name: disableKeepAlivePolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.disableKeepAlive = true;\n return next(request);\n },\n };\n}\n\n/**\n * @internal\n */\nexport function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean {\n return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);\n}\n"]}

View File

@@ -0,0 +1,11 @@
/**
* Keep Alive Options for how HTTP connections.
*/
export interface KeepAliveOptions {
/**
* When true, connections will be kept alive for multiple requests.
* Defaults to true.
*/
enable?: boolean;
}
//# sourceMappingURL=keepAliveOptions.d.ts.map

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=keepAliveOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"keepAliveOptions.js","sourceRoot":"","sources":["../../../src/policies/keepAliveOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Keep Alive Options for how HTTP connections.\n */\nexport interface KeepAliveOptions {\n /**\n * When true, connections will be kept alive for multiple requests.\n * Defaults to true.\n */\n enable?: boolean;\n}\n"]}

View File

@@ -0,0 +1,15 @@
/**
* Options for how redirect responses are handled.
*/
export interface RedirectOptions {
/**
* When true, redirect responses are followed. Defaults to true.
*/
handleRedirects?: boolean;
/**
* The maximum number of times the redirect URL will be tried before
* failing. Defaults to 20.
*/
maxRetries?: number;
}
//# sourceMappingURL=redirectOptions.d.ts.map

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=redirectOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"redirectOptions.js","sourceRoot":"","sources":["../../../src/policies/redirectOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Options for how redirect responses are handled.\n */\nexport interface RedirectOptions {\n /**\n * When true, redirect responses are followed. Defaults to true.\n */\n handleRedirects?: boolean;\n\n /**\n * The maximum number of times the redirect URL will be tried before\n * failing. Defaults to 20.\n */\n maxRetries?: number;\n}\n"]}

View File

@@ -0,0 +1,41 @@
import type { PipelinePolicy } from "@azure/core-rest-pipeline";
import type { WebResourceLike } from "../util.js";
import type { CompatResponse } from "../response.js";
/**
* A compatible interface for core-http request policies
*/
export interface RequestPolicy {
sendRequest(httpRequest: WebResourceLike): Promise<CompatResponse>;
}
/**
* An enum for compatibility with RequestPolicy
*/
export declare enum HttpPipelineLogLevel {
ERROR = 1,
INFO = 3,
OFF = 0,
WARNING = 2
}
/**
* An interface for compatibility with RequestPolicy
*/
export interface RequestPolicyOptionsLike {
log(logLevel: HttpPipelineLogLevel, message: string): void;
shouldLog(logLevel: HttpPipelineLogLevel): boolean;
}
/**
* An interface for compatibility with core-http's RequestPolicyFactory
*/
export interface RequestPolicyFactory {
create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy;
}
/**
* The name of the RequestPolicyFactoryPolicy
*/
export declare const requestPolicyFactoryPolicyName = "RequestPolicyFactoryPolicy";
/**
* A policy that wraps policies written for core-http.
* @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline
*/
export declare function createRequestPolicyFactoryPolicy(factories: RequestPolicyFactory[]): PipelinePolicy;
//# sourceMappingURL=requestPolicyFactoryPolicy.d.ts.map

View File

@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toPipelineRequest, toWebResourceLike } from "../util.js";
import { toCompatResponse, toPipelineResponse } from "../response.js";
/**
* An enum for compatibility with RequestPolicy
*/
export var HttpPipelineLogLevel;
(function (HttpPipelineLogLevel) {
HttpPipelineLogLevel[HttpPipelineLogLevel["ERROR"] = 1] = "ERROR";
HttpPipelineLogLevel[HttpPipelineLogLevel["INFO"] = 3] = "INFO";
HttpPipelineLogLevel[HttpPipelineLogLevel["OFF"] = 0] = "OFF";
HttpPipelineLogLevel[HttpPipelineLogLevel["WARNING"] = 2] = "WARNING";
})(HttpPipelineLogLevel || (HttpPipelineLogLevel = {}));
const mockRequestPolicyOptions = {
log(_logLevel, _message) {
/* do nothing */
},
shouldLog(_logLevel) {
return false;
},
};
/**
* The name of the RequestPolicyFactoryPolicy
*/
export const requestPolicyFactoryPolicyName = "RequestPolicyFactoryPolicy";
/**
* A policy that wraps policies written for core-http.
* @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline
*/
export function createRequestPolicyFactoryPolicy(factories) {
const orderedFactories = factories.slice().reverse();
return {
name: requestPolicyFactoryPolicyName,
async sendRequest(request, next) {
let httpPipeline = {
async sendRequest(httpRequest) {
const response = await next(toPipelineRequest(httpRequest));
return toCompatResponse(response, { createProxy: true });
},
};
for (const factory of orderedFactories) {
httpPipeline = factory.create(httpPipeline, mockRequestPolicyOptions);
}
const webResourceLike = toWebResourceLike(request, { createProxy: true });
const response = await httpPipeline.sendRequest(webResourceLike);
return toPipelineResponse(response);
},
};
}
//# sourceMappingURL=requestPolicyFactoryPolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"requestPolicyFactoryPolicy.js","sourceRoot":"","sources":["../../../src/policies/requestPolicyFactoryPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAStE;;GAEG;AACH,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,iEAAS,CAAA;IACT,+DAAQ,CAAA;IACR,6DAAO,CAAA;IACP,qEAAW,CAAA;AACb,CAAC,EALW,oBAAoB,KAApB,oBAAoB,QAK/B;AAUD,MAAM,wBAAwB,GAA6B;IACzD,GAAG,CAAC,SAA+B,EAAE,QAAgB;QACnD,gBAAgB;IAClB,CAAC;IACD,SAAS,CAAC,SAA+B;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AASF;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,4BAA4B,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC9C,SAAiC;IAEjC,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC;IAErD,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IAAI,YAAY,GAAkB;gBAChC,KAAK,CAAC,WAAW,CAAC,WAAW;oBAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;oBAC5D,OAAO,gBAAgB,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3D,CAAC;aACF,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;gBACvC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;YACxE,CAAC;YAED,MAAM,eAAe,GAAG,iBAAiB,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;YACjE,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport type { WebResourceLike } from \"../util.js\";\nimport { toPipelineRequest, toWebResourceLike } from \"../util.js\";\nimport type { CompatResponse } from \"../response.js\";\nimport { toCompatResponse, toPipelineResponse } from \"../response.js\";\n\n/**\n * A compatible interface for core-http request policies\n */\nexport interface RequestPolicy {\n sendRequest(httpRequest: WebResourceLike): Promise<CompatResponse>;\n}\n\n/**\n * An enum for compatibility with RequestPolicy\n */\nexport enum HttpPipelineLogLevel {\n ERROR = 1,\n INFO = 3,\n OFF = 0,\n WARNING = 2,\n}\n\n/**\n * An interface for compatibility with RequestPolicy\n */\nexport interface RequestPolicyOptionsLike {\n log(logLevel: HttpPipelineLogLevel, message: string): void;\n shouldLog(logLevel: HttpPipelineLogLevel): boolean;\n}\n\nconst mockRequestPolicyOptions: RequestPolicyOptionsLike = {\n log(_logLevel: HttpPipelineLogLevel, _message: string): void {\n /* do nothing */\n },\n shouldLog(_logLevel: HttpPipelineLogLevel): boolean {\n return false;\n },\n};\n\n/**\n * An interface for compatibility with core-http's RequestPolicyFactory\n */\nexport interface RequestPolicyFactory {\n create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy;\n}\n\n/**\n * The name of the RequestPolicyFactoryPolicy\n */\nexport const requestPolicyFactoryPolicyName = \"RequestPolicyFactoryPolicy\";\n\n/**\n * A policy that wraps policies written for core-http.\n * @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline\n */\nexport function createRequestPolicyFactoryPolicy(\n factories: RequestPolicyFactory[],\n): PipelinePolicy {\n const orderedFactories = factories.slice().reverse();\n\n return {\n name: requestPolicyFactoryPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n let httpPipeline: RequestPolicy = {\n async sendRequest(httpRequest) {\n const response = await next(toPipelineRequest(httpRequest));\n return toCompatResponse(response, { createProxy: true });\n },\n };\n for (const factory of orderedFactories) {\n httpPipeline = factory.create(httpPipeline, mockRequestPolicyOptions);\n }\n\n const webResourceLike = toWebResourceLike(request, { createProxy: true });\n const response = await httpPipeline.sendRequest(webResourceLike);\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,30 @@
import type { FullOperationResponse } from "@azure/core-client";
import type { PipelineResponse } from "@azure/core-rest-pipeline";
import type { HttpHeadersLike, WebResourceLike } from "./util.js";
/**
* Http Response that is compatible with the core-v1(core-http).
*/
export interface CompatResponse extends Omit<FullOperationResponse, "request" | "headers"> {
/**
* A description of a HTTP request to be made to a remote server.
*/
request: WebResourceLike;
/**
* A collection of HTTP header key/value pairs.
*/
headers: HttpHeadersLike;
}
/**
* A helper to convert response objects from the new pipeline back to the old one.
* @param response - A response object from core-client.
* @returns A response compatible with `HttpOperationResponse` from core-http.
*/
export declare function toCompatResponse(response: FullOperationResponse, options?: {
createProxy?: boolean;
}): CompatResponse;
/**
* A helper to convert back to a PipelineResponse
* @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.
*/
export declare function toPipelineResponse(compatResponse: CompatResponse): PipelineResponse;
//# sourceMappingURL=response.d.ts.map

View File

@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createHttpHeaders } from "@azure/core-rest-pipeline";
import { toHttpHeadersLike, toPipelineRequest, toWebResourceLike } from "./util.js";
const originalResponse = Symbol("Original FullOperationResponse");
/**
* A helper to convert response objects from the new pipeline back to the old one.
* @param response - A response object from core-client.
* @returns A response compatible with `HttpOperationResponse` from core-http.
*/
export function toCompatResponse(response, options) {
let request = toWebResourceLike(response.request);
let headers = toHttpHeadersLike(response.headers);
if (options === null || options === void 0 ? void 0 : options.createProxy) {
return new Proxy(response, {
get(target, prop, receiver) {
if (prop === "headers") {
return headers;
}
else if (prop === "request") {
return request;
}
else if (prop === originalResponse) {
return response;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (prop === "headers") {
headers = value;
}
else if (prop === "request") {
request = value;
}
return Reflect.set(target, prop, value, receiver);
},
});
}
else {
return Object.assign(Object.assign({}, response), { request,
headers });
}
}
/**
* A helper to convert back to a PipelineResponse
* @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.
*/
export function toPipelineResponse(compatResponse) {
const extendedCompatResponse = compatResponse;
const response = extendedCompatResponse[originalResponse];
const headers = createHttpHeaders(compatResponse.headers.toJson({ preserveCase: true }));
if (response) {
response.headers = headers;
return response;
}
else {
return Object.assign(Object.assign({}, compatResponse), { headers, request: toPipelineRequest(compatResponse.request) });
}
}
//# sourceMappingURL=response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/response.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAepF,MAAM,gBAAgB,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAGlE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAA+B,EAC/B,OAAmC;IAEnC,IAAI,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;YACzB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;gBACxB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,OAAO,CAAC;gBACjB,CAAC;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,OAAO,OAAO,CAAC;gBACjB,CAAC;qBAAM,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;oBACrC,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC;YACD,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ;gBAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YACpD,CAAC;SACF,CAA8B,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,uCACK,QAAQ,KACX,OAAO;YACP,OAAO,IACP;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,cAA8B;IAC/D,MAAM,sBAAsB,GAAG,cAAwC,CAAC;IACxE,MAAM,QAAQ,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACzF,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,uCACK,cAAc,KACjB,OAAO,EACP,OAAO,EAAE,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,IAClD;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { FullOperationResponse } from \"@azure/core-client\";\nimport type { PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport type { HttpHeadersLike, WebResourceLike } from \"./util.js\";\nimport { toHttpHeadersLike, toPipelineRequest, toWebResourceLike } from \"./util.js\";\n/**\n * Http Response that is compatible with the core-v1(core-http).\n */\nexport interface CompatResponse extends Omit<FullOperationResponse, \"request\" | \"headers\"> {\n /**\n * A description of a HTTP request to be made to a remote server.\n */\n request: WebResourceLike;\n /**\n * A collection of HTTP header key/value pairs.\n */\n headers: HttpHeadersLike;\n}\n\nconst originalResponse = Symbol(\"Original FullOperationResponse\");\ntype ExtendedCompatResponse = CompatResponse & { [originalResponse]?: FullOperationResponse };\n\n/**\n * A helper to convert response objects from the new pipeline back to the old one.\n * @param response - A response object from core-client.\n * @returns A response compatible with `HttpOperationResponse` from core-http.\n */\nexport function toCompatResponse(\n response: FullOperationResponse,\n options?: { createProxy?: boolean },\n): CompatResponse {\n let request = toWebResourceLike(response.request);\n let headers = toHttpHeadersLike(response.headers);\n if (options?.createProxy) {\n return new Proxy(response, {\n get(target, prop, receiver) {\n if (prop === \"headers\") {\n return headers;\n } else if (prop === \"request\") {\n return request;\n } else if (prop === originalResponse) {\n return response;\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, value, receiver) {\n if (prop === \"headers\") {\n headers = value;\n } else if (prop === \"request\") {\n request = value;\n }\n return Reflect.set(target, prop, value, receiver);\n },\n }) as unknown as CompatResponse;\n } else {\n return {\n ...response,\n request,\n headers,\n };\n }\n}\n\n/**\n * A helper to convert back to a PipelineResponse\n * @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.\n */\nexport function toPipelineResponse(compatResponse: CompatResponse): PipelineResponse {\n const extendedCompatResponse = compatResponse as ExtendedCompatResponse;\n const response = extendedCompatResponse[originalResponse];\n const headers = createHttpHeaders(compatResponse.headers.toJson({ preserveCase: true }));\n if (response) {\n response.headers = headers;\n return response;\n } else {\n return {\n ...compatResponse,\n headers,\n request: toPipelineRequest(compatResponse.request),\n };\n }\n}\n"]}

View File

@@ -0,0 +1,287 @@
import type { HttpMethods, ProxySettings } from "@azure/core-rest-pipeline";
import type { AbortSignalLike } from "@azure/abort-controller";
import type { HttpHeaders as HttpHeadersV2, PipelineRequest } from "@azure/core-rest-pipeline";
export declare function toPipelineRequest(webResource: WebResourceLike, options?: {
originalRequest?: PipelineRequest;
}): PipelineRequest;
export declare function toWebResourceLike(request: PipelineRequest, options?: {
createProxy?: boolean;
originalRequest?: PipelineRequest;
}): WebResourceLike;
/**
* Converts HttpHeaders from core-rest-pipeline to look like
* HttpHeaders from core-http.
* @param headers - HttpHeaders from core-rest-pipeline
* @returns HttpHeaders as they looked in core-http
*/
export declare function toHttpHeadersLike(headers: HttpHeadersV2): HttpHeadersLike;
/**
* An individual header within a HttpHeaders collection.
*/
export interface HttpHeader {
/**
* The name of the header.
*/
name: string;
/**
* The value of the header.
*/
value: string;
}
/**
* A HttpHeaders collection represented as a simple JSON object.
*/
export type RawHttpHeaders = {
[headerName: string]: string;
};
/**
* A collection of HTTP header key/value pairs.
*/
export interface HttpHeadersLike {
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header values that are contained in this collection.
*/
headerValues(): string[];
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeadersLike;
/**
* Get the JSON object representation of this HTTP header collection.
* The result is the same as `rawHeaders()`.
*/
toJson(options?: {
preserveCase?: boolean;
}): RawHttpHeaders;
}
/**
* A collection of HTTP header key/value pairs.
*/
export declare class HttpHeaders implements HttpHeadersLike {
private readonly _headersMap;
constructor(rawHeaders?: RawHttpHeaders);
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header values that are contained in this collection.
*/
headerValues(): string[];
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(options?: {
preserveCase?: boolean;
}): RawHttpHeaders;
/**
* Get the string representation of this HTTP header collection.
*/
toString(): string;
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeaders;
}
/**
* An interface compatible with NodeJS's `http.Agent`.
* We want to avoid publicly re-exporting the actual interface,
* since it might vary across runtime versions.
*/
export interface Agent {
/**
* Destroy any sockets that are currently in use by the agent.
*/
destroy(): void;
/**
* For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state.
*/
maxFreeSockets: number;
/**
* Determines how many concurrent sockets the agent can have open per origin.
*/
maxSockets: number;
/**
* An object which contains queues of requests that have not yet been assigned to sockets.
*/
requests: unknown;
/**
* An object which contains arrays of sockets currently in use by the agent.
*/
sockets: unknown;
}
/**
* A description of a HTTP request to be made to a remote server.
*/
export interface WebResourceLike {
/**
* The URL being accessed by the request.
*/
url: string;
/**
* The HTTP method to use when making the request.
*/
method: HttpMethods;
/**
* The HTTP body contents of the request.
*/
body?: any;
/**
* The HTTP headers to use when making the request.
*/
headers: HttpHeadersLike;
/**
* Whether or not the body of the HttpOperationResponse should be treated as a stream.
* @deprecated Use streamResponseStatusCodes property instead.
*/
streamResponseBody?: boolean;
/**
* A list of response status codes whose corresponding HttpOperationResponse body should be treated as a stream.
*/
streamResponseStatusCodes?: Set<number>;
/**
* Form data, used to build the request body.
*/
formData?: any;
/**
* A query string represented as an object.
*/
query?: {
[key: string]: any;
};
/**
* If credentials (cookies) should be sent along during an XHR.
*/
withCredentials: boolean;
/**
* The number of milliseconds a request can take before automatically being terminated.
* If the request is terminated, an `AbortError` is thrown.
*/
timeout: number;
/**
* Proxy configuration.
*/
proxySettings?: ProxySettings;
/**
* If the connection should be reused.
*/
keepAlive?: boolean;
/**
* Whether or not to decompress response according to Accept-Encoding header (node-fetch only)
*/
decompressResponse?: boolean;
/**
* A unique identifier for the request. Used for logging and tracing.
*/
requestId: string;
/**
* Signal of an abort controller. Can be used to abort both sending a network request and waiting for a response.
*/
abortSignal?: AbortSignalLike;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/** Callback which fires upon download progress. */
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/**
* NODEJS ONLY
*
* A Node-only option to provide a custom `http.Agent`/`https.Agent`.
* NOTE: usually this should be one instance shared by multiple requests so that the underlying
* connection to the service can be reused.
* Does nothing when running in the browser.
*/
agent?: Agent;
/**
* Clone this request object.
*/
clone(): WebResourceLike;
/**
* Validates that the required properties such as method, url, headers["Content-Type"],
* headers["accept-language"] are defined. It will throw an error if one of the above
* mentioned properties are not defined.
* Note: this a no-op for compat purposes.
*/
validateRequestProperties(): void;
/**
* This is a no-op for compat purposes and will throw if called.
*/
prepare(options: unknown): WebResourceLike;
}
/**
* Fired in response to upload or download progress.
*/
export type TransferProgressEvent = {
/**
* The number of bytes loaded so far.
*/
loadedBytes: number;
};
//# sourceMappingURL=util.d.ts.map

View File

@@ -0,0 +1,259 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
// We use a custom symbol to cache a reference to the original request without
// exposing it on the public interface.
const originalRequestSymbol = Symbol("Original PipelineRequest");
// Symbol.for() will return the same symbol if it's already been created
// This particular one is used in core-client to handle the case of when a request is
// cloned but we need to retrieve the OperationSpec and OperationArguments from the
// original request.
const originalClientRequestSymbol = Symbol.for("@azure/core-client original request");
export function toPipelineRequest(webResource, options = {}) {
const compatWebResource = webResource;
const request = compatWebResource[originalRequestSymbol];
const headers = createHttpHeaders(webResource.headers.toJson({ preserveCase: true }));
if (request) {
request.headers = headers;
return request;
}
else {
const newRequest = createPipelineRequest({
url: webResource.url,
method: webResource.method,
headers,
withCredentials: webResource.withCredentials,
timeout: webResource.timeout,
requestId: webResource.requestId,
abortSignal: webResource.abortSignal,
body: webResource.body,
formData: webResource.formData,
disableKeepAlive: !!webResource.keepAlive,
onDownloadProgress: webResource.onDownloadProgress,
onUploadProgress: webResource.onUploadProgress,
proxySettings: webResource.proxySettings,
streamResponseStatusCodes: webResource.streamResponseStatusCodes,
agent: webResource.agent,
});
if (options.originalRequest) {
newRequest[originalClientRequestSymbol] =
options.originalRequest;
}
return newRequest;
}
}
export function toWebResourceLike(request, options) {
var _a;
const originalRequest = (_a = options === null || options === void 0 ? void 0 : options.originalRequest) !== null && _a !== void 0 ? _a : request;
const webResource = {
url: request.url,
method: request.method,
headers: toHttpHeadersLike(request.headers),
withCredentials: request.withCredentials,
timeout: request.timeout,
requestId: request.headers.get("x-ms-client-request-id") || request.requestId,
abortSignal: request.abortSignal,
body: request.body,
formData: request.formData,
keepAlive: !!request.disableKeepAlive,
onDownloadProgress: request.onDownloadProgress,
onUploadProgress: request.onUploadProgress,
proxySettings: request.proxySettings,
streamResponseStatusCodes: request.streamResponseStatusCodes,
agent: request.agent,
clone() {
throw new Error("Cannot clone a non-proxied WebResourceLike");
},
prepare() {
throw new Error("WebResourceLike.prepare() is not supported by @azure/core-http-compat");
},
validateRequestProperties() {
/** do nothing */
},
};
if (options === null || options === void 0 ? void 0 : options.createProxy) {
return new Proxy(webResource, {
get(target, prop, receiver) {
if (prop === originalRequestSymbol) {
return request;
}
else if (prop === "clone") {
return () => {
return toWebResourceLike(toPipelineRequest(webResource, { originalRequest }), {
createProxy: true,
originalRequest,
});
};
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (prop === "keepAlive") {
request.disableKeepAlive = !value;
}
const passThroughProps = [
"url",
"method",
"withCredentials",
"timeout",
"requestId",
"abortSignal",
"body",
"formData",
"onDownloadProgress",
"onUploadProgress",
"proxySettings",
"streamResponseStatusCodes",
"agent",
];
if (typeof prop === "string" && passThroughProps.includes(prop)) {
request[prop] = value;
}
return Reflect.set(target, prop, value, receiver);
},
});
}
else {
return webResource;
}
}
/**
* Converts HttpHeaders from core-rest-pipeline to look like
* HttpHeaders from core-http.
* @param headers - HttpHeaders from core-rest-pipeline
* @returns HttpHeaders as they looked in core-http
*/
export function toHttpHeadersLike(headers) {
return new HttpHeaders(headers.toJSON({ preserveCase: true }));
}
/**
* A collection of HttpHeaders that can be sent with a HTTP request.
*/
function getHeaderKey(headerName) {
return headerName.toLowerCase();
}
/**
* A collection of HTTP header key/value pairs.
*/
export class HttpHeaders {
constructor(rawHeaders) {
this._headersMap = {};
if (rawHeaders) {
for (const headerName in rawHeaders) {
this.set(headerName, rawHeaders[headerName]);
}
}
}
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName, headerValue) {
this._headersMap[getHeaderKey(headerName)] = {
name: headerName,
value: headerValue.toString(),
};
}
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName) {
const header = this._headersMap[getHeaderKey(headerName)];
return !header ? undefined : header.value;
}
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName) {
return !!this._headersMap[getHeaderKey(headerName)];
}
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName) {
const result = this.contains(headerName);
delete this._headersMap[getHeaderKey(headerName)];
return result;
}
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders() {
return this.toJson({ preserveCase: true });
}
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray() {
const headers = [];
for (const headerKey in this._headersMap) {
headers.push(this._headersMap[headerKey]);
}
return headers;
}
/**
* Get the header names that are contained in this collection.
*/
headerNames() {
const headerNames = [];
const headers = this.headersArray();
for (let i = 0; i < headers.length; ++i) {
headerNames.push(headers[i].name);
}
return headerNames;
}
/**
* Get the header values that are contained in this collection.
*/
headerValues() {
const headerValues = [];
const headers = this.headersArray();
for (let i = 0; i < headers.length; ++i) {
headerValues.push(headers[i].value);
}
return headerValues;
}
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(options = {}) {
const result = {};
if (options.preserveCase) {
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
result[header.name] = header.value;
}
}
else {
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
result[getHeaderKey(header.name)] = header.value;
}
}
return result;
}
/**
* Get the string representation of this HTTP header collection.
*/
toString() {
return JSON.stringify(this.toJson({ preserveCase: true }));
}
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone() {
const resultPreservingCasing = {};
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
resultPreservingCasing[header.name] = header.value;
}
return new HttpHeaders(resultPreservingCasing);
}
}
//# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,40 @@
import type { KeepAliveOptions } from "./policies/keepAliveOptions.js";
import type { RedirectOptions } from "./policies/redirectOptions.js";
import type { CommonClientOptions, OperationArguments, OperationSpec, ServiceClientOptions } from "@azure/core-client";
import { ServiceClient } from "@azure/core-client";
/**
* Options specific to Shim Clients.
*/
export interface ExtendedClientOptions {
/**
* Options to disable keep alive.
*/
keepAliveOptions?: KeepAliveOptions;
/**
* Options to redirect requests.
*/
redirectOptions?: RedirectOptions;
}
/**
* Options that shim clients are expected to expose.
*/
export type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;
/**
* The common set of options that custom shim clients are expected to expose.
*/
export type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;
/**
* Client to provide compatability between core V1 & V2.
*/
export declare class ExtendedServiceClient extends ServiceClient {
constructor(options: ExtendedServiceClientOptions);
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
sendOperationRequest<T>(operationArguments: OperationArguments, operationSpec: OperationSpec): Promise<T>;
}
//# sourceMappingURL=extendedClient.d.ts.map

View File

@@ -0,0 +1,55 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtendedServiceClient = void 0;
const disableKeepAlivePolicy_js_1 = require("./policies/disableKeepAlivePolicy.js");
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
const core_client_1 = require("@azure/core-client");
const response_js_1 = require("./response.js");
/**
* Client to provide compatability between core V1 & V2.
*/
class ExtendedServiceClient extends core_client_1.ServiceClient {
constructor(options) {
var _a, _b;
super(options);
if (((_a = options.keepAliveOptions) === null || _a === void 0 ? void 0 : _a.enable) === false &&
!(0, disableKeepAlivePolicy_js_1.pipelineContainsDisableKeepAlivePolicy)(this.pipeline)) {
this.pipeline.addPolicy((0, disableKeepAlivePolicy_js_1.createDisableKeepAlivePolicy)());
}
if (((_b = options.redirectOptions) === null || _b === void 0 ? void 0 : _b.handleRedirects) === false) {
this.pipeline.removePolicy({
name: core_rest_pipeline_1.redirectPolicyName,
});
}
}
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
async sendOperationRequest(operationArguments, operationSpec) {
var _a;
const userProvidedCallBack = (_a = operationArguments === null || operationArguments === void 0 ? void 0 : operationArguments.options) === null || _a === void 0 ? void 0 : _a.onResponse;
let lastResponse;
function onResponse(rawResponse, flatResponse, error) {
lastResponse = rawResponse;
if (userProvidedCallBack) {
userProvidedCallBack(rawResponse, flatResponse, error);
}
}
operationArguments.options = Object.assign(Object.assign({}, operationArguments.options), { onResponse });
const result = await super.sendOperationRequest(operationArguments, operationSpec);
if (lastResponse) {
Object.defineProperty(result, "_response", {
value: (0, response_js_1.toCompatResponse)(lastResponse),
});
}
return result;
}
}
exports.ExtendedServiceClient = ExtendedServiceClient;
//# sourceMappingURL=extendedClient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extendedClient.js","sourceRoot":"","sources":["../../src/extendedClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAGlC,oFAG8C;AAE9C,kEAA+D;AAS/D,oDAAmD;AACnD,+CAAiD;AA0BjD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,2BAAa;IACtD,YAAY,OAAqC;;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IACE,CAAA,MAAA,OAAO,CAAC,gBAAgB,0CAAE,MAAM,MAAK,KAAK;YAC1C,CAAC,IAAA,kEAAsC,EAAC,IAAI,CAAC,QAAQ,CAAC,EACtD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAA,wDAA4B,GAAE,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAA,MAAA,OAAO,CAAC,eAAe,0CAAE,eAAe,MAAK,KAAK,EAAE,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;gBACzB,IAAI,EAAE,uCAAkB;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,oBAAoB,CACxB,kBAAsC,EACtC,aAA4B;;QAE5B,MAAM,oBAAoB,GACxB,MAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,OAAO,0CAAE,UAAU,CAAC;QAE1C,IAAI,YAA+C,CAAC;QAEpD,SAAS,UAAU,CACjB,WAAkC,EAClC,YAAqB,EACrB,KAAe;YAEf,YAAY,GAAG,WAAW,CAAC;YAC3B,IAAI,oBAAoB,EAAE,CAAC;gBACzB,oBAAoB,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,kBAAkB,CAAC,OAAO,mCACrB,kBAAkB,CAAC,OAAO,KAC7B,UAAU,GACX,CAAC;QAEF,MAAM,MAAM,GAAM,MAAM,KAAK,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;QAEtF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;gBACzC,KAAK,EAAE,IAAA,8BAAgB,EAAC,YAAY,CAAC;aACtC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5DD,sDA4DC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nimport {\n createDisableKeepAlivePolicy,\n pipelineContainsDisableKeepAlivePolicy,\n} from \"./policies/disableKeepAlivePolicy.js\";\nimport type { RedirectOptions } from \"./policies/redirectOptions.js\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport type {\n CommonClientOptions,\n FullOperationResponse,\n OperationArguments,\n OperationSpec,\n RawResponseCallback,\n ServiceClientOptions,\n} from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { toCompatResponse } from \"./response.js\";\n\n/**\n * Options specific to Shim Clients.\n */\nexport interface ExtendedClientOptions {\n /**\n * Options to disable keep alive.\n */\n keepAliveOptions?: KeepAliveOptions;\n /**\n * Options to redirect requests.\n */\n redirectOptions?: RedirectOptions;\n}\n\n/**\n * Options that shim clients are expected to expose.\n */\nexport type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;\n\n/**\n * The common set of options that custom shim clients are expected to expose.\n */\nexport type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;\n\n/**\n * Client to provide compatability between core V1 & V2.\n */\nexport class ExtendedServiceClient extends ServiceClient {\n constructor(options: ExtendedServiceClientOptions) {\n super(options);\n\n if (\n options.keepAliveOptions?.enable === false &&\n !pipelineContainsDisableKeepAlivePolicy(this.pipeline)\n ) {\n this.pipeline.addPolicy(createDisableKeepAlivePolicy());\n }\n\n if (options.redirectOptions?.handleRedirects === false) {\n this.pipeline.removePolicy({\n name: redirectPolicyName,\n });\n }\n }\n\n /**\n * Compatible send operation request function.\n *\n * @param operationArguments - Operation arguments\n * @param operationSpec - Operation Spec\n * @returns\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<T> {\n const userProvidedCallBack: RawResponseCallback | undefined =\n operationArguments?.options?.onResponse;\n\n let lastResponse: FullOperationResponse | undefined;\n\n function onResponse(\n rawResponse: FullOperationResponse,\n flatResponse: unknown,\n error?: unknown,\n ): void {\n lastResponse = rawResponse;\n if (userProvidedCallBack) {\n userProvidedCallBack(rawResponse, flatResponse, error);\n }\n }\n\n operationArguments.options = {\n ...operationArguments.options,\n onResponse,\n };\n\n const result: T = await super.sendOperationRequest(operationArguments, operationSpec);\n\n if (lastResponse) {\n Object.defineProperty(result, \"_response\", {\n value: toCompatResponse(lastResponse),\n });\n }\n\n return result;\n }\n}\n"]}

View File

@@ -0,0 +1,9 @@
import type { HttpClient } from "@azure/core-rest-pipeline";
import type { RequestPolicy } from "./policies/requestPolicyFactoryPolicy.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export declare function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient;
//# sourceMappingURL=httpClientAdapter.d.ts.map

View File

@@ -0,0 +1,21 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertHttpClient = convertHttpClient;
const response_js_1 = require("./response.js");
const util_js_1 = require("./util.js");
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
function convertHttpClient(requestPolicyClient) {
return {
sendRequest: async (request) => {
const response = await requestPolicyClient.sendRequest((0, util_js_1.toWebResourceLike)(request, { createProxy: true }));
return (0, response_js_1.toPipelineResponse)(response);
},
};
}
//# sourceMappingURL=httpClientAdapter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"httpClientAdapter.js","sourceRoot":"","sources":["../../src/httpClientAdapter.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAYlC,8CASC;AAjBD,+CAAmD;AACnD,uCAA8C;AAE9C;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,mBAAkC;IAClE,OAAO;QACL,WAAW,EAAE,KAAK,EAAE,OAAwB,EAA6B,EAAE;YACzE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,WAAW,CACpD,IAAA,2BAAiB,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAClD,CAAC;YACF,OAAO,IAAA,gCAAkB,EAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, PipelineRequest, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport type { RequestPolicy } from \"./policies/requestPolicyFactoryPolicy.js\";\nimport { toPipelineResponse } from \"./response.js\";\nimport { toWebResourceLike } from \"./util.js\";\n\n/**\n * Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.\n * @param requestPolicyClient - A HttpClient compatible with core-http\n * @returns A HttpClient compatible with core-rest-pipeline\n */\nexport function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient {\n return {\n sendRequest: async (request: PipelineRequest): Promise<PipelineResponse> => {\n const response = await requestPolicyClient.sendRequest(\n toWebResourceLike(request, { createProxy: true }),\n );\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,14 @@
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, ExtendedServiceClientOptions, ExtendedCommonClientOptions, ExtendedClientOptions, } from "./extendedClient.js";
export { CompatResponse } from "./response.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, RequestPolicyFactory, RequestPolicy, RequestPolicyOptionsLike, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { KeepAliveOptions } from "./policies/keepAliveOptions.js";
export { RedirectOptions } from "./policies/redirectOptions.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { Agent, WebResourceLike, HttpHeadersLike, RawHttpHeaders, HttpHeader, TransferProgressEvent, toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,23 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.toHttpHeadersLike = exports.convertHttpClient = exports.disableKeepAlivePolicyName = exports.HttpPipelineLogLevel = exports.createRequestPolicyFactoryPolicy = exports.requestPolicyFactoryPolicyName = exports.ExtendedServiceClient = void 0;
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
var extendedClient_js_1 = require("./extendedClient.js");
Object.defineProperty(exports, "ExtendedServiceClient", { enumerable: true, get: function () { return extendedClient_js_1.ExtendedServiceClient; } });
var requestPolicyFactoryPolicy_js_1 = require("./policies/requestPolicyFactoryPolicy.js");
Object.defineProperty(exports, "requestPolicyFactoryPolicyName", { enumerable: true, get: function () { return requestPolicyFactoryPolicy_js_1.requestPolicyFactoryPolicyName; } });
Object.defineProperty(exports, "createRequestPolicyFactoryPolicy", { enumerable: true, get: function () { return requestPolicyFactoryPolicy_js_1.createRequestPolicyFactoryPolicy; } });
Object.defineProperty(exports, "HttpPipelineLogLevel", { enumerable: true, get: function () { return requestPolicyFactoryPolicy_js_1.HttpPipelineLogLevel; } });
var disableKeepAlivePolicy_js_1 = require("./policies/disableKeepAlivePolicy.js");
Object.defineProperty(exports, "disableKeepAlivePolicyName", { enumerable: true, get: function () { return disableKeepAlivePolicy_js_1.disableKeepAlivePolicyName; } });
var httpClientAdapter_js_1 = require("./httpClientAdapter.js");
Object.defineProperty(exports, "convertHttpClient", { enumerable: true, get: function () { return httpClientAdapter_js_1.convertHttpClient; } });
var util_js_1 = require("./util.js");
Object.defineProperty(exports, "toHttpHeadersLike", { enumerable: true, get: function () { return util_js_1.toHttpHeadersLike; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC;;;;GAIG;AACH,yDAK6B;AAJ3B,0HAAA,qBAAqB,OAAA;AAMvB,0FAOkD;AANhD,+IAAA,8BAA8B,OAAA;AAC9B,iJAAA,gCAAgC,OAAA;AAIhC,qIAAA,oBAAoB,OAAA;AAItB,kFAAkF;AAAzE,uIAAA,0BAA0B,OAAA;AACnC,+DAA2D;AAAlD,yHAAA,iBAAiB,OAAA;AAC1B,qCAQmB;AADjB,4GAAA,iBAAiB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A Shim Library that provides compatibility between Core V1 & V2 Packages.\n *\n * @packageDocumentation\n */\nexport {\n ExtendedServiceClient,\n ExtendedServiceClientOptions,\n ExtendedCommonClientOptions,\n ExtendedClientOptions,\n} from \"./extendedClient.js\";\nexport { CompatResponse } from \"./response.js\";\nexport {\n requestPolicyFactoryPolicyName,\n createRequestPolicyFactoryPolicy,\n RequestPolicyFactory,\n RequestPolicy,\n RequestPolicyOptionsLike,\n HttpPipelineLogLevel,\n} from \"./policies/requestPolicyFactoryPolicy.js\";\nexport { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nexport { RedirectOptions } from \"./policies/redirectOptions.js\";\nexport { disableKeepAlivePolicyName } from \"./policies/disableKeepAlivePolicy.js\";\nexport { convertHttpClient } from \"./httpClientAdapter.js\";\nexport {\n Agent,\n WebResourceLike,\n HttpHeadersLike,\n RawHttpHeaders,\n HttpHeader,\n TransferProgressEvent,\n toHttpHeadersLike,\n} from \"./util.js\";\n"]}

View File

@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

View File

@@ -0,0 +1,8 @@
import type { Pipeline, PipelinePolicy } from "@azure/core-rest-pipeline";
export declare const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export declare function createDisableKeepAlivePolicy(): PipelinePolicy;
/**
* @internal
*/
export declare function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean;
//# sourceMappingURL=disableKeepAlivePolicy.d.ts.map

View File

@@ -0,0 +1,24 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.disableKeepAlivePolicyName = void 0;
exports.createDisableKeepAlivePolicy = createDisableKeepAlivePolicy;
exports.pipelineContainsDisableKeepAlivePolicy = pipelineContainsDisableKeepAlivePolicy;
exports.disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
function createDisableKeepAlivePolicy() {
return {
name: exports.disableKeepAlivePolicyName,
async sendRequest(request, next) {
request.disableKeepAlive = true;
return next(request);
},
};
}
/**
* @internal
*/
function pipelineContainsDisableKeepAlivePolicy(pipeline) {
return pipeline.getOrderedPolicies().some((policy) => policy.name === exports.disableKeepAlivePolicyName);
}
//# sourceMappingURL=disableKeepAlivePolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"disableKeepAlivePolicy.js","sourceRoot":"","sources":["../../../src/policies/disableKeepAlivePolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAYlC,oEAQC;AAKD,wFAEC;AAjBY,QAAA,0BAA0B,GAAG,wBAAwB,CAAC;AAEnE,SAAgB,4BAA4B;IAC1C,OAAO;QACL,IAAI,EAAE,kCAA0B;QAChC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAChC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,sCAAsC,CAAC,QAAkB;IACvE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,kCAA0B,CAAC,CAAC;AACpG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n Pipeline,\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\nexport const disableKeepAlivePolicyName = \"DisableKeepAlivePolicy\";\n\nexport function createDisableKeepAlivePolicy(): PipelinePolicy {\n return {\n name: disableKeepAlivePolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.disableKeepAlive = true;\n return next(request);\n },\n };\n}\n\n/**\n * @internal\n */\nexport function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean {\n return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);\n}\n"]}

View File

@@ -0,0 +1,11 @@
/**
* Keep Alive Options for how HTTP connections.
*/
export interface KeepAliveOptions {
/**
* When true, connections will be kept alive for multiple requests.
* Defaults to true.
*/
enable?: boolean;
}
//# sourceMappingURL=keepAliveOptions.d.ts.map

View File

@@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=keepAliveOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"keepAliveOptions.js","sourceRoot":"","sources":["../../../src/policies/keepAliveOptions.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Keep Alive Options for how HTTP connections.\n */\nexport interface KeepAliveOptions {\n /**\n * When true, connections will be kept alive for multiple requests.\n * Defaults to true.\n */\n enable?: boolean;\n}\n"]}

View File

@@ -0,0 +1,15 @@
/**
* Options for how redirect responses are handled.
*/
export interface RedirectOptions {
/**
* When true, redirect responses are followed. Defaults to true.
*/
handleRedirects?: boolean;
/**
* The maximum number of times the redirect URL will be tried before
* failing. Defaults to 20.
*/
maxRetries?: number;
}
//# sourceMappingURL=redirectOptions.d.ts.map

View File

@@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=redirectOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"redirectOptions.js","sourceRoot":"","sources":["../../../src/policies/redirectOptions.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Options for how redirect responses are handled.\n */\nexport interface RedirectOptions {\n /**\n * When true, redirect responses are followed. Defaults to true.\n */\n handleRedirects?: boolean;\n\n /**\n * The maximum number of times the redirect URL will be tried before\n * failing. Defaults to 20.\n */\n maxRetries?: number;\n}\n"]}

View File

@@ -0,0 +1,41 @@
import type { PipelinePolicy } from "@azure/core-rest-pipeline";
import type { WebResourceLike } from "../util.js";
import type { CompatResponse } from "../response.js";
/**
* A compatible interface for core-http request policies
*/
export interface RequestPolicy {
sendRequest(httpRequest: WebResourceLike): Promise<CompatResponse>;
}
/**
* An enum for compatibility with RequestPolicy
*/
export declare enum HttpPipelineLogLevel {
ERROR = 1,
INFO = 3,
OFF = 0,
WARNING = 2
}
/**
* An interface for compatibility with RequestPolicy
*/
export interface RequestPolicyOptionsLike {
log(logLevel: HttpPipelineLogLevel, message: string): void;
shouldLog(logLevel: HttpPipelineLogLevel): boolean;
}
/**
* An interface for compatibility with core-http's RequestPolicyFactory
*/
export interface RequestPolicyFactory {
create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy;
}
/**
* The name of the RequestPolicyFactoryPolicy
*/
export declare const requestPolicyFactoryPolicyName = "RequestPolicyFactoryPolicy";
/**
* A policy that wraps policies written for core-http.
* @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline
*/
export declare function createRequestPolicyFactoryPolicy(factories: RequestPolicyFactory[]): PipelinePolicy;
//# sourceMappingURL=requestPolicyFactoryPolicy.d.ts.map

View File

@@ -0,0 +1,55 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.requestPolicyFactoryPolicyName = exports.HttpPipelineLogLevel = void 0;
exports.createRequestPolicyFactoryPolicy = createRequestPolicyFactoryPolicy;
const util_js_1 = require("../util.js");
const response_js_1 = require("../response.js");
/**
* An enum for compatibility with RequestPolicy
*/
var HttpPipelineLogLevel;
(function (HttpPipelineLogLevel) {
HttpPipelineLogLevel[HttpPipelineLogLevel["ERROR"] = 1] = "ERROR";
HttpPipelineLogLevel[HttpPipelineLogLevel["INFO"] = 3] = "INFO";
HttpPipelineLogLevel[HttpPipelineLogLevel["OFF"] = 0] = "OFF";
HttpPipelineLogLevel[HttpPipelineLogLevel["WARNING"] = 2] = "WARNING";
})(HttpPipelineLogLevel || (exports.HttpPipelineLogLevel = HttpPipelineLogLevel = {}));
const mockRequestPolicyOptions = {
log(_logLevel, _message) {
/* do nothing */
},
shouldLog(_logLevel) {
return false;
},
};
/**
* The name of the RequestPolicyFactoryPolicy
*/
exports.requestPolicyFactoryPolicyName = "RequestPolicyFactoryPolicy";
/**
* A policy that wraps policies written for core-http.
* @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline
*/
function createRequestPolicyFactoryPolicy(factories) {
const orderedFactories = factories.slice().reverse();
return {
name: exports.requestPolicyFactoryPolicyName,
async sendRequest(request, next) {
let httpPipeline = {
async sendRequest(httpRequest) {
const response = await next((0, util_js_1.toPipelineRequest)(httpRequest));
return (0, response_js_1.toCompatResponse)(response, { createProxy: true });
},
};
for (const factory of orderedFactories) {
httpPipeline = factory.create(httpPipeline, mockRequestPolicyOptions);
}
const webResourceLike = (0, util_js_1.toWebResourceLike)(request, { createProxy: true });
const response = await httpPipeline.sendRequest(webResourceLike);
return (0, response_js_1.toPipelineResponse)(response);
},
};
}
//# sourceMappingURL=requestPolicyFactoryPolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"requestPolicyFactoryPolicy.js","sourceRoot":"","sources":["../../../src/policies/requestPolicyFactoryPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA+DlC,4EAuBC;AA7ED,wCAAkE;AAElE,gDAAsE;AAStE;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,iEAAS,CAAA;IACT,+DAAQ,CAAA;IACR,6DAAO,CAAA;IACP,qEAAW,CAAA;AACb,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B;AAUD,MAAM,wBAAwB,GAA6B;IACzD,GAAG,CAAC,SAA+B,EAAE,QAAgB;QACnD,gBAAgB;IAClB,CAAC;IACD,SAAS,CAAC,SAA+B;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AASF;;GAEG;AACU,QAAA,8BAA8B,GAAG,4BAA4B,CAAC;AAE3E;;;GAGG;AACH,SAAgB,gCAAgC,CAC9C,SAAiC;IAEjC,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC;IAErD,OAAO;QACL,IAAI,EAAE,sCAA8B;QACpC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IAAI,YAAY,GAAkB;gBAChC,KAAK,CAAC,WAAW,CAAC,WAAW;oBAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAA,2BAAiB,EAAC,WAAW,CAAC,CAAC,CAAC;oBAC5D,OAAO,IAAA,8BAAgB,EAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3D,CAAC;aACF,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;gBACvC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;YACxE,CAAC;YAED,MAAM,eAAe,GAAG,IAAA,2BAAiB,EAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;YACjE,OAAO,IAAA,gCAAkB,EAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport type { WebResourceLike } from \"../util.js\";\nimport { toPipelineRequest, toWebResourceLike } from \"../util.js\";\nimport type { CompatResponse } from \"../response.js\";\nimport { toCompatResponse, toPipelineResponse } from \"../response.js\";\n\n/**\n * A compatible interface for core-http request policies\n */\nexport interface RequestPolicy {\n sendRequest(httpRequest: WebResourceLike): Promise<CompatResponse>;\n}\n\n/**\n * An enum for compatibility with RequestPolicy\n */\nexport enum HttpPipelineLogLevel {\n ERROR = 1,\n INFO = 3,\n OFF = 0,\n WARNING = 2,\n}\n\n/**\n * An interface for compatibility with RequestPolicy\n */\nexport interface RequestPolicyOptionsLike {\n log(logLevel: HttpPipelineLogLevel, message: string): void;\n shouldLog(logLevel: HttpPipelineLogLevel): boolean;\n}\n\nconst mockRequestPolicyOptions: RequestPolicyOptionsLike = {\n log(_logLevel: HttpPipelineLogLevel, _message: string): void {\n /* do nothing */\n },\n shouldLog(_logLevel: HttpPipelineLogLevel): boolean {\n return false;\n },\n};\n\n/**\n * An interface for compatibility with core-http's RequestPolicyFactory\n */\nexport interface RequestPolicyFactory {\n create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy;\n}\n\n/**\n * The name of the RequestPolicyFactoryPolicy\n */\nexport const requestPolicyFactoryPolicyName = \"RequestPolicyFactoryPolicy\";\n\n/**\n * A policy that wraps policies written for core-http.\n * @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline\n */\nexport function createRequestPolicyFactoryPolicy(\n factories: RequestPolicyFactory[],\n): PipelinePolicy {\n const orderedFactories = factories.slice().reverse();\n\n return {\n name: requestPolicyFactoryPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n let httpPipeline: RequestPolicy = {\n async sendRequest(httpRequest) {\n const response = await next(toPipelineRequest(httpRequest));\n return toCompatResponse(response, { createProxy: true });\n },\n };\n for (const factory of orderedFactories) {\n httpPipeline = factory.create(httpPipeline, mockRequestPolicyOptions);\n }\n\n const webResourceLike = toWebResourceLike(request, { createProxy: true });\n const response = await httpPipeline.sendRequest(webResourceLike);\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,30 @@
import type { FullOperationResponse } from "@azure/core-client";
import type { PipelineResponse } from "@azure/core-rest-pipeline";
import type { HttpHeadersLike, WebResourceLike } from "./util.js";
/**
* Http Response that is compatible with the core-v1(core-http).
*/
export interface CompatResponse extends Omit<FullOperationResponse, "request" | "headers"> {
/**
* A description of a HTTP request to be made to a remote server.
*/
request: WebResourceLike;
/**
* A collection of HTTP header key/value pairs.
*/
headers: HttpHeadersLike;
}
/**
* A helper to convert response objects from the new pipeline back to the old one.
* @param response - A response object from core-client.
* @returns A response compatible with `HttpOperationResponse` from core-http.
*/
export declare function toCompatResponse(response: FullOperationResponse, options?: {
createProxy?: boolean;
}): CompatResponse;
/**
* A helper to convert back to a PipelineResponse
* @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.
*/
export declare function toPipelineResponse(compatResponse: CompatResponse): PipelineResponse;
//# sourceMappingURL=response.d.ts.map

View File

@@ -0,0 +1,64 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.toCompatResponse = toCompatResponse;
exports.toPipelineResponse = toPipelineResponse;
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
const util_js_1 = require("./util.js");
const originalResponse = Symbol("Original FullOperationResponse");
/**
* A helper to convert response objects from the new pipeline back to the old one.
* @param response - A response object from core-client.
* @returns A response compatible with `HttpOperationResponse` from core-http.
*/
function toCompatResponse(response, options) {
let request = (0, util_js_1.toWebResourceLike)(response.request);
let headers = (0, util_js_1.toHttpHeadersLike)(response.headers);
if (options === null || options === void 0 ? void 0 : options.createProxy) {
return new Proxy(response, {
get(target, prop, receiver) {
if (prop === "headers") {
return headers;
}
else if (prop === "request") {
return request;
}
else if (prop === originalResponse) {
return response;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (prop === "headers") {
headers = value;
}
else if (prop === "request") {
request = value;
}
return Reflect.set(target, prop, value, receiver);
},
});
}
else {
return Object.assign(Object.assign({}, response), { request,
headers });
}
}
/**
* A helper to convert back to a PipelineResponse
* @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.
*/
function toPipelineResponse(compatResponse) {
const extendedCompatResponse = compatResponse;
const response = extendedCompatResponse[originalResponse];
const headers = (0, core_rest_pipeline_1.createHttpHeaders)(compatResponse.headers.toJson({ preserveCase: true }));
if (response) {
response.headers = headers;
return response;
}
else {
return Object.assign(Object.assign({}, compatResponse), { headers, request: (0, util_js_1.toPipelineRequest)(compatResponse.request) });
}
}
//# sourceMappingURL=response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/response.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA6BlC,4CAkCC;AAMD,gDAcC;AA/ED,kEAA8D;AAE9D,uCAAoF;AAepF,MAAM,gBAAgB,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAGlE;;;;GAIG;AACH,SAAgB,gBAAgB,CAC9B,QAA+B,EAC/B,OAAmC;IAEnC,IAAI,OAAO,GAAG,IAAA,2BAAiB,EAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,GAAG,IAAA,2BAAiB,EAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;YACzB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;gBACxB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,OAAO,CAAC;gBACjB,CAAC;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,OAAO,OAAO,CAAC;gBACjB,CAAC;qBAAM,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;oBACrC,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC;YACD,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ;gBAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YACpD,CAAC;SACF,CAA8B,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,uCACK,QAAQ,KACX,OAAO;YACP,OAAO,IACP;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,cAA8B;IAC/D,MAAM,sBAAsB,GAAG,cAAwC,CAAC;IACxE,MAAM,QAAQ,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,IAAA,sCAAiB,EAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACzF,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,uCACK,cAAc,KACjB,OAAO,EACP,OAAO,EAAE,IAAA,2BAAiB,EAAC,cAAc,CAAC,OAAO,CAAC,IAClD;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { FullOperationResponse } from \"@azure/core-client\";\nimport type { PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport type { HttpHeadersLike, WebResourceLike } from \"./util.js\";\nimport { toHttpHeadersLike, toPipelineRequest, toWebResourceLike } from \"./util.js\";\n/**\n * Http Response that is compatible with the core-v1(core-http).\n */\nexport interface CompatResponse extends Omit<FullOperationResponse, \"request\" | \"headers\"> {\n /**\n * A description of a HTTP request to be made to a remote server.\n */\n request: WebResourceLike;\n /**\n * A collection of HTTP header key/value pairs.\n */\n headers: HttpHeadersLike;\n}\n\nconst originalResponse = Symbol(\"Original FullOperationResponse\");\ntype ExtendedCompatResponse = CompatResponse & { [originalResponse]?: FullOperationResponse };\n\n/**\n * A helper to convert response objects from the new pipeline back to the old one.\n * @param response - A response object from core-client.\n * @returns A response compatible with `HttpOperationResponse` from core-http.\n */\nexport function toCompatResponse(\n response: FullOperationResponse,\n options?: { createProxy?: boolean },\n): CompatResponse {\n let request = toWebResourceLike(response.request);\n let headers = toHttpHeadersLike(response.headers);\n if (options?.createProxy) {\n return new Proxy(response, {\n get(target, prop, receiver) {\n if (prop === \"headers\") {\n return headers;\n } else if (prop === \"request\") {\n return request;\n } else if (prop === originalResponse) {\n return response;\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, value, receiver) {\n if (prop === \"headers\") {\n headers = value;\n } else if (prop === \"request\") {\n request = value;\n }\n return Reflect.set(target, prop, value, receiver);\n },\n }) as unknown as CompatResponse;\n } else {\n return {\n ...response,\n request,\n headers,\n };\n }\n}\n\n/**\n * A helper to convert back to a PipelineResponse\n * @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.\n */\nexport function toPipelineResponse(compatResponse: CompatResponse): PipelineResponse {\n const extendedCompatResponse = compatResponse as ExtendedCompatResponse;\n const response = extendedCompatResponse[originalResponse];\n const headers = createHttpHeaders(compatResponse.headers.toJson({ preserveCase: true }));\n if (response) {\n response.headers = headers;\n return response;\n } else {\n return {\n ...compatResponse,\n headers,\n request: toPipelineRequest(compatResponse.request),\n };\n }\n}\n"]}

View File

@@ -0,0 +1,11 @@
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
// It should be published with your NPM package. It should not be tracked by Git.
{
"tsdocVersion": "0.12",
"toolPackages": [
{
"packageName": "@microsoft/api-extractor",
"packageVersion": "7.49.2"
}
]
}

View File

@@ -0,0 +1,287 @@
import type { HttpMethods, ProxySettings } from "@azure/core-rest-pipeline";
import type { AbortSignalLike } from "@azure/abort-controller";
import type { HttpHeaders as HttpHeadersV2, PipelineRequest } from "@azure/core-rest-pipeline";
export declare function toPipelineRequest(webResource: WebResourceLike, options?: {
originalRequest?: PipelineRequest;
}): PipelineRequest;
export declare function toWebResourceLike(request: PipelineRequest, options?: {
createProxy?: boolean;
originalRequest?: PipelineRequest;
}): WebResourceLike;
/**
* Converts HttpHeaders from core-rest-pipeline to look like
* HttpHeaders from core-http.
* @param headers - HttpHeaders from core-rest-pipeline
* @returns HttpHeaders as they looked in core-http
*/
export declare function toHttpHeadersLike(headers: HttpHeadersV2): HttpHeadersLike;
/**
* An individual header within a HttpHeaders collection.
*/
export interface HttpHeader {
/**
* The name of the header.
*/
name: string;
/**
* The value of the header.
*/
value: string;
}
/**
* A HttpHeaders collection represented as a simple JSON object.
*/
export type RawHttpHeaders = {
[headerName: string]: string;
};
/**
* A collection of HTTP header key/value pairs.
*/
export interface HttpHeadersLike {
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header values that are contained in this collection.
*/
headerValues(): string[];
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeadersLike;
/**
* Get the JSON object representation of this HTTP header collection.
* The result is the same as `rawHeaders()`.
*/
toJson(options?: {
preserveCase?: boolean;
}): RawHttpHeaders;
}
/**
* A collection of HTTP header key/value pairs.
*/
export declare class HttpHeaders implements HttpHeadersLike {
private readonly _headersMap;
constructor(rawHeaders?: RawHttpHeaders);
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header values that are contained in this collection.
*/
headerValues(): string[];
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(options?: {
preserveCase?: boolean;
}): RawHttpHeaders;
/**
* Get the string representation of this HTTP header collection.
*/
toString(): string;
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeaders;
}
/**
* An interface compatible with NodeJS's `http.Agent`.
* We want to avoid publicly re-exporting the actual interface,
* since it might vary across runtime versions.
*/
export interface Agent {
/**
* Destroy any sockets that are currently in use by the agent.
*/
destroy(): void;
/**
* For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state.
*/
maxFreeSockets: number;
/**
* Determines how many concurrent sockets the agent can have open per origin.
*/
maxSockets: number;
/**
* An object which contains queues of requests that have not yet been assigned to sockets.
*/
requests: unknown;
/**
* An object which contains arrays of sockets currently in use by the agent.
*/
sockets: unknown;
}
/**
* A description of a HTTP request to be made to a remote server.
*/
export interface WebResourceLike {
/**
* The URL being accessed by the request.
*/
url: string;
/**
* The HTTP method to use when making the request.
*/
method: HttpMethods;
/**
* The HTTP body contents of the request.
*/
body?: any;
/**
* The HTTP headers to use when making the request.
*/
headers: HttpHeadersLike;
/**
* Whether or not the body of the HttpOperationResponse should be treated as a stream.
* @deprecated Use streamResponseStatusCodes property instead.
*/
streamResponseBody?: boolean;
/**
* A list of response status codes whose corresponding HttpOperationResponse body should be treated as a stream.
*/
streamResponseStatusCodes?: Set<number>;
/**
* Form data, used to build the request body.
*/
formData?: any;
/**
* A query string represented as an object.
*/
query?: {
[key: string]: any;
};
/**
* If credentials (cookies) should be sent along during an XHR.
*/
withCredentials: boolean;
/**
* The number of milliseconds a request can take before automatically being terminated.
* If the request is terminated, an `AbortError` is thrown.
*/
timeout: number;
/**
* Proxy configuration.
*/
proxySettings?: ProxySettings;
/**
* If the connection should be reused.
*/
keepAlive?: boolean;
/**
* Whether or not to decompress response according to Accept-Encoding header (node-fetch only)
*/
decompressResponse?: boolean;
/**
* A unique identifier for the request. Used for logging and tracing.
*/
requestId: string;
/**
* Signal of an abort controller. Can be used to abort both sending a network request and waiting for a response.
*/
abortSignal?: AbortSignalLike;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/** Callback which fires upon download progress. */
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/**
* NODEJS ONLY
*
* A Node-only option to provide a custom `http.Agent`/`https.Agent`.
* NOTE: usually this should be one instance shared by multiple requests so that the underlying
* connection to the service can be reused.
* Does nothing when running in the browser.
*/
agent?: Agent;
/**
* Clone this request object.
*/
clone(): WebResourceLike;
/**
* Validates that the required properties such as method, url, headers["Content-Type"],
* headers["accept-language"] are defined. It will throw an error if one of the above
* mentioned properties are not defined.
* Note: this a no-op for compat purposes.
*/
validateRequestProperties(): void;
/**
* This is a no-op for compat purposes and will throw if called.
*/
prepare(options: unknown): WebResourceLike;
}
/**
* Fired in response to upload or download progress.
*/
export type TransferProgressEvent = {
/**
* The number of bytes loaded so far.
*/
loadedBytes: number;
};
//# sourceMappingURL=util.d.ts.map

View File

@@ -0,0 +1,266 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpHeaders = void 0;
exports.toPipelineRequest = toPipelineRequest;
exports.toWebResourceLike = toWebResourceLike;
exports.toHttpHeadersLike = toHttpHeadersLike;
const core_rest_pipeline_1 = require("@azure/core-rest-pipeline");
// We use a custom symbol to cache a reference to the original request without
// exposing it on the public interface.
const originalRequestSymbol = Symbol("Original PipelineRequest");
// Symbol.for() will return the same symbol if it's already been created
// This particular one is used in core-client to handle the case of when a request is
// cloned but we need to retrieve the OperationSpec and OperationArguments from the
// original request.
const originalClientRequestSymbol = Symbol.for("@azure/core-client original request");
function toPipelineRequest(webResource, options = {}) {
const compatWebResource = webResource;
const request = compatWebResource[originalRequestSymbol];
const headers = (0, core_rest_pipeline_1.createHttpHeaders)(webResource.headers.toJson({ preserveCase: true }));
if (request) {
request.headers = headers;
return request;
}
else {
const newRequest = (0, core_rest_pipeline_1.createPipelineRequest)({
url: webResource.url,
method: webResource.method,
headers,
withCredentials: webResource.withCredentials,
timeout: webResource.timeout,
requestId: webResource.requestId,
abortSignal: webResource.abortSignal,
body: webResource.body,
formData: webResource.formData,
disableKeepAlive: !!webResource.keepAlive,
onDownloadProgress: webResource.onDownloadProgress,
onUploadProgress: webResource.onUploadProgress,
proxySettings: webResource.proxySettings,
streamResponseStatusCodes: webResource.streamResponseStatusCodes,
agent: webResource.agent,
});
if (options.originalRequest) {
newRequest[originalClientRequestSymbol] =
options.originalRequest;
}
return newRequest;
}
}
function toWebResourceLike(request, options) {
var _a;
const originalRequest = (_a = options === null || options === void 0 ? void 0 : options.originalRequest) !== null && _a !== void 0 ? _a : request;
const webResource = {
url: request.url,
method: request.method,
headers: toHttpHeadersLike(request.headers),
withCredentials: request.withCredentials,
timeout: request.timeout,
requestId: request.headers.get("x-ms-client-request-id") || request.requestId,
abortSignal: request.abortSignal,
body: request.body,
formData: request.formData,
keepAlive: !!request.disableKeepAlive,
onDownloadProgress: request.onDownloadProgress,
onUploadProgress: request.onUploadProgress,
proxySettings: request.proxySettings,
streamResponseStatusCodes: request.streamResponseStatusCodes,
agent: request.agent,
clone() {
throw new Error("Cannot clone a non-proxied WebResourceLike");
},
prepare() {
throw new Error("WebResourceLike.prepare() is not supported by @azure/core-http-compat");
},
validateRequestProperties() {
/** do nothing */
},
};
if (options === null || options === void 0 ? void 0 : options.createProxy) {
return new Proxy(webResource, {
get(target, prop, receiver) {
if (prop === originalRequestSymbol) {
return request;
}
else if (prop === "clone") {
return () => {
return toWebResourceLike(toPipelineRequest(webResource, { originalRequest }), {
createProxy: true,
originalRequest,
});
};
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (prop === "keepAlive") {
request.disableKeepAlive = !value;
}
const passThroughProps = [
"url",
"method",
"withCredentials",
"timeout",
"requestId",
"abortSignal",
"body",
"formData",
"onDownloadProgress",
"onUploadProgress",
"proxySettings",
"streamResponseStatusCodes",
"agent",
];
if (typeof prop === "string" && passThroughProps.includes(prop)) {
request[prop] = value;
}
return Reflect.set(target, prop, value, receiver);
},
});
}
else {
return webResource;
}
}
/**
* Converts HttpHeaders from core-rest-pipeline to look like
* HttpHeaders from core-http.
* @param headers - HttpHeaders from core-rest-pipeline
* @returns HttpHeaders as they looked in core-http
*/
function toHttpHeadersLike(headers) {
return new HttpHeaders(headers.toJSON({ preserveCase: true }));
}
/**
* A collection of HttpHeaders that can be sent with a HTTP request.
*/
function getHeaderKey(headerName) {
return headerName.toLowerCase();
}
/**
* A collection of HTTP header key/value pairs.
*/
class HttpHeaders {
constructor(rawHeaders) {
this._headersMap = {};
if (rawHeaders) {
for (const headerName in rawHeaders) {
this.set(headerName, rawHeaders[headerName]);
}
}
}
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName, headerValue) {
this._headersMap[getHeaderKey(headerName)] = {
name: headerName,
value: headerValue.toString(),
};
}
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName) {
const header = this._headersMap[getHeaderKey(headerName)];
return !header ? undefined : header.value;
}
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName) {
return !!this._headersMap[getHeaderKey(headerName)];
}
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName) {
const result = this.contains(headerName);
delete this._headersMap[getHeaderKey(headerName)];
return result;
}
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders() {
return this.toJson({ preserveCase: true });
}
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray() {
const headers = [];
for (const headerKey in this._headersMap) {
headers.push(this._headersMap[headerKey]);
}
return headers;
}
/**
* Get the header names that are contained in this collection.
*/
headerNames() {
const headerNames = [];
const headers = this.headersArray();
for (let i = 0; i < headers.length; ++i) {
headerNames.push(headers[i].name);
}
return headerNames;
}
/**
* Get the header values that are contained in this collection.
*/
headerValues() {
const headerValues = [];
const headers = this.headersArray();
for (let i = 0; i < headers.length; ++i) {
headerValues.push(headers[i].value);
}
return headerValues;
}
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(options = {}) {
const result = {};
if (options.preserveCase) {
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
result[header.name] = header.value;
}
}
else {
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
result[getHeaderKey(header.name)] = header.value;
}
}
return result;
}
/**
* Get the string representation of this HTTP header collection.
*/
toString() {
return JSON.stringify(this.toJson({ preserveCase: true }));
}
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone() {
const resultPreservingCasing = {};
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
resultPreservingCasing[header.name] = header.value;
}
return new HttpHeaders(resultPreservingCasing);
}
}
exports.HttpHeaders = HttpHeaders;
//# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,40 @@
import type { KeepAliveOptions } from "./policies/keepAliveOptions.js";
import type { RedirectOptions } from "./policies/redirectOptions.js";
import type { CommonClientOptions, OperationArguments, OperationSpec, ServiceClientOptions } from "@azure/core-client";
import { ServiceClient } from "@azure/core-client";
/**
* Options specific to Shim Clients.
*/
export interface ExtendedClientOptions {
/**
* Options to disable keep alive.
*/
keepAliveOptions?: KeepAliveOptions;
/**
* Options to redirect requests.
*/
redirectOptions?: RedirectOptions;
}
/**
* Options that shim clients are expected to expose.
*/
export type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;
/**
* The common set of options that custom shim clients are expected to expose.
*/
export type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;
/**
* Client to provide compatability between core V1 & V2.
*/
export declare class ExtendedServiceClient extends ServiceClient {
constructor(options: ExtendedServiceClientOptions);
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
sendOperationRequest<T>(operationArguments: OperationArguments, operationSpec: OperationSpec): Promise<T>;
}
//# sourceMappingURL=extendedClient.d.ts.map

View File

@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createDisableKeepAlivePolicy, pipelineContainsDisableKeepAlivePolicy, } from "./policies/disableKeepAlivePolicy.js";
import { redirectPolicyName } from "@azure/core-rest-pipeline";
import { ServiceClient } from "@azure/core-client";
import { toCompatResponse } from "./response.js";
/**
* Client to provide compatability between core V1 & V2.
*/
export class ExtendedServiceClient extends ServiceClient {
constructor(options) {
var _a, _b;
super(options);
if (((_a = options.keepAliveOptions) === null || _a === void 0 ? void 0 : _a.enable) === false &&
!pipelineContainsDisableKeepAlivePolicy(this.pipeline)) {
this.pipeline.addPolicy(createDisableKeepAlivePolicy());
}
if (((_b = options.redirectOptions) === null || _b === void 0 ? void 0 : _b.handleRedirects) === false) {
this.pipeline.removePolicy({
name: redirectPolicyName,
});
}
}
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
async sendOperationRequest(operationArguments, operationSpec) {
var _a;
const userProvidedCallBack = (_a = operationArguments === null || operationArguments === void 0 ? void 0 : operationArguments.options) === null || _a === void 0 ? void 0 : _a.onResponse;
let lastResponse;
function onResponse(rawResponse, flatResponse, error) {
lastResponse = rawResponse;
if (userProvidedCallBack) {
userProvidedCallBack(rawResponse, flatResponse, error);
}
}
operationArguments.options = Object.assign(Object.assign({}, operationArguments.options), { onResponse });
const result = await super.sendOperationRequest(operationArguments, operationSpec);
if (lastResponse) {
Object.defineProperty(result, "_response", {
value: toCompatResponse(lastResponse),
});
}
return result;
}
}
//# sourceMappingURL=extendedClient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extendedClient.js","sourceRoot":"","sources":["../../src/extendedClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAS/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA0BjD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAqC;;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IACE,CAAA,MAAA,OAAO,CAAC,gBAAgB,0CAAE,MAAM,MAAK,KAAK;YAC1C,CAAC,sCAAsC,CAAC,IAAI,CAAC,QAAQ,CAAC,EACtD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,4BAA4B,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAA,MAAA,OAAO,CAAC,eAAe,0CAAE,eAAe,MAAK,KAAK,EAAE,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;gBACzB,IAAI,EAAE,kBAAkB;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,oBAAoB,CACxB,kBAAsC,EACtC,aAA4B;;QAE5B,MAAM,oBAAoB,GACxB,MAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,OAAO,0CAAE,UAAU,CAAC;QAE1C,IAAI,YAA+C,CAAC;QAEpD,SAAS,UAAU,CACjB,WAAkC,EAClC,YAAqB,EACrB,KAAe;YAEf,YAAY,GAAG,WAAW,CAAC;YAC3B,IAAI,oBAAoB,EAAE,CAAC;gBACzB,oBAAoB,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,kBAAkB,CAAC,OAAO,mCACrB,kBAAkB,CAAC,OAAO,KAC7B,UAAU,GACX,CAAC;QAEF,MAAM,MAAM,GAAM,MAAM,KAAK,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;QAEtF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;gBACzC,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC;aACtC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nimport {\n createDisableKeepAlivePolicy,\n pipelineContainsDisableKeepAlivePolicy,\n} from \"./policies/disableKeepAlivePolicy.js\";\nimport type { RedirectOptions } from \"./policies/redirectOptions.js\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport type {\n CommonClientOptions,\n FullOperationResponse,\n OperationArguments,\n OperationSpec,\n RawResponseCallback,\n ServiceClientOptions,\n} from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { toCompatResponse } from \"./response.js\";\n\n/**\n * Options specific to Shim Clients.\n */\nexport interface ExtendedClientOptions {\n /**\n * Options to disable keep alive.\n */\n keepAliveOptions?: KeepAliveOptions;\n /**\n * Options to redirect requests.\n */\n redirectOptions?: RedirectOptions;\n}\n\n/**\n * Options that shim clients are expected to expose.\n */\nexport type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;\n\n/**\n * The common set of options that custom shim clients are expected to expose.\n */\nexport type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;\n\n/**\n * Client to provide compatability between core V1 & V2.\n */\nexport class ExtendedServiceClient extends ServiceClient {\n constructor(options: ExtendedServiceClientOptions) {\n super(options);\n\n if (\n options.keepAliveOptions?.enable === false &&\n !pipelineContainsDisableKeepAlivePolicy(this.pipeline)\n ) {\n this.pipeline.addPolicy(createDisableKeepAlivePolicy());\n }\n\n if (options.redirectOptions?.handleRedirects === false) {\n this.pipeline.removePolicy({\n name: redirectPolicyName,\n });\n }\n }\n\n /**\n * Compatible send operation request function.\n *\n * @param operationArguments - Operation arguments\n * @param operationSpec - Operation Spec\n * @returns\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<T> {\n const userProvidedCallBack: RawResponseCallback | undefined =\n operationArguments?.options?.onResponse;\n\n let lastResponse: FullOperationResponse | undefined;\n\n function onResponse(\n rawResponse: FullOperationResponse,\n flatResponse: unknown,\n error?: unknown,\n ): void {\n lastResponse = rawResponse;\n if (userProvidedCallBack) {\n userProvidedCallBack(rawResponse, flatResponse, error);\n }\n }\n\n operationArguments.options = {\n ...operationArguments.options,\n onResponse,\n };\n\n const result: T = await super.sendOperationRequest(operationArguments, operationSpec);\n\n if (lastResponse) {\n Object.defineProperty(result, \"_response\", {\n value: toCompatResponse(lastResponse),\n });\n }\n\n return result;\n }\n}\n"]}

View File

@@ -0,0 +1,9 @@
import type { HttpClient } from "@azure/core-rest-pipeline";
import type { RequestPolicy } from "./policies/requestPolicyFactoryPolicy.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export declare function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient;
//# sourceMappingURL=httpClientAdapter.d.ts.map

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toPipelineResponse } from "./response.js";
import { toWebResourceLike } from "./util.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export function convertHttpClient(requestPolicyClient) {
return {
sendRequest: async (request) => {
const response = await requestPolicyClient.sendRequest(toWebResourceLike(request, { createProxy: true }));
return toPipelineResponse(response);
},
};
}
//# sourceMappingURL=httpClientAdapter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"httpClientAdapter.js","sourceRoot":"","sources":["../../src/httpClientAdapter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,mBAAkC;IAClE,OAAO;QACL,WAAW,EAAE,KAAK,EAAE,OAAwB,EAA6B,EAAE;YACzE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,WAAW,CACpD,iBAAiB,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAClD,CAAC;YACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, PipelineRequest, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport type { RequestPolicy } from \"./policies/requestPolicyFactoryPolicy.js\";\nimport { toPipelineResponse } from \"./response.js\";\nimport { toWebResourceLike } from \"./util.js\";\n\n/**\n * Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.\n * @param requestPolicyClient - A HttpClient compatible with core-http\n * @returns A HttpClient compatible with core-rest-pipeline\n */\nexport function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient {\n return {\n sendRequest: async (request: PipelineRequest): Promise<PipelineResponse> => {\n const response = await requestPolicyClient.sendRequest(\n toWebResourceLike(request, { createProxy: true }),\n );\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,14 @@
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, ExtendedServiceClientOptions, ExtendedCommonClientOptions, ExtendedClientOptions, } from "./extendedClient.js";
export { CompatResponse } from "./response.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, RequestPolicyFactory, RequestPolicy, RequestPolicyOptionsLike, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { KeepAliveOptions } from "./policies/keepAliveOptions.js";
export { RedirectOptions } from "./policies/redirectOptions.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { Agent, WebResourceLike, HttpHeadersLike, RawHttpHeaders, HttpHeader, TransferProgressEvent, toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.d.ts.map

13
node_modules/@azure/core-http-compat/dist/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, } from "./extendedClient.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;GAIG;AACH,OAAO,EACL,qBAAqB,GAItB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAIhC,oBAAoB,GACrB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAOL,iBAAiB,GAClB,MAAM,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A Shim Library that provides compatibility between Core V1 & V2 Packages.\n *\n * @packageDocumentation\n */\nexport {\n ExtendedServiceClient,\n ExtendedServiceClientOptions,\n ExtendedCommonClientOptions,\n ExtendedClientOptions,\n} from \"./extendedClient.js\";\nexport { CompatResponse } from \"./response.js\";\nexport {\n requestPolicyFactoryPolicyName,\n createRequestPolicyFactoryPolicy,\n RequestPolicyFactory,\n RequestPolicy,\n RequestPolicyOptionsLike,\n HttpPipelineLogLevel,\n} from \"./policies/requestPolicyFactoryPolicy.js\";\nexport { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nexport { RedirectOptions } from \"./policies/redirectOptions.js\";\nexport { disableKeepAlivePolicyName } from \"./policies/disableKeepAlivePolicy.js\";\nexport { convertHttpClient } from \"./httpClientAdapter.js\";\nexport {\n Agent,\n WebResourceLike,\n HttpHeadersLike,\n RawHttpHeaders,\n HttpHeader,\n TransferProgressEvent,\n toHttpHeadersLike,\n} from \"./util.js\";\n"]}

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,8 @@
import type { Pipeline, PipelinePolicy } from "@azure/core-rest-pipeline";
export declare const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export declare function createDisableKeepAlivePolicy(): PipelinePolicy;
/**
* @internal
*/
export declare function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean;
//# sourceMappingURL=disableKeepAlivePolicy.d.ts.map

View File

@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export function createDisableKeepAlivePolicy() {
return {
name: disableKeepAlivePolicyName,
async sendRequest(request, next) {
request.disableKeepAlive = true;
return next(request);
},
};
}
/**
* @internal
*/
export function pipelineContainsDisableKeepAlivePolicy(pipeline) {
return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);
}
//# sourceMappingURL=disableKeepAlivePolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"disableKeepAlivePolicy.js","sourceRoot":"","sources":["../../../src/policies/disableKeepAlivePolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,MAAM,CAAC,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAEnE,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAChC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sCAAsC,CAAC,QAAkB;IACvE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,0BAA0B,CAAC,CAAC;AACpG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n Pipeline,\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\nexport const disableKeepAlivePolicyName = \"DisableKeepAlivePolicy\";\n\nexport function createDisableKeepAlivePolicy(): PipelinePolicy {\n return {\n name: disableKeepAlivePolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.disableKeepAlive = true;\n return next(request);\n },\n };\n}\n\n/**\n * @internal\n */\nexport function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean {\n return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);\n}\n"]}

View File

@@ -0,0 +1,11 @@
/**
* Keep Alive Options for how HTTP connections.
*/
export interface KeepAliveOptions {
/**
* When true, connections will be kept alive for multiple requests.
* Defaults to true.
*/
enable?: boolean;
}
//# sourceMappingURL=keepAliveOptions.d.ts.map

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=keepAliveOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"keepAliveOptions.js","sourceRoot":"","sources":["../../../src/policies/keepAliveOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Keep Alive Options for how HTTP connections.\n */\nexport interface KeepAliveOptions {\n /**\n * When true, connections will be kept alive for multiple requests.\n * Defaults to true.\n */\n enable?: boolean;\n}\n"]}

View File

@@ -0,0 +1,15 @@
/**
* Options for how redirect responses are handled.
*/
export interface RedirectOptions {
/**
* When true, redirect responses are followed. Defaults to true.
*/
handleRedirects?: boolean;
/**
* The maximum number of times the redirect URL will be tried before
* failing. Defaults to 20.
*/
maxRetries?: number;
}
//# sourceMappingURL=redirectOptions.d.ts.map

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=redirectOptions.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"redirectOptions.js","sourceRoot":"","sources":["../../../src/policies/redirectOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Options for how redirect responses are handled.\n */\nexport interface RedirectOptions {\n /**\n * When true, redirect responses are followed. Defaults to true.\n */\n handleRedirects?: boolean;\n\n /**\n * The maximum number of times the redirect URL will be tried before\n * failing. Defaults to 20.\n */\n maxRetries?: number;\n}\n"]}

View File

@@ -0,0 +1,41 @@
import type { PipelinePolicy } from "@azure/core-rest-pipeline";
import type { WebResourceLike } from "../util.js";
import type { CompatResponse } from "../response.js";
/**
* A compatible interface for core-http request policies
*/
export interface RequestPolicy {
sendRequest(httpRequest: WebResourceLike): Promise<CompatResponse>;
}
/**
* An enum for compatibility with RequestPolicy
*/
export declare enum HttpPipelineLogLevel {
ERROR = 1,
INFO = 3,
OFF = 0,
WARNING = 2
}
/**
* An interface for compatibility with RequestPolicy
*/
export interface RequestPolicyOptionsLike {
log(logLevel: HttpPipelineLogLevel, message: string): void;
shouldLog(logLevel: HttpPipelineLogLevel): boolean;
}
/**
* An interface for compatibility with core-http's RequestPolicyFactory
*/
export interface RequestPolicyFactory {
create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy;
}
/**
* The name of the RequestPolicyFactoryPolicy
*/
export declare const requestPolicyFactoryPolicyName = "RequestPolicyFactoryPolicy";
/**
* A policy that wraps policies written for core-http.
* @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline
*/
export declare function createRequestPolicyFactoryPolicy(factories: RequestPolicyFactory[]): PipelinePolicy;
//# sourceMappingURL=requestPolicyFactoryPolicy.d.ts.map

View File

@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toPipelineRequest, toWebResourceLike } from "../util.js";
import { toCompatResponse, toPipelineResponse } from "../response.js";
/**
* An enum for compatibility with RequestPolicy
*/
export var HttpPipelineLogLevel;
(function (HttpPipelineLogLevel) {
HttpPipelineLogLevel[HttpPipelineLogLevel["ERROR"] = 1] = "ERROR";
HttpPipelineLogLevel[HttpPipelineLogLevel["INFO"] = 3] = "INFO";
HttpPipelineLogLevel[HttpPipelineLogLevel["OFF"] = 0] = "OFF";
HttpPipelineLogLevel[HttpPipelineLogLevel["WARNING"] = 2] = "WARNING";
})(HttpPipelineLogLevel || (HttpPipelineLogLevel = {}));
const mockRequestPolicyOptions = {
log(_logLevel, _message) {
/* do nothing */
},
shouldLog(_logLevel) {
return false;
},
};
/**
* The name of the RequestPolicyFactoryPolicy
*/
export const requestPolicyFactoryPolicyName = "RequestPolicyFactoryPolicy";
/**
* A policy that wraps policies written for core-http.
* @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline
*/
export function createRequestPolicyFactoryPolicy(factories) {
const orderedFactories = factories.slice().reverse();
return {
name: requestPolicyFactoryPolicyName,
async sendRequest(request, next) {
let httpPipeline = {
async sendRequest(httpRequest) {
const response = await next(toPipelineRequest(httpRequest));
return toCompatResponse(response, { createProxy: true });
},
};
for (const factory of orderedFactories) {
httpPipeline = factory.create(httpPipeline, mockRequestPolicyOptions);
}
const webResourceLike = toWebResourceLike(request, { createProxy: true });
const response = await httpPipeline.sendRequest(webResourceLike);
return toPipelineResponse(response);
},
};
}
//# sourceMappingURL=requestPolicyFactoryPolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"requestPolicyFactoryPolicy.js","sourceRoot":"","sources":["../../../src/policies/requestPolicyFactoryPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AASlC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAStE;;GAEG;AACH,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,iEAAS,CAAA;IACT,+DAAQ,CAAA;IACR,6DAAO,CAAA;IACP,qEAAW,CAAA;AACb,CAAC,EALW,oBAAoB,KAApB,oBAAoB,QAK/B;AAUD,MAAM,wBAAwB,GAA6B;IACzD,GAAG,CAAC,SAA+B,EAAE,QAAgB;QACnD,gBAAgB;IAClB,CAAC;IACD,SAAS,CAAC,SAA+B;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAC;AASF;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,4BAA4B,CAAC;AAE3E;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC9C,SAAiC;IAEjC,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC;IAErD,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,IAAI,YAAY,GAAkB;gBAChC,KAAK,CAAC,WAAW,CAAC,WAAW;oBAC3B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;oBAC5D,OAAO,gBAAgB,CAAC,QAAQ,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC3D,CAAC;aACF,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;gBACvC,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;YACxE,CAAC;YAED,MAAM,eAAe,GAAG,iBAAiB,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1E,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;YACjE,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\nimport type { WebResourceLike } from \"../util.js\";\nimport { toPipelineRequest, toWebResourceLike } from \"../util.js\";\nimport type { CompatResponse } from \"../response.js\";\nimport { toCompatResponse, toPipelineResponse } from \"../response.js\";\n\n/**\n * A compatible interface for core-http request policies\n */\nexport interface RequestPolicy {\n sendRequest(httpRequest: WebResourceLike): Promise<CompatResponse>;\n}\n\n/**\n * An enum for compatibility with RequestPolicy\n */\nexport enum HttpPipelineLogLevel {\n ERROR = 1,\n INFO = 3,\n OFF = 0,\n WARNING = 2,\n}\n\n/**\n * An interface for compatibility with RequestPolicy\n */\nexport interface RequestPolicyOptionsLike {\n log(logLevel: HttpPipelineLogLevel, message: string): void;\n shouldLog(logLevel: HttpPipelineLogLevel): boolean;\n}\n\nconst mockRequestPolicyOptions: RequestPolicyOptionsLike = {\n log(_logLevel: HttpPipelineLogLevel, _message: string): void {\n /* do nothing */\n },\n shouldLog(_logLevel: HttpPipelineLogLevel): boolean {\n return false;\n },\n};\n\n/**\n * An interface for compatibility with core-http's RequestPolicyFactory\n */\nexport interface RequestPolicyFactory {\n create(nextPolicy: RequestPolicy, options: RequestPolicyOptionsLike): RequestPolicy;\n}\n\n/**\n * The name of the RequestPolicyFactoryPolicy\n */\nexport const requestPolicyFactoryPolicyName = \"RequestPolicyFactoryPolicy\";\n\n/**\n * A policy that wraps policies written for core-http.\n * @param factories - An array of `RequestPolicyFactory` objects from a core-http pipeline\n */\nexport function createRequestPolicyFactoryPolicy(\n factories: RequestPolicyFactory[],\n): PipelinePolicy {\n const orderedFactories = factories.slice().reverse();\n\n return {\n name: requestPolicyFactoryPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n let httpPipeline: RequestPolicy = {\n async sendRequest(httpRequest) {\n const response = await next(toPipelineRequest(httpRequest));\n return toCompatResponse(response, { createProxy: true });\n },\n };\n for (const factory of orderedFactories) {\n httpPipeline = factory.create(httpPipeline, mockRequestPolicyOptions);\n }\n\n const webResourceLike = toWebResourceLike(request, { createProxy: true });\n const response = await httpPipeline.sendRequest(webResourceLike);\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,30 @@
import type { FullOperationResponse } from "@azure/core-client";
import type { PipelineResponse } from "@azure/core-rest-pipeline";
import type { HttpHeadersLike, WebResourceLike } from "./util.js";
/**
* Http Response that is compatible with the core-v1(core-http).
*/
export interface CompatResponse extends Omit<FullOperationResponse, "request" | "headers"> {
/**
* A description of a HTTP request to be made to a remote server.
*/
request: WebResourceLike;
/**
* A collection of HTTP header key/value pairs.
*/
headers: HttpHeadersLike;
}
/**
* A helper to convert response objects from the new pipeline back to the old one.
* @param response - A response object from core-client.
* @returns A response compatible with `HttpOperationResponse` from core-http.
*/
export declare function toCompatResponse(response: FullOperationResponse, options?: {
createProxy?: boolean;
}): CompatResponse;
/**
* A helper to convert back to a PipelineResponse
* @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.
*/
export declare function toPipelineResponse(compatResponse: CompatResponse): PipelineResponse;
//# sourceMappingURL=response.d.ts.map

View File

@@ -0,0 +1,60 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createHttpHeaders } from "@azure/core-rest-pipeline";
import { toHttpHeadersLike, toPipelineRequest, toWebResourceLike } from "./util.js";
const originalResponse = Symbol("Original FullOperationResponse");
/**
* A helper to convert response objects from the new pipeline back to the old one.
* @param response - A response object from core-client.
* @returns A response compatible with `HttpOperationResponse` from core-http.
*/
export function toCompatResponse(response, options) {
let request = toWebResourceLike(response.request);
let headers = toHttpHeadersLike(response.headers);
if (options === null || options === void 0 ? void 0 : options.createProxy) {
return new Proxy(response, {
get(target, prop, receiver) {
if (prop === "headers") {
return headers;
}
else if (prop === "request") {
return request;
}
else if (prop === originalResponse) {
return response;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (prop === "headers") {
headers = value;
}
else if (prop === "request") {
request = value;
}
return Reflect.set(target, prop, value, receiver);
},
});
}
else {
return Object.assign(Object.assign({}, response), { request,
headers });
}
}
/**
* A helper to convert back to a PipelineResponse
* @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.
*/
export function toPipelineResponse(compatResponse) {
const extendedCompatResponse = compatResponse;
const response = extendedCompatResponse[originalResponse];
const headers = createHttpHeaders(compatResponse.headers.toJson({ preserveCase: true }));
if (response) {
response.headers = headers;
return response;
}
else {
return Object.assign(Object.assign({}, compatResponse), { headers, request: toPipelineRequest(compatResponse.request) });
}
}
//# sourceMappingURL=response.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/response.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAepF,MAAM,gBAAgB,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC;AAGlE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAA+B,EAC/B,OAAmC;IAEnC,IAAI,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE;YACzB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;gBACxB,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,OAAO,CAAC;gBACjB,CAAC;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,OAAO,OAAO,CAAC;gBACjB,CAAC;qBAAM,IAAI,IAAI,KAAK,gBAAgB,EAAE,CAAC;oBACrC,OAAO,QAAQ,CAAC;gBAClB,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7C,CAAC;YACD,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ;gBAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBACvB,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC;qBAAM,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC;gBACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YACpD,CAAC;SACF,CAA8B,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,uCACK,QAAQ,KACX,OAAO;YACP,OAAO,IACP;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,cAA8B;IAC/D,MAAM,sBAAsB,GAAG,cAAwC,CAAC;IACxE,MAAM,QAAQ,GAAG,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IACzF,IAAI,QAAQ,EAAE,CAAC;QACb,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,OAAO,QAAQ,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,uCACK,cAAc,KACjB,OAAO,EACP,OAAO,EAAE,iBAAiB,CAAC,cAAc,CAAC,OAAO,CAAC,IAClD;IACJ,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { FullOperationResponse } from \"@azure/core-client\";\nimport type { PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport { createHttpHeaders } from \"@azure/core-rest-pipeline\";\nimport type { HttpHeadersLike, WebResourceLike } from \"./util.js\";\nimport { toHttpHeadersLike, toPipelineRequest, toWebResourceLike } from \"./util.js\";\n/**\n * Http Response that is compatible with the core-v1(core-http).\n */\nexport interface CompatResponse extends Omit<FullOperationResponse, \"request\" | \"headers\"> {\n /**\n * A description of a HTTP request to be made to a remote server.\n */\n request: WebResourceLike;\n /**\n * A collection of HTTP header key/value pairs.\n */\n headers: HttpHeadersLike;\n}\n\nconst originalResponse = Symbol(\"Original FullOperationResponse\");\ntype ExtendedCompatResponse = CompatResponse & { [originalResponse]?: FullOperationResponse };\n\n/**\n * A helper to convert response objects from the new pipeline back to the old one.\n * @param response - A response object from core-client.\n * @returns A response compatible with `HttpOperationResponse` from core-http.\n */\nexport function toCompatResponse(\n response: FullOperationResponse,\n options?: { createProxy?: boolean },\n): CompatResponse {\n let request = toWebResourceLike(response.request);\n let headers = toHttpHeadersLike(response.headers);\n if (options?.createProxy) {\n return new Proxy(response, {\n get(target, prop, receiver) {\n if (prop === \"headers\") {\n return headers;\n } else if (prop === \"request\") {\n return request;\n } else if (prop === originalResponse) {\n return response;\n }\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop, value, receiver) {\n if (prop === \"headers\") {\n headers = value;\n } else if (prop === \"request\") {\n request = value;\n }\n return Reflect.set(target, prop, value, receiver);\n },\n }) as unknown as CompatResponse;\n } else {\n return {\n ...response,\n request,\n headers,\n };\n }\n}\n\n/**\n * A helper to convert back to a PipelineResponse\n * @param compatResponse - A response compatible with `HttpOperationResponse` from core-http.\n */\nexport function toPipelineResponse(compatResponse: CompatResponse): PipelineResponse {\n const extendedCompatResponse = compatResponse as ExtendedCompatResponse;\n const response = extendedCompatResponse[originalResponse];\n const headers = createHttpHeaders(compatResponse.headers.toJson({ preserveCase: true }));\n if (response) {\n response.headers = headers;\n return response;\n } else {\n return {\n ...compatResponse,\n headers,\n request: toPipelineRequest(compatResponse.request),\n };\n }\n}\n"]}

287
node_modules/@azure/core-http-compat/dist/esm/util.d.ts generated vendored Normal file
View File

@@ -0,0 +1,287 @@
import type { HttpMethods, ProxySettings } from "@azure/core-rest-pipeline";
import type { AbortSignalLike } from "@azure/abort-controller";
import type { HttpHeaders as HttpHeadersV2, PipelineRequest } from "@azure/core-rest-pipeline";
export declare function toPipelineRequest(webResource: WebResourceLike, options?: {
originalRequest?: PipelineRequest;
}): PipelineRequest;
export declare function toWebResourceLike(request: PipelineRequest, options?: {
createProxy?: boolean;
originalRequest?: PipelineRequest;
}): WebResourceLike;
/**
* Converts HttpHeaders from core-rest-pipeline to look like
* HttpHeaders from core-http.
* @param headers - HttpHeaders from core-rest-pipeline
* @returns HttpHeaders as they looked in core-http
*/
export declare function toHttpHeadersLike(headers: HttpHeadersV2): HttpHeadersLike;
/**
* An individual header within a HttpHeaders collection.
*/
export interface HttpHeader {
/**
* The name of the header.
*/
name: string;
/**
* The value of the header.
*/
value: string;
}
/**
* A HttpHeaders collection represented as a simple JSON object.
*/
export type RawHttpHeaders = {
[headerName: string]: string;
};
/**
* A collection of HTTP header key/value pairs.
*/
export interface HttpHeadersLike {
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header values that are contained in this collection.
*/
headerValues(): string[];
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeadersLike;
/**
* Get the JSON object representation of this HTTP header collection.
* The result is the same as `rawHeaders()`.
*/
toJson(options?: {
preserveCase?: boolean;
}): RawHttpHeaders;
}
/**
* A collection of HTTP header key/value pairs.
*/
export declare class HttpHeaders implements HttpHeadersLike {
private readonly _headersMap;
constructor(rawHeaders?: RawHttpHeaders);
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName: string, headerValue: string | number): void;
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName: string): string | undefined;
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName: string): boolean;
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName: string): boolean;
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders(): RawHttpHeaders;
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray(): HttpHeader[];
/**
* Get the header names that are contained in this collection.
*/
headerNames(): string[];
/**
* Get the header values that are contained in this collection.
*/
headerValues(): string[];
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(options?: {
preserveCase?: boolean;
}): RawHttpHeaders;
/**
* Get the string representation of this HTTP header collection.
*/
toString(): string;
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone(): HttpHeaders;
}
/**
* An interface compatible with NodeJS's `http.Agent`.
* We want to avoid publicly re-exporting the actual interface,
* since it might vary across runtime versions.
*/
export interface Agent {
/**
* Destroy any sockets that are currently in use by the agent.
*/
destroy(): void;
/**
* For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state.
*/
maxFreeSockets: number;
/**
* Determines how many concurrent sockets the agent can have open per origin.
*/
maxSockets: number;
/**
* An object which contains queues of requests that have not yet been assigned to sockets.
*/
requests: unknown;
/**
* An object which contains arrays of sockets currently in use by the agent.
*/
sockets: unknown;
}
/**
* A description of a HTTP request to be made to a remote server.
*/
export interface WebResourceLike {
/**
* The URL being accessed by the request.
*/
url: string;
/**
* The HTTP method to use when making the request.
*/
method: HttpMethods;
/**
* The HTTP body contents of the request.
*/
body?: any;
/**
* The HTTP headers to use when making the request.
*/
headers: HttpHeadersLike;
/**
* Whether or not the body of the HttpOperationResponse should be treated as a stream.
* @deprecated Use streamResponseStatusCodes property instead.
*/
streamResponseBody?: boolean;
/**
* A list of response status codes whose corresponding HttpOperationResponse body should be treated as a stream.
*/
streamResponseStatusCodes?: Set<number>;
/**
* Form data, used to build the request body.
*/
formData?: any;
/**
* A query string represented as an object.
*/
query?: {
[key: string]: any;
};
/**
* If credentials (cookies) should be sent along during an XHR.
*/
withCredentials: boolean;
/**
* The number of milliseconds a request can take before automatically being terminated.
* If the request is terminated, an `AbortError` is thrown.
*/
timeout: number;
/**
* Proxy configuration.
*/
proxySettings?: ProxySettings;
/**
* If the connection should be reused.
*/
keepAlive?: boolean;
/**
* Whether or not to decompress response according to Accept-Encoding header (node-fetch only)
*/
decompressResponse?: boolean;
/**
* A unique identifier for the request. Used for logging and tracing.
*/
requestId: string;
/**
* Signal of an abort controller. Can be used to abort both sending a network request and waiting for a response.
*/
abortSignal?: AbortSignalLike;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/** Callback which fires upon download progress. */
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/**
* NODEJS ONLY
*
* A Node-only option to provide a custom `http.Agent`/`https.Agent`.
* NOTE: usually this should be one instance shared by multiple requests so that the underlying
* connection to the service can be reused.
* Does nothing when running in the browser.
*/
agent?: Agent;
/**
* Clone this request object.
*/
clone(): WebResourceLike;
/**
* Validates that the required properties such as method, url, headers["Content-Type"],
* headers["accept-language"] are defined. It will throw an error if one of the above
* mentioned properties are not defined.
* Note: this a no-op for compat purposes.
*/
validateRequestProperties(): void;
/**
* This is a no-op for compat purposes and will throw if called.
*/
prepare(options: unknown): WebResourceLike;
}
/**
* Fired in response to upload or download progress.
*/
export type TransferProgressEvent = {
/**
* The number of bytes loaded so far.
*/
loadedBytes: number;
};
//# sourceMappingURL=util.d.ts.map

259
node_modules/@azure/core-http-compat/dist/esm/util.js generated vendored Normal file
View File

@@ -0,0 +1,259 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createHttpHeaders, createPipelineRequest } from "@azure/core-rest-pipeline";
// We use a custom symbol to cache a reference to the original request without
// exposing it on the public interface.
const originalRequestSymbol = Symbol("Original PipelineRequest");
// Symbol.for() will return the same symbol if it's already been created
// This particular one is used in core-client to handle the case of when a request is
// cloned but we need to retrieve the OperationSpec and OperationArguments from the
// original request.
const originalClientRequestSymbol = Symbol.for("@azure/core-client original request");
export function toPipelineRequest(webResource, options = {}) {
const compatWebResource = webResource;
const request = compatWebResource[originalRequestSymbol];
const headers = createHttpHeaders(webResource.headers.toJson({ preserveCase: true }));
if (request) {
request.headers = headers;
return request;
}
else {
const newRequest = createPipelineRequest({
url: webResource.url,
method: webResource.method,
headers,
withCredentials: webResource.withCredentials,
timeout: webResource.timeout,
requestId: webResource.requestId,
abortSignal: webResource.abortSignal,
body: webResource.body,
formData: webResource.formData,
disableKeepAlive: !!webResource.keepAlive,
onDownloadProgress: webResource.onDownloadProgress,
onUploadProgress: webResource.onUploadProgress,
proxySettings: webResource.proxySettings,
streamResponseStatusCodes: webResource.streamResponseStatusCodes,
agent: webResource.agent,
});
if (options.originalRequest) {
newRequest[originalClientRequestSymbol] =
options.originalRequest;
}
return newRequest;
}
}
export function toWebResourceLike(request, options) {
var _a;
const originalRequest = (_a = options === null || options === void 0 ? void 0 : options.originalRequest) !== null && _a !== void 0 ? _a : request;
const webResource = {
url: request.url,
method: request.method,
headers: toHttpHeadersLike(request.headers),
withCredentials: request.withCredentials,
timeout: request.timeout,
requestId: request.headers.get("x-ms-client-request-id") || request.requestId,
abortSignal: request.abortSignal,
body: request.body,
formData: request.formData,
keepAlive: !!request.disableKeepAlive,
onDownloadProgress: request.onDownloadProgress,
onUploadProgress: request.onUploadProgress,
proxySettings: request.proxySettings,
streamResponseStatusCodes: request.streamResponseStatusCodes,
agent: request.agent,
clone() {
throw new Error("Cannot clone a non-proxied WebResourceLike");
},
prepare() {
throw new Error("WebResourceLike.prepare() is not supported by @azure/core-http-compat");
},
validateRequestProperties() {
/** do nothing */
},
};
if (options === null || options === void 0 ? void 0 : options.createProxy) {
return new Proxy(webResource, {
get(target, prop, receiver) {
if (prop === originalRequestSymbol) {
return request;
}
else if (prop === "clone") {
return () => {
return toWebResourceLike(toPipelineRequest(webResource, { originalRequest }), {
createProxy: true,
originalRequest,
});
};
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value, receiver) {
if (prop === "keepAlive") {
request.disableKeepAlive = !value;
}
const passThroughProps = [
"url",
"method",
"withCredentials",
"timeout",
"requestId",
"abortSignal",
"body",
"formData",
"onDownloadProgress",
"onUploadProgress",
"proxySettings",
"streamResponseStatusCodes",
"agent",
];
if (typeof prop === "string" && passThroughProps.includes(prop)) {
request[prop] = value;
}
return Reflect.set(target, prop, value, receiver);
},
});
}
else {
return webResource;
}
}
/**
* Converts HttpHeaders from core-rest-pipeline to look like
* HttpHeaders from core-http.
* @param headers - HttpHeaders from core-rest-pipeline
* @returns HttpHeaders as they looked in core-http
*/
export function toHttpHeadersLike(headers) {
return new HttpHeaders(headers.toJSON({ preserveCase: true }));
}
/**
* A collection of HttpHeaders that can be sent with a HTTP request.
*/
function getHeaderKey(headerName) {
return headerName.toLowerCase();
}
/**
* A collection of HTTP header key/value pairs.
*/
export class HttpHeaders {
constructor(rawHeaders) {
this._headersMap = {};
if (rawHeaders) {
for (const headerName in rawHeaders) {
this.set(headerName, rawHeaders[headerName]);
}
}
}
/**
* Set a header in this collection with the provided name and value. The name is
* case-insensitive.
* @param headerName - The name of the header to set. This value is case-insensitive.
* @param headerValue - The value of the header to set.
*/
set(headerName, headerValue) {
this._headersMap[getHeaderKey(headerName)] = {
name: headerName,
value: headerValue.toString(),
};
}
/**
* Get the header value for the provided header name, or undefined if no header exists in this
* collection with the provided name.
* @param headerName - The name of the header.
*/
get(headerName) {
const header = this._headersMap[getHeaderKey(headerName)];
return !header ? undefined : header.value;
}
/**
* Get whether or not this header collection contains a header entry for the provided header name.
*/
contains(headerName) {
return !!this._headersMap[getHeaderKey(headerName)];
}
/**
* Remove the header with the provided headerName. Return whether or not the header existed and
* was removed.
* @param headerName - The name of the header to remove.
*/
remove(headerName) {
const result = this.contains(headerName);
delete this._headersMap[getHeaderKey(headerName)];
return result;
}
/**
* Get the headers that are contained this collection as an object.
*/
rawHeaders() {
return this.toJson({ preserveCase: true });
}
/**
* Get the headers that are contained in this collection as an array.
*/
headersArray() {
const headers = [];
for (const headerKey in this._headersMap) {
headers.push(this._headersMap[headerKey]);
}
return headers;
}
/**
* Get the header names that are contained in this collection.
*/
headerNames() {
const headerNames = [];
const headers = this.headersArray();
for (let i = 0; i < headers.length; ++i) {
headerNames.push(headers[i].name);
}
return headerNames;
}
/**
* Get the header values that are contained in this collection.
*/
headerValues() {
const headerValues = [];
const headers = this.headersArray();
for (let i = 0; i < headers.length; ++i) {
headerValues.push(headers[i].value);
}
return headerValues;
}
/**
* Get the JSON object representation of this HTTP header collection.
*/
toJson(options = {}) {
const result = {};
if (options.preserveCase) {
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
result[header.name] = header.value;
}
}
else {
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
result[getHeaderKey(header.name)] = header.value;
}
}
return result;
}
/**
* Get the string representation of this HTTP header collection.
*/
toString() {
return JSON.stringify(this.toJson({ preserveCase: true }));
}
/**
* Create a deep clone/copy of this HttpHeaders collection.
*/
clone() {
const resultPreservingCasing = {};
for (const headerKey in this._headersMap) {
const header = this._headersMap[headerKey];
resultPreservingCasing[header.name] = header.value;
}
return new HttpHeaders(resultPreservingCasing);
}
}
//# sourceMappingURL=util.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,40 @@
import type { KeepAliveOptions } from "./policies/keepAliveOptions.js";
import type { RedirectOptions } from "./policies/redirectOptions.js";
import type { CommonClientOptions, OperationArguments, OperationSpec, ServiceClientOptions } from "@azure/core-client";
import { ServiceClient } from "@azure/core-client";
/**
* Options specific to Shim Clients.
*/
export interface ExtendedClientOptions {
/**
* Options to disable keep alive.
*/
keepAliveOptions?: KeepAliveOptions;
/**
* Options to redirect requests.
*/
redirectOptions?: RedirectOptions;
}
/**
* Options that shim clients are expected to expose.
*/
export type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;
/**
* The common set of options that custom shim clients are expected to expose.
*/
export type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;
/**
* Client to provide compatability between core V1 & V2.
*/
export declare class ExtendedServiceClient extends ServiceClient {
constructor(options: ExtendedServiceClientOptions);
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
sendOperationRequest<T>(operationArguments: OperationArguments, operationSpec: OperationSpec): Promise<T>;
}
//# sourceMappingURL=extendedClient.d.ts.map

View File

@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createDisableKeepAlivePolicy, pipelineContainsDisableKeepAlivePolicy, } from "./policies/disableKeepAlivePolicy.js";
import { redirectPolicyName } from "@azure/core-rest-pipeline";
import { ServiceClient } from "@azure/core-client";
import { toCompatResponse } from "./response.js";
/**
* Client to provide compatability between core V1 & V2.
*/
export class ExtendedServiceClient extends ServiceClient {
constructor(options) {
var _a, _b;
super(options);
if (((_a = options.keepAliveOptions) === null || _a === void 0 ? void 0 : _a.enable) === false &&
!pipelineContainsDisableKeepAlivePolicy(this.pipeline)) {
this.pipeline.addPolicy(createDisableKeepAlivePolicy());
}
if (((_b = options.redirectOptions) === null || _b === void 0 ? void 0 : _b.handleRedirects) === false) {
this.pipeline.removePolicy({
name: redirectPolicyName,
});
}
}
/**
* Compatible send operation request function.
*
* @param operationArguments - Operation arguments
* @param operationSpec - Operation Spec
* @returns
*/
async sendOperationRequest(operationArguments, operationSpec) {
var _a;
const userProvidedCallBack = (_a = operationArguments === null || operationArguments === void 0 ? void 0 : operationArguments.options) === null || _a === void 0 ? void 0 : _a.onResponse;
let lastResponse;
function onResponse(rawResponse, flatResponse, error) {
lastResponse = rawResponse;
if (userProvidedCallBack) {
userProvidedCallBack(rawResponse, flatResponse, error);
}
}
operationArguments.options = Object.assign(Object.assign({}, operationArguments.options), { onResponse });
const result = await super.sendOperationRequest(operationArguments, operationSpec);
if (lastResponse) {
Object.defineProperty(result, "_response", {
value: toCompatResponse(lastResponse),
});
}
return result;
}
}
//# sourceMappingURL=extendedClient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extendedClient.js","sourceRoot":"","sources":["../../src/extendedClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAS/D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA0BjD;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAqC;;QAC/C,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IACE,CAAA,MAAA,OAAO,CAAC,gBAAgB,0CAAE,MAAM,MAAK,KAAK;YAC1C,CAAC,sCAAsC,CAAC,IAAI,CAAC,QAAQ,CAAC,EACtD,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,4BAA4B,EAAE,CAAC,CAAC;QAC1D,CAAC;QAED,IAAI,CAAA,MAAA,OAAO,CAAC,eAAe,0CAAE,eAAe,MAAK,KAAK,EAAE,CAAC;YACvD,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;gBACzB,IAAI,EAAE,kBAAkB;aACzB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,oBAAoB,CACxB,kBAAsC,EACtC,aAA4B;;QAE5B,MAAM,oBAAoB,GACxB,MAAA,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,CAAE,OAAO,0CAAE,UAAU,CAAC;QAE1C,IAAI,YAA+C,CAAC;QAEpD,SAAS,UAAU,CACjB,WAAkC,EAClC,YAAqB,EACrB,KAAe;YAEf,YAAY,GAAG,WAAW,CAAC;YAC3B,IAAI,oBAAoB,EAAE,CAAC;gBACzB,oBAAoB,CAAC,WAAW,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,kBAAkB,CAAC,OAAO,mCACrB,kBAAkB,CAAC,OAAO,KAC7B,UAAU,GACX,CAAC;QAEF,MAAM,MAAM,GAAM,MAAM,KAAK,CAAC,oBAAoB,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;QAEtF,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE;gBACzC,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC;aACtC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nimport {\n createDisableKeepAlivePolicy,\n pipelineContainsDisableKeepAlivePolicy,\n} from \"./policies/disableKeepAlivePolicy.js\";\nimport type { RedirectOptions } from \"./policies/redirectOptions.js\";\nimport { redirectPolicyName } from \"@azure/core-rest-pipeline\";\nimport type {\n CommonClientOptions,\n FullOperationResponse,\n OperationArguments,\n OperationSpec,\n RawResponseCallback,\n ServiceClientOptions,\n} from \"@azure/core-client\";\nimport { ServiceClient } from \"@azure/core-client\";\nimport { toCompatResponse } from \"./response.js\";\n\n/**\n * Options specific to Shim Clients.\n */\nexport interface ExtendedClientOptions {\n /**\n * Options to disable keep alive.\n */\n keepAliveOptions?: KeepAliveOptions;\n /**\n * Options to redirect requests.\n */\n redirectOptions?: RedirectOptions;\n}\n\n/**\n * Options that shim clients are expected to expose.\n */\nexport type ExtendedServiceClientOptions = ServiceClientOptions & ExtendedClientOptions;\n\n/**\n * The common set of options that custom shim clients are expected to expose.\n */\nexport type ExtendedCommonClientOptions = CommonClientOptions & ExtendedClientOptions;\n\n/**\n * Client to provide compatability between core V1 & V2.\n */\nexport class ExtendedServiceClient extends ServiceClient {\n constructor(options: ExtendedServiceClientOptions) {\n super(options);\n\n if (\n options.keepAliveOptions?.enable === false &&\n !pipelineContainsDisableKeepAlivePolicy(this.pipeline)\n ) {\n this.pipeline.addPolicy(createDisableKeepAlivePolicy());\n }\n\n if (options.redirectOptions?.handleRedirects === false) {\n this.pipeline.removePolicy({\n name: redirectPolicyName,\n });\n }\n }\n\n /**\n * Compatible send operation request function.\n *\n * @param operationArguments - Operation arguments\n * @param operationSpec - Operation Spec\n * @returns\n */\n async sendOperationRequest<T>(\n operationArguments: OperationArguments,\n operationSpec: OperationSpec,\n ): Promise<T> {\n const userProvidedCallBack: RawResponseCallback | undefined =\n operationArguments?.options?.onResponse;\n\n let lastResponse: FullOperationResponse | undefined;\n\n function onResponse(\n rawResponse: FullOperationResponse,\n flatResponse: unknown,\n error?: unknown,\n ): void {\n lastResponse = rawResponse;\n if (userProvidedCallBack) {\n userProvidedCallBack(rawResponse, flatResponse, error);\n }\n }\n\n operationArguments.options = {\n ...operationArguments.options,\n onResponse,\n };\n\n const result: T = await super.sendOperationRequest(operationArguments, operationSpec);\n\n if (lastResponse) {\n Object.defineProperty(result, \"_response\", {\n value: toCompatResponse(lastResponse),\n });\n }\n\n return result;\n }\n}\n"]}

View File

@@ -0,0 +1,9 @@
import type { HttpClient } from "@azure/core-rest-pipeline";
import type { RequestPolicy } from "./policies/requestPolicyFactoryPolicy.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export declare function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient;
//# sourceMappingURL=httpClientAdapter.d.ts.map

View File

@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toPipelineResponse } from "./response.js";
import { toWebResourceLike } from "./util.js";
/**
* Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.
* @param requestPolicyClient - A HttpClient compatible with core-http
* @returns A HttpClient compatible with core-rest-pipeline
*/
export function convertHttpClient(requestPolicyClient) {
return {
sendRequest: async (request) => {
const response = await requestPolicyClient.sendRequest(toWebResourceLike(request, { createProxy: true }));
return toPipelineResponse(response);
},
};
}
//# sourceMappingURL=httpClientAdapter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"httpClientAdapter.js","sourceRoot":"","sources":["../../src/httpClientAdapter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,mBAAkC;IAClE,OAAO;QACL,WAAW,EAAE,KAAK,EAAE,OAAwB,EAA6B,EAAE;YACzE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,WAAW,CACpD,iBAAiB,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAClD,CAAC;YACF,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, PipelineRequest, PipelineResponse } from \"@azure/core-rest-pipeline\";\nimport type { RequestPolicy } from \"./policies/requestPolicyFactoryPolicy.js\";\nimport { toPipelineResponse } from \"./response.js\";\nimport { toWebResourceLike } from \"./util.js\";\n\n/**\n * Converts a RequestPolicy based HttpClient to a PipelineRequest based HttpClient.\n * @param requestPolicyClient - A HttpClient compatible with core-http\n * @returns A HttpClient compatible with core-rest-pipeline\n */\nexport function convertHttpClient(requestPolicyClient: RequestPolicy): HttpClient {\n return {\n sendRequest: async (request: PipelineRequest): Promise<PipelineResponse> => {\n const response = await requestPolicyClient.sendRequest(\n toWebResourceLike(request, { createProxy: true }),\n );\n return toPipelineResponse(response);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,14 @@
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, ExtendedServiceClientOptions, ExtendedCommonClientOptions, ExtendedClientOptions, } from "./extendedClient.js";
export { CompatResponse } from "./response.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, RequestPolicyFactory, RequestPolicy, RequestPolicyOptionsLike, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { KeepAliveOptions } from "./policies/keepAliveOptions.js";
export { RedirectOptions } from "./policies/redirectOptions.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { Agent, WebResourceLike, HttpHeadersLike, RawHttpHeaders, HttpHeader, TransferProgressEvent, toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* A Shim Library that provides compatibility between Core V1 & V2 Packages.
*
* @packageDocumentation
*/
export { ExtendedServiceClient, } from "./extendedClient.js";
export { requestPolicyFactoryPolicyName, createRequestPolicyFactoryPolicy, HttpPipelineLogLevel, } from "./policies/requestPolicyFactoryPolicy.js";
export { disableKeepAlivePolicyName } from "./policies/disableKeepAlivePolicy.js";
export { convertHttpClient } from "./httpClientAdapter.js";
export { toHttpHeadersLike, } from "./util.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;GAIG;AACH,OAAO,EACL,qBAAqB,GAItB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAIhC,oBAAoB,GACrB,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAOL,iBAAiB,GAClB,MAAM,WAAW,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * A Shim Library that provides compatibility between Core V1 & V2 Packages.\n *\n * @packageDocumentation\n */\nexport {\n ExtendedServiceClient,\n ExtendedServiceClientOptions,\n ExtendedCommonClientOptions,\n ExtendedClientOptions,\n} from \"./extendedClient.js\";\nexport { CompatResponse } from \"./response.js\";\nexport {\n requestPolicyFactoryPolicyName,\n createRequestPolicyFactoryPolicy,\n RequestPolicyFactory,\n RequestPolicy,\n RequestPolicyOptionsLike,\n HttpPipelineLogLevel,\n} from \"./policies/requestPolicyFactoryPolicy.js\";\nexport { KeepAliveOptions } from \"./policies/keepAliveOptions.js\";\nexport { RedirectOptions } from \"./policies/redirectOptions.js\";\nexport { disableKeepAlivePolicyName } from \"./policies/disableKeepAlivePolicy.js\";\nexport { convertHttpClient } from \"./httpClientAdapter.js\";\nexport {\n Agent,\n WebResourceLike,\n HttpHeadersLike,\n RawHttpHeaders,\n HttpHeader,\n TransferProgressEvent,\n toHttpHeadersLike,\n} from \"./util.js\";\n"]}

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,8 @@
import type { Pipeline, PipelinePolicy } from "@azure/core-rest-pipeline";
export declare const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export declare function createDisableKeepAlivePolicy(): PipelinePolicy;
/**
* @internal
*/
export declare function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean;
//# sourceMappingURL=disableKeepAlivePolicy.d.ts.map

View File

@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export const disableKeepAlivePolicyName = "DisableKeepAlivePolicy";
export function createDisableKeepAlivePolicy() {
return {
name: disableKeepAlivePolicyName,
async sendRequest(request, next) {
request.disableKeepAlive = true;
return next(request);
},
};
}
/**
* @internal
*/
export function pipelineContainsDisableKeepAlivePolicy(pipeline) {
return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);
}
//# sourceMappingURL=disableKeepAlivePolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"disableKeepAlivePolicy.js","sourceRoot":"","sources":["../../../src/policies/disableKeepAlivePolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,MAAM,CAAC,MAAM,0BAA0B,GAAG,wBAAwB,CAAC;AAEnE,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;YAChC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sCAAsC,CAAC,QAAkB;IACvE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,0BAA0B,CAAC,CAAC;AACpG,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n Pipeline,\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\nexport const disableKeepAlivePolicyName = \"DisableKeepAlivePolicy\";\n\nexport function createDisableKeepAlivePolicy(): PipelinePolicy {\n return {\n name: disableKeepAlivePolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.disableKeepAlive = true;\n return next(request);\n },\n };\n}\n\n/**\n * @internal\n */\nexport function pipelineContainsDisableKeepAlivePolicy(pipeline: Pipeline): boolean {\n return pipeline.getOrderedPolicies().some((policy) => policy.name === disableKeepAlivePolicyName);\n}\n"]}

Some files were not shown because too many files have changed in this diff Show More