UNPKG

@hocuspocus/common

Version:

shared code for multiple Hocuspocus packages

78 lines (77 loc) 3.15 kB
import type { IncomingMessage } from "http"; import type WebSocket from "ws"; import { DirectConnection } from "./DirectConnection.ts"; import Document from "./Document.ts"; import type { Server } from "./Server.ts"; import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from "./types.ts"; export declare const defaultConfiguration: { name: null; timeout: number; debounce: number; maxDebounce: number; quiet: boolean; yDocOptions: { gc: boolean; gcFilter: () => boolean; }; unloadImmediately: boolean; }; export declare class Hocuspocus { configuration: Configuration; loadingDocuments: Map<string, Promise<Document>>; documents: Map<string, Document>; server?: Server; debouncer: { debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any; isDebounced: (id: string) => boolean; executeNow: (id: string) => any; }; constructor(configuration?: Partial<Configuration>); /** * Configure Hocuspocus */ configure(configuration: Partial<Configuration>): Hocuspocus; /** * Get the total number of active documents */ getDocumentsCount(): number; /** * Get the total number of active connections */ getConnectionsCount(): number; /** * Force close one or more connections */ closeConnections(documentName?: string): void; /** * The `handleConnection` method receives incoming WebSocket connections, * runs all hooks: * * - onConnect for all connections * - onAuthenticate only if required * * … and if nothing fails it’ll fully establish the connection and * load the Document then. */ handleConnection(incoming: WebSocket, request: IncomingMessage, defaultContext?: any): void; /** * Handle update of the given document * * "connection" is not necessarily type "Connection", it's the Yjs "origin" (which is "Connection" if * the update is incoming from the provider, but can be anything if the updates is originated from an extension. */ private handleDocumentUpdate; /** * Create a new document by the given request */ createDocument(documentName: string, request: Partial<Pick<IncomingMessage, "headers" | "url">>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>; loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, "headers" | "url">>, socketId: string, connectionConfig: ConnectionConfiguration, context?: any): Promise<Document>; storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): any; /** * Run the given hook on all configured extensions. * Runs the given callback after each hook. */ hooks<T extends HookName>(name: T, payload: HookPayloadByName[T], callback?: Function | null): Promise<any>; unloadDocument(document: Document): Promise<any>; openDirectConnection(documentName: string, context?: any): Promise<DirectConnection>; }