import { ConnectionClient } from './ConnectionClient'; import { Observable } from 'rxjs'; import { BranchInfoEvent, BranchesEvent, AddCommitsEvent, DevicesEvent, WatchBranchEvent, BranchesStatusEvent, CommitCreatedEvent, RestoredEvent, RateLimitExceededEvent } from './CausalRepoEvents'; import { Atom } from './Atom2'; import { DeviceAction, DeviceActionResult, DeviceActionError, RemoteActions } from '../core/Event'; import { DeviceInfo } from '../core/DeviceInfo'; import { TimeSample } from '@casual-simulation/timesync'; /** * Defines a client for a causal repo. */ export declare class CausalRepoClient { private _client; private _sentAtoms; private _sentUpdates; private _updateCounter; private _watchedBranches; private _connectedDevices; private _forcedOffline; private _timeSyncCounter; constructor(connection: ConnectionClient); /** * Gets the connection that this client is using. */ get connection(): ConnectionClient; /** * Gets whether the client is forcing the connection to be offline or not. */ get forcedOffline(): boolean; /** * Sets whether the client is forcing the connection to be offline or not. */ set forcedOffline(value: boolean); /** * Starts watching the given branch. * @param name The name of the branch to watch. */ watchBranchAtoms(nameOrEvent: string | WatchBranchEvent): Observable; /** * Starts watching the given branch. * @param name The name of the branch to watch. */ watchBranchUpdates(nameOrEvent: string | WatchBranchEvent): Observable; /** * Watches for rate limit exceeded events. */ watchRateLimitExceeded(): Observable; /** * Gets the atoms stored on the given branch. * @param name The name of the branch to get. */ getBranch(name: string): Observable[]>; /** * Gets the updates stored on the given branch. * @param name The name of the branch to get. */ getBranchUpdates(name: string): Observable<{ updates: string[]; timestamps?: number[]; }>; watchBranches(): Observable<{ readonly branch: string; readonly type: "repo/load_branch"; } | { readonly branch: string; readonly type: "repo/unload_branch"; }>; watchDevices(): Observable<{ readonly broadcast: boolean; readonly branch: WatchBranchEvent; readonly device: DeviceInfo; readonly type: "repo/device_connected_to_branch"; } | { readonly broadcast: boolean; readonly branch: string; readonly device: DeviceInfo; readonly type: "repo/device_disconnected_from_branch"; }>; /** * Watches for device connection/disconnection events on the given branch. * @param branch The branch to watch. */ watchBranchDevices(branch: string): Observable<{ readonly broadcast: boolean; readonly branch: WatchBranchEvent; readonly device: DeviceInfo; readonly type: "repo/device_connected_to_branch"; } | { readonly broadcast: boolean; readonly branch: string; readonly device: DeviceInfo; readonly type: "repo/device_disconnected_from_branch"; }>; private _disconnectDevices; private _watchConnectedDevices; /** * Gets the info for the given branch. * @param branch The branch. */ branchInfo(branch: string): Observable; /** * Requests a list of branches. */ branches(): Observable; /** * Requests that the given branch have its password changed. * @param branch The branch. * @param oldPassword The old password. * @param newPassword The new password. */ setBranchPassword(branch: string, oldPassword: string, newPassword: string): Observable; /** * Requests that the current session be able to write to the given branch. * @param branch The branch. * @param password The password. */ authenticateBranchWrites(branch: string, password: string): Observable; /** * Requests status information for the list of branches. */ branchesStatus(): Observable; /** * Requests a list of devices that are currently connected. * @param branch The branch that the devices should be retrieved from. */ devices(branch?: string): Observable; /** * Requests the number of devices that are currently connected. * @param branch The branch that the devices should be counted on. */ deviceCount(branch?: string): Observable; /** * Adds the given atoms to the given branch. * @param branch The name of the branch. * @param atoms The atoms to add. */ addAtoms(branch: string, atoms: Atom[], removedAtoms?: string[]): void; addUpdates(branch: string, updates: string[]): void; /** * Sends the given action to devices on the given branch. * @param branch The branch. * @param action The action. */ sendEvent(branch: string, action: RemoteActions): void; /** * Sends a commit event to the given branch. * @param branch The branch. * @param message The commit message. */ commit(branch: string, message: string): Observable; /** * Checks out the given hash for the given branch. * @param branch The branch to move. * @param hash The hash that the branch should checkout. */ checkout(branch: string, hash: string): void; restore(branch: string, hash: string): Observable; watchCommits(branch: string): Observable; /** * Sends a SyncTimeRequest to the server. */ sampleServerTime(): Promise; private _whenConnected; private _sendAddAtoms; private _sendAddUpdates; private _getSentAtoms; private _getSentUpdates; private _getConnectedDevices; private _isDeviceConnected; } export interface ClientAtoms { type: 'atoms'; atoms?: Atom[]; removedAtoms?: string[]; } export interface ClientResetAtoms { type: 'reset'; atoms: Atom[]; } export interface ClientUpdates { type: 'updates'; updates: string[]; } export interface ClientUpdatesReceived { type: 'updates_received'; } export interface ClientAtomsReceived { type: 'atoms_received'; } export interface ClientEvent { type: 'event'; action: DeviceAction | DeviceActionResult | DeviceActionError; } export interface BaseClientError { type: 'error'; errorCode: string; } export type ClientError = MaxInstSizeReachedClientError; export interface MaxInstSizeReachedClientError extends BaseClientError { errorCode: 'max_size_reached'; maxBranchSizeInBytes: number; neededBranchSizeInBytes: number; } export type ClientWatchBranchEvents = ClientAtoms | ClientAtomsReceived | ClientEvent | ClientResetAtoms; export type ClientWatchBranchUpdatesEvents = ClientUpdates | ClientUpdatesReceived | ClientEvent | ClientError; export type ClientAtomsOrEvent = ClientAtoms | ClientEvent | ClientResetAtoms; export type ClientUpdatesOrEvent = ClientUpdates | ClientEvent | ClientError; export declare function isClientAtoms(event: ClientWatchBranchEvents): event is ClientAtoms; export declare function isClientEvent(event: ClientWatchBranchEvents | ClientWatchBranchUpdatesEvents): event is ClientEvent; export declare function isClientAtomsOrEvents(event: ClientWatchBranchEvents): event is ClientAtomsOrEvent; export declare function isClientResetAtoms(event: ClientWatchBranchEvents): event is ClientResetAtoms; export declare function isClientUpdates(event: ClientWatchBranchUpdatesEvents): event is ClientUpdates; export declare function isClientUpdatesOrEvents(event: ClientWatchBranchUpdatesEvents): event is ClientUpdatesOrEvent; export declare function isClientError(event: ClientWatchBranchUpdatesEvents): event is ClientError; //# sourceMappingURL=CausalRepoClient.d.ts.map