@hocuspocus/extension-redis 2.0.6 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hocuspocus-redis.cjs +199 -206
- package/dist/hocuspocus-redis.cjs.map +1 -1
- package/dist/hocuspocus-redis.esm.js +199 -205
- package/dist/hocuspocus-redis.esm.js.map +1 -1
- package/dist/packages/common/src/CloseEvents.d.ts +29 -29
- package/dist/packages/common/src/auth.d.ts +6 -6
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -3
- package/dist/packages/common/src/index.d.ts +4 -4
- package/dist/packages/common/src/types.d.ts +10 -10
- package/dist/packages/extension-database/src/Database.d.ts +30 -30
- package/dist/packages/extension-database/src/index.d.ts +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +67 -67
- package/dist/packages/extension-logger/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +116 -117
- package/dist/packages/extension-redis/src/index.d.ts +1 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -26
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
- package/dist/packages/extension-throttle/src/index.d.ts +31 -31
- package/dist/packages/extension-webhook/src/index.d.ts +57 -57
- package/dist/packages/provider/src/EventEmitter.d.ts +9 -9
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +110 -110
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +115 -115
- package/dist/packages/provider/src/IncomingMessage.d.ts +16 -16
- package/dist/packages/provider/src/MessageReceiver.d.ts +13 -13
- package/dist/packages/provider/src/MessageSender.d.ts +10 -10
- package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -9
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -7
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +7 -7
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -8
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -7
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +11 -11
- package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +11 -11
- package/dist/packages/provider/src/index.d.ts +5 -5
- package/dist/packages/provider/src/types.d.ts +84 -84
- package/dist/packages/server/src/Connection.d.ts +71 -71
- package/dist/packages/server/src/Debugger.d.ts +14 -14
- package/dist/packages/server/src/DirectConnection.d.ts +13 -0
- package/dist/packages/server/src/Document.d.ts +91 -88
- package/dist/packages/server/src/Hocuspocus.d.ts +111 -108
- package/dist/packages/server/src/IncomingMessage.d.ts +21 -21
- package/dist/packages/server/src/MessageReceiver.d.ts +12 -12
- package/dist/packages/server/src/OutgoingMessage.d.ts +20 -20
- package/dist/packages/server/src/index.d.ts +8 -8
- package/dist/packages/server/src/types.d.ts +266 -264
- package/dist/packages/transformer/src/Prosemirror.d.ts +11 -11
- package/dist/packages/transformer/src/Tiptap.d.ts +10 -10
- package/dist/packages/transformer/src/index.d.ts +3 -3
- package/dist/packages/transformer/src/types.d.ts +5 -5
- package/dist/playground/backend/src/default.d.ts +1 -1
- package/dist/playground/backend/src/express.d.ts +1 -1
- package/dist/playground/backend/src/koa.d.ts +1 -1
- package/dist/playground/backend/src/load-document.d.ts +1 -1
- package/dist/playground/backend/src/redis.d.ts +1 -1
- package/dist/playground/backend/src/slow.d.ts +1 -1
- package/dist/playground/backend/src/tiptapcollab.d.ts +1 -1
- package/dist/playground/backend/src/webhook.d.ts +1 -1
- package/dist/playground/frontend/src/main.d.ts +1 -1
- package/dist/playground/frontend/vite.config.d.ts +2 -2
- package/dist/tests/extension-database/fetch.d.ts +1 -1
- package/dist/tests/extension-logger/onListen.d.ts +1 -1
- package/dist/tests/extension-redis/closeConnections.d.ts +1 -1
- package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -1
- package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -1
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -1
- package/dist/tests/extension-redis/onChange.d.ts +1 -1
- package/dist/tests/extension-redis/onStateless.d.ts +1 -1
- package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -1
- package/dist/tests/extension-throttle/banning.d.ts +1 -1
- package/dist/tests/extension-throttle/configuration.d.ts +1 -1
- package/dist/tests/provider/observe.d.ts +1 -1
- package/dist/tests/provider/observeDeep.d.ts +1 -1
- package/dist/tests/provider/onAuthenticated.d.ts +1 -1
- package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -1
- package/dist/tests/provider/onAwarenessChange.d.ts +1 -1
- package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -1
- package/dist/tests/provider/onClose.d.ts +1 -1
- package/dist/tests/provider/onConnect.d.ts +1 -1
- package/dist/tests/provider/onDisconnect.d.ts +1 -1
- package/dist/tests/provider/onMessage.d.ts +1 -1
- package/dist/tests/provider/onOpen.d.ts +1 -1
- package/dist/tests/provider/onStateless.d.ts +1 -1
- package/dist/tests/provider/onSynced.d.ts +1 -1
- package/dist/tests/providerwebsocket/configuration.d.ts +1 -1
- package/dist/tests/server/address.d.ts +1 -1
- package/dist/tests/server/afterStoreDocument.d.ts +1 -1
- package/dist/tests/server/beforeBroadcastStateless.d.ts +1 -1
- package/dist/tests/server/beforeHandleMessage.d.ts +1 -1
- package/dist/tests/server/closeConnections.d.ts +1 -1
- package/dist/tests/server/getConnectionsCount.d.ts +1 -1
- package/dist/tests/server/getDocumentsCount.d.ts +1 -1
- package/dist/tests/server/getMessageLogs.d.ts +1 -1
- package/dist/tests/server/listen.d.ts +1 -1
- package/dist/tests/server/onAuthenticate.d.ts +1 -1
- package/dist/tests/server/onAwarenessUpdate.d.ts +1 -1
- package/dist/tests/server/onChange.d.ts +1 -1
- package/dist/tests/server/onClose.d.ts +1 -1
- package/dist/tests/server/onConfigure.d.ts +1 -1
- package/dist/tests/server/onConnect.d.ts +1 -1
- package/dist/tests/server/onDestroy.d.ts +1 -1
- package/dist/tests/server/onDisconnect.d.ts +1 -1
- package/dist/tests/server/onListen.d.ts +1 -1
- package/dist/tests/server/onLoadDocument.d.ts +1 -1
- package/dist/tests/server/onRequest.d.ts +1 -1
- package/dist/tests/server/onStateless.d.ts +1 -1
- package/dist/tests/server/onStoreDocument.d.ts +1 -1
- package/dist/tests/server/onUpgrade.d.ts +1 -1
- package/dist/tests/server/openDirectConnection.d.ts +1 -0
- package/dist/tests/server/requiresAuthentication.d.ts +1 -1
- package/dist/tests/server/websocketError.d.ts +1 -1
- package/dist/tests/transformer/TiptapTransformer.d.ts +1 -1
- package/dist/tests/utils/createDirectory.d.ts +1 -1
- package/dist/tests/utils/flushRedis.d.ts +1 -1
- package/dist/tests/utils/index.d.ts +9 -9
- package/dist/tests/utils/newHocuspocus.d.ts +2 -2
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -3
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +3 -3
- package/dist/tests/utils/randomInteger.d.ts +1 -1
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -4
- package/dist/tests/utils/removeDirectory.d.ts +1 -1
- package/dist/tests/utils/retryableAssertion.d.ts +2 -2
- package/dist/tests/utils/sleep.d.ts +1 -1
- package/package.json +4 -3
- package/src/Redis.ts +3 -12
- package/src/index.ts +1 -1
|
@@ -6,218 +6,211 @@ var RedisClient = require('ioredis');
|
|
|
6
6
|
var Redlock = require('redlock');
|
|
7
7
|
var uuid = require('uuid');
|
|
8
8
|
var server = require('@hocuspocus/server');
|
|
9
|
-
var kleur = require('kleur');
|
|
10
9
|
|
|
11
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
11
|
|
|
13
12
|
var RedisClient__default = /*#__PURE__*/_interopDefaultLegacy(RedisClient);
|
|
14
13
|
var Redlock__default = /*#__PURE__*/_interopDefaultLegacy(Redlock);
|
|
15
|
-
var kleur__default = /*#__PURE__*/_interopDefaultLegacy(kleur);
|
|
16
14
|
|
|
17
|
-
class Redis {
|
|
18
|
-
constructor(configuration) {
|
|
19
|
-
/**
|
|
20
|
-
* Make sure to give that extension a higher priority, so
|
|
21
|
-
* the `onStoreDocument` hook is able to intercept the chain,
|
|
22
|
-
* before documents are stored to the database.
|
|
23
|
-
*/
|
|
24
|
-
this.priority = 1000;
|
|
25
|
-
this.configuration = {
|
|
26
|
-
port: 6379,
|
|
27
|
-
host: '127.0.0.1',
|
|
28
|
-
prefix: 'hocuspocus',
|
|
29
|
-
identifier: `host-${uuid.v4()}`,
|
|
30
|
-
lockTimeout: 1000,
|
|
31
|
-
disconnectDelay: 1000,
|
|
32
|
-
};
|
|
33
|
-
this.locks = new Map();
|
|
34
|
-
/**
|
|
35
|
-
* Handle incoming messages published on all subscribed document channels.
|
|
36
|
-
* Note that this will also include messages from ourselves as it is not possible
|
|
37
|
-
* in Redis to filter these.
|
|
38
|
-
*/
|
|
39
|
-
this.handleIncomingMessage = async (channel, pattern, data) => {
|
|
40
|
-
const message = new server.IncomingMessage(data);
|
|
41
|
-
// we don't need the documentName from the message, we are just taking it from the redis channelName.
|
|
42
|
-
// we have to immediately write it back to the encoder though, to make sure the structure of the message is correct
|
|
43
|
-
message.writeVarString(message.readVarString());
|
|
44
|
-
const channelName = pattern.toString();
|
|
45
|
-
const [_, documentName, identifier] = channelName.split(':');
|
|
46
|
-
const document = this.instance.documents.get(documentName);
|
|
47
|
-
if (identifier === this.configuration.identifier) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (!document) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
new server.MessageReceiver(message, this.logger).apply(document, undefined, reply => {
|
|
54
|
-
return this.pub.publishBuffer(this.pubKey(document.name), Buffer.from(reply));
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Make sure to *not* listen for further changes, when there’s
|
|
59
|
-
* noone connected anymore.
|
|
60
|
-
*/
|
|
61
|
-
this.onDisconnect = async ({ documentName }) => {
|
|
62
|
-
const disconnect = () => {
|
|
63
|
-
const document = this.instance.documents.get(documentName);
|
|
64
|
-
// Do nothing, when other users are still connected to the document.
|
|
65
|
-
if (document && document.getConnectionsCount() > 0) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// Time to end the subscription on the document channel.
|
|
69
|
-
this.sub.punsubscribe(this.subKey(documentName), (error) => {
|
|
70
|
-
if (error) {
|
|
71
|
-
console.error(error);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
// Delay the disconnect procedure to allow last minute syncs to happen
|
|
76
|
-
setTimeout(disconnect, this.configuration.disconnectDelay);
|
|
77
|
-
};
|
|
78
|
-
this.configuration = {
|
|
79
|
-
...this.configuration,
|
|
80
|
-
...configuration,
|
|
81
|
-
};
|
|
82
|
-
// We’ll replace that in the onConfigure hook with the global instance.
|
|
83
|
-
this.logger = new server.Debugger();
|
|
84
|
-
// Create Redis instance
|
|
85
|
-
const { port, host, options, nodes, redis, createClient, } = this.configuration;
|
|
86
|
-
if (typeof createClient === 'function') {
|
|
87
|
-
this.pub = createClient();
|
|
88
|
-
this.sub = createClient();
|
|
89
|
-
}
|
|
90
|
-
else if (redis) {
|
|
91
|
-
this.pub = redis.duplicate();
|
|
92
|
-
this.sub = redis.duplicate();
|
|
93
|
-
}
|
|
94
|
-
else if (nodes && nodes.length > 0) {
|
|
95
|
-
this.pub = new RedisClient__default["default"].Cluster(nodes, options);
|
|
96
|
-
this.sub = new RedisClient__default["default"].Cluster(nodes, options);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.pub = new RedisClient__default["default"](port, host, options);
|
|
100
|
-
this.sub = new RedisClient__default["default"](port, host, options);
|
|
101
|
-
}
|
|
102
|
-
this.sub.on('pmessageBuffer', this.handleIncomingMessage);
|
|
103
|
-
this.redlock = new Redlock__default["default"]([this.pub]);
|
|
104
|
-
}
|
|
105
|
-
async onConfigure({ instance }) {
|
|
106
|
-
this.logger = instance.debugger;
|
|
107
|
-
this.instance = instance;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
* Kill the Redlock connection immediately.
|
|
217
|
-
*/
|
|
218
|
-
async onDestroy() {
|
|
219
|
-
this.redlock.quit();
|
|
220
|
-
}
|
|
15
|
+
class Redis {
|
|
16
|
+
constructor(configuration) {
|
|
17
|
+
/**
|
|
18
|
+
* Make sure to give that extension a higher priority, so
|
|
19
|
+
* the `onStoreDocument` hook is able to intercept the chain,
|
|
20
|
+
* before documents are stored to the database.
|
|
21
|
+
*/
|
|
22
|
+
this.priority = 1000;
|
|
23
|
+
this.configuration = {
|
|
24
|
+
port: 6379,
|
|
25
|
+
host: '127.0.0.1',
|
|
26
|
+
prefix: 'hocuspocus',
|
|
27
|
+
identifier: `host-${uuid.v4()}`,
|
|
28
|
+
lockTimeout: 1000,
|
|
29
|
+
disconnectDelay: 1000,
|
|
30
|
+
};
|
|
31
|
+
this.locks = new Map();
|
|
32
|
+
/**
|
|
33
|
+
* Handle incoming messages published on all subscribed document channels.
|
|
34
|
+
* Note that this will also include messages from ourselves as it is not possible
|
|
35
|
+
* in Redis to filter these.
|
|
36
|
+
*/
|
|
37
|
+
this.handleIncomingMessage = async (channel, pattern, data) => {
|
|
38
|
+
const message = new server.IncomingMessage(data);
|
|
39
|
+
// we don't need the documentName from the message, we are just taking it from the redis channelName.
|
|
40
|
+
// we have to immediately write it back to the encoder though, to make sure the structure of the message is correct
|
|
41
|
+
message.writeVarString(message.readVarString());
|
|
42
|
+
const channelName = pattern.toString();
|
|
43
|
+
const [_, documentName, identifier] = channelName.split(':');
|
|
44
|
+
const document = this.instance.documents.get(documentName);
|
|
45
|
+
if (identifier === this.configuration.identifier) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (!document) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
new server.MessageReceiver(message, this.logger).apply(document, undefined, reply => {
|
|
52
|
+
return this.pub.publishBuffer(this.pubKey(document.name), Buffer.from(reply));
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Make sure to *not* listen for further changes, when there’s
|
|
57
|
+
* noone connected anymore.
|
|
58
|
+
*/
|
|
59
|
+
this.onDisconnect = async ({ documentName }) => {
|
|
60
|
+
const disconnect = () => {
|
|
61
|
+
const document = this.instance.documents.get(documentName);
|
|
62
|
+
// Do nothing, when other users are still connected to the document.
|
|
63
|
+
if (document && document.getConnectionsCount() > 0) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// Time to end the subscription on the document channel.
|
|
67
|
+
this.sub.punsubscribe(this.subKey(documentName), (error) => {
|
|
68
|
+
if (error) {
|
|
69
|
+
console.error(error);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
// Delay the disconnect procedure to allow last minute syncs to happen
|
|
74
|
+
setTimeout(disconnect, this.configuration.disconnectDelay);
|
|
75
|
+
};
|
|
76
|
+
this.configuration = {
|
|
77
|
+
...this.configuration,
|
|
78
|
+
...configuration,
|
|
79
|
+
};
|
|
80
|
+
// We’ll replace that in the onConfigure hook with the global instance.
|
|
81
|
+
this.logger = new server.Debugger();
|
|
82
|
+
// Create Redis instance
|
|
83
|
+
const { port, host, options, nodes, redis, createClient, } = this.configuration;
|
|
84
|
+
if (typeof createClient === 'function') {
|
|
85
|
+
this.pub = createClient();
|
|
86
|
+
this.sub = createClient();
|
|
87
|
+
}
|
|
88
|
+
else if (redis) {
|
|
89
|
+
this.pub = redis.duplicate();
|
|
90
|
+
this.sub = redis.duplicate();
|
|
91
|
+
}
|
|
92
|
+
else if (nodes && nodes.length > 0) {
|
|
93
|
+
this.pub = new RedisClient__default["default"].Cluster(nodes, options);
|
|
94
|
+
this.sub = new RedisClient__default["default"].Cluster(nodes, options);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
this.pub = new RedisClient__default["default"](port, host, options);
|
|
98
|
+
this.sub = new RedisClient__default["default"](port, host, options);
|
|
99
|
+
}
|
|
100
|
+
this.sub.on('pmessageBuffer', this.handleIncomingMessage);
|
|
101
|
+
this.redlock = new Redlock__default["default"]([this.pub]);
|
|
102
|
+
}
|
|
103
|
+
async onConfigure({ instance }) {
|
|
104
|
+
this.logger = instance.debugger;
|
|
105
|
+
this.instance = instance;
|
|
106
|
+
}
|
|
107
|
+
getKey(documentName) {
|
|
108
|
+
return `${this.configuration.prefix}:${documentName}`;
|
|
109
|
+
}
|
|
110
|
+
pubKey(documentName) {
|
|
111
|
+
return `${this.getKey(documentName)}:${this.configuration.identifier.replace(/:/g, '')}`;
|
|
112
|
+
}
|
|
113
|
+
subKey(documentName) {
|
|
114
|
+
return `${this.getKey(documentName)}:*`;
|
|
115
|
+
}
|
|
116
|
+
lockKey(documentName) {
|
|
117
|
+
return `${this.getKey(documentName)}:lock`;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Once a document is laoded, subscribe to the channel in Redis.
|
|
121
|
+
*/
|
|
122
|
+
async afterLoadDocument({ documentName, document }) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
// On document creation the node will connect to pub and sub channels
|
|
125
|
+
// for the document.
|
|
126
|
+
this.sub.psubscribe(this.subKey(documentName), async (error) => {
|
|
127
|
+
if (error) {
|
|
128
|
+
reject(error);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
this.publishFirstSyncStep(documentName, document);
|
|
132
|
+
this.requestAwarenessFromOtherInstances(documentName);
|
|
133
|
+
resolve(undefined);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Publish the first sync step through Redis.
|
|
139
|
+
*/
|
|
140
|
+
async publishFirstSyncStep(documentName, document) {
|
|
141
|
+
const syncMessage = new server.OutgoingMessage(documentName)
|
|
142
|
+
.createSyncMessage()
|
|
143
|
+
.writeFirstSyncStepFor(document);
|
|
144
|
+
return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(syncMessage.toUint8Array()));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Let’s ask Redis who is connected already.
|
|
148
|
+
*/
|
|
149
|
+
async requestAwarenessFromOtherInstances(documentName) {
|
|
150
|
+
const awarenessMessage = new server.OutgoingMessage(documentName)
|
|
151
|
+
.writeQueryAwareness();
|
|
152
|
+
return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(awarenessMessage.toUint8Array()));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Before the document is stored, make sure to set a lock in Redis.
|
|
156
|
+
* That’s meant to avoid conflicts with other instances trying to store the document.
|
|
157
|
+
*/
|
|
158
|
+
async onStoreDocument({ documentName }) {
|
|
159
|
+
// Attempt to acquire a lock and read lastReceivedTimestamp from Redis,
|
|
160
|
+
// to avoid conflict with other instances storing the same document.
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
this.redlock.lock(this.lockKey(documentName), this.configuration.lockTimeout, async (error, lock) => {
|
|
163
|
+
if (error || !lock) {
|
|
164
|
+
// Expected behavior: Could not acquire lock, another instance locked it already.
|
|
165
|
+
// No further `onStoreDocument` hooks will be executed.
|
|
166
|
+
reject();
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.locks.set(this.lockKey(documentName), lock);
|
|
170
|
+
resolve(undefined);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Release the Redis lock, so other instances can store documents.
|
|
176
|
+
*/
|
|
177
|
+
async afterStoreDocument({ documentName }) {
|
|
178
|
+
var _a;
|
|
179
|
+
(_a = this.locks.get(this.lockKey(documentName))) === null || _a === void 0 ? void 0 : _a.unlock().catch(() => {
|
|
180
|
+
// Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.
|
|
181
|
+
// console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)
|
|
182
|
+
}).finally(() => {
|
|
183
|
+
this.locks.delete(this.lockKey(documentName));
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Handle awareness update messages received directly by this Hocuspocus instance.
|
|
188
|
+
*/
|
|
189
|
+
async onAwarenessUpdate({ documentName, awareness, added, updated, removed, }) {
|
|
190
|
+
const changedClients = added.concat(updated, removed);
|
|
191
|
+
const message = new server.OutgoingMessage(documentName)
|
|
192
|
+
.createAwarenessUpdateMessage(awareness, changedClients);
|
|
193
|
+
return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(message.toUint8Array()));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
|
|
197
|
+
*/
|
|
198
|
+
async onChange(data) {
|
|
199
|
+
return this.publishFirstSyncStep(data.documentName, data.document);
|
|
200
|
+
}
|
|
201
|
+
async beforeBroadcastStateless(data) {
|
|
202
|
+
const message = new server.OutgoingMessage(data.documentName)
|
|
203
|
+
.writeBroadcastStateless(data.payload);
|
|
204
|
+
return this.pub.publishBuffer(this.pubKey(data.documentName), Buffer.from(message.toUint8Array()));
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Kill the Redlock connection immediately.
|
|
208
|
+
*/
|
|
209
|
+
async onDestroy() {
|
|
210
|
+
await this.redlock.quit();
|
|
211
|
+
this.pub.disconnect(false);
|
|
212
|
+
this.sub.disconnect(false);
|
|
213
|
+
}
|
|
221
214
|
}
|
|
222
215
|
|
|
223
216
|
exports.Redis = Redis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-redis.cjs","sources":["../src/Redis.ts"],"sourcesContent":["import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis'\nimport Redlock from 'redlock'\nimport { v4 as uuid } from 'uuid'\nimport {\n IncomingMessage,\n OutgoingMessage,\n Document,\n Extension,\n afterLoadDocumentPayload,\n afterStoreDocumentPayload,\n onDisconnectPayload,\n onStoreDocumentPayload,\n onAwarenessUpdatePayload,\n onChangePayload,\n MessageReceiver,\n Debugger,\n onConfigurePayload,\n onListenPayload,\n beforeBroadcastStatelessPayload, Hocuspocus,\n} from '@hocuspocus/server'\nimport kleur from 'kleur'\n\nexport type RedisInstance = RedisClient.Cluster | RedisClient.Redis\n\nexport interface Configuration {\n /**\n * Redis port\n */\n port: number,\n /**\n * Redis host\n */\n host: string,\n /**\n * Redis Cluster\n */\n nodes?: ClusterNode[],\n /**\n * Duplicate from an existed Redis instance\n */\n redis?: RedisInstance,\n /**\n * Redis instance creator\n */\n createClient?: () => RedisInstance,\n /**\n * Options passed directly to Redis constructor\n *\n * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options\n */\n options?: ClusterOptions | RedisOptions,\n /**\n * An unique instance name, required to filter messages in Redis.\n * If none is provided an unique id is generated.\n */\n identifier: string,\n /**\n * Namespace for Redis keys, if none is provided 'hocuspocus' is used\n */\n prefix: string,\n /**\n * The maximum time for the Redis lock in ms (in case it can’t be released).\n */\n lockTimeout: number,\n /**\n * A delay before onDisconnect is executed. This allows last minute updates'\n * sync messages to be received by the subscription before it's closed.\n */\n disconnectDelay: number,\n}\n\nexport class Redis implements Extension {\n /**\n * Make sure to give that extension a higher priority, so\n * the `onStoreDocument` hook is able to intercept the chain,\n * before documents are stored to the database.\n */\n priority = 1000\n\n configuration: Configuration = {\n port: 6379,\n host: '127.0.0.1',\n prefix: 'hocuspocus',\n identifier: `host-${uuid()}`,\n lockTimeout: 1000,\n disconnectDelay: 1000,\n }\n\n pub: RedisInstance\n\n sub: RedisInstance\n\n instance!: Hocuspocus\n\n redlock: Redlock\n\n locks = new Map<string, Redlock.Lock>()\n\n logger: Debugger\n\n public constructor(configuration: Partial<Configuration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n // We’ll replace that in the onConfigure hook with the global instance.\n this.logger = new Debugger()\n\n // Create Redis instance\n const {\n port,\n host,\n options,\n nodes,\n redis,\n createClient,\n } = this.configuration\n\n if (typeof createClient === 'function') {\n this.pub = createClient()\n this.sub = createClient()\n } else if (redis) {\n this.pub = redis.duplicate()\n this.sub = redis.duplicate()\n } else if (nodes && nodes.length > 0) {\n this.pub = new RedisClient.Cluster(nodes, options)\n this.sub = new RedisClient.Cluster(nodes, options)\n } else {\n this.pub = new RedisClient(port, host, options)\n this.sub = new RedisClient(port, host, options)\n }\n this.sub.on('pmessageBuffer', this.handleIncomingMessage)\n\n this.redlock = new Redlock([this.pub])\n }\n\n async onConfigure({ instance }: onConfigurePayload) {\n this.logger = instance.debugger\n this.instance = instance\n }\n\n async onListen({ configuration }: onListenPayload) {\n if (configuration.quiet) {\n return\n }\n\n console.warn(` ${kleur.yellow('[BREAKING CHANGE] Wait, the Redis extension got an overhaul. The new Redis extension doesn’t persist data, it only syncs data between instances. Use @hocuspocus/extension-database to store your documents. It works well with the Redis extension.')}`)\n console.log()\n }\n\n private getKey(documentName: string) {\n return `${this.configuration.prefix}:${documentName}`\n }\n\n private pubKey(documentName: string) {\n return `${this.getKey(documentName)}:${this.configuration.identifier.replace(/:/g, '')}`\n }\n\n private subKey(documentName: string) {\n return `${this.getKey(documentName)}:*`\n }\n\n private lockKey(documentName: string) {\n return `${this.getKey(documentName)}:lock`\n }\n\n /**\n * Once a document is laoded, subscribe to the channel in Redis.\n */\n public async afterLoadDocument({ documentName, document }: afterLoadDocumentPayload) {\n return new Promise((resolve, reject) => {\n // On document creation the node will connect to pub and sub channels\n // for the document.\n this.sub.psubscribe(this.subKey(documentName), async error => {\n if (error) {\n reject(error)\n return\n }\n\n this.publishFirstSyncStep(documentName, document)\n this.requestAwarenessFromOtherInstances(documentName)\n\n resolve(undefined)\n })\n })\n }\n\n /**\n * Publish the first sync step through Redis.\n */\n private async publishFirstSyncStep(documentName: string, document: Document) {\n const syncMessage = new OutgoingMessage(documentName)\n .createSyncMessage()\n .writeFirstSyncStepFor(document)\n\n return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(syncMessage.toUint8Array()))\n }\n\n /**\n * Let’s ask Redis who is connected already.\n */\n private async requestAwarenessFromOtherInstances(documentName: string) {\n const awarenessMessage = new OutgoingMessage(documentName)\n .writeQueryAwareness()\n\n return this.pub.publishBuffer(\n this.pubKey(documentName),\n Buffer.from(awarenessMessage.toUint8Array()),\n )\n }\n\n /**\n * Before the document is stored, make sure to set a lock in Redis.\n * That’s meant to avoid conflicts with other instances trying to store the document.\n */\n async onStoreDocument({ documentName }: onStoreDocumentPayload) {\n // Attempt to acquire a lock and read lastReceivedTimestamp from Redis,\n // to avoid conflict with other instances storing the same document.\n return new Promise((resolve, reject) => {\n this.redlock.lock(this.lockKey(documentName), this.configuration.lockTimeout, async (error, lock) => {\n if (error || !lock) {\n // Expected behavior: Could not acquire lock, another instance locked it already.\n // No further `onStoreDocument` hooks will be executed.\n reject()\n return\n }\n\n this.locks.set(this.lockKey(documentName), lock)\n\n resolve(undefined)\n })\n })\n }\n\n /**\n * Release the Redis lock, so other instances can store documents.\n */\n async afterStoreDocument({ documentName }: afterStoreDocumentPayload) {\n this.locks.get(this.lockKey(documentName))?.unlock()\n .catch(() => {\n // Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.\n // console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)\n })\n .finally(() => {\n this.locks.delete(this.lockKey(documentName))\n })\n }\n\n /**\n * Handle awareness update messages received directly by this Hocuspocus instance.\n */\n async onAwarenessUpdate({\n documentName, awareness, added, updated, removed,\n }: onAwarenessUpdatePayload) {\n const changedClients = added.concat(updated, removed)\n const message = new OutgoingMessage(documentName)\n .createAwarenessUpdateMessage(awareness, changedClients)\n\n return this.pub.publishBuffer(\n this.pubKey(documentName),\n Buffer.from(message.toUint8Array()),\n )\n }\n\n /**\n * Handle incoming messages published on all subscribed document channels.\n * Note that this will also include messages from ourselves as it is not possible\n * in Redis to filter these.\n */\n private handleIncomingMessage = async (channel: Buffer, pattern: Buffer, data: Buffer) => {\n const message = new IncomingMessage(data)\n // we don't need the documentName from the message, we are just taking it from the redis channelName.\n // we have to immediately write it back to the encoder though, to make sure the structure of the message is correct\n message.writeVarString(message.readVarString())\n\n const channelName = pattern.toString()\n const [_, documentName, identifier] = channelName.split(':')\n const document = this.instance.documents.get(documentName)\n\n if (identifier === this.configuration.identifier) {\n return\n }\n\n if (!document) {\n return\n }\n\n new MessageReceiver(\n message,\n this.logger,\n ).apply(document, undefined, reply => {\n return this.pub.publishBuffer(\n this.pubKey(document.name),\n Buffer.from(reply),\n )\n })\n }\n\n /**\n * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.\n */\n public async onChange(data: onChangePayload): Promise<any> {\n return this.publishFirstSyncStep(data.documentName, data.document)\n }\n\n /**\n * Make sure to *not* listen for further changes, when there’s\n * noone connected anymore.\n */\n public onDisconnect = async ({ documentName }: onDisconnectPayload) => {\n const disconnect = () => {\n const document = this.instance.documents.get(documentName)\n\n // Do nothing, when other users are still connected to the document.\n if (document && document.getConnectionsCount() > 0) {\n return\n }\n\n // Time to end the subscription on the document channel.\n this.sub.punsubscribe(this.subKey(documentName), (error: any) => {\n if (error) {\n console.error(error)\n }\n })\n }\n // Delay the disconnect procedure to allow last minute syncs to happen\n setTimeout(disconnect, this.configuration.disconnectDelay)\n }\n\n async beforeBroadcastStateless(data: beforeBroadcastStatelessPayload) {\n const message = new OutgoingMessage(data.documentName)\n .writeBroadcastStateless(data.payload)\n\n return this.pub.publishBuffer(\n this.pubKey(data.documentName),\n Buffer.from(message.toUint8Array()),\n )\n }\n\n /**\n * Kill the Redlock connection immediately.\n */\n async onDestroy() {\n this.redlock.quit()\n }\n}\n"],"names":["uuid","IncomingMessage","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CAAA;KACnE;IA0BD,MAAM,wBAAwB,CAAC,IAAqC,EAAA;QAClE,MAAM,OAAO,GAAG,IAAIA,sBAAe,CAAC,IAAI,CAAC,YAAY,CAAC;AACnD,aAAA,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAExC,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CACpC,CAAA;KACF;AAED;;AAEG;AACH,IAAA,MAAM,SAAS,GAAA;AACb,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;KACpB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"hocuspocus-redis.cjs","sources":["../src/Redis.ts"],"sourcesContent":["import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis'\nimport Redlock from 'redlock'\nimport { v4 as uuid } from 'uuid'\nimport {\n IncomingMessage,\n OutgoingMessage,\n Document,\n Extension,\n afterLoadDocumentPayload,\n afterStoreDocumentPayload,\n onDisconnectPayload,\n onStoreDocumentPayload,\n onAwarenessUpdatePayload,\n onChangePayload,\n MessageReceiver,\n Debugger,\n onConfigurePayload,\n beforeBroadcastStatelessPayload, Hocuspocus,\n} from '@hocuspocus/server'\n\nexport type RedisInstance = RedisClient.Cluster | RedisClient.Redis\n\nexport interface Configuration {\n /**\n * Redis port\n */\n port: number,\n /**\n * Redis host\n */\n host: string,\n /**\n * Redis Cluster\n */\n nodes?: ClusterNode[],\n /**\n * Duplicate from an existed Redis instance\n */\n redis?: RedisInstance,\n /**\n * Redis instance creator\n */\n createClient?: () => RedisInstance,\n /**\n * Options passed directly to Redis constructor\n *\n * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options\n */\n options?: ClusterOptions | RedisOptions,\n /**\n * An unique instance name, required to filter messages in Redis.\n * If none is provided an unique id is generated.\n */\n identifier: string,\n /**\n * Namespace for Redis keys, if none is provided 'hocuspocus' is used\n */\n prefix: string,\n /**\n * The maximum time for the Redis lock in ms (in case it can’t be released).\n */\n lockTimeout: number,\n /**\n * A delay before onDisconnect is executed. This allows last minute updates'\n * sync messages to be received by the subscription before it's closed.\n */\n disconnectDelay: number,\n}\n\nexport class Redis implements Extension {\n /**\n * Make sure to give that extension a higher priority, so\n * the `onStoreDocument` hook is able to intercept the chain,\n * before documents are stored to the database.\n */\n priority = 1000\n\n configuration: Configuration = {\n port: 6379,\n host: '127.0.0.1',\n prefix: 'hocuspocus',\n identifier: `host-${uuid()}`,\n lockTimeout: 1000,\n disconnectDelay: 1000,\n }\n\n pub: RedisInstance\n\n sub: RedisInstance\n\n instance!: Hocuspocus\n\n redlock: Redlock\n\n locks = new Map<string, Redlock.Lock>()\n\n logger: Debugger\n\n public constructor(configuration: Partial<Configuration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n\n // We’ll replace that in the onConfigure hook with the global instance.\n this.logger = new Debugger()\n\n // Create Redis instance\n const {\n port,\n host,\n options,\n nodes,\n redis,\n createClient,\n } = this.configuration\n\n if (typeof createClient === 'function') {\n this.pub = createClient()\n this.sub = createClient()\n } else if (redis) {\n this.pub = redis.duplicate()\n this.sub = redis.duplicate()\n } else if (nodes && nodes.length > 0) {\n this.pub = new RedisClient.Cluster(nodes, options)\n this.sub = new RedisClient.Cluster(nodes, options)\n } else {\n this.pub = new RedisClient(port, host, options)\n this.sub = new RedisClient(port, host, options)\n }\n this.sub.on('pmessageBuffer', this.handleIncomingMessage)\n\n this.redlock = new Redlock([this.pub])\n }\n\n async onConfigure({ instance }: onConfigurePayload) {\n this.logger = instance.debugger\n this.instance = instance\n }\n\n private getKey(documentName: string) {\n return `${this.configuration.prefix}:${documentName}`\n }\n\n private pubKey(documentName: string) {\n return `${this.getKey(documentName)}:${this.configuration.identifier.replace(/:/g, '')}`\n }\n\n private subKey(documentName: string) {\n return `${this.getKey(documentName)}:*`\n }\n\n private lockKey(documentName: string) {\n return `${this.getKey(documentName)}:lock`\n }\n\n /**\n * Once a document is laoded, subscribe to the channel in Redis.\n */\n public async afterLoadDocument({ documentName, document }: afterLoadDocumentPayload) {\n return new Promise((resolve, reject) => {\n // On document creation the node will connect to pub and sub channels\n // for the document.\n this.sub.psubscribe(this.subKey(documentName), async error => {\n if (error) {\n reject(error)\n return\n }\n\n this.publishFirstSyncStep(documentName, document)\n this.requestAwarenessFromOtherInstances(documentName)\n\n resolve(undefined)\n })\n })\n }\n\n /**\n * Publish the first sync step through Redis.\n */\n private async publishFirstSyncStep(documentName: string, document: Document) {\n const syncMessage = new OutgoingMessage(documentName)\n .createSyncMessage()\n .writeFirstSyncStepFor(document)\n\n return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(syncMessage.toUint8Array()))\n }\n\n /**\n * Let’s ask Redis who is connected already.\n */\n private async requestAwarenessFromOtherInstances(documentName: string) {\n const awarenessMessage = new OutgoingMessage(documentName)\n .writeQueryAwareness()\n\n return this.pub.publishBuffer(\n this.pubKey(documentName),\n Buffer.from(awarenessMessage.toUint8Array()),\n )\n }\n\n /**\n * Before the document is stored, make sure to set a lock in Redis.\n * That’s meant to avoid conflicts with other instances trying to store the document.\n */\n async onStoreDocument({ documentName }: onStoreDocumentPayload) {\n // Attempt to acquire a lock and read lastReceivedTimestamp from Redis,\n // to avoid conflict with other instances storing the same document.\n return new Promise((resolve, reject) => {\n this.redlock.lock(this.lockKey(documentName), this.configuration.lockTimeout, async (error, lock) => {\n if (error || !lock) {\n // Expected behavior: Could not acquire lock, another instance locked it already.\n // No further `onStoreDocument` hooks will be executed.\n reject()\n return\n }\n\n this.locks.set(this.lockKey(documentName), lock)\n\n resolve(undefined)\n })\n })\n }\n\n /**\n * Release the Redis lock, so other instances can store documents.\n */\n async afterStoreDocument({ documentName }: afterStoreDocumentPayload) {\n this.locks.get(this.lockKey(documentName))?.unlock()\n .catch(() => {\n // Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.\n // console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)\n })\n .finally(() => {\n this.locks.delete(this.lockKey(documentName))\n })\n }\n\n /**\n * Handle awareness update messages received directly by this Hocuspocus instance.\n */\n async onAwarenessUpdate({\n documentName, awareness, added, updated, removed,\n }: onAwarenessUpdatePayload) {\n const changedClients = added.concat(updated, removed)\n const message = new OutgoingMessage(documentName)\n .createAwarenessUpdateMessage(awareness, changedClients)\n\n return this.pub.publishBuffer(\n this.pubKey(documentName),\n Buffer.from(message.toUint8Array()),\n )\n }\n\n /**\n * Handle incoming messages published on all subscribed document channels.\n * Note that this will also include messages from ourselves as it is not possible\n * in Redis to filter these.\n */\n private handleIncomingMessage = async (channel: Buffer, pattern: Buffer, data: Buffer) => {\n const message = new IncomingMessage(data)\n // we don't need the documentName from the message, we are just taking it from the redis channelName.\n // we have to immediately write it back to the encoder though, to make sure the structure of the message is correct\n message.writeVarString(message.readVarString())\n\n const channelName = pattern.toString()\n const [_, documentName, identifier] = channelName.split(':')\n const document = this.instance.documents.get(documentName)\n\n if (identifier === this.configuration.identifier) {\n return\n }\n\n if (!document) {\n return\n }\n\n new MessageReceiver(\n message,\n this.logger,\n ).apply(document, undefined, reply => {\n return this.pub.publishBuffer(\n this.pubKey(document.name),\n Buffer.from(reply),\n )\n })\n }\n\n /**\n * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.\n */\n public async onChange(data: onChangePayload): Promise<any> {\n return this.publishFirstSyncStep(data.documentName, data.document)\n }\n\n /**\n * Make sure to *not* listen for further changes, when there’s\n * noone connected anymore.\n */\n public onDisconnect = async ({ documentName }: onDisconnectPayload) => {\n const disconnect = () => {\n const document = this.instance.documents.get(documentName)\n\n // Do nothing, when other users are still connected to the document.\n if (document && document.getConnectionsCount() > 0) {\n return\n }\n\n // Time to end the subscription on the document channel.\n this.sub.punsubscribe(this.subKey(documentName), (error: any) => {\n if (error) {\n console.error(error)\n }\n })\n }\n // Delay the disconnect procedure to allow last minute syncs to happen\n setTimeout(disconnect, this.configuration.disconnectDelay)\n }\n\n async beforeBroadcastStateless(data: beforeBroadcastStatelessPayload) {\n const message = new OutgoingMessage(data.documentName)\n .writeBroadcastStateless(data.payload)\n\n return this.pub.publishBuffer(\n this.pubKey(data.documentName),\n Buffer.from(message.toUint8Array()),\n )\n }\n\n /**\n * Kill the Redlock connection immediately.\n */\n async onDestroy() {\n await this.redlock.quit()\n this.pub.disconnect(false)\n this.sub.disconnect(false)\n }\n}\n"],"names":["uuid","IncomingMessage","MessageReceiver","Debugger","RedisClient","Redlock","OutgoingMessage"],"mappings":";;;;;;;;;;;;;;MAqEa,KAAK,CAAA;AA6BhB,IAAA,WAAA,CAAmB,aAAqC,EAAA;AA5BxD;;;;AAIG;QACH,IAAQ,CAAA,QAAA,GAAG,IAAI,CAAA;AAEf,QAAA,IAAA,CAAA,aAAa,GAAkB;AAC7B,YAAA,IAAI,EAAE,IAAI;AACV,YAAA,IAAI,EAAE,WAAW;AACjB,YAAA,MAAM,EAAE,YAAY;AACpB,YAAA,UAAU,EAAE,CAAA,KAAA,EAAQA,OAAI,EAAE,CAAE,CAAA;AAC5B,YAAA,WAAW,EAAE,IAAI;AACjB,YAAA,eAAe,EAAE,IAAI;SACtB,CAAA;AAUD,QAAA,IAAA,CAAA,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAA;AAgKvC;;;;AAIE;QACM,IAAqB,CAAA,qBAAA,GAAG,OAAO,OAAe,EAAE,OAAe,EAAE,IAAY,KAAI;AACvF,YAAA,MAAM,OAAO,GAAG,IAAIC,sBAAe,CAAC,IAAI,CAAC,CAAA;;;YAGzC,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;AAE/C,YAAA,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;AACtC,YAAA,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG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