@hocuspocus/provider 3.4.4 → 3.4.5-rc.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-provider.cjs +1836 -2085
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +1803 -2062
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/index.d.ts +558 -0
- package/dist/index.js +1940 -0
- package/package.json +4 -4
- package/dist/node_modules/@tiptap/pm/model/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/state/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/transform/index.d.ts +0 -1
- package/dist/node_modules/@tiptap/pm/view/index.d.ts +0 -1
- package/dist/packages/common/src/CloseEvents.d.ts +0 -29
- package/dist/packages/common/src/auth.d.ts +0 -13
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +0 -3
- package/dist/packages/common/src/index.d.ts +0 -4
- package/dist/packages/common/src/types.d.ts +0 -10
- package/dist/packages/extension-database/src/Database.d.ts +0 -30
- package/dist/packages/extension-database/src/index.d.ts +0 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +0 -67
- package/dist/packages/extension-logger/src/index.d.ts +0 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +0 -124
- package/dist/packages/extension-redis/src/index.d.ts +0 -1
- package/dist/packages/extension-s3/src/S3.d.ts +0 -44
- package/dist/packages/extension-s3/src/index.d.ts +0 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +0 -27
- package/dist/packages/extension-sqlite/src/index.d.ts +0 -1
- package/dist/packages/extension-throttle/src/index.d.ts +0 -30
- package/dist/packages/extension-webhook/src/index.d.ts +0 -56
- package/dist/packages/provider/src/EventEmitter.d.ts +0 -9
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +0 -116
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +0 -119
- package/dist/packages/provider/src/IncomingMessage.d.ts +0 -17
- package/dist/packages/provider/src/MessageReceiver.d.ts +0 -12
- package/dist/packages/provider/src/MessageSender.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +0 -8
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +0 -8
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +0 -9
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +0 -8
- package/dist/packages/provider/src/index.d.ts +0 -3
- package/dist/packages/provider/src/types.d.ts +0 -93
- package/dist/packages/server/src/ClientConnection.d.ts +0 -63
- package/dist/packages/server/src/Connection.d.ts +0 -75
- package/dist/packages/server/src/DirectConnection.d.ts +0 -14
- package/dist/packages/server/src/Document.d.ts +0 -92
- package/dist/packages/server/src/Hocuspocus.d.ts +0 -80
- package/dist/packages/server/src/IncomingMessage.d.ts +0 -25
- package/dist/packages/server/src/MessageReceiver.d.ts +0 -11
- package/dist/packages/server/src/OutgoingMessage.d.ts +0 -23
- package/dist/packages/server/src/Server.d.ts +0 -32
- package/dist/packages/server/src/index.d.ts +0 -9
- package/dist/packages/server/src/types.d.ts +0 -342
- package/dist/packages/server/src/util/debounce.d.ts +0 -6
- package/dist/packages/server/src/util/getParameters.d.ts +0 -6
- package/dist/packages/transformer/src/Prosemirror.d.ts +0 -11
- package/dist/packages/transformer/src/Tiptap.d.ts +0 -10
- package/dist/packages/transformer/src/index.d.ts +0 -3
- package/dist/packages/transformer/src/types.d.ts +0 -5
- package/dist/playground/backend/src/default.d.ts +0 -1
- package/dist/playground/backend/src/deno.d.ts +0 -1
- package/dist/playground/backend/src/express.d.ts +0 -1
- package/dist/playground/backend/src/hono.d.ts +0 -1
- package/dist/playground/backend/src/koa.d.ts +0 -1
- package/dist/playground/backend/src/load-document.d.ts +0 -1
- package/dist/playground/backend/src/redis.d.ts +0 -1
- package/dist/playground/backend/src/s3-redis.d.ts +0 -1
- package/dist/playground/backend/src/s3.d.ts +0 -1
- package/dist/playground/backend/src/slow.d.ts +0 -1
- package/dist/playground/backend/src/tiptapcollab.d.ts +0 -1
- package/dist/playground/backend/src/webhook.d.ts +0 -1
- package/dist/playground/frontend/app/SocketContext1.d.ts +0 -2
- package/dist/playground/frontend/app/SocketContext2.d.ts +0 -2
- package/dist/playground/frontend/next.config.d.ts +0 -3
- package/dist/tests/extension-database/fetch.d.ts +0 -1
- package/dist/tests/extension-logger/onListen.d.ts +0 -1
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +0 -1
- package/dist/tests/extension-redis/onChange.d.ts +0 -1
- package/dist/tests/extension-redis/onStateless.d.ts +0 -1
- package/dist/tests/extension-redis/onStoreDocument.d.ts +0 -1
- package/dist/tests/extension-s3/fetch.d.ts +0 -1
- package/dist/tests/extension-throttle/banning.d.ts +0 -1
- package/dist/tests/extension-throttle/configuration.d.ts +0 -1
- package/dist/tests/provider/hasUnsyncedChanges.d.ts +0 -1
- package/dist/tests/provider/observe.d.ts +0 -1
- package/dist/tests/provider/observeDeep.d.ts +0 -1
- package/dist/tests/provider/onAuthenticated.d.ts +0 -1
- package/dist/tests/provider/onAuthenticationFailed.d.ts +0 -1
- package/dist/tests/provider/onAwarenessChange.d.ts +0 -1
- package/dist/tests/provider/onAwarenessUpdate.d.ts +0 -1
- package/dist/tests/provider/onClose.d.ts +0 -1
- package/dist/tests/provider/onConnect.d.ts +0 -1
- package/dist/tests/provider/onDisconnect.d.ts +0 -1
- package/dist/tests/provider/onMessage.d.ts +0 -1
- package/dist/tests/provider/onOpen.d.ts +0 -1
- package/dist/tests/provider/onStateless.d.ts +0 -1
- package/dist/tests/provider/onSynced.d.ts +0 -1
- package/dist/tests/providerwebsocket/configuration.d.ts +0 -1
- package/dist/tests/server/address.d.ts +0 -1
- package/dist/tests/server/afterLoadDocument.d.ts +0 -1
- package/dist/tests/server/afterStoreDocument.d.ts +0 -1
- package/dist/tests/server/afterUnloadDocument.d.ts +0 -1
- package/dist/tests/server/beforeBroadcastStateless.d.ts +0 -1
- package/dist/tests/server/beforeHandleMessage.d.ts +0 -1
- package/dist/tests/server/beforeSync.d.ts +0 -1
- package/dist/tests/server/beforeUnloadDocument.d.ts +0 -1
- package/dist/tests/server/closeConnections.d.ts +0 -1
- package/dist/tests/server/getConnectionsCount.d.ts +0 -1
- package/dist/tests/server/getDocumentsCount.d.ts +0 -1
- package/dist/tests/server/listen.d.ts +0 -1
- package/dist/tests/server/onAuthenticate.d.ts +0 -1
- package/dist/tests/server/onAwarenessUpdate.d.ts +0 -1
- package/dist/tests/server/onChange.d.ts +0 -1
- package/dist/tests/server/onClose.d.ts +0 -1
- package/dist/tests/server/onConfigure.d.ts +0 -1
- package/dist/tests/server/onConnect.d.ts +0 -1
- package/dist/tests/server/onDestroy.d.ts +0 -1
- package/dist/tests/server/onDisconnect.d.ts +0 -1
- package/dist/tests/server/onListen.d.ts +0 -1
- package/dist/tests/server/onLoadDocument.d.ts +0 -1
- package/dist/tests/server/onRequest.d.ts +0 -1
- package/dist/tests/server/onStateless.d.ts +0 -1
- package/dist/tests/server/onStoreDocument.d.ts +0 -1
- package/dist/tests/server/onTokenSync.d.ts +0 -1
- package/dist/tests/server/onUpgrade.d.ts +0 -1
- package/dist/tests/server/openDirectConnection.d.ts +0 -1
- package/dist/tests/server/websocketError.d.ts +0 -1
- package/dist/tests/transformer/TiptapTransformer.d.ts +0 -1
- package/dist/tests/utils/createDirectory.d.ts +0 -1
- package/dist/tests/utils/flushRedis.d.ts +0 -1
- package/dist/tests/utils/index.d.ts +0 -9
- package/dist/tests/utils/newHocuspocus.d.ts +0 -2
- package/dist/tests/utils/newHocuspocusProvider.d.ts +0 -3
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +0 -4
- package/dist/tests/utils/randomInteger.d.ts +0 -1
- package/dist/tests/utils/redisConnectionSettings.d.ts +0 -4
- package/dist/tests/utils/removeDirectory.d.ts +0 -1
- package/dist/tests/utils/retryableAssertion.d.ts +0 -2
- package/dist/tests/utils/sleep.d.ts +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
import { CloseEvent } from "@hocuspocus/common";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
import { Event, MessageEvent } from "ws";
|
|
4
|
+
|
|
5
|
+
//#region node_modules/lib0/observable.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Handles named events.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated
|
|
10
|
+
* @template N
|
|
11
|
+
*/
|
|
12
|
+
declare class Observable<N> {
|
|
13
|
+
/**
|
|
14
|
+
* Some desc.
|
|
15
|
+
* @type {Map<N, any>}
|
|
16
|
+
*/
|
|
17
|
+
_observers: Map<N, any>;
|
|
18
|
+
/**
|
|
19
|
+
* @param {N} name
|
|
20
|
+
* @param {function} f
|
|
21
|
+
*/
|
|
22
|
+
on(name: N, f: Function): void;
|
|
23
|
+
/**
|
|
24
|
+
* @param {N} name
|
|
25
|
+
* @param {function} f
|
|
26
|
+
*/
|
|
27
|
+
once(name: N, f: Function): void;
|
|
28
|
+
/**
|
|
29
|
+
* @param {N} name
|
|
30
|
+
* @param {function} f
|
|
31
|
+
*/
|
|
32
|
+
off(name: N, f: Function): void;
|
|
33
|
+
/**
|
|
34
|
+
* Emit a named event. All registered event listeners that listen to the
|
|
35
|
+
* specified name will receive the event.
|
|
36
|
+
*
|
|
37
|
+
* @todo This should catch exceptions
|
|
38
|
+
*
|
|
39
|
+
* @param {N} name The event name.
|
|
40
|
+
* @param {Array<any>} args The arguments that are applied to the event listener.
|
|
41
|
+
*/
|
|
42
|
+
emit(name: N, args: Array<any>): void;
|
|
43
|
+
destroy(): void;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region node_modules/y-protocols/awareness.d.ts
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {Object} MetaClientState
|
|
49
|
+
* @property {number} MetaClientState.clock
|
|
50
|
+
* @property {number} MetaClientState.lastUpdated unix timestamp
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* The Awareness class implements a simple shared state protocol that can be used for non-persistent data like awareness information
|
|
54
|
+
* (cursor, username, status, ..). Each client can update its own local state and listen to state changes of
|
|
55
|
+
* remote clients. Every client may set a state of a remote peer to `null` to mark the client as offline.
|
|
56
|
+
*
|
|
57
|
+
* Each client is identified by a unique client id (something we borrow from `doc.clientID`). A client can override
|
|
58
|
+
* its own state by propagating a message with an increasing timestamp (`clock`). If such a message is received, it is
|
|
59
|
+
* applied if the known state of that client is older than the new state (`clock < newClock`). If a client thinks that
|
|
60
|
+
* a remote client is offline, it may propagate a message with
|
|
61
|
+
* `{ clock: currentClientClock, state: null, client: remoteClient }`. If such a
|
|
62
|
+
* message is received, and the known clock of that client equals the received clock, it will override the state with `null`.
|
|
63
|
+
*
|
|
64
|
+
* Before a client disconnects, it should propagate a `null` state with an updated clock.
|
|
65
|
+
*
|
|
66
|
+
* Awareness states must be updated every 30 seconds. Otherwise the Awareness instance will delete the client state.
|
|
67
|
+
*
|
|
68
|
+
* @extends {Observable<string>}
|
|
69
|
+
*/
|
|
70
|
+
declare class Awareness extends Observable<string> {
|
|
71
|
+
/**
|
|
72
|
+
* @param {Y.Doc} doc
|
|
73
|
+
*/
|
|
74
|
+
constructor(doc: Y.Doc);
|
|
75
|
+
doc: Y.Doc;
|
|
76
|
+
/**
|
|
77
|
+
* @type {number}
|
|
78
|
+
*/
|
|
79
|
+
clientID: number;
|
|
80
|
+
/**
|
|
81
|
+
* Maps from client id to client state
|
|
82
|
+
* @type {Map<number, Object<string, any>>}
|
|
83
|
+
*/
|
|
84
|
+
states: Map<number, {
|
|
85
|
+
[x: string]: any;
|
|
86
|
+
}>;
|
|
87
|
+
/**
|
|
88
|
+
* @type {Map<number, MetaClientState>}
|
|
89
|
+
*/
|
|
90
|
+
meta: Map<number, MetaClientState>;
|
|
91
|
+
_checkInterval: any;
|
|
92
|
+
/**
|
|
93
|
+
* @return {Object<string,any>|null}
|
|
94
|
+
*/
|
|
95
|
+
getLocalState(): {
|
|
96
|
+
[x: string]: any;
|
|
97
|
+
} | null;
|
|
98
|
+
/**
|
|
99
|
+
* @param {Object<string,any>|null} state
|
|
100
|
+
*/
|
|
101
|
+
setLocalState(state: {
|
|
102
|
+
[x: string]: any;
|
|
103
|
+
} | null): void;
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} field
|
|
106
|
+
* @param {any} value
|
|
107
|
+
*/
|
|
108
|
+
setLocalStateField(field: string, value: any): void;
|
|
109
|
+
/**
|
|
110
|
+
* @return {Map<number,Object<string,any>>}
|
|
111
|
+
*/
|
|
112
|
+
getStates(): Map<number, {
|
|
113
|
+
[x: string]: any;
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
type MetaClientState = {
|
|
117
|
+
clock: number;
|
|
118
|
+
/**
|
|
119
|
+
* unix timestamp
|
|
120
|
+
*/
|
|
121
|
+
lastUpdated: number;
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region packages/provider/src/EventEmitter.d.ts
|
|
125
|
+
declare class EventEmitter {
|
|
126
|
+
callbacks: {
|
|
127
|
+
[key: string]: Function[];
|
|
128
|
+
};
|
|
129
|
+
on(event: string, fn: Function): this;
|
|
130
|
+
protected emit(event: string, ...args: any): this;
|
|
131
|
+
off(event: string, fn?: Function): this;
|
|
132
|
+
removeAllListeners(): void;
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region node_modules/lib0/encoding.d.ts
|
|
136
|
+
/**
|
|
137
|
+
* A BinaryEncoder handles the encoding to an Uint8Array.
|
|
138
|
+
*/
|
|
139
|
+
declare class Encoder {
|
|
140
|
+
cpos: number;
|
|
141
|
+
cbuf: Uint8Array;
|
|
142
|
+
/**
|
|
143
|
+
* @type {Array<Uint8Array>}
|
|
144
|
+
*/
|
|
145
|
+
bufs: Array<Uint8Array>;
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region node_modules/lib0/decoding.d.ts
|
|
149
|
+
/**
|
|
150
|
+
* A Decoder handles the decoding of an Uint8Array.
|
|
151
|
+
*/
|
|
152
|
+
declare class Decoder {
|
|
153
|
+
/**
|
|
154
|
+
* @param {Uint8Array} uint8Array Binary data to decode
|
|
155
|
+
*/
|
|
156
|
+
constructor(uint8Array: Uint8Array);
|
|
157
|
+
/**
|
|
158
|
+
* Decoding target.
|
|
159
|
+
*
|
|
160
|
+
* @type {Uint8Array}
|
|
161
|
+
*/
|
|
162
|
+
arr: Uint8Array;
|
|
163
|
+
/**
|
|
164
|
+
* Current decoding position.
|
|
165
|
+
*
|
|
166
|
+
* @type {number}
|
|
167
|
+
*/
|
|
168
|
+
pos: number;
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region packages/provider/src/IncomingMessage.d.ts
|
|
172
|
+
declare class IncomingMessage {
|
|
173
|
+
data: any;
|
|
174
|
+
encoder: Encoder;
|
|
175
|
+
decoder: Decoder;
|
|
176
|
+
constructor(data: any);
|
|
177
|
+
peekVarString(): string;
|
|
178
|
+
readVarUint(): MessageType;
|
|
179
|
+
readVarString(): string;
|
|
180
|
+
readVarUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
181
|
+
writeVarUint(type: MessageType): void;
|
|
182
|
+
writeVarString(string: string): void;
|
|
183
|
+
writeVarUint8Array(data: Uint8Array): void;
|
|
184
|
+
length(): number;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region packages/provider/src/OutgoingMessage.d.ts
|
|
188
|
+
declare class OutgoingMessage implements OutgoingMessageInterface {
|
|
189
|
+
encoder: Encoder;
|
|
190
|
+
type?: MessageType;
|
|
191
|
+
constructor();
|
|
192
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
|
|
193
|
+
toUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts
|
|
197
|
+
declare class AuthenticationMessage extends OutgoingMessage {
|
|
198
|
+
type: MessageType;
|
|
199
|
+
description: string;
|
|
200
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder;
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts
|
|
204
|
+
declare class AwarenessMessage extends OutgoingMessage {
|
|
205
|
+
type: MessageType;
|
|
206
|
+
description: string;
|
|
207
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder;
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts
|
|
211
|
+
declare class QueryAwarenessMessage extends OutgoingMessage {
|
|
212
|
+
type: MessageType;
|
|
213
|
+
description: string;
|
|
214
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts
|
|
218
|
+
declare class SyncStepOneMessage extends OutgoingMessage {
|
|
219
|
+
type: MessageType;
|
|
220
|
+
description: string;
|
|
221
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder;
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts
|
|
225
|
+
declare class SyncStepTwoMessage extends OutgoingMessage {
|
|
226
|
+
type: MessageType;
|
|
227
|
+
description: string;
|
|
228
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region packages/provider/src/OutgoingMessages/UpdateMessage.d.ts
|
|
232
|
+
declare class UpdateMessage extends OutgoingMessage {
|
|
233
|
+
type: MessageType;
|
|
234
|
+
description: string;
|
|
235
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder;
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region packages/provider/src/types.d.ts
|
|
239
|
+
declare enum MessageType {
|
|
240
|
+
Sync = 0,
|
|
241
|
+
Awareness = 1,
|
|
242
|
+
Auth = 2,
|
|
243
|
+
QueryAwareness = 3,
|
|
244
|
+
Stateless = 5,
|
|
245
|
+
CLOSE = 7,
|
|
246
|
+
SyncStatus = 8
|
|
247
|
+
}
|
|
248
|
+
declare enum WebSocketStatus {
|
|
249
|
+
Connecting = "connecting",
|
|
250
|
+
Connected = "connected",
|
|
251
|
+
Disconnected = "disconnected"
|
|
252
|
+
}
|
|
253
|
+
type AuthorizedScope = "read-write" | "readonly";
|
|
254
|
+
interface OutgoingMessageInterface {
|
|
255
|
+
encoder: Encoder;
|
|
256
|
+
type?: MessageType;
|
|
257
|
+
}
|
|
258
|
+
interface OutgoingMessageArguments {
|
|
259
|
+
documentName: string;
|
|
260
|
+
token: string;
|
|
261
|
+
document: Y.Doc;
|
|
262
|
+
awareness: Awareness;
|
|
263
|
+
clients: number[];
|
|
264
|
+
states: Map<number, {
|
|
265
|
+
[key: string]: any;
|
|
266
|
+
}>;
|
|
267
|
+
update: any;
|
|
268
|
+
payload: string;
|
|
269
|
+
encoder: Encoder;
|
|
270
|
+
}
|
|
271
|
+
interface Constructable<T> {
|
|
272
|
+
new (...args: any): T;
|
|
273
|
+
}
|
|
274
|
+
type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
275
|
+
type onAuthenticationFailedParameters = {
|
|
276
|
+
reason: string;
|
|
277
|
+
};
|
|
278
|
+
type onAuthenticatedParameters = {
|
|
279
|
+
scope: AuthorizedScope;
|
|
280
|
+
};
|
|
281
|
+
type onOpenParameters = {
|
|
282
|
+
event: Event;
|
|
283
|
+
};
|
|
284
|
+
type onMessageParameters = {
|
|
285
|
+
event: MessageEvent;
|
|
286
|
+
message: IncomingMessage;
|
|
287
|
+
};
|
|
288
|
+
type onOutgoingMessageParameters = {
|
|
289
|
+
message: OutgoingMessage;
|
|
290
|
+
};
|
|
291
|
+
type onStatusParameters = {
|
|
292
|
+
status: WebSocketStatus;
|
|
293
|
+
};
|
|
294
|
+
type onSyncedParameters = {
|
|
295
|
+
state: boolean;
|
|
296
|
+
};
|
|
297
|
+
type onUnsyncedChangesParameters = {
|
|
298
|
+
number: number;
|
|
299
|
+
};
|
|
300
|
+
type onDisconnectParameters = {
|
|
301
|
+
event: CloseEvent;
|
|
302
|
+
};
|
|
303
|
+
type onCloseParameters = {
|
|
304
|
+
event: CloseEvent;
|
|
305
|
+
};
|
|
306
|
+
type onAwarenessUpdateParameters = {
|
|
307
|
+
states: StatesArray;
|
|
308
|
+
};
|
|
309
|
+
type onAwarenessChangeParameters = {
|
|
310
|
+
states: StatesArray;
|
|
311
|
+
};
|
|
312
|
+
type onStatelessParameters = {
|
|
313
|
+
payload: string;
|
|
314
|
+
};
|
|
315
|
+
type StatesArray = {
|
|
316
|
+
clientId: number;
|
|
317
|
+
[key: string | number]: any;
|
|
318
|
+
}[];
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region packages/provider/src/HocuspocusProviderWebsocket.d.ts
|
|
321
|
+
type HocuspocusWebSocket = WebSocket & {
|
|
322
|
+
identifier: string;
|
|
323
|
+
};
|
|
324
|
+
type HocusPocusWebSocket = HocuspocusWebSocket;
|
|
325
|
+
type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
326
|
+
interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
327
|
+
/**
|
|
328
|
+
* Whether to connect automatically when creating the provider instance. Default=true
|
|
329
|
+
*/
|
|
330
|
+
autoConnect: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* URL of your @hocuspocus/server instance
|
|
333
|
+
*/
|
|
334
|
+
url: string;
|
|
335
|
+
/**
|
|
336
|
+
* By default, trailing slashes are removed from the URL. Set this to true
|
|
337
|
+
* to preserve trailing slashes if your server configuration requires them.
|
|
338
|
+
*/
|
|
339
|
+
preserveTrailingSlash: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* An optional WebSocket polyfill, for example for Node.js
|
|
342
|
+
*/
|
|
343
|
+
WebSocketPolyfill: any;
|
|
344
|
+
/**
|
|
345
|
+
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
346
|
+
*/
|
|
347
|
+
messageReconnectTimeout: number;
|
|
348
|
+
/**
|
|
349
|
+
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
350
|
+
*/
|
|
351
|
+
delay: number;
|
|
352
|
+
/**
|
|
353
|
+
* The initialDelay 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.
|
|
354
|
+
*/
|
|
355
|
+
initialDelay: number;
|
|
356
|
+
/**
|
|
357
|
+
* The factor option is used to grow the delay exponentially.
|
|
358
|
+
*/
|
|
359
|
+
factor: number;
|
|
360
|
+
/**
|
|
361
|
+
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
362
|
+
*/
|
|
363
|
+
maxAttempts: number;
|
|
364
|
+
/**
|
|
365
|
+
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
366
|
+
*/
|
|
367
|
+
minDelay: number;
|
|
368
|
+
/**
|
|
369
|
+
* 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.
|
|
370
|
+
*/
|
|
371
|
+
maxDelay: number;
|
|
372
|
+
/**
|
|
373
|
+
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
374
|
+
*/
|
|
375
|
+
jitter: boolean;
|
|
376
|
+
/**
|
|
377
|
+
* 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.
|
|
378
|
+
*/
|
|
379
|
+
timeout: number;
|
|
380
|
+
handleTimeout: (() => Promise<unknown>) | null;
|
|
381
|
+
onOpen: (data: onOpenParameters) => void;
|
|
382
|
+
onConnect: () => void;
|
|
383
|
+
onMessage: (data: onMessageParameters) => void;
|
|
384
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
385
|
+
onStatus: (data: onStatusParameters) => void;
|
|
386
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
387
|
+
onClose: (data: onCloseParameters) => void;
|
|
388
|
+
onDestroy: () => void;
|
|
389
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
390
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
391
|
+
/**
|
|
392
|
+
* Map of attached providers keyed by documentName.
|
|
393
|
+
*/
|
|
394
|
+
providerMap: Map<string, HocuspocusProvider>;
|
|
395
|
+
}
|
|
396
|
+
declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
397
|
+
private messageQueue;
|
|
398
|
+
configuration: CompleteHocuspocusProviderWebsocketConfiguration;
|
|
399
|
+
webSocket: HocusPocusWebSocket | null;
|
|
400
|
+
webSocketHandlers: {
|
|
401
|
+
[key: string]: any;
|
|
402
|
+
};
|
|
403
|
+
shouldConnect: boolean;
|
|
404
|
+
status: WebSocketStatus;
|
|
405
|
+
lastMessageReceived: number;
|
|
406
|
+
identifier: number;
|
|
407
|
+
intervals: any;
|
|
408
|
+
connectionAttempt: {
|
|
409
|
+
resolve: (value?: any) => void;
|
|
410
|
+
reject: (reason?: any) => void;
|
|
411
|
+
} | null;
|
|
412
|
+
constructor(configuration: HocuspocusProviderWebsocketConfiguration);
|
|
413
|
+
receivedOnOpenPayload?: Event | undefined;
|
|
414
|
+
onOpen(event: Event): Promise<void>;
|
|
415
|
+
attach(provider: HocuspocusProvider): void;
|
|
416
|
+
detach(provider: HocuspocusProvider): void;
|
|
417
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
|
|
418
|
+
cancelWebsocketRetry?: () => void;
|
|
419
|
+
connect(): Promise<unknown>;
|
|
420
|
+
attachWebSocketListeners(ws: HocusPocusWebSocket, reject: Function): void;
|
|
421
|
+
cleanupWebSocket(): void;
|
|
422
|
+
createWebSocketConnection(): Promise<unknown>;
|
|
423
|
+
onMessage(event: MessageEvent): void;
|
|
424
|
+
resolveConnectionAttempt(): void;
|
|
425
|
+
stopConnectionAttempt(): void;
|
|
426
|
+
rejectConnectionAttempt(): void;
|
|
427
|
+
closeTries: number;
|
|
428
|
+
checkConnection(): void;
|
|
429
|
+
get serverUrl(): string;
|
|
430
|
+
get url(): string;
|
|
431
|
+
disconnect(): void;
|
|
432
|
+
send(message: any): void;
|
|
433
|
+
onClose({
|
|
434
|
+
event
|
|
435
|
+
}: onCloseParameters): void;
|
|
436
|
+
destroy(): void;
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region packages/provider/src/HocuspocusProvider.d.ts
|
|
440
|
+
type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, "name">> & Partial<CompleteHocuspocusProviderConfiguration> & ((Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "preserveTrailingSlash">>) | Required<Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">>);
|
|
441
|
+
interface CompleteHocuspocusProviderConfiguration {
|
|
442
|
+
/**
|
|
443
|
+
* The identifier/name of your document
|
|
444
|
+
*/
|
|
445
|
+
name: string;
|
|
446
|
+
/**
|
|
447
|
+
* The actual Y.js document
|
|
448
|
+
*/
|
|
449
|
+
document: Y.Doc;
|
|
450
|
+
/**
|
|
451
|
+
* An Awareness instance to keep the presence state of all clients.
|
|
452
|
+
*
|
|
453
|
+
* You can disable sharing awareness information by passing `null`.
|
|
454
|
+
* Note that having no awareness information shared across all connections will break our ping checks
|
|
455
|
+
* and thus trigger reconnects. You should always have at least one Provider with enabled awareness per
|
|
456
|
+
* socket connection, or ensure that the Provider receives messages before running into `HocuspocusProviderWebsocket.messageReconnectTimeout`.
|
|
457
|
+
*/
|
|
458
|
+
awareness: Awareness | null;
|
|
459
|
+
/**
|
|
460
|
+
* A token that’s sent to the backend for authentication purposes.
|
|
461
|
+
*/
|
|
462
|
+
token: string | (() => string) | (() => Promise<string>) | null;
|
|
463
|
+
/**
|
|
464
|
+
* Hocuspocus websocket provider
|
|
465
|
+
*/
|
|
466
|
+
websocketProvider: HocuspocusProviderWebsocket;
|
|
467
|
+
/**
|
|
468
|
+
* Force syncing the document in the defined interval.
|
|
469
|
+
*/
|
|
470
|
+
forceSyncInterval: false | number;
|
|
471
|
+
onAuthenticated: (data: onAuthenticatedParameters) => void;
|
|
472
|
+
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
473
|
+
onOpen: (data: onOpenParameters) => void;
|
|
474
|
+
onConnect: () => void;
|
|
475
|
+
onStatus: (data: onStatusParameters) => void;
|
|
476
|
+
onMessage: (data: onMessageParameters) => void;
|
|
477
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
478
|
+
onSynced: (data: onSyncedParameters) => void;
|
|
479
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
480
|
+
onClose: (data: onCloseParameters) => void;
|
|
481
|
+
onDestroy: () => void;
|
|
482
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
483
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
484
|
+
onStateless: (data: onStatelessParameters) => void;
|
|
485
|
+
onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
|
|
486
|
+
}
|
|
487
|
+
declare class AwarenessError extends Error {
|
|
488
|
+
code: number;
|
|
489
|
+
}
|
|
490
|
+
declare class HocuspocusProvider extends EventEmitter {
|
|
491
|
+
configuration: CompleteHocuspocusProviderConfiguration;
|
|
492
|
+
isSynced: boolean;
|
|
493
|
+
unsyncedChanges: number;
|
|
494
|
+
isAuthenticated: boolean;
|
|
495
|
+
authorizedScope: AuthorizedScope | undefined;
|
|
496
|
+
manageSocket: boolean;
|
|
497
|
+
private _isAttached;
|
|
498
|
+
intervals: any;
|
|
499
|
+
constructor(configuration: HocuspocusProviderConfiguration);
|
|
500
|
+
boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
|
|
501
|
+
boundAwarenessUpdateHandler: ({
|
|
502
|
+
added,
|
|
503
|
+
updated,
|
|
504
|
+
removed
|
|
505
|
+
}: any, origin: any) => void;
|
|
506
|
+
boundPageHide: () => void;
|
|
507
|
+
boundOnOpen: (event: Event) => Promise<void>;
|
|
508
|
+
boundOnClose: () => void;
|
|
509
|
+
forwardConnect: () => this;
|
|
510
|
+
forwardStatus: (e: onStatusParameters) => this;
|
|
511
|
+
forwardClose: (e: onCloseParameters) => this;
|
|
512
|
+
forwardDisconnect: (e: onDisconnectParameters) => this;
|
|
513
|
+
forwardDestroy: () => this;
|
|
514
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
515
|
+
get document(): Y.Doc;
|
|
516
|
+
get isAttached(): boolean;
|
|
517
|
+
get awareness(): Awareness | null;
|
|
518
|
+
get hasUnsyncedChanges(): boolean;
|
|
519
|
+
private resetUnsyncedChanges;
|
|
520
|
+
incrementUnsyncedChanges(): void;
|
|
521
|
+
decrementUnsyncedChanges(): void;
|
|
522
|
+
forceSync(): void;
|
|
523
|
+
pageHide(): void;
|
|
524
|
+
registerEventListeners(): void;
|
|
525
|
+
sendStateless(payload: string): void;
|
|
526
|
+
sendToken(): Promise<void>;
|
|
527
|
+
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
528
|
+
awarenessUpdateHandler({
|
|
529
|
+
added,
|
|
530
|
+
updated,
|
|
531
|
+
removed
|
|
532
|
+
}: any, origin: any): void;
|
|
533
|
+
/**
|
|
534
|
+
* Indicates whether a first handshake with the server has been established
|
|
535
|
+
*
|
|
536
|
+
* Note: this does not mean all updates from the client have been persisted to the backend. For this,
|
|
537
|
+
* use `hasUnsyncedChanges`.
|
|
538
|
+
*/
|
|
539
|
+
get synced(): boolean;
|
|
540
|
+
set synced(state: boolean);
|
|
541
|
+
receiveStateless(payload: string): void;
|
|
542
|
+
connect(): Promise<unknown>;
|
|
543
|
+
disconnect(): void;
|
|
544
|
+
onOpen(event: Event): Promise<void>;
|
|
545
|
+
getToken(): Promise<string | null>;
|
|
546
|
+
startSync(): void;
|
|
547
|
+
send(message: ConstructableOutgoingMessage, args: any): void;
|
|
548
|
+
onMessage(event: MessageEvent): void;
|
|
549
|
+
onClose(): void;
|
|
550
|
+
destroy(): void;
|
|
551
|
+
detach(): void;
|
|
552
|
+
attach(): void;
|
|
553
|
+
permissionDeniedHandler(reason: string): void;
|
|
554
|
+
authenticatedHandler(scope: string): void;
|
|
555
|
+
setAwarenessField(key: string, value: any): void;
|
|
556
|
+
}
|
|
557
|
+
//#endregion
|
|
558
|
+
export { AuthorizedScope, AwarenessError, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, Constructable, ConstructableOutgoingMessage, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, MessageType, OutgoingMessageArguments, OutgoingMessageInterface, StatesArray, WebSocketStatus, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, onUnsyncedChangesParameters };
|