{"version":3,"sources":["../src/client-observers.ts"],"sourcesContent":["/** Metadata shared by app-route and integration execution attempts. */\nexport type ClientRequestEvent = {\n  requestId: string;\n  method: string;\n  path: string;\n  attempt: number;\n  timestamp: number;\n};\n\nexport type ClientResponseEvent<TData = unknown> = ClientRequestEvent & {\n  response?: Response;\n  data?: TData;\n  error?: Error;\n  ok?: boolean;\n  status?: number;\n};\n\n/** Observers compose with per-call hooks; return values never replace the result. */\nexport type ClientLifecycleHooks<TData = unknown> = {\n  onRequest?: (event: ClientRequestEvent) => void;\n  onResponse?: (\n    data: TData | undefined,\n    error: Error | null,\n    event: ClientResponseEvent<TData>,\n  ) => void;\n  onError?: (error: Error) => void;\n};\n\nexport function notifyClientObserver(\n  observer: ((...args: any[]) => unknown) | undefined,\n  args: unknown[],\n  label = \"Client lifecycle\",\n): void {\n  if (!observer) return;\n  const report = (error: unknown) => {\n    const reportError = (\n      globalThis as typeof globalThis & { reportError?: (error: unknown) => void }\n    ).reportError;\n    if (typeof reportError === \"function\") {\n      try {\n        reportError.call(globalThis, error);\n        return;\n      } catch {\n        /* Try the console fallback. */\n      }\n    }\n    try {\n      console.error(`[Farm.js] ${label} callback failed:`, error);\n    } catch {\n      /* Reporting must not affect a call. */\n    }\n  };\n  try {\n    const result = observer(...args);\n    if (result && typeof (result as PromiseLike<unknown>).then === \"function\")\n      void Promise.resolve(result).catch(report);\n  } catch (error) {\n    report(error);\n  }\n}\n"],"mappings":";;;;;AA4BO,SAAS,qBACd,UACA,MACA,QAAQ,oBACF;AACN,MAAI,CAAC,SAAU;AACf,QAAM,SAAS,wBAAC,UAAmB;AACjC,UAAM,cACJ,WACA;AACF,QAAI,OAAO,gBAAgB,YAAY;AACrC,UAAI;AACF,oBAAY,KAAK,YAAY,KAAK;AAClC;AAAA,MACF,QAAQ;AAAA,MAER;AAAA,IACF;AACA,QAAI;AACF,cAAQ,MAAM,aAAa,KAAK,qBAAqB,KAAK;AAAA,IAC5D,QAAQ;AAAA,IAER;AAAA,EACF,GAjBe;AAkBf,MAAI;AACF,UAAM,SAAS,SAAS,GAAG,IAAI;AAC/B,QAAI,UAAU,OAAQ,OAAgC,SAAS;AAC7D,WAAK,QAAQ,QAAQ,MAAM,EAAE,MAAM,MAAM;AAAA,EAC7C,SAAS,OAAO;AACd,WAAO,KAAK;AAAA,EACd;AACF;AA/BgB;","names":[]}