@hocuspocus/extension-sqlite 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (93) hide show
  1. package/README.md +1 -1
  2. package/dist/hocuspocus-sqlite.cjs +29 -20
  3. package/dist/hocuspocus-sqlite.cjs.map +1 -1
  4. package/dist/hocuspocus-sqlite.esm.js +26 -20
  5. package/dist/hocuspocus-sqlite.esm.js.map +1 -1
  6. package/dist/packages/common/src/CloseEvents.d.ts +23 -0
  7. package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
  8. package/dist/packages/common/src/index.d.ts +3 -0
  9. package/dist/packages/common/src/types.d.ts +10 -0
  10. package/dist/packages/extension-database/src/Database.d.ts +5 -11
  11. package/dist/packages/extension-logger/src/Logger.d.ts +5 -0
  12. package/dist/packages/extension-monitor/src/Collector.d.ts +2 -3
  13. package/dist/packages/extension-monitor/src/index.d.ts +2 -2
  14. package/dist/packages/extension-redis/src/Redis.d.ts +91 -9
  15. package/dist/packages/extension-redis/src/index.d.ts +0 -1
  16. package/dist/packages/extension-sqlite/src/SQLite.d.ts +4 -4
  17. package/dist/packages/extension-throttle/src/index.d.ts +6 -2
  18. package/dist/packages/extension-webhook/src/index.d.ts +1 -2
  19. package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
  20. package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +4 -3
  21. package/dist/packages/provider/src/HocuspocusProvider.d.ts +30 -26
  22. package/dist/packages/provider/src/index.d.ts +0 -1
  23. package/dist/packages/provider/src/types.d.ts +43 -0
  24. package/dist/packages/server/src/Connection.d.ts +12 -5
  25. package/dist/packages/server/src/Debugger.d.ts +1 -2
  26. package/dist/packages/server/src/Document.d.ts +9 -5
  27. package/dist/packages/server/src/Hocuspocus.d.ts +37 -15
  28. package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
  29. package/dist/packages/server/src/OutgoingMessage.d.ts +2 -0
  30. package/dist/packages/server/src/index.d.ts +6 -0
  31. package/dist/packages/server/src/types.d.ts +115 -38
  32. package/dist/tests/extension-database/fetch.d.ts +1 -0
  33. package/dist/tests/extension-logger/onListen.d.ts +1 -0
  34. package/dist/tests/extension-redis/closeConnections.d.ts +1 -0
  35. package/dist/tests/extension-redis/getConnectionCount.d.ts +1 -0
  36. package/dist/tests/extension-redis/getDocumentsCount.d.ts +1 -0
  37. package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -0
  38. package/dist/tests/extension-redis/onChange.d.ts +1 -0
  39. package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -0
  40. package/dist/tests/extension-throttle/configuration.d.ts +1 -0
  41. package/dist/tests/provider/configuration.d.ts +1 -0
  42. package/dist/tests/provider/observe.d.ts +1 -0
  43. package/dist/tests/provider/observeDeep.d.ts +1 -0
  44. package/dist/tests/provider/onAuthenticated.d.ts +1 -0
  45. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
  46. package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
  47. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
  48. package/dist/tests/provider/onClose.d.ts +1 -0
  49. package/dist/tests/provider/onConnect.d.ts +1 -0
  50. package/dist/tests/provider/onDisconnect.d.ts +1 -0
  51. package/dist/tests/provider/onMessage.d.ts +1 -0
  52. package/dist/tests/provider/onOpen.d.ts +1 -0
  53. package/dist/tests/provider/onSynced.d.ts +1 -0
  54. package/dist/tests/server/address.d.ts +1 -0
  55. package/dist/tests/server/afterStoreDocument.d.ts +1 -0
  56. package/dist/tests/server/closeConnections.d.ts +1 -0
  57. package/dist/tests/server/getConnectionsCount.d.ts +1 -0
  58. package/dist/tests/server/getDocumentName.d.ts +1 -0
  59. package/dist/tests/server/getDocumentsCount.d.ts +1 -0
  60. package/dist/tests/server/getMessageLogs.d.ts +1 -0
  61. package/dist/tests/server/listen.d.ts +1 -0
  62. package/dist/tests/server/onAuthenticate.d.ts +1 -0
  63. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
  64. package/dist/tests/server/onChange.d.ts +1 -0
  65. package/dist/tests/server/onConfigure.d.ts +1 -0
  66. package/dist/tests/server/onConnect.d.ts +1 -0
  67. package/dist/tests/server/onDestroy.d.ts +1 -0
  68. package/dist/tests/server/onDisconnect.d.ts +1 -0
  69. package/dist/tests/server/onListen.d.ts +1 -0
  70. package/dist/tests/server/onLoadDocument.d.ts +1 -0
  71. package/dist/tests/server/onRequest.d.ts +1 -0
  72. package/dist/tests/server/onStoreDocument.d.ts +1 -0
  73. package/dist/tests/server/onUpgrade.d.ts +1 -0
  74. package/dist/tests/server/requiresAuthentication.d.ts +1 -0
  75. package/dist/tests/server/websocketError.d.ts +1 -0
  76. package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
  77. package/dist/tests/utils/createDirectory.d.ts +1 -0
  78. package/dist/tests/utils/flushRedis.d.ts +1 -0
  79. package/dist/tests/utils/index.d.ts +8 -0
  80. package/dist/tests/utils/newHocuspocus.d.ts +2 -0
  81. package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
  82. package/dist/tests/utils/randomInteger.d.ts +1 -0
  83. package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
  84. package/dist/tests/utils/removeDirectory.d.ts +1 -0
  85. package/dist/tests/utils/retryableAssertion.d.ts +2 -0
  86. package/dist/tests/utils/sleep.d.ts +1 -0
  87. package/package.json +7 -7
  88. package/src/SQLite.ts +29 -21
  89. package/dist/packages/extension-redis/src/RedisCluster.d.ts +0 -4
  90. package/dist/packages/extension-rocksdb/src/index.d.ts +0 -22
  91. package/dist/packages/provider/src/utils/awarenessStatesToArray.d.ts +0 -4
  92. package/dist/packages/provider/src/utils/index.d.ts +0 -1
  93. package/dist/packages/server/src/CloseEvents.d.ts +0 -4
@@ -1,16 +1,12 @@
1
1
  import * as Y from 'yjs';
2
2
  import { Awareness } from 'y-protocols/awareness';
3
3
  import * as mutex from 'lib0/mutex';
4
- import { Event, CloseEvent, MessageEvent } from 'ws';
4
+ import type { Event, CloseEvent, MessageEvent } from 'ws';
5
5
  import EventEmitter from './EventEmitter';
6
- import { OutgoingMessage } from './OutgoingMessage';
7
- import { ConstructableOutgoingMessage } from './types';
8
- export declare enum WebSocketStatus {
9
- Connecting = "connecting",
10
- Connected = "connected",
11
- Disconnected = "disconnected"
12
- }
13
- export interface HocuspocusProviderOptions {
6
+ import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
7
+ import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
8
+ export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
9
+ export interface CompleteHocuspocusProviderConfiguration {
14
10
  /**
15
11
  * URL of your @hocuspocus/server instance
16
12
  */
@@ -90,28 +86,31 @@ export interface HocuspocusProviderOptions {
90
86
  */
91
87
  timeout: number;
92
88
  onAuthenticated: () => void;
93
- onAuthenticationFailed: ({ reason }: {
94
- reason: string;
95
- }) => void;
96
- onOpen: (event: Event) => void;
89
+ onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
90
+ onOpen: (data: onOpenParameters) => void;
97
91
  onConnect: () => void;
98
- onMessage: (event: MessageEvent) => void;
99
- onOutgoingMessage: (message: OutgoingMessage) => void;
100
- onStatus: (status: any) => void;
101
- onSynced: () => void;
102
- onDisconnect: (event: CloseEvent) => void;
103
- 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;
104
98
  onDestroy: () => void;
105
- onAwarenessUpdate: (states: any) => void;
106
- onAwarenessChange: (states: any) => void;
99
+ onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
100
+ onAwarenessChange: (data: onAwarenessChangeParameters) => void;
101
+ /**
102
+ * Don’t output any warnings.
103
+ */
104
+ quiet: boolean;
107
105
  }
108
106
  export declare class HocuspocusProvider extends EventEmitter {
109
- options: HocuspocusProviderOptions;
107
+ configuration: CompleteHocuspocusProviderConfiguration;
110
108
  subscribedToBroadcastChannel: boolean;
111
109
  webSocket: WebSocket | null;
112
110
  shouldConnect: boolean;
113
111
  status: WebSocketStatus;
114
112
  isSynced: boolean;
113
+ unsyncedChanges: number;
115
114
  isAuthenticated: boolean;
116
115
  lastMessageReceived: number;
117
116
  mux: mutex.mutex;
@@ -120,16 +119,21 @@ export declare class HocuspocusProvider extends EventEmitter {
120
119
  resolve: (value?: any) => void;
121
120
  reject: (reason?: any) => void;
122
121
  } | null;
123
- constructor(options?: Partial<HocuspocusProviderOptions>);
124
- setOptions(options?: Partial<HocuspocusProviderOptions>): void;
122
+ constructor(configuration: HocuspocusProviderConfiguration);
123
+ setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
124
+ boundConnect: () => Promise<void>;
125
125
  connect(): Promise<void>;
126
126
  createWebSocketConnection(): Promise<unknown>;
127
127
  resolveConnectionAttempt(): void;
128
+ stopConnectionAttempt(): void;
128
129
  rejectConnectionAttempt(): void;
129
130
  get document(): Y.Doc;
130
131
  get awareness(): Awareness;
132
+ get hasUnsyncedChanges(): boolean;
131
133
  checkConnection(): void;
132
134
  forceSync(): void;
135
+ boundBeforeUnload: () => void;
136
+ beforeUnload(): void;
133
137
  registerEventListeners(): void;
134
138
  documentUpdateHandler(update: Uint8Array, origin: any): void;
135
139
  awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
@@ -141,15 +145,15 @@ export declare class HocuspocusProvider extends EventEmitter {
141
145
  set synced(state: boolean);
142
146
  get isAuthenticationRequired(): boolean;
143
147
  disconnect(): void;
144
- onOpen(event: Event): void;
148
+ onOpen(event: Event): Promise<void>;
145
149
  getToken(): Promise<string | null>;
146
- webSocketConnectionEstablished(): Promise<void>;
147
150
  startSync(): void;
148
151
  send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
149
152
  onMessage(event: MessageEvent): void;
150
153
  onClose(event: CloseEvent): void;
151
154
  destroy(): void;
152
155
  get broadcastChannel(): string;
156
+ boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
153
157
  broadcastChannelSubscriber(data: ArrayBuffer): void;
154
158
  subscribeToBroadcastChannel(): void;
155
159
  disconnectBroadcastChannel(): void;
@@ -1,4 +1,3 @@
1
1
  export * from './HocuspocusProvider';
2
2
  export * from './HocuspocusCloudProvider';
3
3
  export * from './types';
4
- export * from './utils';
@@ -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,3 +40,38 @@ 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
+ };
68
+ export declare type onAwarenessUpdateParameters = {
69
+ states: StatesArray;
70
+ };
71
+ export declare type onAwarenessChangeParameters = {
72
+ states: StatesArray;
73
+ };
74
+ export declare type StatesArray = {
75
+ clientId: number;
76
+ [key: string | number]: any;
77
+ }[];
@@ -2,10 +2,10 @@
2
2
  import AsyncLock from 'async-lock';
3
3
  import WebSocket from 'ws';
4
4
  import { IncomingMessage as HTTPIncomingMessage } from 'http';
5
+ import { CloseEvent } from '@hocuspocus/common';
5
6
  import Document from './Document';
6
- import { CloseEvent } from './types';
7
- import { MessageLogger } from './Debugger';
8
- declare class Connection {
7
+ import { Debugger } from './Debugger';
8
+ export declare class Connection {
9
9
  webSocket: WebSocket;
10
10
  context: any;
11
11
  document: Document;
@@ -17,11 +17,11 @@ declare class Connection {
17
17
  socketId: string;
18
18
  lock: AsyncLock;
19
19
  readOnly: Boolean;
20
- debugger: MessageLogger;
20
+ logger: Debugger;
21
21
  /**
22
22
  * Constructor.
23
23
  */
24
- constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly?: boolean);
24
+ constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, timeout: number, socketId: string, context: any, readOnly: boolean | undefined, logger: Debugger);
25
25
  /**
26
26
  * Set a callback that will be triggered when the connection is closed
27
27
  */
@@ -49,6 +49,13 @@ declare class Connection {
49
49
  * @private
50
50
  */
51
51
  private handleMessage;
52
+ /**
53
+ * Handle a ws instance error, which is required to prevent
54
+ * the server from crashing when one happens
55
+ * See https://github.com/websockets/ws/issues/1777#issuecomment-660803472
56
+ * @private
57
+ */
58
+ private handleError;
52
59
  /**
53
60
  * Get the underlying connection instance
54
61
  * @deprecated
@@ -1,4 +1,4 @@
1
- export declare class MessageLogger {
1
+ export declare class Debugger {
2
2
  logs: any[];
3
3
  listen: boolean;
4
4
  output: boolean;
@@ -12,4 +12,3 @@ export declare class MessageLogger {
12
12
  logs: any[];
13
13
  };
14
14
  }
15
- export declare const Debugger: MessageLogger;
@@ -3,20 +3,24 @@ import { Awareness } from 'y-protocols/awareness';
3
3
  import { Doc } from 'yjs';
4
4
  import { mutex } from 'lib0/mutex.js';
5
5
  import Connection from './Connection';
6
- import { MessageLogger } from './Debugger';
7
- declare class Document extends Doc {
6
+ import { Debugger } from './Debugger';
7
+ export declare class Document extends Doc {
8
8
  awareness: Awareness;
9
9
  callbacks: {
10
10
  onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
11
11
  };
12
- connections: Map<any, any>;
12
+ connections: Map<WebSocket, {
13
+ clients: Set<any>;
14
+ connection: Connection;
15
+ }>;
13
16
  name: string;
14
17
  mux: mutex;
15
- debugger: MessageLogger;
18
+ logger: Debugger;
19
+ isLoading: boolean;
16
20
  /**
17
21
  * Constructor.
18
22
  */
19
- constructor(name: string);
23
+ constructor(name: string, logger: Debugger, yDocOptions: {});
20
24
  /**
21
25
  * Check if the Document is empty
22
26
  */
@@ -1,24 +1,32 @@
1
1
  /// <reference types="node" />
2
- import WebSocket, { WebSocketServer } from 'ws';
2
+ import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
3
3
  import { IncomingMessage, Server as HTTPServer } from 'http';
4
- import { Configuration, Hook } from './types';
5
- import { MessageLogger } from './Debugger';
4
+ import { Configuration, HookName, HookPayload } from './types';
5
+ import Document from './Document';
6
+ import { Debugger } from './Debugger';
6
7
  import { onListenPayload } from '.';
7
8
  export declare const defaultConfiguration: {
8
9
  name: null;
9
10
  port: number;
10
11
  timeout: number;
12
+ debounce: number;
13
+ maxDebounce: number;
11
14
  quiet: boolean;
15
+ yDocOptions: {
16
+ gc: boolean;
17
+ gcFilter: () => boolean;
18
+ };
12
19
  };
13
20
  /**
14
21
  * Hocuspocus Server
15
22
  */
16
23
  export declare class Hocuspocus {
17
24
  configuration: Configuration;
18
- documents: Map<any, any>;
25
+ documents: Map<string, Document>;
19
26
  httpServer?: HTTPServer;
20
27
  webSocketServer?: WebSocketServer;
21
- debugger: MessageLogger;
28
+ debugger: Debugger;
29
+ constructor(configuration?: Partial<Configuration>);
22
30
  /**
23
31
  * Configure the server
24
32
  */
@@ -27,7 +35,11 @@ export declare class Hocuspocus {
27
35
  /**
28
36
  * Start the server
29
37
  */
30
- listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<void>;
38
+ listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<Hocuspocus>;
39
+ get address(): AddressInfo;
40
+ get URL(): string;
41
+ get webSocketURL(): string;
42
+ get httpURL(): string;
31
43
  private showStartScreen;
32
44
  /**
33
45
  * Get the total number of active documents
@@ -46,37 +58,47 @@ export declare class Hocuspocus {
46
58
  */
47
59
  destroy(): Promise<any>;
48
60
  /**
49
- * Handle the incoming WebSocket connection
61
+ * The `handleConnection` method receives incoming WebSocket connections,
62
+ * runs all hooks:
63
+ *
64
+ * - onConnect for all connections
65
+ * - onAuthenticate only if required
66
+ *
67
+ * … and if nothings fails it’ll fully establish the connection and
68
+ * load the Document then.
50
69
  */
51
70
  handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
52
71
  /**
53
72
  * Handle update of the given document
54
- * @private
55
73
  */
56
74
  private handleDocumentUpdate;
75
+ timers: Map<string, {
76
+ timeout: NodeJS.Timeout;
77
+ start: number;
78
+ }>;
79
+ /**
80
+ * debounce the given function, using the given identifier
81
+ */
82
+ debounce(id: string, func: Function, immediately?: boolean): void;
57
83
  /**
58
84
  * Create a new document by the given request
59
- * @private
60
85
  */
61
86
  private createDocument;
62
87
  /**
63
88
  * Create a new connection by the given request and document
64
- * @private
65
89
  */
66
90
  private createConnection;
67
91
  /**
68
- * Run the given hook on all configured extensions
69
- * Runs the given callback after each hook
92
+ * Run the given hook on all configured extensions.
93
+ * Runs the given callback after each hook.
70
94
  */
71
- hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
95
+ hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
72
96
  /**
73
97
  * Get parameters by the given request
74
- * @private
75
98
  */
76
99
  private static getParameters;
77
100
  /**
78
101
  * Get document name by the given request
79
- * @private
80
102
  */
81
103
  private getDocumentNameFromRequest;
82
104
  enableDebugging(): void;
@@ -1,10 +1,13 @@
1
+ import { Awareness } from 'y-protocols/awareness';
1
2
  import Connection from './Connection';
2
3
  import { IncomingMessage } from './IncomingMessage';
3
- import { MessageLogger } from './Debugger';
4
+ import { Debugger } from './Debugger';
5
+ import Document from './Document';
4
6
  export declare class MessageReceiver {
5
7
  message: IncomingMessage;
6
- debugger: MessageLogger;
7
- constructor(message: IncomingMessage);
8
- apply(connection: Connection): void;
9
- readSyncMessage(message: IncomingMessage, connection: Connection): 0 | 1 | 2;
8
+ logger: Debugger;
9
+ constructor(message: IncomingMessage, logger: Debugger);
10
+ apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
11
+ readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
12
+ applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
10
13
  }
@@ -7,7 +7,9 @@ export declare class OutgoingMessage {
7
7
  category?: string;
8
8
  constructor();
9
9
  createSyncMessage(): OutgoingMessage;
10
+ createSyncReplyMessage(): OutgoingMessage;
10
11
  createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
12
+ writeQueryAwareness(): OutgoingMessage;
11
13
  writeAuthenticated(): OutgoingMessage;
12
14
  writePermissionDenied(reason: string): OutgoingMessage;
13
15
  writeFirstSyncStepFor(document: Document): OutgoingMessage;
@@ -1,2 +1,8 @@
1
+ export * from './Connection';
2
+ export * from './Debugger';
3
+ export * from './Document';
1
4
  export * from './Hocuspocus';
5
+ export * from './IncomingMessage';
6
+ export * from './MessageReceiver';
7
+ export * from './OutgoingMessage';
2
8
  export * from './types';
@@ -1,56 +1,55 @@
1
1
  /// <reference types="node" />
2
2
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http';
3
3
  import { URLSearchParams } from 'url';
4
- import { Socket } from 'net';
4
+ import { Awareness } from 'y-protocols/awareness';
5
5
  import Document from './Document';
6
6
  import { Hocuspocus } from './Hocuspocus';
7
7
  export declare enum MessageType {
8
8
  Unknown = -1,
9
9
  Sync = 0,
10
10
  Awareness = 1,
11
- Auth = 2
12
- }
13
- /**
14
- * State of the WebSocket connection.
15
- * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
16
- */
17
- export declare enum WsReadyStates {
18
- Connecting = 0,
19
- Open = 1,
20
- Closing = 2,
21
- Closed = 3
11
+ Auth = 2,
12
+ QueryAwareness = 3,
13
+ SyncReply = 4
22
14
  }
23
15
  export interface AwarenessUpdate {
24
16
  added: Array<any>;
25
17
  updated: Array<any>;
26
18
  removed: Array<any>;
27
19
  }
28
- export interface ConnectionConfig {
20
+ export interface ConnectionConfiguration {
29
21
  readOnly: boolean;
30
22
  requiresAuthentication: boolean;
31
23
  isAuthenticated: boolean;
32
24
  }
33
25
  export interface Extension {
34
- onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
35
- onChange?(data: onChangePayload): Promise<any>;
36
- onConnect?(data: onConnectPayload): Promise<any>;
26
+ priority?: number;
37
27
  onConfigure?(data: onConfigurePayload): Promise<any>;
28
+ onListen?(data: onListenPayload): Promise<any>;
29
+ onUpgrade?(data: onUpgradePayload): Promise<any>;
30
+ onConnect?(data: onConnectPayload): Promise<any>;
31
+ connected?(data: connectedPayload): Promise<any>;
32
+ onAuthenticate?(data: onAuthenticatePayload): Promise<any>;
38
33
  /**
39
34
  * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
40
35
  */
41
36
  onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
42
37
  onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
43
- onDestroy?(data: onDestroyPayload): Promise<any>;
44
- onDisconnect?(data: onDisconnectPayload): Promise<any>;
45
- onListen?(data: onListenPayload): Promise<any>;
38
+ afterLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
39
+ onChange?(data: onChangePayload): Promise<any>;
40
+ onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;
41
+ afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>;
42
+ onAwarenessUpdate?(data: onAwarenessUpdatePayload): Promise<any>;
46
43
  onRequest?(data: onRequestPayload): Promise<any>;
47
- onUpgrade?(data: onUpgradePayload): Promise<any>;
44
+ onDisconnect?(data: onDisconnectPayload): Promise<any>;
45
+ onDestroy?(data: onDestroyPayload): Promise<any>;
48
46
  }
49
- export declare type Hook = 'onAuthenticate' | 'onChange' | 'onConnect' | 'onConfigure' |
47
+ export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' |
50
48
  /**
51
49
  * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
52
50
  */
53
- 'onCreateDocument' | 'onLoadDocument' | 'onDestroy' | 'onDisconnect' | 'onListen' | 'onRequest' | 'onUpgrade';
51
+ 'onCreateDocument' | 'onLoadDocument' | 'afterLoadDocument' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
52
+ export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
54
53
  export interface Configuration extends Extension {
55
54
  /**
56
55
  * A name for the instance, used for logging.
@@ -68,18 +67,35 @@ export interface Configuration extends Extension {
68
67
  * Defines in which interval the server sends a ping, and closes the connection when no pong is sent back.
69
68
  */
70
69
  timeout: number;
70
+ /**
71
+ * Debounces the call of the `onStoreDocument` hook for the given amount of time in ms.
72
+ * Otherwise every single update would be persisted.
73
+ */
74
+ debounce: number;
75
+ /**
76
+ * Makes sure to call `onStoreDocument` at least in the given amount of time (ms).
77
+ */
78
+ maxDebounce: number;
71
79
  /**
72
80
  * By default, the servers show a start screen. If passed false, the server will start quietly.
73
81
  */
74
82
  quiet: boolean;
83
+ /**
84
+ * options to pass to the ydoc document
85
+ */
86
+ yDocOptions: {
87
+ gc: boolean;
88
+ gcFilter: () => boolean;
89
+ };
75
90
  /**
76
91
  * Function which returns the (customized) document name based on the request
77
92
  */
78
- getDocumentName?(data: {
79
- documentName: string;
80
- request: IncomingMessage;
81
- requestParameters: URLSearchParams;
82
- }): string | Promise<string>;
93
+ getDocumentName?(data: getDocumentNamePayload): string | Promise<string>;
94
+ }
95
+ export interface getDocumentNamePayload {
96
+ documentName: string;
97
+ request: IncomingMessage;
98
+ requestParameters: URLSearchParams;
83
99
  }
84
100
  export interface onAuthenticatePayload {
85
101
  documentName: string;
@@ -88,7 +104,7 @@ export interface onAuthenticatePayload {
88
104
  requestParameters: URLSearchParams;
89
105
  socketId: string;
90
106
  token: string;
91
- connection: ConnectionConfig;
107
+ connection: ConnectionConfiguration;
92
108
  }
93
109
  export interface onConnectPayload {
94
110
  documentName: string;
@@ -97,7 +113,16 @@ export interface onConnectPayload {
97
113
  requestHeaders: IncomingHttpHeaders;
98
114
  requestParameters: URLSearchParams;
99
115
  socketId: string;
100
- connection: ConnectionConfig;
116
+ connection: ConnectionConfiguration;
117
+ }
118
+ export interface connectedPayload {
119
+ documentName: string;
120
+ instance: Hocuspocus;
121
+ request: IncomingMessage;
122
+ requestHeaders: IncomingHttpHeaders;
123
+ requestParameters: URLSearchParams;
124
+ socketId: string;
125
+ connection: ConnectionConfiguration;
101
126
  }
102
127
  export interface onLoadDocumentPayload {
103
128
  context: any;
@@ -107,7 +132,17 @@ export interface onLoadDocumentPayload {
107
132
  requestHeaders: IncomingHttpHeaders;
108
133
  requestParameters: URLSearchParams;
109
134
  socketId: string;
110
- connection: ConnectionConfig;
135
+ connection: ConnectionConfiguration;
136
+ }
137
+ export interface afterLoadDocumentPayload {
138
+ context: any;
139
+ document: Document;
140
+ documentName: string;
141
+ instance: Hocuspocus;
142
+ requestHeaders: IncomingHttpHeaders;
143
+ requestParameters: URLSearchParams;
144
+ socketId: string;
145
+ connection: ConnectionConfiguration;
111
146
  }
112
147
  export interface onChangePayload {
113
148
  clientsCount: number;
@@ -120,6 +155,51 @@ export interface onChangePayload {
120
155
  update: Uint8Array;
121
156
  socketId: string;
122
157
  }
158
+ export interface onStoreDocumentPayload {
159
+ clientsCount: number;
160
+ context: any;
161
+ document: Document;
162
+ documentName: string;
163
+ instance: Hocuspocus;
164
+ requestHeaders: IncomingHttpHeaders;
165
+ requestParameters: URLSearchParams;
166
+ socketId: string;
167
+ }
168
+ export interface afterStoreDocumentPayload extends onStoreDocumentPayload {
169
+ }
170
+ export interface onAwarenessUpdatePayload {
171
+ clientsCount: number;
172
+ context: any;
173
+ document: Document;
174
+ documentName: string;
175
+ instance: Hocuspocus;
176
+ requestHeaders: IncomingHttpHeaders;
177
+ requestParameters: URLSearchParams;
178
+ update: Uint8Array;
179
+ socketId: string;
180
+ added: number[];
181
+ updated: number[];
182
+ removed: number[];
183
+ awareness: Awareness;
184
+ states: StatesArray;
185
+ }
186
+ export declare type StatesArray = {
187
+ clientId: number;
188
+ [key: string | number]: any;
189
+ }[];
190
+ export interface fetchPayload {
191
+ context: any;
192
+ document: Document;
193
+ documentName: string;
194
+ instance: Hocuspocus;
195
+ requestHeaders: IncomingHttpHeaders;
196
+ requestParameters: URLSearchParams;
197
+ socketId: string;
198
+ connection: ConnectionConfiguration;
199
+ }
200
+ export interface storePayload extends onStoreDocumentPayload {
201
+ state: Buffer;
202
+ }
123
203
  export interface onDisconnectPayload {
124
204
  clientsCount: number;
125
205
  context: any;
@@ -136,24 +216,21 @@ export interface onRequestPayload {
136
216
  instance: Hocuspocus;
137
217
  }
138
218
  export interface onUpgradePayload {
139
- head: any;
140
219
  request: IncomingMessage;
141
- socket: Socket;
220
+ socket: any;
221
+ head: any;
142
222
  instance: Hocuspocus;
143
223
  }
144
224
  export interface onListenPayload {
225
+ instance: Hocuspocus;
226
+ configuration: Configuration;
145
227
  port: number;
146
228
  }
147
229
  export interface onDestroyPayload {
148
230
  instance: Hocuspocus;
149
231
  }
150
232
  export interface onConfigurePayload {
233
+ instance: Hocuspocus;
151
234
  configuration: Configuration;
152
235
  version: string;
153
- yjsVersion: string;
154
- instance: Hocuspocus;
155
- }
156
- export interface CloseEvent {
157
- code: number;
158
- reason: string;
159
236
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};