@hocuspocus/provider 1.0.0-alpha.18 → 1.0.0-alpha.22
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.
- package/dist/demos/backend/src/{create-document.d.ts → load-document.d.ts} +0 -0
- package/dist/hocuspocus-provider.cjs +9 -7
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +9 -7
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +68 -0
- package/dist/packages/extension-logger/src/index.d.ts +1 -0
- package/dist/packages/{monitor → extension-monitor}/src/Collector.d.ts +2 -2
- package/dist/packages/{monitor → extension-monitor}/src/Dashboard.d.ts +2 -2
- package/dist/packages/{monitor → extension-monitor}/src/Storage.d.ts +0 -0
- package/dist/packages/{monitor → extension-monitor}/src/index.d.ts +2 -2
- package/dist/packages/{redis → extension-redis}/src/Redis.d.ts +2 -2
- package/dist/packages/{redis → extension-redis}/src/RedisCluster.d.ts +0 -0
- package/dist/packages/{redis → extension-redis}/src/index.d.ts +0 -0
- package/dist/packages/{rocksdb → extension-rocksdb}/src/index.d.ts +3 -3
- package/dist/packages/{throttle → extension-throttle}/src/index.d.ts +0 -0
- package/dist/packages/{webhook → extension-webhook}/src/index.d.ts +4 -4
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +4 -4
- package/dist/packages/server/src/Hocuspocus.d.ts +3 -2
- package/dist/packages/server/src/types.d.ts +10 -2
- package/package.json +10 -5
- package/src/HocuspocusProvider.ts +12 -11
- package/dist/packages/logger/src/index.d.ts +0 -13
|
@@ -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,
|
|
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:
|
|
33
|
+
createDocument(data: onLoadDocumentPayload): {
|
|
34
34
|
action: string;
|
|
35
35
|
document: any;
|
|
36
36
|
documentName: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import WebSocket from 'ws';
|
|
3
|
+
import WebSocket, { WebSocketServer } from 'ws';
|
|
4
4
|
import { Socket } from 'net';
|
|
5
5
|
import { Storage } from './Storage';
|
|
6
6
|
export interface Configuration {
|
|
@@ -12,7 +12,7 @@ export interface Configuration {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class Dashboard {
|
|
14
14
|
configuration: Configuration;
|
|
15
|
-
websocketServer:
|
|
15
|
+
websocketServer: WebSocketServer;
|
|
16
16
|
connections: Map<WebSocket, any>;
|
|
17
17
|
/**
|
|
18
18
|
* Constructor
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConfigurePayload, onConnectPayload,
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Extension,
|
|
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
|
-
*
|
|
15
|
+
* onLoadDocument hook
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
|
|
18
18
|
/**
|
|
19
19
|
* store updates in y-leveldb persistence
|
|
20
20
|
*/
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConnectPayload,
|
|
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';
|
|
@@ -42,15 +42,15 @@ export declare class Webhook implements Extension {
|
|
|
42
42
|
/**
|
|
43
43
|
* Send a request to the given url containing the given data
|
|
44
44
|
*/
|
|
45
|
-
sendRequest(event: Events, payload: any): Promise<AxiosResponse<any>>;
|
|
45
|
+
sendRequest(event: Events, payload: any): Promise<AxiosResponse<unknown, any>>;
|
|
46
46
|
/**
|
|
47
47
|
* onChange hook
|
|
48
48
|
*/
|
|
49
49
|
onChange(data: onChangePayload): Promise<void>;
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* onLoadDocument hook
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
54
54
|
/**
|
|
55
55
|
* onConnect hook
|
|
56
56
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
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 { CloseEvent, MessageEvent
|
|
4
|
+
import { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
5
|
import EventEmitter from './EventEmitter';
|
|
6
6
|
import { OutgoingMessage } from './OutgoingMessage';
|
|
7
7
|
import { ConstructableOutgoingMessage } from './types';
|
|
@@ -93,7 +93,7 @@ export interface HocuspocusProviderOptions {
|
|
|
93
93
|
onAuthenticationFailed: ({ reason }: {
|
|
94
94
|
reason: string;
|
|
95
95
|
}) => void;
|
|
96
|
-
onOpen: (event:
|
|
96
|
+
onOpen: (event: Event) => void;
|
|
97
97
|
onConnect: () => void;
|
|
98
98
|
onMessage: (event: MessageEvent) => void;
|
|
99
99
|
onOutgoingMessage: (message: OutgoingMessage) => void;
|
|
@@ -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:
|
|
111
|
+
webSocket: WebSocket | null;
|
|
112
112
|
shouldConnect: boolean;
|
|
113
113
|
status: WebSocketStatus;
|
|
114
114
|
isSynced: boolean;
|
|
@@ -141,7 +141,7 @@ export declare class HocuspocusProvider extends EventEmitter {
|
|
|
141
141
|
set synced(state: boolean);
|
|
142
142
|
get isAuthenticationRequired(): boolean;
|
|
143
143
|
disconnect(): void;
|
|
144
|
-
onOpen(event:
|
|
144
|
+
onOpen(event: Event): void;
|
|
145
145
|
getToken(): Promise<string | null>;
|
|
146
146
|
webSocketConnectionEstablished(): Promise<void>;
|
|
147
147
|
startSync(): void;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import WebSocket from 'ws';
|
|
2
|
+
import WebSocket, { WebSocketServer } from 'ws';
|
|
3
3
|
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
|
};
|
|
@@ -14,7 +15,7 @@ export declare class Hocuspocus {
|
|
|
14
15
|
configuration: Configuration;
|
|
15
16
|
documents: Map<any, any>;
|
|
16
17
|
httpServer?: HTTPServer;
|
|
17
|
-
webSocketServer?:
|
|
18
|
+
webSocketServer?: WebSocketServer;
|
|
18
19
|
debugger: MessageLogger;
|
|
19
20
|
/**
|
|
20
21
|
* Configure the server
|
|
@@ -34,7 +34,11 @@ 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
|
-
|
|
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>;
|
|
@@ -42,6 +46,10 @@ export interface Extension {
|
|
|
42
46
|
onUpgrade?(data: onUpgradePayload): Promise<any>;
|
|
43
47
|
}
|
|
44
48
|
export interface Configuration extends Extension {
|
|
49
|
+
/**
|
|
50
|
+
* A name for the instance, used for logging.
|
|
51
|
+
*/
|
|
52
|
+
name: string | null;
|
|
45
53
|
/**
|
|
46
54
|
* A list of hocuspocus extenions.
|
|
47
55
|
*/
|
|
@@ -73,7 +81,7 @@ export interface onConnectPayload {
|
|
|
73
81
|
socketId: string;
|
|
74
82
|
connection: ConnectionConfig;
|
|
75
83
|
}
|
|
76
|
-
export interface
|
|
84
|
+
export interface onLoadDocumentPayload {
|
|
77
85
|
context: any;
|
|
78
86
|
document: Document;
|
|
79
87
|
documentName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hocuspocus/provider",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
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
|
-
"
|
|
19
|
-
|
|
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.
|
|
34
|
+
"yjs": "^13.5.0"
|
|
30
35
|
},
|
|
31
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "f9f5acf828d4a1f5ae4df8188000b5c3873e18cf",
|
|
32
37
|
"publishConfig": {
|
|
33
38
|
"access": "public"
|
|
34
39
|
}
|
|
@@ -4,7 +4,7 @@ import * as time from 'lib0/time'
|
|
|
4
4
|
import { Awareness, removeAwarenessStates } from 'y-protocols/awareness'
|
|
5
5
|
import * as mutex from 'lib0/mutex'
|
|
6
6
|
import * as url from 'lib0/url'
|
|
7
|
-
import { CloseEvent, MessageEvent
|
|
7
|
+
import { Event, CloseEvent, MessageEvent } from 'ws'
|
|
8
8
|
import { retry } from '@lifeomic/attempt'
|
|
9
9
|
import EventEmitter from './EventEmitter'
|
|
10
10
|
import { IncomingMessage } from './IncomingMessage'
|
|
@@ -105,7 +105,7 @@ export interface HocuspocusProviderOptions {
|
|
|
105
105
|
timeout: number,
|
|
106
106
|
onAuthenticated: () => void,
|
|
107
107
|
onAuthenticationFailed: ({ reason }: { reason: string }) => void,
|
|
108
|
-
onOpen: (event:
|
|
108
|
+
onOpen: (event: Event) => void,
|
|
109
109
|
onConnect: () => void,
|
|
110
110
|
onMessage: (event: MessageEvent) => void,
|
|
111
111
|
onOutgoingMessage: (message: OutgoingMessage) => void,
|
|
@@ -167,7 +167,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
167
167
|
|
|
168
168
|
subscribedToBroadcastChannel = false
|
|
169
169
|
|
|
170
|
-
webSocket:
|
|
170
|
+
webSocket: WebSocket | null = null
|
|
171
171
|
|
|
172
172
|
shouldConnect = true
|
|
173
173
|
|
|
@@ -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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
|
349
|
+
this.webSocket?.close()
|
|
349
350
|
}
|
|
350
351
|
|
|
351
352
|
forceSync() {
|
|
@@ -444,7 +445,7 @@ export class HocuspocusProvider extends EventEmitter {
|
|
|
444
445
|
}
|
|
445
446
|
}
|
|
446
447
|
|
|
447
|
-
onOpen(event:
|
|
448
|
+
onOpen(event: Event) {
|
|
448
449
|
this.emit('open', { event })
|
|
449
450
|
|
|
450
451
|
if (this.status !== WebSocketStatus.Connected) {
|
|
@@ -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
|
-
}
|