@hocuspocus/extension-redis 1.0.0-alpha.60 → 1.0.0-alpha.63

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 (27) hide show
  1. package/dist/hocuspocus-redis.cjs +168 -46
  2. package/dist/hocuspocus-redis.cjs.map +1 -1
  3. package/dist/hocuspocus-redis.esm.js +164 -47
  4. package/dist/hocuspocus-redis.esm.js.map +1 -1
  5. package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
  6. package/dist/packages/extension-redis/src/Redis.d.ts +87 -9
  7. package/dist/packages/extension-redis/src/index.d.ts +0 -1
  8. package/dist/packages/provider/src/HocuspocusProvider.d.ts +11 -21
  9. package/dist/packages/provider/src/types.d.ts +33 -0
  10. package/dist/packages/server/src/Hocuspocus.d.ts +2 -2
  11. package/dist/packages/server/src/index.d.ts +3 -4
  12. package/dist/packages/server/src/types.d.ts +7 -6
  13. package/dist/tests/{extension-redis-rewrite → extension-redis}/closeConnections.d.ts +0 -0
  14. package/dist/tests/{extension-redis-rewrite → extension-redis}/getConnectionCount.d.ts +0 -0
  15. package/dist/tests/{extension-redis-rewrite → extension-redis}/getDocumentsCount.d.ts +0 -0
  16. package/dist/tests/{extension-redis-rewrite → extension-redis}/onAwarenessChange.d.ts +0 -0
  17. package/dist/tests/{extension-redis-rewrite → extension-redis}/onChange.d.ts +0 -0
  18. package/dist/tests/{extension-redis-rewrite → extension-redis}/onStoreDocument.d.ts +0 -0
  19. package/dist/tests/utils/index.d.ts +1 -0
  20. package/dist/tests/utils/randomInteger.d.ts +1 -0
  21. package/package.json +16 -6
  22. package/src/Redis.ts +239 -39
  23. package/src/index.ts +0 -1
  24. package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
  25. package/dist/tests/extension-redis/onLoadDocument.d.ts +0 -1
  26. package/dist/tests/extension-redis/onSynced.d.ts +0 -1
  27. package/src/RedisCluster.ts +0 -7
@@ -2,67 +2,189 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var yRedis = require('y-redis');
5
+ var RedisClient = require('ioredis');
6
+ var Redlock = require('redlock');
7
+ var uuid = require('uuid');
8
+ var server = require('@hocuspocus/server');
9
+ var kleur = require('kleur');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var RedisClient__default = /*#__PURE__*/_interopDefaultLegacy(RedisClient);
14
+ var Redlock__default = /*#__PURE__*/_interopDefaultLegacy(Redlock);
15
+ var kleur__default = /*#__PURE__*/_interopDefaultLegacy(kleur);
6
16
 
7
17
  class Redis {
8
- /**
9
- * Constructor
10
- */
11
18
  constructor(configuration) {
12
- this.configuration = {};
13
- this.cluster = false;
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
+ };
32
+ this.documents = new Map();
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 channelName = pattern.toString();
41
+ const [_, documentName, identifier] = channelName.split(':');
42
+ const document = this.documents.get(documentName);
43
+ if (identifier === this.configuration.identifier) {
44
+ return;
45
+ }
46
+ if (!document) {
47
+ return;
48
+ }
49
+ new server.MessageReceiver(new server.IncomingMessage(data), this.logger).apply(document, undefined, reply => {
50
+ return this.pub.publishBuffer(this.pubKey(document.name), Buffer.from(reply));
51
+ });
52
+ };
53
+ /**
54
+ * Make sure to *not* listen for further changes, when there’s
55
+ * noone connected anymore.
56
+ */
57
+ this.onDisconnect = async ({ documentName, clientsCount }) => {
58
+ // Do nothing, when other users are still connected to the document.
59
+ if (clientsCount > 0) {
60
+ return;
61
+ }
62
+ // It was indeed the last connected user.
63
+ this.documents.delete(documentName);
64
+ // Time to end the subscription on the document channel.
65
+ this.sub.punsubscribe(this.subKey(documentName), error => {
66
+ if (error) {
67
+ console.error(error);
68
+ }
69
+ });
70
+ };
14
71
  this.configuration = {
15
72
  ...this.configuration,
16
73
  ...configuration,
17
74
  };
75
+ const { port, host, options } = this.configuration;
76
+ this.pub = new RedisClient__default["default"](port, host, options);
77
+ this.sub = new RedisClient__default["default"](port, host, options);
78
+ this.sub.on('pmessageBuffer', this.handleIncomingMessage);
79
+ this.redlock = new Redlock__default["default"]([this.pub]);
80
+ // We’ll replace that in the onConfigure hook with the global instance.
81
+ this.logger = new server.Debugger();
18
82
  }
19
- /*
20
- * onLoadDocument hook
21
- */
22
- async onLoadDocument(data) {
23
- if (!this.persistence) {
24
- return;
25
- }
26
- // If another connection has already loaded this doc, return this one instead
27
- const binding = this.persistence.docs.get(data.documentName);
28
- if (binding) {
29
- return binding.doc;
30
- }
31
- await this.persistence.bindState(data.documentName, data.document).synced;
83
+ async onConfigure({ instance }) {
84
+ this.logger = instance.debugger;
32
85
  }
33
- async onConnect(data) {
34
- // Bind to Redis already? Ok, no worries.
35
- if (this.persistence) {
86
+ async onListen({ configuration }) {
87
+ if (configuration.quiet) {
36
88
  return;
37
89
  }
38
- this.persistence = new yRedis.RedisPersistence(
39
- // @ts-ignore
40
- this.cluster
41
- ? { redisClusterOpts: this.configuration }
42
- : { redisOpts: this.configuration });
90
+ console.warn(` ${kleur__default["default"].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.')}`);
91
+ console.log();
43
92
  }
44
- async onDisconnect(data) {
45
- // Not binded to Redis? Never mind!
46
- if (!this.persistence) {
47
- return;
48
- }
49
- // Still clients connected?
50
- if (data.clientsCount > 0) {
51
- return;
52
- }
53
- // Fine, let’s remove the binding …
54
- this.persistence.destroy();
55
- this.persistence = undefined;
93
+ getKey(documentName) {
94
+ return `${this.configuration.prefix}:${documentName}`;
56
95
  }
57
- }
58
-
59
- class RedisCluster extends Redis {
60
- constructor() {
61
- super(...arguments);
62
- this.cluster = true;
96
+ pubKey(documentName) {
97
+ return `${this.getKey(documentName)}:${this.configuration.identifier.replace(/:/g, '')}`;
98
+ }
99
+ subKey(documentName) {
100
+ return `${this.getKey(documentName)}:*`;
101
+ }
102
+ lockKey(documentName) {
103
+ return `${this.getKey(documentName)}:lock`;
104
+ }
105
+ /**
106
+ * Once a document is laoded, subscribe to the channel in Redis.
107
+ */
108
+ async afterLoadDocument({ documentName, document }) {
109
+ this.documents.set(documentName, document);
110
+ return new Promise((resolve, reject) => {
111
+ // On document creation the node will connect to pub and sub channels
112
+ // for the document.
113
+ this.sub.psubscribe(this.subKey(documentName), async (error) => {
114
+ if (error) {
115
+ reject(error);
116
+ return;
117
+ }
118
+ this.publishFirstSyncStep(documentName, document);
119
+ this.requestAwarenessFromOtherInstances(documentName);
120
+ resolve(undefined);
121
+ });
122
+ });
123
+ }
124
+ /**
125
+ * Publish the first sync step through Redis.
126
+ */
127
+ async publishFirstSyncStep(documentName, document) {
128
+ const syncMessage = new server.OutgoingMessage()
129
+ .createSyncMessage()
130
+ .writeFirstSyncStepFor(document);
131
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(syncMessage.toUint8Array()));
132
+ }
133
+ /**
134
+ * Let’s ask Redis who is connected already.
135
+ */
136
+ async requestAwarenessFromOtherInstances(documentName) {
137
+ const awarenessMessage = new server.OutgoingMessage()
138
+ .writeQueryAwareness();
139
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(awarenessMessage.toUint8Array()));
140
+ }
141
+ /**
142
+ * Before the document is stored, make sure to set a lock in Redis.
143
+ * That’s meant to avoid conflicts with other instances trying to store the document.
144
+ */
145
+ async onStoreDocument({ documentName }) {
146
+ // Attempt to acquire a lock and read lastReceivedTimestamp from Redis,
147
+ // to avoid conflict with other instances storing the same document.
148
+ return new Promise((resolve, reject) => {
149
+ this.redlock.lock(this.lockKey(documentName), this.configuration.lockTimeout, async (error, lock) => {
150
+ if (error || !lock) {
151
+ // Expected behavior: Could not acquire lock, another instance locked it already.
152
+ // No further `onStoreDocument` hooks will be executed.
153
+ reject();
154
+ return;
155
+ }
156
+ this.locks.set(this.lockKey(documentName), lock);
157
+ resolve(undefined);
158
+ });
159
+ });
160
+ }
161
+ /**
162
+ * Release the Redis lock, so other instances can store documents.
163
+ */
164
+ async afterStoreDocument({ documentName }) {
165
+ var _a;
166
+ (_a = this.locks.get(this.lockKey(documentName))) === null || _a === void 0 ? void 0 : _a.unlock().catch(() => {
167
+ // Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.
168
+ // console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)
169
+ }).finally(() => {
170
+ this.locks.delete(this.lockKey(documentName));
171
+ });
172
+ }
173
+ /**
174
+ * Handle awareness update messages received directly by this Hocuspocus instance.
175
+ */
176
+ async onAwarenessUpdate({ documentName, awareness }) {
177
+ const message = new server.OutgoingMessage()
178
+ .createAwarenessUpdateMessage(awareness);
179
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(message.toUint8Array()));
180
+ }
181
+ /**
182
+ * Kill the Redlock connection immediately.
183
+ */
184
+ async onDestroy() {
185
+ this.redlock.quit();
63
186
  }
64
187
  }
65
188
 
66
189
  exports.Redis = Redis;
67
- exports.RedisCluster = RedisCluster;
68
190
  //# sourceMappingURL=hocuspocus-redis.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-redis.cjs","sources":["../src/Redis.ts","../src/RedisCluster.ts"],"sourcesContent":["import { RedisPersistence } from 'y-redis'\nimport {\n Extension,\n onConnectPayload,\n onLoadDocumentPayload,\n onDisconnectPayload,\n} from '@hocuspocus/server'\n\nexport interface Configuration {\n}\n\nexport class Redis implements Extension {\n\n configuration: Configuration = {}\n\n cluster = false\n\n persistence!: RedisPersistence | undefined\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<Configuration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /*\n * onLoadDocument hook\n */\n async onLoadDocument(data: onLoadDocumentPayload) {\n if (!this.persistence) {\n return\n }\n\n // If another connection has already loaded this doc, return this one instead\n const binding = this.persistence.docs.get(data.documentName)\n\n if (binding) {\n return binding.doc\n }\n\n await this.persistence.bindState(data.documentName, data.document).synced\n }\n\n async onConnect(data: onConnectPayload) {\n // Bind to Redis already? Ok, no worries.\n if (this.persistence) {\n return\n }\n\n this.persistence = new RedisPersistence(\n // @ts-ignore\n this.cluster\n ? { redisClusterOpts: this.configuration }\n : { redisOpts: this.configuration },\n )\n\n }\n\n async onDisconnect(data: onDisconnectPayload) {\n // Not binded to Redis? Never mind!\n if (!this.persistence) {\n return\n }\n\n // Still clients connected?\n if (data.clientsCount > 0) {\n return\n }\n\n // Fine, let’s remove the binding …\n this.persistence.destroy()\n this.persistence = undefined\n\n }\n\n}\n","import { Redis } from './Redis'\n\nexport class RedisCluster extends Redis {\n\n cluster = true\n\n}\n"],"names":["RedisPersistence"],"mappings":";;;;;;MAWa,KAAK;;;;IAWhB,YAAY,aAAsC;QATlD,kBAAa,GAAkB,EAAE,CAAA;QAEjC,YAAO,GAAG,KAAK,CAAA;QAQb,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;;;;IAKD,MAAM,cAAc,CAAC,IAA2B;QAC9C,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAM;SACP;;QAGD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAE5D,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAC,GAAG,CAAA;SACnB;QAED,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAA;KAC1E;IAED,MAAM,SAAS,CAAC,IAAsB;;QAEpC,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAM;SACP;QAED,IAAI,CAAC,WAAW,GAAG,IAAIA,uBAAgB;;QAErC,IAAI,CAAC,OAAO;cACR,EAAE,gBAAgB,EAAE,IAAI,CAAC,aAAa,EAAE;cACxC,EAAE,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,CACtC,CAAA;KAEF;IAED,MAAM,YAAY,CAAC,IAAyB;;QAE1C,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAM;SACP;;QAGD,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE;YACzB,OAAM;SACP;;QAGD,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;KAE7B;;;MC3EU,YAAa,SAAQ,KAAK;IAAvC;;QAEE,YAAO,GAAG,IAAI,CAAA;KAEf;;;;;;"}
1
+ {"version":3,"file":"hocuspocus-redis.cjs","sources":["../src/Redis.ts"],"sourcesContent":["import RedisClient 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 MessageReceiver,\n Debugger,\n onConfigurePayload,\n onListenPayload,\n} from '@hocuspocus/server'\nimport kleur from 'kleur'\n\nexport interface Configuration {\n /**\n * Redis port\n */\n port: number,\n /**\n * Redis host\n */\n host: string,\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?: RedisClient.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\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 }\n\n pub: RedisClient.Redis\n\n sub: RedisClient.Redis\n\n documents: Map<string, Document> = new Map()\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 const { port, host, options } = this.configuration\n\n this.pub = new RedisClient(port, host, options)\n\n this.sub = new RedisClient(port, host, options)\n this.sub.on('pmessageBuffer', this.handleIncomingMessage)\n\n this.redlock = new Redlock([this.pub])\n\n // We’ll replace that in the onConfigure hook with the global instance.\n this.logger = new Debugger()\n }\n\n async onConfigure({ instance }: onConfigurePayload) {\n this.logger = instance.debugger\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 this.documents.set(documentName, document)\n\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()\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()\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({ documentName, awareness }: onAwarenessUpdatePayload) {\n const message = new OutgoingMessage()\n .createAwarenessUpdateMessage(awareness)\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 channelName = pattern.toString()\n const [_, documentName, identifier] = channelName.split(':')\n const document = this.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 new IncomingMessage(data),\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 * Make sure to *not* listen for further changes, when there’s\n * noone connected anymore.\n */\n public onDisconnect = async ({ documentName, clientsCount }: onDisconnectPayload) => {\n // Do nothing, when other users are still connected to the document.\n if (clientsCount > 0) {\n return\n }\n\n // It was indeed the last connected user.\n this.documents.delete(documentName)\n\n // Time to end the subscription on the document channel.\n this.sub.punsubscribe(this.subKey(documentName), error => {\n if (error) {\n console.error(error)\n }\n })\n }\n\n /**\n * Kill the Redlock connection immediately.\n */\n async onDestroy() {\n this.redlock.quit()\n }\n}\n"],"names":["uuid","MessageReceiver","IncomingMessage","RedisClient","Redlock","Debugger","kleur","OutgoingMessage"],"mappings":";;;;;;;;;;;;;;;;MAkDa,KAAK,CAAA;AA4BhB,IAAA,WAAA,CAAmB,aAAqC,EAAA;AA3BxD;;;;AAIG;QACH,IAAQ,CAAA,QAAA,GAAG,IAAI,CAAA;AAEf,QAAA,IAAA,CAAA,aAAa,GAAkB;AAC7B,YAAA,IAAI,EAAE,IAAI;AACV,YAA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AAC,YAAY,CAAC,EAAE,IAAI,CAAC,CAAA;gBAEhD,OAAO,CAAC,SAAS,CAAC,CAAA;AACpB,aAAC,CAAC,CAAA;AACJ,SAAC,CAAC,CAAA;KACH;AAED;;AAEG;AACH,IAAA,MAAM,kBAAkB,CAAC,EAAE,YAAY,EAA6B,EAAA;;AAClE,QAAA,CAAA,EAAA,GAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,MAAM,GAC/C,KAAK,CAAC,MAAK;;;AAGZ,SAAC,CACA,CAAA,OAAO,CAAC,MAAK;AACZ,YAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;AAC/C,SAAC,CAAC,CAAA;KACL;AAED;;AAEG;AACH,IAAA,MAAM,iBAAiB,CAAC,EAAE,YAAY,EAAE,SAAS,EAA4B,EAAA;AAC3E,QAAA,MAAM,OAAO,GAAG,IAAIA,sBAAe,EAAE;aAClC,4BAA4B,CAAC,SAAS,CAAC,CAAA;QAE1C,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAC3B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EACzB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CACpC,CAAA;KACF;AAoDD;;AAEG;AACH,IAAA,MAAM,SAAS,GAAA;AACb,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;KACpB;AACF;;;;"}
@@ -1,63 +1,180 @@
1
- import { RedisPersistence } from 'y-redis';
1
+ import RedisClient from 'ioredis';
2
+ import Redlock from 'redlock';
3
+ import { v4 } from 'uuid';
4
+ import { MessageReceiver, IncomingMessage, Debugger, OutgoingMessage } from '@hocuspocus/server';
5
+ import kleur from 'kleur';
2
6
 
3
7
  class Redis {
4
- /**
5
- * Constructor
6
- */
7
8
  constructor(configuration) {
8
- this.configuration = {};
9
- this.cluster = false;
9
+ /**
10
+ * Make sure to give that extension a higher priority, so
11
+ * the `onStoreDocument` hook is able to intercept the chain,
12
+ * before documents are stored to the database.
13
+ */
14
+ this.priority = 1000;
15
+ this.configuration = {
16
+ port: 6379,
17
+ host: '127.0.0.1',
18
+ prefix: 'hocuspocus',
19
+ identifier: `host-${v4()}`,
20
+ lockTimeout: 1000,
21
+ };
22
+ this.documents = new Map();
23
+ this.locks = new Map();
24
+ /**
25
+ * Handle incoming messages published on all subscribed document channels.
26
+ * Note that this will also include messages from ourselves as it is not possible
27
+ * in Redis to filter these.
28
+ */
29
+ this.handleIncomingMessage = async (channel, pattern, data) => {
30
+ const channelName = pattern.toString();
31
+ const [_, documentName, identifier] = channelName.split(':');
32
+ const document = this.documents.get(documentName);
33
+ if (identifier === this.configuration.identifier) {
34
+ return;
35
+ }
36
+ if (!document) {
37
+ return;
38
+ }
39
+ new MessageReceiver(new IncomingMessage(data), this.logger).apply(document, undefined, reply => {
40
+ return this.pub.publishBuffer(this.pubKey(document.name), Buffer.from(reply));
41
+ });
42
+ };
43
+ /**
44
+ * Make sure to *not* listen for further changes, when there’s
45
+ * noone connected anymore.
46
+ */
47
+ this.onDisconnect = async ({ documentName, clientsCount }) => {
48
+ // Do nothing, when other users are still connected to the document.
49
+ if (clientsCount > 0) {
50
+ return;
51
+ }
52
+ // It was indeed the last connected user.
53
+ this.documents.delete(documentName);
54
+ // Time to end the subscription on the document channel.
55
+ this.sub.punsubscribe(this.subKey(documentName), error => {
56
+ if (error) {
57
+ console.error(error);
58
+ }
59
+ });
60
+ };
10
61
  this.configuration = {
11
62
  ...this.configuration,
12
63
  ...configuration,
13
64
  };
65
+ const { port, host, options } = this.configuration;
66
+ this.pub = new RedisClient(port, host, options);
67
+ this.sub = new RedisClient(port, host, options);
68
+ this.sub.on('pmessageBuffer', this.handleIncomingMessage);
69
+ this.redlock = new Redlock([this.pub]);
70
+ // We’ll replace that in the onConfigure hook with the global instance.
71
+ this.logger = new Debugger();
14
72
  }
15
- /*
16
- * onLoadDocument hook
17
- */
18
- async onLoadDocument(data) {
19
- if (!this.persistence) {
20
- return;
21
- }
22
- // If another connection has already loaded this doc, return this one instead
23
- const binding = this.persistence.docs.get(data.documentName);
24
- if (binding) {
25
- return binding.doc;
26
- }
27
- await this.persistence.bindState(data.documentName, data.document).synced;
73
+ async onConfigure({ instance }) {
74
+ this.logger = instance.debugger;
28
75
  }
29
- async onConnect(data) {
30
- // Bind to Redis already? Ok, no worries.
31
- if (this.persistence) {
76
+ async onListen({ configuration }) {
77
+ if (configuration.quiet) {
32
78
  return;
33
79
  }
34
- this.persistence = new RedisPersistence(
35
- // @ts-ignore
36
- this.cluster
37
- ? { redisClusterOpts: this.configuration }
38
- : { redisOpts: this.configuration });
39
- }
40
- async onDisconnect(data) {
41
- // Not binded to Redis? Never mind!
42
- if (!this.persistence) {
43
- return;
44
- }
45
- // Still clients connected?
46
- if (data.clientsCount > 0) {
47
- return;
48
- }
49
- // Fine, let’s remove the binding …
50
- this.persistence.destroy();
51
- this.persistence = undefined;
80
+ 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.')}`);
81
+ console.log();
52
82
  }
53
- }
54
-
55
- class RedisCluster extends Redis {
56
- constructor() {
57
- super(...arguments);
58
- this.cluster = true;
83
+ getKey(documentName) {
84
+ return `${this.configuration.prefix}:${documentName}`;
85
+ }
86
+ pubKey(documentName) {
87
+ return `${this.getKey(documentName)}:${this.configuration.identifier.replace(/:/g, '')}`;
88
+ }
89
+ subKey(documentName) {
90
+ return `${this.getKey(documentName)}:*`;
91
+ }
92
+ lockKey(documentName) {
93
+ return `${this.getKey(documentName)}:lock`;
94
+ }
95
+ /**
96
+ * Once a document is laoded, subscribe to the channel in Redis.
97
+ */
98
+ async afterLoadDocument({ documentName, document }) {
99
+ this.documents.set(documentName, document);
100
+ return new Promise((resolve, reject) => {
101
+ // On document creation the node will connect to pub and sub channels
102
+ // for the document.
103
+ this.sub.psubscribe(this.subKey(documentName), async (error) => {
104
+ if (error) {
105
+ reject(error);
106
+ return;
107
+ }
108
+ this.publishFirstSyncStep(documentName, document);
109
+ this.requestAwarenessFromOtherInstances(documentName);
110
+ resolve(undefined);
111
+ });
112
+ });
113
+ }
114
+ /**
115
+ * Publish the first sync step through Redis.
116
+ */
117
+ async publishFirstSyncStep(documentName, document) {
118
+ const syncMessage = new OutgoingMessage()
119
+ .createSyncMessage()
120
+ .writeFirstSyncStepFor(document);
121
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(syncMessage.toUint8Array()));
122
+ }
123
+ /**
124
+ * Let’s ask Redis who is connected already.
125
+ */
126
+ async requestAwarenessFromOtherInstances(documentName) {
127
+ const awarenessMessage = new OutgoingMessage()
128
+ .writeQueryAwareness();
129
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(awarenessMessage.toUint8Array()));
130
+ }
131
+ /**
132
+ * Before the document is stored, make sure to set a lock in Redis.
133
+ * That’s meant to avoid conflicts with other instances trying to store the document.
134
+ */
135
+ async onStoreDocument({ documentName }) {
136
+ // Attempt to acquire a lock and read lastReceivedTimestamp from Redis,
137
+ // to avoid conflict with other instances storing the same document.
138
+ return new Promise((resolve, reject) => {
139
+ this.redlock.lock(this.lockKey(documentName), this.configuration.lockTimeout, async (error, lock) => {
140
+ if (error || !lock) {
141
+ // Expected behavior: Could not acquire lock, another instance locked it already.
142
+ // No further `onStoreDocument` hooks will be executed.
143
+ reject();
144
+ return;
145
+ }
146
+ this.locks.set(this.lockKey(documentName), lock);
147
+ resolve(undefined);
148
+ });
149
+ });
150
+ }
151
+ /**
152
+ * Release the Redis lock, so other instances can store documents.
153
+ */
154
+ async afterStoreDocument({ documentName }) {
155
+ var _a;
156
+ (_a = this.locks.get(this.lockKey(documentName))) === null || _a === void 0 ? void 0 : _a.unlock().catch(() => {
157
+ // Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.
158
+ // console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)
159
+ }).finally(() => {
160
+ this.locks.delete(this.lockKey(documentName));
161
+ });
162
+ }
163
+ /**
164
+ * Handle awareness update messages received directly by this Hocuspocus instance.
165
+ */
166
+ async onAwarenessUpdate({ documentName, awareness }) {
167
+ const message = new OutgoingMessage()
168
+ .createAwarenessUpdateMessage(awareness);
169
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(message.toUint8Array()));
170
+ }
171
+ /**
172
+ * Kill the Redlock connection immediately.
173
+ */
174
+ async onDestroy() {
175
+ this.redlock.quit();
59
176
  }
60
177
  }
61
178
 
62
- export { Redis, RedisCluster };
179
+ export { Redis };
63
180
  //# sourceMappingURL=hocuspocus-redis.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hocuspocus-redis.esm.js","sources":["../src/Redis.ts","../src/RedisCluster.ts"],"sourcesContent":["import { RedisPersistence } from 'y-redis'\nimport {\n Extension,\n onConnectPayload,\n onLoadDocumentPayload,\n onDisconnectPayload,\n} from '@hocuspocus/server'\n\nexport interface Configuration {\n}\n\nexport class Redis implements Extension {\n\n configuration: Configuration = {}\n\n cluster = false\n\n persistence!: RedisPersistence | undefined\n\n /**\n * Constructor\n */\n constructor(configuration?: Partial<Configuration>) {\n this.configuration = {\n ...this.configuration,\n ...configuration,\n }\n }\n\n /*\n * onLoadDocument hook\n */\n async onLoadDocument(data: onLoadDocumentPayload) {\n if (!this.persistence) {\n return\n }\n\n // If another connection has already loaded this doc, return this one instead\n const binding = this.persistence.docs.get(data.documentName)\n\n if (binding) {\n return binding.doc\n }\n\n await this.persistence.bindState(data.documentName, data.document).synced\n }\n\n async onConnect(data: onConnectPayload) {\n // Bind to Redis already? Ok, no worries.\n if (this.persistence) {\n return\n }\n\n this.persistence = new RedisPersistence(\n // @ts-ignore\n this.cluster\n ? { redisClusterOpts: this.configuration }\n : { redisOpts: this.configuration },\n )\n\n }\n\n async onDisconnect(data: onDisconnectPayload) {\n // Not binded to Redis? Never mind!\n if (!this.persistence) {\n return\n }\n\n // Still clients connected?\n if (data.clientsCount > 0) {\n return\n }\n\n // Fine, let’s remove the binding …\n this.persistence.destroy()\n this.persistence = undefined\n\n }\n\n}\n","import { Redis } from './Redis'\n\nexport class RedisCluster extends Redis {\n\n cluster = true\n\n}\n"],"names":[],"mappings":";;MAWa,KAAK;;;;IAWhB,YAAY,aAAsC;QATlD,kBAAa,GAAkB,EAAE,CAAA;QAEjC,YAAO,GAAG,KAAK,CAAA;QAQb,IAAI,CAAC,aAAa,GAAG;YACnB,GAAG,IAAI,CAAC,aAAa;YACrB,GAAG,aAAa;SACjB,CAAA;KACF;;;;IAKD,MAAM,cAAc,CAAC,IAA2B;QAC9C,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAM;SACP;;QAGD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAE5D,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAC,GAAG,CAAA;SACnB;QAED,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAA;KAC1E;IAED,MAAM,SAAS,CAAC,IAAsB;;QAEpC,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAM;SACP;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,gBAAgB;;QAErC,IAAI,CAAC,OAAO;cACR,EAAE,gBAAgB,EAAE,IAAI,CAAC,aAAa,EAAE;cACxC,EAAE,SAAS,EAAE,IAAI,CAAC,aAAa,EAAE,CACtC,CAAA;KAEF;IAED,MAAM,YAAY,CAAC,IAAyB;;QAE1C,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,OAAM;SACP;;QAGD,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE;YACzB,OAAM;SACP;;QAGD,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;KAE7B;;;MC3EU,YAAa,SAAQ,KAAK;IAAvC;;QAEE,YAAO,GAAG,IAAI,CAAA;KAEf;;;;;"}
1
+ {"version":3,"file":"hocuspocus-redis.esm.js","sources":["../src/Redis.ts"],"sourcesContent":["import RedisClient 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 MessageReceiver,\n Debugger,\n onConfigurePayload,\n onListenPayload,\n} from '@hocuspocus/server'\nimport kleur from 'kleur'\n\nexport interface Configuration {\n /**\n * Redis port\n */\n port: number,\n /**\n * Redis host\n */\n host: string,\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?: RedisClient.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\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 }\n\n pub: RedisClient.Redis\n\n sub: RedisClient.Redis\n\n documents: Map<string, Document> = new Map()\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 const { port, host, options } = this.configuration\n\n this.pub = new RedisClient(port, host, options)\n\n this.sub = new RedisClient(port, host, options)\n this.sub.on('pmessageBuffer', this.handleIncomingMessage)\n\n this.redlock = new Redlock([this.pub])\n\n // We’ll replace that in the onConfigure hook with the global instance.\n this.logger = new Debugger()\n }\n\n async onConfigure({ instance }: onConfigurePayload) {\n this.logger = instance.debugger\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 this.documents.set(documentName, document)\n\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()\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()\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({ documentName, awareness }: onAwarenessUpdatePayload) {\n const message = new OutgoingMessage()\n .createAwarenessUpdateMessage(awareness)\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 channelName = pattern.toString()\n const [_, documentName, identifier] = channelName.split(':')\n const document = this.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 new IncomingMessage(data),\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 * Make sure to *not* listen for further changes, when there’s\n * noone connected anymore.\n */\n public onDisconnect = async ({ documentName, clientsCount }: onDisconnectPayload) => {\n // Do nothing, when other users are still connected to the document.\n if (clientsCount > 0) {\n return\n }\n\n // It was indeed the last connected user.\n this.documents.delete(documentName)\n\n // Time to end the subscription on the document channel.\n this.sub.punsubscribe(this.subKey(documentName), error => {\n if (error) {\n console.error(error)\n }\n })\n }\n\n /**\n * Kill the Redlock connection immediately.\n */\n async onDestroy() {\n this.redlock.quit()\n }\n}\n"],"names":["uuid"],"mappings":";;;;;;MAkDa,KAAK,CAAA;AA4BhB,IAAA,WAAA,CAAmB,aAAqC,EAAA;AA3BxD;;;;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,EAAI,EAAE,CAAE,CAAA;AAC5B,YAAA,WAAW,EAAE,IAAI;SAClB,CAAA;AAMD,QAAA,IAAA,CAAA,SAAS,GAA0B,IAAI,GAAG,EAAE,CAAA;AAI5C,QAAA,IAAA,CAAA,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAA;AAqJvC;;;;AAIE;QACM,IAAqB,CAAA,qBAAA,GAAG,OAAO,OAAe,EAAE,OAAe,EAAE,IAAY,KAAI;AACvF,YAAA,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAA;AACtC,YAAA,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,WAAW,CAAC,KAAK,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CAAC,CAAC,CAAA;AAC/C,SAAC,CAAC,CAAA;KACL;AAED;;AAEG;AACH,IAAA,MAAM,iBAAiB,CAAC,EAAE,YAAY,EAAE,SAAS,EAA4B,EAAA;AAC3E,QAAA,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE;aAClC,4BAA4B,CAAC,SAAS,CAAC,CAAA;QAE1C,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAC3B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EACzB,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CACpC,CAAA;KACF;AAoDD;;AAEG;AACH,IAAA,MAAM,SAAS,GAAA;AACb,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAA;KACpB;AACF;;;;"}
@@ -3,7 +3,6 @@ import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPay
3
3
  export declare class Collector {
4
4
  serverConfiguration: Partial<Configuration>;
5
5
  version: string;
6
- yjsVersion: string;
7
6
  connections: {};
8
7
  messages: {};
9
8
  messageCounter: number;
@@ -51,12 +50,12 @@ export declare class Collector {
51
50
  documents(): {};
52
51
  info(): Promise<{
53
52
  configuration: Partial<Configuration>;
54
- ipAddress: string;
53
+ ipAddress: string | null;
55
54
  nodeVersion: string;
56
55
  platform: NodeJS.Platform;
57
56
  started: string;
58
57
  version: string;
59
- yjsVersion: string;
60
58
  }>;
59
+ private getIpAddress;
61
60
  private static readableYDoc;
62
61
  }
@@ -1,16 +1,94 @@
1
- import { RedisPersistence } from 'y-redis';
2
- import { Extension, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
1
+ import RedisClient from 'ioredis';
2
+ import Redlock from 'redlock';
3
+ import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, Debugger, onConfigurePayload, onListenPayload } from '@hocuspocus/server';
3
4
  export interface Configuration {
5
+ /**
6
+ * Redis port
7
+ */
8
+ port: number;
9
+ /**
10
+ * Redis host
11
+ */
12
+ host: string;
13
+ /**
14
+ * Options passed directly to Redis constructor
15
+ *
16
+ * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
17
+ */
18
+ options?: RedisClient.RedisOptions;
19
+ /**
20
+ * An unique instance name, required to filter messages in Redis.
21
+ * If none is provided an unique id is generated.
22
+ */
23
+ identifier: string;
24
+ /**
25
+ * Namespace for Redis keys, if none is provided 'hocuspocus' is used
26
+ */
27
+ prefix: string;
28
+ /**
29
+ * The maximum time for the Redis lock in ms (in case it can’t be released).
30
+ */
31
+ lockTimeout: number;
4
32
  }
5
33
  export declare class Redis implements Extension {
34
+ /**
35
+ * Make sure to give that extension a higher priority, so
36
+ * the `onStoreDocument` hook is able to intercept the chain,
37
+ * before documents are stored to the database.
38
+ */
39
+ priority: number;
6
40
  configuration: Configuration;
7
- cluster: boolean;
8
- persistence: RedisPersistence | undefined;
41
+ pub: RedisClient.Redis;
42
+ sub: RedisClient.Redis;
43
+ documents: Map<string, Document>;
44
+ redlock: Redlock;
45
+ locks: Map<string, Redlock.Lock>;
46
+ logger: Debugger;
47
+ constructor(configuration: Partial<Configuration>);
48
+ onConfigure({ instance }: onConfigurePayload): Promise<void>;
49
+ onListen({ configuration }: onListenPayload): Promise<void>;
50
+ private getKey;
51
+ private pubKey;
52
+ private subKey;
53
+ private lockKey;
54
+ /**
55
+ * Once a document is laoded, subscribe to the channel in Redis.
56
+ */
57
+ afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
58
+ /**
59
+ * Publish the first sync step through Redis.
60
+ */
61
+ private publishFirstSyncStep;
62
+ /**
63
+ * Let’s ask Redis who is connected already.
64
+ */
65
+ private requestAwarenessFromOtherInstances;
66
+ /**
67
+ * Before the document is stored, make sure to set a lock in Redis.
68
+ * That’s meant to avoid conflicts with other instances trying to store the document.
69
+ */
70
+ onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<unknown>;
71
+ /**
72
+ * Release the Redis lock, so other instances can store documents.
73
+ */
74
+ afterStoreDocument({ documentName }: afterStoreDocumentPayload): Promise<void>;
75
+ /**
76
+ * Handle awareness update messages received directly by this Hocuspocus instance.
77
+ */
78
+ onAwarenessUpdate({ documentName, awareness }: onAwarenessUpdatePayload): Promise<number>;
79
+ /**
80
+ * Handle incoming messages published on all subscribed document channels.
81
+ * Note that this will also include messages from ourselves as it is not possible
82
+ * in Redis to filter these.
83
+ */
84
+ private handleIncomingMessage;
85
+ /**
86
+ * Make sure to *not* listen for further changes, when there’s
87
+ * noone connected anymore.
88
+ */
89
+ onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise<void>;
9
90
  /**
10
- * Constructor
91
+ * Kill the Redlock connection immediately.
11
92
  */
12
- constructor(configuration?: Partial<Configuration>);
13
- onLoadDocument(data: onLoadDocumentPayload): Promise<import("yjs").Doc | undefined>;
14
- onConnect(data: onConnectPayload): Promise<void>;
15
- onDisconnect(data: onDisconnectPayload): Promise<void>;
93
+ onDestroy(): Promise<void>;
16
94
  }
@@ -1,2 +1 @@
1
1
  export * from './Redis';
2
- export * from './RedisCluster';
@@ -3,14 +3,8 @@ import { Awareness } from 'y-protocols/awareness';
3
3
  import * as mutex from 'lib0/mutex';
4
4
  import type { Event, CloseEvent, MessageEvent } from 'ws';
5
5
  import EventEmitter from './EventEmitter';
6
- import { OutgoingMessage } from './OutgoingMessage';
7
- import { ConstructableOutgoingMessage } from './types';
6
+ import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
8
7
  import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
9
- export declare enum WebSocketStatus {
10
- Connecting = "connecting",
11
- Connected = "connected",
12
- Disconnected = "disconnected"
13
- }
14
8
  export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
15
9
  export interface CompleteHocuspocusProviderConfiguration {
16
10
  /**
@@ -92,22 +86,18 @@ export interface CompleteHocuspocusProviderConfiguration {
92
86
  */
93
87
  timeout: number;
94
88
  onAuthenticated: () => void;
95
- onAuthenticationFailed: ({ reason }: {
96
- reason: string;
97
- }) => void;
98
- onOpen: (event: Event) => void;
89
+ onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
90
+ onOpen: (data: onOpenParameters) => void;
99
91
  onConnect: () => void;
100
- onMessage: (event: MessageEvent) => void;
101
- onOutgoingMessage: (message: OutgoingMessage) => void;
102
- onStatus: (status: any) => void;
103
- onSynced: ({ state }: {
104
- state: boolean;
105
- }) => void;
106
- onDisconnect: (event: CloseEvent) => void;
107
- onClose: (event: CloseEvent) => void;
92
+ onMessage: (data: onMessageParameters) => void;
93
+ onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
94
+ onStatus: (data: onStatusParameters) => void;
95
+ onSynced: (data: onSyncedParameters) => void;
96
+ onDisconnect: (data: onDisconnectParameters) => void;
97
+ onClose: (data: onCloseParameters) => void;
108
98
  onDestroy: () => void;
109
- onAwarenessUpdate: ({ states }: onAwarenessUpdateParameters) => void;
110
- onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void;
99
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
100
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
111
101
  /**
112
102
  * Don’t output any warnings.
113
103
  */
@@ -1,18 +1,26 @@
1
1
  import { Awareness } from 'y-protocols/awareness';
2
2
  import * as Y from 'yjs';
3
3
  import { Encoder } from 'lib0/encoding';
4
+ import type { Event, CloseEvent, MessageEvent } from 'ws';
4
5
  import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
5
6
  import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
6
7
  import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
7
8
  import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
8
9
  import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
9
10
  import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
11
+ import { IncomingMessage } from './IncomingMessage';
12
+ import { OutgoingMessage } from './OutgoingMessage';
10
13
  export declare enum MessageType {
11
14
  Sync = 0,
12
15
  Awareness = 1,
13
16
  Auth = 2,
14
17
  QueryAwareness = 3
15
18
  }
19
+ export declare enum WebSocketStatus {
20
+ Connecting = "connecting",
21
+ Connected = "connected",
22
+ Disconnected = "disconnected"
23
+ }
16
24
  export interface OutgoingMessageInterface {
17
25
  encoder: Encoder;
18
26
  type?: MessageType;
@@ -32,6 +40,31 @@ export interface Constructable<T> {
32
40
  new (...args: any): T;
33
41
  }
34
42
  export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
43
+ export declare type onAuthenticationFailedParameters = {
44
+ reason: string;
45
+ };
46
+ export declare type onOpenParameters = {
47
+ event: Event;
48
+ };
49
+ export declare type onMessageParameters = {
50
+ event: MessageEvent;
51
+ message: IncomingMessage;
52
+ };
53
+ export declare type onOutgoingMessageParameters = {
54
+ message: OutgoingMessage;
55
+ };
56
+ export declare type onStatusParameters = {
57
+ status: WebSocketStatus;
58
+ };
59
+ export declare type onSyncedParameters = {
60
+ state: boolean;
61
+ };
62
+ export declare type onDisconnectParameters = {
63
+ event: CloseEvent;
64
+ };
65
+ export declare type onCloseParameters = {
66
+ event: CloseEvent;
67
+ };
35
68
  export declare type onAwarenessUpdateParameters = {
36
69
  states: StatesArray;
37
70
  };
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
3
3
  import { IncomingMessage, Server as HTTPServer } from 'http';
4
- import { Configuration, Hook } from './types';
4
+ import { Configuration, HookName, HookPayload } from './types';
5
5
  import Document from './Document';
6
6
  import { Debugger } from './Debugger';
7
7
  import { onListenPayload } from '.';
@@ -88,7 +88,7 @@ export declare class Hocuspocus {
88
88
  * Run the given hook on all configured extensions.
89
89
  * Runs the given callback after each hook.
90
90
  */
91
- hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
91
+ hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
92
92
  /**
93
93
  * Get parameters by the given request
94
94
  */
@@ -1,9 +1,8 @@
1
- export * from './Hocuspocus';
2
1
  export * from './Connection';
2
+ export * from './Debugger';
3
3
  export * from './Document';
4
+ export * from './Hocuspocus';
4
5
  export * from './IncomingMessage';
6
+ export * from './MessageReceiver';
5
7
  export * from './OutgoingMessage';
6
8
  export * from './types';
7
- export * from './MessageReceiver';
8
- export * from './Document';
9
- export * from './Connection';
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
3
3
  import { URLSearchParams } from 'url';
4
- import { Socket } from 'net';
5
4
  import { Awareness } from 'y-protocols/awareness';
6
5
  import Document from './Document';
7
6
  import { Hocuspocus } from './Hocuspocus';
@@ -44,11 +43,12 @@ export interface Extension {
44
43
  onDisconnect?(data: onDisconnectPayload): Promise<any>;
45
44
  onDestroy?(data: onDestroyPayload): Promise<any>;
46
45
  }
47
- export declare type Hook = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
46
+ export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
48
47
  /**
49
48
  * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
50
49
  */
51
50
  'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
51
+ export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onLoadDocumentPayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
52
52
  export interface Configuration extends Extension {
53
53
  /**
54
54
  * A name for the instance, used for logging.
@@ -198,20 +198,21 @@ export interface onRequestPayload {
198
198
  instance: Hocuspocus;
199
199
  }
200
200
  export interface onUpgradePayload {
201
- head: any;
202
201
  request: IncomingMessage;
203
- socket: Socket;
202
+ socket: any;
203
+ head: any;
204
204
  instance: Hocuspocus;
205
205
  }
206
206
  export interface onListenPayload {
207
+ instance: Hocuspocus;
208
+ configuration: Configuration;
207
209
  port: number;
208
210
  }
209
211
  export interface onDestroyPayload {
210
212
  instance: Hocuspocus;
211
213
  }
212
214
  export interface onConfigurePayload {
215
+ instance: Hocuspocus;
213
216
  configuration: Configuration;
214
217
  version: string;
215
- yjsVersion: string;
216
- instance: Hocuspocus;
217
218
  }
@@ -2,6 +2,7 @@ export * from './createDirectory';
2
2
  export * from './flushRedis';
3
3
  export * from './newHocuspocus';
4
4
  export * from './newHocuspocusProvider';
5
+ export * from './randomInteger';
5
6
  export * from './redisConnectionSettings';
6
7
  export * from './removeDirectory';
7
8
  export * from './sleep';
@@ -0,0 +1 @@
1
+ export declare const randomInteger: (min: number, max: number) => number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-redis",
3
- "version": "1.0.0-alpha.60",
4
- "description": "hocuspocus persistence driver for Redis",
3
+ "version": "1.0.0-alpha.63",
4
+ "description": "Scale Hocuspocus horizontally with Redis",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -26,10 +26,20 @@
26
26
  "src",
27
27
  "dist"
28
28
  ],
29
+ "devDependencies": {
30
+ "@types/ioredis": "^4.28.7",
31
+ "@types/lodash.debounce": "^4.0.6",
32
+ "@types/redlock": "^4.0.3"
33
+ },
29
34
  "dependencies": {
30
- "@hocuspocus/server": "^1.0.0-alpha.97",
31
- "y-redis": "^1.0.3",
32
- "yjs": "^13.5.28"
35
+ "@hocuspocus/server": "^1.0.0-alpha.100",
36
+ "ioredis": "^4.28.2",
37
+ "kleur": "^4.1.4",
38
+ "lodash.debounce": "^4.0.8",
39
+ "redlock": "^4.2.0",
40
+ "uuid": "^8.3.2",
41
+ "y-protocols": "^1.0.5",
42
+ "yjs": "^13.5.23"
33
43
  },
34
- "gitHead": "673dd4b2c723e71bf9b33b8f7804ab35c8417417"
44
+ "gitHead": "29d403cdc2b972cf3129229abcaceb08e365fbb4"
35
45
  }
package/src/Redis.ts CHANGED
@@ -1,80 +1,280 @@
1
- import { RedisPersistence } from 'y-redis'
1
+ import RedisClient from 'ioredis'
2
+ import Redlock from 'redlock'
3
+ import { v4 as uuid } from 'uuid'
2
4
  import {
5
+ IncomingMessage,
6
+ OutgoingMessage,
7
+ Document,
3
8
  Extension,
4
- onConnectPayload,
5
- onLoadDocumentPayload,
9
+ afterLoadDocumentPayload,
10
+ afterStoreDocumentPayload,
6
11
  onDisconnectPayload,
12
+ onStoreDocumentPayload,
13
+ onAwarenessUpdatePayload,
14
+ MessageReceiver,
15
+ Debugger,
16
+ onConfigurePayload,
17
+ onListenPayload,
7
18
  } from '@hocuspocus/server'
19
+ import kleur from 'kleur'
8
20
 
9
21
  export interface Configuration {
22
+ /**
23
+ * Redis port
24
+ */
25
+ port: number,
26
+ /**
27
+ * Redis host
28
+ */
29
+ host: string,
30
+ /**
31
+ * Options passed directly to Redis constructor
32
+ *
33
+ * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
34
+ */
35
+ options?: RedisClient.RedisOptions,
36
+ /**
37
+ * An unique instance name, required to filter messages in Redis.
38
+ * If none is provided an unique id is generated.
39
+ */
40
+ identifier: string,
41
+ /**
42
+ * Namespace for Redis keys, if none is provided 'hocuspocus' is used
43
+ */
44
+ prefix: string,
45
+ /**
46
+ * The maximum time for the Redis lock in ms (in case it can’t be released).
47
+ */
48
+ lockTimeout: number,
10
49
  }
11
50
 
12
51
  export class Redis implements Extension {
52
+ /**
53
+ * Make sure to give that extension a higher priority, so
54
+ * the `onStoreDocument` hook is able to intercept the chain,
55
+ * before documents are stored to the database.
56
+ */
57
+ priority = 1000
58
+
59
+ configuration: Configuration = {
60
+ port: 6379,
61
+ host: '127.0.0.1',
62
+ prefix: 'hocuspocus',
63
+ identifier: `host-${uuid()}`,
64
+ lockTimeout: 1000,
65
+ }
13
66
 
14
- configuration: Configuration = {}
67
+ pub: RedisClient.Redis
15
68
 
16
- cluster = false
69
+ sub: RedisClient.Redis
17
70
 
18
- persistence!: RedisPersistence | undefined
71
+ documents: Map<string, Document> = new Map()
19
72
 
20
- /**
21
- * Constructor
22
- */
23
- constructor(configuration?: Partial<Configuration>) {
73
+ redlock: Redlock
74
+
75
+ locks = new Map<string, Redlock.Lock>()
76
+
77
+ logger: Debugger
78
+
79
+ public constructor(configuration: Partial<Configuration>) {
24
80
  this.configuration = {
25
81
  ...this.configuration,
26
82
  ...configuration,
27
83
  }
84
+
85
+ const { port, host, options } = this.configuration
86
+
87
+ this.pub = new RedisClient(port, host, options)
88
+
89
+ this.sub = new RedisClient(port, host, options)
90
+ this.sub.on('pmessageBuffer', this.handleIncomingMessage)
91
+
92
+ this.redlock = new Redlock([this.pub])
93
+
94
+ // We’ll replace that in the onConfigure hook with the global instance.
95
+ this.logger = new Debugger()
28
96
  }
29
97
 
30
- /*
31
- * onLoadDocument hook
32
- */
33
- async onLoadDocument(data: onLoadDocumentPayload) {
34
- if (!this.persistence) {
98
+ async onConfigure({ instance }: onConfigurePayload) {
99
+ this.logger = instance.debugger
100
+ }
101
+
102
+ async onListen({ configuration }: onListenPayload) {
103
+ if (configuration.quiet) {
35
104
  return
36
105
  }
37
106
 
38
- // If another connection has already loaded this doc, return this one instead
39
- const binding = this.persistence.docs.get(data.documentName)
107
+ 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.')}`)
108
+ console.log()
109
+ }
110
+
111
+ private getKey(documentName: string) {
112
+ return `${this.configuration.prefix}:${documentName}`
113
+ }
40
114
 
41
- if (binding) {
42
- return binding.doc
43
- }
115
+ private pubKey(documentName: string) {
116
+ return `${this.getKey(documentName)}:${this.configuration.identifier.replace(/:/g, '')}`
117
+ }
44
118
 
45
- await this.persistence.bindState(data.documentName, data.document).synced
119
+ private subKey(documentName: string) {
120
+ return `${this.getKey(documentName)}:*`
46
121
  }
47
122
 
48
- async onConnect(data: onConnectPayload) {
49
- // Bind to Redis already? Ok, no worries.
50
- if (this.persistence) {
51
- return
52
- }
123
+ private lockKey(documentName: string) {
124
+ return `${this.getKey(documentName)}:lock`
125
+ }
126
+
127
+ /**
128
+ * Once a document is laoded, subscribe to the channel in Redis.
129
+ */
130
+ public async afterLoadDocument({ documentName, document }: afterLoadDocumentPayload) {
131
+ this.documents.set(documentName, document)
53
132
 
54
- this.persistence = new RedisPersistence(
55
- // @ts-ignore
56
- this.cluster
57
- ? { redisClusterOpts: this.configuration }
58
- : { redisOpts: this.configuration },
133
+ return new Promise((resolve, reject) => {
134
+ // On document creation the node will connect to pub and sub channels
135
+ // for the document.
136
+ this.sub.psubscribe(this.subKey(documentName), async error => {
137
+ if (error) {
138
+ reject(error)
139
+ return
140
+ }
141
+
142
+ this.publishFirstSyncStep(documentName, document)
143
+ this.requestAwarenessFromOtherInstances(documentName)
144
+
145
+ resolve(undefined)
146
+ })
147
+ })
148
+ }
149
+
150
+ /**
151
+ * Publish the first sync step through Redis.
152
+ */
153
+ private async publishFirstSyncStep(documentName: string, document: Document) {
154
+ const syncMessage = new OutgoingMessage()
155
+ .createSyncMessage()
156
+ .writeFirstSyncStepFor(document)
157
+
158
+ return this.pub.publishBuffer(this.pubKey(documentName), Buffer.from(syncMessage.toUint8Array()))
159
+ }
160
+
161
+ /**
162
+ * Let’s ask Redis who is connected already.
163
+ */
164
+ private async requestAwarenessFromOtherInstances(documentName: string) {
165
+ const awarenessMessage = new OutgoingMessage()
166
+ .writeQueryAwareness()
167
+
168
+ return this.pub.publishBuffer(
169
+ this.pubKey(documentName),
170
+ Buffer.from(awarenessMessage.toUint8Array()),
59
171
  )
172
+ }
173
+
174
+ /**
175
+ * Before the document is stored, make sure to set a lock in Redis.
176
+ * That’s meant to avoid conflicts with other instances trying to store the document.
177
+ */
178
+ async onStoreDocument({ documentName }: onStoreDocumentPayload) {
179
+ // Attempt to acquire a lock and read lastReceivedTimestamp from Redis,
180
+ // to avoid conflict with other instances storing the same document.
181
+ return new Promise((resolve, reject) => {
182
+ this.redlock.lock(this.lockKey(documentName), this.configuration.lockTimeout, async (error, lock) => {
183
+ if (error || !lock) {
184
+ // Expected behavior: Could not acquire lock, another instance locked it already.
185
+ // No further `onStoreDocument` hooks will be executed.
186
+ reject()
187
+ return
188
+ }
189
+
190
+ this.locks.set(this.lockKey(documentName), lock)
60
191
 
192
+ resolve(undefined)
193
+ })
194
+ })
61
195
  }
62
196
 
63
- async onDisconnect(data: onDisconnectPayload) {
64
- // Not binded to Redis? Never mind!
65
- if (!this.persistence) {
197
+ /**
198
+ * Release the Redis lock, so other instances can store documents.
199
+ */
200
+ async afterStoreDocument({ documentName }: afterStoreDocumentPayload) {
201
+ this.locks.get(this.lockKey(documentName))?.unlock()
202
+ .catch(() => {
203
+ // Not able to unlock Redis. The lock will expire after ${lockTimeout} ms.
204
+ // console.error(`Not able to unlock Redis. The lock will expire after ${this.configuration.lockTimeout}ms.`)
205
+ })
206
+ .finally(() => {
207
+ this.locks.delete(this.lockKey(documentName))
208
+ })
209
+ }
210
+
211
+ /**
212
+ * Handle awareness update messages received directly by this Hocuspocus instance.
213
+ */
214
+ async onAwarenessUpdate({ documentName, awareness }: onAwarenessUpdatePayload) {
215
+ const message = new OutgoingMessage()
216
+ .createAwarenessUpdateMessage(awareness)
217
+
218
+ return this.pub.publishBuffer(
219
+ this.pubKey(documentName),
220
+ Buffer.from(message.toUint8Array()),
221
+ )
222
+ }
223
+
224
+ /**
225
+ * Handle incoming messages published on all subscribed document channels.
226
+ * Note that this will also include messages from ourselves as it is not possible
227
+ * in Redis to filter these.
228
+ */
229
+ private handleIncomingMessage = async (channel: Buffer, pattern: Buffer, data: Buffer) => {
230
+ const channelName = pattern.toString()
231
+ const [_, documentName, identifier] = channelName.split(':')
232
+ const document = this.documents.get(documentName)
233
+
234
+ if (identifier === this.configuration.identifier) {
66
235
  return
67
236
  }
68
237
 
69
- // Still clients connected?
70
- if (data.clientsCount > 0) {
238
+ if (!document) {
71
239
  return
72
240
  }
73
241
 
74
- // Fine, let’s remove the binding …
75
- this.persistence.destroy()
76
- this.persistence = undefined
242
+ new MessageReceiver(
243
+ new IncomingMessage(data),
244
+ this.logger,
245
+ ).apply(document, undefined, reply => {
246
+ return this.pub.publishBuffer(
247
+ this.pubKey(document.name),
248
+ Buffer.from(reply),
249
+ )
250
+ })
251
+ }
77
252
 
253
+ /**
254
+ * Make sure to *not* listen for further changes, when there’s
255
+ * noone connected anymore.
256
+ */
257
+ public onDisconnect = async ({ documentName, clientsCount }: onDisconnectPayload) => {
258
+ // Do nothing, when other users are still connected to the document.
259
+ if (clientsCount > 0) {
260
+ return
261
+ }
262
+
263
+ // It was indeed the last connected user.
264
+ this.documents.delete(documentName)
265
+
266
+ // Time to end the subscription on the document channel.
267
+ this.sub.punsubscribe(this.subKey(documentName), error => {
268
+ if (error) {
269
+ console.error(error)
270
+ }
271
+ })
78
272
  }
79
273
 
274
+ /**
275
+ * Kill the Redlock connection immediately.
276
+ */
277
+ async onDestroy() {
278
+ this.redlock.quit()
279
+ }
80
280
  }
package/src/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from './Redis'
2
- export * from './RedisCluster'
@@ -1,4 +0,0 @@
1
- import { Redis } from './Redis';
2
- export declare class RedisCluster extends Redis {
3
- cluster: boolean;
4
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { Redis } from './Redis'
2
-
3
- export class RedisCluster extends Redis {
4
-
5
- cluster = true
6
-
7
- }