{"version":3,"file":"http-client-DZIOGWs6.mjs","names":[],"sources":["../src/http/http-client.ts"],"sourcesContent":["/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\nimport {\n  callServiceFunction,\n  closeService,\n  isServiceAvailable,\n  openService,\n  resolveHost,\n  type ServiceClientOptions,\n  type ServiceHandle,\n} from '../common/service-rpc.ts';\nimport type { HttpRequest, HttpRequestStateInfo, HttpResponse } from './http-types.ts';\n\n/** Registered name (`helper::Http::get_name()`). */\nexport const HTTP_SERVICE_NAME = 'Http';\n\n/** RPC function names (`helper::Http::FunctionId`). */\nexport const HTTP_FUNCTIONS = {\n  Request: 'Request',\n  RequestAsync: 'RequestAsync',\n  CancelRequest: 'CancelRequest',\n  GetRequestState: 'GetRequestState',\n  ResetStatistics: 'ResetStatistics',\n} as const;\n\nexport type HttpClientOptions = ServiceClientOptions;\n\nexport { type ServiceHandle as HttpHandle };\n\nexport function isHttpAvailable(options?: HttpClientOptions): boolean {\n  return isServiceAvailable(HTTP_SERVICE_NAME, options);\n}\n\nexport function openHttp(options?: HttpClientOptions): ServiceHandle {\n  return openService(HTTP_SERVICE_NAME, options);\n}\n\nexport function closeHttp(handle: ServiceHandle, options?: HttpClientOptions): void {\n  closeService(handle, options);\n}\n\nfunction callHttp<T>(\n  handle: ServiceHandle,\n  functionName: string,\n  params: Record<string, unknown>,\n  options?: HttpClientOptions,\n): T {\n  return callServiceFunction<T>(resolveHost(options), handle, functionName, params);\n}\n\nexport function request(\n  handle: ServiceHandle,\n  req: HttpRequest,\n  options?: HttpClientOptions,\n): HttpResponse {\n  return callHttp<HttpResponse>(handle, HTTP_FUNCTIONS.Request, { Request: req }, options);\n}\n\nexport function requestAsync(\n  handle: ServiceHandle,\n  req: HttpRequest,\n  options?: HttpClientOptions,\n): number {\n  return callHttp<number>(handle, HTTP_FUNCTIONS.RequestAsync, { Request: req }, options);\n}\n\nexport function cancelRequest(\n  handle: ServiceHandle,\n  requestId: number,\n  options?: HttpClientOptions,\n): void {\n  callHttp<void>(handle, HTTP_FUNCTIONS.CancelRequest, { RequestId: requestId }, options);\n}\n\nexport function getRequestState(\n  handle: ServiceHandle,\n  requestId: number,\n  options?: HttpClientOptions,\n): HttpRequestStateInfo {\n  return callHttp<HttpRequestStateInfo>(\n    handle,\n    HTTP_FUNCTIONS.GetRequestState,\n    { RequestId: requestId },\n    options,\n  );\n}\n\nexport function resetHttpStatistics(handle: ServiceHandle, options?: HttpClientOptions): void {\n  callHttp<void>(handle, HTTP_FUNCTIONS.ResetStatistics, {}, options);\n}\n"],"mappings":";;;AAeA,MAAa,oBAAoB;;AAGjC,MAAa,iBAAiB;CAC5B,SAAS;CACT,cAAc;CACd,eAAe;CACf,iBAAiB;CACjB,iBAAiB;AACnB;AAMA,SAAgB,gBAAgB,SAAsC;CACpE,OAAO,mBAAmB,mBAAmB,OAAO;AACtD;AAEA,SAAgB,SAAS,SAA4C;CACnE,OAAO,YAAY,mBAAmB,OAAO;AAC/C;AAEA,SAAgB,UAAU,QAAuB,SAAmC;CAClF,aAAa,QAAQ,OAAO;AAC9B;AAEA,SAAS,SACP,QACA,cACA,QACA,SACG;CACH,OAAO,oBAAuB,YAAY,OAAO,GAAG,QAAQ,cAAc,MAAM;AAClF;AAEA,SAAgB,QACd,QACA,KACA,SACc;CACd,OAAO,SAAuB,QAAQ,eAAe,SAAS,EAAE,SAAS,IAAI,GAAG,OAAO;AACzF;AAEA,SAAgB,aACd,QACA,KACA,SACQ;CACR,OAAO,SAAiB,QAAQ,eAAe,cAAc,EAAE,SAAS,IAAI,GAAG,OAAO;AACxF;AAEA,SAAgB,cACd,QACA,WACA,SACM;CACN,SAAe,QAAQ,eAAe,eAAe,EAAE,WAAW,UAAU,GAAG,OAAO;AACxF;AAEA,SAAgB,gBACd,QACA,WACA,SACsB;CACtB,OAAO,SACL,QACA,eAAe,iBACf,EAAE,WAAW,UAAU,GACvB,OACF;AACF;AAEA,SAAgB,oBAAoB,QAAuB,SAAmC;CAC5F,SAAe,QAAQ,eAAe,iBAAiB,CAAC,GAAG,OAAO;AACpE"}