@hocuspocus/provider 3.0.0-rc.0 → 3.0.6-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 +773 -11306
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +753 -11303
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/common/src/index.d.ts +4 -4
- package/dist/packages/extension-database/src/index.d.ts +1 -1
- package/dist/packages/extension-logger/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +6 -2
- package/dist/packages/extension-redis/src/index.d.ts +1 -1
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +14 -36
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +4 -8
- package/dist/packages/provider/src/IncomingMessage.d.ts +2 -2
- package/dist/packages/provider/src/MessageReceiver.d.ts +2 -4
- package/dist/packages/provider/src/MessageSender.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
- package/dist/packages/provider/src/index.d.ts +3 -5
- package/dist/packages/provider/src/types.d.ts +50 -10
- package/dist/packages/server/src/ClientConnection.d.ts +16 -8
- package/dist/packages/server/src/Connection.d.ts +14 -20
- package/dist/packages/server/src/DirectConnection.d.ts +4 -4
- package/dist/packages/server/src/Document.d.ts +2 -6
- package/dist/packages/server/src/Hocuspocus.d.ts +6 -15
- package/dist/packages/server/src/IncomingMessage.d.ts +4 -3
- package/dist/packages/server/src/MessageReceiver.d.ts +6 -8
- package/dist/packages/server/src/OutgoingMessage.d.ts +2 -1
- package/dist/packages/server/src/Server.d.ts +3 -3
- package/dist/packages/server/src/index.d.ts +9 -10
- package/dist/packages/server/src/types.d.ts +41 -13
- package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
- package/dist/packages/transformer/src/Tiptap.d.ts +1 -1
- package/dist/packages/transformer/src/index.d.ts +3 -3
- package/dist/playground/frontend/app/SocketContext.d.ts +2 -0
- package/dist/playground/frontend/next.config.d.ts +3 -0
- package/dist/tests/utils/index.d.ts +9 -9
- package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
- package/package.json +3 -3
- package/src/HocuspocusProvider.ts +88 -210
- package/src/HocuspocusProviderWebsocket.ts +23 -73
- package/src/IncomingMessage.ts +1 -1
- package/src/MessageReceiver.ts +22 -21
- package/src/MessageSender.ts +1 -1
- package/src/OutgoingMessage.ts +1 -1
- package/src/OutgoingMessages/AuthenticationMessage.ts +3 -3
- package/src/OutgoingMessages/AwarenessMessage.ts +3 -3
- package/src/OutgoingMessages/CloseMessage.ts +3 -3
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +3 -3
- package/src/OutgoingMessages/StatelessMessage.ts +3 -3
- package/src/OutgoingMessages/SyncStepOneMessage.ts +3 -3
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +3 -3
- package/src/OutgoingMessages/UpdateMessage.ts +3 -3
- package/src/index.ts +3 -5
- package/src/types.ts +56 -10
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +0 -64
- package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +0 -20
- package/dist/packages/server/src/Debugger.d.ts +0 -14
- package/dist/playground/frontend/vite.config.d.ts +0 -2
- package/dist/tests/server/getMessageLogs.d.ts +0 -1
- package/dist/tests/server/requiresAuthentication.d.ts +0 -1
- package/src/TiptapCollabProvider.ts +0 -321
- package/src/TiptapCollabProviderWebsocket.ts +0 -39
- /package/dist/{playground/frontend/src/main.d.ts → tests/server/beforeSync.d.ts} +0 -0
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
WsReadyStates,
|
|
3
3
|
} from '@hocuspocus/common'
|
|
4
4
|
import { retry } from '@lifeomic/attempt'
|
|
5
5
|
import * as time from 'lib0/time'
|
|
6
6
|
import * as url from 'lib0/url'
|
|
7
7
|
import type { MessageEvent , Event } from 'ws'
|
|
8
|
-
import EventEmitter from './EventEmitter.
|
|
9
|
-
import type { HocuspocusProvider } from './HocuspocusProvider.
|
|
8
|
+
import EventEmitter from './EventEmitter.ts'
|
|
9
|
+
import type { HocuspocusProvider } from './HocuspocusProvider.ts'
|
|
10
10
|
import type {
|
|
11
11
|
onAwarenessChangeParameters, onAwarenessUpdateParameters,
|
|
12
|
-
onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters} from './types.
|
|
12
|
+
onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters} from './types.ts'
|
|
13
13
|
import {
|
|
14
14
|
WebSocketStatus,
|
|
15
|
-
} from './types.
|
|
16
|
-
import { IncomingMessage } from './IncomingMessage.
|
|
15
|
+
} from './types.ts'
|
|
16
|
+
import { IncomingMessage } from './IncomingMessage.ts'
|
|
17
|
+
import { CloseMessage } from "./OutgoingMessages/CloseMessage.ts"
|
|
17
18
|
|
|
18
19
|
export type HocusPocusWebSocket = WebSocket & { identifier: string };
|
|
19
20
|
|
|
@@ -87,10 +88,6 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
|
87
88
|
onDestroy: () => void,
|
|
88
89
|
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void,
|
|
89
90
|
onAwarenessChange: (data: onAwarenessChangeParameters) => void,
|
|
90
|
-
/**
|
|
91
|
-
* Don’t output any warnings.
|
|
92
|
-
*/
|
|
93
|
-
quiet: boolean,
|
|
94
91
|
|
|
95
92
|
/**
|
|
96
93
|
* Map of attached providers keyed by documentName.
|
|
@@ -138,7 +135,6 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
138
135
|
onDestroy: () => null,
|
|
139
136
|
onAwarenessUpdate: () => null,
|
|
140
137
|
onAwarenessChange: () => null,
|
|
141
|
-
quiet: false,
|
|
142
138
|
providerMap: new Map(),
|
|
143
139
|
}
|
|
144
140
|
|
|
@@ -155,7 +151,6 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
155
151
|
identifier = 0
|
|
156
152
|
|
|
157
153
|
intervals: any = {
|
|
158
|
-
forceSync: null,
|
|
159
154
|
connectionChecker: null,
|
|
160
155
|
}
|
|
161
156
|
|
|
@@ -209,6 +204,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
209
204
|
receivedOnStatusPayload?: onStatusParameters | undefined = undefined
|
|
210
205
|
|
|
211
206
|
async onOpen(event: Event) {
|
|
207
|
+
this.cancelWebsocketRetry = undefined
|
|
212
208
|
this.receivedOnOpenPayload = event
|
|
213
209
|
}
|
|
214
210
|
|
|
@@ -227,14 +223,13 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
227
223
|
if (this.receivedOnOpenPayload) {
|
|
228
224
|
provider.onOpen(this.receivedOnOpenPayload)
|
|
229
225
|
}
|
|
230
|
-
|
|
231
|
-
// if (this.receivedOnStatusPayload) {
|
|
232
|
-
// provider.onStatus(this.receivedOnStatusPayload)
|
|
233
|
-
// }
|
|
234
226
|
}
|
|
235
227
|
|
|
236
228
|
detach(provider: HocuspocusProvider) {
|
|
237
|
-
this.configuration.providerMap.
|
|
229
|
+
if( this.configuration.providerMap.has(provider.configuration.name )) {
|
|
230
|
+
provider.send(CloseMessage, { documentName: provider.configuration.name })
|
|
231
|
+
this.configuration.providerMap.delete(provider.configuration.name)
|
|
232
|
+
}
|
|
238
233
|
}
|
|
239
234
|
|
|
240
235
|
public setConfiguration(
|
|
@@ -441,7 +436,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
441
436
|
}
|
|
442
437
|
}
|
|
443
438
|
|
|
444
|
-
// Ensure that the URL
|
|
439
|
+
// Ensure that the URL never ends with /
|
|
445
440
|
get serverUrl() {
|
|
446
441
|
while (this.configuration.url[this.configuration.url.length - 1] === '/') {
|
|
447
442
|
return this.configuration.url.slice(0, this.configuration.url.length - 1)
|
|
@@ -466,8 +461,8 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
466
461
|
try {
|
|
467
462
|
this.webSocket.close()
|
|
468
463
|
this.messageQueue = []
|
|
469
|
-
} catch {
|
|
470
|
-
|
|
464
|
+
} catch(e) {
|
|
465
|
+
console.error(e)
|
|
471
466
|
}
|
|
472
467
|
}
|
|
473
468
|
|
|
@@ -483,73 +478,28 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
|
|
|
483
478
|
this.closeTries = 0
|
|
484
479
|
this.cleanupWebSocket()
|
|
485
480
|
|
|
486
|
-
if (this.status === WebSocketStatus.Connected) {
|
|
487
|
-
this.status = WebSocketStatus.Disconnected
|
|
488
|
-
this.emit('status', { status: WebSocketStatus.Disconnected })
|
|
489
|
-
this.emit('disconnect', { event })
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
if (event.code === Unauthorized.code) {
|
|
493
|
-
if (event.reason === Unauthorized.reason) {
|
|
494
|
-
console.warn(
|
|
495
|
-
'[HocuspocusProvider] An authentication token is required, but you didn’t send one. Try adding a `token` to your HocuspocusProvider configuration. Won’t try again.',
|
|
496
|
-
)
|
|
497
|
-
} else {
|
|
498
|
-
console.warn(
|
|
499
|
-
`[HocuspocusProvider] Connection closed with status Unauthorized: ${event.reason}`,
|
|
500
|
-
)
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
this.shouldConnect = false
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
if (event.code === Forbidden.code) {
|
|
507
|
-
if (!this.configuration.quiet) {
|
|
508
|
-
console.warn(
|
|
509
|
-
'[HocuspocusProvider] The provided authentication token isn’t allowed to connect to this server. Will try again.',
|
|
510
|
-
)
|
|
511
|
-
return // TODO REMOVE ME
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
if (event.code === MessageTooBig.code) {
|
|
516
|
-
console.warn(
|
|
517
|
-
`[HocuspocusProvider] Connection closed with status MessageTooBig: ${event.reason}`,
|
|
518
|
-
)
|
|
519
|
-
this.shouldConnect = false
|
|
520
|
-
}
|
|
521
|
-
|
|
522
481
|
if (this.connectionAttempt) {
|
|
523
482
|
// That connection attempt failed.
|
|
524
483
|
this.rejectConnectionAttempt()
|
|
525
|
-
} else if (this.shouldConnect) {
|
|
526
|
-
// The connection was closed by the server. Let’s just try again.
|
|
527
|
-
this.connect()
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// If we’ll reconnect, we’re done for now.
|
|
531
|
-
if (this.shouldConnect) {
|
|
532
|
-
return
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
// The status is set correctly already.
|
|
536
|
-
if (this.status === WebSocketStatus.Disconnected) {
|
|
537
|
-
return
|
|
538
484
|
}
|
|
539
485
|
|
|
540
486
|
// Let’s update the connection status.
|
|
541
487
|
this.status = WebSocketStatus.Disconnected
|
|
542
488
|
this.emit('status', { status: WebSocketStatus.Disconnected })
|
|
543
489
|
this.emit('disconnect', { event })
|
|
490
|
+
|
|
491
|
+
// trigger connect if no retry is running and we want to have a connection
|
|
492
|
+
if( !this.cancelWebsocketRetry && this.shouldConnect ) {
|
|
493
|
+
|
|
494
|
+
setTimeout(() => {
|
|
495
|
+
this.connect()
|
|
496
|
+
}, this.configuration.delay)
|
|
497
|
+
}
|
|
544
498
|
}
|
|
545
499
|
|
|
546
500
|
destroy() {
|
|
547
501
|
this.emit('destroy')
|
|
548
502
|
|
|
549
|
-
if (this.intervals.forceSync) {
|
|
550
|
-
clearInterval(this.intervals.forceSync)
|
|
551
|
-
}
|
|
552
|
-
|
|
553
503
|
clearInterval(this.intervals.connectionChecker)
|
|
554
504
|
|
|
555
505
|
// If there is still a connection attempt outstanding then we should stop
|
package/src/IncomingMessage.ts
CHANGED
package/src/MessageReceiver.ts
CHANGED
|
@@ -2,27 +2,20 @@ import { readAuthMessage } from '@hocuspocus/common'
|
|
|
2
2
|
import { readVarInt, readVarString } from 'lib0/decoding'
|
|
3
3
|
import * as awarenessProtocol from 'y-protocols/awareness'
|
|
4
4
|
import { messageYjsSyncStep2, readSyncMessage } from 'y-protocols/sync'
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import type { CloseEvent } from 'ws'
|
|
6
|
+
import type { HocuspocusProvider } from './HocuspocusProvider.ts'
|
|
7
|
+
import type { IncomingMessage } from './IncomingMessage.ts'
|
|
8
|
+
import { OutgoingMessage } from './OutgoingMessage.ts'
|
|
9
|
+
import { MessageType } from './types.ts'
|
|
9
10
|
|
|
10
11
|
export class MessageReceiver {
|
|
11
12
|
|
|
12
13
|
message: IncomingMessage
|
|
13
14
|
|
|
14
|
-
broadcasted = false
|
|
15
|
-
|
|
16
15
|
constructor(message: IncomingMessage) {
|
|
17
16
|
this.message = message
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
public setBroadcasted(value: boolean) {
|
|
21
|
-
this.broadcasted = value
|
|
22
|
-
|
|
23
|
-
return this
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
public apply(provider: HocuspocusProvider, emitSynced: boolean) {
|
|
27
20
|
const { message } = this
|
|
28
21
|
const type = message.readVarUint()
|
|
@@ -53,21 +46,29 @@ export class MessageReceiver {
|
|
|
53
46
|
case MessageType.SyncStatus:
|
|
54
47
|
this.applySyncStatusMessage(provider, readVarInt(message.decoder) === 1)
|
|
55
48
|
break
|
|
49
|
+
|
|
50
|
+
case MessageType.CLOSE:
|
|
51
|
+
// eslint-disable-next-line no-case-declarations
|
|
52
|
+
const event: CloseEvent = {
|
|
53
|
+
code: 1000,
|
|
54
|
+
reason: readVarString(message.decoder),
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
target: provider.configuration.websocketProvider.webSocket!,
|
|
57
|
+
type: 'close',
|
|
58
|
+
}
|
|
59
|
+
provider.onClose()
|
|
60
|
+
provider.configuration.onClose({ event })
|
|
61
|
+
provider.forwardClose(event)
|
|
62
|
+
break
|
|
63
|
+
|
|
56
64
|
default:
|
|
57
65
|
throw new Error(`Can’t apply message of unknown type: ${type}`)
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
// Reply
|
|
61
69
|
if (message.length() > emptyMessageLength + 1) { // length of documentName (considered in emptyMessageLength plus length of yjs sync type, set in applySyncMessage)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
provider.broadcast(OutgoingMessage, { encoder: message.encoder })
|
|
66
|
-
} else {
|
|
67
|
-
// TODO: Some weird TypeScript error
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
provider.send(OutgoingMessage, { encoder: message.encoder })
|
|
70
|
-
}
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
provider.send(OutgoingMessage, { encoder: message.encoder })
|
|
71
72
|
}
|
|
72
73
|
}
|
|
73
74
|
|
package/src/MessageSender.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Encoder} from 'lib0/encoding'
|
|
2
2
|
import { toUint8Array } from 'lib0/encoding'
|
|
3
3
|
import * as bc from 'lib0/broadcastchannel'
|
|
4
|
-
import type { ConstructableOutgoingMessage } from './types.
|
|
4
|
+
import type { ConstructableOutgoingMessage } from './types.ts'
|
|
5
5
|
|
|
6
6
|
export class MessageSender {
|
|
7
7
|
|
package/src/OutgoingMessage.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Encoder} from 'lib0/encoding'
|
|
2
2
|
import { createEncoder, toUint8Array } from 'lib0/encoding'
|
|
3
|
-
import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.
|
|
3
|
+
import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.ts'
|
|
4
4
|
|
|
5
5
|
export class OutgoingMessage implements OutgoingMessageInterface {
|
|
6
6
|
encoder: Encoder
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { writeVarString, writeVarUint } from 'lib0/encoding'
|
|
2
2
|
import { writeAuthentication } from '@hocuspocus/common'
|
|
3
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
4
|
-
import { MessageType } from '../types.
|
|
5
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
4
|
+
import { MessageType } from '../types.ts'
|
|
5
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
6
6
|
|
|
7
7
|
export class AuthenticationMessage extends OutgoingMessage {
|
|
8
8
|
type = MessageType.Auth
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
2
|
import { encodeAwarenessUpdate } from 'y-protocols/awareness'
|
|
3
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
4
|
-
import { MessageType } from '../types.
|
|
5
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
4
|
+
import { MessageType } from '../types.ts'
|
|
5
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
6
6
|
|
|
7
7
|
export class AwarenessMessage extends OutgoingMessage {
|
|
8
8
|
type = MessageType.Awareness
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
3
|
-
import { MessageType } from '../types.
|
|
4
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
2
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
3
|
+
import { MessageType } from '../types.ts'
|
|
4
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
5
5
|
|
|
6
6
|
export class CloseMessage extends OutgoingMessage {
|
|
7
7
|
type = MessageType.CLOSE
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
3
|
-
import { MessageType } from '../types.
|
|
4
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
2
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
3
|
+
import { MessageType } from '../types.ts'
|
|
4
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
5
5
|
|
|
6
6
|
export class QueryAwarenessMessage extends OutgoingMessage {
|
|
7
7
|
type = MessageType.QueryAwareness
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writeVarString, writeVarUint } from 'lib0/encoding'
|
|
2
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
3
|
-
import { MessageType } from '../types.
|
|
4
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
2
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
3
|
+
import { MessageType } from '../types.ts'
|
|
4
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
5
5
|
|
|
6
6
|
export class StatelessMessage extends OutgoingMessage {
|
|
7
7
|
type = MessageType.Stateless
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
2
|
import * as syncProtocol from 'y-protocols/sync'
|
|
3
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
4
|
-
import { MessageType } from '../types.
|
|
5
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
4
|
+
import { MessageType } from '../types.ts'
|
|
5
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
6
6
|
|
|
7
7
|
export class SyncStepOneMessage extends OutgoingMessage {
|
|
8
8
|
type = MessageType.Sync
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as encoding from 'lib0/encoding'
|
|
2
2
|
import * as syncProtocol from 'y-protocols/sync'
|
|
3
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
4
|
-
import { MessageType } from '../types.
|
|
5
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
4
|
+
import { MessageType } from '../types.ts'
|
|
5
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
6
6
|
|
|
7
7
|
export class SyncStepTwoMessage extends OutgoingMessage {
|
|
8
8
|
type = MessageType.Sync
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { writeVarString, writeVarUint } from 'lib0/encoding'
|
|
2
2
|
import { writeUpdate } from 'y-protocols/sync'
|
|
3
|
-
import type { OutgoingMessageArguments } from '../types.
|
|
4
|
-
import { MessageType } from '../types.
|
|
5
|
-
import { OutgoingMessage } from '../OutgoingMessage.
|
|
3
|
+
import type { OutgoingMessageArguments } from '../types.ts'
|
|
4
|
+
import { MessageType } from '../types.ts'
|
|
5
|
+
import { OutgoingMessage } from '../OutgoingMessage.ts'
|
|
6
6
|
|
|
7
7
|
export class UpdateMessage extends OutgoingMessage {
|
|
8
8
|
type = MessageType.Sync
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export * from './HocuspocusProvider.
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './HocuspocusProviderWebsocket.js'
|
|
5
|
-
export * from './types.js'
|
|
1
|
+
export * from './HocuspocusProvider.ts'
|
|
2
|
+
export * from './HocuspocusProviderWebsocket.ts'
|
|
3
|
+
export * from './types.ts'
|
package/src/types.ts
CHANGED
|
@@ -3,14 +3,14 @@ import type { Event, MessageEvent } from 'ws'
|
|
|
3
3
|
import type { Awareness } from 'y-protocols/awareness'
|
|
4
4
|
import type * as Y from 'yjs'
|
|
5
5
|
import type { CloseEvent } from '@hocuspocus/common'
|
|
6
|
-
import type { IncomingMessage } from './IncomingMessage.
|
|
7
|
-
import type { OutgoingMessage } from './OutgoingMessage.
|
|
8
|
-
import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.
|
|
9
|
-
import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.
|
|
10
|
-
import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.
|
|
11
|
-
import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.
|
|
12
|
-
import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.
|
|
13
|
-
import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.
|
|
6
|
+
import type { IncomingMessage } from './IncomingMessage.ts'
|
|
7
|
+
import type { OutgoingMessage } from './OutgoingMessage.ts'
|
|
8
|
+
import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.ts'
|
|
9
|
+
import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.ts'
|
|
10
|
+
import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.ts'
|
|
11
|
+
import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.ts'
|
|
12
|
+
import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.ts'
|
|
13
|
+
import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.ts'
|
|
14
14
|
|
|
15
15
|
export enum MessageType {
|
|
16
16
|
Sync = 0,
|
|
@@ -110,15 +110,18 @@ export type TCollabThread<Data = any, CommentData = any> = {
|
|
|
110
110
|
id: string;
|
|
111
111
|
createdAt: number;
|
|
112
112
|
updatedAt: number;
|
|
113
|
+
deletedAt: number | null;
|
|
113
114
|
resolvedAt?: string; // (new Date()).toISOString()
|
|
114
115
|
comments: TCollabComment<CommentData>[];
|
|
116
|
+
deletedComments: TCollabComment<CommentData>[];
|
|
115
117
|
data: Data
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
export type TCollabComment<Data = any> = {
|
|
119
121
|
id: string;
|
|
120
|
-
createdAt:
|
|
121
|
-
updatedAt:
|
|
122
|
+
createdAt: string;
|
|
123
|
+
updatedAt: string;
|
|
124
|
+
deletedAt?: string;
|
|
122
125
|
data: Data
|
|
123
126
|
content: any
|
|
124
127
|
}
|
|
@@ -183,3 +186,46 @@ export type THistoryDocumentRevertedEvent = {
|
|
|
183
186
|
event: 'document.reverted';
|
|
184
187
|
version: number;
|
|
185
188
|
};
|
|
189
|
+
|
|
190
|
+
export type DeleteCommentOptions = {
|
|
191
|
+
/**
|
|
192
|
+
* If `true`, the thread will also be deleted if the deleted comment was the first comment in the thread.
|
|
193
|
+
*/
|
|
194
|
+
deleteThread?: boolean
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* If `true`, will remove the content of the deleted comment
|
|
198
|
+
*/
|
|
199
|
+
deleteContent?: boolean
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export type DeleteThreadOptions = {
|
|
203
|
+
/**
|
|
204
|
+
* If `true`, will remove the comments on the thread,
|
|
205
|
+
* otherwise will only mark the thread as deleted
|
|
206
|
+
* and keep the comments
|
|
207
|
+
* @default false
|
|
208
|
+
*/
|
|
209
|
+
deleteComments?: boolean
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* If `true`, will forcefully remove the thread and all comments,
|
|
213
|
+
* otherwise will only mark the thread as deleted
|
|
214
|
+
* and keep the comments
|
|
215
|
+
* @default false
|
|
216
|
+
*/
|
|
217
|
+
force?: boolean,
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The type of thread
|
|
222
|
+
*/
|
|
223
|
+
export type ThreadType = 'archived' | 'unarchived'
|
|
224
|
+
|
|
225
|
+
export type GetThreadsOptions = {
|
|
226
|
+
/**
|
|
227
|
+
* The types of threads to get
|
|
228
|
+
* @default ['unarchived']
|
|
229
|
+
*/
|
|
230
|
+
types?: Array<ThreadType>
|
|
231
|
+
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { AbstractType, YArrayEvent } from 'yjs';
|
|
2
|
-
import * as Y from 'yjs';
|
|
3
|
-
import type { HocuspocusProviderConfiguration } from './HocuspocusProvider.js';
|
|
4
|
-
import { HocuspocusProvider } from './HocuspocusProvider.js';
|
|
5
|
-
import { TiptapCollabProviderWebsocket } from './TiptapCollabProviderWebsocket.js';
|
|
6
|
-
import type { TCollabComment, TCollabThread, THistoryVersion } from './types.js';
|
|
7
|
-
export type TiptapCollabProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & (Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'websocketProvider'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'appId'>> | Required<Pick<AdditionalTiptapCollabProviderConfiguration, 'baseUrl'>>) & Pick<AdditionalTiptapCollabProviderConfiguration, 'user'>;
|
|
8
|
-
export interface AdditionalTiptapCollabProviderConfiguration {
|
|
9
|
-
/**
|
|
10
|
-
* A Hocuspocus Cloud App ID, get one here: https://cloud.tiptap.dev
|
|
11
|
-
*/
|
|
12
|
-
appId?: string;
|
|
13
|
-
/**
|
|
14
|
-
* If you are using the on-premise version of TiptapCollab, put your baseUrl here (e.g. https://collab.yourdomain.com)
|
|
15
|
-
*/
|
|
16
|
-
baseUrl?: string;
|
|
17
|
-
websocketProvider?: TiptapCollabProviderWebsocket;
|
|
18
|
-
user?: string;
|
|
19
|
-
}
|
|
20
|
-
export declare class TiptapCollabProvider extends HocuspocusProvider {
|
|
21
|
-
tiptapCollabConfigurationPrefix: string;
|
|
22
|
-
userData?: Y.PermanentUserData;
|
|
23
|
-
constructor(configuration: TiptapCollabProviderConfiguration);
|
|
24
|
-
/**
|
|
25
|
-
* note: this will only work if your server loaded @hocuspocus-pro/extension-history, or if you are on a Tiptap business plan.
|
|
26
|
-
*/
|
|
27
|
-
createVersion(name?: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* note: this will only work if your server loaded @hocuspocus-pro/extension-history, or if you are on a Tiptap business plan.
|
|
30
|
-
*/
|
|
31
|
-
revertToVersion(targetVersion: number): void;
|
|
32
|
-
/**
|
|
33
|
-
* note: this will only work if your server loaded @hocuspocus-pro/extension-history, or if you are on a Tiptap business plan.
|
|
34
|
-
*
|
|
35
|
-
* The server will reply with a stateless message (THistoryVersionPreviewEvent)
|
|
36
|
-
*/
|
|
37
|
-
previewVersion(targetVersion: number): void;
|
|
38
|
-
/**
|
|
39
|
-
* note: this will only work if your server loaded @hocuspocus-pro/extension-history, or if you are on a Tiptap business plan.
|
|
40
|
-
*/
|
|
41
|
-
getVersions(): THistoryVersion[];
|
|
42
|
-
watchVersions(callback: Parameters<AbstractType<YArrayEvent<THistoryVersion>>['observe']>[0]): void;
|
|
43
|
-
unwatchVersions(callback: Parameters<AbstractType<YArrayEvent<THistoryVersion>>['unobserve']>[0]): void;
|
|
44
|
-
isAutoVersioning(): boolean;
|
|
45
|
-
enableAutoVersioning(): 1;
|
|
46
|
-
disableAutoVersioning(): 0;
|
|
47
|
-
private getYThreads;
|
|
48
|
-
getThreads<Data, CommentData>(): TCollabThread<Data, CommentData>[];
|
|
49
|
-
private getThreadIndex;
|
|
50
|
-
getThread<Data, CommentData>(id: string): TCollabThread<Data, CommentData> | null;
|
|
51
|
-
private getYThread;
|
|
52
|
-
createThread(data: Omit<TCollabThread, 'id' | 'createdAt' | 'updatedAt' | 'comments'>): TCollabThread;
|
|
53
|
-
updateThread(id: TCollabThread['id'], data: Partial<Pick<TCollabThread, 'data'> & {
|
|
54
|
-
resolvedAt: TCollabThread['resolvedAt'] | null;
|
|
55
|
-
}>): TCollabThread;
|
|
56
|
-
deleteThread(id: TCollabThread['id']): void;
|
|
57
|
-
getThreadComments(threadId: TCollabThread['id']): TCollabComment[] | null;
|
|
58
|
-
getThreadComment(threadId: TCollabThread['id'], commentId: TCollabComment['id']): TCollabComment | null;
|
|
59
|
-
addComment(threadId: TCollabThread['id'], data: Omit<TCollabComment, 'id' | 'updatedAt' | 'createdAt'>): TCollabThread;
|
|
60
|
-
updateComment(threadId: TCollabThread['id'], commentId: TCollabComment['id'], data: Partial<Pick<TCollabComment, 'data' | 'content'>>): TCollabThread;
|
|
61
|
-
deleteComment(threadId: TCollabThread['id'], commentId: TCollabComment['id']): TCollabThread | null | undefined;
|
|
62
|
-
watchThreads(callback: () => void): void;
|
|
63
|
-
unwatchThreads(callback: () => void): void;
|
|
64
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.js';
|
|
2
|
-
import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
|
|
3
|
-
export type TiptapCollabProviderWebsocketConfiguration = Partial<CompleteHocuspocusProviderWebsocketConfiguration> & AdditionalTiptapCollabProviderWebsocketConfiguration;
|
|
4
|
-
export interface AdditionalTiptapCollabProviderWebsocketConfiguration {
|
|
5
|
-
/**
|
|
6
|
-
* A Hocuspocus Cloud App ID, get one here: https://cloud.tiptap.dev
|
|
7
|
-
*/
|
|
8
|
-
appId?: string;
|
|
9
|
-
/**
|
|
10
|
-
* If you are using the on-premise version of TiptapCollab, put your baseUrl here (e.g. https://collab.yourdomain.com)
|
|
11
|
-
*/
|
|
12
|
-
baseUrl?: string;
|
|
13
|
-
/**
|
|
14
|
-
* Only fill this if you are using Tiptap Collab HA.
|
|
15
|
-
*/
|
|
16
|
-
shardKey?: string;
|
|
17
|
-
}
|
|
18
|
-
export declare class TiptapCollabProviderWebsocket extends HocuspocusProviderWebsocket {
|
|
19
|
-
constructor(configuration: TiptapCollabProviderWebsocketConfiguration);
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|