@hocuspocus/provider 3.2.1 → 3.2.3

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.
@@ -1,7 +1,8 @@
1
1
  import type { Extension, Hocuspocus, afterLoadDocumentPayload, afterStoreDocumentPayload, beforeBroadcastStatelessPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, onDisconnectPayload, onStoreDocumentPayload } from "@hocuspocus/server";
2
- import type { ClusterNode, ClusterOptions, RedisOptions } from "ioredis";
3
- import Redlock from "redlock";
4
- export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
2
+ import { Redlock, type ExecutionResult, type Lock } from '@sesamecare-oss/redlock';
3
+ import type { Cluster, ClusterNode, ClusterOptions, RedisOptions } from "ioredis";
4
+ import RedisClient from "ioredis";
5
+ export type RedisInstance = RedisClient | Cluster;
5
6
  export interface Configuration {
6
7
  /**
7
8
  * Redis port
@@ -61,7 +62,10 @@ export declare class Redis implements Extension {
61
62
  sub: RedisInstance;
62
63
  instance: Hocuspocus;
63
64
  redlock: Redlock;
64
- locks: Map<string, Redlock.Lock>;
65
+ locks: Map<string, {
66
+ lock: Lock;
67
+ release?: Promise<ExecutionResult>;
68
+ }>;
65
69
  messagePrefix: Buffer;
66
70
  /**
67
71
  * When we have a high frequency of updates to a document we don't need tons of setTimeouts
@@ -93,15 +97,15 @@ export declare class Redis implements Extension {
93
97
  * Before the document is stored, make sure to set a lock in Redis.
94
98
  * That’s meant to avoid conflicts with other instances trying to store the document.
95
99
  */
96
- onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<unknown>;
100
+ onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<void>;
97
101
  /**
98
102
  * Release the Redis lock, so other instances can store documents.
99
103
  */
100
- afterStoreDocument({ documentName, socketId, }: afterStoreDocumentPayload): Promise<void>;
104
+ afterStoreDocument({ documentName, socketId }: afterStoreDocumentPayload): Promise<void>;
101
105
  /**
102
106
  * Handle awareness update messages received directly by this Hocuspocus instance.
103
107
  */
104
- onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<any>;
108
+ onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<number>;
105
109
  /**
106
110
  * Handle incoming messages published on subscribed document channels.
107
111
  * Note that this will also include messages from ourselves as it is not possible
@@ -117,7 +121,7 @@ export declare class Redis implements Extension {
117
121
  * no one connected anymore.
118
122
  */
119
123
  onDisconnect: ({ documentName }: onDisconnectPayload) => Promise<void>;
120
- beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<any>;
124
+ beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
121
125
  /**
122
126
  * Kill the Redlock connection immediately.
123
127
  */
@@ -2,11 +2,16 @@ import type { Event, MessageEvent } from "ws";
2
2
  import EventEmitter from "./EventEmitter.ts";
3
3
  import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
4
4
  import { WebSocketStatus, type onAwarenessChangeParameters, type onAwarenessUpdateParameters, type onCloseParameters, type onDisconnectParameters, type onMessageParameters, type onOpenParameters, type onOutgoingMessageParameters, type onStatusParameters } from "./types.ts";
5
- export type HocusPocusWebSocket = WebSocket & {
5
+ export type HocuspocusWebSocket = WebSocket & {
6
6
  identifier: string;
7
7
  };
8
+ export type HocusPocusWebSocket = HocuspocusWebSocket;
8
9
  export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
9
10
  export interface CompleteHocuspocusProviderWebsocketConfiguration {
11
+ /**
12
+ * Whether to connect automatically when creating the provider instance. Default=true
13
+ */
14
+ autoConnect: boolean;
10
15
  /**
11
16
  * URL of your @hocuspocus/server instance
12
17
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "3.2.1",
3
+ "version": "3.2.3",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -29,7 +29,7 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@hocuspocus/common": "^3.2.1",
32
+ "@hocuspocus/common": "^3.2.3",
33
33
  "@lifeomic/attempt": "^3.0.2",
34
34
  "lib0": "^0.2.87",
35
35
  "ws": "^8.17.1"
@@ -18,7 +18,8 @@ import {
18
18
  type onStatusParameters,
19
19
  } from "./types.ts";
20
20
 
21
- export type HocusPocusWebSocket = WebSocket & { identifier: string };
21
+ export type HocuspocusWebSocket = WebSocket & { identifier: string };
22
+ export type HocusPocusWebSocket = HocuspocusWebSocket;
22
23
 
23
24
  export type HocuspocusProviderWebsocketConfiguration = Required<
24
25
  Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">
@@ -26,6 +27,11 @@ export type HocuspocusProviderWebsocketConfiguration = Required<
26
27
  Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
27
28
 
28
29
  export interface CompleteHocuspocusProviderWebsocketConfiguration {
30
+ /**
31
+ * Whether to connect automatically when creating the provider instance. Default=true
32
+ */
33
+ autoConnect: boolean;
34
+
29
35
  /**
30
36
  * URL of your @hocuspocus/server instance
31
37
  */
@@ -95,6 +101,7 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
95
101
 
96
102
  public configuration: CompleteHocuspocusProviderWebsocketConfiguration = {
97
103
  url: "",
104
+ autoConnect: true,
98
105
  // @ts-ignore
99
106
  document: undefined,
100
107
  WebSocketPolyfill: undefined,
@@ -179,11 +186,9 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
179
186
  this.configuration.messageReconnectTimeout / 10,
180
187
  );
181
188
 
182
- if (!this.shouldConnect) {
183
- return;
189
+ if (this.shouldConnect) {
190
+ this.connect();
184
191
  }
185
-
186
- this.connect();
187
192
  }
188
193
 
189
194
  receivedOnOpenPayload?: Event | undefined = undefined;
@@ -222,6 +227,10 @@ export class HocuspocusProviderWebsocket extends EventEmitter {
222
227
  configuration: Partial<HocuspocusProviderWebsocketConfiguration> = {},
223
228
  ): void {
224
229
  this.configuration = { ...this.configuration, ...configuration };
230
+
231
+ if (!this.configuration.autoConnect) {
232
+ this.shouldConnect = false;
233
+ }
225
234
  }
226
235
 
227
236
  cancelWebsocketRetry?: () => void;