@hocuspocus/extension-throttle 2.2.3 → 2.3.1
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/packages/extension-redis/src/Redis.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +23 -8
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +3 -1
- package/dist/packages/provider/src/MessageReceiver.d.ts +2 -1
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +2 -2
- package/dist/packages/provider/src/types.d.ts +2 -1
- package/dist/packages/server/src/Hocuspocus.d.ts +3 -2
- package/dist/packages/server/src/MessageReceiver.d.ts +1 -1
- package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
- package/dist/packages/server/src/types.d.ts +30 -6
- package/dist/tests/provider/hasUnsyncedChanges.d.ts +1 -0
- package/dist/tests/server/afterUnloadDocument.d.ts +1 -0
- package/package.json +2 -2
|
@@ -69,7 +69,7 @@ export declare class Redis implements Extension {
|
|
|
69
69
|
private subKey;
|
|
70
70
|
private lockKey;
|
|
71
71
|
/**
|
|
72
|
-
* Once a document is
|
|
72
|
+
* Once a document is loaded, subscribe to the channel in Redis.
|
|
73
73
|
*/
|
|
74
74
|
afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
|
|
75
75
|
/**
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
3
1
|
import * as mutex from 'lib0/mutex';
|
|
4
2
|
import type { CloseEvent, Event, MessageEvent } from 'ws';
|
|
3
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
4
|
+
import * as Y from 'yjs';
|
|
5
5
|
import EventEmitter from './EventEmitter.js';
|
|
6
|
-
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus, onAwarenessChangeParameters, onAwarenessUpdateParameters } from './types.js';
|
|
7
6
|
import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
|
|
7
|
+
import { ConstructableOutgoingMessage, WebSocketStatus, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters } from './types.js';
|
|
8
8
|
export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
|
|
9
9
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
* The identifier/name of your document
|
|
12
|
+
*/
|
|
13
13
|
name: string;
|
|
14
14
|
/**
|
|
15
15
|
* The actual Y.js document
|
|
@@ -59,6 +59,14 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
59
59
|
* Don’t output any warnings.
|
|
60
60
|
*/
|
|
61
61
|
quiet: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Pass `false` to start the connection manually.
|
|
64
|
+
*/
|
|
65
|
+
connect: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Pass `false` to close the connection manually.
|
|
68
|
+
*/
|
|
69
|
+
preserveConnection: boolean;
|
|
62
70
|
}
|
|
63
71
|
export declare class HocuspocusProvider extends EventEmitter {
|
|
64
72
|
configuration: CompleteHocuspocusProviderConfiguration;
|
|
@@ -73,7 +81,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
73
81
|
isConnected: boolean;
|
|
74
82
|
constructor(configuration: HocuspocusProviderConfiguration);
|
|
75
83
|
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
76
|
-
|
|
84
|
+
boundPageUnload: () => void;
|
|
77
85
|
boundOnOpen: (event: Event) => Promise<void>;
|
|
78
86
|
boundOnMessage: (event: MessageEvent) => void;
|
|
79
87
|
boundOnClose: (event: CloseEvent) => void;
|
|
@@ -88,13 +96,20 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
88
96
|
get document(): Y.Doc;
|
|
89
97
|
get awareness(): Awareness;
|
|
90
98
|
get hasUnsyncedChanges(): boolean;
|
|
91
|
-
|
|
99
|
+
incrementUnsyncedChanges(): void;
|
|
100
|
+
decrementUnsyncedChanges(): void;
|
|
92
101
|
forceSync(): void;
|
|
93
|
-
|
|
102
|
+
pageUnload(): void;
|
|
94
103
|
registerEventListeners(): void;
|
|
95
104
|
sendStateless(payload: string): void;
|
|
96
105
|
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
97
106
|
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
107
|
+
/**
|
|
108
|
+
* Indicates whether a first handshake with the server has been established
|
|
109
|
+
*
|
|
110
|
+
* Note: this does not mean all updates from the client have been persisted to the backend. For this,
|
|
111
|
+
* use `hasUnsyncedChanges`.
|
|
112
|
+
*/
|
|
98
113
|
get synced(): boolean;
|
|
99
114
|
set synced(state: boolean);
|
|
100
115
|
receiveStateless(payload: string): void;
|
|
@@ -2,8 +2,8 @@ import * as mutex from 'lib0/mutex';
|
|
|
2
2
|
import type { MessageEvent } from 'ws';
|
|
3
3
|
import { Event } from 'ws';
|
|
4
4
|
import EventEmitter from './EventEmitter.js';
|
|
5
|
-
import { onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, WebSocketStatus, onAwarenessChangeParameters, onAwarenessUpdateParameters } from './types.js';
|
|
6
5
|
import { HocuspocusProvider } from './HocuspocusProvider.js';
|
|
6
|
+
import { WebSocketStatus, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.js';
|
|
7
7
|
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
8
8
|
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
9
9
|
/**
|
|
@@ -76,6 +76,7 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
76
76
|
quiet: boolean;
|
|
77
77
|
}
|
|
78
78
|
export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
79
|
+
private messageQueue;
|
|
79
80
|
configuration: CompleteHocuspocusProviderWebsocketConfiguration;
|
|
80
81
|
subscribedToBroadcastChannel: boolean;
|
|
81
82
|
webSocket: WebSocket | null;
|
|
@@ -104,6 +105,7 @@ export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
104
105
|
resolveConnectionAttempt(): void;
|
|
105
106
|
stopConnectionAttempt(): void;
|
|
106
107
|
rejectConnectionAttempt(): void;
|
|
108
|
+
closeTries: number;
|
|
107
109
|
checkConnection(): void;
|
|
108
110
|
registerEventListeners(): void;
|
|
109
111
|
get serverUrl(): string;
|
|
@@ -5,8 +5,9 @@ export declare class MessageReceiver {
|
|
|
5
5
|
broadcasted: boolean;
|
|
6
6
|
constructor(message: IncomingMessage);
|
|
7
7
|
setBroadcasted(value: boolean): this;
|
|
8
|
-
apply(provider: HocuspocusProvider, emitSynced
|
|
8
|
+
apply(provider: HocuspocusProvider, emitSynced: boolean): void;
|
|
9
9
|
private applySyncMessage;
|
|
10
|
+
applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean): void;
|
|
10
11
|
private applyAwarenessMessage;
|
|
11
12
|
private applyAuthMessage;
|
|
12
13
|
private applyQueryAwarenessMessage;
|
|
@@ -23,6 +23,6 @@ export declare class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
23
23
|
watchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['observe']>[0]): void;
|
|
24
24
|
unwatchVersions(callback: Parameters<AbstractType<YArrayEvent<AuditHistoryVersion>>['unobserve']>[0]): void;
|
|
25
25
|
isAutoVersioning(): boolean;
|
|
26
|
-
enableAutoVersioning():
|
|
27
|
-
disableAutoVersioning():
|
|
26
|
+
enableAutoVersioning(): 1;
|
|
27
|
+
disableAutoVersioning(): 0;
|
|
28
28
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Encoder } from 'lib0/encoding';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Event, MessageEvent } from 'ws';
|
|
3
3
|
import { Awareness } from 'y-protocols/awareness';
|
|
4
4
|
import * as Y from 'yjs';
|
|
5
|
+
import { CloseEvent } from '@hocuspocus/common';
|
|
5
6
|
import { IncomingMessage } from './IncomingMessage.js';
|
|
6
7
|
import { OutgoingMessage } from './OutgoingMessage.js';
|
|
7
8
|
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js';
|
|
@@ -5,7 +5,7 @@ import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
|
5
5
|
import { Debugger } from './Debugger.js';
|
|
6
6
|
import { DirectConnection } from './DirectConnection.js';
|
|
7
7
|
import Document from './Document.js';
|
|
8
|
-
import { Configuration, ConnectionConfiguration, HookName,
|
|
8
|
+
import { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onListenPayload, onStoreDocumentPayload } from './types.js';
|
|
9
9
|
export declare const defaultConfiguration: {
|
|
10
10
|
name: null;
|
|
11
11
|
port: number;
|
|
@@ -91,7 +91,8 @@ export declare class Hocuspocus {
|
|
|
91
91
|
* Run the given hook on all configured extensions.
|
|
92
92
|
* Runs the given callback after each hook.
|
|
93
93
|
*/
|
|
94
|
-
hooks(name:
|
|
94
|
+
hooks<T extends HookName>(name: T, payload: HookPayloadByName[T], callback?: Function | null): Promise<any>;
|
|
95
|
+
unloadDocument(document: Document): void;
|
|
95
96
|
enableDebugging(): void;
|
|
96
97
|
enableMessageLogging(): void;
|
|
97
98
|
disableLogging(): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Connection from './Connection.js';
|
|
2
|
-
import { IncomingMessage } from './IncomingMessage.js';
|
|
3
2
|
import { Debugger } from './Debugger.js';
|
|
4
3
|
import Document from './Document.js';
|
|
4
|
+
import { IncomingMessage } from './IncomingMessage.js';
|
|
5
5
|
export declare class MessageReceiver {
|
|
6
6
|
message: IncomingMessage;
|
|
7
7
|
logger: Debugger;
|
|
@@ -16,5 +16,6 @@ export declare class OutgoingMessage {
|
|
|
16
16
|
writeUpdate(update: Uint8Array): OutgoingMessage;
|
|
17
17
|
writeStateless(payload: string): OutgoingMessage;
|
|
18
18
|
writeBroadcastStateless(payload: string): OutgoingMessage;
|
|
19
|
+
writeSyncStatus(updateSaved: boolean): OutgoingMessage;
|
|
19
20
|
toUint8Array(): Uint8Array;
|
|
20
21
|
}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
|
|
5
5
|
import { URLSearchParams } from 'url';
|
|
6
6
|
import { Awareness } from 'y-protocols/awareness';
|
|
7
|
+
import Connection from './Connection.js';
|
|
7
8
|
import Document from './Document.js';
|
|
8
9
|
import { Hocuspocus } from './Hocuspocus.js';
|
|
9
|
-
import Connection from './Connection.js';
|
|
10
10
|
export declare enum MessageType {
|
|
11
11
|
Unknown = -1,
|
|
12
12
|
Sync = 0,
|
|
@@ -16,7 +16,8 @@ export declare enum MessageType {
|
|
|
16
16
|
SyncReply = 4,
|
|
17
17
|
Stateless = 5,
|
|
18
18
|
BroadcastStateless = 6,
|
|
19
|
-
CLOSE = 7
|
|
19
|
+
CLOSE = 7,
|
|
20
|
+
SyncStatus = 8
|
|
20
21
|
}
|
|
21
22
|
export interface AwarenessUpdate {
|
|
22
23
|
added: Array<any>;
|
|
@@ -47,10 +48,31 @@ export interface Extension {
|
|
|
47
48
|
onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
|
|
48
49
|
onRequest?(data: onRequestPayload): Promise<any>;
|
|
49
50
|
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
51
|
+
afterUnloadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
50
52
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
51
53
|
}
|
|
52
|
-
export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
53
|
-
export type
|
|
54
|
+
export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'afterUnloadDocument' | 'onDestroy';
|
|
55
|
+
export type HookPayloadByName = {
|
|
56
|
+
onConfigure: onConfigurePayload;
|
|
57
|
+
onListen: onListenPayload;
|
|
58
|
+
onUpgrade: onUpgradePayload;
|
|
59
|
+
onConnect: onConnectPayload;
|
|
60
|
+
connected: connectedPayload;
|
|
61
|
+
onAuthenticate: onAuthenticatePayload;
|
|
62
|
+
onLoadDocument: onLoadDocumentPayload;
|
|
63
|
+
afterLoadDocument: onLoadDocumentPayload;
|
|
64
|
+
beforeHandleMessage: beforeHandleMessagePayload;
|
|
65
|
+
beforeBroadcastStateless: beforeBroadcastStatelessPayload;
|
|
66
|
+
onStateless: onStatelessPayload;
|
|
67
|
+
onChange: onChangePayload;
|
|
68
|
+
onStoreDocument: onStoreDocumentPayload;
|
|
69
|
+
afterStoreDocument: afterStoreDocumentPayload;
|
|
70
|
+
onAwarenessUpdate: onAwarenessUpdatePayload;
|
|
71
|
+
onRequest: onRequestPayload;
|
|
72
|
+
onDisconnect: onDisconnectPayload;
|
|
73
|
+
afterUnloadDocument: afterUnloadDocumentPayload;
|
|
74
|
+
onDestroy: onDestroyPayload;
|
|
75
|
+
};
|
|
54
76
|
export interface Configuration extends Extension {
|
|
55
77
|
/**
|
|
56
78
|
* A name for the instance, used for logging.
|
|
@@ -198,14 +220,12 @@ export interface onStoreDocumentPayload {
|
|
|
198
220
|
export interface afterStoreDocumentPayload extends onStoreDocumentPayload {
|
|
199
221
|
}
|
|
200
222
|
export interface onAwarenessUpdatePayload {
|
|
201
|
-
clientsCount: number;
|
|
202
223
|
context: any;
|
|
203
224
|
document: Document;
|
|
204
225
|
documentName: string;
|
|
205
226
|
instance: Hocuspocus;
|
|
206
227
|
requestHeaders: IncomingHttpHeaders;
|
|
207
228
|
requestParameters: URLSearchParams;
|
|
208
|
-
update: Uint8Array;
|
|
209
229
|
socketId: string;
|
|
210
230
|
added: number[];
|
|
211
231
|
updated: number[];
|
|
@@ -264,6 +284,10 @@ export interface onConfigurePayload {
|
|
|
264
284
|
configuration: Configuration;
|
|
265
285
|
version: string;
|
|
266
286
|
}
|
|
287
|
+
export interface afterUnloadDocumentPayload {
|
|
288
|
+
instance: Hocuspocus;
|
|
289
|
+
documentName: string;
|
|
290
|
+
}
|
|
267
291
|
export interface DirectConnection {
|
|
268
292
|
transact(transaction: (document: Document) => void): Promise<void>;
|
|
269
293
|
disconnect(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-throttle",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"description": "hocuspocus throttle extension",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@hocuspocus/server": "^2.
|
|
31
|
+
"@hocuspocus/server": "^2.3.1"
|
|
32
32
|
},
|
|
33
33
|
"gitHead": "b3454a4ca289a84ddfb7fa5607a2d4b8d5c37e9d"
|
|
34
34
|
}
|