{"version":3,"file":"ota-client-DCsm3Lgb.mjs","names":[],"sources":["../src/ota/ota-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 {\n  OtaAssetsState,\n  OtaCheckResult,\n  OtaHistoryEntry,\n  OtaProgress,\n  OtaSource,\n  OtaStorageConfig,\n} from './ota-types.ts';\n\n/** Registered name (`helper::Ota::get_name()`). */\nexport const OTA_SERVICE_NAME = 'OTA';\n\n/** RPC function names (`helper::Ota::FunctionId`). */\nexport const OTA_FUNCTIONS = {\n  CheckUpdate: 'CheckUpdate',\n  StartUpdate: 'StartUpdate',\n  CancelUpdate: 'CancelUpdate',\n  GetState: 'GetState',\n  GetProgress: 'GetProgress',\n  GetHistory: 'GetHistory',\n  ConfirmPendingBoot: 'ConfirmPendingBoot',\n  GetAssetsState: 'GetAssetsState',\n  GetStorageConfig: 'GetStorageConfig',\n  SetStorageConfig: 'SetStorageConfig',\n  ResetFailure: 'ResetFailure',\n} as const;\n\nexport type OtaClientOptions = ServiceClientOptions;\n\nexport { type ServiceHandle as OtaHandle };\n\nexport function isOtaAvailable(options?: OtaClientOptions): boolean {\n  return isServiceAvailable(OTA_SERVICE_NAME, options);\n}\n\nexport function openOta(options?: OtaClientOptions): ServiceHandle {\n  return openService(OTA_SERVICE_NAME, options);\n}\n\nexport function closeOta(handle: ServiceHandle, options?: OtaClientOptions): void {\n  closeService(handle, options);\n}\n\nfunction callOta<T>(\n  handle: ServiceHandle,\n  functionName: string,\n  params: Record<string, unknown>,\n  options?: OtaClientOptions,\n): T {\n  return callServiceFunction<T>(resolveHost(options), handle, functionName, params);\n}\n\nexport function checkUpdate(\n  handle: ServiceHandle,\n  source: OtaSource,\n  options?: OtaClientOptions,\n): OtaCheckResult {\n  return callOta<OtaCheckResult>(handle, OTA_FUNCTIONS.CheckUpdate, { Source: source }, options);\n}\n\nexport function startUpdate(\n  handle: ServiceHandle,\n  source: OtaSource,\n  options?: OtaClientOptions,\n): OtaProgress {\n  return callOta<OtaProgress>(handle, OTA_FUNCTIONS.StartUpdate, { Source: source }, options);\n}\n\nexport function cancelUpdate(handle: ServiceHandle, options?: OtaClientOptions): void {\n  callOta<void>(handle, OTA_FUNCTIONS.CancelUpdate, {}, options);\n}\n\nexport function getOtaState(handle: ServiceHandle, options?: OtaClientOptions): OtaProgress {\n  return callOta<OtaProgress>(handle, OTA_FUNCTIONS.GetState, {}, options);\n}\n\nexport function getOtaProgress(handle: ServiceHandle, options?: OtaClientOptions): OtaProgress {\n  return callOta<OtaProgress>(handle, OTA_FUNCTIONS.GetProgress, {}, options);\n}\n\nexport function getOtaHistory(\n  handle: ServiceHandle,\n  options?: OtaClientOptions,\n): OtaHistoryEntry[] {\n  return callOta<OtaHistoryEntry[]>(handle, OTA_FUNCTIONS.GetHistory, {}, options);\n}\n\nexport function confirmPendingBoot(handle: ServiceHandle, options?: OtaClientOptions): void {\n  callOta<void>(handle, OTA_FUNCTIONS.ConfirmPendingBoot, {}, options);\n}\n\nexport function getAssetsState(handle: ServiceHandle, options?: OtaClientOptions): OtaAssetsState {\n  return callOta<OtaAssetsState>(handle, OTA_FUNCTIONS.GetAssetsState, {}, options);\n}\n\nexport function getStorageConfig(\n  handle: ServiceHandle,\n  options?: OtaClientOptions,\n): OtaStorageConfig {\n  return callOta<OtaStorageConfig>(handle, OTA_FUNCTIONS.GetStorageConfig, {}, options);\n}\n\nexport function setStorageConfig(\n  handle: ServiceHandle,\n  config: OtaStorageConfig,\n  options?: OtaClientOptions,\n): void {\n  callOta<void>(handle, OTA_FUNCTIONS.SetStorageConfig, { Config: config }, options);\n}\n\nexport function resetOtaFailure(handle: ServiceHandle, options?: OtaClientOptions): void {\n  callOta<void>(handle, OTA_FUNCTIONS.ResetF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