import { type AutomergeUrl, type DocumentId } from '@automerge/automerge-repo'; import * as Effect from 'effect/Effect'; import * as SqlClient from 'effect/sql/SqlClient'; import type * as SqlError from 'effect/sql/SqlError'; import { Event } from '@dxos/async'; import { Context, Resource } from '@dxos/context'; import * as RuntimeProvider from '@dxos/effect/RuntimeProvider'; import { type SpaceId } from '@dxos/keys'; import { DatabaseRoot, type DatabaseRootSource } from './database-root.ts'; export type SpaceStateManagerProps = { runtime: RuntimeProvider.RuntimeProvider; }; export declare class SpaceStateManager extends Resource { private readonly _runtime; private readonly _roots; private readonly _rootBySpace; /** Keyed by space, not by root document: two spaces can share one root and must tear down apart. */ private readonly _perSpaceContext; private readonly _lastSpaceDocumentList; private readonly _spaceRootRefs; /** Re-runs a space's document-list check; the anchor documents enter the list only once refs exist. */ private readonly _documentListCheck; readonly spaceDocumentListUpdated: Event; constructor({ runtime }: SpaceStateManagerProps); /** * Applies any migrations this database has not recorded yet. */ readonly migrate: Effect.Effect; protected _open(ctx: Context): Promise; protected _close(ctx: Context): Promise; get roots(): ReadonlyMap; get spaceIds(): SpaceId[]; getRootByDocumentId(documentId: DocumentId): DatabaseRoot | undefined; /** Whether the document is the directory of a space this host stores, opened this session or not. */ isSpaceRootDocument(documentId: DocumentId): boolean; getSpaceRootDocumentId(spaceId: SpaceId): DocumentId | undefined; getRootBySpaceId(spaceId: SpaceId): DatabaseRoot | undefined; isBranchDocument(documentId: DocumentId): boolean; /** * References carried by the space root document, or undefined for a space that has none yet * (every space created before the root document existed). */ getSpaceRootRefs(spaceId: SpaceId): SpaceRootRefs | undefined; /** The root is immutable, so this is written once per space — at creation, or when a legacy space gains one. */ setSpaceRootRefs(spaceId: SpaceId, refs: SpaceRootRefs): Promise; /** * Get all persisted spaces. */ getPersistedSpaces(): Array<{ spaceId: SpaceId; rootDocUrl: AutomergeUrl; }>; /** * Remove a space from the persistent store and close its resources. */ removeSpace(spaceId: SpaceId): Promise; /** Whether any space still reads through this root document. */ private _isRootReferenced; /** Takes ownership of a lease in `source`: the root holds it until the space is removed or the manager closes. */ assignRootToSpace(spaceId: SpaceId, source: DatabaseRootSource): Promise; private _loadSpaces; private _saveSpace; private _saveSpaceRootRefs; private _deleteSpace; /** The directory JSON last stored for a space root, with the heads it was read at. */ readDirectorySnapshot(documentId: DocumentId): Promise; writeDirectorySnapshot(documentId: DocumentId, { heads, json }: DirectorySnapshotRow): Promise; } /** * The references a space root document carries, as persisted beside the space. The directory lives in * `root_doc_url` and is reached through {@link SpaceStateManager.getRootBySpaceId}. */ export type SpaceRootRefs = { spaceRootDocUrl: AutomergeUrl; credentialsDocUrl?: AutomergeUrl; }; /** A space directory's JSON and the heads it was read at; see `directoryJson` in `@dxos/echo-protocol`. */ export type DirectorySnapshotRow = { heads: readonly string[]; json: string; }; export declare class SpaceDocumentListUpdatedEvent { readonly spaceId: SpaceId; readonly spaceRootId: DocumentId; /** The directory `spaceRootId` replaced; set only on the first update after the swap. */ readonly previousRootId: DocumentId | undefined; readonly documentIds: DocumentId[]; constructor(spaceId: SpaceId, spaceRootId: DocumentId, /** The directory `spaceRootId` replaced; set only on the first update after the swap. */ previousRootId: DocumentId | undefined, documentIds: DocumentId[]); } //# sourceMappingURL=space-state-manager.d.ts.map