@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.
Files changed (70) hide show
  1. package/dist/hocuspocus-provider.cjs +773 -11306
  2. package/dist/hocuspocus-provider.cjs.map +1 -1
  3. package/dist/hocuspocus-provider.esm.js +753 -11303
  4. package/dist/hocuspocus-provider.esm.js.map +1 -1
  5. package/dist/packages/common/src/index.d.ts +4 -4
  6. package/dist/packages/extension-database/src/index.d.ts +1 -1
  7. package/dist/packages/extension-logger/src/index.d.ts +1 -1
  8. package/dist/packages/extension-redis/src/Redis.d.ts +6 -2
  9. package/dist/packages/extension-redis/src/index.d.ts +1 -1
  10. package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
  11. package/dist/packages/provider/src/HocuspocusProvider.d.ts +14 -36
  12. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +4 -8
  13. package/dist/packages/provider/src/IncomingMessage.d.ts +2 -2
  14. package/dist/packages/provider/src/MessageReceiver.d.ts +2 -4
  15. package/dist/packages/provider/src/MessageSender.d.ts +2 -2
  16. package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
  17. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
  18. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +3 -3
  19. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +3 -3
  20. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +3 -3
  21. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
  22. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +3 -3
  23. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +3 -3
  24. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
  25. package/dist/packages/provider/src/index.d.ts +3 -5
  26. package/dist/packages/provider/src/types.d.ts +50 -10
  27. package/dist/packages/server/src/ClientConnection.d.ts +16 -8
  28. package/dist/packages/server/src/Connection.d.ts +14 -20
  29. package/dist/packages/server/src/DirectConnection.d.ts +4 -4
  30. package/dist/packages/server/src/Document.d.ts +2 -6
  31. package/dist/packages/server/src/Hocuspocus.d.ts +6 -15
  32. package/dist/packages/server/src/IncomingMessage.d.ts +4 -3
  33. package/dist/packages/server/src/MessageReceiver.d.ts +6 -8
  34. package/dist/packages/server/src/OutgoingMessage.d.ts +2 -1
  35. package/dist/packages/server/src/Server.d.ts +3 -3
  36. package/dist/packages/server/src/index.d.ts +9 -10
  37. package/dist/packages/server/src/types.d.ts +41 -13
  38. package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
  39. package/dist/packages/transformer/src/Tiptap.d.ts +1 -1
  40. package/dist/packages/transformer/src/index.d.ts +3 -3
  41. package/dist/playground/frontend/app/SocketContext.d.ts +2 -0
  42. package/dist/playground/frontend/next.config.d.ts +3 -0
  43. package/dist/tests/utils/index.d.ts +9 -9
  44. package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
  45. package/package.json +3 -3
  46. package/src/HocuspocusProvider.ts +88 -210
  47. package/src/HocuspocusProviderWebsocket.ts +23 -73
  48. package/src/IncomingMessage.ts +1 -1
  49. package/src/MessageReceiver.ts +22 -21
  50. package/src/MessageSender.ts +1 -1
  51. package/src/OutgoingMessage.ts +1 -1
  52. package/src/OutgoingMessages/AuthenticationMessage.ts +3 -3
  53. package/src/OutgoingMessages/AwarenessMessage.ts +3 -3
  54. package/src/OutgoingMessages/CloseMessage.ts +3 -3
  55. package/src/OutgoingMessages/QueryAwarenessMessage.ts +3 -3
  56. package/src/OutgoingMessages/StatelessMessage.ts +3 -3
  57. package/src/OutgoingMessages/SyncStepOneMessage.ts +3 -3
  58. package/src/OutgoingMessages/SyncStepTwoMessage.ts +3 -3
  59. package/src/OutgoingMessages/UpdateMessage.ts +3 -3
  60. package/src/index.ts +3 -5
  61. package/src/types.ts +56 -10
  62. package/dist/packages/provider/src/TiptapCollabProvider.d.ts +0 -64
  63. package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +0 -20
  64. package/dist/packages/server/src/Debugger.d.ts +0 -14
  65. package/dist/playground/frontend/vite.config.d.ts +0 -2
  66. package/dist/tests/server/getMessageLogs.d.ts +0 -1
  67. package/dist/tests/server/requiresAuthentication.d.ts +0 -1
  68. package/src/TiptapCollabProvider.ts +0 -321
  69. package/src/TiptapCollabProviderWebsocket.ts +0 -39
  70. /package/dist/{playground/frontend/src/main.d.ts → tests/server/beforeSync.d.ts} +0 -0
@@ -1,19 +1,20 @@
1
1
  import {
2
- Forbidden, MessageTooBig, Unauthorized, WsReadyStates,
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.js'
9
- import type { HocuspocusProvider } from './HocuspocusProvider.js'
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.js'
12
+ onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters} from './types.ts'
13
13
  import {
14
14
  WebSocketStatus,
15
- } from './types.js'
16
- import { IncomingMessage } from './IncomingMessage.js'
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.delete(provider.configuration.name)
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 always ends with /
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
@@ -16,7 +16,7 @@ import {
16
16
  writeVarString,
17
17
  length,
18
18
  } from 'lib0/encoding'
19
- import type { MessageType } from './types.js'
19
+ import type { MessageType } from './types.ts'
20
20
 
21
21
  export class IncomingMessage {
22
22
 
@@ -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 { HocuspocusProvider } from './HocuspocusProvider.js'
6
- import type { IncomingMessage } from './IncomingMessage.js'
7
- import { OutgoingMessage } from './OutgoingMessage.js'
8
- import { MessageType } from './types.js'
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
- if (this.broadcasted) {
63
- // TODO: Some weird TypeScript error
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
 
@@ -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.js'
4
+ import type { ConstructableOutgoingMessage } from './types.ts'
5
5
 
6
6
  export class MessageSender {
7
7
 
@@ -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.js'
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.js'
4
- import { MessageType } from '../types.js'
5
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
4
- import { MessageType } from '../types.js'
5
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
3
- import { MessageType } from '../types.js'
4
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
3
- import { MessageType } from '../types.js'
4
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
3
- import { MessageType } from '../types.js'
4
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
4
- import { MessageType } from '../types.js'
5
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
4
- import { MessageType } from '../types.js'
5
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
4
- import { MessageType } from '../types.js'
5
- import { OutgoingMessage } from '../OutgoingMessage.js'
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.js'
2
- export * from './TiptapCollabProvider.js'
3
- export * from './TiptapCollabProviderWebsocket.js'
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.js'
7
- import type { OutgoingMessage } from './OutgoingMessage.js'
8
- import type { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage.js'
9
- import type { AwarenessMessage } from './OutgoingMessages/AwarenessMessage.js'
10
- import type { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage.js'
11
- import type { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage.js'
12
- import type { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage.js'
13
- import type { UpdateMessage } from './OutgoingMessages/UpdateMessage.js'
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: number;
121
- updatedAt: number;
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,14 +0,0 @@
1
- export declare class Debugger {
2
- logs: any[];
3
- listen: boolean;
4
- output: boolean;
5
- enable(): void;
6
- disable(): void;
7
- verbose(): void;
8
- quiet(): void;
9
- log(message: any): this;
10
- flush(): this;
11
- get(): {
12
- logs: any[];
13
- };
14
- }
@@ -1,2 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};