@hocuspocus/extension-webhook 2.1.0-alpha.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/hocuspocus-webhook.cjs +157 -157
  2. package/dist/hocuspocus-webhook.esm.js +157 -157
  3. package/dist/packages/common/src/CloseEvents.d.ts +29 -29
  4. package/dist/packages/common/src/auth.d.ts +6 -6
  5. package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -3
  6. package/dist/packages/common/src/index.d.ts +4 -4
  7. package/dist/packages/common/src/types.d.ts +10 -10
  8. package/dist/packages/extension-database/src/Database.d.ts +30 -30
  9. package/dist/packages/extension-database/src/index.d.ts +1 -1
  10. package/dist/packages/extension-logger/src/Logger.d.ts +67 -67
  11. package/dist/packages/extension-logger/src/index.d.ts +1 -1
  12. package/dist/packages/extension-redis/src/Redis.d.ts +116 -95
  13. package/dist/packages/extension-redis/src/index.d.ts +1 -1
  14. package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -26
  15. package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
  16. package/dist/packages/extension-throttle/src/index.d.ts +31 -31
  17. package/dist/packages/extension-webhook/src/index.d.ts +57 -57
  18. package/dist/packages/provider/src/EventEmitter.d.ts +9 -9
  19. package/dist/packages/provider/src/HocuspocusProvider.d.ts +110 -110
  20. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +115 -115
  21. package/dist/packages/provider/src/IncomingMessage.d.ts +16 -16
  22. package/dist/packages/provider/src/MessageReceiver.d.ts +13 -13
  23. package/dist/packages/provider/src/MessageSender.d.ts +10 -10
  24. package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -9
  25. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -7
  26. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -8
  27. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +8 -8
  28. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -8
  29. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +7 -7
  30. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -8
  31. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -8
  32. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -7
  33. package/dist/packages/provider/src/TiptapCollabProvider.d.ts +11 -11
  34. package/dist/packages/provider/src/TiptapCollabProviderWebsocket.d.ts +11 -11
  35. package/dist/packages/provider/src/index.d.ts +5 -5
  36. package/dist/packages/provider/src/types.d.ts +84 -84
  37. package/dist/packages/server/src/ClientConnection.d.ts +56 -0
  38. package/dist/packages/server/src/Connection.d.ts +71 -71
  39. package/dist/packages/server/src/Debugger.d.ts +14 -14
  40. package/dist/packages/server/src/DirectConnection.d.ts +14 -0
  41. package/dist/packages/server/src/Document.d.ts +91 -88
  42. package/dist/packages/server/src/Hocuspocus.d.ts +103 -108
  43. package/dist/packages/server/src/IncomingMessage.d.ts +21 -21
  44. package/dist/packages/server/src/MessageReceiver.d.ts +12 -12
  45. package/dist/packages/server/src/OutgoingMessage.d.ts +20 -20
  46. package/dist/packages/server/src/index.d.ts +8 -8
  47. package/dist/packages/server/src/types.d.ts +270 -264
  48. package/dist/packages/server/src/util/getParameters.d.ts +8 -0
  49. package/dist/packages/transformer/src/Prosemirror.d.ts +11 -11
  50. package/dist/packages/transformer/src/Tiptap.d.ts +10 -10
  51. package/dist/packages/transformer/src/index.d.ts +3 -3
  52. package/dist/packages/transformer/src/types.d.ts +5 -5
  53. package/dist/playground/backend/src/default.d.ts +1 -1
  54. package/dist/playground/backend/src/express.d.ts +1 -1
  55. package/dist/playground/backend/src/koa.d.ts +1 -1
  56. package/dist/playground/backend/src/load-document.d.ts +1 -1
  57. package/dist/playground/backend/src/redis.d.ts +1 -1
  58. package/dist/playground/backend/src/slow.d.ts +1 -1
  59. package/dist/playground/backend/src/tiptapcollab.d.ts +1 -1
  60. package/dist/playground/backend/src/webhook.d.ts +1 -1
  61. package/dist/playground/frontend/src/main.d.ts +1 -1
  62. package/dist/playground/frontend/vite.config.d.ts +2 -2
  63. package/dist/tests/extension-database/fetch.d.ts +1 -1
  64. package/dist/tests/extension-logger/onListen.d.ts +1 -1
  65. package/dist/tests/extension-redis/closeConnections.d.ts +1 -1
  66. package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -1
  67. package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -1
  68. package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -1
  69. package/dist/tests/extension-redis/onChange.d.ts +1 -1
  70. package/dist/tests/extension-redis/onStateless.d.ts +1 -1
  71. package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -1
  72. package/dist/tests/extension-throttle/banning.d.ts +1 -1
  73. package/dist/tests/extension-throttle/configuration.d.ts +1 -1
  74. package/dist/tests/provider/observe.d.ts +1 -1
  75. package/dist/tests/provider/observeDeep.d.ts +1 -1
  76. package/dist/tests/provider/onAuthenticated.d.ts +1 -1
  77. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -1
  78. package/dist/tests/provider/onAwarenessChange.d.ts +1 -1
  79. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -1
  80. package/dist/tests/provider/onClose.d.ts +1 -1
  81. package/dist/tests/provider/onConnect.d.ts +1 -1
  82. package/dist/tests/provider/onDisconnect.d.ts +1 -1
  83. package/dist/tests/provider/onMessage.d.ts +1 -1
  84. package/dist/tests/provider/onOpen.d.ts +1 -1
  85. package/dist/tests/provider/onStateless.d.ts +1 -1
  86. package/dist/tests/provider/onSynced.d.ts +1 -1
  87. package/dist/tests/providerwebsocket/configuration.d.ts +1 -1
  88. package/dist/tests/server/address.d.ts +1 -1
  89. package/dist/tests/server/afterStoreDocument.d.ts +1 -1
  90. package/dist/tests/server/beforeBroadcastStateless.d.ts +1 -1
  91. package/dist/tests/server/beforeHandleMessage.d.ts +1 -1
  92. package/dist/tests/server/closeConnections.d.ts +1 -1
  93. package/dist/tests/server/getConnectionsCount.d.ts +1 -1
  94. package/dist/tests/server/getDocumentsCount.d.ts +1 -1
  95. package/dist/tests/server/getMessageLogs.d.ts +1 -1
  96. package/dist/tests/server/listen.d.ts +1 -1
  97. package/dist/tests/server/onAuthenticate.d.ts +1 -1
  98. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -1
  99. package/dist/tests/server/onChange.d.ts +1 -1
  100. package/dist/tests/server/onClose.d.ts +1 -1
  101. package/dist/tests/server/onConfigure.d.ts +1 -1
  102. package/dist/tests/server/onConnect.d.ts +1 -1
  103. package/dist/tests/server/onDestroy.d.ts +1 -1
  104. package/dist/tests/server/onDisconnect.d.ts +1 -1
  105. package/dist/tests/server/onListen.d.ts +1 -1
  106. package/dist/tests/server/onLoadDocument.d.ts +1 -1
  107. package/dist/tests/server/onRequest.d.ts +1 -1
  108. package/dist/tests/server/onStateless.d.ts +1 -1
  109. package/dist/tests/server/onStoreDocument.d.ts +1 -1
  110. package/dist/tests/server/onUpgrade.d.ts +1 -1
  111. package/dist/tests/server/openDirectConnection.d.ts +1 -0
  112. package/dist/tests/server/requiresAuthentication.d.ts +1 -1
  113. package/dist/tests/server/websocketError.d.ts +1 -1
  114. package/dist/tests/transformer/TiptapTransformer.d.ts +1 -1
  115. package/dist/tests/utils/createDirectory.d.ts +1 -1
  116. package/dist/tests/utils/flushRedis.d.ts +1 -1
  117. package/dist/tests/utils/index.d.ts +9 -9
  118. package/dist/tests/utils/newHocuspocus.d.ts +2 -2
  119. package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -3
  120. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +3 -3
  121. package/dist/tests/utils/randomInteger.d.ts +1 -1
  122. package/dist/tests/utils/redisConnectionSettings.d.ts +4 -4
  123. package/dist/tests/utils/removeDirectory.d.ts +1 -1
  124. package/dist/tests/utils/retryableAssertion.d.ts +2 -2
  125. package/dist/tests/utils/sleep.d.ts +1 -1
  126. package/package.json +6 -5
@@ -1,29 +1,29 @@
1
- export interface CloseEvent {
2
- code: number;
3
- reason: string;
4
- }
5
- /**
6
- * The server is terminating the connection because a data frame was received
7
- * that is too large.
8
- * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
9
- */
10
- export declare const MessageTooBig: CloseEvent;
11
- /**
12
- * The server successfully processed the request, asks that the requester reset
13
- * its document view, and is not returning any content.
14
- */
15
- export declare const ResetConnection: CloseEvent;
16
- /**
17
- * Similar to Forbidden, but specifically for use when authentication is required and has
18
- * failed or has not yet been provided.
19
- */
20
- export declare const Unauthorized: CloseEvent;
21
- /**
22
- * The request contained valid data and was understood by the server, but the server
23
- * is refusing action.
24
- */
25
- export declare const Forbidden: CloseEvent;
26
- /**
27
- * The server timed out waiting for the request.
28
- */
29
- export declare const ConnectionTimeout: CloseEvent;
1
+ export interface CloseEvent {
2
+ code: number;
3
+ reason: string;
4
+ }
5
+ /**
6
+ * The server is terminating the connection because a data frame was received
7
+ * that is too large.
8
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
9
+ */
10
+ export declare const MessageTooBig: CloseEvent;
11
+ /**
12
+ * The server successfully processed the request, asks that the requester reset
13
+ * its document view, and is not returning any content.
14
+ */
15
+ export declare const ResetConnection: CloseEvent;
16
+ /**
17
+ * Similar to Forbidden, but specifically for use when authentication is required and has
18
+ * failed or has not yet been provided.
19
+ */
20
+ export declare const Unauthorized: CloseEvent;
21
+ /**
22
+ * The request contained valid data and was understood by the server, but the server
23
+ * is refusing action.
24
+ */
25
+ export declare const Forbidden: CloseEvent;
26
+ /**
27
+ * The server timed out waiting for the request.
28
+ */
29
+ export declare const ConnectionTimeout: CloseEvent;
@@ -1,6 +1,6 @@
1
- import * as encoding from 'lib0/encoding';
2
- import * as decoding from 'lib0/decoding';
3
- export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
4
- export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
5
- export declare const writeAuthenticated: (encoder: encoding.Encoder) => void;
6
- export declare const readAuthMessage: (decoder: decoding.Decoder, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: () => void) => void;
1
+ import * as encoding from 'lib0/encoding';
2
+ import * as decoding from 'lib0/decoding';
3
+ export declare const writeAuthentication: (encoder: encoding.Encoder, auth: string) => void;
4
+ export declare const writePermissionDenied: (encoder: encoding.Encoder, reason: string) => void;
5
+ export declare const writeAuthenticated: (encoder: encoding.Encoder, scope: 'readonly' | 'read-write') => void;
6
+ export declare const readAuthMessage: (decoder: decoding.Decoder, permissionDeniedHandler: (reason: string) => void, authenticatedHandler: (scope: string) => void) => void;
@@ -1,3 +1,3 @@
1
- export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
2
- clientId: number;
3
- }[];
1
+ export declare const awarenessStatesToArray: (states: Map<number, Record<string, any>>) => {
2
+ clientId: number;
3
+ }[];
@@ -1,4 +1,4 @@
1
- export * from './auth';
2
- export * from './CloseEvents';
3
- export * from './awarenessStatesToArray';
4
- export * from './types';
1
+ export * from './auth.js';
2
+ export * from './CloseEvents.js';
3
+ export * from './awarenessStatesToArray.js';
4
+ export * from './types.js';
@@ -1,10 +1,10 @@
1
- /**
2
- * State of the WebSocket connection.
3
- * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
4
- */
5
- export declare enum WsReadyStates {
6
- Connecting = 0,
7
- Open = 1,
8
- Closing = 2,
9
- Closed = 3
10
- }
1
+ /**
2
+ * State of the WebSocket connection.
3
+ * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
4
+ */
5
+ export declare enum WsReadyStates {
6
+ Connecting = 0,
7
+ Open = 1,
8
+ Closing = 2,
9
+ Closed = 3
10
+ }
@@ -1,30 +1,30 @@
1
- import { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
2
- export interface DatabaseConfiguration {
3
- /**
4
- * Pass a Promise to retrieve updates from your database. The Promise should resolve to
5
- * an array of items with Y.js-compatible binary data.
6
- */
7
- fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
8
- /**
9
- * Pass a function to store updates in your database.
10
- */
11
- store: (data: storePayload) => void;
12
- }
13
- export declare class Database implements Extension {
14
- /**
15
- * Default configuration
16
- */
17
- configuration: DatabaseConfiguration;
18
- /**
19
- * Constructor
20
- */
21
- constructor(configuration: Partial<DatabaseConfiguration>);
22
- /**
23
- * Get stored data from the database.
24
- */
25
- onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
26
- /**
27
- * Store new updates in the database.
28
- */
29
- onStoreDocument(data: onChangePayload): Promise<void>;
30
- }
1
+ import { Extension, onChangePayload, onLoadDocumentPayload, storePayload, fetchPayload } from '@hocuspocus/server';
2
+ export interface DatabaseConfiguration {
3
+ /**
4
+ * Pass a Promise to retrieve updates from your database. The Promise should resolve to
5
+ * an array of items with Y.js-compatible binary data.
6
+ */
7
+ fetch: (data: fetchPayload) => Promise<Uint8Array | null>;
8
+ /**
9
+ * Pass a function to store updates in your database.
10
+ */
11
+ store: (data: storePayload) => void;
12
+ }
13
+ export declare class Database implements Extension {
14
+ /**
15
+ * Default configuration
16
+ */
17
+ configuration: DatabaseConfiguration;
18
+ /**
19
+ * Constructor
20
+ */
21
+ constructor(configuration: Partial<DatabaseConfiguration>);
22
+ /**
23
+ * Get stored data from the database.
24
+ */
25
+ onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
26
+ /**
27
+ * Store new updates in the database.
28
+ */
29
+ onStoreDocument(data: onChangePayload): Promise<void>;
30
+ }
@@ -1 +1 @@
1
- export * from './Database';
1
+ export * from './Database.js';
@@ -1,67 +1,67 @@
1
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
- export interface LoggerConfiguration {
3
- /**
4
- * Prepend all logging message with a string.
5
- *
6
- * @deprecated
7
- */
8
- prefix: null | string;
9
- /**
10
- * Whether to log something for the `onLoadDocument` hook.
11
- */
12
- onLoadDocument: boolean;
13
- /**
14
- * Whether to log something for the `onChange` hook.
15
- */
16
- onChange: boolean;
17
- /**
18
- * Whether to log something for the `onStoreDocument` hook.
19
- */
20
- onStoreDocument: boolean;
21
- /**
22
- * Whether to log something for the `onConnect` hook.
23
- */
24
- onConnect: boolean;
25
- /**
26
- * Whether to log something for the `onDisconnect` hook.
27
- */
28
- onDisconnect: boolean;
29
- /**
30
- * Whether to log something for the `onUpgrade` hook.
31
- */
32
- onUpgrade: boolean;
33
- /**
34
- * Whether to log something for the `onRequest` hook.
35
- */
36
- onRequest: boolean;
37
- /**
38
- * Whether to log something for the `onDestroy` hook.
39
- */
40
- onDestroy: boolean;
41
- /**
42
- * Whether to log something for the `onConfigure` hook.
43
- */
44
- onConfigure: boolean;
45
- /**
46
- * A log function, if none is provided output will go to console
47
- */
48
- log: (...args: any[]) => void;
49
- }
50
- export declare class Logger implements Extension {
51
- name: string | null;
52
- configuration: LoggerConfiguration;
53
- /**
54
- * Constructor
55
- */
56
- constructor(configuration?: Partial<LoggerConfiguration>);
57
- onConfigure(data: onConfigurePayload): Promise<void>;
58
- onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
59
- onChange(data: onChangePayload): Promise<void>;
60
- onStoreDocument(data: onDisconnectPayload): Promise<void>;
61
- onConnect(data: onConnectPayload): Promise<void>;
62
- onDisconnect(data: onDisconnectPayload): Promise<void>;
63
- onUpgrade(data: onUpgradePayload): Promise<void>;
64
- onRequest(data: onRequestPayload): Promise<void>;
65
- onDestroy(data: onDestroyPayload): Promise<void>;
66
- private log;
67
- }
1
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ export interface LoggerConfiguration {
3
+ /**
4
+ * Prepend all logging message with a string.
5
+ *
6
+ * @deprecated
7
+ */
8
+ prefix: null | string;
9
+ /**
10
+ * Whether to log something for the `onLoadDocument` hook.
11
+ */
12
+ onLoadDocument: boolean;
13
+ /**
14
+ * Whether to log something for the `onChange` hook.
15
+ */
16
+ onChange: boolean;
17
+ /**
18
+ * Whether to log something for the `onStoreDocument` hook.
19
+ */
20
+ onStoreDocument: boolean;
21
+ /**
22
+ * Whether to log something for the `onConnect` hook.
23
+ */
24
+ onConnect: boolean;
25
+ /**
26
+ * Whether to log something for the `onDisconnect` hook.
27
+ */
28
+ onDisconnect: boolean;
29
+ /**
30
+ * Whether to log something for the `onUpgrade` hook.
31
+ */
32
+ onUpgrade: boolean;
33
+ /**
34
+ * Whether to log something for the `onRequest` hook.
35
+ */
36
+ onRequest: boolean;
37
+ /**
38
+ * Whether to log something for the `onDestroy` hook.
39
+ */
40
+ onDestroy: boolean;
41
+ /**
42
+ * Whether to log something for the `onConfigure` hook.
43
+ */
44
+ onConfigure: boolean;
45
+ /**
46
+ * A log function, if none is provided output will go to console
47
+ */
48
+ log: (...args: any[]) => void;
49
+ }
50
+ export declare class Logger implements Extension {
51
+ name: string | null;
52
+ configuration: LoggerConfiguration;
53
+ /**
54
+ * Constructor
55
+ */
56
+ constructor(configuration?: Partial<LoggerConfiguration>);
57
+ onConfigure(data: onConfigurePayload): Promise<void>;
58
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
59
+ onChange(data: onChangePayload): Promise<void>;
60
+ onStoreDocument(data: onDisconnectPayload): Promise<void>;
61
+ onConnect(data: onConnectPayload): Promise<void>;
62
+ onDisconnect(data: onDisconnectPayload): Promise<void>;
63
+ onUpgrade(data: onUpgradePayload): Promise<void>;
64
+ onRequest(data: onRequestPayload): Promise<void>;
65
+ onDestroy(data: onDestroyPayload): Promise<void>;
66
+ private log;
67
+ }
@@ -1 +1 @@
1
- export * from './Logger';
1
+ export * from './Logger.js';
@@ -1,95 +1,116 @@
1
- import RedisClient, { ClusterNode, ClusterOptions, RedisOptions, Cluster as RedisClusterClient } from 'ioredis';
2
- import { Extension, afterLoadDocumentPayload, onDisconnectPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
3
- export type RedisInstance = RedisClient | RedisClusterClient;
4
- export interface Configuration {
5
- /**
6
- * Redis port
7
- */
8
- port: number;
9
- /**
10
- * Redis host
11
- */
12
- host: string;
13
- /**
14
- * Redis Cluster
15
- */
16
- nodes?: ClusterNode[];
17
- /**
18
- * Duplicate from an existed Redis instance
19
- */
20
- redis?: RedisInstance;
21
- /**
22
- * Redis instance creator
23
- */
24
- createClient?: () => RedisInstance;
25
- /**
26
- * Options passed directly to Redis constructor
27
- *
28
- * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
29
- */
30
- options?: ClusterOptions | RedisOptions;
31
- /**
32
- * An unique instance name, required to filter messages in Redis.
33
- * If none is provided an unique id is generated.
34
- */
35
- identifier: string;
36
- /**
37
- * Namespace for Redis keys, if none is provided 'hocuspocus' is used
38
- */
39
- prefix: string;
40
- /**
41
- * A delay before onDisconnect is executed. This allows last minute updates'
42
- * sync messages to be received by the subscription before it's closed.
43
- */
44
- disconnectDelay: number;
45
- }
46
- export declare class Redis implements Extension {
47
- /**
48
- * Make sure to give that extension a higher priority, so
49
- * the `onStoreDocument` hook is able to intercept the chain,
50
- * before documents are stored to the database.
51
- */
52
- priority: number;
53
- configuration: Configuration;
54
- pub: RedisInstance;
55
- sub: RedisInstance;
56
- instance: Hocuspocus;
57
- logger: Debugger;
58
- constructor(configuration: Partial<Configuration>);
59
- onConfigure({ instance }: onConfigurePayload): Promise<void>;
60
- private getKey;
61
- private pubKey;
62
- private subKey;
63
- /**
64
- * Once a document is laoded, subscribe to the channel in Redis.
65
- */
66
- afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
67
- /**
68
- * Publish the first sync step through Redis.
69
- */
70
- private publishFirstSyncStep;
71
- /**
72
- * Let’s ask Redis who is connected already.
73
- */
74
- private requestAwarenessFromOtherInstances;
75
- /**
76
- * Handle awareness update messages received directly by this Hocuspocus instance.
77
- */
78
- onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: 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
- * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
87
- */
88
- onChange(data: onChangePayload): Promise<any>;
89
- /**
90
- * Make sure to *not* listen for further changes, when there’s
91
- * noone connected anymore.
92
- */
93
- onDisconnect: ({ documentName }: onDisconnectPayload) => Promise<void>;
94
- beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
95
- }
1
+ import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
2
+ import Redlock from 'redlock';
3
+ import { Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, beforeBroadcastStatelessPayload, Hocuspocus } from '@hocuspocus/server';
4
+ export type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
5
+ export interface Configuration {
6
+ /**
7
+ * Redis port
8
+ */
9
+ port: number;
10
+ /**
11
+ * Redis host
12
+ */
13
+ host: string;
14
+ /**
15
+ * Redis Cluster
16
+ */
17
+ nodes?: ClusterNode[];
18
+ /**
19
+ * Duplicate from an existed Redis instance
20
+ */
21
+ redis?: RedisInstance;
22
+ /**
23
+ * Redis instance creator
24
+ */
25
+ createClient?: () => RedisInstance;
26
+ /**
27
+ * Options passed directly to Redis constructor
28
+ *
29
+ * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
30
+ */
31
+ options?: ClusterOptions | RedisOptions;
32
+ /**
33
+ * An unique instance name, required to filter messages in Redis.
34
+ * If none is provided an unique id is generated.
35
+ */
36
+ identifier: string;
37
+ /**
38
+ * Namespace for Redis keys, if none is provided 'hocuspocus' is used
39
+ */
40
+ prefix: string;
41
+ /**
42
+ * The maximum time for the Redis lock in ms (in case it can’t be released).
43
+ */
44
+ lockTimeout: number;
45
+ /**
46
+ * A delay before onDisconnect is executed. This allows last minute updates'
47
+ * sync messages to be received by the subscription before it's closed.
48
+ */
49
+ disconnectDelay: number;
50
+ }
51
+ export declare 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: number;
58
+ configuration: Configuration;
59
+ pub: RedisInstance;
60
+ sub: RedisInstance;
61
+ instance: Hocuspocus;
62
+ redlock: Redlock;
63
+ locks: Map<string, Redlock.Lock>;
64
+ logger: Debugger;
65
+ constructor(configuration: Partial<Configuration>);
66
+ onConfigure({ instance }: onConfigurePayload): Promise<void>;
67
+ private getKey;
68
+ private pubKey;
69
+ private subKey;
70
+ private lockKey;
71
+ /**
72
+ * Once a document is laoded, subscribe to the channel in Redis.
73
+ */
74
+ afterLoadDocument({ documentName, document }: afterLoadDocumentPayload): Promise<unknown>;
75
+ /**
76
+ * Publish the first sync step through Redis.
77
+ */
78
+ private publishFirstSyncStep;
79
+ /**
80
+ * Let’s ask Redis who is connected already.
81
+ */
82
+ private requestAwarenessFromOtherInstances;
83
+ /**
84
+ * Before the document is stored, make sure to set a lock in Redis.
85
+ * That’s meant to avoid conflicts with other instances trying to store the document.
86
+ */
87
+ onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<unknown>;
88
+ /**
89
+ * Release the Redis lock, so other instances can store documents.
90
+ */
91
+ afterStoreDocument({ documentName }: afterStoreDocumentPayload): Promise<void>;
92
+ /**
93
+ * Handle awareness update messages received directly by this Hocuspocus instance.
94
+ */
95
+ onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<number>;
96
+ /**
97
+ * Handle incoming messages published on all subscribed document channels.
98
+ * Note that this will also include messages from ourselves as it is not possible
99
+ * in Redis to filter these.
100
+ */
101
+ private handleIncomingMessage;
102
+ /**
103
+ * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
104
+ */
105
+ onChange(data: onChangePayload): Promise<any>;
106
+ /**
107
+ * Make sure to *not* listen for further changes, when there’s
108
+ * noone connected anymore.
109
+ */
110
+ onDisconnect: ({ documentName }: onDisconnectPayload) => Promise<void>;
111
+ beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
112
+ /**
113
+ * Kill the Redlock connection immediately.
114
+ */
115
+ onDestroy(): Promise<void>;
116
+ }
@@ -1 +1 @@
1
- export * from './Redis';
1
+ export * from './Redis.js';
@@ -1,26 +1,26 @@
1
- import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
2
- import sqlite3 from 'sqlite3';
3
- export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
4
- export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
5
- export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
6
- export interface SQLiteConfiguration extends DatabaseConfiguration {
7
- /**
8
- * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
9
- * string for an anonymous disk-based database. Anonymous databases are not persisted and
10
- * when closing the database handle, their contents are lost.
11
- *
12
- * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
13
- */
14
- database: string;
15
- /**
16
- * The database schema to create.
17
- */
18
- schema: string;
19
- }
20
- export declare class SQLite extends Database {
21
- db?: sqlite3.Database;
22
- configuration: SQLiteConfiguration;
23
- constructor(configuration?: Partial<SQLiteConfiguration>);
24
- onConfigure(): Promise<void>;
25
- onListen(): Promise<void>;
26
- }
1
+ import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
2
+ import sqlite3 from 'sqlite3';
3
+ export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
4
+ export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
5
+ export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
6
+ export interface SQLiteConfiguration extends DatabaseConfiguration {
7
+ /**
8
+ * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
9
+ * string for an anonymous disk-based database. Anonymous databases are not persisted and
10
+ * when closing the database handle, their contents are lost.
11
+ *
12
+ * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
13
+ */
14
+ database: string;
15
+ /**
16
+ * The database schema to create.
17
+ */
18
+ schema: string;
19
+ }
20
+ export declare class SQLite extends Database {
21
+ db?: sqlite3.Database;
22
+ configuration: SQLiteConfiguration;
23
+ constructor(configuration?: Partial<SQLiteConfiguration>);
24
+ onConfigure(): Promise<void>;
25
+ onListen(): Promise<void>;
26
+ }
@@ -1 +1 @@
1
- export * from './SQLite';
1
+ export * from './SQLite.js';