src/types/ipc
IPC response type definitions and utilities for type-safe frontend-backend communication.
Remarksโ
This module provides TypeScript interfaces and utility functions that mirror the backend IpcResponse interface, ensuring type safety across the Electron IPC boundary. All standardized IPC handlers in the application return responses in the defined format.
The module includes:
- Standardized response format interface
- Type guards for runtime type checking
- Data extraction utilities with error handling
- Safe fallback mechanisms for failed operations
These utilities are essential for maintaining type safety when communicating between the renderer process (frontend) and main process (backend) in the Electron application.
Exampleโ
import { SiteService } from "../services/SiteService";
// Preferred: use the renderer service facade, which handles bridge readiness
// and validation internally.
const sites = await SiteService.getSites();
setSites(sites);
// Low-level example for preload authors wiring a new invoke channel.
// In the preload layer, handlers return `IpcResponse<T>` instances, which
// are validated and unwrapped by the typed bridge factory before reaching
// `window.electronAPI`.
// Avoid direct ipcRenderer usage in app code.
// Preload should use: createTypedInvoker(SITES_CHANNELS.getSites)
// Renderer should use: src/services/* wrappers.
if (isIpcResponse<Site[]>(rawResponse)) {
const sites = extractIpcData<Site[]>(rawResponse);
setSites(sites);
}
// Safe extraction with fallback when raw responses are unavoidable (e.g.
// diagnostics helpers that must operate on untyped IPC calls).
const sites = safeExtractIpcData(rawResponse, []);
Type Aliasesโ
- RendererIpcResponse
- IpcDiagnosticsChannel
- IpcDiagnosticsEvent
- IpcHandlerVerificationResult
- IpcInvokeChannel
- IpcInvokeChannelMap
- IpcInvokeChannelParams
- IpcInvokeChannelResult
- IpcValidationResponse
- PreloadGuardDiagnosticsReport
- SerializedDatabaseBackupMetadata
- SerializedDatabaseBackupResult
- SerializedDatabaseRestorePayload
- SerializedDatabaseRestoreResult