@hocuspocus/common 1.0.0-alpha.10
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.
- package/LICENSE.md +21 -0
- package/README.md +14 -0
- package/dist/hocuspocus-common.cjs +280 -0
- package/dist/hocuspocus-common.cjs.map +1 -0
- package/dist/hocuspocus-common.esm.js +268 -0
- package/dist/hocuspocus-common.esm.js.map +1 -0
- package/dist/packages/common/src/CloseEvents.d.ts +23 -0
- package/dist/packages/common/src/auth.d.ts +6 -0
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
- package/dist/packages/common/src/index.d.ts +4 -0
- package/dist/packages/common/src/types.d.ts +10 -0
- package/dist/packages/extension-database/src/Database.d.ts +32 -0
- package/dist/packages/extension-database/src/index.d.ts +1 -0
- package/dist/packages/extension-logger/src/Logger.d.ts +67 -0
- package/dist/packages/extension-logger/src/index.d.ts +1 -0
- package/dist/packages/extension-monitor/src/Collector.d.ts +60 -0
- package/dist/packages/extension-monitor/src/Dashboard.d.ts +29 -0
- package/dist/packages/extension-monitor/src/Storage.d.ts +35 -0
- package/dist/packages/extension-monitor/src/index.d.ts +38 -0
- package/dist/packages/extension-redis/src/Redis.d.ts +16 -0
- package/dist/packages/extension-redis/src/RedisCluster.d.ts +4 -0
- package/dist/packages/extension-redis/src/index.d.ts +2 -0
- package/dist/packages/extension-rocksdb/src/index.d.ts +22 -0
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
- package/dist/packages/extension-throttle/src/index.d.ts +24 -0
- package/dist/packages/extension-webhook/src/index.d.ts +58 -0
- package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +11 -0
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +156 -0
- package/dist/packages/provider/src/IncomingMessage.d.ts +14 -0
- package/dist/packages/provider/src/MessageReceiver.d.ts +13 -0
- package/dist/packages/provider/src/MessageSender.d.ts +10 -0
- package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -0
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -0
- package/dist/packages/provider/src/index.d.ts +3 -0
- package/dist/packages/provider/src/types.d.ts +77 -0
- package/dist/packages/server/src/Connection.d.ts +63 -0
- package/dist/packages/server/src/Debugger.d.ts +14 -0
- package/dist/packages/server/src/Document.d.ts +78 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +107 -0
- package/dist/packages/server/src/IncomingMessage.d.ts +19 -0
- package/dist/packages/server/src/MessageReceiver.d.ts +13 -0
- package/dist/packages/server/src/OutgoingMessage.d.ts +17 -0
- package/dist/packages/server/src/index.d.ts +9 -0
- package/dist/packages/server/src/types.d.ts +216 -0
- package/dist/packages/transformer/src/Prosemirror.d.ts +11 -0
- package/dist/packages/transformer/src/Tiptap.d.ts +10 -0
- package/dist/packages/transformer/src/index.d.ts +3 -0
- package/dist/packages/transformer/src/types.d.ts +5 -0
- package/dist/playground/backend/src/default.d.ts +1 -0
- package/dist/playground/backend/src/express.d.ts +1 -0
- package/dist/playground/backend/src/koa.d.ts +1 -0
- package/dist/playground/backend/src/load-document.d.ts +1 -0
- package/dist/playground/backend/src/monitor.d.ts +1 -0
- package/dist/playground/backend/src/redis.d.ts +1 -0
- package/dist/playground/backend/src/slow.d.ts +1 -0
- package/dist/playground/backend/src/webhook.d.ts +1 -0
- package/dist/tests/extension-logger/onListen.d.ts +1 -0
- package/dist/tests/extension-redis/onLoadDocument.d.ts +1 -0
- package/dist/tests/extension-redis/onSynced.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/closeConnections.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/getConnectionCount.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/getDocumentsCount.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onAwarenessChange.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onChange.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onStoreDocument.d.ts +1 -0
- package/dist/tests/extension-rocksdb/onLoadDocument.d.ts +1 -0
- package/dist/tests/extension-throttle/configuration.d.ts +1 -0
- package/dist/tests/provider/configuration.d.ts +1 -0
- package/dist/tests/provider/observe.d.ts +1 -0
- package/dist/tests/provider/observeDeep.d.ts +1 -0
- package/dist/tests/provider/onAuthenticated.d.ts +1 -0
- package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
- package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
- package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/provider/onClose.d.ts +1 -0
- package/dist/tests/provider/onConnect.d.ts +1 -0
- package/dist/tests/provider/onDisconnect.d.ts +1 -0
- package/dist/tests/provider/onMessage.d.ts +1 -0
- package/dist/tests/provider/onOpen.d.ts +1 -0
- package/dist/tests/provider/onSynced.d.ts +1 -0
- package/dist/tests/server/address.d.ts +1 -0
- package/dist/tests/server/afterStoreDocument.d.ts +1 -0
- package/dist/tests/server/closeConnections.d.ts +1 -0
- package/dist/tests/server/getConnectionsCount.d.ts +1 -0
- package/dist/tests/server/getDocumentName.d.ts +1 -0
- package/dist/tests/server/getDocumentsCount.d.ts +1 -0
- package/dist/tests/server/getMessageLogs.d.ts +1 -0
- package/dist/tests/server/listen.d.ts +1 -0
- package/dist/tests/server/onAuthenticate.d.ts +1 -0
- package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/server/onChange.d.ts +1 -0
- package/dist/tests/server/onConfigure.d.ts +1 -0
- package/dist/tests/server/onConnect.d.ts +1 -0
- package/dist/tests/server/onDestroy.d.ts +1 -0
- package/dist/tests/server/onDisconnect.d.ts +1 -0
- package/dist/tests/server/onListen.d.ts +1 -0
- package/dist/tests/server/onLoadDocument.d.ts +1 -0
- package/dist/tests/server/onRequest.d.ts +1 -0
- package/dist/tests/server/onStoreDocument.d.ts +1 -0
- package/dist/tests/server/onUpgrade.d.ts +1 -0
- package/dist/tests/server/requiresAuthentication.d.ts +1 -0
- package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
- package/dist/tests/utils/createDirectory.d.ts +1 -0
- package/dist/tests/utils/flushRedis.d.ts +1 -0
- package/dist/tests/utils/index.d.ts +7 -0
- package/dist/tests/utils/newHocuspocus.d.ts +2 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
- package/dist/tests/utils/removeDirectory.d.ts +1 -0
- package/dist/tests/utils/sleep.d.ts +1 -0
- package/package.json +31 -0
- package/src/CloseEvents.ts +39 -0
- package/src/auth.ts +40 -0
- package/src/awarenessStatesToArray.ts +8 -0
- package/src/index.ts +4 -0
- package/src/types.ts +10 -0
|
@@ -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 { CloseEvent } from '@hocuspocus/common';
|
|
6
|
+
import Document from './Document';
|
|
7
|
+
import { Debugger } from './Debugger';
|
|
8
|
+
export 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
|
+
logger: Debugger;
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*/
|
|
24
|
+
constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
|
|
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,78 @@
|
|
|
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 { Debugger } from './Debugger';
|
|
7
|
+
export declare class Document extends Doc {
|
|
8
|
+
awareness: Awareness;
|
|
9
|
+
callbacks: {
|
|
10
|
+
onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
|
|
11
|
+
};
|
|
12
|
+
connections: Map<WebSocket, {
|
|
13
|
+
clients: Set<any>;
|
|
14
|
+
connection: Connection;
|
|
15
|
+
}>;
|
|
16
|
+
name: string;
|
|
17
|
+
mux: mutex;
|
|
18
|
+
logger: Debugger;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor.
|
|
21
|
+
*/
|
|
22
|
+
constructor(name: string, logger: Debugger);
|
|
23
|
+
/**
|
|
24
|
+
* Check if the Document is empty
|
|
25
|
+
*/
|
|
26
|
+
isEmpty(fieldName: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Merge the given document(s) into this one
|
|
29
|
+
*/
|
|
30
|
+
merge(documents: Doc | Array<Doc>): Document;
|
|
31
|
+
/**
|
|
32
|
+
* Set a callback that will be triggered when the document is updated
|
|
33
|
+
*/
|
|
34
|
+
onUpdate(callback: (document: Document, connection: Connection, update: Uint8Array) => void): Document;
|
|
35
|
+
/**
|
|
36
|
+
* Register a connection and a set of clients on this document keyed by the
|
|
37
|
+
* underlying websocket connection
|
|
38
|
+
*/
|
|
39
|
+
addConnection(connection: Connection): Document;
|
|
40
|
+
/**
|
|
41
|
+
* Is the given connection registered on this document
|
|
42
|
+
*/
|
|
43
|
+
hasConnection(connection: Connection): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Remove the given connection from this document
|
|
46
|
+
*/
|
|
47
|
+
removeConnection(connection: Connection): Document;
|
|
48
|
+
/**
|
|
49
|
+
* Get the number of active connections for this document
|
|
50
|
+
*/
|
|
51
|
+
getConnectionsCount(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get an array of registered connections
|
|
54
|
+
*/
|
|
55
|
+
getConnections(): Array<Connection>;
|
|
56
|
+
/**
|
|
57
|
+
* Get the client ids for the given connection instance
|
|
58
|
+
*/
|
|
59
|
+
getClients(connectionInstance: WebSocket): Set<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Has the document awareness states
|
|
62
|
+
*/
|
|
63
|
+
hasAwarenessStates(): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Apply the given awareness update
|
|
66
|
+
*/
|
|
67
|
+
applyAwarenessUpdate(connection: Connection, update: Uint8Array): Document;
|
|
68
|
+
/**
|
|
69
|
+
* Handle an awareness update and sync changes to clients
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
72
|
+
private handleAwarenessUpdate;
|
|
73
|
+
/**
|
|
74
|
+
* Handle an updated document and sync changes to clients
|
|
75
|
+
*/
|
|
76
|
+
private handleUpdate;
|
|
77
|
+
}
|
|
78
|
+
export default Document;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
3
|
+
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
|
+
import { Configuration, Hook } from './types';
|
|
5
|
+
import Document from './Document';
|
|
6
|
+
import { Debugger } from './Debugger';
|
|
7
|
+
import { onListenPayload } from '.';
|
|
8
|
+
export declare const defaultConfiguration: {
|
|
9
|
+
name: null;
|
|
10
|
+
port: number;
|
|
11
|
+
timeout: number;
|
|
12
|
+
debounce: number;
|
|
13
|
+
maxDebounce: number;
|
|
14
|
+
quiet: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Hocuspocus Server
|
|
18
|
+
*/
|
|
19
|
+
export declare class Hocuspocus {
|
|
20
|
+
configuration: Configuration;
|
|
21
|
+
documents: Map<string, Document>;
|
|
22
|
+
httpServer?: HTTPServer;
|
|
23
|
+
webSocketServer?: WebSocketServer;
|
|
24
|
+
debugger: Debugger;
|
|
25
|
+
constructor(configuration?: Partial<Configuration>);
|
|
26
|
+
/**
|
|
27
|
+
* Configure the server
|
|
28
|
+
*/
|
|
29
|
+
configure(configuration: Partial<Configuration>): Hocuspocus;
|
|
30
|
+
get requiresAuthentication(): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Start the server
|
|
33
|
+
*/
|
|
34
|
+
listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<Hocuspocus>;
|
|
35
|
+
get address(): AddressInfo;
|
|
36
|
+
get URL(): string;
|
|
37
|
+
get webSocketURL(): string;
|
|
38
|
+
get httpURL(): string;
|
|
39
|
+
private showStartScreen;
|
|
40
|
+
/**
|
|
41
|
+
* Get the total number of active documents
|
|
42
|
+
*/
|
|
43
|
+
getDocumentsCount(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Get the total number of active connections
|
|
46
|
+
*/
|
|
47
|
+
getConnectionsCount(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Force close one or more connections
|
|
50
|
+
*/
|
|
51
|
+
closeConnections(documentName?: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Destroy the server
|
|
54
|
+
*/
|
|
55
|
+
destroy(): Promise<any>;
|
|
56
|
+
/**
|
|
57
|
+
* The `handleConnection` method receives incoming WebSocket connections,
|
|
58
|
+
* runs all hooks:
|
|
59
|
+
*
|
|
60
|
+
* - onConnect for all connections
|
|
61
|
+
* - onAuthenticate only if required
|
|
62
|
+
*
|
|
63
|
+
* … and if nothings fails it’ll fully establish the connection and
|
|
64
|
+
* load the Document then.
|
|
65
|
+
*/
|
|
66
|
+
handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
|
|
67
|
+
/**
|
|
68
|
+
* Handle update of the given document
|
|
69
|
+
*/
|
|
70
|
+
private handleDocumentUpdate;
|
|
71
|
+
timers: Map<string, {
|
|
72
|
+
timeout: NodeJS.Timeout;
|
|
73
|
+
start: number;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* debounce the given function, using the given identifier
|
|
77
|
+
*/
|
|
78
|
+
debounce(id: string, func: Function, immediately?: boolean): void;
|
|
79
|
+
/**
|
|
80
|
+
* Create a new document by the given request
|
|
81
|
+
*/
|
|
82
|
+
private createDocument;
|
|
83
|
+
/**
|
|
84
|
+
* Create a new connection by the given request and document
|
|
85
|
+
*/
|
|
86
|
+
private createConnection;
|
|
87
|
+
/**
|
|
88
|
+
* Run the given hook on all configured extensions.
|
|
89
|
+
* Runs the given callback after each hook.
|
|
90
|
+
*/
|
|
91
|
+
hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
|
|
92
|
+
/**
|
|
93
|
+
* Get parameters by the given request
|
|
94
|
+
*/
|
|
95
|
+
private static getParameters;
|
|
96
|
+
/**
|
|
97
|
+
* Get document name by the given request
|
|
98
|
+
*/
|
|
99
|
+
private getDocumentNameFromRequest;
|
|
100
|
+
enableDebugging(): void;
|
|
101
|
+
enableMessageLogging(): void;
|
|
102
|
+
disableLogging(): void;
|
|
103
|
+
disableDebugging(): void;
|
|
104
|
+
flushMessageLogs(): this;
|
|
105
|
+
getMessageLogs(): any[];
|
|
106
|
+
}
|
|
107
|
+
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,13 @@
|
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
2
|
+
import Connection from './Connection';
|
|
3
|
+
import { IncomingMessage } from './IncomingMessage';
|
|
4
|
+
import { Debugger } from './Debugger';
|
|
5
|
+
import Document from './Document';
|
|
6
|
+
export declare class MessageReceiver {
|
|
7
|
+
message: IncomingMessage;
|
|
8
|
+
logger: Debugger;
|
|
9
|
+
constructor(message: IncomingMessage, logger: Debugger);
|
|
10
|
+
apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
|
|
11
|
+
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): 0 | 1 | 2;
|
|
12
|
+
applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
writeQueryAwareness(): OutgoingMessage;
|
|
12
|
+
writeAuthenticated(): OutgoingMessage;
|
|
13
|
+
writePermissionDenied(reason: string): OutgoingMessage;
|
|
14
|
+
writeFirstSyncStepFor(document: Document): OutgoingMessage;
|
|
15
|
+
writeUpdate(update: Uint8Array): OutgoingMessage;
|
|
16
|
+
toUint8Array(): Uint8Array;
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './Hocuspocus';
|
|
2
|
+
export * from './Connection';
|
|
3
|
+
export * from './Document';
|
|
4
|
+
export * from './IncomingMessage';
|
|
5
|
+
export * from './OutgoingMessage';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './MessageReceiver';
|
|
8
|
+
export * from './Document';
|
|
9
|
+
export * from './Connection';
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { URLSearchParams } from 'url';
|
|
4
|
+
import { Socket } from 'net';
|
|
5
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
6
|
+
import Document from './Document';
|
|
7
|
+
import { Hocuspocus } from './Hocuspocus';
|
|
8
|
+
export declare enum MessageType {
|
|
9
|
+
Unknown = -1,
|
|
10
|
+
Sync = 0,
|
|
11
|
+
Awareness = 1,
|
|
12
|
+
Auth = 2,
|
|
13
|
+
QueryAwareness = 3
|
|
14
|
+
}
|
|
15
|
+
export interface AwarenessUpdate {
|
|
16
|
+
added: Array<any>;
|
|
17
|
+
updated: Array<any>;
|
|
18
|
+
removed: Array<any>;
|
|
19
|
+
}
|
|
20
|
+
export interface ConnectionConfiguration {
|
|
21
|
+
readOnly: boolean;
|
|
22
|
+
requiresAuthentication: boolean;
|
|
23
|
+
isAuthenticated: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface Extension {
|
|
26
|
+
priority?: number;
|
|
27
|
+
onConfigure?(data: onConfigurePayload): Promise<any>;
|
|
28
|
+
onListen?(data: onListenPayload): Promise<any>;
|
|
29
|
+
onUpgrade?(data: onUpgradePayload): Promise<any>;
|
|
30
|
+
onConnect?(data: onConnectPayload): Promise<any>;
|
|
31
|
+
connected?(data: connectedPayload): Promise<any>;
|
|
32
|
+
onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
35
|
+
*/
|
|
36
|
+
onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
37
|
+
onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
38
|
+
afterLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
39
|
+
onChange?(data: onChangePayload): Promise<any>;
|
|
40
|
+
onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;
|
|
41
|
+
afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>;
|
|
42
|
+
onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
|
|
43
|
+
onRequest?(data: onRequestPayload): Promise<any>;
|
|
44
|
+
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
45
|
+
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
46
|
+
}
|
|
47
|
+
export declare type Hook = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
50
|
+
*/
|
|
51
|
+
'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
52
|
+
export interface Configuration extends Extension {
|
|
53
|
+
/**
|
|
54
|
+
* A name for the instance, used for logging.
|
|
55
|
+
*/
|
|
56
|
+
name: string | null;
|
|
57
|
+
/**
|
|
58
|
+
* A list of hocuspocus extenions.
|
|
59
|
+
*/
|
|
60
|
+
extensions: Array<Extension>;
|
|
61
|
+
/**
|
|
62
|
+
* The port which the server listens on.
|
|
63
|
+
*/
|
|
64
|
+
port: number | null;
|
|
65
|
+
/**
|
|
66
|
+
* Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
|
|
67
|
+
*/
|
|
68
|
+
timeout: number;
|
|
69
|
+
/**
|
|
70
|
+
* Debounces the call of the `onStoreDocument` hook for the given amount of time in ms.
|
|
71
|
+
* Otherwise every single update would be persisted.
|
|
72
|
+
*/
|
|
73
|
+
debounce: number;
|
|
74
|
+
/**
|
|
75
|
+
* Makes sure to call `onStoreDocument` at least in the given amount of time (ms).
|
|
76
|
+
*/
|
|
77
|
+
maxDebounce: number;
|
|
78
|
+
/**
|
|
79
|
+
* By default, the servers show a start screen. If passed false, the server will start quietly.
|
|
80
|
+
*/
|
|
81
|
+
quiet: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Function which returns the (customized) document name based on the request
|
|
84
|
+
*/
|
|
85
|
+
getDocumentName?(data: getDocumentNamePayload): string | Promise<string>;
|
|
86
|
+
}
|
|
87
|
+
export interface getDocumentNamePayload {
|
|
88
|
+
documentName: string;
|
|
89
|
+
request: IncomingMessage;
|
|
90
|
+
requestParameters: URLSearchParams;
|
|
91
|
+
}
|
|
92
|
+
export interface onAuthenticatePayload {
|
|
93
|
+
documentName: string;
|
|
94
|
+
instance: Hocuspocus;
|
|
95
|
+
requestHeaders: IncomingHttpHeaders;
|
|
96
|
+
requestParameters: URLSearchParams;
|
|
97
|
+
socketId: string;
|
|
98
|
+
token: string;
|
|
99
|
+
connection: ConnectionConfiguration;
|
|
100
|
+
}
|
|
101
|
+
export interface onConnectPayload {
|
|
102
|
+
documentName: string;
|
|
103
|
+
instance: Hocuspocus;
|
|
104
|
+
request: IncomingMessage;
|
|
105
|
+
requestHeaders: IncomingHttpHeaders;
|
|
106
|
+
requestParameters: URLSearchParams;
|
|
107
|
+
socketId: string;
|
|
108
|
+
connection: ConnectionConfiguration;
|
|
109
|
+
}
|
|
110
|
+
export interface connectedPayload {
|
|
111
|
+
documentName: string;
|
|
112
|
+
instance: Hocuspocus;
|
|
113
|
+
request: IncomingMessage;
|
|
114
|
+
requestHeaders: IncomingHttpHeaders;
|
|
115
|
+
requestParameters: URLSearchParams;
|
|
116
|
+
socketId: string;
|
|
117
|
+
connection: ConnectionConfiguration;
|
|
118
|
+
}
|
|
119
|
+
export interface onLoadDocumentPayload {
|
|
120
|
+
context: any;
|
|
121
|
+
document: Document;
|
|
122
|
+
documentName: string;
|
|
123
|
+
instance: Hocuspocus;
|
|
124
|
+
requestHeaders: IncomingHttpHeaders;
|
|
125
|
+
requestParameters: URLSearchParams;
|
|
126
|
+
socketId: string;
|
|
127
|
+
connection: ConnectionConfiguration;
|
|
128
|
+
}
|
|
129
|
+
export interface afterLoadDocumentPayload {
|
|
130
|
+
context: any;
|
|
131
|
+
document: Document;
|
|
132
|
+
documentName: string;
|
|
133
|
+
instance: Hocuspocus;
|
|
134
|
+
requestHeaders: IncomingHttpHeaders;
|
|
135
|
+
requestParameters: URLSearchParams;
|
|
136
|
+
socketId: string;
|
|
137
|
+
connection: ConnectionConfiguration;
|
|
138
|
+
}
|
|
139
|
+
export interface onChangePayload {
|
|
140
|
+
clientsCount: number;
|
|
141
|
+
context: any;
|
|
142
|
+
document: Document;
|
|
143
|
+
documentName: string;
|
|
144
|
+
instance: Hocuspocus;
|
|
145
|
+
requestHeaders: IncomingHttpHeaders;
|
|
146
|
+
requestParameters: URLSearchParams;
|
|
147
|
+
update: Uint8Array;
|
|
148
|
+
socketId: string;
|
|
149
|
+
}
|
|
150
|
+
export interface onStoreDocumentPayload {
|
|
151
|
+
clientsCount: number;
|
|
152
|
+
context: any;
|
|
153
|
+
document: Document;
|
|
154
|
+
documentName: string;
|
|
155
|
+
instance: Hocuspocus;
|
|
156
|
+
requestHeaders: IncomingHttpHeaders;
|
|
157
|
+
requestParameters: URLSearchParams;
|
|
158
|
+
socketId: string;
|
|
159
|
+
}
|
|
160
|
+
export interface afterStoreDocumentPayload extends onStoreDocumentPayload {
|
|
161
|
+
}
|
|
162
|
+
export interface onAwarenessUpdatePayload {
|
|
163
|
+
clientsCount: number;
|
|
164
|
+
context: any;
|
|
165
|
+
document: Document;
|
|
166
|
+
documentName: string;
|
|
167
|
+
instance: Hocuspocus;
|
|
168
|
+
requestHeaders: IncomingHttpHeaders;
|
|
169
|
+
requestParameters: URLSearchParams;
|
|
170
|
+
update: Uint8Array;
|
|
171
|
+
socketId: string;
|
|
172
|
+
added: number[];
|
|
173
|
+
updated: number[];
|
|
174
|
+
removed: number[];
|
|
175
|
+
awareness: Awareness;
|
|
176
|
+
states: StatesArray;
|
|
177
|
+
}
|
|
178
|
+
export declare type StatesArray = {
|
|
179
|
+
clientId: number;
|
|
180
|
+
[key: string | number]: any;
|
|
181
|
+
}[];
|
|
182
|
+
export interface storePayload extends onStoreDocumentPayload {
|
|
183
|
+
state: Buffer;
|
|
184
|
+
}
|
|
185
|
+
export interface onDisconnectPayload {
|
|
186
|
+
clientsCount: number;
|
|
187
|
+
context: any;
|
|
188
|
+
document: Document;
|
|
189
|
+
documentName: string;
|
|
190
|
+
instance: Hocuspocus;
|
|
191
|
+
requestHeaders: IncomingHttpHeaders;
|
|
192
|
+
requestParameters: URLSearchParams;
|
|
193
|
+
socketId: string;
|
|
194
|
+
}
|
|
195
|
+
export interface onRequestPayload {
|
|
196
|
+
request: IncomingMessage;
|
|
197
|
+
response: ServerResponse;
|
|
198
|
+
instance: Hocuspocus;
|
|
199
|
+
}
|
|
200
|
+
export interface onUpgradePayload {
|
|
201
|
+
head: any;
|
|
202
|
+
request: IncomingMessage;
|
|
203
|
+
socket: Socket;
|
|
204
|
+
instance: Hocuspocus;
|
|
205
|
+
}
|
|
206
|
+
export interface onListenPayload {
|
|
207
|
+
port: number;
|
|
208
|
+
}
|
|
209
|
+
export interface onDestroyPayload {
|
|
210
|
+
instance: Hocuspocus;
|
|
211
|
+
}
|
|
212
|
+
export interface onConfigurePayload {
|
|
213
|
+
configuration: Configuration;
|
|
214
|
+
version: string;
|
|
215
|
+
instance: Hocuspocus;
|
|
216
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Doc } from 'yjs';
|
|
2
|
+
import { Schema } from 'prosemirror-model';
|
|
3
|
+
import { Transformer } from './types';
|
|
4
|
+
declare class Prosemirror implements Transformer {
|
|
5
|
+
defaultSchema: Schema;
|
|
6
|
+
schema(schema: Schema): Prosemirror;
|
|
7
|
+
fromYdoc(document: Doc, fieldName?: string | Array<string>): any;
|
|
8
|
+
toYdoc(document: any, fieldName?: string | Array<string>, schema?: Schema): Doc;
|
|
9
|
+
}
|
|
10
|
+
export declare const ProsemirrorTransformer: Prosemirror;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Doc } from 'yjs';
|
|
2
|
+
import { Extensions } from '@tiptap/core/dist/packages/core/src/types';
|
|
3
|
+
import { Transformer } from './types';
|
|
4
|
+
export declare class Tiptap implements Transformer {
|
|
5
|
+
defaultExtensions: Extensions;
|
|
6
|
+
extensions(extensions: Extensions): Tiptap;
|
|
7
|
+
fromYdoc(document: Doc, fieldName?: string | Array<string>): any;
|
|
8
|
+
toYdoc(document: any, fieldName?: string | Array<string>, extensions?: Extensions): Doc;
|
|
9
|
+
}
|
|
10
|
+
export declare const TiptapTransformer: Tiptap;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|