/** * @license * Copyright 2022-2026 Matter.js Authors * SPDX-License-Identifier: Apache-2.0 */ import { Datasource } from "#behavior/state/managed/Datasource.js"; import { StorageDriver, Transaction } from "@matter/general"; import { Val } from "@matter/protocol"; import { EndpointNumber } from "@matter/types"; import type { ClientCacheBuffer } from "./ClientCacheBuffer.js"; import type { LocalWriter } from "./LocalWriter.js"; import { RemoteWriteParticipant } from "./RemoteWriteParticipant.js"; import type { RemoteWriter } from "./RemoteWriter.js"; /** * The default implementation of {@link Datasource.ExternallyMutableStore}. * * This implements storage for attribute values for a single cluster loaded from peers. */ export declare class DatasourceCache implements Datasource.ExternallyMutableStore, RemoteWriteParticipant.Compensator { #private; initialValues?: Val.Struct; constructor(options: DatasourceCache.Options); get consumer(): Datasource.ExternallyMutableStore.Consumer | undefined; set consumer(consumer: Datasource.ExternallyMutableStore.Consumer | undefined); /** * Current values, preferring the live consumer over the seed snapshot, so cluster structure can rebuild from * up-to-date data while a behavior is active. */ get currentValues(): Val.Struct | undefined; set(transaction: Transaction, values: Val.Struct): Promise; /** * Restores local cache values whose remote write was declined. * * Only restores keys that: * - had a captured pre-write value (skip if the snapshot doesn't know the prior state), AND * - still hold the value we attempted to write (skip if a concurrent subscription update already moved on). */ compensate(failedAttributeIds: Set, previousValues: Val.Struct, writtenValues: Val.Struct): Promise; externalSet(values: Val.StructMap): Promise; /** * Reclaim {@link initialValues} from the active datasource so the cache can be detached. Blocks * {@link externalSet} until a new {@link consumer} is assigned, preventing writes to the released datasource. */ reclaimValues(): void; get version(): number; set version(_version: number); get erased(): boolean; /** * Disable this cache in memory without touching persisted storage. */ discard(): void; /** * Erase values just for this datasource. After this call, {@link externalSet} is permanently disabled. */ erase(): Promise; /** * Re-add keys that were cleared during a successful {@link flush} but whose transaction subsequently failed to * commit. Without this, a commit failure would silently lose buffered writes. */ restoreDirtyKeys(keys: Set): void; /** * Flush dirty values to storage. When {@link tx} is provided, writes go through the shared transaction. * * Returns the set of keys that were flushed, so the caller can restore them via {@link restoreDirtyKeys} if * the enclosing transaction fails to commit. */ flush(tx?: StorageDriver.Transaction): Promise | undefined>; } export declare namespace DatasourceCache { /** * Standard key for storing the version. * * This conveys the version to the {@link Datasource}. */ const VERSION_KEY = "__version__"; interface Options { writer: RemoteWriter; endpointNumber: EndpointNumber; behaviorId: string; initialValues?: Val.Struct; localWriter?: LocalWriter; buffer?: ClientCacheBuffer; } } //# sourceMappingURL=DatasourceCache.d.ts.map