@hocuspocus/provider 1.0.0-alpha.20 → 1.0.0-alpha.24

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
  */
@@ -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.20",
3
+ "version": "1.0.0-alpha.24",
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
+ "source": {
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": "d15359746b9d8e6518ef4128a033512ba0a893e6",
36
+ "gitHead": "53a194759b3bfbea5cf22bab39e3788021387f69",
32
37
  "publishConfig": {
33
38
  "access": "public"
34
39
  }
@@ -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
  }
@@ -475,8 +475,6 @@ export class HocuspocusProvider extends EventEmitter {
475
475
  }
476
476
 
477
477
  this.startSync()
478
-
479
- this.resolveConnectionAttempt()
480
478
  }
481
479
 
482
480
  startSync() {
@@ -504,6 +502,8 @@ export class HocuspocusProvider extends EventEmitter {
504
502
  }
505
503
 
506
504
  onMessage(event: MessageEvent) {
505
+ this.resolveConnectionAttempt()
506
+
507
507
  this.lastMessageReceived = time.getUnixTime()
508
508
 
509
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
- }