@hocuspocus/extension-sqlite 1.0.0-alpha.2 → 1.0.0-alpha.21
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/README.md +1 -1
- package/dist/hocuspocus-sqlite.cjs +29 -20
- package/dist/hocuspocus-sqlite.cjs.map +1 -1
- package/dist/hocuspocus-sqlite.esm.js +26 -20
- package/dist/hocuspocus-sqlite.esm.js.map +1 -1
- package/dist/packages/common/src/CloseEvents.d.ts +23 -0
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
- package/dist/packages/common/src/index.d.ts +3 -0
- package/dist/packages/common/src/types.d.ts +10 -0
- package/dist/packages/extension-database/src/Database.d.ts +5 -11
- package/dist/packages/extension-logger/src/Logger.d.ts +5 -0
- package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
- package/dist/packages/extension-monitor/src/index.d.ts +2 -2
- package/dist/packages/extension-redis/src/Redis.d.ts +91 -9
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +4 -4
- package/dist/packages/extension-throttle/src/index.d.ts +6 -2
- package/dist/packages/extension-webhook/src/index.d.ts +1 -2
- package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +4 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +30 -26
- package/dist/packages/provider/src/index.d.ts +0 -1
- package/dist/packages/provider/src/types.d.ts +43 -0
- package/dist/packages/server/src/Connection.d.ts +16 -5
- package/dist/packages/server/src/Debugger.d.ts +1 -2
- package/dist/packages/server/src/Document.d.ts +9 -5
- package/dist/packages/server/src/Hocuspocus.d.ts +37 -15
- package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
- package/dist/packages/server/src/OutgoingMessage.d.ts +2 -0
- package/dist/packages/server/src/index.d.ts +6 -0
- package/dist/packages/server/src/types.d.ts +127 -38
- package/dist/tests/extension-database/fetch.d.ts +1 -0
- package/dist/tests/extension-logger/onListen.d.ts +1 -0
- package/dist/tests/extension-redis/closeConnections.d.ts +1 -0
- package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -0
- package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -0
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -0
- package/dist/tests/extension-redis/onChange.d.ts +1 -0
- package/dist/tests/extension-redis/onStoreDocument.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/beforeHandleMessage.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/server/websocketError.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 +8 -0
- package/dist/tests/utils/newHocuspocus.d.ts +2 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
- package/dist/tests/utils/randomInteger.d.ts +1 -0
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
- package/dist/tests/utils/removeDirectory.d.ts +1 -0
- package/dist/tests/utils/retryableAssertion.d.ts +2 -0
- package/dist/tests/utils/sleep.d.ts +1 -0
- package/package.json +7 -7
- package/src/SQLite.ts +29 -21
- package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
- package/dist/packages/extension-rocksdb/src/index.d.ts +0 -22
- package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
- package/dist/packages/provider/src/utils/index.d.ts +0 -1
- package/dist/packages/server/src/CloseEvents.d.ts +0 -4
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import * as Y from 'yjs';
|
|
2
2
|
import { Awareness } from 'y-protocols/awareness';
|
|
3
3
|
import * as mutex from 'lib0/mutex';
|
|
4
|
-
import { Event, CloseEvent, MessageEvent } from 'ws';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
5
|
import EventEmitter from './EventEmitter';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
Connected = "connected",
|
|
11
|
-
Disconnected = "disconnected"
|
|
12
|
-
}
|
|
13
|
-
export interface HocuspocusProviderOptions {
|
|
6
|
+
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
7
|
+
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
8
|
+
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
|
|
9
|
+
export interface CompleteHocuspocusProviderConfiguration {
|
|
14
10
|
/**
|
|
15
11
|
* URL of your @hocuspocus/server instance
|
|
16
12
|
*/
|
|
@@ -90,28 +86,31 @@ export interface HocuspocusProviderOptions {
|
|
|
90
86
|
*/
|
|
91
87
|
timeout: number;
|
|
92
88
|
onAuthenticated: () => void;
|
|
93
|
-
onAuthenticationFailed: (
|
|
94
|
-
|
|
95
|
-
}) => void;
|
|
96
|
-
onOpen: (event: Event) => void;
|
|
89
|
+
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
90
|
+
onOpen: (data: onOpenParameters) => void;
|
|
97
91
|
onConnect: () => void;
|
|
98
|
-
onMessage: (
|
|
99
|
-
onOutgoingMessage: (
|
|
100
|
-
onStatus: (
|
|
101
|
-
onSynced: () => void;
|
|
102
|
-
onDisconnect: (
|
|
103
|
-
onClose: (
|
|
92
|
+
onMessage: (data: onMessageParameters) => void;
|
|
93
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
94
|
+
onStatus: (data: onStatusParameters) => void;
|
|
95
|
+
onSynced: (data: onSyncedParameters) => void;
|
|
96
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
97
|
+
onClose: (data: onCloseParameters) => void;
|
|
104
98
|
onDestroy: () => void;
|
|
105
|
-
onAwarenessUpdate: (
|
|
106
|
-
onAwarenessChange: (
|
|
99
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
100
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Don’t output any warnings.
|
|
103
|
+
*/
|
|
104
|
+
quiet: boolean;
|
|
107
105
|
}
|
|
108
106
|
export declare class HocuspocusProvider extends EventEmitter {
|
|
109
|
-
|
|
107
|
+
configuration: CompleteHocuspocusProviderConfiguration;
|
|
110
108
|
subscribedToBroadcastChannel: boolean;
|
|
111
109
|
webSocket: WebSocket | null;
|
|
112
110
|
shouldConnect: boolean;
|
|
113
111
|
status: WebSocketStatus;
|
|
114
112
|
isSynced: boolean;
|
|
113
|
+
unsyncedChanges: number;
|
|
115
114
|
isAuthenticated: boolean;
|
|
116
115
|
lastMessageReceived: number;
|
|
117
116
|
mux: mutex.mutex;
|
|
@@ -120,16 +119,21 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
120
119
|
resolve: (value?: any) => void;
|
|
121
120
|
reject: (reason?: any) => void;
|
|
122
121
|
} | null;
|
|
123
|
-
constructor(
|
|
124
|
-
|
|
122
|
+
constructor(configuration: HocuspocusProviderConfiguration);
|
|
123
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
124
|
+
boundConnect: () => Promise<void>;
|
|
125
125
|
connect(): Promise<void>;
|
|
126
126
|
createWebSocketConnection(): Promise<unknown>;
|
|
127
127
|
resolveConnectionAttempt(): void;
|
|
128
|
+
stopConnectionAttempt(): void;
|
|
128
129
|
rejectConnectionAttempt(): void;
|
|
129
130
|
get document(): Y.Doc;
|
|
130
131
|
get awareness(): Awareness;
|
|
132
|
+
get hasUnsyncedChanges(): boolean;
|
|
131
133
|
checkConnection(): void;
|
|
132
134
|
forceSync(): void;
|
|
135
|
+
boundBeforeUnload: () => void;
|
|
136
|
+
beforeUnload(): void;
|
|
133
137
|
registerEventListeners(): void;
|
|
134
138
|
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
135
139
|
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
@@ -141,15 +145,15 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
141
145
|
set synced(state: boolean);
|
|
142
146
|
get isAuthenticationRequired(): boolean;
|
|
143
147
|
disconnect(): void;
|
|
144
|
-
onOpen(event: Event): void
|
|
148
|
+
onOpen(event: Event): Promise<void>;
|
|
145
149
|
getToken(): Promise<string | null>;
|
|
146
|
-
webSocketConnectionEstablished(): Promise<void>;
|
|
147
150
|
startSync(): void;
|
|
148
151
|
send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
|
|
149
152
|
onMessage(event: MessageEvent): void;
|
|
150
153
|
onClose(event: CloseEvent): void;
|
|
151
154
|
destroy(): void;
|
|
152
155
|
get broadcastChannel(): string;
|
|
156
|
+
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
153
157
|
broadcastChannelSubscriber(data: ArrayBuffer): void;
|
|
154
158
|
subscribeToBroadcastChannel(): void;
|
|
155
159
|
disconnectBroadcastChannel(): void;
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { Awareness } from 'y-protocols/awareness';
|
|
2
2
|
import * as Y from 'yjs';
|
|
3
3
|
import { Encoder } from 'lib0/encoding';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
4
5
|
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
|
|
5
6
|
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
|
|
6
7
|
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
|
|
7
8
|
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
|
|
8
9
|
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
|
|
9
10
|
import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
|
|
11
|
+
import { IncomingMessage } from './IncomingMessage';
|
|
12
|
+
import { OutgoingMessage } from './OutgoingMessage';
|
|
10
13
|
export declare enum MessageType {
|
|
11
14
|
Sync = 0,
|
|
12
15
|
Awareness = 1,
|
|
13
16
|
Auth = 2,
|
|
14
17
|
QueryAwareness = 3
|
|
15
18
|
}
|
|
19
|
+
export declare enum WebSocketStatus {
|
|
20
|
+
Connecting = "connecting",
|
|
21
|
+
Connected = "connected",
|
|
22
|
+
Disconnected = "disconnected"
|
|
23
|
+
}
|
|
16
24
|
export interface OutgoingMessageInterface {
|
|
17
25
|
encoder: Encoder;
|
|
18
26
|
type?: MessageType;
|
|
@@ -32,3 +40,38 @@ export interface Constructable<T> {
|
|
|
32
40
|
new (...args: any): T;
|
|
33
41
|
}
|
|
34
42
|
export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
43
|
+
export declare type onAuthenticationFailedParameters = {
|
|
44
|
+
reason: string;
|
|
45
|
+
};
|
|
46
|
+
export declare type onOpenParameters = {
|
|
47
|
+
event: Event;
|
|
48
|
+
};
|
|
49
|
+
export declare type onMessageParameters = {
|
|
50
|
+
event: MessageEvent;
|
|
51
|
+
message: IncomingMessage;
|
|
52
|
+
};
|
|
53
|
+
export declare type onOutgoingMessageParameters = {
|
|
54
|
+
message: OutgoingMessage;
|
|
55
|
+
};
|
|
56
|
+
export declare type onStatusParameters = {
|
|
57
|
+
status: WebSocketStatus;
|
|
58
|
+
};
|
|
59
|
+
export declare type onSyncedParameters = {
|
|
60
|
+
state: boolean;
|
|
61
|
+
};
|
|
62
|
+
export declare type onDisconnectParameters = {
|
|
63
|
+
event: CloseEvent;
|
|
64
|
+
};
|
|
65
|
+
export declare type onCloseParameters = {
|
|
66
|
+
event: CloseEvent;
|
|
67
|
+
};
|
|
68
|
+
export declare type onAwarenessUpdateParameters = {
|
|
69
|
+
states: StatesArray;
|
|
70
|
+
};
|
|
71
|
+
export declare type onAwarenessChangeParameters = {
|
|
72
|
+
states: StatesArray;
|
|
73
|
+
};
|
|
74
|
+
export declare type StatesArray = {
|
|
75
|
+
clientId: number;
|
|
76
|
+
[key: string | number]: any;
|
|
77
|
+
}[];
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import AsyncLock from 'async-lock';
|
|
3
3
|
import WebSocket from 'ws';
|
|
4
4
|
import { IncomingMessage as HTTPIncomingMessage } from 'http';
|
|
5
|
+
import { CloseEvent } from '@hocuspocus/common';
|
|
5
6
|
import Document from './Document';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
declare class Connection {
|
|
7
|
+
import { Debugger } from './Debugger';
|
|
8
|
+
export declare class Connection {
|
|
9
9
|
webSocket: WebSocket;
|
|
10
10
|
context: any;
|
|
11
11
|
document: Document;
|
|
@@ -17,15 +17,19 @@ declare class Connection {
|
|
|
17
17
|
socketId: string;
|
|
18
18
|
lock: AsyncLock;
|
|
19
19
|
readOnly: Boolean;
|
|
20
|
-
|
|
20
|
+
logger: Debugger;
|
|
21
21
|
/**
|
|
22
22
|
* Constructor.
|
|
23
23
|
*/
|
|
24
|
-
constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly
|
|
24
|
+
constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
|
|
25
25
|
/**
|
|
26
26
|
* Set a callback that will be triggered when the connection is closed
|
|
27
27
|
*/
|
|
28
28
|
onClose(callback: (document: Document) => void): Connection;
|
|
29
|
+
/**
|
|
30
|
+
* Set a callback that will be triggered before an message is handled
|
|
31
|
+
*/
|
|
32
|
+
beforeHandleMessage(callback: (payload: Document, update: Uint8Array) => Promise<any>): Connection;
|
|
29
33
|
/**
|
|
30
34
|
* Send the given message
|
|
31
35
|
*/
|
|
@@ -49,6 +53,13 @@ declare class Connection {
|
|
|
49
53
|
* @private
|
|
50
54
|
*/
|
|
51
55
|
private handleMessage;
|
|
56
|
+
/**
|
|
57
|
+
* Handle a ws instance error, which is required to prevent
|
|
58
|
+
* the server from crashing when one happens
|
|
59
|
+
* See https://github.com/websockets/ws/issues/1777#issuecomment-660803472
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
private handleError;
|
|
52
63
|
/**
|
|
53
64
|
* Get the underlying connection instance
|
|
54
65
|
* @deprecated
|
|
@@ -3,20 +3,24 @@ import { Awareness } from 'y-protocols/awareness';
|
|
|
3
3
|
import { Doc } from 'yjs';
|
|
4
4
|
import { mutex } from 'lib0/mutex.js';
|
|
5
5
|
import Connection from './Connection';
|
|
6
|
-
import {
|
|
7
|
-
declare class Document extends Doc {
|
|
6
|
+
import { Debugger } from './Debugger';
|
|
7
|
+
export declare class Document extends Doc {
|
|
8
8
|
awareness: Awareness;
|
|
9
9
|
callbacks: {
|
|
10
10
|
onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
|
|
11
11
|
};
|
|
12
|
-
connections: Map<
|
|
12
|
+
connections: Map<WebSocket, {
|
|
13
|
+
clients: Set<any>;
|
|
14
|
+
connection: Connection;
|
|
15
|
+
}>;
|
|
13
16
|
name: string;
|
|
14
17
|
mux: mutex;
|
|
15
|
-
|
|
18
|
+
logger: Debugger;
|
|
19
|
+
isLoading: boolean;
|
|
16
20
|
/**
|
|
17
21
|
* Constructor.
|
|
18
22
|
*/
|
|
19
|
-
constructor(name: string);
|
|
23
|
+
constructor(name: string, logger: Debugger, yDocOptions: {});
|
|
20
24
|
/**
|
|
21
25
|
* Check if the Document is empty
|
|
22
26
|
*/
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import WebSocket, { WebSocketServer } from 'ws';
|
|
2
|
+
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
3
3
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
|
-
import { Configuration,
|
|
5
|
-
import
|
|
4
|
+
import { Configuration, HookName, HookPayload } from './types';
|
|
5
|
+
import Document from './Document';
|
|
6
|
+
import { Debugger } from './Debugger';
|
|
6
7
|
import { onListenPayload } from '.';
|
|
7
8
|
export declare const defaultConfiguration: {
|
|
8
9
|
name: null;
|
|
9
10
|
port: number;
|
|
10
11
|
timeout: number;
|
|
12
|
+
debounce: number;
|
|
13
|
+
maxDebounce: number;
|
|
11
14
|
quiet: boolean;
|
|
15
|
+
yDocOptions: {
|
|
16
|
+
gc: boolean;
|
|
17
|
+
gcFilter: () => boolean;
|
|
18
|
+
};
|
|
12
19
|
};
|
|
13
20
|
/**
|
|
14
21
|
* Hocuspocus Server
|
|
15
22
|
*/
|
|
16
23
|
export declare class Hocuspocus {
|
|
17
24
|
configuration: Configuration;
|
|
18
|
-
documents: Map<
|
|
25
|
+
documents: Map<string, Document>;
|
|
19
26
|
httpServer?: HTTPServer;
|
|
20
27
|
webSocketServer?: WebSocketServer;
|
|
21
|
-
debugger:
|
|
28
|
+
debugger: Debugger;
|
|
29
|
+
constructor(configuration?: Partial<Configuration>);
|
|
22
30
|
/**
|
|
23
31
|
* Configure the server
|
|
24
32
|
*/
|
|
@@ -27,7 +35,11 @@ export declare class Hocuspocus {
|
|
|
27
35
|
/**
|
|
28
36
|
* Start the server
|
|
29
37
|
*/
|
|
30
|
-
listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<
|
|
38
|
+
listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<Hocuspocus>;
|
|
39
|
+
get address(): AddressInfo;
|
|
40
|
+
get URL(): string;
|
|
41
|
+
get webSocketURL(): string;
|
|
42
|
+
get httpURL(): string;
|
|
31
43
|
private showStartScreen;
|
|
32
44
|
/**
|
|
33
45
|
* Get the total number of active documents
|
|
@@ -46,37 +58,47 @@ export declare class Hocuspocus {
|
|
|
46
58
|
*/
|
|
47
59
|
destroy(): Promise<any>;
|
|
48
60
|
/**
|
|
49
|
-
*
|
|
61
|
+
* The `handleConnection` method receives incoming WebSocket connections,
|
|
62
|
+
* runs all hooks:
|
|
63
|
+
*
|
|
64
|
+
* - onConnect for all connections
|
|
65
|
+
* - onAuthenticate only if required
|
|
66
|
+
*
|
|
67
|
+
* … and if nothings fails it’ll fully establish the connection and
|
|
68
|
+
* load the Document then.
|
|
50
69
|
*/
|
|
51
70
|
handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
|
|
52
71
|
/**
|
|
53
72
|
* Handle update of the given document
|
|
54
|
-
* @private
|
|
55
73
|
*/
|
|
56
74
|
private handleDocumentUpdate;
|
|
75
|
+
timers: Map<string, {
|
|
76
|
+
timeout: NodeJS.Timeout;
|
|
77
|
+
start: number;
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* debounce the given function, using the given identifier
|
|
81
|
+
*/
|
|
82
|
+
debounce(id: string, func: Function, immediately?: boolean): void;
|
|
57
83
|
/**
|
|
58
84
|
* Create a new document by the given request
|
|
59
|
-
* @private
|
|
60
85
|
*/
|
|
61
86
|
private createDocument;
|
|
62
87
|
/**
|
|
63
88
|
* Create a new connection by the given request and document
|
|
64
|
-
* @private
|
|
65
89
|
*/
|
|
66
90
|
private createConnection;
|
|
67
91
|
/**
|
|
68
|
-
* Run the given hook on all configured extensions
|
|
69
|
-
* Runs the given callback after each hook
|
|
92
|
+
* Run the given hook on all configured extensions.
|
|
93
|
+
* Runs the given callback after each hook.
|
|
70
94
|
*/
|
|
71
|
-
hooks(name:
|
|
95
|
+
hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
|
|
72
96
|
/**
|
|
73
97
|
* Get parameters by the given request
|
|
74
|
-
* @private
|
|
75
98
|
*/
|
|
76
99
|
private static getParameters;
|
|
77
100
|
/**
|
|
78
101
|
* Get document name by the given request
|
|
79
|
-
* @private
|
|
80
102
|
*/
|
|
81
103
|
private getDocumentNameFromRequest;
|
|
82
104
|
enableDebugging(): void;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
1
2
|
import Connection from './Connection';
|
|
2
3
|
import { IncomingMessage } from './IncomingMessage';
|
|
3
|
-
import {
|
|
4
|
+
import { Debugger } from './Debugger';
|
|
5
|
+
import Document from './Document';
|
|
4
6
|
export declare class MessageReceiver {
|
|
5
7
|
message: IncomingMessage;
|
|
6
|
-
|
|
7
|
-
constructor(message: IncomingMessage);
|
|
8
|
-
apply(connection:
|
|
9
|
-
readSyncMessage(message: IncomingMessage, connection:
|
|
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, requestFirstSync?: boolean): 0 | 2 | 1;
|
|
12
|
+
applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
|
|
10
13
|
}
|
|
@@ -7,7 +7,9 @@ export declare class OutgoingMessage {
|
|
|
7
7
|
category?: string;
|
|
8
8
|
constructor();
|
|
9
9
|
createSyncMessage(): OutgoingMessage;
|
|
10
|
+
createSyncReplyMessage(): OutgoingMessage;
|
|
10
11
|
createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
|
|
12
|
+
writeQueryAwareness(): OutgoingMessage;
|
|
11
13
|
writeAuthenticated(): OutgoingMessage;
|
|
12
14
|
writePermissionDenied(reason: string): OutgoingMessage;
|
|
13
15
|
writeFirstSyncStepFor(document: Document): OutgoingMessage;
|
|
@@ -1,56 +1,56 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
|
|
3
3
|
import { URLSearchParams } from 'url';
|
|
4
|
-
import {
|
|
4
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
5
5
|
import Document from './Document';
|
|
6
6
|
import { Hocuspocus } from './Hocuspocus';
|
|
7
7
|
export declare enum MessageType {
|
|
8
8
|
Unknown = -1,
|
|
9
9
|
Sync = 0,
|
|
10
10
|
Awareness = 1,
|
|
11
|
-
Auth = 2
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* State of the WebSocket connection.
|
|
15
|
-
* https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
|
|
16
|
-
*/
|
|
17
|
-
export declare enum WsReadyStates {
|
|
18
|
-
Connecting = 0,
|
|
19
|
-
Open = 1,
|
|
20
|
-
Closing = 2,
|
|
21
|
-
Closed = 3
|
|
11
|
+
Auth = 2,
|
|
12
|
+
QueryAwareness = 3,
|
|
13
|
+
SyncReply = 4
|
|
22
14
|
}
|
|
23
15
|
export interface AwarenessUpdate {
|
|
24
16
|
added: Array<any>;
|
|
25
17
|
updated: Array<any>;
|
|
26
18
|
removed: Array<any>;
|
|
27
19
|
}
|
|
28
|
-
export interface
|
|
20
|
+
export interface ConnectionConfiguration {
|
|
29
21
|
readOnly: boolean;
|
|
30
22
|
requiresAuthentication: boolean;
|
|
31
23
|
isAuthenticated: boolean;
|
|
32
24
|
}
|
|
33
25
|
export interface Extension {
|
|
34
|
-
|
|
35
|
-
onChange?(data: onChangePayload): Promise<any>;
|
|
36
|
-
onConnect?(data: onConnectPayload): Promise<any>;
|
|
26
|
+
priority?: number;
|
|
37
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>;
|
|
38
33
|
/**
|
|
39
34
|
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
40
35
|
*/
|
|
41
36
|
onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
42
37
|
onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
afterLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
39
|
+
beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
|
|
40
|
+
onChange?(data: onChangePayload): Promise<any>;
|
|
41
|
+
onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;
|
|
42
|
+
afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>;
|
|
43
|
+
onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
|
|
46
44
|
onRequest?(data: onRequestPayload): Promise<any>;
|
|
47
|
-
|
|
45
|
+
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
46
|
+
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
48
47
|
}
|
|
49
|
-
export declare type
|
|
48
|
+
export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
|
|
50
49
|
/**
|
|
51
50
|
* @deprecated onCreateDocument is deprecated, use onLoadDocument instead
|
|
52
51
|
*/
|
|
53
|
-
'onCreateDocument' | 'onLoadDocument' | '
|
|
52
|
+
'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
53
|
+
export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
|
|
54
54
|
export interface Configuration extends Extension {
|
|
55
55
|
/**
|
|
56
56
|
* A name for the instance, used for logging.
|
|
@@ -68,18 +68,35 @@ export interface Configuration extends Extension {
|
|
|
68
68
|
* Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
|
|
69
69
|
*/
|
|
70
70
|
timeout: number;
|
|
71
|
+
/**
|
|
72
|
+
* Debounces the call of the `onStoreDocument` hook for the given amount of time in ms.
|
|
73
|
+
* Otherwise every single update would be persisted.
|
|
74
|
+
*/
|
|
75
|
+
debounce: number;
|
|
76
|
+
/**
|
|
77
|
+
* Makes sure to call `onStoreDocument` at least in the given amount of time (ms).
|
|
78
|
+
*/
|
|
79
|
+
maxDebounce: number;
|
|
71
80
|
/**
|
|
72
81
|
* By default, the servers show a start screen. If passed false, the server will start quietly.
|
|
73
82
|
*/
|
|
74
83
|
quiet: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* options to pass to the ydoc document
|
|
86
|
+
*/
|
|
87
|
+
yDocOptions: {
|
|
88
|
+
gc: boolean;
|
|
89
|
+
gcFilter: () => boolean;
|
|
90
|
+
};
|
|
75
91
|
/**
|
|
76
92
|
* Function which returns the (customized) document name based on the request
|
|
77
93
|
*/
|
|
78
|
-
getDocumentName?(data:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
getDocumentName?(data: getDocumentNamePayload): string | Promise<string>;
|
|
95
|
+
}
|
|
96
|
+
export interface getDocumentNamePayload {
|
|
97
|
+
documentName: string;
|
|
98
|
+
request: IncomingMessage;
|
|
99
|
+
requestParameters: URLSearchParams;
|
|
83
100
|
}
|
|
84
101
|
export interface onAuthenticatePayload {
|
|
85
102
|
documentName: string;
|
|
@@ -88,7 +105,7 @@ export interface onAuthenticatePayload {
|
|
|
88
105
|
requestParameters: URLSearchParams;
|
|
89
106
|
socketId: string;
|
|
90
107
|
token: string;
|
|
91
|
-
connection:
|
|
108
|
+
connection: ConnectionConfiguration;
|
|
92
109
|
}
|
|
93
110
|
export interface onConnectPayload {
|
|
94
111
|
documentName: string;
|
|
@@ -97,7 +114,16 @@ export interface onConnectPayload {
|
|
|
97
114
|
requestHeaders: IncomingHttpHeaders;
|
|
98
115
|
requestParameters: URLSearchParams;
|
|
99
116
|
socketId: string;
|
|
100
|
-
connection:
|
|
117
|
+
connection: ConnectionConfiguration;
|
|
118
|
+
}
|
|
119
|
+
export interface connectedPayload {
|
|
120
|
+
documentName: string;
|
|
121
|
+
instance: Hocuspocus;
|
|
122
|
+
request: IncomingMessage;
|
|
123
|
+
requestHeaders: IncomingHttpHeaders;
|
|
124
|
+
requestParameters: URLSearchParams;
|
|
125
|
+
socketId: string;
|
|
126
|
+
connection: ConnectionConfiguration;
|
|
101
127
|
}
|
|
102
128
|
export interface onLoadDocumentPayload {
|
|
103
129
|
context: any;
|
|
@@ -107,7 +133,17 @@ export interface onLoadDocumentPayload {
|
|
|
107
133
|
requestHeaders: IncomingHttpHeaders;
|
|
108
134
|
requestParameters: URLSearchParams;
|
|
109
135
|
socketId: string;
|
|
110
|
-
connection:
|
|
136
|
+
connection: ConnectionConfiguration;
|
|
137
|
+
}
|
|
138
|
+
export interface afterLoadDocumentPayload {
|
|
139
|
+
context: any;
|
|
140
|
+
document: Document;
|
|
141
|
+
documentName: string;
|
|
142
|
+
instance: Hocuspocus;
|
|
143
|
+
requestHeaders: IncomingHttpHeaders;
|
|
144
|
+
requestParameters: URLSearchParams;
|
|
145
|
+
socketId: string;
|
|
146
|
+
connection: ConnectionConfiguration;
|
|
111
147
|
}
|
|
112
148
|
export interface onChangePayload {
|
|
113
149
|
clientsCount: number;
|
|
@@ -120,6 +156,62 @@ export interface onChangePayload {
|
|
|
120
156
|
update: Uint8Array;
|
|
121
157
|
socketId: string;
|
|
122
158
|
}
|
|
159
|
+
export interface beforeHandleMessagePayload {
|
|
160
|
+
clientsCount: number;
|
|
161
|
+
context: any;
|
|
162
|
+
document: Document;
|
|
163
|
+
documentName: string;
|
|
164
|
+
instance: Hocuspocus;
|
|
165
|
+
requestHeaders: IncomingHttpHeaders;
|
|
166
|
+
requestParameters: URLSearchParams;
|
|
167
|
+
update: Uint8Array;
|
|
168
|
+
socketId: string;
|
|
169
|
+
}
|
|
170
|
+
export interface onStoreDocumentPayload {
|
|
171
|
+
clientsCount: number;
|
|
172
|
+
context: any;
|
|
173
|
+
document: Document;
|
|
174
|
+
documentName: string;
|
|
175
|
+
instance: Hocuspocus;
|
|
176
|
+
requestHeaders: IncomingHttpHeaders;
|
|
177
|
+
requestParameters: URLSearchParams;
|
|
178
|
+
socketId: string;
|
|
179
|
+
}
|
|
180
|
+
export interface afterStoreDocumentPayload extends onStoreDocumentPayload {
|
|
181
|
+
}
|
|
182
|
+
export interface onAwarenessUpdatePayload {
|
|
183
|
+
clientsCount: number;
|
|
184
|
+
context: any;
|
|
185
|
+
document: Document;
|
|
186
|
+
documentName: string;
|
|
187
|
+
instance: Hocuspocus;
|
|
188
|
+
requestHeaders: IncomingHttpHeaders;
|
|
189
|
+
requestParameters: URLSearchParams;
|
|
190
|
+
update: Uint8Array;
|
|
191
|
+
socketId: string;
|
|
192
|
+
added: number[];
|
|
193
|
+
updated: number[];
|
|
194
|
+
removed: number[];
|
|
195
|
+
awareness: Awareness;
|
|
196
|
+
states: StatesArray;
|
|
197
|
+
}
|
|
198
|
+
export declare type StatesArray = {
|
|
199
|
+
clientId: number;
|
|
200
|
+
[key: string | number]: any;
|
|
201
|
+
}[];
|
|
202
|
+
export interface fetchPayload {
|
|
203
|
+
context: any;
|
|
204
|
+
document: Document;
|
|
205
|
+
documentName: string;
|
|
206
|
+
instance: Hocuspocus;
|
|
207
|
+
requestHeaders: IncomingHttpHeaders;
|
|
208
|
+
requestParameters: URLSearchParams;
|
|
209
|
+
socketId: string;
|
|
210
|
+
connection: ConnectionConfiguration;
|
|
211
|
+
}
|
|
212
|
+
export interface storePayload extends onStoreDocumentPayload {
|
|
213
|
+
state: Buffer;
|
|
214
|
+
}
|
|
123
215
|
export interface onDisconnectPayload {
|
|
124
216
|
clientsCount: number;
|
|
125
217
|
context: any;
|
|
@@ -136,24 +228,21 @@ export interface onRequestPayload {
|
|
|
136
228
|
instance: Hocuspocus;
|
|
137
229
|
}
|
|
138
230
|
export interface onUpgradePayload {
|
|
139
|
-
head: any;
|
|
140
231
|
request: IncomingMessage;
|
|
141
|
-
socket:
|
|
232
|
+
socket: any;
|
|
233
|
+
head: any;
|
|
142
234
|
instance: Hocuspocus;
|
|
143
235
|
}
|
|
144
236
|
export interface onListenPayload {
|
|
237
|
+
instance: Hocuspocus;
|
|
238
|
+
configuration: Configuration;
|
|
145
239
|
port: number;
|
|
146
240
|
}
|
|
147
241
|
export interface onDestroyPayload {
|
|
148
242
|
instance: Hocuspocus;
|
|
149
243
|
}
|
|
150
244
|
export interface onConfigurePayload {
|
|
245
|
+
instance: Hocuspocus;
|
|
151
246
|
configuration: Configuration;
|
|
152
247
|
version: string;
|
|
153
|
-
yjsVersion: string;
|
|
154
|
-
instance: Hocuspocus;
|
|
155
|
-
}
|
|
156
|
-
export interface CloseEvent {
|
|
157
|
-
code: number;
|
|
158
|
-
reason: string;
|
|
159
248
|
}
|