// // Copyright 2021 DXOS.org // import { type MulticastObservable, type CleanupFn } from '@dxos/async'; import { type SpecificCredential } from '@dxos/credentials'; import { type QueueFactory, type CoreDatabase, type EchoDatabase, type AnyLiveObject } from '@dxos/echo-db'; import { type PublicKey, type SpaceId } from '@dxos/keys'; import { type Contact, type CreateEpochRequest, type Invitation, type Space as SpaceData, type SpaceArchive, type SpaceMember, type SpaceState, type UpdateMemberRoleRequest, } from '@dxos/protocols/proto/dxos/client/services'; import { type EdgeReplicationSetting } from '@dxos/protocols/proto/dxos/echo/metadata'; import { type SpaceSnapshot } from '@dxos/protocols/proto/dxos/echo/snapshot'; import { type Credential, type Epoch } from '@dxos/protocols/proto/dxos/halo/credentials'; import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip'; import { type CancellableInvitation } from './invitations'; export type CreateEpochOptions = { migration?: CreateEpochRequest.Migration; automergeRootUrl?: string; }; export interface SpaceInternal { get data(): SpaceData; // TODO(dmaretskyi): Return epoch info. createEpoch(options?: CreateEpochOptions): Promise; getCredentials(): Promise; getEpochs(): Promise[]>; removeMember(memberKey: PublicKey): Promise; /** * Migrate space data to the latest version. */ migrate(): Promise; setEdgeReplicationPreference(setting: EdgeReplicationSetting): Promise; export(): Promise; } // TODO(burdon): Separate public API form implementation (move comments here). export interface Space { /** * Unique space identifier. */ get id(): SpaceId; /** * @deprecated Use `id`. */ get key(): PublicKey; /** * Echo database. */ get db(): EchoDatabase; /** * Access to queues. */ get queues(): QueueFactory; /** * Echo database CRUD API. * @deprecated Use the database api with the `plain` format. */ // TODO(burdon): Remove. get crud(): CoreDatabase; get isOpen(): boolean; /** * Properties object. */ get properties(): AnyLiveObject; /** * Current state of the space. * The database is ready to be used in `SpaceState.SPACE_READY` state. * Presence is available in `SpaceState.SPACE_CONTROL_ONLY` state. */ get state(): MulticastObservable; /** * Current state of space pipeline. */ get pipeline(): MulticastObservable; get invitations(): MulticastObservable; get members(): MulticastObservable; /** * @deprecated */ // TODO(wittjosiah): Remove. This should not be exposed. get internal(): SpaceInternal; // TODO(wittjosiah): Rename activate/deactivate? /** * Activates the space enabling the use of the database and starts replication with peers. * The setting is persisted on the local device. */ open(): Promise; /** * Deactivates the space stopping replication with other peers. * The space will not auto-open on the next app launch. * The setting is persisted on the local device. */ close(): Promise; /** * Waits until the space is in the ready state, with database initialized. */ waitUntilReady(): Promise; createSnapshot(): Promise; // TODO(burdon): Create invitation? share(options?: Partial): CancellableInvitation; admitContact(contact: Contact): Promise; updateMemberRole(request: Omit): Promise; // TODO(wittjosiah): Gather into messaging abstraction? postMessage: (channel: string, message: any) => Promise; listen: (channel: string, callback: (message: GossipMessage) => void) => CleanupFn; }