@hocuspocus/extension-throttle 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 (50) hide show
  1. package/dist/hocuspocus-throttle.cjs.map +1 -1
  2. package/dist/hocuspocus-throttle.esm.js.map +1 -1
  3. package/dist/packages/common/src/index.d.ts +4 -4
  4. package/dist/packages/extension-database/src/index.d.ts +1 -1
  5. package/dist/packages/extension-logger/src/index.d.ts +1 -1
  6. package/dist/packages/extension-redis/src/Redis.d.ts +6 -2
  7. package/dist/packages/extension-redis/src/index.d.ts +1 -1
  8. package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
  9. package/dist/packages/provider/src/HocuspocusProvider.d.ts +14 -36
  10. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +4 -8
  11. package/dist/packages/provider/src/IncomingMessage.d.ts +2 -2
  12. package/dist/packages/provider/src/MessageReceiver.d.ts +2 -4
  13. package/dist/packages/provider/src/MessageSender.d.ts +2 -2
  14. package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
  15. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
  16. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +3 -3
  17. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +3 -3
  18. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +3 -3
  19. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
  20. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +3 -3
  21. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +3 -3
  22. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
  23. package/dist/packages/provider/src/index.d.ts +3 -5
  24. package/dist/packages/provider/src/types.d.ts +50 -10
  25. package/dist/packages/server/src/ClientConnection.d.ts +16 -8
  26. package/dist/packages/server/src/Connection.d.ts +14 -20
  27. package/dist/packages/server/src/DirectConnection.d.ts +4 -4
  28. package/dist/packages/server/src/Document.d.ts +2 -6
  29. package/dist/packages/server/src/Hocuspocus.d.ts +6 -15
  30. package/dist/packages/server/src/IncomingMessage.d.ts +4 -3
  31. package/dist/packages/server/src/MessageReceiver.d.ts +6 -8
  32. package/dist/packages/server/src/OutgoingMessage.d.ts +2 -1
  33. package/dist/packages/server/src/Server.d.ts +3 -3
  34. package/dist/packages/server/src/index.d.ts +9 -10
  35. package/dist/packages/server/src/types.d.ts +41 -13
  36. package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
  37. package/dist/packages/transformer/src/Tiptap.d.ts +1 -1
  38. package/dist/packages/transformer/src/index.d.ts +3 -3
  39. package/dist/playground/frontend/app/SocketContext.d.ts +2 -0
  40. package/dist/playground/frontend/next.config.d.ts +3 -0
  41. package/dist/tests/utils/index.d.ts +9 -9
  42. package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
  43. package/package.json +3 -3
  44. package/dist/packages/provider/src/TiptapCollabProvider.d.ts +0 -64
  45. package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +0 -20
  46. package/dist/packages/server/src/Debugger.d.ts +0 -14
  47. package/dist/playground/frontend/vite.config.d.ts +0 -2
  48. package/dist/tests/server/getMessageLogs.d.ts +0 -1
  49. package/dist/tests/server/requiresAuthentication.d.ts +0 -1
  50. /package/dist/{playground/frontend/src/main.d.ts → tests/server/beforeSync.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-throttle.cjs","sources":["../src/index.ts"],"sourcesContent":["import type {\n Extension,\n onConnectPayload,\n} from '@hocuspocus/server'\n\nexport interface ThrottleConfiguration {\n throttle: number | null | false, // how many requests within `consideredSeconds` until we're rejecting requests (setting this to 15 means the 16th request will be rejected)\n consideredSeconds: number, // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n banTime: number, // for how long to ban after receiving too many requests (in minutes!)\n cleanupInterval: number // how often to clean up the records of IPs (this won't delete ips that are still blocked or recent enough by `consideredSeconds`)\n}\n\nexport class Throttle implements Extension {\n\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n consideredSeconds: 60,\n cleanupInterval: 90,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n cleanupInterval?: NodeJS.Timeout\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1000)\n }\n\n onDestroy() {\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval)\n }\n\n return Promise.resolve()\n }\n\n public clearMaps() {\n this.connectionsByIp.forEach((value, key) => {\n const filteredValue = value\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n if (filteredValue.length) {\n this.connectionsByIp.set(key, filteredValue)\n } else {\n this.connectionsByIp.delete(key)\n }\n })\n\n this.bannedIps.forEach((value, key) => {\n if (!this.isBanned(key)) {\n this.bannedIps.delete(key)\n }\n })\n }\n\n isBanned(ip: string) {\n const bannedAt = this.bannedIps.get(ip) || 0\n return Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))\n }\n\n /**\n * Throttle requests\n * @private\n */\n private throttle(ip: string): boolean {\n if (!this.configuration.throttle) {\n return false\n }\n\n if (this.isBanned(ip)) return true\n\n this.bannedIps.delete(ip)\n\n // add this connection try to the list of previous connections\n const previousConnections = this.connectionsByIp.get(ip) || []\n previousConnections.push(Date.now())\n\n // calculate the previous connections in the last considered time interval\n const previousConnectionsInTheConsideredInterval = previousConnections\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval)\n\n if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {\n this.bannedIps.set(ip, Date.now())\n return true\n }\n\n return false\n }\n\n /**\n * onConnect hook\n * @param data\n */\n onConnect(data: onConnectPayload): Promise<any> {\n const { request } = data\n\n // get the remote ip address\n const ip = request.headers['x-real-ip']\n || request.headers['x-forwarded-for']\n || request.socket.remoteAddress\n || ''\n\n // throttle the connection\n return this.throttle(<string> ip) ? Promise.reject() : Promise.resolve()\n }\n\n}\n"],"names":[],"mappings":";;MAYa,QAAQ,CAAA;AAenB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAhB1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,eAAe,EAAE,EAAE;SACpB,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAQxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,YAAA,GAAG,aAAa;SACjB,CAAA;QAED,IAAI,CAAC,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,eAAe,GAAG,IAAI,CAAC,CAAA;KACzG;IAED,SAAS,GAAA;AACP,QAAA,IAAI,IAAI,CAAC,eAAe,EAAE;AACxB,YAAA,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;SACpC;AAED,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;KACzB;IAEM,SAAS,GAAA;QACd,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,KAAI;YAC1C,MAAM,aAAa,GAAG,KAAK;iBACxB,MAAM,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa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,OAAO,CAAC,OAAO,CAAC,WAAW;AACjC,eAAA,OAAO,CAAC,OAAO,CAAC,iBAAiB;eACjC,OAAO,CAAC,MAAM,CAAC;AACf,eAAA,EAAE;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE;;AAG3E;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-throttle.esm.js","sources":["../src/index.ts"],"sourcesContent":["import type {\n Extension,\n onConnectPayload,\n} from '@hocuspocus/server'\n\nexport interface ThrottleConfiguration {\n throttle: number | null | false, // how many requests within `consideredSeconds` until we're rejecting requests (setting this to 15 means the 16th request will be rejected)\n consideredSeconds: number, // how many seconds to consider (default is last 60 seconds from the current connection attempt)\n banTime: number, // for how long to ban after receiving too many requests (in minutes!)\n cleanupInterval: number // how often to clean up the records of IPs (this won't delete ips that are still blocked or recent enough by `consideredSeconds`)\n}\n\nexport class Throttle implements Extension {\n\n configuration: ThrottleConfiguration = {\n throttle: 15,\n banTime: 5,\n consideredSeconds: 60,\n cleanupInterval: 90,\n }\n\n connectionsByIp: Map<string, Array<number>> = new Map()\n\n bannedIps: Map<string, number> = new Map()\n\n cleanupInterval?: NodeJS.Timeout\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<ThrottleConfiguration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n this.cleanupInterval = setInterval(this.clearMaps.bind(this), this.configuration.cleanupInterval * 1000)\n }\n\n onDestroy() {\n if (this.cleanupInterval) {\n clearInterval(this.cleanupInterval)\n }\n\n return Promise.resolve()\n }\n\n public clearMaps() {\n this.connectionsByIp.forEach((value, key) => {\n const filteredValue = value\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n if (filteredValue.length) {\n this.connectionsByIp.set(key, filteredValue)\n } else {\n this.connectionsByIp.delete(key)\n }\n })\n\n this.bannedIps.forEach((value, key) => {\n if (!this.isBanned(key)) {\n this.bannedIps.delete(key)\n }\n })\n }\n\n isBanned(ip: string) {\n const bannedAt = this.bannedIps.get(ip) || 0\n return Date.now() < (bannedAt + (this.configuration.banTime * 60 * 1000))\n }\n\n /**\n * Throttle requests\n * @private\n */\n private throttle(ip: string): boolean {\n if (!this.configuration.throttle) {\n return false\n }\n\n if (this.isBanned(ip)) return true\n\n this.bannedIps.delete(ip)\n\n // add this connection try to the list of previous connections\n const previousConnections = this.connectionsByIp.get(ip) || []\n previousConnections.push(Date.now())\n\n // calculate the previous connections in the last considered time interval\n const previousConnectionsInTheConsideredInterval = previousConnections\n .filter(timestamp => timestamp + (this.configuration.consideredSeconds * 1000) > Date.now())\n\n this.connectionsByIp.set(ip, previousConnectionsInTheConsideredInterval)\n\n if (previousConnectionsInTheConsideredInterval.length > this.configuration.throttle) {\n this.bannedIps.set(ip, Date.now())\n return true\n }\n\n return false\n }\n\n /**\n * onConnect hook\n * @param data\n */\n onConnect(data: onConnectPayload): Promise<any> {\n const { request } = data\n\n // get the remote ip address\n const ip = request.headers['x-real-ip']\n || request.headers['x-forwarded-for']\n || request.socket.remoteAddress\n || ''\n\n // throttle the connection\n return this.throttle(<string> ip) ? Promise.reject() : Promise.resolve()\n }\n\n}\n"],"names":[],"mappings":"MAYa,QAAQ,CAAA;AAenB;;AAEG;AACH,IAAA,WAAA,CAAY,aAA8C,EAAA;AAhB1D,QAAA,IAAA,CAAA,aAAa,GAA0B;AACrC,YAAA,QAAQ,EAAE,EAAE;AACZ,YAAA,OAAO,EAAE,CAAC;AACV,YAAA,iBAAiB,EAAE,EAAE;AACrB,YAAA,eAAe,EAAE,EAAE;SACpB,CAAA;AAED,QAAA,IAAA,CAAA,eAAe,GAA+B,IAAI,GAAG,EAAE,CAAA;AAEvD,QAAA,IAAA,CAAA,SAAS,GAAwB,IAAI,GAAG,EAAE,CAAA;QAQxC,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;AACrB,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M,CAAC,SAAS,IAAI,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE9F,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC;QAExE,IAAI,0CAA0C,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;AACnF,YAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC;AAClC,YAAA,OAAO,IAAI;;AAGb,QAAA,OAAO,KAAK;;AAGd;;;AAGG;AACH,IAAA,SAAS,CAAC,IAAsB,EAAA;AAC9B,QAAA,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI;;AAGxB,QAAA,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW;AACjC,eAAA,OAAO,CAAC,OAAO,CAAC,iBAAiB;eACjC,OAAO,CAAC,MAAM,CAAC;AACf,eAAA,EAAE;;QAGP,OAAO,IAAI,CAAC,QAAQ,CAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE;;AAG3E;;;;"}
@@ -1,4 +1,4 @@
1
- export * from './auth.js';
2
- export * from './CloseEvents.js';
3
- export * from './awarenessStatesToArray.js';
4
- export * from './types.js';
1
+ export * from './auth.ts';
2
+ export * from './CloseEvents.ts';
3
+ export * from './awarenessStatesToArray.ts';
4
+ export * from './types.ts';
@@ -1 +1 @@
1
- export * from './Database.js';
1
+ export * from './Database.ts';
@@ -1 +1 @@
1
- export * from './Logger.js';
1
+ export * from './Logger.ts';
@@ -2,7 +2,6 @@ import type { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
2
2
  import RedisClient from 'ioredis';
3
3
  import Redlock from 'redlock';
4
4
  import type { Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
5
- import { Debugger } from '@hocuspocus/server';
6
5
  export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
7
6
  export interface Configuration {
8
7
  /**
@@ -64,8 +63,13 @@ export declare class Redis implements Extension {
64
63
  instance: Hocuspocus;
65
64
  redlock: Redlock;
66
65
  locks: Map<string, Redlock.Lock>;
67
- logger: Debugger;
68
66
  messagePrefix: Buffer;
67
+ /**
68
+ * When we have a high frequency of updates to a document we don't need tons of setTimeouts
69
+ * piling up, so we'll track them to keep it to the most recent per document.
70
+ */
71
+ private pendingDisconnects;
72
+ private pendingAfterStoreDocumentResolves;
69
73
  constructor(configuration: Partial<Configuration>);
70
74
  onConfigure({ instance }: onConfigurePayload): Promise<void>;
71
75
  private getKey;
@@ -1 +1 @@
1
- export * from './Redis.js';
1
+ export * from './Redis.ts';
@@ -1 +1 @@
1
- export * from './SQLite.js';
1
+ export * from './SQLite.ts';
@@ -1,11 +1,10 @@
1
- import * as mutex from 'lib0/mutex';
2
- import type { CloseEvent, Event, MessageEvent } from 'ws';
1
+ import type { Event, MessageEvent } from 'ws';
3
2
  import { Awareness } from 'y-protocols/awareness';
4
3
  import * as Y from 'yjs';
5
- import EventEmitter from './EventEmitter.js';
6
- import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.js';
7
- import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.js';
8
- import type { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters } from './types.js';
4
+ import EventEmitter from './EventEmitter.ts';
5
+ import type { CompleteHocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket.ts';
6
+ import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket.ts';
7
+ import type { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onSyncedParameters } from './types.ts';
9
8
  export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name'>> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> | Required<Pick<CompleteHocuspocusProviderConfiguration, 'websocketProvider'>>);
10
9
  export interface CompleteHocuspocusProviderConfiguration {
11
10
  /**
@@ -16,10 +15,6 @@ export interface CompleteHocuspocusProviderConfiguration {
16
15
  * The actual Y.js document
17
16
  */
18
17
  document: Y.Doc;
19
- /**
20
- * Pass false to disable broadcasting between browser tabs.
21
- */
22
- broadcast: boolean;
23
18
  /**
24
19
  * An Awareness instance to keep the presence state of all clients.
25
20
  *
@@ -33,12 +28,6 @@ export interface CompleteHocuspocusProviderConfiguration {
33
28
  * A token that’s sent to the backend for authentication purposes.
34
29
  */
35
30
  token: string | (() => string) | (() => Promise<string>) | null;
36
- /**
37
- * URL parameters that should be added.
38
- */
39
- parameters: {
40
- [key: string]: any;
41
- };
42
31
  /**
43
32
  * Hocuspocus websocket provider
44
33
  */
@@ -53,7 +42,6 @@ export interface CompleteHocuspocusProviderConfiguration {
53
42
  onConnect: () => void;
54
43
  onMessage: (data: onMessageParameters) => void;
55
44
  onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
56
- onStatus: (data: onStatusParameters) => void;
57
45
  onSynced: (data: onSyncedParameters) => void;
58
46
  onDisconnect: (data: onDisconnectParameters) => void;
59
47
  onClose: (data: onCloseParameters) => void;
@@ -61,37 +49,26 @@ export interface CompleteHocuspocusProviderConfiguration {
61
49
  onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
62
50
  onAwarenessChange: (data: onAwarenessChangeParameters) => void;
63
51
  onStateless: (data: onStatelessParameters) => void;
64
- /**
65
- * Don’t output any warnings.
66
- */
67
- quiet: boolean;
68
- /**
69
- * Pass `false` to start the connection manually.
70
- */
71
- connect: boolean;
72
- /**
73
- * Pass `false` to close the connection manually.
74
- */
75
- preserveConnection: boolean;
76
52
  }
77
53
  export declare class AwarenessError extends Error {
78
54
  code: number;
79
55
  }
80
56
  export declare class HocuspocusProvider extends EventEmitter {
81
57
  configuration: CompleteHocuspocusProviderConfiguration;
82
- subscribedToBroadcastChannel: boolean;
83
58
  isSynced: boolean;
84
59
  unsyncedChanges: number;
85
60
  isAuthenticated: boolean;
86
61
  authorizedScope: string | undefined;
87
- mux: mutex.mutex;
62
+ manageSocket: boolean;
63
+ private isAttached;
88
64
  intervals: any;
89
65
  constructor(configuration: HocuspocusProviderConfiguration);
66
+ boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
67
+ boundAwarenessUpdateHandler: ({ added, updated, removed }: any, origin: any) => void;
90
68
  boundPageHide: () => void;
91
69
  boundOnOpen: (event: Event) => Promise<void>;
92
- boundOnClose: (event: CloseEvent) => void;
70
+ boundOnClose: () => void;
93
71
  forwardConnect: (e: any) => this;
94
- forwardOpen: (e: any) => this;
95
72
  forwardClose: (e: any) => this;
96
73
  forwardDisconnect: (e: any) => this;
97
74
  forwardDestroy: (e: any) => this;
@@ -117,16 +94,17 @@ export declare class HocuspocusProvider extends EventEmitter {
117
94
  get synced(): boolean;
118
95
  set synced(state: boolean);
119
96
  receiveStateless(payload: string): void;
120
- get isAuthenticationRequired(): boolean;
121
97
  connect(): Promise<void>;
122
98
  disconnect(): void;
123
99
  onOpen(event: Event): Promise<void>;
124
100
  getToken(): Promise<string | null>;
125
101
  startSync(): void;
126
- send(message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
102
+ send(message: ConstructableOutgoingMessage, args: any): void;
127
103
  onMessage(event: MessageEvent): void;
128
- onClose(event: CloseEvent): void;
104
+ onClose(): void;
129
105
  destroy(): void;
106
+ detach(): void;
107
+ attach(): void;
130
108
  permissionDeniedHandler(reason: string): void;
131
109
  authenticatedHandler(scope: string): void;
132
110
  setAwarenessField(key: string, value: any): void;
@@ -1,8 +1,8 @@
1
1
  import type { MessageEvent, Event } from 'ws';
2
- import EventEmitter from './EventEmitter.js';
3
- import type { HocuspocusProvider } from './HocuspocusProvider.js';
4
- import type { onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.js';
5
- import { WebSocketStatus } from './types.js';
2
+ import EventEmitter from './EventEmitter.ts';
3
+ import type { HocuspocusProvider } from './HocuspocusProvider.ts';
4
+ import type { onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from './types.ts';
5
+ import { WebSocketStatus } from './types.ts';
6
6
  export type HocusPocusWebSocket = WebSocket & {
7
7
  identifier: string;
8
8
  };
@@ -72,10 +72,6 @@ export interface CompleteHocuspocusProviderWebsocketConfiguration {
72
72
  onDestroy: () => void;
73
73
  onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
74
74
  onAwarenessChange: (data: onAwarenessChangeParameters) => void;
75
- /**
76
- * Don’t output any warnings.
77
- */
78
- quiet: boolean;
79
75
  /**
80
76
  * Map of attached providers keyed by documentName.
81
77
  */
@@ -1,6 +1,6 @@
1
1
  import type { Decoder } from 'lib0/decoding';
2
2
  import type { Encoder } from 'lib0/encoding';
3
- import type { MessageType } from './types.js';
3
+ import type { MessageType } from './types.ts';
4
4
  export declare class IncomingMessage {
5
5
  data: any;
6
6
  encoder: Encoder;
@@ -9,7 +9,7 @@ export declare class IncomingMessage {
9
9
  peekVarString(): string;
10
10
  readVarUint(): MessageType;
11
11
  readVarString(): string;
12
- readVarUint8Array(): Uint8Array;
12
+ readVarUint8Array(): Uint8Array<ArrayBufferLike>;
13
13
  writeVarUint(type: MessageType): void;
14
14
  writeVarString(string: string): void;
15
15
  writeVarUint8Array(data: Uint8Array): void;
@@ -1,10 +1,8 @@
1
- import type { HocuspocusProvider } from './HocuspocusProvider.js';
2
- import type { IncomingMessage } from './IncomingMessage.js';
1
+ import type { HocuspocusProvider } from './HocuspocusProvider.ts';
2
+ import type { IncomingMessage } from './IncomingMessage.ts';
3
3
  export declare class MessageReceiver {
4
4
  message: IncomingMessage;
5
- broadcasted: boolean;
6
5
  constructor(message: IncomingMessage);
7
- setBroadcasted(value: boolean): this;
8
6
  apply(provider: HocuspocusProvider, emitSynced: boolean): void;
9
7
  private applySyncMessage;
10
8
  applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean): void;
@@ -1,10 +1,10 @@
1
1
  import type { Encoder } from 'lib0/encoding';
2
- import type { ConstructableOutgoingMessage } from './types.js';
2
+ import type { ConstructableOutgoingMessage } from './types.ts';
3
3
  export declare class MessageSender {
4
4
  encoder: Encoder;
5
5
  message: any;
6
6
  constructor(Message: ConstructableOutgoingMessage, args?: any);
7
- create(): Uint8Array;
7
+ create(): Uint8Array<ArrayBufferLike>;
8
8
  send(webSocket: any): void;
9
9
  broadcast(channel: string): void;
10
10
  }
@@ -1,9 +1,9 @@
1
1
  import type { Encoder } from 'lib0/encoding';
2
- import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.js';
2
+ import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types.ts';
3
3
  export declare class OutgoingMessage implements OutgoingMessageInterface {
4
4
  encoder: Encoder;
5
5
  type?: MessageType;
6
6
  constructor();
7
7
  get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
8
- toUint8Array(): Uint8Array;
8
+ toUint8Array(): Uint8Array<ArrayBufferLike>;
9
9
  }
@@ -1,6 +1,6 @@
1
- import type { OutgoingMessageArguments } from '../types.js';
2
- import { MessageType } from '../types.js';
3
- import { OutgoingMessage } from '../OutgoingMessage.js';
1
+ import type { OutgoingMessageArguments } from '../types.ts';
2
+ import { MessageType } from '../types.ts';
3
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
4
4
  export declare class AuthenticationMessage extends OutgoingMessage {
5
5
  type: MessageType;
6
6
  description: string;
@@ -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
  export declare class AwarenessMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -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
  export declare class CloseMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -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
  export declare class QueryAwarenessMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,6 +1,6 @@
1
- import type { OutgoingMessageArguments } from '../types.js';
2
- import { MessageType } from '../types.js';
3
- import { OutgoingMessage } from '../OutgoingMessage.js';
1
+ import type { OutgoingMessageArguments } from '../types.ts';
2
+ import { MessageType } from '../types.ts';
3
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
4
4
  export declare class StatelessMessage extends OutgoingMessage {
5
5
  type: MessageType;
6
6
  description: string;
@@ -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
  export declare class SyncStepOneMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -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
  export declare class SyncStepTwoMessage extends OutgoingMessage {
6
6
  type: MessageType;
7
7
  description: string;
@@ -1,6 +1,6 @@
1
- import type { OutgoingMessageArguments } from '../types.js';
2
- import { MessageType } from '../types.js';
3
- import { OutgoingMessage } from '../OutgoingMessage.js';
1
+ import type { OutgoingMessageArguments } from '../types.ts';
2
+ import { MessageType } from '../types.ts';
3
+ import { OutgoingMessage } from '../OutgoingMessage.ts';
4
4
  export declare class UpdateMessage extends OutgoingMessage {
5
5
  type: MessageType;
6
6
  description: string;
@@ -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';
@@ -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
  export declare enum MessageType {
15
15
  Sync = 0,
16
16
  Awareness = 1,
@@ -88,14 +88,17 @@ export type TCollabThread<Data = any, CommentData = any> = {
88
88
  id: string;
89
89
  createdAt: number;
90
90
  updatedAt: number;
91
+ deletedAt: number | null;
91
92
  resolvedAt?: string;
92
93
  comments: TCollabComment<CommentData>[];
94
+ deletedComments: TCollabComment<CommentData>[];
93
95
  data: Data;
94
96
  };
95
97
  export type TCollabComment<Data = any> = {
96
98
  id: string;
97
- createdAt: number;
98
- updatedAt: number;
99
+ createdAt: string;
100
+ updatedAt: string;
101
+ deletedAt?: string;
99
102
  data: Data;
100
103
  content: any;
101
104
  };
@@ -144,3 +147,40 @@ export type THistoryDocumentRevertedEvent = {
144
147
  event: 'document.reverted';
145
148
  version: number;
146
149
  };
150
+ export type DeleteCommentOptions = {
151
+ /**
152
+ * If `true`, the thread will also be deleted if the deleted comment was the first comment in the thread.
153
+ */
154
+ deleteThread?: boolean;
155
+ /**
156
+ * If `true`, will remove the content of the deleted comment
157
+ */
158
+ deleteContent?: boolean;
159
+ };
160
+ export type DeleteThreadOptions = {
161
+ /**
162
+ * If `true`, will remove the comments on the thread,
163
+ * otherwise will only mark the thread as deleted
164
+ * and keep the comments
165
+ * @default false
166
+ */
167
+ deleteComments?: boolean;
168
+ /**
169
+ * If `true`, will forcefully remove the thread and all comments,
170
+ * otherwise will only mark the thread as deleted
171
+ * and keep the comments
172
+ * @default false
173
+ */
174
+ force?: boolean;
175
+ };
176
+ /**
177
+ * The type of thread
178
+ */
179
+ export type ThreadType = 'archived' | 'unarchived';
180
+ export type GetThreadsOptions = {
181
+ /**
182
+ * The types of threads to get
183
+ * @default ['unarchived']
184
+ */
185
+ types?: Array<ThreadType>;
186
+ };
@@ -1,9 +1,9 @@
1
1
  import type { IncomingMessage } from 'http';
2
+ import { type CloseEvent } from '@hocuspocus/common';
2
3
  import type WebSocket from 'ws';
3
- import type { Debugger } from './Debugger.js';
4
- import type Document from './Document.js';
5
- import type { Hocuspocus } from './Hocuspocus.js';
6
- import type { onDisconnectPayload } from './types.js';
4
+ import type Document from './Document.ts';
5
+ import type { Hocuspocus } from './Hocuspocus.ts';
6
+ import type { onDisconnectPayload } from './types.ts';
7
7
  /**
8
8
  * The `ClientConnection` class is responsible for handling an incoming WebSocket
9
9
  *
@@ -15,7 +15,6 @@ export declare class ClientConnection {
15
15
  private readonly request;
16
16
  private readonly documentProvider;
17
17
  private readonly hooks;
18
- private readonly debuggerTool;
19
18
  private readonly opts;
20
19
  private readonly defaultContext;
21
20
  private readonly documentConnections;
@@ -23,8 +22,10 @@ export declare class ClientConnection {
23
22
  private readonly documentConnectionsEstablished;
24
23
  private readonly hookPayloads;
25
24
  private readonly callbacks;
26
- private readonly closeIdleConnectionTimeout;
27
25
  private readonly socketId;
26
+ timeout: number;
27
+ pingInterval: NodeJS.Timeout;
28
+ pongReceived: boolean;
28
29
  /**
29
30
  * The `ClientConnection` class receives incoming WebSocket connections,
30
31
  * runs all hooks:
@@ -37,10 +38,17 @@ export declare class ClientConnection {
37
38
  */
38
39
  constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
39
40
  createDocument: Hocuspocus['createDocument'];
40
- }, hooks: Hocuspocus['hooks'], debuggerTool: Debugger, opts: {
41
- requiresAuthentication: boolean;
41
+ }, hooks: Hocuspocus['hooks'], opts: {
42
42
  timeout: number;
43
43
  }, defaultContext?: any);
44
+ private handleWebsocketClose;
45
+ close(event?: CloseEvent): void;
46
+ handlePong: () => void;
47
+ /**
48
+ * Check if pong was received and close the connection otherwise
49
+ * @private
50
+ */
51
+ private check;
44
52
  /**
45
53
  * Set a callback that will be triggered when the connection is closed
46
54
  */
@@ -1,30 +1,25 @@
1
1
  import type { IncomingMessage as HTTPIncomingMessage } from 'http';
2
- import AsyncLock from 'async-lock';
2
+ import { type CloseEvent } from '@hocuspocus/common';
3
3
  import type WebSocket from 'ws';
4
- import type { CloseEvent } from '@hocuspocus/common';
5
- import type Document from './Document.js';
6
- import type { Debugger } from './Debugger.js';
7
- import type { onStatelessPayload } from './types.js';
4
+ import type Document from './Document.ts';
5
+ import type { beforeSyncPayload, onStatelessPayload } from './types.ts';
8
6
  export declare class Connection {
9
7
  webSocket: WebSocket;
10
8
  context: any;
11
9
  document: Document;
12
- pingInterval: NodeJS.Timeout;
13
- pongReceived: boolean;
14
10
  request: HTTPIncomingMessage;
15
- timeout: number;
16
- callbacks: any;
11
+ callbacks: {
12
+ onClose: ((document: Document, event?: CloseEvent) => void)[];
13
+ beforeHandleMessage: (connection: Connection, update: Uint8Array) => Promise<void>;
14
+ beforeSync: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<void>;
15
+ statelessCallback: (payload: onStatelessPayload) => Promise<void>;
16
+ };
17
17
  socketId: string;
18
- lock: AsyncLock;
19
18
  readOnly: boolean;
20
- logger: Debugger;
21
19
  /**
22
20
  * Constructor.
23
21
  */
24
- constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
25
- boundClose: (event?: CloseEvent) => void;
26
- boundHandlePong: () => void;
27
- handlePong(): void;
22
+ constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, socketId: string, context: any, readOnly?: boolean);
28
23
  /**
29
24
  * Set a callback that will be triggered when the connection is closed
30
25
  */
@@ -37,6 +32,10 @@ export declare class Connection {
37
32
  * Set a callback that will be triggered before an message is handled
38
33
  */
39
34
  beforeHandleMessage(callback: (connection: Connection, update: Uint8Array) => Promise<any>): Connection;
35
+ /**
36
+ * Set a callback that will be triggered before a sync message is handled
37
+ */
38
+ beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, 'type' | 'payload'>) => Promise<any>): Connection;
40
39
  /**
41
40
  * Send the given message
42
41
  */
@@ -49,11 +48,6 @@ export declare class Connection {
49
48
  * Graceful wrapper around the WebSocket close method.
50
49
  */
51
50
  close(event?: CloseEvent): void;
52
- /**
53
- * Check if pong was received and close the connection otherwise
54
- * @private
55
- */
56
- private check;
57
51
  /**
58
52
  * Send the current document awareness to the client, if any
59
53
  * @private
@@ -1,6 +1,6 @@
1
- import type Document from './Document.js';
2
- import type { Hocuspocus } from './Hocuspocus.js';
3
- import type { DirectConnection as DirectConnectionInterface } from './types.js';
1
+ import type Document from './Document.ts';
2
+ import type { Hocuspocus } from './Hocuspocus.ts';
3
+ import type { DirectConnection as DirectConnectionInterface } from './types.ts';
4
4
  export declare class DirectConnection implements DirectConnectionInterface {
5
5
  document: Document | null;
6
6
  instance: Hocuspocus;
@@ -9,6 +9,6 @@ export declare class DirectConnection implements DirectConnectionInterface {
9
9
  * Constructor.
10
10
  */
11
11
  constructor(document: Document, instance: Hocuspocus, context?: any);
12
- transact(transaction: (document: Document) => void, transactionOrigin?: any): Promise<void>;
12
+ transact(transaction: (document: Document) => void): Promise<void>;
13
13
  disconnect(): Promise<void>;
14
14
  }
@@ -1,9 +1,7 @@
1
1
  import type WebSocket from 'ws';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import { Doc } from 'yjs';
4
- import type { mutex } from 'lib0/mutex.js';
5
- import type Connection from './Connection.js';
6
- import type { Debugger } from './Debugger.js';
4
+ import type Connection from './Connection.ts';
7
5
  export declare class Document extends Doc {
8
6
  awareness: Awareness;
9
7
  callbacks: {
@@ -16,14 +14,12 @@ export declare class Document extends Doc {
16
14
  }>;
17
15
  directConnectionsCount: number;
18
16
  name: string;
19
- mux: mutex;
20
- logger?: Debugger;
21
17
  isLoading: boolean;
22
18
  isDestroyed: boolean;
23
19
  /**
24
20
  * Constructor.
25
21
  */
26
- constructor(name: string, logger?: Debugger, yDocOptions?: object);
22
+ constructor(name: string, yDocOptions?: object);
27
23
  /**
28
24
  * Check if the Document (XMLFragment or Map) is empty
29
25
  */
@@ -1,10 +1,9 @@
1
1
  import type { IncomingMessage } from 'http';
2
2
  import type WebSocket from 'ws';
3
- import type { Server } from './Server.js';
4
- import { Debugger } from './Debugger.js';
5
- import { DirectConnection } from './DirectConnection.js';
6
- import Document from './Document.js';
7
- import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from './types.js';
3
+ import { DirectConnection } from './DirectConnection.ts';
4
+ import Document from './Document.ts';
5
+ import type { Server } from './Server.ts';
6
+ import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from './types.ts';
8
7
  export declare const defaultConfiguration: {
9
8
  name: null;
10
9
  timeout: number;
@@ -22,7 +21,6 @@ export declare class Hocuspocus {
22
21
  loadingDocuments: Map<string, Promise<Document>>;
23
22
  documents: Map<string, Document>;
24
23
  server?: Server;
25
- debugger: Debugger;
26
24
  debouncer: {
27
25
  debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any;
28
26
  isDebounced: (id: string) => boolean;
@@ -33,7 +31,6 @@ export declare class Hocuspocus {
33
31
  * Configure Hocuspocus
34
32
  */
35
33
  configure(configuration: Partial<Configuration>): Hocuspocus;
36
- get requiresAuthentication(): boolean;
37
34
  /**
38
35
  * Get the total number of active documents
39
36
  */
@@ -68,19 +65,13 @@ export declare class Hocuspocus {
68
65
  * Create a new document by the given request
69
66
  */
70
67
  createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
71
- loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
68
+ loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connectionConfig: ConnectionConfiguration, context?: any): Promise<Document>;
72
69
  storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): any;
73
70
  /**
74
71
  * Run the given hook on all configured extensions.
75
72
  * Runs the given callback after each hook.
76
73
  */
77
74
  hooks<T extends HookName>(name: T, payload: HookPayloadByName[T], callback?: Function | null): Promise<any>;
78
- unloadDocument(document: Document): void;
79
- enableDebugging(): void;
80
- enableMessageLogging(): void;
81
- disableLogging(): void;
82
- disableDebugging(): void;
83
- flushMessageLogs(): this;
84
- getMessageLogs(): any[];
75
+ unloadDocument(document: Document): Promise<any>;
85
76
  openDirectConnection(documentName: string, context?: any): Promise<DirectConnection>;
86
77
  }
@@ -1,6 +1,6 @@
1
1
  import type { Decoder } from 'lib0/decoding';
2
2
  import type { Encoder } from 'lib0/encoding';
3
- import type { MessageType } from './types.js';
3
+ import type { MessageType } from './types.ts';
4
4
  export declare class IncomingMessage {
5
5
  /**
6
6
  * Access to the received message.
@@ -14,10 +14,11 @@ export declare class IncomingMessage {
14
14
  private encoderInternal?;
15
15
  constructor(input: any);
16
16
  get encoder(): Encoder;
17
- readVarUint8Array(): Uint8Array;
17
+ readVarUint8Array(): Uint8Array<ArrayBufferLike>;
18
+ peekVarUint8Array(): Uint8Array<ArrayBufferLike>;
18
19
  readVarUint(): number;
19
20
  readVarString(): string;
20
- toUint8Array(): Uint8Array;
21
+ toUint8Array(): Uint8Array<ArrayBufferLike>;
21
22
  writeVarUint(type: MessageType): void;
22
23
  writeVarString(string: string): void;
23
24
  get length(): number;
@@ -1,13 +1,11 @@
1
- import type Connection from './Connection.js';
2
- import type { Debugger } from './Debugger.js';
3
- import type Document from './Document.js';
4
- import type { IncomingMessage } from './IncomingMessage.js';
1
+ import type Connection from './Connection.ts';
2
+ import type Document from './Document.ts';
3
+ import type { IncomingMessage } from './IncomingMessage.ts';
5
4
  export declare class MessageReceiver {
6
5
  message: IncomingMessage;
7
- logger: Debugger;
8
6
  defaultTransactionOrigin?: string;
9
- constructor(message: IncomingMessage, logger: Debugger, defaultTransactionOrigin?: string);
10
- apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
- readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 1 | 2;
7
+ constructor(message: IncomingMessage, defaultTransactionOrigin?: string);
8
+ apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): Promise<void>;
9
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): Promise<0 | 1 | 2>;
12
10
  applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
13
11
  }
@@ -1,6 +1,6 @@
1
1
  import type { Encoder } from 'lib0/encoding';
2
2
  import type { Awareness } from 'y-protocols/awareness';
3
- import type Document from './Document.js';
3
+ import type Document from './Document.ts';
4
4
  export declare class OutgoingMessage {
5
5
  encoder: Encoder;
6
6
  type?: number;
@@ -17,5 +17,6 @@ export declare class OutgoingMessage {
17
17
  writeStateless(payload: string): OutgoingMessage;
18
18
  writeBroadcastStateless(payload: string): OutgoingMessage;
19
19
  writeSyncStatus(updateSaved: boolean): OutgoingMessage;
20
+ writeCloseMessage(reason: string): OutgoingMessage;
20
21
  toUint8Array(): Uint8Array;
21
22
  }
@@ -1,7 +1,7 @@
1
1
  import type { IncomingMessage, Server as HTTPServer, ServerResponse } from 'http';
2
- import type { AddressInfo } from 'ws';
3
2
  import { WebSocketServer } from 'ws';
4
- import { Hocuspocus } from './Hocuspocus.js';
3
+ import type { AddressInfo, ServerOptions } from 'ws';
4
+ import { Hocuspocus } from './Hocuspocus.ts';
5
5
  import type { Configuration } from './types';
6
6
  export interface ServerConfiguration extends Configuration {
7
7
  port?: number;
@@ -18,7 +18,7 @@ export declare class Server {
18
18
  webSocketServer: WebSocketServer;
19
19
  hocuspocus: Hocuspocus;
20
20
  configuration: ServerConfiguration;
21
- constructor(configuration?: Partial<ServerConfiguration>);
21
+ constructor(configuration?: Partial<ServerConfiguration>, websocketOptions?: ServerOptions);
22
22
  setupWebsocketConnection: () => void;
23
23
  setupHttpUpgrade: () => void;
24
24
  requestHandler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
@@ -1,10 +1,9 @@
1
- export * from './Connection.js';
2
- export * from './Debugger.js';
3
- export * from './Document.js';
4
- export * from './Hocuspocus.js';
5
- export * from './IncomingMessage.js';
6
- export * from './MessageReceiver.js';
7
- export * from './OutgoingMessage.js';
8
- export * from './Server.js';
9
- export * from './types.js';
10
- export * from './util/debounce.js';
1
+ export * from './Connection.ts';
2
+ export * from './Document.ts';
3
+ export * from './Hocuspocus.ts';
4
+ export * from './IncomingMessage.ts';
5
+ export * from './MessageReceiver.ts';
6
+ export * from './OutgoingMessage.ts';
7
+ export * from './Server.ts';
8
+ export * from './types.ts';
9
+ export * from './util/debounce.ts';
@@ -1,9 +1,9 @@
1
1
  import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
2
2
  import type { URLSearchParams } from 'url';
3
3
  import type { Awareness } from 'y-protocols/awareness';
4
- import type Connection from './Connection.js';
5
- import type Document from './Document.js';
6
- import type { Hocuspocus } from './Hocuspocus.js';
4
+ import type Connection from './Connection.ts';
5
+ import type Document from './Document.ts';
6
+ import type { Hocuspocus } from './Hocuspocus.ts';
7
7
  export declare enum MessageType {
8
8
  Unknown = -1,
9
9
  Sync = 0,
@@ -23,7 +23,6 @@ export interface AwarenessUpdate {
23
23
  }
24
24
  export interface ConnectionConfiguration {
25
25
  readOnly: boolean;
26
- requiresAuthentication: boolean;
27
26
  isAuthenticated: boolean;
28
27
  }
29
28
  export interface Extension {
@@ -39,6 +38,7 @@ export interface Extension {
39
38
  onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
40
39
  afterLoadDocument?(data: afterLoadDocumentPayload): Promise<any>;
41
40
  beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
41
+ beforeSync?(data: beforeSyncPayload): Promise<any>;
42
42
  beforeBroadcastStateless?(data: beforeBroadcastStatelessPayload): Promise<any>;
43
43
  onStateless?(payload: onStatelessPayload): Promise<any>;
44
44
  onChange?(data: onChangePayload): Promise<any>;
@@ -47,10 +47,11 @@ export interface Extension {
47
47
  onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
48
48
  onRequest?(data: onRequestPayload): Promise<any>;
49
49
  onDisconnect?(data: onDisconnectPayload): Promise<any>;
50
+ beforeUnloadDocument?(data: beforeUnloadDocumentPayload): Promise<any>;
50
51
  afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>;
51
52
  onDestroy?(data: onDestroyPayload): Promise<any>;
52
53
  }
53
- export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'afterUnloadDocument' | 'onDestroy';
54
+ export type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'beforeSync' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'beforeUnloadDocument' | 'afterUnloadDocument' | 'onDestroy';
54
55
  export type HookPayloadByName = {
55
56
  onConfigure: onConfigurePayload;
56
57
  onListen: onListenPayload;
@@ -63,6 +64,7 @@ export type HookPayloadByName = {
63
64
  afterLoadDocument: afterLoadDocumentPayload;
64
65
  beforeHandleMessage: beforeHandleMessagePayload;
65
66
  beforeBroadcastStateless: beforeBroadcastStatelessPayload;
67
+ beforeSync: beforeSyncPayload;
66
68
  onStateless: onStatelessPayload;
67
69
  onChange: onChangePayload;
68
70
  onStoreDocument: onStoreDocumentPayload;
@@ -71,6 +73,7 @@ export type HookPayloadByName = {
71
73
  onRequest: onRequestPayload;
72
74
  onDisconnect: onDisconnectPayload;
73
75
  afterUnloadDocument: afterUnloadDocumentPayload;
76
+ beforeUnloadDocument: beforeUnloadDocumentPayload;
74
77
  onDestroy: onDestroyPayload;
75
78
  };
76
79
  export interface Configuration extends Extension {
@@ -130,7 +133,7 @@ export interface onAuthenticatePayload {
130
133
  request: IncomingMessage;
131
134
  socketId: string;
132
135
  token: string;
133
- connection: ConnectionConfiguration;
136
+ connectionConfig: ConnectionConfiguration;
134
137
  }
135
138
  export interface onCreateDocumentPayload {
136
139
  context: any;
@@ -139,7 +142,7 @@ export interface onCreateDocumentPayload {
139
142
  requestHeaders: IncomingHttpHeaders;
140
143
  requestParameters: URLSearchParams;
141
144
  socketId: string;
142
- connection: ConnectionConfiguration;
145
+ connectionConfig: ConnectionConfiguration;
143
146
  }
144
147
  export interface onConnectPayload {
145
148
  context: any;
@@ -149,7 +152,7 @@ export interface onConnectPayload {
149
152
  requestHeaders: IncomingHttpHeaders;
150
153
  requestParameters: URLSearchParams;
151
154
  socketId: string;
152
- connection: ConnectionConfiguration;
155
+ connectionConfig: ConnectionConfiguration;
153
156
  }
154
157
  export interface connectedPayload {
155
158
  context: any;
@@ -159,8 +162,8 @@ export interface connectedPayload {
159
162
  requestHeaders: IncomingHttpHeaders;
160
163
  requestParameters: URLSearchParams;
161
164
  socketId: string;
162
- connection: ConnectionConfiguration;
163
- connectionInstance: Connection;
165
+ connectionConfig: ConnectionConfiguration;
166
+ connection: Connection;
164
167
  }
165
168
  export interface onLoadDocumentPayload {
166
169
  context: any;
@@ -170,7 +173,7 @@ export interface onLoadDocumentPayload {
170
173
  requestHeaders: IncomingHttpHeaders;
171
174
  requestParameters: URLSearchParams;
172
175
  socketId: string;
173
- connection: ConnectionConfiguration;
176
+ connectionConfig: ConnectionConfiguration;
174
177
  }
175
178
  export interface afterLoadDocumentPayload {
176
179
  context: any;
@@ -180,7 +183,7 @@ export interface afterLoadDocumentPayload {
180
183
  requestHeaders: IncomingHttpHeaders;
181
184
  requestParameters: URLSearchParams;
182
185
  socketId: string;
183
- connection: ConnectionConfiguration;
186
+ connectionConfig: ConnectionConfiguration;
184
187
  }
185
188
  export interface onChangePayload {
186
189
  clientsCount: number;
@@ -206,6 +209,27 @@ export interface beforeHandleMessagePayload {
206
209
  socketId: string;
207
210
  connection: Connection;
208
211
  }
212
+ export interface beforeSyncPayload {
213
+ clientsCount: number;
214
+ context: any;
215
+ document: Document;
216
+ documentName: string;
217
+ connection: Connection;
218
+ /**
219
+ * The y-protocols/sync message type
220
+ * @example
221
+ * 0: SyncStep1
222
+ * 1: SyncStep2
223
+ * 2: YjsUpdate
224
+ *
225
+ * @see https://github.com/yjs/y-protocols/blob/master/sync.js#L13-L40
226
+ */
227
+ type: number;
228
+ /**
229
+ * The payload of the y-sync message.
230
+ */
231
+ payload: Uint8Array;
232
+ }
209
233
  export interface beforeBroadcastStatelessPayload {
210
234
  document: Document;
211
235
  documentName: string;
@@ -250,7 +274,7 @@ export interface fetchPayload {
250
274
  requestHeaders: IncomingHttpHeaders;
251
275
  requestParameters: URLSearchParams;
252
276
  socketId: string;
253
- connection: ConnectionConfiguration;
277
+ connectionConfig: ConnectionConfiguration;
254
278
  }
255
279
  export interface storePayload extends onStoreDocumentPayload {
256
280
  state: Buffer;
@@ -293,6 +317,10 @@ export interface afterUnloadDocumentPayload {
293
317
  instance: Hocuspocus;
294
318
  documentName: string;
295
319
  }
320
+ export interface beforeUnloadDocumentPayload {
321
+ instance: Hocuspocus;
322
+ documentName: string;
323
+ }
296
324
  export interface DirectConnection {
297
325
  transact(transaction: (document: Document) => void): Promise<void>;
298
326
  disconnect(): void;
@@ -1,6 +1,6 @@
1
1
  import { Doc } from 'yjs';
2
2
  import { Schema } from '@tiptap/pm/model';
3
- import type { Transformer } from './types.js';
3
+ import type { Transformer } from './types.ts';
4
4
  declare class Prosemirror implements Transformer {
5
5
  defaultSchema: Schema;
6
6
  schema(schema: Schema): Prosemirror;
@@ -1,6 +1,6 @@
1
1
  import type { Doc } from 'yjs';
2
2
  import type { Extensions } from '@tiptap/core';
3
- import type { Transformer } from './types.js';
3
+ import type { Transformer } from './types.ts';
4
4
  export declare class Tiptap implements Transformer {
5
5
  defaultExtensions: Extensions;
6
6
  extensions(extensions: Extensions): Tiptap;
@@ -1,3 +1,3 @@
1
- export * from './Prosemirror.js';
2
- export * from './Tiptap.js';
3
- export * from './types.js';
1
+ export * from './Prosemirror.ts';
2
+ export * from './Tiptap.ts';
3
+ export * from './types.ts';
@@ -0,0 +1,2 @@
1
+ import type { HocuspocusProviderWebsocket } from "@hocuspocus/provider";
2
+ export declare const SocketContext: import("react").Context<HocuspocusProviderWebsocket | null>;
@@ -0,0 +1,3 @@
1
+ import type { NextConfig } from "next";
2
+ declare const nextConfig: NextConfig;
3
+ export default nextConfig;
@@ -1,9 +1,9 @@
1
- export * from './createDirectory.js';
2
- export * from './flushRedis.js';
3
- export * from './newHocuspocus.js';
4
- export * from './newHocuspocusProvider.js';
5
- export * from './newHocuspocusProviderWebsocket.js';
6
- export * from './randomInteger.js';
7
- export * from './redisConnectionSettings.js';
8
- export * from './removeDirectory.js';
9
- export * from './sleep.js';
1
+ export * from './createDirectory.ts';
2
+ export * from './flushRedis.ts';
3
+ export * from './newHocuspocus.ts';
4
+ export * from './newHocuspocusProvider.ts';
5
+ export * from './newHocuspocusProviderWebsocket.ts';
6
+ export * from './randomInteger.ts';
7
+ export * from './redisConnectionSettings.ts';
8
+ export * from './removeDirectory.ts';
9
+ export * from './sleep.ts';
@@ -1,3 +1,3 @@
1
- import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
1
+ import { HocuspocusProvider, type HocuspocusProviderConfiguration, type HocuspocusProviderWebsocket, type HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
2
2
  import type { Hocuspocus } from '@hocuspocus/server';
3
- export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>) => HocuspocusProvider;
3
+ export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>, websocketProvider?: HocuspocusProviderWebsocket) => HocuspocusProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-throttle",
3
- "version": "3.0.0-rc.0",
3
+ "version": "3.0.6-rc.0",
4
4
  "description": "hocuspocus throttle extension",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -15,7 +15,7 @@
15
15
  "types": "dist/packages/extension-throttle/src/index.d.ts",
16
16
  "exports": {
17
17
  "source": {
18
- "import": "./src"
18
+ "import": "./src/index.ts"
19
19
  },
20
20
  "default": {
21
21
  "import": "./dist/hocuspocus-throttle.esm.js",
@@ -28,7 +28,7 @@
28
28
  "dist"
29
29
  ],
30
30
  "dependencies": {
31
- "@hocuspocus/server": "^3.0.0-rc.0"
31
+ "@hocuspocus/server": "^3.0.6-rc.0"
32
32
  },
33
33
  "gitHead": "b3454a4ca289a84ddfb7fa5607a2d4b8d5c37e9d"
34
34
  }
@@ -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 {};