@hocuspocus/common 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +14 -0
  3. package/dist/demos/backend/src/express.d.ts +1 -0
  4. package/dist/demos/backend/src/koa.d.ts +1 -0
  5. package/dist/demos/backend/src/load-document.d.ts +1 -0
  6. package/dist/demos/backend/src/minimal.d.ts +1 -0
  7. package/dist/demos/backend/src/monitor.d.ts +1 -0
  8. package/dist/demos/backend/src/redis.d.ts +1 -0
  9. package/dist/demos/backend/src/slow.d.ts +1 -0
  10. package/dist/demos/backend/src/webhook.d.ts +1 -0
  11. package/dist/hocuspocus-common.cjs +222 -0
  12. package/dist/hocuspocus-common.cjs.map +1 -0
  13. package/dist/hocuspocus-common.esm.js +215 -0
  14. package/dist/hocuspocus-common.esm.js.map +1 -0
  15. package/dist/packages/common/src/auth.d.ts +6 -0
  16. package/dist/packages/common/src/index.d.ts +1 -0
  17. package/dist/packages/extension-logger/src/Logger.d.ts +68 -0
  18. package/dist/packages/extension-logger/src/index.d.ts +1 -0
  19. package/dist/packages/extension-monitor/src/Collector.d.ts +62 -0
  20. package/dist/packages/extension-monitor/src/Dashboard.d.ts +29 -0
  21. package/dist/packages/extension-monitor/src/Storage.d.ts +35 -0
  22. package/dist/packages/extension-monitor/src/index.d.ts +38 -0
  23. package/dist/packages/extension-redis/src/Redis.d.ts +16 -0
  24. package/dist/packages/extension-redis/src/RedisCluster.d.ts +4 -0
  25. package/dist/packages/extension-redis/src/index.d.ts +2 -0
  26. package/dist/packages/extension-rocksdb/src/index.d.ts +22 -0
  27. package/dist/packages/extension-throttle/src/index.d.ts +20 -0
  28. package/dist/packages/extension-webhook/src/index.d.ts +59 -0
  29. package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
  30. package/dist/packages/provider/src/HocuspocusProvider.d.ts +158 -0
  31. package/dist/packages/provider/src/IncomingMessage.d.ts +14 -0
  32. package/dist/packages/provider/src/MessageReceiver.d.ts +13 -0
  33. package/dist/packages/provider/src/MessageSender.d.ts +10 -0
  34. package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
  35. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -0
  36. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -0
  37. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -0
  38. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -0
  39. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -0
  40. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -0
  41. package/dist/packages/provider/src/index.d.ts +3 -0
  42. package/dist/packages/provider/src/types.d.ts +34 -0
  43. package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +4 -0
  44. package/dist/packages/provider/src/utils/index.d.ts +1 -0
  45. package/dist/packages/server/src/CloseEvents.d.ts +4 -0
  46. package/dist/packages/server/src/Connection.d.ts +63 -0
  47. package/dist/packages/server/src/Debugger.d.ts +15 -0
  48. package/dist/packages/server/src/Document.d.ts +75 -0
  49. package/dist/packages/server/src/Hocuspocus.d.ts +86 -0
  50. package/dist/packages/server/src/IncomingMessage.d.ts +19 -0
  51. package/dist/packages/server/src/MessageReceiver.d.ts +10 -0
  52. package/dist/packages/server/src/OutgoingMessage.d.ts +16 -0
  53. package/dist/packages/server/src/index.d.ts +2 -0
  54. package/dist/packages/server/src/types.d.ts +146 -0
  55. package/dist/packages/transformer/src/Prosemirror.d.ts +11 -0
  56. package/dist/packages/transformer/src/Tiptap.d.ts +10 -0
  57. package/dist/packages/transformer/src/index.d.ts +3 -0
  58. package/dist/packages/transformer/src/types.d.ts +5 -0
  59. package/package.json +31 -0
  60. package/src/auth.ts +40 -0
  61. package/src/index.ts +1 -0
@@ -0,0 +1,158 @@
1
+ import * as Y from 'yjs';
2
+ import { Awareness } from 'y-protocols/awareness';
3
+ import * as mutex from 'lib0/mutex';
4
+ import { Event, CloseEvent, MessageEvent } from 'ws';
5
+ import EventEmitter from './EventEmitter';
6
+ import { OutgoingMessage } from './OutgoingMessage';
7
+ import { ConstructableOutgoingMessage } from './types';
8
+ export declare enum WebSocketStatus {
9
+ Connecting = "connecting",
10
+ Connected = "connected",
11
+ Disconnected = "disconnected"
12
+ }
13
+ export interface HocuspocusProviderOptions {
14
+ /**
15
+ * URL of your @hocuspocus/server instance
16
+ */
17
+ url: string;
18
+ /**
19
+ * The identifier/name of your document
20
+ */
21
+ name: string;
22
+ /**
23
+ * The actual Y.js document
24
+ */
25
+ document: Y.Doc;
26
+ /**
27
+ * Pass `false` to start the connection manually.
28
+ */
29
+ connect: boolean;
30
+ /**
31
+ * Pass false to disable broadcasting between browser tabs.
32
+ */
33
+ broadcast: boolean;
34
+ /**
35
+ * An Awareness instance to keep the presence state of all clients.
36
+ */
37
+ awareness: Awareness;
38
+ /**
39
+ * A token that’s sent to the backend for authentication purposes.
40
+ */
41
+ token: string | (() => string) | (() => Promise<string>) | null;
42
+ /**
43
+ * URL parameters that should be added.
44
+ */
45
+ parameters: {
46
+ [key: string]: any;
47
+ };
48
+ /**
49
+ * An optional WebSocket polyfill, for example for Node.js
50
+ */
51
+ WebSocketPolyfill: any;
52
+ /**
53
+ * Force syncing the document in the defined interval.
54
+ */
55
+ forceSyncInterval: false | number;
56
+ /**
57
+ * Disconnect when no message is received for the defined amount of milliseconds.
58
+ */
59
+ messageReconnectTimeout: number;
60
+ /**
61
+ * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
62
+ */
63
+ delay: number;
64
+ /**
65
+ * The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
66
+ */
67
+ initialDelay: number;
68
+ /**
69
+ * The factor option is used to grow the delay exponentially.
70
+ */
71
+ factor: number;
72
+ /**
73
+ * The maximum number of attempts or 0 if there is no limit on number of attempts.
74
+ */
75
+ maxAttempts: number;
76
+ /**
77
+ * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
78
+ */
79
+ minDelay: number;
80
+ /**
81
+ * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
82
+ */
83
+ maxDelay: number;
84
+ /**
85
+ * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
86
+ */
87
+ jitter: boolean;
88
+ /**
89
+ * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
90
+ */
91
+ timeout: number;
92
+ onAuthenticated: () => void;
93
+ onAuthenticationFailed: ({ reason }: {
94
+ reason: string;
95
+ }) => void;
96
+ onOpen: (event: Event) => void;
97
+ onConnect: () => void;
98
+ onMessage: (event: MessageEvent) => void;
99
+ onOutgoingMessage: (message: OutgoingMessage) => void;
100
+ onStatus: (status: any) => void;
101
+ onSynced: () => void;
102
+ onDisconnect: (event: CloseEvent) => void;
103
+ onClose: (event: CloseEvent) => void;
104
+ onDestroy: () => void;
105
+ onAwarenessUpdate: (states: any) => void;
106
+ onAwarenessChange: (states: any) => void;
107
+ }
108
+ export declare class HocuspocusProvider extends EventEmitter {
109
+ options: HocuspocusProviderOptions;
110
+ subscribedToBroadcastChannel: boolean;
111
+ webSocket: WebSocket | null;
112
+ shouldConnect: boolean;
113
+ status: WebSocketStatus;
114
+ isSynced: boolean;
115
+ isAuthenticated: boolean;
116
+ lastMessageReceived: number;
117
+ mux: mutex.mutex;
118
+ intervals: any;
119
+ connectionAttempt: {
120
+ resolve: (value?: any) => void;
121
+ reject: (reason?: any) => void;
122
+ } | null;
123
+ constructor(options?: Partial<HocuspocusProviderOptions>);
124
+ setOptions(options?: Partial<HocuspocusProviderOptions>): void;
125
+ connect(): Promise<void>;
126
+ createWebSocketConnection(): Promise<unknown>;
127
+ resolveConnectionAttempt(): void;
128
+ rejectConnectionAttempt(): void;
129
+ get document(): Y.Doc;
130
+ get awareness(): Awareness;
131
+ checkConnection(): void;
132
+ forceSync(): void;
133
+ registerBeforeUnloadEventListener(): void;
134
+ documentUpdateHandler(update: Uint8Array, origin: any): void;
135
+ awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
136
+ permissionDeniedHandler(reason: string): void;
137
+ authenticatedHandler(): void;
138
+ get serverUrl(): string;
139
+ get url(): string;
140
+ get synced(): boolean;
141
+ set synced(state: boolean);
142
+ get isAuthenticationRequired(): boolean;
143
+ disconnect(): void;
144
+ onOpen(event: Event): void;
145
+ getToken(): Promise<string | null>;
146
+ webSocketConnectionEstablished(): Promise<void>;
147
+ startSync(): void;
148
+ send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
149
+ onMessage(event: MessageEvent): void;
150
+ onClose(event: CloseEvent): void;
151
+ destroy(): void;
152
+ get broadcastChannel(): string;
153
+ broadcastChannelSubscriber(data: ArrayBuffer): void;
154
+ subscribeToBroadcastChannel(): void;
155
+ disconnectBroadcastChannel(): void;
156
+ broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
157
+ setAwarenessField(key: string, value: any): void;
158
+ }
@@ -0,0 +1,14 @@
1
+ import { Decoder } from 'lib0/decoding';
2
+ import { Encoder } from 'lib0/encoding';
3
+ import { MessageType } from './types';
4
+ export declare class IncomingMessage {
5
+ data: any;
6
+ encoder: Encoder;
7
+ decoder: Decoder;
8
+ constructor(data: any);
9
+ readVarUint(): MessageType;
10
+ readVarUint8Array(): Uint8Array;
11
+ writeVarUint(type: MessageType): void;
12
+ writeVarUint8Array(data: Uint8Array): void;
13
+ length(): number;
14
+ }
@@ -0,0 +1,13 @@
1
+ import { HocuspocusProvider } from './HocuspocusProvider';
2
+ import { IncomingMessage } from './IncomingMessage';
3
+ export declare class MessageReceiver {
4
+ message: IncomingMessage;
5
+ broadcasted: boolean;
6
+ constructor(message: IncomingMessage);
7
+ setBroadcasted(value: boolean): this;
8
+ apply(provider: HocuspocusProvider, emitSynced?: boolean): void;
9
+ private applySyncMessage;
10
+ private applyAwarenessMessage;
11
+ private applyAuthMessage;
12
+ private applyQueryAwarenessMessage;
13
+ }
@@ -0,0 +1,10 @@
1
+ import { Encoder } from 'lib0/encoding';
2
+ import { ConstructableOutgoingMessage } from './types';
3
+ export declare class MessageSender {
4
+ encoder: Encoder;
5
+ message: any;
6
+ constructor(Message: ConstructableOutgoingMessage, args?: any);
7
+ create(): Uint8Array;
8
+ send(webSocket: any): void;
9
+ broadcast(channel: string): void;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { Encoder } from 'lib0/encoding';
2
+ import { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types';
3
+ export declare class OutgoingMessage implements OutgoingMessageInterface {
4
+ encoder: Encoder;
5
+ type?: MessageType;
6
+ constructor();
7
+ get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
8
+ toUint8Array(): Uint8Array;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { MessageType, OutgoingMessageArguments } from '../types';
2
+ import { OutgoingMessage } from '../OutgoingMessage';
3
+ export declare class AuthenticationMessage extends OutgoingMessage {
4
+ type: MessageType;
5
+ description: string;
6
+ get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
7
+ }
@@ -0,0 +1,8 @@
1
+ import * as encoding from 'lib0/encoding';
2
+ import { MessageType, OutgoingMessageArguments } from '../types';
3
+ import { OutgoingMessage } from '../OutgoingMessage';
4
+ export declare class AwarenessMessage extends OutgoingMessage {
5
+ type: MessageType;
6
+ description: string;
7
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
8
+ }
@@ -0,0 +1,8 @@
1
+ import * as encoding from 'lib0/encoding';
2
+ import { MessageType, OutgoingMessageArguments } from '../types';
3
+ import { OutgoingMessage } from '../OutgoingMessage';
4
+ export declare class QueryAwarenessMessage extends OutgoingMessage {
5
+ type: MessageType;
6
+ description: string;
7
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
8
+ }
@@ -0,0 +1,8 @@
1
+ import * as encoding from 'lib0/encoding';
2
+ import { MessageType, OutgoingMessageArguments } from '../types';
3
+ import { OutgoingMessage } from '../OutgoingMessage';
4
+ export declare class SyncStepOneMessage extends OutgoingMessage {
5
+ type: MessageType;
6
+ description: string;
7
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
8
+ }
@@ -0,0 +1,8 @@
1
+ import * as encoding from 'lib0/encoding';
2
+ import { MessageType, OutgoingMessageArguments } from '../types';
3
+ import { OutgoingMessage } from '../OutgoingMessage';
4
+ export declare class SyncStepTwoMessage extends OutgoingMessage {
5
+ type: MessageType;
6
+ description: string;
7
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
8
+ }
@@ -0,0 +1,7 @@
1
+ import { MessageType, OutgoingMessageArguments } from '../types';
2
+ import { OutgoingMessage } from '../OutgoingMessage';
3
+ export declare class UpdateMessage extends OutgoingMessage {
4
+ type: MessageType;
5
+ description: string;
6
+ get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
7
+ }
@@ -0,0 +1,3 @@
1
+ export * from './HocuspocusProvider';
2
+ export * from './types';
3
+ export * from './utils';
@@ -0,0 +1,34 @@
1
+ import { Awareness } from 'y-protocols/awareness';
2
+ import * as Y from 'yjs';
3
+ import { Encoder } from 'lib0/encoding';
4
+ import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
5
+ import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
6
+ import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
7
+ import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
8
+ import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
9
+ import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
10
+ export declare enum MessageType {
11
+ Sync = 0,
12
+ Awareness = 1,
13
+ Auth = 2,
14
+ QueryAwareness = 3
15
+ }
16
+ export interface OutgoingMessageInterface {
17
+ encoder: Encoder;
18
+ type?: MessageType;
19
+ }
20
+ export interface OutgoingMessageArguments {
21
+ token: string;
22
+ document: Y.Doc;
23
+ awareness: Awareness;
24
+ clients: number[];
25
+ states: Map<number, {
26
+ [key: string]: any;
27
+ }>;
28
+ update: any;
29
+ encoder: Encoder;
30
+ }
31
+ export interface Constructable<T> {
32
+ new (...args: any): T;
33
+ }
34
+ export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
@@ -0,0 +1,4 @@
1
+ declare const _default: (states: Map<number, Record<string, any>>) => {
2
+ clientId: number;
3
+ }[];
4
+ export default _default;
@@ -0,0 +1 @@
1
+ export { default as awarenessStatesToArray } from './awarenessStatesToArray';
@@ -0,0 +1,4 @@
1
+ import { CloseEvent } from './types';
2
+ export declare const Forbidden: CloseEvent;
3
+ export declare const ResetConnection: CloseEvent;
4
+ export declare const CloseEvents: CloseEvent[];
@@ -0,0 +1,63 @@
1
+ /// <reference types="node" />
2
+ import AsyncLock from 'async-lock';
3
+ import WebSocket from 'ws';
4
+ import { IncomingMessage as HTTPIncomingMessage } from 'http';
5
+ import Document from './Document';
6
+ import { CloseEvent } from './types';
7
+ import { MessageLogger } from './Debugger';
8
+ declare class Connection {
9
+ webSocket: WebSocket;
10
+ context: any;
11
+ document: Document;
12
+ pingInterval: NodeJS.Timeout;
13
+ pongReceived: boolean;
14
+ request: HTTPIncomingMessage;
15
+ timeout: number;
16
+ callbacks: any;
17
+ socketId: string;
18
+ lock: AsyncLock;
19
+ readOnly: Boolean;
20
+ debugger: MessageLogger;
21
+ /**
22
+ * Constructor.
23
+ */
24
+ constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly?: boolean);
25
+ /**
26
+ * Set a callback that will be triggered when the connection is closed
27
+ */
28
+ onClose(callback: (document: Document) => void): Connection;
29
+ /**
30
+ * Send the given message
31
+ */
32
+ send(message: any): void;
33
+ /**
34
+ * Graceful wrapper around the WebSocket close method.
35
+ */
36
+ close(event?: CloseEvent): void;
37
+ /**
38
+ * Check if pong was received and close the connection otherwise
39
+ * @private
40
+ */
41
+ private check;
42
+ /**
43
+ * Send the current document awareness to the client, if any
44
+ * @private
45
+ */
46
+ private sendCurrentAwareness;
47
+ /**
48
+ * Handle an incoming message
49
+ * @private
50
+ */
51
+ private handleMessage;
52
+ /**
53
+ * Get the underlying connection instance
54
+ * @deprecated
55
+ */
56
+ get instance(): WebSocket;
57
+ /**
58
+ * Get the underlying connection instance
59
+ * @deprecated
60
+ */
61
+ get connection(): WebSocket;
62
+ }
63
+ export default Connection;
@@ -0,0 +1,15 @@
1
+ export declare class MessageLogger {
2
+ logs: any[];
3
+ listen: boolean;
4
+ output: boolean;
5
+ enable(): void;
6
+ disable(): void;
7
+ verbose(): void;
8
+ quiet(): void;
9
+ log(message: any): this;
10
+ flush(): this;
11
+ get(): {
12
+ logs: any[];
13
+ };
14
+ }
15
+ export declare const Debugger: MessageLogger;
@@ -0,0 +1,75 @@
1
+ import WebSocket from 'ws';
2
+ import { Awareness } from 'y-protocols/awareness';
3
+ import { Doc } from 'yjs';
4
+ import { mutex } from 'lib0/mutex.js';
5
+ import Connection from './Connection';
6
+ import { MessageLogger } from './Debugger';
7
+ declare class Document extends Doc {
8
+ awareness: Awareness;
9
+ callbacks: {
10
+ onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
11
+ };
12
+ connections: Map<any, any>;
13
+ name: string;
14
+ mux: mutex;
15
+ debugger: MessageLogger;
16
+ /**
17
+ * Constructor.
18
+ */
19
+ constructor(name: string);
20
+ /**
21
+ * Check if the Document is empty
22
+ */
23
+ isEmpty(fieldName: string): boolean;
24
+ /**
25
+ * Merge the given document(s) into this one
26
+ */
27
+ merge(documents: Doc | Array<Doc>): Document;
28
+ /**
29
+ * Set a callback that will be triggered when the document is updated
30
+ */
31
+ onUpdate(callback: (document: Document, connection: Connection, update: Uint8Array) => void): Document;
32
+ /**
33
+ * Register a connection and a set of clients on this document keyed by the
34
+ * underlying websocket connection
35
+ */
36
+ addConnection(connection: Connection): Document;
37
+ /**
38
+ * Is the given connection registered on this document
39
+ */
40
+ hasConnection(connection: Connection): boolean;
41
+ /**
42
+ * Remove the given connection from this document
43
+ */
44
+ removeConnection(connection: Connection): Document;
45
+ /**
46
+ * Get the number of active connections for this document
47
+ */
48
+ getConnectionsCount(): number;
49
+ /**
50
+ * Get an array of registered connections
51
+ */
52
+ getConnections(): Array<Connection>;
53
+ /**
54
+ * Get the client ids for the given connection instance
55
+ */
56
+ getClients(connectionInstance: WebSocket): Set<any>;
57
+ /**
58
+ * Has the document awareness states
59
+ */
60
+ hasAwarenessStates(): boolean;
61
+ /**
62
+ * Apply the given awareness update
63
+ */
64
+ applyAwarenessUpdate(connection: Connection, update: Uint8Array): Document;
65
+ /**
66
+ * Handle an awareness update and sync changes to clients
67
+ * @private
68
+ */
69
+ private handleAwarenessUpdate;
70
+ /**
71
+ * Handle an updated document and sync changes to clients
72
+ */
73
+ private handleUpdate;
74
+ }
75
+ export default Document;
@@ -0,0 +1,86 @@
1
+ /// <reference types="node" />
2
+ import WebSocket, { WebSocketServer } from 'ws';
3
+ import { IncomingMessage, Server as HTTPServer } from 'http';
4
+ import { Configuration, Hook } from './types';
5
+ import { MessageLogger } from './Debugger';
6
+ export declare const defaultConfiguration: {
7
+ name: null;
8
+ port: number;
9
+ timeout: number;
10
+ };
11
+ /**
12
+ * Hocuspocus server
13
+ */
14
+ export declare class Hocuspocus {
15
+ configuration: Configuration;
16
+ documents: Map<any, any>;
17
+ httpServer?: HTTPServer;
18
+ webSocketServer?: WebSocketServer;
19
+ debugger: MessageLogger;
20
+ /**
21
+ * Configure the server
22
+ */
23
+ configure(configuration: Partial<Configuration>): Hocuspocus;
24
+ get authenticationRequired(): boolean;
25
+ /**
26
+ * Start the server
27
+ */
28
+ listen(): Promise<void>;
29
+ /**
30
+ * Get the total number of active documents
31
+ */
32
+ getDocumentsCount(): number;
33
+ /**
34
+ * Get the total number of active connections
35
+ */
36
+ getConnectionsCount(): number;
37
+ /**
38
+ * Force close one or more connections
39
+ */
40
+ closeConnections(documentName?: string): void;
41
+ /**
42
+ * Destroy the server
43
+ */
44
+ destroy(): Promise<any>;
45
+ /**
46
+ * Handle the incoming WebSocket connection
47
+ */
48
+ handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
49
+ /**
50
+ * Handle update of the given document
51
+ * @private
52
+ */
53
+ private handleDocumentUpdate;
54
+ /**
55
+ * Create a new document by the given request
56
+ * @private
57
+ */
58
+ private createDocument;
59
+ /**
60
+ * Create a new connection by the given request and document
61
+ * @private
62
+ */
63
+ private createConnection;
64
+ /**
65
+ * Run the given hook on all configured extensions
66
+ * Runs the given callback after each hook
67
+ */
68
+ hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
69
+ /**
70
+ * Get parameters by the given request
71
+ * @private
72
+ */
73
+ private static getParameters;
74
+ /**
75
+ * Get document name by the given request
76
+ * @private
77
+ */
78
+ private static getDocumentName;
79
+ enableDebugging(): void;
80
+ enableMessageLogging(): void;
81
+ disableLogging(): void;
82
+ disableDebugging(): void;
83
+ flushMessageLogs(): this;
84
+ getMessageLogs(): any[];
85
+ }
86
+ export declare const Server: Hocuspocus;
@@ -0,0 +1,19 @@
1
+ import { Decoder } from 'lib0/decoding';
2
+ import { Encoder } from 'lib0/encoding';
3
+ import { MessageType } from './types';
4
+ export declare class IncomingMessage {
5
+ /**
6
+ * Access to the received message.
7
+ */
8
+ decoder: Decoder;
9
+ /**
10
+ * Access to the reply.
11
+ */
12
+ encoder: Encoder;
13
+ constructor(input: any);
14
+ readVarUint8Array(): Uint8Array;
15
+ readVarUint(): number;
16
+ toUint8Array(): Uint8Array;
17
+ writeVarUint(type: MessageType): void;
18
+ get length(): number;
19
+ }
@@ -0,0 +1,10 @@
1
+ import Connection from './Connection';
2
+ import { IncomingMessage } from './IncomingMessage';
3
+ import { MessageLogger } from './Debugger';
4
+ export declare class MessageReceiver {
5
+ message: IncomingMessage;
6
+ debugger: MessageLogger;
7
+ constructor(message: IncomingMessage);
8
+ apply(connection: Connection): void;
9
+ readSyncMessage(message: IncomingMessage, connection: Connection): 0 | 1 | 2;
10
+ }
@@ -0,0 +1,16 @@
1
+ import { Encoder } from 'lib0/encoding';
2
+ import { Awareness } from 'y-protocols/awareness';
3
+ import Document from './Document';
4
+ export declare class OutgoingMessage {
5
+ encoder: Encoder;
6
+ type?: number;
7
+ category?: string;
8
+ constructor();
9
+ createSyncMessage(): OutgoingMessage;
10
+ createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
11
+ writeAuthenticated(): OutgoingMessage;
12
+ writePermissionDenied(reason: string): OutgoingMessage;
13
+ writeFirstSyncStepFor(document: Document): OutgoingMessage;
14
+ writeUpdate(update: Uint8Array): OutgoingMessage;
15
+ toUint8Array(): Uint8Array;
16
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Hocuspocus';
2
+ export * from './types';