import type { ESPCDF } from "../store/index"; /** * Disk snapshot of the home tree (C3 of the caching design). * * What is saved is an allow-list of plain fields: group tree and membership, * node config, device and service params with their last value (so schedules, * scenes and the time zone restore with the tree), and connectivity as * "last seen". Never saved: `_raw`, `operations`, transports, fabric details. * * What is restored are real entities whose `operations` wait for the first * live sync and then forward to the live adaptor, so the first screen can paint * from disk and controls still work after a short wait. * * Follow-up (offline support): move local-control credentials (the service * param values of `esp.service.local_control`) to OS secure storage and let * restored operations route locally before the first live sync. */ export declare const SNAPSHOT_SCHEMA_VERSION = 1; export declare const SNAPSHOT_DEFAULT_KEY_PREFIX = "espcdf.snapshot"; export declare const SNAPSHOT_DEFAULT_LIVE_TIMEOUT_MS = 15000; export declare const SNAPSHOT_DEFAULT_PERSIST_DELAY_MS = 1500; export interface ESPCDFSnapshotParam { name: string; value?: unknown; properties?: string[]; dataType?: string; type?: string; bounds?: Record; uiType?: string; } export interface ESPCDFSnapshotDevice { name: string; displayName?: string; type?: string; attributes?: { name: string; value?: unknown; }[]; params: ESPCDFSnapshotParam[]; } export interface ESPCDFSnapshotService { name: string; type: string; params: ESPCDFSnapshotParam[]; } export interface ESPCDFSnapshotNode { identifier: string; id: string; type?: string; isPrimaryUser?: boolean; connectivityStatus?: { isConnected: boolean; lastConnectionTimestamp: number; }; nodeConfig?: { configVersion: string; attributes?: { name: string; value?: unknown; }[]; info?: Record; }; devices: ESPCDFSnapshotDevice[]; services: ESPCDFSnapshotService[]; metadata?: Record; tags?: string[]; role?: string; transportOrder?: string[]; isMatter?: boolean; nodeType?: string; } export interface ESPCDFSnapshotGroup { identifier: string; id: string; name: string; type?: string; parentId?: string; nodeIds: string[]; mutuallyExclusive?: boolean; isPrimaryUser?: boolean; accessType?: string; totalNodes?: number; description?: string; metadata?: Record; customData?: Record; isMatter?: boolean; fabricId?: string; subGroups: ESPCDFSnapshotGroup[]; } export interface ESPCDFSnapshot { version: number; savedAt: number; adaptorId: string; /** `userInfo.id` of the signed-in user at save time; also part of the storage key. */ userId: string; currentHomeId: string | null; groups: ESPCDFSnapshotGroup[]; nodes: ESPCDFSnapshotNode[]; } /** * Content identity of a snapshot: everything except `savedAt`. Two snapshots with * the same fingerprint hold the same tree, so the second write can be skipped. */ export declare function snapshotFingerprint(snapshot: ESPCDFSnapshot | null): string; /** Plain, allow-listed copy of the store, or `null` when there is nothing to save. */ export declare function buildSnapshot(store: ESPCDF, identity: { adaptorId: string; userId: string; }): ESPCDFSnapshot | null; /** * Operations for an entity restored from disk. Every call waits for the first * live sync (`whenLive`), then forwards to the live entity's operations. * Until then nothing is "unavailable": a tap during the first second simply * completes once the network answers. */ export declare function createDeferredOperations(resolveLive: () => T | undefined, whenLive: () => Promise, label: string): T; /** Rebuilds the stores from a snapshot. The caller validates the snapshot first. */ export declare function hydrateSnapshotIntoStore(store: ESPCDF, snapshot: ESPCDFSnapshot, liveTimeoutMs?: number): void; /** `true` when a parsed value is a usable snapshot for this adaptor and user. */ export declare function isSnapshotUsable(value: unknown, expected: { adaptorId: string; userId: string; maxAgeMs: number; schemaVersion: number; }): value is ESPCDFSnapshot;