@hocuspocus/extension-redis 3.0.7-rc.0 → 3.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hocuspocus-redis.cjs +31 -27
- package/dist/hocuspocus-redis.cjs.map +1 -1
- package/dist/hocuspocus-redis.esm.js +31 -27
- package/dist/hocuspocus-redis.esm.js.map +1 -1
- package/dist/node_modules/@tiptap/pm/model/index.d.ts +1 -0
- package/dist/node_modules/@tiptap/pm/state/index.d.ts +1 -0
- package/dist/node_modules/@tiptap/pm/transform/index.d.ts +1 -0
- package/dist/node_modules/@tiptap/pm/view/index.d.ts +1 -0
- package/dist/packages/extension-redis/src/Redis.d.ts +8 -9
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +6 -16
- package/dist/packages/provider/src/MessageSender.d.ts +2 -3
- package/package.json +3 -4
- package/src/Redis.ts +424 -393
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var server = require('@hocuspocus/server');
|
|
3
4
|
var RedisClient = require('ioredis');
|
|
4
5
|
var Redlock = require('redlock');
|
|
5
6
|
var uuid = require('uuid');
|
|
6
|
-
var server = require('@hocuspocus/server');
|
|
7
7
|
|
|
8
8
|
class Redis {
|
|
9
9
|
constructor(configuration) {
|
|
@@ -15,13 +15,13 @@ class Redis {
|
|
|
15
15
|
this.priority = 1000;
|
|
16
16
|
this.configuration = {
|
|
17
17
|
port: 6379,
|
|
18
|
-
host:
|
|
19
|
-
prefix:
|
|
18
|
+
host: "127.0.0.1",
|
|
19
|
+
prefix: "hocuspocus",
|
|
20
20
|
identifier: `host-${uuid.v4()}`,
|
|
21
21
|
lockTimeout: 1000,
|
|
22
22
|
disconnectDelay: 1000,
|
|
23
23
|
};
|
|
24
|
-
this.redisTransactionOrigin =
|
|
24
|
+
this.redisTransactionOrigin = "__hocuspocus__redis__origin__";
|
|
25
25
|
this.locks = new Map();
|
|
26
26
|
/**
|
|
27
27
|
* When we have a high frequency of updates to a document we don't need tons of setTimeouts
|
|
@@ -33,7 +33,7 @@ class Redis {
|
|
|
33
33
|
* Handle incoming messages published on subscribed document channels.
|
|
34
34
|
* Note that this will also include messages from ourselves as it is not possible
|
|
35
35
|
* in Redis to filter these.
|
|
36
|
-
|
|
36
|
+
*/
|
|
37
37
|
this.handleIncomingMessage = async (channel, data) => {
|
|
38
38
|
const [identifier, messageBuffer] = this.decodeMessage(data);
|
|
39
39
|
if (identifier === this.configuration.identifier) {
|
|
@@ -46,7 +46,7 @@ class Redis {
|
|
|
46
46
|
if (!document) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
new server.MessageReceiver(message, this.redisTransactionOrigin).apply(document, undefined, reply => {
|
|
49
|
+
new server.MessageReceiver(message, this.redisTransactionOrigin).apply(document, undefined, (reply) => {
|
|
50
50
|
return this.pub.publishBuffer(this.pubKey(document.name), this.encodeMessage(reply));
|
|
51
51
|
});
|
|
52
52
|
};
|
|
@@ -84,8 +84,8 @@ class Redis {
|
|
|
84
84
|
...configuration,
|
|
85
85
|
};
|
|
86
86
|
// Create Redis instance
|
|
87
|
-
const { port, host, options, nodes, redis, createClient
|
|
88
|
-
if (typeof createClient ===
|
|
87
|
+
const { port, host, options, nodes, redis, createClient } = this.configuration;
|
|
88
|
+
if (typeof createClient === "function") {
|
|
89
89
|
this.pub = createClient();
|
|
90
90
|
this.sub = createClient();
|
|
91
91
|
}
|
|
@@ -98,15 +98,18 @@ class Redis {
|
|
|
98
98
|
this.sub = new RedisClient.Cluster(nodes, options);
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
|
-
this.pub = new RedisClient(port, host, options);
|
|
102
|
-
this.sub = new RedisClient(port, host, options);
|
|
101
|
+
this.pub = new RedisClient(port, host, options !== null && options !== void 0 ? options : {});
|
|
102
|
+
this.sub = new RedisClient(port, host, options !== null && options !== void 0 ? options : {});
|
|
103
103
|
}
|
|
104
|
-
this.sub.on(
|
|
104
|
+
this.sub.on("messageBuffer", this.handleIncomingMessage);
|
|
105
105
|
this.redlock = new Redlock([this.pub], {
|
|
106
106
|
retryCount: 0,
|
|
107
107
|
});
|
|
108
|
-
const identifierBuffer = Buffer.from(this.configuration.identifier,
|
|
109
|
-
this.messagePrefix = Buffer.concat([
|
|
108
|
+
const identifierBuffer = Buffer.from(this.configuration.identifier, "utf-8");
|
|
109
|
+
this.messagePrefix = Buffer.concat([
|
|
110
|
+
Buffer.from([identifierBuffer.length]),
|
|
111
|
+
identifierBuffer,
|
|
112
|
+
]);
|
|
110
113
|
}
|
|
111
114
|
async onConfigure({ instance }) {
|
|
112
115
|
this.instance = instance;
|
|
@@ -128,13 +131,13 @@ class Redis {
|
|
|
128
131
|
}
|
|
129
132
|
decodeMessage(buffer) {
|
|
130
133
|
const identifierLength = buffer[0];
|
|
131
|
-
const identifier = buffer.toString(
|
|
134
|
+
const identifier = buffer.toString("utf-8", 1, identifierLength + 1);
|
|
132
135
|
return [identifier, buffer.slice(identifierLength + 1)];
|
|
133
136
|
}
|
|
134
137
|
/**
|
|
135
138
|
* Once a document is loaded, subscribe to the channel in Redis.
|
|
136
139
|
*/
|
|
137
|
-
async afterLoadDocument({ documentName, document }) {
|
|
140
|
+
async afterLoadDocument({ documentName, document, }) {
|
|
138
141
|
return new Promise((resolve, reject) => {
|
|
139
142
|
// On document creation the node will connect to pub and sub channels
|
|
140
143
|
// for the document.
|
|
@@ -162,8 +165,7 @@ class Redis {
|
|
|
162
165
|
* Let’s ask Redis who is connected already.
|
|
163
166
|
*/
|
|
164
167
|
async requestAwarenessFromOtherInstances(documentName) {
|
|
165
|
-
const awarenessMessage = new server.OutgoingMessage(documentName)
|
|
166
|
-
.writeQueryAwareness();
|
|
168
|
+
const awarenessMessage = new server.OutgoingMessage(documentName).writeQueryAwareness();
|
|
167
169
|
return this.pub.publishBuffer(this.pubKey(documentName), this.encodeMessage(awarenessMessage.toUint8Array()));
|
|
168
170
|
}
|
|
169
171
|
/**
|
|
@@ -178,7 +180,7 @@ class Redis {
|
|
|
178
180
|
if (error || !lock) {
|
|
179
181
|
// Expected behavior: Could not acquire lock, another instance locked it already.
|
|
180
182
|
// No further `onStoreDocument` hooks will be executed.
|
|
181
|
-
console.log(
|
|
183
|
+
console.log("unable to acquire lock");
|
|
182
184
|
reject();
|
|
183
185
|
return;
|
|
184
186
|
}
|
|
@@ -190,9 +192,10 @@ class Redis {
|
|
|
190
192
|
/**
|
|
191
193
|
* Release the Redis lock, so other instances can store documents.
|
|
192
194
|
*/
|
|
193
|
-
async afterStoreDocument({ documentName, socketId }) {
|
|
195
|
+
async afterStoreDocument({ documentName, socketId, }) {
|
|
194
196
|
var _a;
|
|
195
|
-
(_a = this.locks
|
|
197
|
+
(_a = this.locks
|
|
198
|
+
.get(this.lockKey(documentName))) === null || _a === void 0 ? void 0 : _a.unlock().catch(() => {
|
|
196
199
|
// Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.
|
|
197
200
|
// console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)
|
|
198
201
|
}).finally(() => {
|
|
@@ -200,7 +203,7 @@ class Redis {
|
|
|
200
203
|
});
|
|
201
204
|
// if the change was initiated by a directConnection, we need to delay this hook to make sure sync can finish first.
|
|
202
205
|
// for provider connections, this usually happens in the onDisconnect hook
|
|
203
|
-
if (socketId ===
|
|
206
|
+
if (socketId === "server") {
|
|
204
207
|
const pending = this.pendingAfterStoreDocumentResolves.get(documentName);
|
|
205
208
|
if (pending) {
|
|
206
209
|
clearTimeout(pending.timeout);
|
|
@@ -208,14 +211,17 @@ class Redis {
|
|
|
208
211
|
this.pendingAfterStoreDocumentResolves.delete(documentName);
|
|
209
212
|
}
|
|
210
213
|
let resolveFunction = () => { };
|
|
211
|
-
const delayedPromise = new Promise(resolve => {
|
|
214
|
+
const delayedPromise = new Promise((resolve) => {
|
|
212
215
|
resolveFunction = resolve;
|
|
213
216
|
});
|
|
214
217
|
const timeout = setTimeout(() => {
|
|
215
218
|
this.pendingAfterStoreDocumentResolves.delete(documentName);
|
|
216
219
|
resolveFunction();
|
|
217
220
|
}, this.configuration.disconnectDelay);
|
|
218
|
-
this.pendingAfterStoreDocumentResolves.set(documentName, {
|
|
221
|
+
this.pendingAfterStoreDocumentResolves.set(documentName, {
|
|
222
|
+
timeout,
|
|
223
|
+
resolve: resolveFunction,
|
|
224
|
+
});
|
|
219
225
|
await delayedPromise;
|
|
220
226
|
}
|
|
221
227
|
}
|
|
@@ -224,8 +230,7 @@ class Redis {
|
|
|
224
230
|
*/
|
|
225
231
|
async onAwarenessUpdate({ documentName, awareness, added, updated, removed, }) {
|
|
226
232
|
const changedClients = added.concat(updated, removed);
|
|
227
|
-
const message = new server.OutgoingMessage(documentName)
|
|
228
|
-
.createAwarenessUpdateMessage(awareness, changedClients);
|
|
233
|
+
const message = new server.OutgoingMessage(documentName).createAwarenessUpdateMessage(awareness, changedClients);
|
|
229
234
|
return this.pub.publishBuffer(this.pubKey(documentName), this.encodeMessage(message.toUint8Array()));
|
|
230
235
|
}
|
|
231
236
|
/**
|
|
@@ -237,8 +242,7 @@ class Redis {
|
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
async beforeBroadcastStateless(data) {
|
|
240
|
-
const message = new server.OutgoingMessage(data.documentName)
|
|
241
|
-
.writeBroadcastStateless(data.payload);
|
|
245
|
+
const message = new server.OutgoingMessage(data.documentName).writeBroadcastStateless(data.payload);
|
|
242
246
|
return this.pub.publishBuffer(this.pubKey(data.documentName), this.encodeMessage(message.toUint8Array()));
|
|
243
247
|
}
|
|
244
248
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-redis.cjs","sources":["../src/Redis.ts"],"sourcesContent":[null],"names":["uuid","IncomingMessage","MessageReceiver","OutgoingMessage"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"hocuspocus-redis.cjs","sources":["../src/Redis.ts"],"sourcesContent":[null],"names":["uuid","Incoming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M,wBAAwB,CAAC,IAAqC,EAAA;AACnE,QAAA,MAAM,OAAO,GAAG,IAAIA,sBAAe,CAClC,IAAI,CAAC,YAAY,CACjB,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC;QAEvC,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAC9B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAC1C;;AAGF;;AAEG;AACH,IAAA,MAAM,SAAS,GAAA;AACd,QAAA,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AACzB,QAAA,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;AAC1B,QAAA,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;;AAE3B;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { IncomingMessage, MessageReceiver, OutgoingMessage } from '@hocuspocus/server';
|
|
1
2
|
import RedisClient from 'ioredis';
|
|
2
3
|
import Redlock from 'redlock';
|
|
3
4
|
import { v4 } from 'uuid';
|
|
4
|
-
import { IncomingMessage, MessageReceiver, OutgoingMessage } from '@hocuspocus/server';
|
|
5
5
|
|
|
6
6
|
class Redis {
|
|
7
7
|
constructor(configuration) {
|
|
@@ -13,13 +13,13 @@ class Redis {
|
|
|
13
13
|
this.priority = 1000;
|
|
14
14
|
this.configuration = {
|
|
15
15
|
port: 6379,
|
|
16
|
-
host:
|
|
17
|
-
prefix:
|
|
16
|
+
host: "127.0.0.1",
|
|
17
|
+
prefix: "hocuspocus",
|
|
18
18
|
identifier: `host-${v4()}`,
|
|
19
19
|
lockTimeout: 1000,
|
|
20
20
|
disconnectDelay: 1000,
|
|
21
21
|
};
|
|
22
|
-
this.redisTransactionOrigin =
|
|
22
|
+
this.redisTransactionOrigin = "__hocuspocus__redis__origin__";
|
|
23
23
|
this.locks = new Map();
|
|
24
24
|
/**
|
|
25
25
|
* When we have a high frequency of updates to a document we don't need tons of setTimeouts
|
|
@@ -31,7 +31,7 @@ class Redis {
|
|
|
31
31
|
* Handle incoming messages published on subscribed document channels.
|
|
32
32
|
* Note that this will also include messages from ourselves as it is not possible
|
|
33
33
|
* in Redis to filter these.
|
|
34
|
-
|
|
34
|
+
*/
|
|
35
35
|
this.handleIncomingMessage = async (channel, data) => {
|
|
36
36
|
const [identifier, messageBuffer] = this.decodeMessage(data);
|
|
37
37
|
if (identifier === this.configuration.identifier) {
|
|
@@ -44,7 +44,7 @@ class Redis {
|
|
|
44
44
|
if (!document) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
new MessageReceiver(message, this.redisTransactionOrigin).apply(document, undefined, reply => {
|
|
47
|
+
new MessageReceiver(message, this.redisTransactionOrigin).apply(document, undefined, (reply) => {
|
|
48
48
|
return this.pub.publishBuffer(this.pubKey(document.name), this.encodeMessage(reply));
|
|
49
49
|
});
|
|
50
50
|
};
|
|
@@ -82,8 +82,8 @@ class Redis {
|
|
|
82
82
|
...configuration,
|
|
83
83
|
};
|
|
84
84
|
// Create Redis instance
|
|
85
|
-
const { port, host, options, nodes, redis, createClient
|
|
86
|
-
if (typeof createClient ===
|
|
85
|
+
const { port, host, options, nodes, redis, createClient } = this.configuration;
|
|
86
|
+
if (typeof createClient === "function") {
|
|
87
87
|
this.pub = createClient();
|
|
88
88
|
this.sub = createClient();
|
|
89
89
|
}
|
|
@@ -96,15 +96,18 @@ class Redis {
|
|
|
96
96
|
this.sub = new RedisClient.Cluster(nodes, options);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
this.pub = new RedisClient(port, host, options);
|
|
100
|
-
this.sub = new RedisClient(port, host, options);
|
|
99
|
+
this.pub = new RedisClient(port, host, options !== null && options !== void 0 ? options : {});
|
|
100
|
+
this.sub = new RedisClient(port, host, options !== null && options !== void 0 ? options : {});
|
|
101
101
|
}
|
|
102
|
-
this.sub.on(
|
|
102
|
+
this.sub.on("messageBuffer", this.handleIncomingMessage);
|
|
103
103
|
this.redlock = new Redlock([this.pub], {
|
|
104
104
|
retryCount: 0,
|
|
105
105
|
});
|
|
106
|
-
const identifierBuffer = Buffer.from(this.configuration.identifier,
|
|
107
|
-
this.messagePrefix = Buffer.concat([
|
|
106
|
+
const identifierBuffer = Buffer.from(this.configuration.identifier, "utf-8");
|
|
107
|
+
this.messagePrefix = Buffer.concat([
|
|
108
|
+
Buffer.from([identifierBuffer.length]),
|
|
109
|
+
identifierBuffer,
|
|
110
|
+
]);
|
|
108
111
|
}
|
|
109
112
|
async onConfigure({ instance }) {
|
|
110
113
|
this.instance = instance;
|
|
@@ -126,13 +129,13 @@ class Redis {
|
|
|
126
129
|
}
|
|
127
130
|
decodeMessage(buffer) {
|
|
128
131
|
const identifierLength = buffer[0];
|
|
129
|
-
const identifier = buffer.toString(
|
|
132
|
+
const identifier = buffer.toString("utf-8", 1, identifierLength + 1);
|
|
130
133
|
return [identifier, buffer.slice(identifierLength + 1)];
|
|
131
134
|
}
|
|
132
135
|
/**
|
|
133
136
|
* Once a document is loaded, subscribe to the channel in Redis.
|
|
134
137
|
*/
|
|
135
|
-
async afterLoadDocument({ documentName, document }) {
|
|
138
|
+
async afterLoadDocument({ documentName, document, }) {
|
|
136
139
|
return new Promise((resolve, reject) => {
|
|
137
140
|
// On document creation the node will connect to pub and sub channels
|
|
138
141
|
// for the document.
|
|
@@ -160,8 +163,7 @@ class Redis {
|
|
|
160
163
|
* Let’s ask Redis who is connected already.
|
|
161
164
|
*/
|
|
162
165
|
async requestAwarenessFromOtherInstances(documentName) {
|
|
163
|
-
const awarenessMessage = new OutgoingMessage(documentName)
|
|
164
|
-
.writeQueryAwareness();
|
|
166
|
+
const awarenessMessage = new OutgoingMessage(documentName).writeQueryAwareness();
|
|
165
167
|
return this.pub.publishBuffer(this.pubKey(documentName), this.encodeMessage(awarenessMessage.toUint8Array()));
|
|
166
168
|
}
|
|
167
169
|
/**
|
|
@@ -176,7 +178,7 @@ class Redis {
|
|
|
176
178
|
if (error || !lock) {
|
|
177
179
|
// Expected behavior: Could not acquire lock, another instance locked it already.
|
|
178
180
|
// No further `onStoreDocument` hooks will be executed.
|
|
179
|
-
console.log(
|
|
181
|
+
console.log("unable to acquire lock");
|
|
180
182
|
reject();
|
|
181
183
|
return;
|
|
182
184
|
}
|
|
@@ -188,9 +190,10 @@ class Redis {
|
|
|
188
190
|
/**
|
|
189
191
|
* Release the Redis lock, so other instances can store documents.
|
|
190
192
|
*/
|
|
191
|
-
async afterStoreDocument({ documentName, socketId }) {
|
|
193
|
+
async afterStoreDocument({ documentName, socketId, }) {
|
|
192
194
|
var _a;
|
|
193
|
-
(_a = this.locks
|
|
195
|
+
(_a = this.locks
|
|
196
|
+
.get(this.lockKey(documentName))) === null || _a === void 0 ? void 0 : _a.unlock().catch(() => {
|
|
194
197
|
// Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.
|
|
195
198
|
// console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)
|
|
196
199
|
}).finally(() => {
|
|
@@ -198,7 +201,7 @@ class Redis {
|
|
|
198
201
|
});
|
|
199
202
|
// if the change was initiated by a directConnection, we need to delay this hook to make sure sync can finish first.
|
|
200
203
|
// for provider connections, this usually happens in the onDisconnect hook
|
|
201
|
-
if (socketId ===
|
|
204
|
+
if (socketId === "server") {
|
|
202
205
|
const pending = this.pendingAfterStoreDocumentResolves.get(documentName);
|
|
203
206
|
if (pending) {
|
|
204
207
|
clearTimeout(pending.timeout);
|
|
@@ -206,14 +209,17 @@ class Redis {
|
|
|
206
209
|
this.pendingAfterStoreDocumentResolves.delete(documentName);
|
|
207
210
|
}
|
|
208
211
|
let resolveFunction = () => { };
|
|
209
|
-
const delayedPromise = new Promise(resolve => {
|
|
212
|
+
const delayedPromise = new Promise((resolve) => {
|
|
210
213
|
resolveFunction = resolve;
|
|
211
214
|
});
|
|
212
215
|
const timeout = setTimeout(() => {
|
|
213
216
|
this.pendingAfterStoreDocumentResolves.delete(documentName);
|
|
214
217
|
resolveFunction();
|
|
215
218
|
}, this.configuration.disconnectDelay);
|
|
216
|
-
this.pendingAfterStoreDocumentResolves.set(documentName, {
|
|
219
|
+
this.pendingAfterStoreDocumentResolves.set(documentName, {
|
|
220
|
+
timeout,
|
|
221
|
+
resolve: resolveFunction,
|
|
222
|
+
});
|
|
217
223
|
await delayedPromise;
|
|
218
224
|
}
|
|
219
225
|
}
|
|
@@ -222,8 +228,7 @@ class Redis {
|
|
|
222
228
|
*/
|
|
223
229
|
async onAwarenessUpdate({ documentName, awareness, added, updated, removed, }) {
|
|
224
230
|
const changedClients = added.concat(updated, removed);
|
|
225
|
-
const message = new OutgoingMessage(documentName)
|
|
226
|
-
.createAwarenessUpdateMessage(awareness, changedClients);
|
|
231
|
+
const message = new OutgoingMessage(documentName).createAwarenessUpdateMessage(awareness, changedClients);
|
|
227
232
|
return this.pub.publishBuffer(this.pubKey(documentName), this.encodeMessage(message.toUint8Array()));
|
|
228
233
|
}
|
|
229
234
|
/**
|
|
@@ -235,8 +240,7 @@ class Redis {
|
|
|
235
240
|
}
|
|
236
241
|
}
|
|
237
242
|
async beforeBroadcastStateless(data) {
|
|
238
|
-
const message = new OutgoingMessage(data.documentName)
|
|
239
|
-
.writeBroadcastStateless(data.payload);
|
|
243
|
+
const message = new OutgoingMessage(data.documentName).writeBroadcastStateless(data.payload);
|
|
240
244
|
return this.pub.publishBuffer(this.pubKey(data.documentName), this.encodeMessage(message.toUint8Array()));
|
|
241
245
|
}
|
|
242
246
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-redis.esm.js","sources":["../src/Redis.ts"],"sourcesContent":[null],"names":["uuid"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"hocuspocus-redis.esm.js","sources":["../src/Redis.ts"],"sourcesContent":[null],"names":["uuid"],"mappings":";;;;;MAwEa,KAAK,CAAA;AA0CjB,IAAA,WAAA,C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Y,CACjB,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC;QAEvC,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAC9B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAC1C;;AAGF;;AAEG;AACH,IAAA,MAAM,SAAS,GAAA;AACd,QAAA,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AACzB,QAAA,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;AAC1B,QAAA,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC;;AAE3B;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'prosemirror-model';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'prosemirror-state';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'prosemirror-transform';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'prosemirror-view';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import Redlock from
|
|
4
|
-
import type { Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
|
|
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";
|
|
5
4
|
export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
|
|
6
5
|
export interface Configuration {
|
|
7
6
|
/**
|
|
@@ -81,7 +80,7 @@ export declare class Redis implements Extension {
|
|
|
81
80
|
/**
|
|
82
81
|
* Once a document is loaded, subscribe to the channel in Redis.
|
|
83
82
|
*/
|
|
84
|
-
afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
|
|
83
|
+
afterLoadDocument({ documentName, document, }: afterLoadDocumentPayload): Promise<unknown>;
|
|
85
84
|
/**
|
|
86
85
|
* Publish the first sync step through Redis.
|
|
87
86
|
*/
|
|
@@ -98,16 +97,16 @@ export declare class Redis implements Extension {
|
|
|
98
97
|
/**
|
|
99
98
|
* Release the Redis lock, so other instances can store documents.
|
|
100
99
|
*/
|
|
101
|
-
afterStoreDocument({ documentName, socketId }: afterStoreDocumentPayload): Promise<void>;
|
|
100
|
+
afterStoreDocument({ documentName, socketId, }: afterStoreDocumentPayload): Promise<void>;
|
|
102
101
|
/**
|
|
103
102
|
* Handle awareness update messages received directly by this Hocuspocus instance.
|
|
104
103
|
*/
|
|
105
|
-
onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<
|
|
104
|
+
onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<any>;
|
|
106
105
|
/**
|
|
107
106
|
* Handle incoming messages published on subscribed document channels.
|
|
108
107
|
* Note that this will also include messages from ourselves as it is not possible
|
|
109
108
|
* in Redis to filter these.
|
|
110
|
-
|
|
109
|
+
*/
|
|
111
110
|
private handleIncomingMessage;
|
|
112
111
|
/**
|
|
113
112
|
* if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
|
|
@@ -118,7 +117,7 @@ export declare class Redis implements Extension {
|
|
|
118
117
|
* no one connected anymore.
|
|
119
118
|
*/
|
|
120
119
|
onDisconnect: ({ documentName }: onDisconnectPayload) => Promise<void>;
|
|
121
|
-
beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<
|
|
120
|
+
beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<any>;
|
|
122
121
|
/**
|
|
123
122
|
* Kill the Redlock connection immediately.
|
|
124
123
|
*/
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import EventEmitter from
|
|
3
|
-
import type { HocuspocusProvider } from
|
|
4
|
-
import type { onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters } from
|
|
5
|
-
import { WebSocketStatus } from
|
|
1
|
+
import type { Event, MessageEvent } from "ws";
|
|
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
|
};
|
|
9
|
-
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration,
|
|
9
|
+
export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
10
10
|
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
11
11
|
/**
|
|
12
12
|
* URL of your @hocuspocus/server instance
|
|
13
13
|
*/
|
|
14
14
|
url: string;
|
|
15
|
-
/**
|
|
16
|
-
* Pass `false` to start the connection manually.
|
|
17
|
-
*/
|
|
18
|
-
connect: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* URL parameters that should be added.
|
|
21
|
-
*/
|
|
22
|
-
parameters: {
|
|
23
|
-
[key: string]: any;
|
|
24
|
-
};
|
|
25
15
|
/**
|
|
26
16
|
* An optional WebSocket polyfill, for example for Node.js
|
|
27
17
|
*/
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { Encoder } from
|
|
2
|
-
import type { ConstructableOutgoingMessage } from
|
|
1
|
+
import type { Encoder } from "lib0/encoding";
|
|
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
7
|
create(): Uint8Array<ArrayBufferLike>;
|
|
8
8
|
send(webSocket: any): void;
|
|
9
|
-
broadcast(channel: string): void;
|
|
10
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/extension-redis",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-rc.0",
|
|
4
4
|
"description": "Scale Hocuspocus horizontally with Redis",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
@@ -28,13 +28,12 @@
|
|
|
28
28
|
"dist"
|
|
29
29
|
],
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/ioredis": "^4.28.7",
|
|
32
31
|
"@types/lodash.debounce": "^4.0.6",
|
|
33
32
|
"@types/redlock": "^4.0.3"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
|
-
"@hocuspocus/server": "^3.0
|
|
37
|
-
"ioredis": "^
|
|
35
|
+
"@hocuspocus/server": "^3.1.0-rc.0",
|
|
36
|
+
"ioredis": "^5.6.1",
|
|
38
37
|
"kleur": "^4.1.4",
|
|
39
38
|
"lodash.debounce": "^4.0.8",
|
|
40
39
|
"redlock": "^4.2.0",
|