@hocuspocus/extension-database 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage } from 'http';
3
+ import WebSocket from 'ws';
4
+ import { Debugger } from './Debugger.js';
5
+ import Document from './Document.js';
6
+ import { Hocuspocus } from './Hocuspocus.js';
7
+ import { onDisconnectPayload } from './types.js';
8
+ /**
9
+ * The `ClientConnection` class is responsible for handling an incoming WebSocket
10
+ *
11
+ * TODO-refactor:
12
+ * - use event handlers instead of calling hooks directly, hooks should probably be called from Hocuspocus.ts
13
+ */
14
+ export declare class ClientConnection {
15
+ private readonly websocket;
16
+ private readonly request;
17
+ private readonly documentProvider;
18
+ private readonly hooks;
19
+ private readonly debuggerTool;
20
+ private readonly opts;
21
+ private readonly defaultContext;
22
+ private readonly documentConnections;
23
+ private readonly incomingMessageQueue;
24
+ private readonly documentConnectionsEstablished;
25
+ private readonly hookPayloads;
26
+ private readonly callbacks;
27
+ private readonly closeIdleConnectionTimeout;
28
+ private readonly socketId;
29
+ /**
30
+ * The `ClientConnection` class receives incoming WebSocket connections,
31
+ * runs all hooks:
32
+ *
33
+ * - onConnect for all connections
34
+ * - onAuthenticate only if required
35
+ *
36
+ * … and if nothings fails it’ll fully establish the connection and
37
+ * load the Document then.
38
+ */
39
+ constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
40
+ createDocument: Hocuspocus['createDocument'];
41
+ }, hooks: Hocuspocus['hooks'], debuggerTool: Debugger, opts: {
42
+ requiresAuthentication: boolean;
43
+ timeout: number;
44
+ }, defaultContext?: any);
45
+ /**
46
+ * Set a callback that will be triggered when the connection is closed
47
+ */
48
+ onClose(callback: (document: Document, payload: onDisconnectPayload) => void): ClientConnection;
49
+ /**
50
+ * Create a new connection by the given request and document
51
+ */
52
+ private createConnection;
53
+ private setUpNewConnection;
54
+ private handleQueueingMessage;
55
+ private messageHandler;
56
+ }
@@ -1,6 +1,7 @@
1
1
  import Document from './Document.js';
2
2
  import type { Hocuspocus } from './Hocuspocus.js';
3
- export declare class DirectConnection {
3
+ import type { DirectConnection as DirectConnectionInterface } from './types';
4
+ export declare class DirectConnection implements DirectConnectionInterface {
4
5
  document: Document | null;
5
6
  instance: Hocuspocus;
6
7
  context: any;
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
- import { IncomingMessage, Server as HTTPServer } from 'http';
3
+ import { Server as HTTPServer, IncomingMessage } from 'http';
4
4
  import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
5
- import { Configuration, HookName, HookPayload, onListenPayload, onStoreDocumentPayload } from './types.js';
6
- import Document from './Document.js';
7
5
  import { Debugger } from './Debugger.js';
8
6
  import { DirectConnection } from './DirectConnection.js';
7
+ import Document from './Document.js';
8
+ import { Configuration, ConnectionConfiguration, HookName, HookPayload, onListenPayload, onStoreDocumentPayload } from './types.js';
9
9
  export declare const defaultConfiguration: {
10
10
  name: null;
11
11
  port: number;
@@ -69,7 +69,7 @@ export declare class Hocuspocus {
69
69
  * … and if nothings fails it’ll fully establish the connection and
70
70
  * load the Document then.
71
71
  */
72
- handleConnection(incoming: WebSocket, request: IncomingMessage, context?: any): void;
72
+ handleConnection(incoming: WebSocket, request: IncomingMessage, defaultContext?: any): void;
73
73
  /**
74
74
  * Handle update of the given document
75
75
  */
@@ -85,21 +85,13 @@ export declare class Hocuspocus {
85
85
  /**
86
86
  * Create a new document by the given request
87
87
  */
88
- private createDocument;
89
- /**
90
- * Create a new connection by the given request and document
91
- */
92
- private createConnection;
88
+ createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
93
89
  storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): void;
94
90
  /**
95
91
  * Run the given hook on all configured extensions.
96
92
  * Runs the given callback after each hook.
97
93
  */
98
94
  hooks(name: HookName, payload: HookPayload, callback?: Function | null): Promise<any>;
99
- /**
100
- * Get parameters by the given request
101
- */
102
- private static getParameters;
103
95
  enableDebugging(): void;
104
96
  enableMessageLogging(): void;
105
97
  disableLogging(): void;
@@ -264,3 +264,7 @@ export interface onConfigurePayload {
264
264
  configuration: Configuration;
265
265
  version: string;
266
266
  }
267
+ export interface DirectConnection {
268
+ transact(transaction: (document: Document) => void): Promise<void>;
269
+ disconnect(): void;
270
+ }
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { IncomingMessage } from 'http';
4
+ import { URLSearchParams } from 'url';
5
+ /**
6
+ * Get parameters by the given request
7
+ */
8
+ export declare function getParameters(request?: Pick<IncomingMessage, 'url'>): URLSearchParams;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hocuspocus/extension-database",
3
3
  "description": "a generic Hocuspocus persistence driver for the database",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
7
7
  "hocuspocus",
@@ -27,7 +27,7 @@
27
27
  "dist"
28
28
  ],
29
29
  "dependencies": {
30
- "@hocuspocus/server": "^2.1.0"
30
+ "@hocuspocus/server": "^2.2.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "yjs": "^13.5.29"