import type { StoreRegistry } from '../config.js'; import type { Json, LwwFields } from '@interop/was-sync'; import type { LocalStore } from './localStore.js'; import { type SyncStatusStore } from './syncStatusStore.js'; import type { WasRemoteStore } from './wasRemoteStore.js'; export declare class StorageContext { #private; /** * The app's per-collection hydrate/patch handlers; the change patches and the * scheduled re-hydrates route on it. */ readonly registry: StoreRegistry; /** * This session's per-collection replication statuses. */ readonly syncStatus: SyncStatusStore; /** * @param options {object} * @param options.registry {StoreRegistry} * @param options.writerId {string} the resolved per-install writer id (see * `getWriterId`), the value every stamp of this session carries */ constructor({ registry, writerId }: { registry: StoreRegistry; writerId: string; }); /** * The writer id this session stamps with: an unkeyed, clearable attribution * label, never an identity. * * @returns {string} */ get writerId(): string; /** * Replaces the in-memory writer id with a fresh one (the clear-data wipe, * after `clearPersistedWriterId` removed the persisted one). The session * keeps running over its new anonymous replica and its write verbs still * have to stamp; nothing persists the new id, so the next run resolves and * stores an id of its own. * * @returns {string} the new id */ resetWriterId(): string; /** * Stamps a payload with fresh last-write-wins fields: the current instant as * `updatedAt` and this session's writer id. Any values the caller supplied * are overwritten -- a stamp must describe THIS write, or a hydrated doc's * older `updatedAt` would ride a later edit and lose the conflict. * * @param payload {object} * @returns {object} the payload with the LWW fields set */ stampLww(payload: T): T & LwwFields; /** * Installs the opened replica and makes this the process's active context * (the one the app-facing facades and the entity-store verbs resolve to). * Throws if ANOTHER context still has a replica attached: two live sessions * in one process would write into each other's entity stores. * * @param store {LocalStore} * @returns {void} */ attachStore(store: LocalStore): void; /** * Releases the replica (the caller closes or deletes it), cancels every * pending re-hydrate, and releases the process-wide active pointer when this * context holds it -- the mirror of {@link attachStore}'s claim. Anything * still in flight against the old replica sees the generation change and * ends as a no-op; the facades throw until the next attach claims a live * context, rather than resolving a retired one. * * @returns {LocalStore | null} the replica that was attached, if any */ detachStore(): LocalStore | null; /** * Whether a replica is attached. * * @returns {boolean} */ hasStore(): boolean; /** * The attached replica, or throws if none is open. * * @returns {LocalStore} */ requireStore(): LocalStore; /** * Runs `op` against the replica attached now and resolves with its result * only if that same replica is still attached when `op` settles. Resolves * `undefined` when no replica is attached, or when it was detached or * swapped meanwhile -- including when `op` rejected after the swap, since a * read torn by its own teardown is expected noise, not an error. A rejection * against a replica that is still attached propagates. * * @param op {(store: LocalStore) => Promise} * @returns {Promise} */ whileAttached(op: (store: LocalStore) => Promise): Promise; /** * Installs the connected session's delegated remote store (once background * sync has bootstrapped it from the granted zcaps). * * @param store {WasRemoteStore} * @returns {void} */ attachRemoteStore(store: WasRemoteStore): void; /** * Releases the remote store (logout / sync teardown). * * @returns {void} */ detachRemoteStore(): void; /** * Whether a connected session's remote store is available. * * @returns {boolean} */ hasRemoteStore(): boolean; /** * The connected session's remote store, or throws while no wallet-connected * session is active (local-only mode, or sync has not bootstrapped yet). * * @returns {WasRemoteStore} */ requireRemoteStore(): WasRemoteStore; /** * Hydrates every registered store from the attached replica. * * @returns {Promise} */ hydrateAll(): Promise; /** * Empties every registered store (logout). * * @returns {void} */ clearEntityStores(): void; /** * Patches ONE store from a single RxDB change event (per-doc, no * whole-collection re-hydrate): decrypt the changed envelope, then upsert the * payload (INSERT / UPDATE, including conflict-resolved rows) or drop it * (DELETE / tombstone). The `uuid -> envelopeId` index is kept in step so a * later local edit of a remotely-created doc still finds its envelope. Falls * back to a debounced whole-collection re-hydrate if the envelope is missing * or fails to decrypt. * * Fired floating off the RxDB change stream, so a logout/login teardown can * detach or swap the replica while the decrypt is in flight; the decrypt runs * under {@link StorageContext.whileAttached}, so an event that outlives its * replica is dropped rather than patched into the next session's stores. * * @param collectionKey {string} * @param event {object} an RxDB change event (operation + documentData) * @returns {Promise} */ patchFromChange(collectionKey: string, event: { operation: string; documentData?: { id: string; data?: Json; _deleted?: boolean; }; }): Promise; /** * Schedules a debounced re-hydrate of one collection's store after a pull. * A no-op without an attached replica, and the timer itself is bound to the * replica attached now: a detach cancels it, and one that still fires after * a swap finds the generation changed and does nothing. * * @param collectionKey {string} * @returns {void} */ scheduleRehydrate(collectionKey: string): void; } //# sourceMappingURL=storageContext.d.ts.map