UNPKG

@eweser/db

Version:
63 lines (62 loc) 2.43 kB
import type { CollectionKey, EweDocument, ServerRoom } from '@eweser/shared'; import type { YSweetProvider } from '@y-sweet/client'; import type { IndexeddbPersistence } from 'y-indexeddb'; import type { WebrtcProvider } from 'y-webrtc'; import type { RoomConnectionStatus, RoomEvents } from './events'; import { TypedEventEmitter } from './events'; import type { Database, YDoc } from '.'; import type { GetDocuments } from './utils/getDocuments'; import { RemoteLoadOptions } from './methods/connection/loadRoom'; export type NewRoomOptions<T extends EweDocument> = { db: Database; name: string; collectionKey: CollectionKey; id?: string; tokenExpiry?: string | null; ySweetUrl?: string | null; ySweetBaseUrl?: string | null; publicAccess?: 'private' | 'read' | 'write'; readAccess?: string[]; writeAccess?: string[]; adminAccess?: string[]; createdAt?: string | null; updatedAt?: string | null; _deleted?: boolean | null; _ttl?: string | null; indexedDbProvider?: IndexeddbPersistence | null; webRtcProvider?: WebrtcProvider | null; ySweetProvider?: YSweetProvider | null; ydoc?: YDoc<T> | null; }; export declare class Room<T extends EweDocument> extends TypedEventEmitter<RoomEvents<T>> implements ServerRoom { db: Database; name: string; collectionKey: CollectionKey; id: string; tokenExpiry: string | null; ySweetUrl: string | null; ySweetBaseUrl: string | null; publicAccess: 'private' | 'read' | 'write'; readAccess: string[]; writeAccess: string[]; adminAccess: string[]; createdAt: string | null; updatedAt: string | null; _deleted: boolean | null; _ttl: string | null; indexedDbProvider?: IndexeddbPersistence | null; webRtcProvider?: WebrtcProvider | null; ySweetProvider?: YSweetProvider | null; ydoc?: YDoc<T> | null; connectionRetries: number; connectionStatus: RoomConnectionStatus; connectAbortController?: AbortController; disconnect: () => void; getDocuments: () => GetDocuments<T>; load: (remoteLoadOptions?: RemoteLoadOptions) => Promise<Room<T>>; addingAwareness: boolean; /** disconnect and reconnect the existing ySweetProvider, this time with awareness on */ addAwareness: () => Promise<void>; constructor(options: NewRoomOptions<T>); } export declare function roomToServerRoom(room: Room<any>): ServerRoom;