@hocuspocus/common 1.0.0-alpha.10
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/LICENSE.md +21 -0
- package/README.md +14 -0
- package/dist/hocuspocus-common.cjs +280 -0
- package/dist/hocuspocus-common.cjs.map +1 -0
- package/dist/hocuspocus-common.esm.js +268 -0
- package/dist/hocuspocus-common.esm.js.map +1 -0
- package/dist/packages/common/src/CloseEvents.d.ts +23 -0
- package/dist/packages/common/src/auth.d.ts +6 -0
- package/dist/packages/common/src/awarenessStatesToArray.d.ts +3 -0
- package/dist/packages/common/src/index.d.ts +4 -0
- package/dist/packages/common/src/types.d.ts +10 -0
- package/dist/packages/extension-database/src/Database.d.ts +32 -0
- package/dist/packages/extension-database/src/index.d.ts +1 -0
- package/dist/packages/extension-logger/src/Logger.d.ts +67 -0
- package/dist/packages/extension-logger/src/index.d.ts +1 -0
- package/dist/packages/extension-monitor/src/Collector.d.ts +60 -0
- package/dist/packages/extension-monitor/src/Dashboard.d.ts +29 -0
- package/dist/packages/extension-monitor/src/Storage.d.ts +35 -0
- package/dist/packages/extension-monitor/src/index.d.ts +38 -0
- package/dist/packages/extension-redis/src/Redis.d.ts +16 -0
- package/dist/packages/extension-redis/src/RedisCluster.d.ts +4 -0
- package/dist/packages/extension-redis/src/index.d.ts +2 -0
- package/dist/packages/extension-rocksdb/src/index.d.ts +22 -0
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +26 -0
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
- package/dist/packages/extension-throttle/src/index.d.ts +24 -0
- package/dist/packages/extension-webhook/src/index.d.ts +58 -0
- package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
- package/dist/packages/provider/src/HocuspocusCloudProvider.d.ts +11 -0
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +156 -0
- package/dist/packages/provider/src/IncomingMessage.d.ts +14 -0
- package/dist/packages/provider/src/MessageReceiver.d.ts +13 -0
- package/dist/packages/provider/src/MessageSender.d.ts +10 -0
- package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +7 -0
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +7 -0
- package/dist/packages/provider/src/index.d.ts +3 -0
- package/dist/packages/provider/src/types.d.ts +77 -0
- package/dist/packages/server/src/Connection.d.ts +63 -0
- package/dist/packages/server/src/Debugger.d.ts +14 -0
- package/dist/packages/server/src/Document.d.ts +78 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +107 -0
- package/dist/packages/server/src/IncomingMessage.d.ts +19 -0
- package/dist/packages/server/src/MessageReceiver.d.ts +13 -0
- package/dist/packages/server/src/OutgoingMessage.d.ts +17 -0
- package/dist/packages/server/src/index.d.ts +9 -0
- package/dist/packages/server/src/types.d.ts +216 -0
- package/dist/packages/transformer/src/Prosemirror.d.ts +11 -0
- package/dist/packages/transformer/src/Tiptap.d.ts +10 -0
- package/dist/packages/transformer/src/index.d.ts +3 -0
- package/dist/packages/transformer/src/types.d.ts +5 -0
- package/dist/playground/backend/src/default.d.ts +1 -0
- package/dist/playground/backend/src/express.d.ts +1 -0
- package/dist/playground/backend/src/koa.d.ts +1 -0
- package/dist/playground/backend/src/load-document.d.ts +1 -0
- package/dist/playground/backend/src/monitor.d.ts +1 -0
- package/dist/playground/backend/src/redis.d.ts +1 -0
- package/dist/playground/backend/src/slow.d.ts +1 -0
- package/dist/playground/backend/src/webhook.d.ts +1 -0
- package/dist/tests/extension-logger/onListen.d.ts +1 -0
- package/dist/tests/extension-redis/onLoadDocument.d.ts +1 -0
- package/dist/tests/extension-redis/onSynced.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/closeConnections.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/getConnectionCount.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/getDocumentsCount.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onAwarenessChange.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onChange.d.ts +1 -0
- package/dist/tests/extension-redis-rewrite/onStoreDocument.d.ts +1 -0
- package/dist/tests/extension-rocksdb/onLoadDocument.d.ts +1 -0
- package/dist/tests/extension-throttle/configuration.d.ts +1 -0
- package/dist/tests/provider/configuration.d.ts +1 -0
- package/dist/tests/provider/observe.d.ts +1 -0
- package/dist/tests/provider/observeDeep.d.ts +1 -0
- package/dist/tests/provider/onAuthenticated.d.ts +1 -0
- package/dist/tests/provider/onAuthenticationFailed.d.ts +1 -0
- package/dist/tests/provider/onAwarenessChange.d.ts +1 -0
- package/dist/tests/provider/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/provider/onClose.d.ts +1 -0
- package/dist/tests/provider/onConnect.d.ts +1 -0
- package/dist/tests/provider/onDisconnect.d.ts +1 -0
- package/dist/tests/provider/onMessage.d.ts +1 -0
- package/dist/tests/provider/onOpen.d.ts +1 -0
- package/dist/tests/provider/onSynced.d.ts +1 -0
- package/dist/tests/server/address.d.ts +1 -0
- package/dist/tests/server/afterStoreDocument.d.ts +1 -0
- package/dist/tests/server/closeConnections.d.ts +1 -0
- package/dist/tests/server/getConnectionsCount.d.ts +1 -0
- package/dist/tests/server/getDocumentName.d.ts +1 -0
- package/dist/tests/server/getDocumentsCount.d.ts +1 -0
- package/dist/tests/server/getMessageLogs.d.ts +1 -0
- package/dist/tests/server/listen.d.ts +1 -0
- package/dist/tests/server/onAuthenticate.d.ts +1 -0
- package/dist/tests/server/onAwarenessUpdate.d.ts +1 -0
- package/dist/tests/server/onChange.d.ts +1 -0
- package/dist/tests/server/onConfigure.d.ts +1 -0
- package/dist/tests/server/onConnect.d.ts +1 -0
- package/dist/tests/server/onDestroy.d.ts +1 -0
- package/dist/tests/server/onDisconnect.d.ts +1 -0
- package/dist/tests/server/onListen.d.ts +1 -0
- package/dist/tests/server/onLoadDocument.d.ts +1 -0
- package/dist/tests/server/onRequest.d.ts +1 -0
- package/dist/tests/server/onStoreDocument.d.ts +1 -0
- package/dist/tests/server/onUpgrade.d.ts +1 -0
- package/dist/tests/server/requiresAuthentication.d.ts +1 -0
- package/dist/tests/transformer/TiptapTransformer.d.ts +1 -0
- package/dist/tests/utils/createDirectory.d.ts +1 -0
- package/dist/tests/utils/flushRedis.d.ts +1 -0
- package/dist/tests/utils/index.d.ts +7 -0
- package/dist/tests/utils/newHocuspocus.d.ts +2 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
- package/dist/tests/utils/removeDirectory.d.ts +1 -0
- package/dist/tests/utils/sleep.d.ts +1 -0
- package/package.json +31 -0
- package/src/CloseEvents.ts +39 -0
- package/src/auth.ts +40 -0
- package/src/awarenessStatesToArray.ts +8 -0
- package/src/index.ts +4 -0
- package/src/types.ts +10 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
export declare class Storage extends EventEmitter {
|
|
4
|
+
timed: Map<string, any>;
|
|
5
|
+
constant: Map<string, any>;
|
|
6
|
+
/**
|
|
7
|
+
* Get all constant values.
|
|
8
|
+
*/
|
|
9
|
+
all(): Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* Get a constant value by the given key.
|
|
12
|
+
*/
|
|
13
|
+
get(key: string, defaultValue?: any): Promise<any>;
|
|
14
|
+
/**
|
|
15
|
+
* Set a constant value by the given key.
|
|
16
|
+
*/
|
|
17
|
+
set(key: string, value: any): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Delete a constant value by the given key.
|
|
20
|
+
* @param key
|
|
21
|
+
*/
|
|
22
|
+
delete(key: string): Promise<any>;
|
|
23
|
+
/**
|
|
24
|
+
* Get all timed values.
|
|
25
|
+
*/
|
|
26
|
+
allTimed(): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Add a timed value by the given key.
|
|
29
|
+
*/
|
|
30
|
+
add(key: string, value: any): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* Remove a timed value by the given timestamp and key.
|
|
33
|
+
*/
|
|
34
|
+
remove(key: string, timestamp: string): Promise<any>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Extension, onChangePayload, onConfigurePayload, onLoadDocumentPayload, onDisconnectPayload, onRequestPayload, onUpgradePayload, connectedPayload } from '@hocuspocus/server';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
+
import WebSocket from 'ws';
|
|
5
|
+
import { Storage } from './Storage';
|
|
6
|
+
import { Dashboard } from './Dashboard';
|
|
7
|
+
import { Collector } from './Collector';
|
|
8
|
+
export interface Configuration {
|
|
9
|
+
dashboardPath: string;
|
|
10
|
+
enableDashboard: boolean;
|
|
11
|
+
metricsInterval: number;
|
|
12
|
+
osMetricsInterval: number;
|
|
13
|
+
password: string | undefined;
|
|
14
|
+
port: number | undefined;
|
|
15
|
+
user: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
export declare class Monitor implements Extension {
|
|
18
|
+
configuration: Configuration;
|
|
19
|
+
storage: Storage;
|
|
20
|
+
collector: Collector;
|
|
21
|
+
dashboard?: Dashboard;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor
|
|
24
|
+
*/
|
|
25
|
+
constructor(configuration?: Partial<Configuration>);
|
|
26
|
+
private collectOsMetrics;
|
|
27
|
+
private collectConnectionMetrics;
|
|
28
|
+
private cleanMetrics;
|
|
29
|
+
handleRequest(request: IncomingMessage, response: ServerResponse): boolean | undefined;
|
|
30
|
+
handleConnection(websocket: WebSocket, request: IncomingMessage): void | undefined;
|
|
31
|
+
onRequest({ request, response }: onRequestPayload): Promise<void>;
|
|
32
|
+
onUpgrade({ request, socket, head }: onUpgradePayload): Promise<void>;
|
|
33
|
+
connected(data: connectedPayload): Promise<void>;
|
|
34
|
+
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
35
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
36
|
+
onChange(data: onChangePayload): Promise<void>;
|
|
37
|
+
onConfigure(data: onConfigurePayload): Promise<void>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RedisPersistence } from 'y-redis';
|
|
2
|
+
import { Extension, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
|
+
export interface Configuration {
|
|
4
|
+
}
|
|
5
|
+
export declare class Redis implements Extension {
|
|
6
|
+
configuration: Configuration;
|
|
7
|
+
cluster: boolean;
|
|
8
|
+
persistence: RedisPersistence | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor(configuration?: Partial<Configuration>);
|
|
13
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<import("yjs").Doc | undefined>;
|
|
14
|
+
onConnect(data: onConnectPayload): Promise<void>;
|
|
15
|
+
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Extension, onLoadDocumentPayload } from '@hocuspocus/server';
|
|
2
|
+
import { LeveldbPersistence } from 'y-leveldb';
|
|
3
|
+
export interface Configuration {
|
|
4
|
+
options: object | undefined;
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class RocksDB implements Extension {
|
|
8
|
+
configuration: Configuration;
|
|
9
|
+
provider: LeveldbPersistence;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor(configuration?: Partial<Configuration>);
|
|
14
|
+
/**
|
|
15
|
+
* onLoadDocument hook
|
|
16
|
+
*/
|
|
17
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* store updates in y-leveldb persistence
|
|
20
|
+
*/
|
|
21
|
+
store(documentName: string, update: Uint8Array): Promise<any>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Database, DatabaseConfiguration } from '@hocuspocus/extension-database';
|
|
2
|
+
import sqlite3 from 'sqlite3';
|
|
3
|
+
export declare const schema = "CREATE TABLE IF NOT EXISTS \"documents\" (\n \"name\" varchar(255) NOT NULL,\n \"data\" blob NOT NULL,\n UNIQUE(name)\n)";
|
|
4
|
+
export declare const selectQuery = "\n SELECT data FROM \"documents\" WHERE name = $name ORDER BY rowid DESC\n";
|
|
5
|
+
export declare const upsertQuery = "\n INSERT INTO \"documents\" (\"name\", \"data\") VALUES ($name, $data)\n ON CONFLICT(name) DO UPDATE SET data = $data\n";
|
|
6
|
+
export interface SQLiteConfiguration extends DatabaseConfiguration {
|
|
7
|
+
/**
|
|
8
|
+
* Valid values are filenames, ":memory:" for an anonymous in-memory database and an empty
|
|
9
|
+
* string for an anonymous disk-based database. Anonymous databases are not persisted and
|
|
10
|
+
* when closing the database handle, their contents are lost.
|
|
11
|
+
*
|
|
12
|
+
* https://github.com/mapbox/node-sqlite3/wiki/API#new-sqlite3databasefilename-mode-callback
|
|
13
|
+
*/
|
|
14
|
+
database: string;
|
|
15
|
+
/**
|
|
16
|
+
* The database schema to create.
|
|
17
|
+
*/
|
|
18
|
+
schema: string;
|
|
19
|
+
}
|
|
20
|
+
export declare class SQLite extends Database {
|
|
21
|
+
db?: sqlite3.Database;
|
|
22
|
+
configuration: SQLiteConfiguration;
|
|
23
|
+
constructor(configuration?: Partial<SQLiteConfiguration>);
|
|
24
|
+
onConfigure(): Promise<void>;
|
|
25
|
+
onListen(): Promise<void>;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SQLite';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Extension, onConnectPayload } from '@hocuspocus/server';
|
|
2
|
+
export interface ThrottleConfiguration {
|
|
3
|
+
throttle: number | null | false;
|
|
4
|
+
banTime: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class Throttle implements Extension {
|
|
7
|
+
configuration: ThrottleConfiguration;
|
|
8
|
+
connectionsByIp: Map<string, Array<number>>;
|
|
9
|
+
bannedIps: Map<string, number>;
|
|
10
|
+
/**
|
|
11
|
+
* Constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor(configuration?: Partial<ThrottleConfiguration>);
|
|
14
|
+
/**
|
|
15
|
+
* Throttle requests
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
private throttle;
|
|
19
|
+
/**
|
|
20
|
+
* onConnect hook
|
|
21
|
+
* @param data
|
|
22
|
+
*/
|
|
23
|
+
onConnect(data: onConnectPayload): Promise<any>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Extension, onChangePayload, onConnectPayload, onLoadDocumentPayload, onDisconnectPayload } from '@hocuspocus/server';
|
|
3
|
+
import { Doc } from 'yjs';
|
|
4
|
+
import { Transformer } from '@hocuspocus/transformer';
|
|
5
|
+
import { AxiosResponse } from 'axios';
|
|
6
|
+
export declare enum Events {
|
|
7
|
+
onChange = "change",
|
|
8
|
+
onConnect = "connect",
|
|
9
|
+
onCreate = "create",
|
|
10
|
+
onDisconnect = "disconnect"
|
|
11
|
+
}
|
|
12
|
+
export interface Configuration {
|
|
13
|
+
debounce: number | false | null;
|
|
14
|
+
debounceMaxWait: number;
|
|
15
|
+
secret: string;
|
|
16
|
+
transformer: Transformer | {
|
|
17
|
+
toYdoc: (document: any) => Doc;
|
|
18
|
+
fromYdoc: (document: Doc) => any;
|
|
19
|
+
};
|
|
20
|
+
url: string;
|
|
21
|
+
events: Array<Events>;
|
|
22
|
+
}
|
|
23
|
+
export declare class Webhook implements Extension {
|
|
24
|
+
configuration: Configuration;
|
|
25
|
+
debounced: Map<string, {
|
|
26
|
+
timeout: NodeJS.Timeout;
|
|
27
|
+
start: number;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Constructor
|
|
31
|
+
*/
|
|
32
|
+
constructor(configuration?: Partial<Configuration>);
|
|
33
|
+
/**
|
|
34
|
+
* Create a signature for the response body
|
|
35
|
+
*/
|
|
36
|
+
createSignature(body: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* debounce the given function, using the given identifier
|
|
39
|
+
*/
|
|
40
|
+
debounce(id: string, func: Function): void;
|
|
41
|
+
/**
|
|
42
|
+
* Send a request to the given url containing the given data
|
|
43
|
+
*/
|
|
44
|
+
sendRequest(event: Events, payload: any): Promise<AxiosResponse<any, any>>;
|
|
45
|
+
/**
|
|
46
|
+
* onChange hook
|
|
47
|
+
*/
|
|
48
|
+
onChange(data: onChangePayload): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* onLoadDocument hook
|
|
51
|
+
*/
|
|
52
|
+
onLoadDocument(data: onLoadDocumentPayload): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* onConnect hook
|
|
55
|
+
*/
|
|
56
|
+
onConnect(data: onConnectPayload): Promise<any>;
|
|
57
|
+
onDisconnect(data: onDisconnectPayload): Promise<void>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HocuspocusProvider, HocuspocusProviderConfiguration } from './HocuspocusProvider';
|
|
2
|
+
export declare type HocuspocusCloudProviderConfiguration = Required<Pick<HocuspocusProviderConfiguration, 'name'>> & Partial<HocuspocusProviderConfiguration> & AdditionalHocuspocusCloudProviderConfiguration;
|
|
3
|
+
export interface AdditionalHocuspocusCloudProviderConfiguration {
|
|
4
|
+
/**
|
|
5
|
+
* A Hocuspocus Cloud key, get one here: https://hocuspocus.cloud/
|
|
6
|
+
*/
|
|
7
|
+
key: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class HocuspocusCloudProvider extends HocuspocusProvider {
|
|
10
|
+
constructor(configuration: HocuspocusCloudProviderConfiguration);
|
|
11
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
3
|
+
import * as mutex from 'lib0/mutex';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
|
+
import EventEmitter from './EventEmitter';
|
|
6
|
+
import { ConstructableOutgoingMessage, onAuthenticationFailedParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatusParameters, onSyncedParameters, WebSocketStatus } from './types';
|
|
7
|
+
import { onAwarenessChangeParameters, onAwarenessUpdateParameters } from '.';
|
|
8
|
+
export declare type HocuspocusProviderConfiguration = Required<Pick<CompleteHocuspocusProviderConfiguration, 'url' | 'name'>> & Partial<CompleteHocuspocusProviderConfiguration>;
|
|
9
|
+
export interface CompleteHocuspocusProviderConfiguration {
|
|
10
|
+
/**
|
|
11
|
+
* URL of your @hocuspocus/server instance
|
|
12
|
+
*/
|
|
13
|
+
url: string;
|
|
14
|
+
/**
|
|
15
|
+
* The identifier/name of your document
|
|
16
|
+
*/
|
|
17
|
+
name: string;
|
|
18
|
+
/**
|
|
19
|
+
* The actual Y.js document
|
|
20
|
+
*/
|
|
21
|
+
document: Y.Doc;
|
|
22
|
+
/**
|
|
23
|
+
* Pass `false` to start the connection manually.
|
|
24
|
+
*/
|
|
25
|
+
connect: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Pass false to disable broadcasting between browser tabs.
|
|
28
|
+
*/
|
|
29
|
+
broadcast: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* An Awareness instance to keep the presence state of all clients.
|
|
32
|
+
*/
|
|
33
|
+
awareness: Awareness;
|
|
34
|
+
/**
|
|
35
|
+
* A token that’s sent to the backend for authentication purposes.
|
|
36
|
+
*/
|
|
37
|
+
token: string | (() => string) | (() => Promise<string>) | null;
|
|
38
|
+
/**
|
|
39
|
+
* URL parameters that should be added.
|
|
40
|
+
*/
|
|
41
|
+
parameters: {
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* An optional WebSocket polyfill, for example for Node.js
|
|
46
|
+
*/
|
|
47
|
+
WebSocketPolyfill: any;
|
|
48
|
+
/**
|
|
49
|
+
* Force syncing the document in the defined interval.
|
|
50
|
+
*/
|
|
51
|
+
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
|
+
onAuthenticated: () => void;
|
|
89
|
+
onAuthenticationFailed: (data: onAuthenticationFailedParameters) => void;
|
|
90
|
+
onOpen: (data: onOpenParameters) => void;
|
|
91
|
+
onConnect: () => void;
|
|
92
|
+
onMessage: (data: onMessageParameters) => void;
|
|
93
|
+
onOutgoingMessage: (data: onOutgoingMessageParameters) => void;
|
|
94
|
+
onStatus: (data: onStatusParameters) => void;
|
|
95
|
+
onSynced: (data: onSyncedParameters) => void;
|
|
96
|
+
onDisconnect: (data: onDisconnectParameters) => void;
|
|
97
|
+
onClose: (data: onCloseParameters) => void;
|
|
98
|
+
onDestroy: () => void;
|
|
99
|
+
onAwarenessUpdate: (data: onAwarenessUpdateParameters) => void;
|
|
100
|
+
onAwarenessChange: (data: onAwarenessChangeParameters) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Don’t output any warnings.
|
|
103
|
+
*/
|
|
104
|
+
quiet: boolean;
|
|
105
|
+
}
|
|
106
|
+
export declare class HocuspocusProvider extends EventEmitter {
|
|
107
|
+
configuration: CompleteHocuspocusProviderConfiguration;
|
|
108
|
+
subscribedToBroadcastChannel: boolean;
|
|
109
|
+
webSocket: WebSocket | null;
|
|
110
|
+
shouldConnect: boolean;
|
|
111
|
+
status: WebSocketStatus;
|
|
112
|
+
isSynced: boolean;
|
|
113
|
+
isAuthenticated: boolean;
|
|
114
|
+
lastMessageReceived: number;
|
|
115
|
+
mux: mutex.mutex;
|
|
116
|
+
intervals: any;
|
|
117
|
+
connectionAttempt: {
|
|
118
|
+
resolve: (value?: any) => void;
|
|
119
|
+
reject: (reason?: any) => void;
|
|
120
|
+
} | null;
|
|
121
|
+
constructor(configuration: HocuspocusProviderConfiguration);
|
|
122
|
+
setConfiguration(configuration?: Partial<HocuspocusProviderConfiguration>): void;
|
|
123
|
+
connect(): Promise<void>;
|
|
124
|
+
createWebSocketConnection(): Promise<unknown>;
|
|
125
|
+
resolveConnectionAttempt(): void;
|
|
126
|
+
stopConnectionAttempt(): void;
|
|
127
|
+
rejectConnectionAttempt(): void;
|
|
128
|
+
get document(): Y.Doc;
|
|
129
|
+
get awareness(): Awareness;
|
|
130
|
+
checkConnection(): void;
|
|
131
|
+
forceSync(): void;
|
|
132
|
+
registerEventListeners(): void;
|
|
133
|
+
documentUpdateHandler(update: Uint8Array, origin: any): void;
|
|
134
|
+
awarenessUpdateHandler({ added, updated, removed }: any, origin: any): void;
|
|
135
|
+
permissionDeniedHandler(reason: string): void;
|
|
136
|
+
authenticatedHandler(): void;
|
|
137
|
+
get serverUrl(): string;
|
|
138
|
+
get url(): string;
|
|
139
|
+
get synced(): boolean;
|
|
140
|
+
set synced(state: boolean);
|
|
141
|
+
get isAuthenticationRequired(): boolean;
|
|
142
|
+
disconnect(): void;
|
|
143
|
+
onOpen(event: Event): Promise<void>;
|
|
144
|
+
getToken(): Promise<string | null>;
|
|
145
|
+
startSync(): void;
|
|
146
|
+
send(Message: ConstructableOutgoingMessage, args: any, broadcast?: boolean): void;
|
|
147
|
+
onMessage(event: MessageEvent): void;
|
|
148
|
+
onClose(event: CloseEvent): void;
|
|
149
|
+
destroy(): void;
|
|
150
|
+
get broadcastChannel(): string;
|
|
151
|
+
broadcastChannelSubscriber(data: ArrayBuffer): void;
|
|
152
|
+
subscribeToBroadcastChannel(): void;
|
|
153
|
+
disconnectBroadcastChannel(): void;
|
|
154
|
+
broadcast(Message: ConstructableOutgoingMessage, args?: any): void;
|
|
155
|
+
setAwarenessField(key: string, value: any): void;
|
|
156
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Decoder } from 'lib0/decoding';
|
|
2
|
+
import { Encoder } from 'lib0/encoding';
|
|
3
|
+
import { MessageType } from './types';
|
|
4
|
+
export declare class IncomingMessage {
|
|
5
|
+
data: any;
|
|
6
|
+
encoder: Encoder;
|
|
7
|
+
decoder: Decoder;
|
|
8
|
+
constructor(data: any);
|
|
9
|
+
readVarUint(): MessageType;
|
|
10
|
+
readVarUint8Array(): Uint8Array;
|
|
11
|
+
writeVarUint(type: MessageType): void;
|
|
12
|
+
writeVarUint8Array(data: Uint8Array): void;
|
|
13
|
+
length(): number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HocuspocusProvider } from './HocuspocusProvider';
|
|
2
|
+
import { IncomingMessage } from './IncomingMessage';
|
|
3
|
+
export declare class MessageReceiver {
|
|
4
|
+
message: IncomingMessage;
|
|
5
|
+
broadcasted: boolean;
|
|
6
|
+
constructor(message: IncomingMessage);
|
|
7
|
+
setBroadcasted(value: boolean): this;
|
|
8
|
+
apply(provider: HocuspocusProvider, emitSynced?: boolean): void;
|
|
9
|
+
private applySyncMessage;
|
|
10
|
+
private applyAwarenessMessage;
|
|
11
|
+
private applyAuthMessage;
|
|
12
|
+
private applyQueryAwarenessMessage;
|
|
13
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Encoder } from 'lib0/encoding';
|
|
2
|
+
import { ConstructableOutgoingMessage } from './types';
|
|
3
|
+
export declare class MessageSender {
|
|
4
|
+
encoder: Encoder;
|
|
5
|
+
message: any;
|
|
6
|
+
constructor(Message: ConstructableOutgoingMessage, args?: any);
|
|
7
|
+
create(): Uint8Array;
|
|
8
|
+
send(webSocket: any): void;
|
|
9
|
+
broadcast(channel: string): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Encoder } from 'lib0/encoding';
|
|
2
|
+
import { MessageType, OutgoingMessageArguments, OutgoingMessageInterface } from './types';
|
|
3
|
+
export declare class OutgoingMessage implements OutgoingMessageInterface {
|
|
4
|
+
encoder: Encoder;
|
|
5
|
+
type?: MessageType;
|
|
6
|
+
constructor();
|
|
7
|
+
get(args: Partial<OutgoingMessageArguments>): Encoder | undefined;
|
|
8
|
+
toUint8Array(): Uint8Array;
|
|
9
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
2
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
3
|
+
export declare class AuthenticationMessage extends OutgoingMessage {
|
|
4
|
+
type: MessageType;
|
|
5
|
+
description: string;
|
|
6
|
+
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as encoding from 'lib0/encoding';
|
|
2
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
3
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
4
|
+
export declare class AwarenessMessage extends OutgoingMessage {
|
|
5
|
+
type: MessageType;
|
|
6
|
+
description: string;
|
|
7
|
+
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as encoding from 'lib0/encoding';
|
|
2
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
3
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
4
|
+
export declare class QueryAwarenessMessage extends OutgoingMessage {
|
|
5
|
+
type: MessageType;
|
|
6
|
+
description: string;
|
|
7
|
+
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as encoding from 'lib0/encoding';
|
|
2
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
3
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
4
|
+
export declare class SyncStepOneMessage extends OutgoingMessage {
|
|
5
|
+
type: MessageType;
|
|
6
|
+
description: string;
|
|
7
|
+
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as encoding from 'lib0/encoding';
|
|
2
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
3
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
4
|
+
export declare class SyncStepTwoMessage extends OutgoingMessage {
|
|
5
|
+
type: MessageType;
|
|
6
|
+
description: string;
|
|
7
|
+
get(args: Partial<OutgoingMessageArguments>): encoding.Encoder;
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MessageType, OutgoingMessageArguments } from '../types';
|
|
2
|
+
import { OutgoingMessage } from '../OutgoingMessage';
|
|
3
|
+
export declare class UpdateMessage extends OutgoingMessage {
|
|
4
|
+
type: MessageType;
|
|
5
|
+
description: string;
|
|
6
|
+
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { Encoder } from 'lib0/encoding';
|
|
4
|
+
import type { Event, CloseEvent, MessageEvent } from 'ws';
|
|
5
|
+
import { AuthenticationMessage } from './OutgoingMessages/AuthenticationMessage';
|
|
6
|
+
import { AwarenessMessage } from './OutgoingMessages/AwarenessMessage';
|
|
7
|
+
import { QueryAwarenessMessage } from './OutgoingMessages/QueryAwarenessMessage';
|
|
8
|
+
import { SyncStepOneMessage } from './OutgoingMessages/SyncStepOneMessage';
|
|
9
|
+
import { SyncStepTwoMessage } from './OutgoingMessages/SyncStepTwoMessage';
|
|
10
|
+
import { UpdateMessage } from './OutgoingMessages/UpdateMessage';
|
|
11
|
+
import { IncomingMessage } from './IncomingMessage';
|
|
12
|
+
import { OutgoingMessage } from './OutgoingMessage';
|
|
13
|
+
export declare enum MessageType {
|
|
14
|
+
Sync = 0,
|
|
15
|
+
Awareness = 1,
|
|
16
|
+
Auth = 2,
|
|
17
|
+
QueryAwareness = 3
|
|
18
|
+
}
|
|
19
|
+
export declare enum WebSocketStatus {
|
|
20
|
+
Connecting = "connecting",
|
|
21
|
+
Connected = "connected",
|
|
22
|
+
Disconnected = "disconnected"
|
|
23
|
+
}
|
|
24
|
+
export interface OutgoingMessageInterface {
|
|
25
|
+
encoder: Encoder;
|
|
26
|
+
type?: MessageType;
|
|
27
|
+
}
|
|
28
|
+
export interface OutgoingMessageArguments {
|
|
29
|
+
token: string;
|
|
30
|
+
document: Y.Doc;
|
|
31
|
+
awareness: Awareness;
|
|
32
|
+
clients: number[];
|
|
33
|
+
states: Map<number, {
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
}>;
|
|
36
|
+
update: any;
|
|
37
|
+
encoder: Encoder;
|
|
38
|
+
}
|
|
39
|
+
export interface Constructable<T> {
|
|
40
|
+
new (...args: any): T;
|
|
41
|
+
}
|
|
42
|
+
export declare type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
43
|
+
export declare type onAuthenticationFailedParameters = {
|
|
44
|
+
reason: string;
|
|
45
|
+
};
|
|
46
|
+
export declare type onOpenParameters = {
|
|
47
|
+
event: Event;
|
|
48
|
+
};
|
|
49
|
+
export declare type onMessageParameters = {
|
|
50
|
+
event: MessageEvent;
|
|
51
|
+
message: IncomingMessage;
|
|
52
|
+
};
|
|
53
|
+
export declare type onOutgoingMessageParameters = {
|
|
54
|
+
message: OutgoingMessage;
|
|
55
|
+
};
|
|
56
|
+
export declare type onStatusParameters = {
|
|
57
|
+
status: WebSocketStatus;
|
|
58
|
+
};
|
|
59
|
+
export declare type onSyncedParameters = {
|
|
60
|
+
state: boolean;
|
|
61
|
+
};
|
|
62
|
+
export declare type onDisconnectParameters = {
|
|
63
|
+
event: CloseEvent;
|
|
64
|
+
};
|
|
65
|
+
export declare type onCloseParameters = {
|
|
66
|
+
event: CloseEvent;
|
|
67
|
+
};
|
|
68
|
+
export declare type onAwarenessUpdateParameters = {
|
|
69
|
+
states: StatesArray;
|
|
70
|
+
};
|
|
71
|
+
export declare type onAwarenessChangeParameters = {
|
|
72
|
+
states: StatesArray;
|
|
73
|
+
};
|
|
74
|
+
export declare type StatesArray = {
|
|
75
|
+
clientId: number;
|
|
76
|
+
[key: string | number]: any;
|
|
77
|
+
}[];
|