import { next as A } from '@automerge/automerge'; import { type AutomergeUrl, type DocumentId } from '@automerge/automerge-repo'; import { Event } from '@dxos/async'; import { DatabaseDirectory, type DirectoryJson, SpaceDocVersion } from '@dxos/echo-protocol'; import { type DocumentLease } from '../automerge/document-lease.ts'; import { type DocMetrics } from './automerge-metrics.ts'; /** A space directory's JSON and the stored heads it was read at; see `directoryJson` in `@dxos/echo-protocol`. */ export type DirectorySnapshot = { heads: A.Heads; json: DirectoryJson; }; export type DatabaseRootSource = { lease: DocumentLease; } | { documentId: DocumentId; snapshot: DirectorySnapshot; /** Leases the root's document once it is loaded. */ load: () => Promise>; /** Each save on the host; one for this root means the snapshot no longer shows it. */ headsChanged: Event<{ documentId: DocumentId; }>; }; export declare class DatabaseRoot implements Disposable { #private; static mapLinks(document: DocumentLease, mapping: Record): void; /** Emitted when the directory changes: each change of the loaded root, and the load that ends a snapshot. */ readonly changed: Event; /** * A root from a lease is loaded for as long as the space is open. A root from a snapshot is read from it without * loading, until something writes to the root or its stored heads move; then it loads and stays loaded. */ constructor(source: DatabaseRootSource); get documentId(): DocumentId; /** Derived from the id, so a root whose lease was released still reports which document it was. */ get url(): AutomergeUrl; /** Whether the root's Automerge document is loaded. */ get isLoaded(): boolean; /** Whether the root can be read: loaded, or shown from its snapshot. */ get isAvailable(): boolean; /** Loads the root's document if it was opened from a snapshot; writers await it before {@link change}. */ load(): Promise; /** * The `DocHandle` stays inside the lease — a caller holding one would read and write a document the * host had evicted, so the operations the root needs are proxied instead. */ change(callback: Parameters['change']>[0]): void; /** Releases the root document, which is the last thing keeping the space's directory resident. */ [Symbol.dispose](): void; /** The root's directory as it reads now: the loaded document, or the snapshot it was opened from. */ directory(): DatabaseDirectory | null; /** The heads {@link directory} is read at. */ heads(): A.Heads | null; /** The loaded Automerge document; null for a root shown from its snapshot. */ doc(): A.Doc | null; getVersion(): SpaceDocVersion | null; getSpaceKey(): string | null; /** @deprecated Inline directory objects are migrated into linked documents; this counts the ones left. */ getInlineObjectCount(): number | null; getLinkedObjectCount(): number | null; getAllLinkedDocuments(): AutomergeUrl[]; measureMetrics(): DocMetrics | null; } //# sourceMappingURL=database-root.d.ts.map