@hocuspocus/provider 1.0.0-alpha.19 → 1.0.0-alpha.23

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,68 @@
1
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ export interface LoggerConfiguration {
3
+ /**
4
+ * Prepend all logging message with a string.
5
+ *
6
+ * @deprecated
7
+ */
8
+ prefix: null | string;
9
+ /**
10
+ * Whether to log something for the `onLoadDocument` hook.
11
+ */
12
+ onLoadDocument: boolean;
13
+ /**
14
+ * Whether to log something for the `onChange` hook.
15
+ */
16
+ onChange: boolean;
17
+ /**
18
+ * Whether to log something for the `onConnect` hook.
19
+ */
20
+ onConnect: boolean;
21
+ /**
22
+ * Whether to log something for the `onDisconnect` hook.
23
+ */
24
+ onDisconnect: boolean;
25
+ /**
26
+ * Whether to log something for the `onUpgrade` hook.
27
+ */
28
+ onUpgrade: boolean;
29
+ /**
30
+ * Whether to log something for the `onRequest` hook.
31
+ */
32
+ onRequest: boolean;
33
+ /**
34
+ * Whether to log something for the `onListen` hook.
35
+ */
36
+ onListen: boolean;
37
+ /**
38
+ * Whether to log something for the `onDestroy` hook.
39
+ */
40
+ onDestroy: boolean;
41
+ /**
42
+ * Whether to log something for the `onConfigure` hook.
43
+ */
44
+ onConfigure: boolean;
45
+ /**
46
+ * A log function, if none is provided output will go to console
47
+ */
48
+ log: (...args: any[]) => void;
49
+ }
50
+ export declare class Logger implements Extension {
51
+ name: string | null;
52
+ configuration: LoggerConfiguration;
53
+ /**
54
+ * Constructor
55
+ */
56
+ constructor(configuration?: Partial<LoggerConfiguration>);
57
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
58
+ onChange(data: onChangePayload): Promise<void>;
59
+ onConnect(data: onConnectPayload): Promise<void>;
60
+ onDisconnect(data: onDisconnectPayload): Promise<void>;
61
+ onUpgrade(data: onUpgradePayload): Promise<void>;
62
+ onRequest(data: onRequestPayload): Promise<void>;
63
+ onListen(data: onListenPayload): Promise<void>;
64
+ onDestroy(data: onDestroyPayload): Promise<void>;
65
+ onConfigure(data: onConfigurePayload): Promise<void>;
66
+ private logRawText;
67
+ private log;
68
+ }
@@ -0,0 +1 @@
1
+ export * from './Logger';
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Configuration, onConnectPayload, onDisconnectPayload, onCreateDocumentPayload, onChangePayload } from '@hocuspocus/server';
2
+ import { Configuration, onConnectPayload, onDisconnectPayload, onLoadDocumentPayload, onChangePayload } from '@hocuspocus/server';
3
3
  export declare class Collector {
4
4
  serverConfiguration: Partial<Configuration>;
5
5
  version: string;
@@ -30,7 +30,7 @@ export declare class Collector {
30
30
  connectionCount(): {
31
31
  count: string | number;
32
32
  };
33
- createDocument(data: onCreateDocumentPayload): {
33
+ createDocument(data: onLoadDocumentPayload): {
34
34
  action: string;
35
35
  document: any;
36
36
  documentName: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
+ import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
3
3
  import { IncomingMessage, ServerResponse } from 'http';
4
4
  import WebSocket from 'ws';
5
5
  import { Storage } from './Storage';
@@ -32,7 +32,7 @@ export declare class Monitor implements Extension {
32
32
  onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
33
33
  onConnect(data: onConnectPayload): Promise<void>;
34
34
  onDisconnect(data: onDisconnectPayload): Promise<void>;
35
- onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
35
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
36
36
  onChange(data: onChangePayload): Promise<void>;
37
37
  onConfigure(data: onConfigurePayload): Promise<void>;
38
38
  }
@@ -1,5 +1,5 @@
1
1
  import { RedisPersistence } from 'y-redis';
2
- import { Extension, onConnectPayload, onCreateDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
2
+ import { Extension, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
3
3
  export interface Configuration {
4
4
  }
5
5
  export declare class Redis implements Extension {
@@ -10,7 +10,7 @@ export declare class Redis implements Extension {
10
10
  * Constructor
11
11
  */
12
12
  constructor(configuration?: Partial<Configuration>);
13
- onCreateDocument(data: onCreateDocumentPayload): Promise<import("yjs").Doc | undefined>;
13
+ onLoadDocument(data: onLoadDocumentPayload): Promise<import("yjs").Doc | undefined>;
14
14
  onConnect(data: onConnectPayload): Promise<void>;
15
15
  onDisconnect(data: onDisconnectPayload): Promise<void>;
16
16
  }
@@ -1,4 +1,4 @@
1
- import { Extension, onCreateDocumentPayload } from '@hocuspocus/server';
1
+ import { Extension, onLoadDocumentPayload } from '@hocuspocus/server';
2
2
  import { LeveldbPersistence } from 'y-leveldb';
3
3
  export interface Configuration {
4
4
  options: object | undefined;
@@ -12,9 +12,9 @@ export declare class RocksDB implements Extension {
12
12
  */
13
13
  constructor(configuration?: Partial<Configuration>);
14
14
  /**
15
- * onCreateDocument hook
15
+ * onLoadDocument hook
16
16
  */
17
- onCreateDocument(data: onCreateDocumentPayload): Promise<any>;
17
+ onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
18
18
  /**
19
19
  * store updates in y-leveldb persistence
20
20
  */
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Extension, onChangePayload, onConnectPayload, onCreateDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
2
+ import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
3
3
  import { Doc } from 'yjs';
4
4
  import { Transformer } from '@hocuspocus/transformer';
5
5
  import { AxiosResponse } from 'axios';
@@ -48,9 +48,9 @@ export declare class Webhook implements Extension {
48
48
  */
49
49
  onChange(data: onChangePayload): Promise<void>;
50
50
  /**
51
- * onCreateDocument hook
51
+ * onLoadDocument hook
52
52
  */
53
- onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
53
+ onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
54
54
  /**
55
55
  * onConnect hook
56
56
  */
@@ -108,7 +108,7 @@ export interface HocuspocusProviderOptions {
108
108
  export declare class HocuspocusProvider extends EventEmitter {
109
109
  options: HocuspocusProviderOptions;
110
110
  subscribedToBroadcastChannel: boolean;
111
- webSocket: any;
111
+ webSocket: WebSocket | null;
112
112
  shouldConnect: boolean;
113
113
  status: WebSocketStatus;
114
114
  isSynced: boolean;
@@ -4,6 +4,7 @@ import { IncomingMessage, Server as HTTPServer } from 'http';
4
4
  import { Configuration } from './types';
5
5
  import { MessageLogger } from './Debugger';
6
6
  export declare const defaultConfiguration: {
7
+ name: null;
7
8
  port: number;
8
9
  timeout: number;
9
10
  };
@@ -34,14 +34,27 @@ export interface Extension {
34
34
  onChange?(data: onChangePayload): Promise<any>;
35
35
  onConnect?(data: onConnectPayload): Promise<any>;
36
36
  onConfigure?(data: onConfigurePayload): Promise<any>;
37
- onCreateDocument?(data: onCreateDocumentPayload): Promise<any>;
37
+ /**
38
+ * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
39
+ */
40
+ onCreateDocument?(data: onLoadDocumentPayload): Promise<any>;
41
+ onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
38
42
  onDestroy?(data: onDestroyPayload): Promise<any>;
39
43
  onDisconnect?(data: onDisconnectPayload): Promise<any>;
40
44
  onListen?(data: onListenPayload): Promise<any>;
41
45
  onRequest?(data: onRequestPayload): Promise<any>;
42
46
  onUpgrade?(data: onUpgradePayload): Promise<any>;
43
47
  }
48
+ export declare type Hook = 'onAuthenticate' | 'onChange' | 'onConnect' | 'onConfigure' |
49
+ /**
50
+ * @deprecated onCreateDocument is deprecated, use onLoadDocument instead
51
+ */
52
+ 'onCreateDocument' | 'onLoadDocument' | 'onDestroy' | 'onDisconnect' | 'onListen' | 'onRequest' | 'onUpgrade';
44
53
  export interface Configuration extends Extension {
54
+ /**
55
+ * A name for the instance, used for logging.
56
+ */
57
+ name: string | null;
45
58
  /**
46
59
  * A list of hocuspocus extenions.
47
60
  */
@@ -73,7 +86,7 @@ export interface onConnectPayload {
73
86
  socketId: string;
74
87
  connection: ConnectionConfig;
75
88
  }
76
- export interface onCreateDocumentPayload {
89
+ export interface onLoadDocumentPayload {
77
90
  context: any;
78
91
  document: Document;
79
92
  documentName: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "1.0.0-alpha.19",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -15,8 +15,13 @@
15
15
  "module": "dist/hocuspocus-provider.esm.js",
16
16
  "types": "dist/packages/provider/src/index.d.ts",
17
17
  "exports": {
18
- "import": "./dist/hocuspocus-provider.esm.js",
19
- "require": "./dist/hocuspocus-provider.cjs"
18
+ "development": {
19
+ "import": "./src"
20
+ },
21
+ "default": {
22
+ "import": "./dist/hocuspocus-provider.esm.js",
23
+ "require": "./dist/hocuspocus-provider.cjs"
24
+ }
20
25
  },
21
26
  "files": [
22
27
  "src",
@@ -26,9 +31,9 @@
26
31
  "@lifeomic/attempt": "^3.0.0",
27
32
  "lib0": "^0.2.42",
28
33
  "y-protocols": "^1.0.5",
29
- "yjs": "^13.5.8"
34
+ "yjs": "^13.5.0"
30
35
  },
31
- "gitHead": "49a520f1b6be37139f5c7243a484dc413640869c",
36
+ "gitHead": "f85955a7cca23b23044b0579e96fc8d17c107a4c",
32
37
  "publishConfig": {
33
38
  "access": "public"
34
39
  }
@@ -167,7 +167,7 @@ export class HocuspocusProvider extends EventEmitter {
167
167
 
168
168
  subscribedToBroadcastChannel = false
169
169
 
170
- webSocket: any = null
170
+ webSocket: WebSocket | null = null
171
171
 
172
172
  shouldConnect = true
173
173
 
@@ -275,11 +275,11 @@ export class HocuspocusProvider extends EventEmitter {
275
275
  }
276
276
  },
277
277
  })
278
- } catch (err: any) {
279
- // If we aborted the connection attempt then don't throw an error
278
+ } catch (error: any) {
279
+ // If we aborted the connection attempt then dont throw an error
280
280
  // ref: https://github.com/lifeomic/attempt/blob/master/src/index.ts#L136
281
- if (err.code !== 'ATTEMPT_ABORTED') {
282
- throw err
281
+ if (error && error.code !== 'ATTEMPT_ABORTED') {
282
+ throw error
283
283
  }
284
284
  }
285
285
  }
@@ -287,14 +287,15 @@ export class HocuspocusProvider extends EventEmitter {
287
287
  createWebSocketConnection() {
288
288
  return new Promise((resolve, reject) => {
289
289
  // Init the WebSocket connection
290
- this.webSocket = new this.options.WebSocketPolyfill(this.url)
291
- this.webSocket.binaryType = 'arraybuffer'
292
- this.webSocket.onmessage = this.onMessage.bind(this)
293
- this.webSocket.onclose = this.onClose.bind(this)
294
- this.webSocket.onopen = this.onOpen.bind(this)
295
- this.webSocket.onerror = () => {
290
+ const ws = new this.options.WebSocketPolyfill(this.url)
291
+ ws.binaryType = 'arraybuffer'
292
+ ws.onmessage = this.onMessage.bind(this)
293
+ ws.onclose = this.onClose.bind(this)
294
+ ws.onopen = this.onOpen.bind(this)
295
+ ws.onerror = () => {
296
296
  reject()
297
297
  }
298
+ this.webSocket = ws
298
299
 
299
300
  // Reset the status
300
301
  this.synced = false
@@ -345,7 +346,7 @@ export class HocuspocusProvider extends EventEmitter {
345
346
 
346
347
  // No message received in a long time, not even your own
347
348
  // Awareness updates, which are updated every 15 seconds.
348
- this.webSocket.close()
349
+ this.webSocket?.close()
349
350
  }
350
351
 
351
352
  forceSync() {
@@ -474,8 +475,6 @@ export class HocuspocusProvider extends EventEmitter {
474
475
  }
475
476
 
476
477
  this.startSync()
477
-
478
- this.resolveConnectionAttempt()
479
478
  }
480
479
 
481
480
  startSync() {
@@ -503,6 +502,8 @@ export class HocuspocusProvider extends EventEmitter {
503
502
  }
504
503
 
505
504
  onMessage(event: MessageEvent) {
505
+ this.resolveConnectionAttempt()
506
+
506
507
  this.lastMessageReceived = time.getUnixTime()
507
508
 
508
509
  const message = new IncomingMessage(event.data)
@@ -1,13 +0,0 @@
1
- import { Extension, onChangePayload, onConfigurePayload, onConnectPayload, onCreateDocumentPayload, onDestroyPayload, onDisconnectPayload, onListenPayload, onRequestPayload, onUpgradePayload } from '@hocuspocus/server';
2
- export declare class Logger implements Extension {
3
- onCreateDocument(data: onCreateDocumentPayload): Promise<void>;
4
- onChange(data: onChangePayload): Promise<void>;
5
- onConnect(data: onConnectPayload): Promise<void>;
6
- onDisconnect(data: onDisconnectPayload): Promise<void>;
7
- onUpgrade(data: onUpgradePayload): Promise<void>;
8
- onRequest(data: onRequestPayload): Promise<void>;
9
- onListen(data: onListenPayload): Promise<void>;
10
- onDestroy(data: onDestroyPayload): Promise<void>;
11
- onConfigure(data: onConfigurePayload): Promise<void>;
12
- private static log;
13
- }