@hocuspocus/extension-s3 3.2.4

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 (142) hide show
  1. package/README.md +167 -0
  2. package/dist/hocuspocus-s3.cjs +129 -0
  3. package/dist/hocuspocus-s3.cjs.map +1 -0
  4. package/dist/hocuspocus-s3.esm.js +127 -0
  5. package/dist/hocuspocus-s3.esm.js.map +1 -0
  6. package/dist/node_modules/@tiptap/pm/model/index.d.ts +1 -0
  7. package/dist/node_modules/@tiptap/pm/state/index.d.ts +1 -0
  8. package/dist/node_modules/@tiptap/pm/transform/index.d.ts +1 -0
  9. package/dist/node_modules/@tiptap/pm/view/index.d.ts +1 -0
  10. package/dist/packages/common/src/CloseEvents.d.ts +29 -0
  11. package/dist/packages/common/src/auth.d.ts +6 -0
  12. package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
  13. package/dist/packages/common/src/index.d.ts +4 -0
  14. package/dist/packages/common/src/types.d.ts +10 -0
  15. package/dist/packages/extension-database/src/Database.d.ts +30 -0
  16. package/dist/packages/extension-database/src/index.d.ts +1 -0
  17. package/dist/packages/extension-logger/src/Logger.d.ts +67 -0
  18. package/dist/packages/extension-logger/src/index.d.ts +1 -0
  19. package/dist/packages/extension-redis/src/Redis.d.ts +129 -0
  20. package/dist/packages/extension-redis/src/index.d.ts +1 -0
  21. package/dist/packages/extension-s3/src/S3.d.ts +44 -0
  22. package/dist/packages/extension-s3/src/index.d.ts +1 -0
  23. package/dist/packages/extension-sqlite/src/SQLite.d.ts +27 -0
  24. package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
  25. package/dist/packages/extension-throttle/src/index.d.ts +30 -0
  26. package/dist/packages/extension-webhook/src/index.d.ts +56 -0
  27. package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
  28. package/dist/packages/provider/src/HocuspocusProvider.d.ts +115 -0
  29. package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +114 -0
  30. package/dist/packages/provider/src/IncomingMessage.d.ts +17 -0
  31. package/dist/packages/provider/src/MessageReceiver.d.ts +12 -0
  32. package/dist/packages/provider/src/MessageSender.d.ts +9 -0
  33. package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
  34. package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +8 -0
  35. package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +9 -0
  36. package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +9 -0
  37. package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +9 -0
  38. package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +8 -0
  39. package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +9 -0
  40. package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +9 -0
  41. package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +8 -0
  42. package/dist/packages/provider/src/index.d.ts +3 -0
  43. package/dist/packages/provider/src/types.d.ts +92 -0
  44. package/dist/packages/server/src/ClientConnection.d.ts +63 -0
  45. package/dist/packages/server/src/Connection.d.ts +62 -0
  46. package/dist/packages/server/src/DirectConnection.d.ts +14 -0
  47. package/dist/packages/server/src/Document.d.ts +89 -0
  48. package/dist/packages/server/src/Hocuspocus.d.ts +77 -0
  49. package/dist/packages/server/src/IncomingMessage.d.ts +25 -0
  50. package/dist/packages/server/src/MessageReceiver.d.ts +11 -0
  51. package/dist/packages/server/src/OutgoingMessage.d.ts +22 -0
  52. package/dist/packages/server/src/Server.d.ts +32 -0
  53. package/dist/packages/server/src/index.d.ts +9 -0
  54. package/dist/packages/server/src/types.d.ts +328 -0
  55. package/dist/packages/server/src/util/debounce.d.ts +5 -0
  56. package/dist/packages/server/src/util/getParameters.d.ts +6 -0
  57. package/dist/packages/transformer/src/Prosemirror.d.ts +11 -0
  58. package/dist/packages/transformer/src/Tiptap.d.ts +10 -0
  59. package/dist/packages/transformer/src/index.d.ts +3 -0
  60. package/dist/packages/transformer/src/types.d.ts +5 -0
  61. package/dist/playground/backend/src/default.d.ts +1 -0
  62. package/dist/playground/backend/src/deno.d.ts +1 -0
  63. package/dist/playground/backend/src/express.d.ts +1 -0
  64. package/dist/playground/backend/src/hono.d.ts +1 -0
  65. package/dist/playground/backend/src/koa.d.ts +1 -0
  66. package/dist/playground/backend/src/load-document.d.ts +1 -0
  67. package/dist/playground/backend/src/redis.d.ts +1 -0
  68. package/dist/playground/backend/src/s3-redis.d.ts +1 -0
  69. package/dist/playground/backend/src/s3.d.ts +1 -0
  70. package/dist/playground/backend/src/slow.d.ts +1 -0
  71. package/dist/playground/backend/src/tiptapcollab.d.ts +1 -0
  72. package/dist/playground/backend/src/webhook.d.ts +1 -0
  73. package/dist/playground/frontend/app/SocketContext1.d.ts +2 -0
  74. package/dist/playground/frontend/app/SocketContext2.d.ts +2 -0
  75. package/dist/playground/frontend/next.config.d.ts +3 -0
  76. package/dist/tests/extension-database/fetch.d.ts +1 -0
  77. package/dist/tests/extension-logger/onListen.d.ts +1 -0
  78. package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -0
  79. package/dist/tests/extension-redis/onChange.d.ts +1 -0
  80. package/dist/tests/extension-redis/onStateless.d.ts +1 -0
  81. package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -0
  82. package/dist/tests/extension-s3/fetch.d.ts +1 -0
  83. package/dist/tests/extension-throttle/banning.d.ts +1 -0
  84. package/dist/tests/extension-throttle/configuration.d.ts +1 -0
  85. package/dist/tests/provider/hasUnsyncedChanges.d.ts +1 -0
  86. package/dist/tests/provider/observe.d.ts +1 -0
  87. package/dist/tests/provider/observeDeep.d.ts +1 -0
  88. package/dist/tests/provider/onAuthenticated.d.ts +1 -0
  89. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
  90. package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
  91. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
  92. package/dist/tests/provider/onClose.d.ts +1 -0
  93. package/dist/tests/provider/onConnect.d.ts +1 -0
  94. package/dist/tests/provider/onDisconnect.d.ts +1 -0
  95. package/dist/tests/provider/onMessage.d.ts +1 -0
  96. package/dist/tests/provider/onOpen.d.ts +1 -0
  97. package/dist/tests/provider/onStateless.d.ts +1 -0
  98. package/dist/tests/provider/onSynced.d.ts +1 -0
  99. package/dist/tests/providerwebsocket/configuration.d.ts +1 -0
  100. package/dist/tests/server/address.d.ts +1 -0
  101. package/dist/tests/server/afterLoadDocument.d.ts +1 -0
  102. package/dist/tests/server/afterStoreDocument.d.ts +1 -0
  103. package/dist/tests/server/afterUnloadDocument.d.ts +1 -0
  104. package/dist/tests/server/beforeBroadcastStateless.d.ts +1 -0
  105. package/dist/tests/server/beforeHandleMessage.d.ts +1 -0
  106. package/dist/tests/server/beforeSync.d.ts +1 -0
  107. package/dist/tests/server/beforeUnloadDocument.d.ts +1 -0
  108. package/dist/tests/server/closeConnections.d.ts +1 -0
  109. package/dist/tests/server/getConnectionsCount.d.ts +1 -0
  110. package/dist/tests/server/getDocumentsCount.d.ts +1 -0
  111. package/dist/tests/server/listen.d.ts +1 -0
  112. package/dist/tests/server/onAuthenticate.d.ts +1 -0
  113. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
  114. package/dist/tests/server/onChange.d.ts +1 -0
  115. package/dist/tests/server/onClose.d.ts +1 -0
  116. package/dist/tests/server/onConfigure.d.ts +1 -0
  117. package/dist/tests/server/onConnect.d.ts +1 -0
  118. package/dist/tests/server/onDestroy.d.ts +1 -0
  119. package/dist/tests/server/onDisconnect.d.ts +1 -0
  120. package/dist/tests/server/onListen.d.ts +1 -0
  121. package/dist/tests/server/onLoadDocument.d.ts +1 -0
  122. package/dist/tests/server/onRequest.d.ts +1 -0
  123. package/dist/tests/server/onStateless.d.ts +1 -0
  124. package/dist/tests/server/onStoreDocument.d.ts +1 -0
  125. package/dist/tests/server/onUpgrade.d.ts +1 -0
  126. package/dist/tests/server/openDirectConnection.d.ts +1 -0
  127. package/dist/tests/server/websocketError.d.ts +1 -0
  128. package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
  129. package/dist/tests/utils/createDirectory.d.ts +1 -0
  130. package/dist/tests/utils/flushRedis.d.ts +1 -0
  131. package/dist/tests/utils/index.d.ts +9 -0
  132. package/dist/tests/utils/newHocuspocus.d.ts +2 -0
  133. package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
  134. package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +4 -0
  135. package/dist/tests/utils/randomInteger.d.ts +1 -0
  136. package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
  137. package/dist/tests/utils/removeDirectory.d.ts +1 -0
  138. package/dist/tests/utils/retryableAssertion.d.ts +2 -0
  139. package/dist/tests/utils/sleep.d.ts +1 -0
  140. package/package.json +39 -0
  141. package/src/S3.ts +178 -0
  142. package/src/index.ts +1 -0
@@ -0,0 +1,129 @@
1
+ import type { Extension, Hocuspocus, afterLoadDocumentPayload, afterStoreDocumentPayload, beforeBroadcastStatelessPayload, onAwarenessUpdatePayload, onChangePayload, onConfigurePayload, onDisconnectPayload, onStoreDocumentPayload } from "@hocuspocus/server";
2
+ import { Redlock, type ExecutionResult, type Lock } from '@sesamecare-oss/redlock';
3
+ import type { Cluster, ClusterNode, ClusterOptions, RedisOptions } from "ioredis";
4
+ import RedisClient from "ioredis";
5
+ export type RedisInstance = RedisClient | Cluster;
6
+ export interface Configuration {
7
+ /**
8
+ * Redis port
9
+ */
10
+ port: number;
11
+ /**
12
+ * Redis host
13
+ */
14
+ host: string;
15
+ /**
16
+ * Redis Cluster
17
+ */
18
+ nodes?: ClusterNode[];
19
+ /**
20
+ * Duplicate from an existed Redis instance
21
+ */
22
+ redis?: RedisInstance;
23
+ /**
24
+ * Redis instance creator
25
+ */
26
+ createClient?: () => RedisInstance;
27
+ /**
28
+ * Options passed directly to Redis constructor
29
+ *
30
+ * https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
31
+ */
32
+ options?: ClusterOptions | RedisOptions;
33
+ /**
34
+ * An unique instance name, required to filter messages in Redis.
35
+ * If none is provided an unique id is generated.
36
+ */
37
+ identifier: string;
38
+ /**
39
+ * Namespace for Redis keys, if none is provided 'hocuspocus' is used
40
+ */
41
+ prefix: string;
42
+ /**
43
+ * The maximum time for the Redis lock in ms (in case it can’t be released).
44
+ */
45
+ lockTimeout: number;
46
+ /**
47
+ * A delay before onDisconnect is executed. This allows last minute updates'
48
+ * sync messages to be received by the subscription before it's closed.
49
+ */
50
+ disconnectDelay: number;
51
+ }
52
+ export declare class Redis implements Extension {
53
+ /**
54
+ * Make sure to give that extension a higher priority, so
55
+ * the `onStoreDocument` hook is able to intercept the chain,
56
+ * before documents are stored to the database.
57
+ */
58
+ priority: number;
59
+ configuration: Configuration;
60
+ redisTransactionOrigin: string;
61
+ pub: RedisInstance;
62
+ sub: RedisInstance;
63
+ instance: Hocuspocus;
64
+ redlock: Redlock;
65
+ locks: Map<string, {
66
+ lock: Lock;
67
+ release?: Promise<ExecutionResult>;
68
+ }>;
69
+ messagePrefix: Buffer;
70
+ /**
71
+ * When we have a high frequency of updates to a document we don't need tons of setTimeouts
72
+ * piling up, so we'll track them to keep it to the most recent per document.
73
+ */
74
+ private pendingDisconnects;
75
+ private pendingAfterStoreDocumentResolves;
76
+ constructor(configuration: Partial<Configuration>);
77
+ onConfigure({ instance }: onConfigurePayload): Promise<void>;
78
+ private getKey;
79
+ private pubKey;
80
+ private subKey;
81
+ private lockKey;
82
+ private encodeMessage;
83
+ private decodeMessage;
84
+ /**
85
+ * Once a document is loaded, subscribe to the channel in Redis.
86
+ */
87
+ afterLoadDocument({ documentName, document, }: afterLoadDocumentPayload): Promise<unknown>;
88
+ /**
89
+ * Publish the first sync step through Redis.
90
+ */
91
+ private publishFirstSyncStep;
92
+ /**
93
+ * Let’s ask Redis who is connected already.
94
+ */
95
+ private requestAwarenessFromOtherInstances;
96
+ /**
97
+ * Before the document is stored, make sure to set a lock in Redis.
98
+ * That’s meant to avoid conflicts with other instances trying to store the document.
99
+ */
100
+ onStoreDocument({ documentName }: onStoreDocumentPayload): Promise<void>;
101
+ /**
102
+ * Release the Redis lock, so other instances can store documents.
103
+ */
104
+ afterStoreDocument({ documentName, socketId }: afterStoreDocumentPayload): Promise<void>;
105
+ /**
106
+ * Handle awareness update messages received directly by this Hocuspocus instance.
107
+ */
108
+ onAwarenessUpdate({ documentName, awareness, added, updated, removed, }: onAwarenessUpdatePayload): Promise<number>;
109
+ /**
110
+ * Handle incoming messages published on subscribed document channels.
111
+ * Note that this will also include messages from ourselves as it is not possible
112
+ * in Redis to filter these.
113
+ */
114
+ private handleIncomingMessage;
115
+ /**
116
+ * if the ydoc changed, we'll need to inform other Hocuspocus servers about it.
117
+ */
118
+ onChange(data: onChangePayload): Promise<any>;
119
+ /**
120
+ * Make sure to *not* listen for further changes, when there’s
121
+ * no one connected anymore.
122
+ */
123
+ onDisconnect: ({ documentName }: onDisconnectPayload) => Promise<void>;
124
+ beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
125
+ /**
126
+ * Kill the Redlock connection immediately.
127
+ */
128
+ onDestroy(): Promise<void>;
129
+ }
@@ -0,0 +1 @@
1
+ export * from "./Redis.ts";
@@ -0,0 +1,44 @@
1
+ import type { DatabaseConfiguration } from "@hocuspocus/extension-database";
2
+ import { Database } from "@hocuspocus/extension-database";
3
+ import { S3Client } from "@aws-sdk/client-s3";
4
+ export interface S3Configuration extends DatabaseConfiguration {
5
+ /**
6
+ * AWS S3 region
7
+ */
8
+ region?: string;
9
+ /**
10
+ * S3 bucket name
11
+ */
12
+ bucket: string;
13
+ /**
14
+ * S3 key prefix for documents (optional)
15
+ */
16
+ prefix?: string;
17
+ /**
18
+ * AWS credentials
19
+ */
20
+ credentials?: {
21
+ accessKeyId: string;
22
+ secretAccessKey: string;
23
+ };
24
+ /**
25
+ * S3 endpoint URL (for S3-compatible services like MinIO)
26
+ */
27
+ endpoint?: string;
28
+ /**
29
+ * Force path style URLs (required for MinIO)
30
+ */
31
+ forcePathStyle?: boolean;
32
+ /**
33
+ * Custom S3 client
34
+ */
35
+ s3Client?: S3Client;
36
+ }
37
+ export declare class S3 extends Database {
38
+ private s3Client?;
39
+ configuration: S3Configuration;
40
+ constructor(configuration: Partial<S3Configuration>);
41
+ private getObjectKey;
42
+ onConfigure(): Promise<void>;
43
+ onListen(): Promise<void>;
44
+ }
@@ -0,0 +1 @@
1
+ export * from "./S3.ts";
@@ -0,0 +1,27 @@
1
+ import type { DatabaseConfiguration } from "@hocuspocus/extension-database";
2
+ import { Database } from "@hocuspocus/extension-database";
3
+ import sqlite3 from "sqlite3";
4
+ 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)";
5
+ export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
6
+ export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
7
+ export interface SQLiteConfiguration extends DatabaseConfiguration {
8
+ /**
9
+ * Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
10
+ * string for an anonymous disk-based database. Anonymous databases are not persisted and
11
+ * when closing the database handle, their contents are lost.
12
+ *
13
+ * https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
14
+ */
15
+ database: string;
16
+ /**
17
+ * The database schema to create.
18
+ */
19
+ schema: string;
20
+ }
21
+ export declare class SQLite extends Database {
22
+ db?: sqlite3.Database;
23
+ configuration: SQLiteConfiguration;
24
+ constructor(configuration?: Partial<SQLiteConfiguration>);
25
+ onConfigure(): Promise<void>;
26
+ onListen(): Promise<void>;
27
+ }
@@ -0,0 +1 @@
1
+ export * from "./SQLite.ts";
@@ -0,0 +1,30 @@
1
+ import type { Extension, onConnectPayload } from "@hocuspocus/server";
2
+ export interface ThrottleConfiguration {
3
+ throttle: number | null | false;
4
+ consideredSeconds: number;
5
+ banTime: number;
6
+ cleanupInterval: number;
7
+ }
8
+ export declare class Throttle implements Extension {
9
+ configuration: ThrottleConfiguration;
10
+ connectionsByIp: Map<string, Array<number>>;
11
+ bannedIps: Map<string, number>;
12
+ cleanupInterval?: NodeJS.Timeout;
13
+ /**
14
+ * Constructor
15
+ */
16
+ constructor(configuration?: Partial<ThrottleConfiguration>);
17
+ onDestroy(): Promise<void>;
18
+ clearMaps(): void;
19
+ isBanned(ip: string): boolean;
20
+ /**
21
+ * Throttle requests
22
+ * @private
23
+ */
24
+ private throttle;
25
+ /**
26
+ * onConnect hook
27
+ * @param data
28
+ */
29
+ onConnect(data: onConnectPayload): Promise<any>;
30
+ }
@@ -0,0 +1,56 @@
1
+ import type { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from "@hocuspocus/server";
2
+ import type { Doc } from "yjs";
3
+ import type { Transformer } from "@hocuspocus/transformer";
4
+ export declare enum Events {
5
+ onChange = "change",
6
+ onConnect = "connect",
7
+ onCreate = "create",
8
+ onDisconnect = "disconnect"
9
+ }
10
+ export interface Configuration {
11
+ debounce: number | false | null;
12
+ debounceMaxWait: number;
13
+ secret: string;
14
+ transformer: Transformer | {
15
+ toYdoc: (document: any) => Doc;
16
+ fromYdoc: (document: Doc) => any;
17
+ };
18
+ url: string;
19
+ events: Array<Events>;
20
+ }
21
+ export declare class Webhook implements Extension {
22
+ configuration: Configuration;
23
+ debounced: Map<string, {
24
+ timeout: NodeJS.Timeout;
25
+ start: number;
26
+ }>;
27
+ /**
28
+ * Constructor
29
+ */
30
+ constructor(configuration?: Partial<Configuration>);
31
+ /**
32
+ * Create a signature for the response body
33
+ */
34
+ createSignature(body: string): string;
35
+ /**
36
+ * debounce the given function, using the given identifier
37
+ */
38
+ debounce(id: string, func: Function): void;
39
+ /**
40
+ * Send a request to the given url containing the given data
41
+ */
42
+ sendRequest(event: Events, payload: any): Promise<import("axios").AxiosResponse<any, any, {}>>;
43
+ /**
44
+ * onChange hook
45
+ */
46
+ onChange(data: onChangePayload): Promise<void>;
47
+ /**
48
+ * onLoadDocument hook
49
+ */
50
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
51
+ /**
52
+ * onConnect hook
53
+ */
54
+ onConnect(data: onConnectPayload): Promise<any>;
55
+ onDisconnect(data: onDisconnectPayload): Promise<void>;
56
+ }
@@ -0,0 +1,9 @@
1
+ export default class EventEmitter {
2
+ callbacks: {
3
+ [key: string]: Function[];
4
+ };
5
+ on(event: string, fn: Function): this;
6
+ protected emit(event: string, ...args: any): this;
7
+ off(event: string, fn?: Function): this;
8
+ removeAllListeners(): void;
9
+ }
@@ -0,0 +1,115 @@
1
+ import type { Event, MessageEvent } from "ws";
2
+ import { Awareness } from "y-protocols/awareness";
3
+ import * as Y from "yjs";
4
+ import EventEmitter from "./EventEmitter.ts";
5
+ import type { CompleteHocuspocusProviderWebsocketConfiguration } from "./HocuspocusProviderWebsocket.ts";
6
+ import { HocuspocusProviderWebsocket } from "./HocuspocusProviderWebsocket.ts";
7
+ import type { ConstructableOutgoingMessage, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, onUnsyncedChangesParameters } from "./types.ts";
8
+ export type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, "name">> & Partial<CompleteHocuspocusProviderConfiguration> & (Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> | Required<Pick<CompleteHocuspocusProviderConfiguration, "websocketProvider">>);
9
+ export interface CompleteHocuspocusProviderConfiguration {
10
+ /**
11
+ * The identifier/name of your document
12
+ */
13
+ name: string;
14
+ /**
15
+ * The actual Y.js document
16
+ */
17
+ document: Y.Doc;
18
+ /**
19
+ * An Awareness instance to keep the presence state of all clients.
20
+ *
21
+ * You can disable sharing awareness information by passing `null`.
22
+ * Note that having no awareness information shared across all connections will break our ping checks
23
+ * and thus trigger reconnects. You should always have at least one Provider with enabled awareness per
24
+ * socket connection, or ensure that the Provider receives messages before running into `HocuspocusProviderWebsocket.messageReconnectTimeout`.
25
+ */
26
+ awareness: Awareness | null;
27
+ /**
28
+ * A token that’s sent to the backend for authentication purposes.
29
+ */
30
+ token: string | (() => string) | (() => Promise<string>) | null;
31
+ /**
32
+ * Hocuspocus websocket provider
33
+ */
34
+ websocketProvider: HocuspocusProviderWebsocket;
35
+ /**
36
+ * Force syncing the document in the defined interval.
37
+ */
38
+ forceSyncInterval: false | number;
39
+ onAuthenticated: (data: onAuthenticatedParameters) => void;
40
+ onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
41
+ onOpen: (data: onOpenParameters) => void;
42
+ onConnect: () => void;
43
+ onStatus: (data: onStatusParameters) => void;
44
+ onMessage: (data: onMessageParameters) => void;
45
+ onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
46
+ onSynced: (data: onSyncedParameters) => void;
47
+ onDisconnect: (data: onDisconnectParameters) => void;
48
+ onClose: (data: onCloseParameters) => void;
49
+ onDestroy: () => void;
50
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
51
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
52
+ onStateless: (data: onStatelessParameters) => void;
53
+ onUnsyncedChanges: (data: onUnsyncedChangesParameters) => void;
54
+ }
55
+ export declare class AwarenessError extends Error {
56
+ code: number;
57
+ }
58
+ export declare class HocuspocusProvider extends EventEmitter {
59
+ configuration: CompleteHocuspocusProviderConfiguration;
60
+ isSynced: boolean;
61
+ unsyncedChanges: number;
62
+ isAuthenticated: boolean;
63
+ authorizedScope: string | undefined;
64
+ manageSocket: boolean;
65
+ private _isAttached;
66
+ intervals: any;
67
+ constructor(configuration: HocuspocusProviderConfiguration);
68
+ boundDocumentUpdateHandler: (update: Uint8Array, origin: any) => void;
69
+ boundAwarenessUpdateHandler: ({ added, updated, removed }: any, origin: any) => void;
70
+ boundPageHide: () => void;
71
+ boundOnOpen: (event: Event) => Promise<void>;
72
+ boundOnClose: () => void;
73
+ forwardConnect: () => this;
74
+ forwardStatus: (e: onStatusParameters) => this;
75
+ forwardClose: (e: onCloseParameters) => this;
76
+ forwardDisconnect: (e: onDisconnectParameters) => this;
77
+ forwardDestroy: () => this;
78
+ setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
79
+ get document(): Y.Doc;
80
+ get isAttached(): boolean;
81
+ get awareness(): Awareness | null;
82
+ get hasUnsyncedChanges(): boolean;
83
+ private resetUnsyncedChanges;
84
+ incrementUnsyncedChanges(): void;
85
+ decrementUnsyncedChanges(): void;
86
+ forceSync(): void;
87
+ pageHide(): void;
88
+ registerEventListeners(): void;
89
+ sendStateless(payload: string): void;
90
+ documentUpdateHandler(update: Uint8Array, origin: any): void;
91
+ awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
92
+ /**
93
+ * Indicates whether a first handshake with the server has been established
94
+ *
95
+ * Note: this does not mean all updates from the client have been persisted to the backend. For this,
96
+ * use `hasUnsyncedChanges`.
97
+ */
98
+ get synced(): boolean;
99
+ set synced(state: boolean);
100
+ receiveStateless(payload: string): void;
101
+ connect(): Promise<unknown>;
102
+ disconnect(): void;
103
+ onOpen(event: Event): Promise<void>;
104
+ getToken(): Promise<string | null>;
105
+ startSync(): void;
106
+ send(message: ConstructableOutgoingMessage, args: any): void;
107
+ onMessage(event: MessageEvent): void;
108
+ onClose(): void;
109
+ destroy(): void;
110
+ detach(): void;
111
+ attach(): void;
112
+ permissionDeniedHandler(reason: string): void;
113
+ authenticatedHandler(scope: string): void;
114
+ setAwarenessField(key: string, value: any): void;
115
+ }
@@ -0,0 +1,114 @@
1
+ import type { Event, MessageEvent } from "ws";
2
+ import EventEmitter from "./EventEmitter.ts";
3
+ import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
4
+ import { WebSocketStatus, type onAwarenessChangeParameters, type onAwarenessUpdateParameters, type onCloseParameters, type onDisconnectParameters, type onMessageParameters, type onOpenParameters, type onOutgoingMessageParameters, type onStatusParameters } from "./types.ts";
5
+ export type HocuspocusWebSocket = WebSocket & {
6
+ identifier: string;
7
+ };
8
+ export type HocusPocusWebSocket = HocuspocusWebSocket;
9
+ export type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, "url">> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
10
+ export interface CompleteHocuspocusProviderWebsocketConfiguration {
11
+ /**
12
+ * Whether to connect automatically when creating the provider instance. Default=true
13
+ */
14
+ autoConnect: boolean;
15
+ /**
16
+ * URL of your @hocuspocus/server instance
17
+ */
18
+ url: string;
19
+ /**
20
+ * An optional WebSocket polyfill, for example for Node.js
21
+ */
22
+ WebSocketPolyfill: any;
23
+ /**
24
+ * Disconnect when no message is received for the defined amount of milliseconds.
25
+ */
26
+ messageReconnectTimeout: number;
27
+ /**
28
+ * The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
29
+ */
30
+ delay: number;
31
+ /**
32
+ * The initialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
33
+ */
34
+ initialDelay: number;
35
+ /**
36
+ * The factor option is used to grow the delay exponentially.
37
+ */
38
+ factor: number;
39
+ /**
40
+ * The maximum number of attempts or 0 if there is no limit on number of attempts.
41
+ */
42
+ maxAttempts: number;
43
+ /**
44
+ * minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
45
+ */
46
+ minDelay: number;
47
+ /**
48
+ * The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
49
+ */
50
+ maxDelay: number;
51
+ /**
52
+ * If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
53
+ */
54
+ jitter: boolean;
55
+ /**
56
+ * A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
57
+ */
58
+ timeout: number;
59
+ handleTimeout: (() => Promise<unknown>) | null;
60
+ onOpen: (data: onOpenParameters) => void;
61
+ onConnect: () => void;
62
+ onMessage: (data: onMessageParameters) => void;
63
+ onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
64
+ onStatus: (data: onStatusParameters) => void;
65
+ onDisconnect: (data: onDisconnectParameters) => void;
66
+ onClose: (data: onCloseParameters) => void;
67
+ onDestroy: () => void;
68
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
69
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
70
+ /**
71
+ * Map of attached providers keyed by documentName.
72
+ */
73
+ providerMap: Map<string, HocuspocusProvider>;
74
+ }
75
+ export declare class HocuspocusProviderWebsocket extends EventEmitter {
76
+ private messageQueue;
77
+ configuration: CompleteHocuspocusProviderWebsocketConfiguration;
78
+ webSocket: HocusPocusWebSocket | null;
79
+ webSocketHandlers: {
80
+ [key: string]: any;
81
+ };
82
+ shouldConnect: boolean;
83
+ status: WebSocketStatus;
84
+ lastMessageReceived: number;
85
+ identifier: number;
86
+ intervals: any;
87
+ connectionAttempt: {
88
+ resolve: (value?: any) => void;
89
+ reject: (reason?: any) => void;
90
+ } | null;
91
+ constructor(configuration: HocuspocusProviderWebsocketConfiguration);
92
+ receivedOnOpenPayload?: Event | undefined;
93
+ onOpen(event: Event): Promise<void>;
94
+ attach(provider: HocuspocusProvider): void;
95
+ detach(provider: HocuspocusProvider): void;
96
+ setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
97
+ cancelWebsocketRetry?: () => void;
98
+ connect(): Promise<unknown>;
99
+ attachWebSocketListeners(ws: HocusPocusWebSocket, reject: Function): void;
100
+ cleanupWebSocket(): void;
101
+ createWebSocketConnection(): Promise<unknown>;
102
+ onMessage(event: MessageEvent): void;
103
+ resolveConnectionAttempt(): void;
104
+ stopConnectionAttempt(): void;
105
+ rejectConnectionAttempt(): void;
106
+ closeTries: number;
107
+ checkConnection(): void;
108
+ get serverUrl(): string;
109
+ get url(): string;
110
+ disconnect(): void;
111
+ send(message: any): void;
112
+ onClose({ event }: onCloseParameters): void;
113
+ destroy(): void;
114
+ }
@@ -0,0 +1,17 @@
1
+ import type { Decoder } from "lib0/decoding";
2
+ import type { Encoder } from "lib0/encoding";
3
+ import type { MessageType } from "./types.ts";
4
+ export declare class IncomingMessage {
5
+ data: any;
6
+ encoder: Encoder;
7
+ decoder: Decoder;
8
+ constructor(data: any);
9
+ peekVarString(): string;
10
+ readVarUint(): MessageType;
11
+ readVarString(): string;
12
+ readVarUint8Array(): Uint8Array<ArrayBufferLike>;
13
+ writeVarUint(type: MessageType): void;
14
+ writeVarString(string: string): void;
15
+ writeVarUint8Array(data: Uint8Array): void;
16
+ length(): number;
17
+ }
@@ -0,0 +1,12 @@
1
+ import type { HocuspocusProvider } from "./HocuspocusProvider.ts";
2
+ import type { IncomingMessage } from "./IncomingMessage.ts";
3
+ export declare class MessageReceiver {
4
+ message: IncomingMessage;
5
+ constructor(message: IncomingMessage);
6
+ apply(provider: HocuspocusProvider, emitSynced: boolean): void;
7
+ private applySyncMessage;
8
+ applySyncStatusMessage(provider: HocuspocusProvider, applied: boolean): void;
9
+ private applyAwarenessMessage;
10
+ private applyAuthMessage;
11
+ private applyQueryAwarenessMessage;
12
+ }
@@ -0,0 +1,9 @@
1
+ import type { Encoder } from "lib0/encoding";
2
+ import type { ConstructableOutgoingMessage } from "./types.ts";
3
+ export declare class MessageSender {
4
+ encoder: Encoder;
5
+ message: any;
6
+ constructor(Message: ConstructableOutgoingMessage, args?: any);
7
+ create(): Uint8Array<ArrayBufferLike>;
8
+ send(webSocket: any): void;
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { Encoder } from "lib0/encoding";
2
+ import type { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from "./types.ts";
3
+ export declare class OutgoingMessage implements OutgoingMessageInterface {
4
+ encoder: Encoder;
5
+ type?: MessageType;
6
+ constructor();
7
+ get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
8
+ toUint8Array(): Uint8Array<ArrayBufferLike>;
9
+ }
@@ -0,0 +1,8 @@
1
+ import type { OutgoingMessageArguments } from "../types.ts";
2
+ import { MessageType } from "../types.ts";
3
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
4
+ export declare class AuthenticationMessage extends OutgoingMessage {
5
+ type: MessageType;
6
+ description: string;
7
+ get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
8
+ }
@@ -0,0 +1,9 @@
1
+ import * as encoding from "lib0/encoding";
2
+ import type { OutgoingMessageArguments } from "../types.ts";
3
+ import { MessageType } from "../types.ts";
4
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
5
+ export declare class AwarenessMessage extends OutgoingMessage {
6
+ type: MessageType;
7
+ description: string;
8
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
9
+ }
@@ -0,0 +1,9 @@
1
+ import * as encoding from "lib0/encoding";
2
+ import type { OutgoingMessageArguments } from "../types.ts";
3
+ import { MessageType } from "../types.ts";
4
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
5
+ export declare class CloseMessage extends OutgoingMessage {
6
+ type: MessageType;
7
+ description: string;
8
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
9
+ }
@@ -0,0 +1,9 @@
1
+ import * as encoding from "lib0/encoding";
2
+ import type { OutgoingMessageArguments } from "../types.ts";
3
+ import { MessageType } from "../types.ts";
4
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
5
+ export declare class QueryAwarenessMessage extends OutgoingMessage {
6
+ type: MessageType;
7
+ description: string;
8
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
9
+ }
@@ -0,0 +1,8 @@
1
+ import type { OutgoingMessageArguments } from "../types.ts";
2
+ import { MessageType } from "../types.ts";
3
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
4
+ export declare class StatelessMessage extends OutgoingMessage {
5
+ type: MessageType;
6
+ description: string;
7
+ get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
8
+ }
@@ -0,0 +1,9 @@
1
+ import * as encoding from "lib0/encoding";
2
+ import type { OutgoingMessageArguments } from "../types.ts";
3
+ import { MessageType } from "../types.ts";
4
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
5
+ export declare class SyncStepOneMessage extends OutgoingMessage {
6
+ type: MessageType;
7
+ description: string;
8
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
9
+ }
@@ -0,0 +1,9 @@
1
+ import * as encoding from "lib0/encoding";
2
+ import type { OutgoingMessageArguments } from "../types.ts";
3
+ import { MessageType } from "../types.ts";
4
+ import { OutgoingMessage } from "../OutgoingMessage.ts";
5
+ export declare class SyncStepTwoMessage extends OutgoingMessage {
6
+ type: MessageType;
7
+ description: string;
8
+ get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
9
+ }