@hocuspocus/extension-throttle 1.0.0-alpha.9 → 1.0.0-beta.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.
- package/dist/{hocuspocus-throttle.js → hocuspocus-throttle.cjs} +9 -18
- package/dist/hocuspocus-throttle.cjs.map +1 -0
- package/dist/hocuspocus-throttle.esm.js +8 -17
- package/dist/hocuspocus-throttle.esm.js.map +1 -1
- 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 +30 -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/{monitor → extension-monitor}/src/Collector.d.ts +4 -5
- package/dist/packages/{monitor → extension-monitor}/src/Dashboard.d.ts +2 -2
- package/dist/packages/{monitor → extension-monitor}/src/Storage.d.ts +0 -0
- package/dist/packages/{monitor → extension-monitor}/src/index.d.ts +3 -5
- package/dist/packages/extension-redis/src/Redis.d.ts +98 -0
- package/dist/packages/extension-redis/src/index.d.ts +1 -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/{webhook → extension-webhook}/src/index.d.ts +5 -11
- 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 +163 -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 +27 -7
- package/dist/packages/server/src/Debugger.d.ts +14 -0
- package/dist/packages/server/src/Document.d.ts +11 -5
- package/dist/packages/server/src/Hocuspocus.d.ts +63 -17
- package/dist/packages/server/src/IncomingMessage.d.ts +11 -7
- package/dist/packages/server/src/MessageReceiver.d.ts +13 -0
- package/dist/packages/server/src/OutgoingMessage.d.ts +6 -0
- package/dist/packages/server/src/index.d.ts +6 -0
- package/dist/packages/server/src/types.d.ts +181 -23
- package/dist/{demos/server/src/create-document.d.ts → playground/backend/src/default.d.ts} +0 -0
- package/dist/{demos/server → playground/backend}/src/express.d.ts +0 -0
- package/dist/{demos/server/src/minimal.d.ts → playground/backend/src/koa.d.ts} +0 -0
- package/dist/{demos/server/src/monitor.d.ts → playground/backend/src/load-document.d.ts} +0 -0
- package/dist/{demos/server/src/webhook.d.ts → playground/backend/src/monitor.d.ts} +0 -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-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 +13 -8
- package/src/index.ts +12 -33
- package/CHANGELOG.md +0 -67
- package/dist/hocuspocus-throttle.js.map +0 -1
- package/dist/packages/logger/src/index.d.ts +0 -13
- package/dist/packages/redis/src/Redis.d.ts +0 -22
- package/dist/packages/redis/src/RedisCluster.d.ts +0 -4
- package/dist/packages/redis/src/index.d.ts +0 -2
- package/dist/packages/rocksdb/src/index.d.ts +0 -30
- package/dist/packages/throttle/src/index.d.ts +0 -28
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
+
import * as mutex from 'lib0/mutex';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
|
+
import EventEmitter from './EventEmitter';
|
|
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 {
|
|
10
|
+
/**
|
|
11
|
+
* URL of your @hocuspocus/server instance
|
|
12
|
+
*/
|
|
13
|
+
url: string;
|
|
14
|
+
/**
|
|
15
|
+
* The identifier/name of your document
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* The actual Y.js document
|
|
20
|
+
*/
|
|
21
|
+
document: Y.Doc;
|
|
22
|
+
/**
|
|
23
|
+
* Pass `false` to start the connection manually.
|
|
24
|
+
*/
|
|
25
|
+
connect: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Pass false to disable broadcasting between browser tabs.
|
|
28
|
+
*/
|
|
29
|
+
broadcast: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* An Awareness instance to keep the presence state of all clients.
|
|
32
|
+
*/
|
|
33
|
+
awareness: Awareness;
|
|
34
|
+
/**
|
|
35
|
+
* A token that’s sent to the backend for authentication purposes.
|
|
36
|
+
*/
|
|
37
|
+
token: string | (() => string) | (() => Promise<string>) | null;
|
|
38
|
+
/**
|
|
39
|
+
* URL parameters that should be added.
|
|
40
|
+
*/
|
|
41
|
+
parameters: {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* An optional WebSocket polyfill, for example for Node.js
|
|
46
|
+
*/
|
|
47
|
+
WebSocketPolyfill: any;
|
|
48
|
+
/**
|
|
49
|
+
* Force syncing the document in the defined interval.
|
|
50
|
+
*/
|
|
51
|
+
forceSyncInterval: false | number;
|
|
52
|
+
/**
|
|
53
|
+
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
54
|
+
*/
|
|
55
|
+
messageReconnectTimeout: number;
|
|
56
|
+
/**
|
|
57
|
+
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
58
|
+
*/
|
|
59
|
+
delay: number;
|
|
60
|
+
/**
|
|
61
|
+
* 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.
|
|
62
|
+
*/
|
|
63
|
+
initialDelay: number;
|
|
64
|
+
/**
|
|
65
|
+
* The factor option is used to grow the delay exponentially.
|
|
66
|
+
*/
|
|
67
|
+
factor: number;
|
|
68
|
+
/**
|
|
69
|
+
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
70
|
+
*/
|
|
71
|
+
maxAttempts: number;
|
|
72
|
+
/**
|
|
73
|
+
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
74
|
+
*/
|
|
75
|
+
minDelay: number;
|
|
76
|
+
/**
|
|
77
|
+
* 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.
|
|
78
|
+
*/
|
|
79
|
+
maxDelay: number;
|
|
80
|
+
/**
|
|
81
|
+
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
82
|
+
*/
|
|
83
|
+
jitter: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* 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.
|
|
86
|
+
*/
|
|
87
|
+
timeout: number;
|
|
88
|
+
onAuthenticated: () => void;
|
|
89
|
+
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
90
|
+
onOpen: (data: onOpenParameters) => void;
|
|
91
|
+
onConnect: () => void;
|
|
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;
|
|
98
|
+
onDestroy: () => void;
|
|
99
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
100
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Don’t output any warnings.
|
|
103
|
+
*/
|
|
104
|
+
quiet: boolean;
|
|
105
|
+
}
|
|
106
|
+
export declare class HocuspocusProvider extends EventEmitter {
|
|
107
|
+
configuration: CompleteHocuspocusProviderConfiguration;
|
|
108
|
+
subscribedToBroadcastChannel: boolean;
|
|
109
|
+
webSocket: WebSocket | null;
|
|
110
|
+
shouldConnect: boolean;
|
|
111
|
+
status: WebSocketStatus;
|
|
112
|
+
isSynced: boolean;
|
|
113
|
+
unsyncedChanges: number;
|
|
114
|
+
isAuthenticated: boolean;
|
|
115
|
+
lastMessageReceived: number;
|
|
116
|
+
mux: mutex.mutex;
|
|
117
|
+
intervals: any;
|
|
118
|
+
connectionAttempt: {
|
|
119
|
+
resolve: (value?: any) => void;
|
|
120
|
+
reject: (reason?: any) => void;
|
|
121
|
+
} | null;
|
|
122
|
+
constructor(configuration: HocuspocusProviderConfiguration);
|
|
123
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
124
|
+
boundConnect: () => Promise<unknown>;
|
|
125
|
+
cancelWebsocketRetry?: () => void;
|
|
126
|
+
connect(): Promise<unknown>;
|
|
127
|
+
createWebSocketConnection(): Promise<unknown>;
|
|
128
|
+
resolveConnectionAttempt(): void;
|
|
129
|
+
stopConnectionAttempt(): void;
|
|
130
|
+
rejectConnectionAttempt(): void;
|
|
131
|
+
get document(): Y.Doc;
|
|
132
|
+
get awareness(): Awareness;
|
|
133
|
+
get hasUnsyncedChanges(): boolean;
|
|
134
|
+
checkConnection(): void;
|
|
135
|
+
forceSync(): void;
|
|
136
|
+
boundBeforeUnload: () => void;
|
|
137
|
+
beforeUnload(): void;
|
|
138
|
+
registerEventListeners(): void;
|
|
139
|
+
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
140
|
+
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
141
|
+
permissionDeniedHandler(reason: string): void;
|
|
142
|
+
authenticatedHandler(): void;
|
|
143
|
+
get serverUrl(): string;
|
|
144
|
+
get url(): string;
|
|
145
|
+
get synced(): boolean;
|
|
146
|
+
set synced(state: boolean);
|
|
147
|
+
get isAuthenticationRequired(): boolean;
|
|
148
|
+
disconnect(): void;
|
|
149
|
+
onOpen(event: Event): Promise<void>;
|
|
150
|
+
getToken(): Promise<string | null>;
|
|
151
|
+
startSync(): void;
|
|
152
|
+
send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
|
|
153
|
+
onMessage(event: MessageEvent): void;
|
|
154
|
+
onClose(event: CloseEvent): void;
|
|
155
|
+
destroy(): void;
|
|
156
|
+
get broadcastChannel(): string;
|
|
157
|
+
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
158
|
+
broadcastChannelSubscriber(data: ArrayBuffer): void;
|
|
159
|
+
subscribeToBroadcastChannel(): void;
|
|
160
|
+
disconnectBroadcastChannel(): void;
|
|
161
|
+
broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
|
|
162
|
+
setAwarenessField(key: string, value: any): void;
|
|
163
|
+
}
|
|
@@ -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,77 @@
|
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { Encoder } from 'lib0/encoding';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
|
+
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
|
|
6
|
+
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
|
|
7
|
+
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
|
|
8
|
+
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
|
|
9
|
+
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
|
|
10
|
+
import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
|
|
11
|
+
import { IncomingMessage } from './IncomingMessage';
|
|
12
|
+
import { OutgoingMessage } from './OutgoingMessage';
|
|
13
|
+
export declare enum MessageType {
|
|
14
|
+
Sync = 0,
|
|
15
|
+
Awareness = 1,
|
|
16
|
+
Auth = 2,
|
|
17
|
+
QueryAwareness = 3
|
|
18
|
+
}
|
|
19
|
+
export declare enum WebSocketStatus {
|
|
20
|
+
Connecting = "connecting",
|
|
21
|
+
Connected = "connected",
|
|
22
|
+
Disconnected = "disconnected"
|
|
23
|
+
}
|
|
24
|
+
export interface OutgoingMessageInterface {
|
|
25
|
+
encoder: Encoder;
|
|
26
|
+
type?: MessageType;
|
|
27
|
+
}
|
|
28
|
+
export interface OutgoingMessageArguments {
|
|
29
|
+
token: string;
|
|
30
|
+
document: Y.Doc;
|
|
31
|
+
awareness: Awareness;
|
|
32
|
+
clients: number[];
|
|
33
|
+
states: Map<number, {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
}>;
|
|
36
|
+
update: any;
|
|
37
|
+
encoder: Encoder;
|
|
38
|
+
}
|
|
39
|
+
export interface Constructable<T> {
|
|
40
|
+
new (...args: any): T;
|
|
41
|
+
}
|
|
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,9 +2,11 @@
|
|
|
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
|
-
|
|
7
|
-
|
|
7
|
+
import { Debugger } from './Debugger';
|
|
8
|
+
export declare class Connection {
|
|
9
|
+
webSocket: WebSocket;
|
|
8
10
|
context: any;
|
|
9
11
|
document: Document;
|
|
10
12
|
pingInterval: NodeJS.Timeout;
|
|
@@ -15,40 +17,58 @@ declare class Connection {
|
|
|
15
17
|
socketId: string;
|
|
16
18
|
lock: AsyncLock;
|
|
17
19
|
readOnly: Boolean;
|
|
20
|
+
logger: Debugger;
|
|
18
21
|
/**
|
|
19
22
|
* Constructor.
|
|
20
23
|
*/
|
|
21
|
-
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);
|
|
22
25
|
/**
|
|
23
26
|
* Set a callback that will be triggered when the connection is closed
|
|
24
27
|
*/
|
|
25
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;
|
|
26
33
|
/**
|
|
27
34
|
* Send the given message
|
|
28
35
|
*/
|
|
29
36
|
send(message: any): void;
|
|
30
37
|
/**
|
|
31
|
-
*
|
|
38
|
+
* Graceful wrapper around the WebSocket close method.
|
|
32
39
|
*/
|
|
33
|
-
close(): void;
|
|
40
|
+
close(event?: CloseEvent): void;
|
|
34
41
|
/**
|
|
35
42
|
* Check if pong was received and close the connection otherwise
|
|
36
43
|
* @private
|
|
37
44
|
*/
|
|
38
45
|
private check;
|
|
39
46
|
/**
|
|
40
|
-
* Send
|
|
47
|
+
* Send the current document awareness to the client, if any
|
|
41
48
|
* @private
|
|
42
49
|
*/
|
|
43
|
-
private
|
|
50
|
+
private sendCurrentAwareness;
|
|
44
51
|
/**
|
|
45
52
|
* Handle an incoming message
|
|
46
53
|
* @private
|
|
47
54
|
*/
|
|
48
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;
|
|
49
63
|
/**
|
|
50
64
|
* Get the underlying connection instance
|
|
65
|
+
* @deprecated
|
|
51
66
|
*/
|
|
52
67
|
get instance(): WebSocket;
|
|
68
|
+
/**
|
|
69
|
+
* Get the underlying connection instance
|
|
70
|
+
* @deprecated
|
|
71
|
+
*/
|
|
72
|
+
get connection(): WebSocket;
|
|
53
73
|
}
|
|
54
74
|
export default Connection;
|
|
@@ -3,18 +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
|
-
|
|
6
|
+
import { Debugger } from './Debugger';
|
|
7
|
+
export declare class Document extends Doc {
|
|
7
8
|
awareness: Awareness;
|
|
8
9
|
callbacks: {
|
|
9
10
|
onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
|
|
10
11
|
};
|
|
11
|
-
connections: Map<
|
|
12
|
+
connections: Map<WebSocket, {
|
|
13
|
+
clients: Set<any>;
|
|
14
|
+
connection: Connection;
|
|
15
|
+
}>;
|
|
12
16
|
name: string;
|
|
13
17
|
mux: mutex;
|
|
18
|
+
logger: Debugger;
|
|
19
|
+
isLoading: boolean;
|
|
14
20
|
/**
|
|
15
21
|
* Constructor.
|
|
16
22
|
*/
|
|
17
|
-
constructor(name: string);
|
|
23
|
+
constructor(name: string, logger: Debugger, yDocOptions: {});
|
|
18
24
|
/**
|
|
19
25
|
* Check if the Document is empty
|
|
20
26
|
*/
|
|
@@ -41,9 +47,9 @@ declare class Document extends Doc {
|
|
|
41
47
|
*/
|
|
42
48
|
removeConnection(connection: Connection): Document;
|
|
43
49
|
/**
|
|
44
|
-
* Get the number of active connections
|
|
50
|
+
* Get the number of active connections for this document
|
|
45
51
|
*/
|
|
46
|
-
|
|
52
|
+
getConnectionsCount(): number;
|
|
47
53
|
/**
|
|
48
54
|
* Get an array of registered connections
|
|
49
55
|
*/
|
|
@@ -1,65 +1,111 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import WebSocket from 'ws';
|
|
2
|
+
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
3
3
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
|
-
import { Configuration } from './types';
|
|
4
|
+
import { Configuration, HookName, HookPayload } from './types';
|
|
5
|
+
import Document from './Document';
|
|
6
|
+
import { Debugger } from './Debugger';
|
|
7
|
+
import { onListenPayload } from '.';
|
|
5
8
|
export declare const defaultConfiguration: {
|
|
9
|
+
name: null;
|
|
6
10
|
port: number;
|
|
7
11
|
timeout: number;
|
|
12
|
+
debounce: number;
|
|
13
|
+
maxDebounce: number;
|
|
14
|
+
quiet: boolean;
|
|
15
|
+
yDocOptions: {
|
|
16
|
+
gc: boolean;
|
|
17
|
+
gcFilter: () => boolean;
|
|
18
|
+
};
|
|
8
19
|
};
|
|
9
20
|
/**
|
|
10
|
-
* Hocuspocus
|
|
21
|
+
* Hocuspocus Server
|
|
11
22
|
*/
|
|
12
23
|
export declare class Hocuspocus {
|
|
13
24
|
configuration: Configuration;
|
|
14
|
-
documents: Map<
|
|
25
|
+
documents: Map<string, Document>;
|
|
15
26
|
httpServer?: HTTPServer;
|
|
16
|
-
|
|
27
|
+
webSocketServer?: WebSocketServer;
|
|
28
|
+
debugger: Debugger;
|
|
29
|
+
constructor(configuration?: Partial<Configuration>);
|
|
17
30
|
/**
|
|
18
31
|
* Configure the server
|
|
19
32
|
*/
|
|
20
33
|
configure(configuration: Partial<Configuration>): Hocuspocus;
|
|
34
|
+
get requiresAuthentication(): boolean;
|
|
21
35
|
/**
|
|
22
36
|
* Start the server
|
|
23
37
|
*/
|
|
24
|
-
listen(): 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;
|
|
43
|
+
private showStartScreen;
|
|
44
|
+
/**
|
|
45
|
+
* Get the total number of active documents
|
|
46
|
+
*/
|
|
47
|
+
getDocumentsCount(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Get the total number of active connections
|
|
50
|
+
*/
|
|
51
|
+
getConnectionsCount(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Force close one or more connections
|
|
54
|
+
*/
|
|
55
|
+
closeConnections(documentName?: string): void;
|
|
25
56
|
/**
|
|
26
57
|
* Destroy the server
|
|
27
58
|
*/
|
|
28
59
|
destroy(): Promise<any>;
|
|
29
60
|
/**
|
|
30
|
-
*
|
|
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.
|
|
31
69
|
*/
|
|
32
70
|
handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
|
|
33
71
|
/**
|
|
34
72
|
* Handle update of the given document
|
|
35
|
-
* @private
|
|
36
73
|
*/
|
|
37
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;
|
|
38
83
|
/**
|
|
39
84
|
* Create a new document by the given request
|
|
40
|
-
* @private
|
|
41
85
|
*/
|
|
42
86
|
private createDocument;
|
|
43
87
|
/**
|
|
44
88
|
* Create a new connection by the given request and document
|
|
45
|
-
* @private
|
|
46
89
|
*/
|
|
47
90
|
private createConnection;
|
|
48
91
|
/**
|
|
49
|
-
* Run the given hook on all configured extensions
|
|
50
|
-
* Runs the given callback after each hook
|
|
51
|
-
* @private
|
|
92
|
+
* Run the given hook on all configured extensions.
|
|
93
|
+
* Runs the given callback after each hook.
|
|
52
94
|
*/
|
|
53
|
-
|
|
95
|
+
hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
|
|
54
96
|
/**
|
|
55
97
|
* Get parameters by the given request
|
|
56
|
-
* @private
|
|
57
98
|
*/
|
|
58
99
|
private static getParameters;
|
|
59
100
|
/**
|
|
60
101
|
* Get document name by the given request
|
|
61
|
-
* @private
|
|
62
102
|
*/
|
|
63
|
-
private
|
|
103
|
+
private getDocumentNameFromRequest;
|
|
104
|
+
enableDebugging(): void;
|
|
105
|
+
enableMessageLogging(): void;
|
|
106
|
+
disableLogging(): void;
|
|
107
|
+
disableDebugging(): void;
|
|
108
|
+
flushMessageLogs(): this;
|
|
109
|
+
getMessageLogs(): any[];
|
|
64
110
|
}
|
|
65
111
|
export declare const Server: Hocuspocus;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Decoder } from 'lib0/decoding';
|
|
2
2
|
import { Encoder } from 'lib0/encoding';
|
|
3
|
-
import
|
|
4
|
-
import Connection from './Connection';
|
|
3
|
+
import { MessageType } from './types';
|
|
5
4
|
export declare class IncomingMessage {
|
|
5
|
+
/**
|
|
6
|
+
* Access to the received message.
|
|
7
|
+
*/
|
|
6
8
|
decoder: Decoder;
|
|
7
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Access to the reply.
|
|
11
|
+
*/
|
|
12
|
+
encoder: Encoder;
|
|
8
13
|
constructor(input: any);
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
readVarUint8Array(): Uint8Array;
|
|
15
|
+
readVarUint(): number;
|
|
11
16
|
toUint8Array(): Uint8Array;
|
|
17
|
+
writeVarUint(type: MessageType): void;
|
|
12
18
|
get length(): number;
|
|
13
|
-
get messageType(): number;
|
|
14
|
-
private get encoder();
|
|
15
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, requestFirstSync?: boolean): 0 | 2 | 1;
|
|
12
|
+
applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
|
|
13
|
+
}
|
|
@@ -3,9 +3,15 @@ import { Awareness } from 'y-protocols/awareness';
|
|
|
3
3
|
import Document from './Document';
|
|
4
4
|
export declare class OutgoingMessage {
|
|
5
5
|
encoder: Encoder;
|
|
6
|
+
type?: number;
|
|
7
|
+
category?: string;
|
|
6
8
|
constructor();
|
|
7
9
|
createSyncMessage(): OutgoingMessage;
|
|
10
|
+
createSyncReplyMessage(): OutgoingMessage;
|
|
8
11
|
createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
|
|
12
|
+
writeQueryAwareness(): OutgoingMessage;
|
|
13
|
+
writeAuthenticated(): OutgoingMessage;
|
|
14
|
+
writePermissionDenied(reason: string): OutgoingMessage;
|
|
9
15
|
writeFirstSyncStepFor(document: Document): OutgoingMessage;
|
|
10
16
|
writeUpdate(update: Uint8Array): OutgoingMessage;
|
|
11
17
|
toUint8Array(): Uint8Array;
|