y-websocket-server.d.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. declare module 'y-websocket/bin/utils' {
  2. import type { IncomingMessage } from 'http';
  3. import type { WebSocket } from 'ws';
  4. import type { WebsocketProvider } from 'y-websocket';
  5. import * as Y from 'yjs';
  6. export class WSSharedDoc extends Y.Doc {
  7. name: string;
  8. conns: Map<WebSocket, Set<number>>;
  9. awareness: WebsocketProvider['awareness'];
  10. whenInitialized: Promise<void>;
  11. constructor(name: string);
  12. }
  13. export interface YWebsocketPersistence {
  14. bindState: (docName: string, ydoc: WSSharedDoc) => void;
  15. writeState: (docName: string, ydoc: WSSharedDoc) => Promise<void>;
  16. provider: unknown;
  17. }
  18. export function setPersistence(
  19. persistence: YWebsocketPersistence | null,
  20. ): void;
  21. export function getPersistence(): YWebsocketPersistence | null;
  22. export const docs: Map<string, WSSharedDoc>;
  23. export function getYDoc(docname: string, gc?: boolean): WSSharedDoc;
  24. export function setupWSConnection(
  25. conn: WebSocket,
  26. req: IncomingMessage,
  27. opts?: { docName?: string; gc?: boolean },
  28. ): void;
  29. export function setContentInitializor(
  30. f: (ydoc: Y.Doc) => Promise<void>,
  31. ): void;
  32. }