wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
1
2
3
4
5
6
7
{
  "version": 3,
  "sources": ["../../src/getClient.ts"],
  "sourcesContent": ["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isKeyCredential, isTokenCredential } from \"@azure/core-auth\";\nimport type { PipelineOptions } from \"@azure/core-rest-pipeline\";\nimport { createDefaultPipeline } from \"./clientHelpers.js\";\nimport type { Client, ClientOptions, RequestParameters, StreamableMethod } from \"./common.js\";\nimport {\n  getClient as tspGetClient,\n  type ClientOptions as TspClientOptions,\n} from \"@typespec/ts-http-runtime\";\n\n/**\n * Function to wrap RequestParameters so that we get the legacy onResponse behavior in core-client-rest\n */\nfunction wrapRequestParameters(parameters: RequestParameters): RequestParameters {\n  if (parameters.onResponse) {\n    return {\n      ...parameters,\n      onResponse(rawResponse, error) {\n        parameters.onResponse?.(rawResponse, error, error);\n      },\n    };\n  }\n\n  return parameters;\n}\n\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param options - Client options\n */\nexport function getClient(endpoint: string, options?: ClientOptions): Client;\n/**\n * Creates a client with a default pipeline\n * @param endpoint - Base endpoint for the client\n * @param credentials - Credentials to authenticate the requests\n * @param options - Client options\n */\nexport function getClient(\n  endpoint: string,\n  credentials?: TokenCredential | KeyCredential,\n  options?: ClientOptions,\n): Client;\nexport function getClient(\n  endpoint: string,\n  credentialsOrPipelineOptions?: (TokenCredential | KeyCredential) | ClientOptions,\n  clientOptions: ClientOptions = {},\n): Client {\n  let credentials: TokenCredential | KeyCredential | undefined;\n  if (credentialsOrPipelineOptions) {\n    if (isCredential(credentialsOrPipelineOptions)) {\n      credentials = credentialsOrPipelineOptions;\n    } else {\n      clientOptions = credentialsOrPipelineOptions ?? {};\n    }\n  }\n  const pipeline =\n    clientOptions.pipeline ?? createDefaultPipeline(endpoint, credentials, clientOptions);\n\n  const tspClient = tspGetClient(endpoint, {\n    ...clientOptions,\n    pipeline,\n  } as TspClientOptions) as Client;\n\n  const client = (path: string, ...args: Array<any>) => {\n    return {\n      get: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).get(wrapRequestParameters(requestOptions));\n      },\n      post: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).post(wrapRequestParameters(requestOptions));\n      },\n      put: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).put(wrapRequestParameters(requestOptions));\n      },\n      patch: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).patch(wrapRequestParameters(requestOptions));\n      },\n      delete: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).delete(wrapRequestParameters(requestOptions));\n      },\n      head: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).head(wrapRequestParameters(requestOptions));\n      },\n      options: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).options(wrapRequestParameters(requestOptions));\n      },\n      trace: (requestOptions: RequestParameters = {}): StreamableMethod => {\n        return tspClient.path(path, ...args).trace(wrapRequestParameters(requestOptions));\n      },\n    };\n  };\n\n  return {\n    path: client,\n    pathUnchecked: client,\n    pipeline: tspClient.pipeline,\n  };\n}\n\nfunction isCredential(\n  param: (TokenCredential | KeyCredential) | PipelineOptions,\n): param is TokenCredential | KeyCredential {\n  return isKeyCredential(param) || isTokenCredential(param);\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAmD;AAEnD,2BAAsC;AAEtC,6BAGO;AAKP,SAAS,sBAAsB,YAAkD;AAC/E,MAAI,WAAW,YAAY;AACzB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,WAAW,aAAa,OAAO;AAC7B,mBAAW,aAAa,aAAa,OAAO,KAAK;AAAA,MACnD;AAAA,IACF;A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