@hocuspocus/provider 1.0.0-alpha.26 → 1.0.0-alpha.30

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 (91) hide show
  1. package/dist/hocuspocus-provider.cjs +132 -330
  2. package/dist/hocuspocus-provider.cjs.map +1 -1
  3. package/dist/hocuspocus-provider.esm.js +130 -329
  4. package/dist/hocuspocus-provider.esm.js.map +1 -1
  5. package/dist/packages/common/src/CloseEvents.d.ts +23 -0
  6. package/dist/packages/common/src/index.d.ts +1 -0
  7. package/dist/packages/extension-database/src/Database.d.ts +32 -0
  8. package/dist/packages/extension-database/src/index.d.ts +1 -0
  9. package/dist/packages/extension-logger/src/Logger.d.ts +7 -8
  10. package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
  11. package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
  12. package/dist/packages/extension-webhook/src/index.d.ts +2 -3
  13. package/dist/packages/provider/src/EventEmitter.d.ts +1 -1
  14. package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +11 -0
  15. package/dist/packages/provider/src/HocuspocusProvider.d.ts +17 -9
  16. package/dist/packages/provider/src/index.d.ts +1 -0
  17. package/dist/packages/provider/src/types.d.ts +10 -0
  18. package/dist/packages/server/src/Connection.d.ts +5 -5
  19. package/dist/packages/server/src/Debugger.d.ts +1 -2
  20. package/dist/packages/server/src/Document.d.ts +8 -5
  21. package/dist/packages/server/src/Hocuspocus.d.ts +37 -16
  22. package/dist/packages/server/src/MessageReceiver.d.ts +8 -5
  23. package/dist/packages/server/src/OutgoingMessage.d.ts +1 -0
  24. package/dist/packages/server/src/index.d.ts +7 -0
  25. package/dist/packages/server/src/types.d.ts +89 -18
  26. package/dist/{demos/backend/src/express.d.ts → playground/backend/src/default.d.ts} +0 -0
  27. package/dist/{demos/backend/src/koa.d.ts → playground/backend/src/express.d.ts} +0 -0
  28. package/dist/{demos/backend/src/load-document.d.ts → playground/backend/src/koa.d.ts} +0 -0
  29. package/dist/{demos/backend/src/minimal.d.ts → playground/backend/src/load-document.d.ts} +0 -0
  30. package/dist/{demos → playground}/backend/src/monitor.d.ts +0 -0
  31. package/dist/{demos → playground}/backend/src/redis.d.ts +0 -0
  32. package/dist/{demos → playground}/backend/src/slow.d.ts +0 -0
  33. package/dist/{demos → playground}/backend/src/webhook.d.ts +0 -0
  34. package/dist/tests/extension-logger/onListen.d.ts +1 -0
  35. package/dist/tests/extension-redis/onLoadDocument.d.ts +1 -0
  36. package/dist/tests/extension-redis/onSynced.d.ts +1 -0
  37. package/dist/tests/extension-redis-rewrite/closeConnections.d.ts +1 -0
  38. package/dist/tests/extension-redis-rewrite/getConnectionCount.d.ts +1 -0
  39. package/dist/tests/extension-redis-rewrite/getDocumentsCount.d.ts +1 -0
  40. package/dist/tests/extension-redis-rewrite/onAwarenessChange.d.ts +1 -0
  41. package/dist/tests/extension-redis-rewrite/onChange.d.ts +1 -0
  42. package/dist/tests/extension-redis-rewrite/onStoreDocument.d.ts +1 -0
  43. package/dist/tests/extension-rocksdb/onLoadDocument.d.ts +1 -0
  44. package/dist/tests/provider/configuration.d.ts +1 -0
  45. package/dist/tests/provider/onAuthenticated.d.ts +1 -0
  46. package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
  47. package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
  48. package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
  49. package/dist/tests/provider/onClose.d.ts +1 -0
  50. package/dist/tests/provider/onConnect.d.ts +1 -0
  51. package/dist/tests/provider/onDisconnect.d.ts +1 -0
  52. package/dist/tests/provider/onMessage.d.ts +1 -0
  53. package/dist/tests/provider/onOpen.d.ts +1 -0
  54. package/dist/tests/provider/onSynced.d.ts +1 -0
  55. package/dist/tests/server/address.d.ts +1 -0
  56. package/dist/tests/server/afterStoreDocument.d.ts +1 -0
  57. package/dist/tests/server/closeConnections.d.ts +1 -0
  58. package/dist/tests/server/getConnectionsCount.d.ts +1 -0
  59. package/dist/tests/server/getDocumentName.d.ts +1 -0
  60. package/dist/tests/server/getDocumentsCount.d.ts +1 -0
  61. package/dist/tests/server/getMessageLogs.d.ts +1 -0
  62. package/dist/tests/server/listen.d.ts +1 -0
  63. package/dist/tests/server/onAuthenticate.d.ts +1 -0
  64. package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
  65. package/dist/tests/server/onChange.d.ts +1 -0
  66. package/dist/tests/server/onConfigure.d.ts +1 -0
  67. package/dist/tests/server/onConnect.d.ts +1 -0
  68. package/dist/tests/server/onDestroy.d.ts +1 -0
  69. package/dist/tests/server/onDisconnect.d.ts +1 -0
  70. package/dist/tests/server/onListen.d.ts +1 -0
  71. package/dist/tests/server/onLoadDocument.d.ts +1 -0
  72. package/dist/tests/server/onRequest.d.ts +1 -0
  73. package/dist/tests/server/onStoreDocument.d.ts +1 -0
  74. package/dist/tests/server/onUpgrade.d.ts +1 -0
  75. package/dist/tests/server/requiresAuthentication.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 +7 -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/redisConnectionSettings.d.ts +4 -0
  83. package/dist/tests/utils/removeDirectory.d.ts +1 -0
  84. package/dist/tests/utils/sleep.d.ts +1 -0
  85. package/package.json +6 -5
  86. package/src/EventEmitter.ts +1 -1
  87. package/src/HocuspocusCloudProvider.ts +34 -0
  88. package/src/HocuspocusProvider.ts +101 -68
  89. package/src/index.ts +1 -0
  90. package/src/types.ts +10 -0
  91. package/dist/packages/server/src/CloseEvents.d.ts +0 -4
@@ -0,0 +1,23 @@
1
+ export interface CloseEvent {
2
+ code: number;
3
+ reason: string;
4
+ }
5
+ /**
6
+ * The server successfully processed the request, asks that the requester reset
7
+ * its document view, and is not returning any content.
8
+ */
9
+ export declare const ResetConnection: CloseEvent;
10
+ /**
11
+ * Similar to Forbidden, but specifically for use when authentication is required and has
12
+ * failed or has not yet been provided.
13
+ */
14
+ export declare const Unauthorized: CloseEvent;
15
+ /**
16
+ * The request contained valid data and was understood by the server, but the server
17
+ * is refusing action.
18
+ */
19
+ export declare const Forbidden: CloseEvent;
20
+ /**
21
+ * The server timed out waiting for the request.
22
+ */
23
+ export declare const ConnectionTimeout: CloseEvent;
@@ -1 +1,2 @@
1
1
  export * from './auth';
2
+ export * from './CloseEvents';
@@ -0,0 +1,32 @@
1
+ import { Extension, onChangePayload, onLoadDocumentPayload, storePayload } 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: ({ documentName }: {
8
+ documentName: string;
9
+ }) => Promise<Uint8Array | null>;
10
+ /**
11
+ * Pass a function to store updates in your database.
12
+ */
13
+ store: (data: storePayload) => void;
14
+ }
15
+ export declare class Database implements Extension {
16
+ /**
17
+ * Default configuration
18
+ */
19
+ configuration: DatabaseConfiguration;
20
+ /**
21
+ * Constructor
22
+ */
23
+ constructor(configuration: Partial<DatabaseConfiguration>);
24
+ /**
25
+ * Get stored data from the database.
26
+ */
27
+ onLoadDocument({ document, documentName }: onLoadDocumentPayload): Promise<any>;
28
+ /**
29
+ * Store new updates in the database.
30
+ */
31
+ onStoreDocument(data: onChangePayload): Promise<void>;
32
+ }
@@ -0,0 +1 @@
1
+ export * from './Database';
@@ -1,4 +1,4 @@
1
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
1
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
2
  export interface LoggerConfiguration {
3
3
  /**
4
4
  * Prepend all logging message with a string.
@@ -14,6 +14,10 @@ export interface LoggerConfiguration {
14
14
  * Whether to log something for the `onChange` hook.
15
15
  */
16
16
  onChange: boolean;
17
+ /**
18
+ * Whether to log something for the `onStoreDocument` hook.
19
+ */
20
+ onStoreDocument: boolean;
17
21
  /**
18
22
  * Whether to log something for the `onConnect` hook.
19
23
  */
@@ -30,10 +34,6 @@ export interface LoggerConfiguration {
30
34
  * Whether to log something for the `onRequest` hook.
31
35
  */
32
36
  onRequest: boolean;
33
- /**
34
- * Whether to log something for the `onListen` hook.
35
- */
36
- onListen: boolean;
37
37
  /**
38
38
  * Whether to log something for the `onDestroy` hook.
39
39
  */
@@ -54,15 +54,14 @@ export declare class Logger implements Extension {
54
54
  * Constructor
55
55
  */
56
56
  constructor(configuration?: Partial<LoggerConfiguration>);
57
+ onConfigure(data: onConfigurePayload): Promise<void>;
57
58
  onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
58
59
  onChange(data: onChangePayload): Promise<void>;
60
+ onStoreDocument(data: onDisconnectPayload): Promise<void>;
59
61
  onConnect(data: onConnectPayload): Promise<void>;
60
62
  onDisconnect(data: onDisconnectPayload): Promise<void>;
61
63
  onUpgrade(data: onUpgradePayload): Promise<void>;
62
64
  onRequest(data: onRequestPayload): Promise<void>;
63
- onListen(data: onListenPayload): Promise<void>;
64
65
  onDestroy(data: onDestroyPayload): Promise<void>;
65
- onConfigure(data: onConfigurePayload): Promise<void>;
66
- private logRawText;
67
66
  private log;
68
67
  }
@@ -0,0 +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
+ }
@@ -0,0 +1 @@
1
+ export * from './SQLite';
@@ -3,7 +3,6 @@ import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, on
3
3
  import { Doc } from 'yjs';
4
4
  import { Transformer } from '@hocuspocus/transformer';
5
5
  import { AxiosResponse } from 'axios';
6
- import Timeout = NodeJS.Timeout;
7
6
  export declare enum Events {
8
7
  onChange = "change",
9
8
  onConnect = "connect",
@@ -24,7 +23,7 @@ export interface Configuration {
24
23
  export declare class Webhook implements Extension {
25
24
  configuration: Configuration;
26
25
  debounced: Map<string, {
27
- timeout: Timeout;
26
+ timeout: NodeJS.Timeout;
28
27
  start: number;
29
28
  }>;
30
29
  /**
@@ -42,7 +41,7 @@ export declare class Webhook implements Extension {
42
41
  /**
43
42
  * Send a request to the given url containing the given data
44
43
  */
45
- sendRequest(event: Events, payload: any): Promise<AxiosResponse<unknown, any>>;
44
+ sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
46
45
  /**
47
46
  * onChange hook
48
47
  */
@@ -5,5 +5,5 @@ export default class EventEmitter {
5
5
  on(event: string, fn: Function): this;
6
6
  protected emit(event: string, ...args: any): this;
7
7
  off(event: string, fn?: Function): this;
8
- protected removeAllListeners(): void;
8
+ removeAllListeners(): void;
9
9
  }
@@ -0,0 +1,11 @@
1
+ import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
2
+ export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalHocuspocusCloudProviderConfiguration;
3
+ export interface AdditionalHocuspocusCloudProviderConfiguration {
4
+ /**
5
+ * A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
6
+ */
7
+ key: string;
8
+ }
9
+ export declare class HocuspocusCloudProvider extends HocuspocusProvider {
10
+ constructor(configuration: HocuspocusCloudProviderConfiguration);
11
+ }
@@ -1,16 +1,18 @@
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
6
  import { OutgoingMessage } from './OutgoingMessage';
7
7
  import { ConstructableOutgoingMessage } from './types';
8
+ import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
8
9
  export declare enum WebSocketStatus {
9
10
  Connecting = "connecting",
10
11
  Connected = "connected",
11
12
  Disconnected = "disconnected"
12
13
  }
13
- export interface HocuspocusProviderOptions {
14
+ export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
15
+ export interface CompleteHocuspocusProviderConfiguration {
14
16
  /**
15
17
  * URL of your @hocuspocus/server instance
16
18
  */
@@ -98,15 +100,21 @@ export interface HocuspocusProviderOptions {
98
100
  onMessage: (event: MessageEvent) => void;
99
101
  onOutgoingMessage: (message: OutgoingMessage) => void;
100
102
  onStatus: (status: any) => void;
101
- onSynced: () => void;
103
+ onSynced: ({ state }: {
104
+ state: boolean;
105
+ }) => void;
102
106
  onDisconnect: (event: CloseEvent) => void;
103
107
  onClose: (event: CloseEvent) => void;
104
108
  onDestroy: () => void;
105
- onAwarenessUpdate: (states: any) => void;
106
- onAwarenessChange: (states: any) => void;
109
+ onAwarenessUpdate: ({ states }: onAwarenessUpdateParameters) => void;
110
+ onAwarenessChange: ({ states }: onAwarenessChangeParameters) => void;
111
+ /**
112
+ * Don’t output any warnings.
113
+ */
114
+ quiet: boolean;
107
115
  }
108
116
  export declare class HocuspocusProvider extends EventEmitter {
109
- options: HocuspocusProviderOptions;
117
+ configuration: CompleteHocuspocusProviderConfiguration;
110
118
  subscribedToBroadcastChannel: boolean;
111
119
  webSocket: WebSocket | null;
112
120
  shouldConnect: boolean;
@@ -120,8 +128,8 @@ export declare class HocuspocusProvider extends EventEmitter {
120
128
  resolve: (value?: any) => void;
121
129
  reject: (reason?: any) => void;
122
130
  } | null;
123
- constructor(options?: Partial<HocuspocusProviderOptions>);
124
- setOptions(options?: Partial<HocuspocusProviderOptions>): void;
131
+ constructor(configuration: HocuspocusProviderConfiguration);
132
+ setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
125
133
  connect(): Promise<void>;
126
134
  createWebSocketConnection(): Promise<unknown>;
127
135
  resolveConnectionAttempt(): void;
@@ -130,7 +138,7 @@ export declare class HocuspocusProvider extends EventEmitter {
130
138
  get awareness(): Awareness;
131
139
  checkConnection(): void;
132
140
  forceSync(): void;
133
- registerBeforeUnloadEventListener(): void;
141
+ registerEventListeners(): void;
134
142
  documentUpdateHandler(update: Uint8Array, origin: any): void;
135
143
  awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
136
144
  permissionDeniedHandler(reason: string): void;
@@ -1,3 +1,4 @@
1
1
  export * from './HocuspocusProvider';
2
+ export * from './HocuspocusCloudProvider';
2
3
  export * from './types';
3
4
  export * from './utils';
@@ -32,3 +32,13 @@ export interface Constructable<T> {
32
32
  new (...args: any): T;
33
33
  }
34
34
  export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
35
+ export declare type onAwarenessUpdateParameters = {
36
+ states: StatesArray;
37
+ };
38
+ export declare type onAwarenessChangeParameters = {
39
+ states: StatesArray;
40
+ };
41
+ export declare type StatesArray = {
42
+ clientId: number;
43
+ [key: string | number]: any;
44
+ }[];
@@ -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
  */
@@ -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,23 @@ 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;
16
19
  /**
17
20
  * Constructor.
18
21
  */
19
- constructor(name: string);
22
+ constructor(name: string, logger: Debugger);
20
23
  /**
21
24
  * Check if the Document is empty
22
25
  */
@@ -1,31 +1,42 @@
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
4
  import { Configuration, Hook } from './types';
5
- import { MessageLogger } from './Debugger';
5
+ import Document from './Document';
6
+ import { Debugger } from './Debugger';
7
+ import { onListenPayload } from '.';
6
8
  export declare const defaultConfiguration: {
7
9
  name: null;
8
10
  port: number;
9
11
  timeout: number;
12
+ debounce: number;
13
+ maxDebounce: number;
14
+ quiet: boolean;
10
15
  };
11
16
  /**
12
- * Hocuspocus server
17
+ * Hocuspocus Server
13
18
  */
14
19
  export declare class Hocuspocus {
15
20
  configuration: Configuration;
16
- documents: Map<any, any>;
21
+ documents: Map<string, Document>;
17
22
  httpServer?: HTTPServer;
18
23
  webSocketServer?: WebSocketServer;
19
- debugger: MessageLogger;
24
+ debugger: Debugger;
25
+ constructor(configuration?: Partial<Configuration>);
20
26
  /**
21
27
  * Configure the server
22
28
  */
23
29
  configure(configuration: Partial<Configuration>): Hocuspocus;
24
- get authenticationRequired(): boolean;
30
+ get requiresAuthentication(): boolean;
25
31
  /**
26
32
  * Start the server
27
33
  */
28
- listen(): Promise<void>;
34
+ listen(portOrCallback?: number | ((data: onListenPayload) => Promise<any>) | null, callback?: any): Promise<Hocuspocus>;
35
+ get address(): AddressInfo;
36
+ get URL(): string;
37
+ get webSocketURL(): string;
38
+ get httpURL(): string;
39
+ private showStartScreen;
29
40
  /**
30
41
  * Get the total number of active documents
31
42
  */
@@ -43,39 +54,49 @@ export declare class Hocuspocus {
43
54
  */
44
55
  destroy(): Promise<any>;
45
56
  /**
46
- * Handle the incoming WebSocket connection
57
+ * The `handleConnection` method receives incoming WebSocket connections,
58
+ * runs all hooks:
59
+ *
60
+ * - onConnect for all connections
61
+ * - onAuthenticate only if required
62
+ *
63
+ * … and if nothings fails it’ll fully establish the connection and
64
+ * load the Document then.
47
65
  */
48
66
  handleConnection(incoming: WebSocket, request: IncomingMessage, documentName: string, context?: any): void;
49
67
  /**
50
68
  * Handle update of the given document
51
- * @private
52
69
  */
53
70
  private handleDocumentUpdate;
71
+ timers: Map<string, {
72
+ timeout: NodeJS.Timeout;
73
+ start: number;
74
+ }>;
75
+ /**
76
+ * debounce the given function, using the given identifier
77
+ */
78
+ debounce(id: string, func: Function, immediately?: boolean): void;
54
79
  /**
55
80
  * Create a new document by the given request
56
- * @private
57
81
  */
58
82
  private createDocument;
59
83
  /**
60
84
  * Create a new connection by the given request and document
61
- * @private
62
85
  */
63
86
  private createConnection;
64
87
  /**
65
- * Run the given hook on all configured extensions
66
- * Runs the given callback after each hook
88
+ * Run the given hook on all configured extensions.
89
+ * Runs the given callback after each hook.
67
90
  */
68
91
  hooks(name: Hook, payload: any, callback?: Function | null): Promise<any>;
69
92
  /**
70
93
  * Get parameters by the given request
71
- * @private
72
94
  */
73
95
  private static getParameters;
74
96
  /**
75
97
  * Get document name by the given request
76
- * @private
77
98
  */
78
- private static getDocumentName;
99
+ private getDocumentNameFromRequest;
79
100
  enableDebugging(): void;
80
101
  enableMessageLogging(): void;
81
102
  disableLogging(): 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): 0 | 1 | 2;
12
+ applyQueryAwarenessMessage(awareness: Awareness, reply?: (message: Uint8Array) => void): void;
10
13
  }
@@ -8,6 +8,7 @@ export declare class OutgoingMessage {
8
8
  constructor();
9
9
  createSyncMessage(): OutgoingMessage;
10
10
  createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
11
+ writeQueryAwareness(): OutgoingMessage;
11
12
  writeAuthenticated(): OutgoingMessage;
12
13
  writePermissionDenied(reason: string): OutgoingMessage;
13
14
  writeFirstSyncStepFor(document: Document): OutgoingMessage;
@@ -1,2 +1,9 @@
1
1
  export * from './Hocuspocus';
2
+ export * from './Connection';
3
+ export * from './Document';
4
+ export * from './IncomingMessage';
5
+ export * from './OutgoingMessage';
2
6
  export * from './types';
7
+ export * from './MessageReceiver';
8
+ export * from './Document';
9
+ export * from './Connection';