wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
{
  "version": 3,
  "sources": ["../../src/extendedClient.ts"],
  "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"],
  "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oCAGO;AAEP,gCAAmC;AASnC,yBAA8B;AAC9B,sBAAiC;AA6B1B,MAAM,8BAA8B,iCAAc;AAAA,EACvD,YAAY,SAAuC;AACjD,UAAM,OAAO;AAEb,QACE,QAAQ,kBAAkB,WAAW,SACrC,KAAC,sEAAuC,KAAK,QAAQ,GACrD;AACA,WAAK,SAAS,cAAU,4DAA6B,CAAC;AAAA,IACxD;AAEA,QAAI,QAAQ,iBAAiB,oBAAoB,OAAO;AACtD,WAAK,SAAS,aAAa;AAAA,QACzB,MAAM;AAAA,MACR,CAAC;AAAA,IACH;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,qBACJ,oBACA,eACY;AACZ,UAAM,uBACJ,oBAAoB,SAAS;AAE/B,QAAI;AAEJ,aAAS,WACP,aACA,cACA,OACM;AACN,qBAAe;AACf,UAAI,sBAAsB;AACxB,6BAAqB,aAAa,cAAc,KAAK;AAAA,MACvD;AAAA,IACF;AAEA,uBAAmB,UAAU;AAAA,MAC3B,GAAG,mBAAmB;AAAA,MACtB;AAAA,IACF;AAEA,UAAM,SAAY,MAAM,MAAM,qBAAqB,oBAAoB,aAAa;AAEpF,QAAI,cAAc;AAChB,aAAO,eAAe,QAAQ,aAAa;AAAA,QACzC,WAAO,kCAAiB,YAAY;AAAA,MACtC,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;",
  "names": []
}