@hocuspocus/common 2.1.0-alpha.0 → 2.1.0
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-common.cjs +85 -84
- package/dist/hocuspocus-common.cjs.map +1 -1
- package/dist/hocuspocus-common.esm.js +85 -84
- package/dist/hocuspocus-common.esm.js.map +1 -1
- package/dist/packages/common/src/CloseEvents.d.ts +29 -29
- package/dist/packages/common/src/auth.d.ts +6 -6
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -3
- package/dist/packages/common/src/index.d.ts +4 -4
- package/dist/packages/common/src/types.d.ts +10 -10
- package/dist/packages/extension-database/src/Database.d.ts +30 -30
- package/dist/packages/extension-database/src/index.d.ts +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +67 -67
- package/dist/packages/extension-logger/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +116 -95
- package/dist/packages/extension-redis/src/index.d.ts +1 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -26
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
- package/dist/packages/extension-throttle/src/index.d.ts +31 -31
- package/dist/packages/extension-webhook/src/index.d.ts +57 -57
- package/dist/packages/provider/src/EventEmitter.d.ts +9 -9
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +110 -110
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +115 -115
- package/dist/packages/provider/src/IncomingMessage.d.ts +16 -16
- package/dist/packages/provider/src/MessageReceiver.d.ts +13 -13
- package/dist/packages/provider/src/MessageSender.d.ts +10 -10
- package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -9
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -7
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +7 -7
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -7
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +11 -11
- package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +11 -11
- package/dist/packages/provider/src/index.d.ts +5 -5
- package/dist/packages/provider/src/types.d.ts +84 -84
- package/dist/packages/server/src/Connection.d.ts +71 -71
- package/dist/packages/server/src/Debugger.d.ts +14 -14
- package/dist/packages/server/src/DirectConnection.d.ts +13 -0
- package/dist/packages/server/src/Document.d.ts +91 -88
- package/dist/packages/server/src/Hocuspocus.d.ts +111 -108
- package/dist/packages/server/src/IncomingMessage.d.ts +21 -21
- package/dist/packages/server/src/MessageReceiver.d.ts +12 -12
- package/dist/packages/server/src/OutgoingMessage.d.ts +20 -20
- package/dist/packages/server/src/index.d.ts +8 -8
- package/dist/packages/server/src/types.d.ts +266 -264
- package/dist/packages/transformer/src/Prosemirror.d.ts +11 -11
- package/dist/packages/transformer/src/Tiptap.d.ts +10 -10
- package/dist/packages/transformer/src/index.d.ts +3 -3
- package/dist/packages/transformer/src/types.d.ts +5 -5
- package/dist/playground/backend/src/default.d.ts +1 -1
- package/dist/playground/backend/src/express.d.ts +1 -1
- package/dist/playground/backend/src/koa.d.ts +1 -1
- package/dist/playground/backend/src/load-document.d.ts +1 -1
- package/dist/playground/backend/src/redis.d.ts +1 -1
- package/dist/playground/backend/src/slow.d.ts +1 -1
- package/dist/playground/backend/src/tiptapcollab.d.ts +1 -1
- package/dist/playground/backend/src/webhook.d.ts +1 -1
- package/dist/playground/frontend/src/main.d.ts +1 -1
- package/dist/playground/frontend/vite.config.d.ts +2 -2
- package/dist/tests/extension-database/fetch.d.ts +1 -1
- package/dist/tests/extension-logger/onListen.d.ts +1 -1
- package/dist/tests/extension-redis/closeConnections.d.ts +1 -1
- package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -1
- package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -1
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -1
- package/dist/tests/extension-redis/onChange.d.ts +1 -1
- package/dist/tests/extension-redis/onStateless.d.ts +1 -1
- package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -1
- package/dist/tests/extension-throttle/banning.d.ts +1 -1
- package/dist/tests/extension-throttle/configuration.d.ts +1 -1
- package/dist/tests/provider/observe.d.ts +1 -1
- package/dist/tests/provider/observeDeep.d.ts +1 -1
- package/dist/tests/provider/onAuthenticated.d.ts +1 -1
- package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -1
- package/dist/tests/provider/onAwarenessChange.d.ts +1 -1
- package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -1
- package/dist/tests/provider/onClose.d.ts +1 -1
- package/dist/tests/provider/onConnect.d.ts +1 -1
- package/dist/tests/provider/onDisconnect.d.ts +1 -1
- package/dist/tests/provider/onMessage.d.ts +1 -1
- package/dist/tests/provider/onOpen.d.ts +1 -1
- package/dist/tests/provider/onStateless.d.ts +1 -1
- package/dist/tests/provider/onSynced.d.ts +1 -1
- package/dist/tests/providerwebsocket/configuration.d.ts +1 -1
- package/dist/tests/server/address.d.ts +1 -1
- package/dist/tests/server/afterStoreDocument.d.ts +1 -1
- package/dist/tests/server/beforeBroadcastStateless.d.ts +1 -1
- package/dist/tests/server/beforeHandleMessage.d.ts +1 -1
- package/dist/tests/server/closeConnections.d.ts +1 -1
- package/dist/tests/server/getConnectionsCount.d.ts +1 -1
- package/dist/tests/server/getDocumentsCount.d.ts +1 -1
- package/dist/tests/server/getMessageLogs.d.ts +1 -1
- package/dist/tests/server/listen.d.ts +1 -1
- package/dist/tests/server/onAuthenticate.d.ts +1 -1
- package/dist/tests/server/onAwarenessUpdate.d.ts +1 -1
- package/dist/tests/server/onChange.d.ts +1 -1
- package/dist/tests/server/onClose.d.ts +1 -1
- package/dist/tests/server/onConfigure.d.ts +1 -1
- package/dist/tests/server/onConnect.d.ts +1 -1
- package/dist/tests/server/onDestroy.d.ts +1 -1
- package/dist/tests/server/onDisconnect.d.ts +1 -1
- package/dist/tests/server/onListen.d.ts +1 -1
- package/dist/tests/server/onLoadDocument.d.ts +1 -1
- package/dist/tests/server/onRequest.d.ts +1 -1
- package/dist/tests/server/onStateless.d.ts +1 -1
- package/dist/tests/server/onStoreDocument.d.ts +1 -1
- package/dist/tests/server/onUpgrade.d.ts +1 -1
- package/dist/tests/server/openDirectConnection.d.ts +1 -0
- package/dist/tests/server/requiresAuthentication.d.ts +1 -1
- package/dist/tests/server/websocketError.d.ts +1 -1
- package/dist/tests/transformer/TiptapTransformer.d.ts +1 -1
- package/dist/tests/utils/createDirectory.d.ts +1 -1
- package/dist/tests/utils/flushRedis.d.ts +1 -1
- package/dist/tests/utils/index.d.ts +9 -9
- package/dist/tests/utils/newHocuspocus.d.ts +2 -2
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -3
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +3 -3
- package/dist/tests/utils/randomInteger.d.ts +1 -1
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -4
- package/dist/tests/utils/removeDirectory.d.ts +1 -1
- package/dist/tests/utils/retryableAssertion.d.ts +2 -2
- package/dist/tests/utils/sleep.d.ts +1 -1
- package/package.json +3 -2
- package/src/auth.ts +4 -3
- package/src/index.ts +4 -4
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Extension, onConnectPayload } from '@hocuspocus/server';
|
|
3
|
-
export interface ThrottleConfiguration {
|
|
4
|
-
throttle: number | null | false;
|
|
5
|
-
consideredSeconds: number;
|
|
6
|
-
banTime: number;
|
|
7
|
-
cleanupInterval: number;
|
|
8
|
-
}
|
|
9
|
-
export declare class Throttle implements Extension {
|
|
10
|
-
configuration: ThrottleConfiguration;
|
|
11
|
-
connectionsByIp: Map<string, Array<number>>;
|
|
12
|
-
bannedIps: Map<string, number>;
|
|
13
|
-
cleanupInterval?: NodeJS.Timer;
|
|
14
|
-
/**
|
|
15
|
-
* Constructor
|
|
16
|
-
*/
|
|
17
|
-
constructor(configuration?: Partial<ThrottleConfiguration>);
|
|
18
|
-
onDestroy(): Promise<void>;
|
|
19
|
-
clearMaps(): void;
|
|
20
|
-
isBanned(ip: string): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Throttle requests
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
private throttle;
|
|
26
|
-
/**
|
|
27
|
-
* onConnect hook
|
|
28
|
-
* @param data
|
|
29
|
-
*/
|
|
30
|
-
onConnect(data: onConnectPayload): Promise<any>;
|
|
31
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Extension, onConnectPayload } from '@hocuspocus/server';
|
|
3
|
+
export interface ThrottleConfiguration {
|
|
4
|
+
throttle: number | null | false;
|
|
5
|
+
consideredSeconds: number;
|
|
6
|
+
banTime: number;
|
|
7
|
+
cleanupInterval: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class Throttle implements Extension {
|
|
10
|
+
configuration: ThrottleConfiguration;
|
|
11
|
+
connectionsByIp: Map<string, Array<number>>;
|
|
12
|
+
bannedIps: Map<string, number>;
|
|
13
|
+
cleanupInterval?: NodeJS.Timer;
|
|
14
|
+
/**
|
|
15
|
+
* Constructor
|
|
16
|
+
*/
|
|
17
|
+
constructor(configuration?: Partial<ThrottleConfiguration>);
|
|
18
|
+
onDestroy(): Promise<void>;
|
|
19
|
+
clearMaps(): void;
|
|
20
|
+
isBanned(ip: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Throttle requests
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
private throttle;
|
|
26
|
+
/**
|
|
27
|
+
* onConnect hook
|
|
28
|
+
* @param data
|
|
29
|
+
*/
|
|
30
|
+
onConnect(data: onConnectPayload): Promise<any>;
|
|
31
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
|
-
import { Doc } from 'yjs';
|
|
4
|
-
import { Transformer } from '@hocuspocus/transformer';
|
|
5
|
-
export declare enum Events {
|
|
6
|
-
onChange = "change",
|
|
7
|
-
onConnect = "connect",
|
|
8
|
-
onCreate = "create",
|
|
9
|
-
onDisconnect = "disconnect"
|
|
10
|
-
}
|
|
11
|
-
export interface Configuration {
|
|
12
|
-
debounce: number | false | null;
|
|
13
|
-
debounceMaxWait: number;
|
|
14
|
-
secret: string;
|
|
15
|
-
transformer: Transformer | {
|
|
16
|
-
toYdoc: (document: any) => Doc;
|
|
17
|
-
fromYdoc: (document: Doc) => any;
|
|
18
|
-
};
|
|
19
|
-
url: string;
|
|
20
|
-
events: Array<Events>;
|
|
21
|
-
}
|
|
22
|
-
export declare class Webhook implements Extension {
|
|
23
|
-
configuration: Configuration;
|
|
24
|
-
debounced: Map<string, {
|
|
25
|
-
timeout: NodeJS.Timeout;
|
|
26
|
-
start: number;
|
|
27
|
-
}>;
|
|
28
|
-
/**
|
|
29
|
-
* Constructor
|
|
30
|
-
*/
|
|
31
|
-
constructor(configuration?: Partial<Configuration>);
|
|
32
|
-
/**
|
|
33
|
-
* Create a signature for the response body
|
|
34
|
-
*/
|
|
35
|
-
createSignature(body: string): string;
|
|
36
|
-
/**
|
|
37
|
-
* debounce the given function, using the given identifier
|
|
38
|
-
*/
|
|
39
|
-
debounce(id: string, func: Function): void;
|
|
40
|
-
/**
|
|
41
|
-
* Send a request to the given url containing the given data
|
|
42
|
-
*/
|
|
43
|
-
sendRequest(event: Events, payload: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
44
|
-
/**
|
|
45
|
-
* onChange hook
|
|
46
|
-
*/
|
|
47
|
-
onChange(data: onChangePayload): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* onLoadDocument hook
|
|
50
|
-
*/
|
|
51
|
-
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
52
|
-
/**
|
|
53
|
-
* onConnect hook
|
|
54
|
-
*/
|
|
55
|
-
onConnect(data: onConnectPayload): Promise<any>;
|
|
56
|
-
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
57
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
|
+
import { Doc } from 'yjs';
|
|
4
|
+
import { Transformer } from '@hocuspocus/transformer';
|
|
5
|
+
export declare enum Events {
|
|
6
|
+
onChange = "change",
|
|
7
|
+
onConnect = "connect",
|
|
8
|
+
onCreate = "create",
|
|
9
|
+
onDisconnect = "disconnect"
|
|
10
|
+
}
|
|
11
|
+
export interface Configuration {
|
|
12
|
+
debounce: number | false | null;
|
|
13
|
+
debounceMaxWait: number;
|
|
14
|
+
secret: string;
|
|
15
|
+
transformer: Transformer | {
|
|
16
|
+
toYdoc: (document: any) => Doc;
|
|
17
|
+
fromYdoc: (document: Doc) => any;
|
|
18
|
+
};
|
|
19
|
+
url: string;
|
|
20
|
+
events: Array<Events>;
|
|
21
|
+
}
|
|
22
|
+
export declare class Webhook implements Extension {
|
|
23
|
+
configuration: Configuration;
|
|
24
|
+
debounced: Map<string, {
|
|
25
|
+
timeout: NodeJS.Timeout;
|
|
26
|
+
start: number;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Constructor
|
|
30
|
+
*/
|
|
31
|
+
constructor(configuration?: Partial<Configuration>);
|
|
32
|
+
/**
|
|
33
|
+
* Create a signature for the response body
|
|
34
|
+
*/
|
|
35
|
+
createSignature(body: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* debounce the given function, using the given identifier
|
|
38
|
+
*/
|
|
39
|
+
debounce(id: string, func: Function): void;
|
|
40
|
+
/**
|
|
41
|
+
* Send a request to the given url containing the given data
|
|
42
|
+
*/
|
|
43
|
+
sendRequest(event: Events, payload: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
44
|
+
/**
|
|
45
|
+
* onChange hook
|
|
46
|
+
*/
|
|
47
|
+
onChange(data: onChangePayload): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* onLoadDocument hook
|
|
50
|
+
*/
|
|
51
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* onConnect hook
|
|
54
|
+
*/
|
|
55
|
+
onConnect(data: onConnectPayload): Promise<any>;
|
|
56
|
+
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
57
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export default class EventEmitter {
|
|
2
|
-
callbacks: {
|
|
3
|
-
[key: string]: Function[];
|
|
4
|
-
};
|
|
5
|
-
on(event: string, fn: Function): this;
|
|
6
|
-
protected emit(event: string, ...args: any): this;
|
|
7
|
-
off(event: string, fn?: Function): this;
|
|
8
|
-
removeAllListeners(): void;
|
|
9
|
-
}
|
|
1
|
+
export default class EventEmitter {
|
|
2
|
+
callbacks: {
|
|
3
|
+
[key: string]: Function[];
|
|
4
|
+
};
|
|
5
|
+
on(event: string, fn: Function): this;
|
|
6
|
+
protected emit(event: string, ...args: any): this;
|
|
7
|
+
off(event: string, fn?: Function): this;
|
|
8
|
+
removeAllListeners(): void;
|
|
9
|
+
}
|
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
-
import * as mutex from 'lib0/mutex';
|
|
4
|
-
import type { CloseEvent, Event, MessageEvent } from 'ws';
|
|
5
|
-
import EventEmitter from './EventEmitter';
|
|
6
|
-
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
7
|
-
import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket';
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
mux: mutex.mutex;
|
|
72
|
-
intervals: any;
|
|
73
|
-
isConnected: boolean;
|
|
74
|
-
constructor(configuration: HocuspocusProviderConfiguration);
|
|
75
|
-
onStatus({ status }: onStatusParameters): void;
|
|
76
|
-
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
77
|
-
get document(): Y.Doc;
|
|
78
|
-
get awareness(): Awareness;
|
|
79
|
-
get hasUnsyncedChanges(): boolean;
|
|
80
|
-
updateUnsyncedChanges(unsyncedChanges?: number): void;
|
|
81
|
-
forceSync(): void;
|
|
82
|
-
boundBeforeUnload: () => void;
|
|
83
|
-
beforeUnload(): void;
|
|
84
|
-
registerEventListeners(): void;
|
|
85
|
-
sendStateless(payload: string): void;
|
|
86
|
-
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
87
|
-
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
88
|
-
get synced(): boolean;
|
|
89
|
-
set synced(state: boolean);
|
|
90
|
-
receiveStateless(payload: string): void;
|
|
91
|
-
get isAuthenticationRequired(): boolean;
|
|
92
|
-
connect(): Promise<unknown>;
|
|
93
|
-
disconnect(): void;
|
|
94
|
-
onOpen(event: Event): Promise<void>;
|
|
95
|
-
getToken(): Promise<string | null>;
|
|
96
|
-
startSync(): void;
|
|
97
|
-
send(message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
|
|
98
|
-
onMessage(event: MessageEvent): void;
|
|
99
|
-
onClose(event: CloseEvent): void;
|
|
100
|
-
destroy(): void;
|
|
101
|
-
permissionDeniedHandler(reason: string): void;
|
|
102
|
-
authenticatedHandler(): void;
|
|
103
|
-
get broadcastChannel(): string;
|
|
104
|
-
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
105
|
-
broadcastChannelSubscriber(data: ArrayBuffer): void;
|
|
106
|
-
subscribeToBroadcastChannel(): void;
|
|
107
|
-
disconnectBroadcastChannel(): void;
|
|
108
|
-
broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
|
|
109
|
-
setAwarenessField(key: string, value: any): void;
|
|
110
|
-
}
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
+
import * as mutex from 'lib0/mutex';
|
|
4
|
+
import type { CloseEvent, Event, MessageEvent } from 'ws';
|
|
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
|
+
import { CompleteHocuspocusProviderWebsocketConfiguration, HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
|
|
8
|
+
export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
|
|
9
|
+
export interface CompleteHocuspocusProviderConfiguration {
|
|
10
|
+
/**
|
|
11
|
+
* The identifier/name of your document
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* The actual Y.js document
|
|
16
|
+
*/
|
|
17
|
+
document: Y.Doc;
|
|
18
|
+
/**
|
|
19
|
+
* Pass false to disable broadcasting between browser tabs.
|
|
20
|
+
*/
|
|
21
|
+
broadcast: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* An Awareness instance to keep the presence state of all clients.
|
|
24
|
+
*/
|
|
25
|
+
awareness: Awareness;
|
|
26
|
+
/**
|
|
27
|
+
* A token that’s sent to the backend for authentication purposes.
|
|
28
|
+
*/
|
|
29
|
+
token: string | (() => string) | (() => Promise<string>) | null;
|
|
30
|
+
/**
|
|
31
|
+
* URL parameters that should be added.
|
|
32
|
+
*/
|
|
33
|
+
parameters: {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Hocuspocus websocket provider
|
|
38
|
+
*/
|
|
39
|
+
websocketProvider: HocuspocusProviderWebsocket;
|
|
40
|
+
/**
|
|
41
|
+
* Force syncing the document in the defined interval.
|
|
42
|
+
*/
|
|
43
|
+
forceSyncInterval: false | number;
|
|
44
|
+
onAuthenticated: () => void;
|
|
45
|
+
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
46
|
+
onOpen: (data: onOpenParameters) => void;
|
|
47
|
+
onConnect: () => void;
|
|
48
|
+
onMessage: (data: onMessageParameters) => void;
|
|
49
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
50
|
+
onStatus: (data: onStatusParameters) => void;
|
|
51
|
+
onSynced: (data: onSyncedParameters) => void;
|
|
52
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
53
|
+
onClose: (data: onCloseParameters) => void;
|
|
54
|
+
onDestroy: () => void;
|
|
55
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
56
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
57
|
+
onStateless: (data: onStatelessParameters) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Don’t output any warnings.
|
|
60
|
+
*/
|
|
61
|
+
quiet: boolean;
|
|
62
|
+
}
|
|
63
|
+
export declare class HocuspocusProvider extends EventEmitter {
|
|
64
|
+
configuration: CompleteHocuspocusProviderConfiguration;
|
|
65
|
+
subscribedToBroadcastChannel: boolean;
|
|
66
|
+
isSynced: boolean;
|
|
67
|
+
unsyncedChanges: number;
|
|
68
|
+
status: WebSocketStatus;
|
|
69
|
+
isAuthenticated: boolean;
|
|
70
|
+
authorizedScope: string | undefined;
|
|
71
|
+
mux: mutex.mutex;
|
|
72
|
+
intervals: any;
|
|
73
|
+
isConnected: boolean;
|
|
74
|
+
constructor(configuration: HocuspocusProviderConfiguration);
|
|
75
|
+
onStatus({ status }: onStatusParameters): void;
|
|
76
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
77
|
+
get document(): Y.Doc;
|
|
78
|
+
get awareness(): Awareness;
|
|
79
|
+
get hasUnsyncedChanges(): boolean;
|
|
80
|
+
updateUnsyncedChanges(unsyncedChanges?: number): void;
|
|
81
|
+
forceSync(): void;
|
|
82
|
+
boundBeforeUnload: () => void;
|
|
83
|
+
beforeUnload(): void;
|
|
84
|
+
registerEventListeners(): void;
|
|
85
|
+
sendStateless(payload: string): void;
|
|
86
|
+
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
87
|
+
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
88
|
+
get synced(): boolean;
|
|
89
|
+
set synced(state: boolean);
|
|
90
|
+
receiveStateless(payload: string): void;
|
|
91
|
+
get isAuthenticationRequired(): boolean;
|
|
92
|
+
connect(): Promise<unknown>;
|
|
93
|
+
disconnect(): void;
|
|
94
|
+
onOpen(event: Event): Promise<void>;
|
|
95
|
+
getToken(): Promise<string | null>;
|
|
96
|
+
startSync(): void;
|
|
97
|
+
send(message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
|
|
98
|
+
onMessage(event: MessageEvent): void;
|
|
99
|
+
onClose(event: CloseEvent): void;
|
|
100
|
+
destroy(): void;
|
|
101
|
+
permissionDeniedHandler(reason: string): void;
|
|
102
|
+
authenticatedHandler(scope: string): void;
|
|
103
|
+
get broadcastChannel(): string;
|
|
104
|
+
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
105
|
+
broadcastChannelSubscriber(data: ArrayBuffer): void;
|
|
106
|
+
subscribeToBroadcastChannel(): void;
|
|
107
|
+
disconnectBroadcastChannel(): void;
|
|
108
|
+
broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
|
|
109
|
+
setAwarenessField(key: string, value: any): void;
|
|
110
|
+
}
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import * as mutex from 'lib0/mutex';
|
|
2
|
-
import type { MessageEvent } from 'ws';
|
|
3
|
-
import { Event } from 'ws';
|
|
4
|
-
import EventEmitter from './EventEmitter';
|
|
5
|
-
import { onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, WebSocketStatus } from './types';
|
|
6
|
-
import { HocuspocusProvider
|
|
7
|
-
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
8
|
-
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
9
|
-
/**
|
|
10
|
-
* URL of your @hocuspocus/server instance
|
|
11
|
-
*/
|
|
12
|
-
url: string;
|
|
13
|
-
/**
|
|
14
|
-
* Pass `false` to start the connection manually.
|
|
15
|
-
*/
|
|
16
|
-
connect: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* URL parameters that should be added.
|
|
19
|
-
*/
|
|
20
|
-
parameters: {
|
|
21
|
-
[key: string]: any;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* An optional WebSocket polyfill, for example for Node.js
|
|
25
|
-
*/
|
|
26
|
-
WebSocketPolyfill: any;
|
|
27
|
-
/**
|
|
28
|
-
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
29
|
-
*/
|
|
30
|
-
messageReconnectTimeout: number;
|
|
31
|
-
/**
|
|
32
|
-
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
33
|
-
*/
|
|
34
|
-
delay: number;
|
|
35
|
-
/**
|
|
36
|
-
* 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.
|
|
37
|
-
*/
|
|
38
|
-
initialDelay: number;
|
|
39
|
-
/**
|
|
40
|
-
* The factor option is used to grow the delay exponentially.
|
|
41
|
-
*/
|
|
42
|
-
factor: number;
|
|
43
|
-
/**
|
|
44
|
-
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
45
|
-
*/
|
|
46
|
-
maxAttempts: number;
|
|
47
|
-
/**
|
|
48
|
-
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
49
|
-
*/
|
|
50
|
-
minDelay: number;
|
|
51
|
-
/**
|
|
52
|
-
* 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.
|
|
53
|
-
*/
|
|
54
|
-
maxDelay: number;
|
|
55
|
-
/**
|
|
56
|
-
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
57
|
-
*/
|
|
58
|
-
jitter: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* 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.
|
|
61
|
-
*/
|
|
62
|
-
timeout: number;
|
|
63
|
-
onOpen: (data: onOpenParameters) => void;
|
|
64
|
-
onConnect: () => void;
|
|
65
|
-
onMessage: (data: onMessageParameters) => void;
|
|
66
|
-
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
67
|
-
onStatus: (data: onStatusParameters) => void;
|
|
68
|
-
onDisconnect: (data: onDisconnectParameters) => void;
|
|
69
|
-
onClose: (data: onCloseParameters) => void;
|
|
70
|
-
onDestroy: () => void;
|
|
71
|
-
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
72
|
-
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
73
|
-
/**
|
|
74
|
-
* Don’t output any warnings.
|
|
75
|
-
*/
|
|
76
|
-
quiet: boolean;
|
|
77
|
-
}
|
|
78
|
-
export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
79
|
-
configuration: CompleteHocuspocusProviderWebsocketConfiguration;
|
|
80
|
-
subscribedToBroadcastChannel: boolean;
|
|
81
|
-
webSocket: WebSocket | null;
|
|
82
|
-
shouldConnect: boolean;
|
|
83
|
-
status: WebSocketStatus;
|
|
84
|
-
lastMessageReceived: number;
|
|
85
|
-
mux: mutex.mutex;
|
|
86
|
-
intervals: any;
|
|
87
|
-
connectionAttempt: {
|
|
88
|
-
resolve: (value?: any) => void;
|
|
89
|
-
reject: (reason?: any) => void;
|
|
90
|
-
} | null;
|
|
91
|
-
constructor(configuration: HocuspocusProviderWebsocketConfiguration);
|
|
92
|
-
receivedOnOpenPayload?: Event | undefined;
|
|
93
|
-
receivedOnStatusPayload?: onStatusParameters | undefined;
|
|
94
|
-
onOpen(event: Event): Promise<void>;
|
|
95
|
-
onStatus(data: onStatusParameters): Promise<void>;
|
|
96
|
-
attach(provider: HocuspocusProvider): void;
|
|
97
|
-
detach(provider: HocuspocusProvider): void;
|
|
98
|
-
setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
|
|
99
|
-
boundConnect: () => Promise<unknown>;
|
|
100
|
-
cancelWebsocketRetry?: () => void;
|
|
101
|
-
connect(): Promise<unknown>;
|
|
102
|
-
createWebSocketConnection(): Promise<unknown>;
|
|
103
|
-
onMessage(event: MessageEvent): void;
|
|
104
|
-
resolveConnectionAttempt(): void;
|
|
105
|
-
stopConnectionAttempt(): void;
|
|
106
|
-
rejectConnectionAttempt(): void;
|
|
107
|
-
checkConnection(): void;
|
|
108
|
-
registerEventListeners(): void;
|
|
109
|
-
get serverUrl(): string;
|
|
110
|
-
get url(): string;
|
|
111
|
-
disconnect(): void;
|
|
112
|
-
send(message: any): void;
|
|
113
|
-
onClose({ event }: onCloseParameters): void;
|
|
114
|
-
destroy(): void;
|
|
115
|
-
}
|
|
1
|
+
import * as mutex from 'lib0/mutex';
|
|
2
|
+
import type { MessageEvent } from 'ws';
|
|
3
|
+
import { Event } from 'ws';
|
|
4
|
+
import EventEmitter from './EventEmitter.js';
|
|
5
|
+
import { onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, WebSocketStatus, onAwarenessChangeParameters, onAwarenessUpdateParameters } from './types.js';
|
|
6
|
+
import { HocuspocusProvider } from './HocuspocusProvider.js';
|
|
7
|
+
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
8
|
+
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
9
|
+
/**
|
|
10
|
+
* URL of your @hocuspocus/server instance
|
|
11
|
+
*/
|
|
12
|
+
url: string;
|
|
13
|
+
/**
|
|
14
|
+
* Pass `false` to start the connection manually.
|
|
15
|
+
*/
|
|
16
|
+
connect: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* URL parameters that should be added.
|
|
19
|
+
*/
|
|
20
|
+
parameters: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* An optional WebSocket polyfill, for example for Node.js
|
|
25
|
+
*/
|
|
26
|
+
WebSocketPolyfill: any;
|
|
27
|
+
/**
|
|
28
|
+
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
29
|
+
*/
|
|
30
|
+
messageReconnectTimeout: number;
|
|
31
|
+
/**
|
|
32
|
+
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
33
|
+
*/
|
|
34
|
+
delay: number;
|
|
35
|
+
/**
|
|
36
|
+
* 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.
|
|
37
|
+
*/
|
|
38
|
+
initialDelay: number;
|
|
39
|
+
/**
|
|
40
|
+
* The factor option is used to grow the delay exponentially.
|
|
41
|
+
*/
|
|
42
|
+
factor: number;
|
|
43
|
+
/**
|
|
44
|
+
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
45
|
+
*/
|
|
46
|
+
maxAttempts: number;
|
|
47
|
+
/**
|
|
48
|
+
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
49
|
+
*/
|
|
50
|
+
minDelay: number;
|
|
51
|
+
/**
|
|
52
|
+
* 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.
|
|
53
|
+
*/
|
|
54
|
+
maxDelay: number;
|
|
55
|
+
/**
|
|
56
|
+
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
57
|
+
*/
|
|
58
|
+
jitter: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 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.
|
|
61
|
+
*/
|
|
62
|
+
timeout: number;
|
|
63
|
+
onOpen: (data: onOpenParameters) => void;
|
|
64
|
+
onConnect: () => void;
|
|
65
|
+
onMessage: (data: onMessageParameters) => void;
|
|
66
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
67
|
+
onStatus: (data: onStatusParameters) => void;
|
|
68
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
69
|
+
onClose: (data: onCloseParameters) => void;
|
|
70
|
+
onDestroy: () => void;
|
|
71
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
72
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Don’t output any warnings.
|
|
75
|
+
*/
|
|
76
|
+
quiet: boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
79
|
+
configuration: CompleteHocuspocusProviderWebsocketConfiguration;
|
|
80
|
+
subscribedToBroadcastChannel: boolean;
|
|
81
|
+
webSocket: WebSocket | null;
|
|
82
|
+
shouldConnect: boolean;
|
|
83
|
+
status: WebSocketStatus;
|
|
84
|
+
lastMessageReceived: number;
|
|
85
|
+
mux: mutex.mutex;
|
|
86
|
+
intervals: any;
|
|
87
|
+
connectionAttempt: {
|
|
88
|
+
resolve: (value?: any) => void;
|
|
89
|
+
reject: (reason?: any) => void;
|
|
90
|
+
} | null;
|
|
91
|
+
constructor(configuration: HocuspocusProviderWebsocketConfiguration);
|
|
92
|
+
receivedOnOpenPayload?: Event | undefined;
|
|
93
|
+
receivedOnStatusPayload?: onStatusParameters | undefined;
|
|
94
|
+
onOpen(event: Event): Promise<void>;
|
|
95
|
+
onStatus(data: onStatusParameters): Promise<void>;
|
|
96
|
+
attach(provider: HocuspocusProvider): void;
|
|
97
|
+
detach(provider: HocuspocusProvider): void;
|
|
98
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
|
|
99
|
+
boundConnect: () => Promise<unknown>;
|
|
100
|
+
cancelWebsocketRetry?: () => void;
|
|
101
|
+
connect(): Promise<unknown>;
|
|
102
|
+
createWebSocketConnection(): Promise<unknown>;
|
|
103
|
+
onMessage(event: MessageEvent): void;
|
|
104
|
+
resolveConnectionAttempt(): void;
|
|
105
|
+
stopConnectionAttempt(): void;
|
|
106
|
+
rejectConnectionAttempt(): void;
|
|
107
|
+
checkConnection(): void;
|
|
108
|
+
registerEventListeners(): void;
|
|
109
|
+
get serverUrl(): string;
|
|
110
|
+
get url(): string;
|
|
111
|
+
disconnect(): void;
|
|
112
|
+
send(message: any): void;
|
|
113
|
+
onClose({ event }: onCloseParameters): void;
|
|
114
|
+
destroy(): void;
|
|
115
|
+
}
|