@hocuspocus/extension-database 1.0.2 → 2.0.0-alpha.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.
- package/dist/packages/extension-monitor/src/Dashboard.d.ts +1 -1
- package/dist/packages/extension-monitor/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/Redis.d.ts +19 -5
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +2 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +14 -70
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +115 -0
- package/dist/packages/provider/src/IncomingMessage.d.ts +2 -0
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +7 -0
- package/dist/packages/provider/src/index.d.ts +1 -0
- package/dist/packages/provider/src/types.d.ts +7 -1
- package/dist/packages/server/src/Connection.d.ts +10 -11
- package/dist/packages/server/src/Document.d.ts +9 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +3 -8
- package/dist/packages/server/src/IncomingMessage.d.ts +2 -0
- package/dist/packages/server/src/MessageReceiver.d.ts +1 -2
- package/dist/packages/server/src/OutgoingMessage.d.ts +3 -1
- package/dist/packages/server/src/types.d.ts +19 -3
- package/dist/packages/transformer/src/Prosemirror.d.ts +1 -1
- package/dist/tests/providerwebsocket/configuration.d.ts +1 -0
- package/dist/tests/server/beforeBroadcastStateless.d.ts +1 -0
- package/dist/tests/server/onStateless.d.ts +1 -0
- package/dist/tests/utils/index.d.ts +1 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +2 -2
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +3 -0
- package/package.json +2 -2
- /package/dist/tests/{provider/configuration.d.ts → extension-redis/onStateless.d.ts} +0 -0
- /package/dist/tests/{server/getDocumentName.d.ts → provider/onStateless.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import WebSocket, { WebSocketServer } from 'ws';
|
|
4
3
|
import { Socket } from 'net';
|
|
4
|
+
import WebSocket, { WebSocketServer } from 'ws';
|
|
5
5
|
import { Storage } from './Storage';
|
|
6
6
|
export interface Configuration {
|
|
7
7
|
password: string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
|
|
3
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
|
|
4
4
|
import WebSocket from 'ws';
|
|
5
5
|
import { Storage } from './Storage';
|
|
6
6
|
import { Dashboard } from './Dashboard';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import RedisClient from 'ioredis';
|
|
1
|
+
import RedisClient, { ClusterNode, ClusterOptions, RedisOptions } from 'ioredis';
|
|
2
2
|
import Redlock from 'redlock';
|
|
3
|
-
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload } from '@hocuspocus/server';
|
|
3
|
+
import { Document, Extension, afterLoadDocumentPayload, afterStoreDocumentPayload, onDisconnectPayload, onStoreDocumentPayload, onAwarenessUpdatePayload, onChangePayload, Debugger, onConfigurePayload, onListenPayload, beforeBroadcastStatelessPayload } from '@hocuspocus/server';
|
|
4
|
+
export declare type RedisInstance = RedisClient.Cluster | RedisClient.Redis;
|
|
4
5
|
export interface Configuration {
|
|
5
6
|
/**
|
|
6
7
|
* Redis port
|
|
@@ -10,12 +11,24 @@ export interface Configuration {
|
|
|
10
11
|
* Redis host
|
|
11
12
|
*/
|
|
12
13
|
host: string;
|
|
14
|
+
/**
|
|
15
|
+
* Redis Cluster
|
|
16
|
+
*/
|
|
17
|
+
nodes?: ClusterNode[];
|
|
18
|
+
/**
|
|
19
|
+
* Duplicate from an existed Redis instance
|
|
20
|
+
*/
|
|
21
|
+
redis?: RedisInstance;
|
|
22
|
+
/**
|
|
23
|
+
* Redis instance creator
|
|
24
|
+
*/
|
|
25
|
+
createClient?: () => RedisInstance;
|
|
13
26
|
/**
|
|
14
27
|
* Options passed directly to Redis constructor
|
|
15
28
|
*
|
|
16
29
|
* https://github.com/luin/ioredis/blob/master/API.md#new-redisport-host-options
|
|
17
30
|
*/
|
|
18
|
-
options?:
|
|
31
|
+
options?: ClusterOptions | RedisOptions;
|
|
19
32
|
/**
|
|
20
33
|
* An unique instance name, required to filter messages in Redis.
|
|
21
34
|
* If none is provided an unique id is generated.
|
|
@@ -38,8 +51,8 @@ export declare class Redis implements Extension {
|
|
|
38
51
|
*/
|
|
39
52
|
priority: number;
|
|
40
53
|
configuration: Configuration;
|
|
41
|
-
pub:
|
|
42
|
-
sub:
|
|
54
|
+
pub: RedisInstance;
|
|
55
|
+
sub: RedisInstance;
|
|
43
56
|
documents: Map<string, Document>;
|
|
44
57
|
redlock: Redlock;
|
|
45
58
|
locks: Map<string, Redlock.Lock>;
|
|
@@ -91,6 +104,7 @@ export declare class Redis implements Extension {
|
|
|
91
104
|
* noone connected anymore.
|
|
92
105
|
*/
|
|
93
106
|
onDisconnect: ({ documentName, clientsCount }: onDisconnectPayload) => Promise<void>;
|
|
107
|
+
beforeBroadcastStateless(data: beforeBroadcastStatelessPayload): Promise<number>;
|
|
94
108
|
/**
|
|
95
109
|
* Kill the Redlock connection immediately.
|
|
96
110
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
|
|
2
|
-
|
|
2
|
+
import { HocuspocusProviderWebsocketConfiguration } from './HocuspocusProviderWebsocket';
|
|
3
|
+
export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & Partial<Pick<HocuspocusProviderWebsocketConfiguration, 'url'>> & AdditionalHocuspocusCloudProviderConfiguration;
|
|
3
4
|
export interface AdditionalHocuspocusCloudProviderConfiguration {
|
|
4
5
|
/**
|
|
5
6
|
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
@@ -1,16 +1,13 @@
|
|
|
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 type {
|
|
4
|
+
import type { CloseEvent, Event, MessageEvent } from 'ws';
|
|
5
5
|
import EventEmitter from './EventEmitter';
|
|
6
|
-
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
6
|
+
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
7
|
+
import { HocuspocusProviderWebsocket } from './HocuspocusProviderWebsocket';
|
|
7
8
|
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
8
|
-
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, '
|
|
9
|
+
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'name' | 'websocketProvider'>> & Partial<CompleteHocuspocusProviderConfiguration>;
|
|
9
10
|
export interface CompleteHocuspocusProviderConfiguration {
|
|
10
|
-
/**
|
|
11
|
-
* URL of your @hocuspocus/server instance
|
|
12
|
-
*/
|
|
13
|
-
url: string;
|
|
14
11
|
/**
|
|
15
12
|
* The identifier/name of your document
|
|
16
13
|
*/
|
|
@@ -19,10 +16,6 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
19
16
|
* The actual Y.js document
|
|
20
17
|
*/
|
|
21
18
|
document: Y.Doc;
|
|
22
|
-
/**
|
|
23
|
-
* Pass `false` to start the connection manually.
|
|
24
|
-
*/
|
|
25
|
-
connect: boolean;
|
|
26
19
|
/**
|
|
27
20
|
* Pass false to disable broadcasting between browser tabs.
|
|
28
21
|
*/
|
|
@@ -42,49 +35,13 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
42
35
|
[key: string]: any;
|
|
43
36
|
};
|
|
44
37
|
/**
|
|
45
|
-
*
|
|
38
|
+
* Hocuspocus websocket provider
|
|
46
39
|
*/
|
|
47
|
-
|
|
40
|
+
websocketProvider: HocuspocusProviderWebsocket;
|
|
48
41
|
/**
|
|
49
42
|
* Force syncing the document in the defined interval.
|
|
50
43
|
*/
|
|
51
44
|
forceSyncInterval: false | number;
|
|
52
|
-
/**
|
|
53
|
-
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
54
|
-
*/
|
|
55
|
-
messageReconnectTimeout: number;
|
|
56
|
-
/**
|
|
57
|
-
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
58
|
-
*/
|
|
59
|
-
delay: number;
|
|
60
|
-
/**
|
|
61
|
-
* The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
|
|
62
|
-
*/
|
|
63
|
-
initialDelay: number;
|
|
64
|
-
/**
|
|
65
|
-
* The factor option is used to grow the delay exponentially.
|
|
66
|
-
*/
|
|
67
|
-
factor: number;
|
|
68
|
-
/**
|
|
69
|
-
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
70
|
-
*/
|
|
71
|
-
maxAttempts: number;
|
|
72
|
-
/**
|
|
73
|
-
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
74
|
-
*/
|
|
75
|
-
minDelay: number;
|
|
76
|
-
/**
|
|
77
|
-
* The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
|
|
78
|
-
*/
|
|
79
|
-
maxDelay: number;
|
|
80
|
-
/**
|
|
81
|
-
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
82
|
-
*/
|
|
83
|
-
jitter: boolean;
|
|
84
|
-
/**
|
|
85
|
-
* A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
|
|
86
|
-
*/
|
|
87
|
-
timeout: number;
|
|
88
45
|
onAuthenticated: () => void;
|
|
89
46
|
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
90
47
|
onOpen: (data: onOpenParameters) => void;
|
|
@@ -98,6 +55,7 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
98
55
|
onDestroy: () => void;
|
|
99
56
|
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
100
57
|
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
58
|
+
onStateless: (data: onStatelessParameters) => void;
|
|
101
59
|
/**
|
|
102
60
|
* Don’t output any warnings.
|
|
103
61
|
*/
|
|
@@ -106,53 +64,39 @@ export interface CompleteHocuspocusProviderConfiguration {
|
|
|
106
64
|
export declare class HocuspocusProvider extends EventEmitter {
|
|
107
65
|
configuration: CompleteHocuspocusProviderConfiguration;
|
|
108
66
|
subscribedToBroadcastChannel: boolean;
|
|
109
|
-
webSocket: WebSocket | null;
|
|
110
|
-
shouldConnect: boolean;
|
|
111
|
-
status: WebSocketStatus;
|
|
112
67
|
isSynced: boolean;
|
|
113
68
|
unsyncedChanges: number;
|
|
69
|
+
status: WebSocketStatus;
|
|
114
70
|
isAuthenticated: boolean;
|
|
115
|
-
lastMessageReceived: number;
|
|
116
71
|
mux: mutex.mutex;
|
|
117
72
|
intervals: any;
|
|
118
|
-
connectionAttempt: {
|
|
119
|
-
resolve: (value?: any) => void;
|
|
120
|
-
reject: (reason?: any) => void;
|
|
121
|
-
} | null;
|
|
122
73
|
constructor(configuration: HocuspocusProviderConfiguration);
|
|
74
|
+
onStatus({ status }: onStatusParameters): void;
|
|
123
75
|
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
124
|
-
boundConnect: () => Promise<unknown>;
|
|
125
|
-
cancelWebsocketRetry?: () => void;
|
|
126
|
-
connect(): Promise<unknown>;
|
|
127
|
-
createWebSocketConnection(): Promise<unknown>;
|
|
128
|
-
resolveConnectionAttempt(): void;
|
|
129
|
-
stopConnectionAttempt(): void;
|
|
130
|
-
rejectConnectionAttempt(): void;
|
|
131
76
|
get document(): Y.Doc;
|
|
132
77
|
get awareness(): Awareness;
|
|
133
78
|
get hasUnsyncedChanges(): boolean;
|
|
134
|
-
checkConnection(): void;
|
|
135
79
|
forceSync(): void;
|
|
136
80
|
boundBeforeUnload: () => void;
|
|
137
81
|
beforeUnload(): void;
|
|
138
82
|
registerEventListeners(): void;
|
|
83
|
+
sendStateless(payload: string): void;
|
|
139
84
|
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
140
85
|
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
141
|
-
permissionDeniedHandler(reason: string): void;
|
|
142
|
-
authenticatedHandler(): void;
|
|
143
|
-
get serverUrl(): string;
|
|
144
|
-
get url(): string;
|
|
145
86
|
get synced(): boolean;
|
|
146
87
|
set synced(state: boolean);
|
|
88
|
+
receiveStateless(payload: string): void;
|
|
147
89
|
get isAuthenticationRequired(): boolean;
|
|
148
90
|
disconnect(): void;
|
|
149
91
|
onOpen(event: Event): Promise<void>;
|
|
150
92
|
getToken(): Promise<string | null>;
|
|
151
93
|
startSync(): void;
|
|
152
|
-
send(
|
|
94
|
+
send(message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
|
|
153
95
|
onMessage(event: MessageEvent): void;
|
|
154
96
|
onClose(event: CloseEvent): void;
|
|
155
97
|
destroy(): void;
|
|
98
|
+
permissionDeniedHandler(reason: string): void;
|
|
99
|
+
authenticatedHandler(): void;
|
|
156
100
|
get broadcastChannel(): string;
|
|
157
101
|
boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
|
|
158
102
|
broadcastChannelSubscriber(data: ArrayBuffer): void;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as mutex from 'lib0/mutex';
|
|
2
|
+
import type { MessageEvent } from 'ws';
|
|
3
|
+
import { Event } from 'ws';
|
|
4
|
+
import EventEmitter from './EventEmitter';
|
|
5
|
+
import { onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, WebSocketStatus } from './types';
|
|
6
|
+
import { HocuspocusProvider, onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
7
|
+
export declare type HocuspocusProviderWebsocketConfiguration = Required<Pick<CompleteHocuspocusProviderWebsocketConfiguration, 'url'>> & Partial<CompleteHocuspocusProviderWebsocketConfiguration>;
|
|
8
|
+
export interface CompleteHocuspocusProviderWebsocketConfiguration {
|
|
9
|
+
/**
|
|
10
|
+
* URL of your @hocuspocus/server instance
|
|
11
|
+
*/
|
|
12
|
+
url: string;
|
|
13
|
+
/**
|
|
14
|
+
* Pass `false` to start the connection manually.
|
|
15
|
+
*/
|
|
16
|
+
connect: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* URL parameters that should be added.
|
|
19
|
+
*/
|
|
20
|
+
parameters: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* An optional WebSocket polyfill, for example for Node.js
|
|
25
|
+
*/
|
|
26
|
+
WebSocketPolyfill: any;
|
|
27
|
+
/**
|
|
28
|
+
* Disconnect when no message is received for the defined amount of milliseconds.
|
|
29
|
+
*/
|
|
30
|
+
messageReconnectTimeout: number;
|
|
31
|
+
/**
|
|
32
|
+
* The delay between each attempt in milliseconds. You can provide a factor to have the delay grow exponentially.
|
|
33
|
+
*/
|
|
34
|
+
delay: number;
|
|
35
|
+
/**
|
|
36
|
+
* The intialDelay is the amount of time to wait before making the first attempt. This option should typically be 0 since you typically want the first attempt to happen immediately.
|
|
37
|
+
*/
|
|
38
|
+
initialDelay: number;
|
|
39
|
+
/**
|
|
40
|
+
* The factor option is used to grow the delay exponentially.
|
|
41
|
+
*/
|
|
42
|
+
factor: number;
|
|
43
|
+
/**
|
|
44
|
+
* The maximum number of attempts or 0 if there is no limit on number of attempts.
|
|
45
|
+
*/
|
|
46
|
+
maxAttempts: number;
|
|
47
|
+
/**
|
|
48
|
+
* minDelay is used to set a lower bound of delay when jitter is enabled. This property has no effect if jitter is disabled.
|
|
49
|
+
*/
|
|
50
|
+
minDelay: number;
|
|
51
|
+
/**
|
|
52
|
+
* The maxDelay option is used to set an upper bound for the delay when factor is enabled. A value of 0 can be provided if there should be no upper bound when calculating delay.
|
|
53
|
+
*/
|
|
54
|
+
maxDelay: number;
|
|
55
|
+
/**
|
|
56
|
+
* If jitter is true then the calculated delay will be a random integer value between minDelay and the calculated delay for the current iteration.
|
|
57
|
+
*/
|
|
58
|
+
jitter: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* A timeout in milliseconds. If timeout is non-zero then a timer is set using setTimeout. If the timeout is triggered then future attempts will be aborted.
|
|
61
|
+
*/
|
|
62
|
+
timeout: number;
|
|
63
|
+
onOpen: (data: onOpenParameters) => void;
|
|
64
|
+
onConnect: () => void;
|
|
65
|
+
onMessage: (data: onMessageParameters) => void;
|
|
66
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
67
|
+
onStatus: (data: onStatusParameters) => void;
|
|
68
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
69
|
+
onClose: (data: onCloseParameters) => void;
|
|
70
|
+
onDestroy: () => void;
|
|
71
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
72
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Don’t output any warnings.
|
|
75
|
+
*/
|
|
76
|
+
quiet: boolean;
|
|
77
|
+
}
|
|
78
|
+
export declare class HocuspocusProviderWebsocket extends EventEmitter {
|
|
79
|
+
configuration: CompleteHocuspocusProviderWebsocketConfiguration;
|
|
80
|
+
subscribedToBroadcastChannel: boolean;
|
|
81
|
+
webSocket: WebSocket | null;
|
|
82
|
+
shouldConnect: boolean;
|
|
83
|
+
status: WebSocketStatus;
|
|
84
|
+
lastMessageReceived: number;
|
|
85
|
+
mux: mutex.mutex;
|
|
86
|
+
intervals: any;
|
|
87
|
+
connectionAttempt: {
|
|
88
|
+
resolve: (value?: any) => void;
|
|
89
|
+
reject: (reason?: any) => void;
|
|
90
|
+
} | null;
|
|
91
|
+
constructor(configuration: HocuspocusProviderWebsocketConfiguration);
|
|
92
|
+
receivedOnOpenPayload?: Event | undefined;
|
|
93
|
+
receivedOnStatusPayload?: onStatusParameters | undefined;
|
|
94
|
+
onOpen(event: Event): Promise<void>;
|
|
95
|
+
onStatus(data: onStatusParameters): Promise<void>;
|
|
96
|
+
attach(provider: HocuspocusProvider): void;
|
|
97
|
+
detach(provider: HocuspocusProvider): void;
|
|
98
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderWebsocketConfiguration>): void;
|
|
99
|
+
boundConnect: () => Promise<unknown>;
|
|
100
|
+
cancelWebsocketRetry?: () => void;
|
|
101
|
+
connect(): Promise<unknown>;
|
|
102
|
+
createWebSocketConnection(): Promise<unknown>;
|
|
103
|
+
onMessage(event: MessageEvent): void;
|
|
104
|
+
resolveConnectionAttempt(): void;
|
|
105
|
+
stopConnectionAttempt(): void;
|
|
106
|
+
rejectConnectionAttempt(): void;
|
|
107
|
+
checkConnection(): void;
|
|
108
|
+
registerEventListeners(): void;
|
|
109
|
+
get serverUrl(): string;
|
|
110
|
+
get url(): string;
|
|
111
|
+
disconnect(): void;
|
|
112
|
+
send(message: any): void;
|
|
113
|
+
onClose({ event }: onCloseParameters): void;
|
|
114
|
+
destroy(): void;
|
|
115
|
+
}
|
|
@@ -7,8 +7,10 @@ export declare class IncomingMessage {
|
|
|
7
7
|
decoder: Decoder;
|
|
8
8
|
constructor(data: any);
|
|
9
9
|
readVarUint(): MessageType;
|
|
10
|
+
readVarString(): string;
|
|
10
11
|
readVarUint8Array(): Uint8Array;
|
|
11
12
|
writeVarUint(type: MessageType): void;
|
|
13
|
+
writeVarString(string: string): void;
|
|
12
14
|
writeVarUint8Array(data: Uint8Array): void;
|
|
13
15
|
length(): number;
|
|
14
16
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
2
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
3
|
+
export declare class StatelessMessage extends OutgoingMessage {
|
|
4
|
+
type: MessageType;
|
|
5
|
+
description: string;
|
|
6
|
+
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
7
|
+
}
|
|
@@ -14,7 +14,8 @@ export declare enum MessageType {
|
|
|
14
14
|
Sync = 0,
|
|
15
15
|
Awareness = 1,
|
|
16
16
|
Auth = 2,
|
|
17
|
-
QueryAwareness = 3
|
|
17
|
+
QueryAwareness = 3,
|
|
18
|
+
Stateless = 5
|
|
18
19
|
}
|
|
19
20
|
export declare enum WebSocketStatus {
|
|
20
21
|
Connecting = "connecting",
|
|
@@ -26,6 +27,7 @@ export interface OutgoingMessageInterface {
|
|
|
26
27
|
type?: MessageType;
|
|
27
28
|
}
|
|
28
29
|
export interface OutgoingMessageArguments {
|
|
30
|
+
documentName: string;
|
|
29
31
|
token: string;
|
|
30
32
|
document: Y.Doc;
|
|
31
33
|
awareness: Awareness;
|
|
@@ -34,6 +36,7 @@ export interface OutgoingMessageArguments {
|
|
|
34
36
|
[key: string]: any;
|
|
35
37
|
}>;
|
|
36
38
|
update: any;
|
|
39
|
+
payload: string;
|
|
37
40
|
encoder: Encoder;
|
|
38
41
|
}
|
|
39
42
|
export interface Constructable<T> {
|
|
@@ -71,6 +74,9 @@ export declare type onAwarenessUpdateParameters = {
|
|
|
71
74
|
export declare type onAwarenessChangeParameters = {
|
|
72
75
|
states: StatesArray;
|
|
73
76
|
};
|
|
77
|
+
export declare type onStatelessParameters = {
|
|
78
|
+
payload: string;
|
|
79
|
+
};
|
|
74
80
|
export declare type StatesArray = {
|
|
75
81
|
clientId: number;
|
|
76
82
|
[key: string | number]: any;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage as HTTPIncomingMessage } from 'http';
|
|
2
3
|
import AsyncLock from 'async-lock';
|
|
3
4
|
import WebSocket from 'ws';
|
|
4
|
-
import { IncomingMessage as HTTPIncomingMessage } from 'http';
|
|
5
5
|
import { CloseEvent } from '@hocuspocus/common';
|
|
6
6
|
import Document from './Document';
|
|
7
7
|
import { Debugger } from './Debugger';
|
|
8
|
+
import { onStatelessPayload } from './types';
|
|
8
9
|
export declare class Connection {
|
|
9
10
|
webSocket: WebSocket;
|
|
10
11
|
context: any;
|
|
@@ -26,6 +27,10 @@ export declare class Connection {
|
|
|
26
27
|
* Set a callback that will be triggered when the connection is closed
|
|
27
28
|
*/
|
|
28
29
|
onClose(callback: (document: Document) => void): Connection;
|
|
30
|
+
/**
|
|
31
|
+
* Set a callback that will be triggered when an stateless message is received
|
|
32
|
+
*/
|
|
33
|
+
onStatelessCallback(callback: (payload: onStatelessPayload) => Promise<void>): Connection;
|
|
29
34
|
/**
|
|
30
35
|
* Set a callback that will be triggered before an message is handled
|
|
31
36
|
*/
|
|
@@ -34,6 +39,10 @@ export declare class Connection {
|
|
|
34
39
|
* Send the given message
|
|
35
40
|
*/
|
|
36
41
|
send(message: any): void;
|
|
42
|
+
/**
|
|
43
|
+
* Send a stateless message with payload
|
|
44
|
+
*/
|
|
45
|
+
sendStateless(payload: string): void;
|
|
37
46
|
/**
|
|
38
47
|
* Graceful wrapper around the WebSocket close method.
|
|
39
48
|
*/
|
|
@@ -53,15 +62,5 @@ export declare class Connection {
|
|
|
53
62
|
* @private
|
|
54
63
|
*/
|
|
55
64
|
private handleMessage;
|
|
56
|
-
/**
|
|
57
|
-
* Get the underlying connection instance
|
|
58
|
-
* @deprecated
|
|
59
|
-
*/
|
|
60
|
-
get instance(): WebSocket;
|
|
61
|
-
/**
|
|
62
|
-
* Get the underlying connection instance
|
|
63
|
-
* @deprecated
|
|
64
|
-
*/
|
|
65
|
-
get connection(): WebSocket;
|
|
66
65
|
}
|
|
67
66
|
export default Connection;
|
|
@@ -8,6 +8,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
|
+
beforeBroadcastStateless: (document: Document, stateless: string) => void;
|
|
11
12
|
};
|
|
12
13
|
connections: Map<WebSocket, {
|
|
13
14
|
clients: Set<any>;
|
|
@@ -33,6 +34,10 @@ export declare class Document extends Doc {
|
|
|
33
34
|
* Set a callback that will be triggered when the document is updated
|
|
34
35
|
*/
|
|
35
36
|
onUpdate(callback: (document: Document, connection: Connection, update: Uint8Array) => void): Document;
|
|
37
|
+
/**
|
|
38
|
+
* Set a callback that will be triggered before a stateless message is broadcasted
|
|
39
|
+
*/
|
|
40
|
+
beforeBroadcastStateless(callback: (document: Document, stateless: string) => void): Document;
|
|
36
41
|
/**
|
|
37
42
|
* Register a connection and a set of clients on this document keyed by the
|
|
38
43
|
* underlying websocket connection
|
|
@@ -75,5 +80,9 @@ export declare class Document extends Doc {
|
|
|
75
80
|
* Handle an updated document and sync changes to clients
|
|
76
81
|
*/
|
|
77
82
|
private handleUpdate;
|
|
83
|
+
/**
|
|
84
|
+
* Broadcast stateless message to all connections
|
|
85
|
+
*/
|
|
86
|
+
broadcastStateless(payload: string): void;
|
|
78
87
|
}
|
|
79
88
|
export default Document;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
3
2
|
import { IncomingMessage, Server as HTTPServer } from 'http';
|
|
4
|
-
import {
|
|
3
|
+
import WebSocket, { AddressInfo, WebSocketServer } from 'ws';
|
|
4
|
+
import { Configuration, HookName, HookPayload, onListenPayload } from './types';
|
|
5
5
|
import Document from './Document';
|
|
6
6
|
import { Debugger } from './Debugger';
|
|
7
|
-
import { onListenPayload } from '.';
|
|
8
7
|
export declare const defaultConfiguration: {
|
|
9
8
|
name: null;
|
|
10
9
|
port: number;
|
|
@@ -68,7 +67,7 @@ export declare class Hocuspocus {
|
|
|
68
67
|
* … and if nothings fails it’ll fully establish the connection and
|
|
69
68
|
* load the Document then.
|
|
70
69
|
*/
|
|
71
|
-
handleConnection(incoming: WebSocket, request: IncomingMessage,
|
|
70
|
+
handleConnection(incoming: WebSocket, request: IncomingMessage, context?: any): void;
|
|
72
71
|
/**
|
|
73
72
|
* Handle update of the given document
|
|
74
73
|
*/
|
|
@@ -98,10 +97,6 @@ export declare class Hocuspocus {
|
|
|
98
97
|
* Get parameters by the given request
|
|
99
98
|
*/
|
|
100
99
|
private static getParameters;
|
|
101
|
-
/**
|
|
102
|
-
* Get document name by the given request
|
|
103
|
-
*/
|
|
104
|
-
private getDocumentNameFromRequest;
|
|
105
100
|
enableDebugging(): void;
|
|
106
101
|
enableMessageLogging(): void;
|
|
107
102
|
disableLogging(): void;
|
|
@@ -13,7 +13,9 @@ export declare class IncomingMessage {
|
|
|
13
13
|
constructor(input: any);
|
|
14
14
|
readVarUint8Array(): Uint8Array;
|
|
15
15
|
readVarUint(): number;
|
|
16
|
+
readVarString(): string;
|
|
16
17
|
toUint8Array(): Uint8Array;
|
|
17
18
|
writeVarUint(type: MessageType): void;
|
|
19
|
+
writeVarString(string: string): void;
|
|
18
20
|
get length(): number;
|
|
19
21
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Awareness } from 'y-protocols/awareness';
|
|
2
1
|
import Connection from './Connection';
|
|
3
2
|
import { IncomingMessage } from './IncomingMessage';
|
|
4
3
|
import { Debugger } from './Debugger';
|
|
@@ -9,5 +8,5 @@ export declare class MessageReceiver {
|
|
|
9
8
|
constructor(message: IncomingMessage, logger: Debugger);
|
|
10
9
|
apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): void;
|
|
11
10
|
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): 0 | 2 | 1;
|
|
12
|
-
applyQueryAwarenessMessage(
|
|
11
|
+
applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
|
|
13
12
|
}
|
|
@@ -5,7 +5,7 @@ export declare class OutgoingMessage {
|
|
|
5
5
|
encoder: Encoder;
|
|
6
6
|
type?: number;
|
|
7
7
|
category?: string;
|
|
8
|
-
constructor();
|
|
8
|
+
constructor(documentName: string);
|
|
9
9
|
createSyncMessage(): OutgoingMessage;
|
|
10
10
|
createSyncReplyMessage(): OutgoingMessage;
|
|
11
11
|
createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
|
|
@@ -14,5 +14,7 @@ export declare class OutgoingMessage {
|
|
|
14
14
|
writePermissionDenied(reason: string): OutgoingMessage;
|
|
15
15
|
writeFirstSyncStepFor(document: Document): OutgoingMessage;
|
|
16
16
|
writeUpdate(update: Uint8Array): OutgoingMessage;
|
|
17
|
+
writeStateless(payload: string): OutgoingMessage;
|
|
18
|
+
writeBroadcastStateless(payload: string): OutgoingMessage;
|
|
17
19
|
toUint8Array(): Uint8Array;
|
|
18
20
|
}
|
|
@@ -4,13 +4,16 @@ import { URLSearchParams } from 'url';
|
|
|
4
4
|
import { Awareness } from 'y-protocols/awareness';
|
|
5
5
|
import Document from './Document';
|
|
6
6
|
import { Hocuspocus } from './Hocuspocus';
|
|
7
|
+
import Connection from './Connection';
|
|
7
8
|
export declare enum MessageType {
|
|
8
9
|
Unknown = -1,
|
|
9
10
|
Sync = 0,
|
|
10
11
|
Awareness = 1,
|
|
11
12
|
Auth = 2,
|
|
12
13
|
QueryAwareness = 3,
|
|
13
|
-
SyncReply = 4
|
|
14
|
+
SyncReply = 4,
|
|
15
|
+
Stateless = 5,
|
|
16
|
+
BroadcastStateless = 6
|
|
14
17
|
}
|
|
15
18
|
export interface AwarenessUpdate {
|
|
16
19
|
added: Array<any>;
|
|
@@ -33,6 +36,8 @@ export interface Extension {
|
|
|
33
36
|
onLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
34
37
|
afterLoadDocument?(data: onLoadDocumentPayload): Promise<any>;
|
|
35
38
|
beforeHandleMessage?(data: beforeHandleMessagePayload): Promise<any>;
|
|
39
|
+
beforeBroadcastStateless?(data: beforeBroadcastStatelessPayload): Promise<any>;
|
|
40
|
+
onStateless?(payload: onStatelessPayload): Promise<any>;
|
|
36
41
|
onChange?(data: onChangePayload): Promise<any>;
|
|
37
42
|
onStoreDocument?(data: onStoreDocumentPayload): Promise<any>;
|
|
38
43
|
afterStoreDocument?(data: afterStoreDocumentPayload): Promise<any>;
|
|
@@ -41,8 +46,8 @@ export interface Extension {
|
|
|
41
46
|
onDisconnect?(data: onDisconnectPayload): Promise<any>;
|
|
42
47
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
43
48
|
}
|
|
44
|
-
export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
45
|
-
export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
|
|
49
|
+
export declare type HookName = 'onConfigure' | 'onListen' | 'onUpgrade' | 'onConnect' | 'connected' | 'onAuthenticate' | 'onLoadDocument' | 'afterLoadDocument' | 'beforeHandleMessage' | 'beforeBroadcastStateless' | 'onStateless' | 'onChange' | 'onStoreDocument' | 'afterStoreDocument' | 'onAwarenessUpdate' | 'onRequest' | 'onDisconnect' | 'onDestroy';
|
|
50
|
+
export declare type HookPayload = onConfigurePayload | onListenPayload | onUpgradePayload | onConnectPayload | connectedPayload | onAuthenticatePayload | onLoadDocumentPayload | onStatelessPayload | beforeHandleMessagePayload | beforeBroadcastStatelessPayload | onChangePayload | onStoreDocumentPayload | afterStoreDocumentPayload | onAwarenessUpdatePayload | onRequestPayload | onDisconnectPayload | onDestroyPayload;
|
|
46
51
|
export interface Configuration extends Extension {
|
|
47
52
|
/**
|
|
48
53
|
* A name for the instance, used for logging.
|
|
@@ -94,6 +99,12 @@ export interface getDocumentNamePayload {
|
|
|
94
99
|
request: IncomingMessage;
|
|
95
100
|
requestParameters: URLSearchParams;
|
|
96
101
|
}
|
|
102
|
+
export interface onStatelessPayload {
|
|
103
|
+
connection: Connection;
|
|
104
|
+
documentName: string;
|
|
105
|
+
document: Document;
|
|
106
|
+
payload: string;
|
|
107
|
+
}
|
|
97
108
|
export interface onAuthenticatePayload {
|
|
98
109
|
documentName: string;
|
|
99
110
|
instance: Hocuspocus;
|
|
@@ -163,6 +174,11 @@ export interface beforeHandleMessagePayload {
|
|
|
163
174
|
update: Uint8Array;
|
|
164
175
|
socketId: string;
|
|
165
176
|
}
|
|
177
|
+
export interface beforeBroadcastStatelessPayload {
|
|
178
|
+
document: Document;
|
|
179
|
+
documentName: string;
|
|
180
|
+
payload: string;
|
|
181
|
+
}
|
|
166
182
|
export interface onStoreDocumentPayload {
|
|
167
183
|
clientsCount: number;
|
|
168
184
|
context: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,6 +2,7 @@ export * from './createDirectory';
|
|
|
2
2
|
export * from './flushRedis';
|
|
3
3
|
export * from './newHocuspocus';
|
|
4
4
|
export * from './newHocuspocusProvider';
|
|
5
|
+
export * from './newHocuspocusProviderWebsocket';
|
|
5
6
|
export * from './randomInteger';
|
|
6
7
|
export * from './redisConnectionSettings';
|
|
7
8
|
export * from './removeDirectory';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HocuspocusProvider, HocuspocusProviderConfiguration } from '@hocuspocus/provider';
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
|
|
2
2
|
import { Hocuspocus } from '@hocuspocus/server';
|
|
3
|
-
export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<
|
|
3
|
+
export declare const newHocuspocusProvider: (server: Hocuspocus, options?: Partial<HocuspocusProviderConfiguration>, websocketOptions?: Partial<HocuspocusProviderWebsocketConfiguration>) => HocuspocusProvider;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration } from '@hocuspocus/provider';
|
|
2
|
+
import { Hocuspocus } from '@hocuspocus/server';
|
|
3
|
+
export declare const newHocuspocusProviderWebsocket: (server: Hocuspocus, options?: Partial<Omit<HocuspocusProviderWebsocketConfiguration, 'url'>>) => HocuspocusProviderWebsocket;
|
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": "
|
|
4
|
+
"version": "2.0.0-alpha.0",
|
|
5
5
|
"homepage": "https://hocuspocus.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"hocuspocus",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dist"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@hocuspocus/server": "^
|
|
29
|
+
"@hocuspocus/server": "^2.0.0-alpha.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"yjs": "^13.5.29"
|
|
File without changes
|
|
File without changes
|