@hocuspocus/extension-s3 3.2.4
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/README.md +167 -0
- package/dist/hocuspocus-s3.cjs +129 -0
- package/dist/hocuspocus-s3.cjs.map +1 -0
- package/dist/hocuspocus-s3.esm.js +127 -0
- package/dist/hocuspocus-s3.esm.js.map +1 -0
- package/dist/node_modules/@tiptap/pm/model/index.d.ts +1 -0
- package/dist/node_modules/@tiptap/pm/state/index.d.ts +1 -0
- package/dist/node_modules/@tiptap/pm/transform/index.d.ts +1 -0
- package/dist/node_modules/@tiptap/pm/view/index.d.ts +1 -0
- package/dist/packages/common/src/CloseEvents.d.ts +29 -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 +30 -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-redis/src/Redis.d.ts +129 -0
- package/dist/packages/extension-redis/src/index.d.ts +1 -0
- package/dist/packages/extension-s3/src/S3.d.ts +44 -0
- package/dist/packages/extension-s3/src/index.d.ts +1 -0
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +27 -0
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -0
- package/dist/packages/extension-throttle/src/index.d.ts +30 -0
- package/dist/packages/extension-webhook/src/index.d.ts +56 -0
- package/dist/packages/provider/src/EventEmitter.d.ts +9 -0
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +115 -0
- package/dist/packages/provider/src/HocuspocusProviderWebsocket.d.ts +114 -0
- package/dist/packages/provider/src/IncomingMessage.d.ts +17 -0
- package/dist/packages/provider/src/MessageReceiver.d.ts +12 -0
- package/dist/packages/provider/src/MessageSender.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +8 -0
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +9 -0
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +8 -0
- package/dist/packages/provider/src/index.d.ts +3 -0
- package/dist/packages/provider/src/types.d.ts +92 -0
- package/dist/packages/server/src/ClientConnection.d.ts +63 -0
- package/dist/packages/server/src/Connection.d.ts +62 -0
- package/dist/packages/server/src/DirectConnection.d.ts +14 -0
- package/dist/packages/server/src/Document.d.ts +89 -0
- package/dist/packages/server/src/Hocuspocus.d.ts +77 -0
- package/dist/packages/server/src/IncomingMessage.d.ts +25 -0
- package/dist/packages/server/src/MessageReceiver.d.ts +11 -0
- package/dist/packages/server/src/OutgoingMessage.d.ts +22 -0
- package/dist/packages/server/src/Server.d.ts +32 -0
- package/dist/packages/server/src/index.d.ts +9 -0
- package/dist/packages/server/src/types.d.ts +328 -0
- package/dist/packages/server/src/util/debounce.d.ts +5 -0
- package/dist/packages/server/src/util/getParameters.d.ts +6 -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/deno.d.ts +1 -0
- package/dist/playground/backend/src/express.d.ts +1 -0
- package/dist/playground/backend/src/hono.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/redis.d.ts +1 -0
- package/dist/playground/backend/src/s3-redis.d.ts +1 -0
- package/dist/playground/backend/src/s3.d.ts +1 -0
- package/dist/playground/backend/src/slow.d.ts +1 -0
- package/dist/playground/backend/src/tiptapcollab.d.ts +1 -0
- package/dist/playground/backend/src/webhook.d.ts +1 -0
- package/dist/playground/frontend/app/SocketContext1.d.ts +2 -0
- package/dist/playground/frontend/app/SocketContext2.d.ts +2 -0
- package/dist/playground/frontend/next.config.d.ts +3 -0
- package/dist/tests/extension-database/fetch.d.ts +1 -0
- package/dist/tests/extension-logger/onListen.d.ts +1 -0
- package/dist/tests/extension-redis/onAwarenessChange.d.ts +1 -0
- package/dist/tests/extension-redis/onChange.d.ts +1 -0
- package/dist/tests/extension-redis/onStateless.d.ts +1 -0
- package/dist/tests/extension-redis/onStoreDocument.d.ts +1 -0
- package/dist/tests/extension-s3/fetch.d.ts +1 -0
- package/dist/tests/extension-throttle/banning.d.ts +1 -0
- package/dist/tests/extension-throttle/configuration.d.ts +1 -0
- package/dist/tests/provider/hasUnsyncedChanges.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/onStateless.d.ts +1 -0
- package/dist/tests/provider/onSynced.d.ts +1 -0
- package/dist/tests/providerwebsocket/configuration.d.ts +1 -0
- package/dist/tests/server/address.d.ts +1 -0
- package/dist/tests/server/afterLoadDocument.d.ts +1 -0
- package/dist/tests/server/afterStoreDocument.d.ts +1 -0
- package/dist/tests/server/afterUnloadDocument.d.ts +1 -0
- package/dist/tests/server/beforeBroadcastStateless.d.ts +1 -0
- package/dist/tests/server/beforeHandleMessage.d.ts +1 -0
- package/dist/tests/server/beforeSync.d.ts +1 -0
- package/dist/tests/server/beforeUnloadDocument.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/getDocumentsCount.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/onClose.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/onStateless.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/openDirectConnection.d.ts +1 -0
- package/dist/tests/server/websocketError.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 +9 -0
- package/dist/tests/utils/newHocuspocus.d.ts +2 -0
- package/dist/tests/utils/newHocuspocusProvider.d.ts +3 -0
- package/dist/tests/utils/newHocuspocusProviderWebsocket.d.ts +4 -0
- package/dist/tests/utils/randomInteger.d.ts +1 -0
- package/dist/tests/utils/redisConnectionSettings.d.ts +4 -0
- package/dist/tests/utils/removeDirectory.d.ts +1 -0
- package/dist/tests/utils/retryableAssertion.d.ts +2 -0
- package/dist/tests/utils/sleep.d.ts +1 -0
- package/package.json +39 -0
- package/src/S3.ts +178 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { OutgoingMessageArguments } from "../types.ts";
|
|
2
|
+
import { MessageType } from "../types.ts";
|
|
3
|
+
import { OutgoingMessage } from "../OutgoingMessage.ts";
|
|
4
|
+
export declare class UpdateMessage extends OutgoingMessage {
|
|
5
|
+
type: MessageType;
|
|
6
|
+
description: string;
|
|
7
|
+
get(args: Partial<OutgoingMessageArguments>): import("lib0/encoding").Encoder;
|
|
8
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Encoder } from "lib0/encoding";
|
|
2
|
+
import type { Event, MessageEvent } from "ws";
|
|
3
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
4
|
+
import type * as Y from "yjs";
|
|
5
|
+
import type { CloseEvent } from "@hocuspocus/common";
|
|
6
|
+
import type { IncomingMessage } from "./IncomingMessage.ts";
|
|
7
|
+
import type { OutgoingMessage } from "./OutgoingMessage.ts";
|
|
8
|
+
import type { AuthenticationMessage } from "./OutgoingMessages/AuthenticationMessage.ts";
|
|
9
|
+
import type { AwarenessMessage } from "./OutgoingMessages/AwarenessMessage.ts";
|
|
10
|
+
import type { QueryAwarenessMessage } from "./OutgoingMessages/QueryAwarenessMessage.ts";
|
|
11
|
+
import type { SyncStepOneMessage } from "./OutgoingMessages/SyncStepOneMessage.ts";
|
|
12
|
+
import type { SyncStepTwoMessage } from "./OutgoingMessages/SyncStepTwoMessage.ts";
|
|
13
|
+
import type { UpdateMessage } from "./OutgoingMessages/UpdateMessage.ts";
|
|
14
|
+
export declare enum MessageType {
|
|
15
|
+
Sync = 0,
|
|
16
|
+
Awareness = 1,
|
|
17
|
+
Auth = 2,
|
|
18
|
+
QueryAwareness = 3,
|
|
19
|
+
Stateless = 5,
|
|
20
|
+
CLOSE = 7,
|
|
21
|
+
SyncStatus = 8
|
|
22
|
+
}
|
|
23
|
+
export declare enum WebSocketStatus {
|
|
24
|
+
Connecting = "connecting",
|
|
25
|
+
Connected = "connected",
|
|
26
|
+
Disconnected = "disconnected"
|
|
27
|
+
}
|
|
28
|
+
export interface OutgoingMessageInterface {
|
|
29
|
+
encoder: Encoder;
|
|
30
|
+
type?: MessageType;
|
|
31
|
+
}
|
|
32
|
+
export interface OutgoingMessageArguments {
|
|
33
|
+
documentName: string;
|
|
34
|
+
token: string;
|
|
35
|
+
document: Y.Doc;
|
|
36
|
+
awareness: Awareness;
|
|
37
|
+
clients: number[];
|
|
38
|
+
states: Map<number, {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
}>;
|
|
41
|
+
update: any;
|
|
42
|
+
payload: string;
|
|
43
|
+
encoder: Encoder;
|
|
44
|
+
}
|
|
45
|
+
export interface Constructable<T> {
|
|
46
|
+
new (...args: any): T;
|
|
47
|
+
}
|
|
48
|
+
export type ConstructableOutgoingMessage = Constructable<AuthenticationMessage> | Constructable<AwarenessMessage> | Constructable<QueryAwarenessMessage> | Constructable<SyncStepOneMessage> | Constructable<SyncStepTwoMessage> | Constructable<UpdateMessage>;
|
|
49
|
+
export type onAuthenticationFailedParameters = {
|
|
50
|
+
reason: string;
|
|
51
|
+
};
|
|
52
|
+
export type onAuthenticatedParameters = {
|
|
53
|
+
scope: "read-write" | "readonly";
|
|
54
|
+
};
|
|
55
|
+
export type onOpenParameters = {
|
|
56
|
+
event: Event;
|
|
57
|
+
};
|
|
58
|
+
export type onMessageParameters = {
|
|
59
|
+
event: MessageEvent;
|
|
60
|
+
message: IncomingMessage;
|
|
61
|
+
};
|
|
62
|
+
export type onOutgoingMessageParameters = {
|
|
63
|
+
message: OutgoingMessage;
|
|
64
|
+
};
|
|
65
|
+
export type onStatusParameters = {
|
|
66
|
+
status: WebSocketStatus;
|
|
67
|
+
};
|
|
68
|
+
export type onSyncedParameters = {
|
|
69
|
+
state: boolean;
|
|
70
|
+
};
|
|
71
|
+
export type onUnsyncedChangesParameters = {
|
|
72
|
+
number: number;
|
|
73
|
+
};
|
|
74
|
+
export type onDisconnectParameters = {
|
|
75
|
+
event: CloseEvent;
|
|
76
|
+
};
|
|
77
|
+
export type onCloseParameters = {
|
|
78
|
+
event: CloseEvent;
|
|
79
|
+
};
|
|
80
|
+
export type onAwarenessUpdateParameters = {
|
|
81
|
+
states: StatesArray;
|
|
82
|
+
};
|
|
83
|
+
export type onAwarenessChangeParameters = {
|
|
84
|
+
states: StatesArray;
|
|
85
|
+
};
|
|
86
|
+
export type onStatelessParameters = {
|
|
87
|
+
payload: string;
|
|
88
|
+
};
|
|
89
|
+
export type StatesArray = {
|
|
90
|
+
clientId: number;
|
|
91
|
+
[key: string | number]: any;
|
|
92
|
+
}[];
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { type CloseEvent } from "@hocuspocus/common";
|
|
3
|
+
import type WebSocket from "ws";
|
|
4
|
+
import type Document from "./Document.ts";
|
|
5
|
+
import type { Hocuspocus } from "./Hocuspocus.ts";
|
|
6
|
+
import type { onDisconnectPayload } from "./types.ts";
|
|
7
|
+
/**
|
|
8
|
+
* The `ClientConnection` class is responsible for handling an incoming WebSocket
|
|
9
|
+
*
|
|
10
|
+
* TODO-refactor:
|
|
11
|
+
* - use event handlers instead of calling hooks directly, hooks should probably be called from Hocuspocus.ts
|
|
12
|
+
*/
|
|
13
|
+
export declare class ClientConnection {
|
|
14
|
+
private readonly websocket;
|
|
15
|
+
private readonly request;
|
|
16
|
+
private readonly documentProvider;
|
|
17
|
+
private readonly hooks;
|
|
18
|
+
private readonly opts;
|
|
19
|
+
private readonly defaultContext;
|
|
20
|
+
private readonly documentConnections;
|
|
21
|
+
private readonly incomingMessageQueue;
|
|
22
|
+
private readonly documentConnectionsEstablished;
|
|
23
|
+
private readonly hookPayloads;
|
|
24
|
+
private readonly callbacks;
|
|
25
|
+
private readonly socketId;
|
|
26
|
+
timeout: number;
|
|
27
|
+
pingInterval: NodeJS.Timeout;
|
|
28
|
+
pongReceived: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The `ClientConnection` class receives incoming WebSocket connections,
|
|
31
|
+
* runs all hooks:
|
|
32
|
+
*
|
|
33
|
+
* - onConnect for all connections
|
|
34
|
+
* - onAuthenticate only if required
|
|
35
|
+
*
|
|
36
|
+
* … and if nothings fails it’ll fully establish the connection and
|
|
37
|
+
* load the Document then.
|
|
38
|
+
*/
|
|
39
|
+
constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
|
|
40
|
+
createDocument: Hocuspocus["createDocument"];
|
|
41
|
+
}, hooks: Hocuspocus["hooks"], opts: {
|
|
42
|
+
timeout: number;
|
|
43
|
+
}, defaultContext?: any);
|
|
44
|
+
private handleWebsocketClose;
|
|
45
|
+
close(event?: CloseEvent): void;
|
|
46
|
+
handlePong: () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Check if pong was received and close the connection otherwise
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
private check;
|
|
52
|
+
/**
|
|
53
|
+
* Set a callback that will be triggered when the connection is closed
|
|
54
|
+
*/
|
|
55
|
+
onClose(callback: (document: Document, payload: onDisconnectPayload) => void): ClientConnection;
|
|
56
|
+
/**
|
|
57
|
+
* Create a new connection by the given request and document
|
|
58
|
+
*/
|
|
59
|
+
private createConnection;
|
|
60
|
+
private setUpNewConnection;
|
|
61
|
+
private handleQueueingMessage;
|
|
62
|
+
private messageHandler;
|
|
63
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IncomingMessage as HTTPIncomingMessage } from "node:http";
|
|
2
|
+
import { type CloseEvent } from "@hocuspocus/common";
|
|
3
|
+
import type WebSocket from "ws";
|
|
4
|
+
import type Document from "./Document.ts";
|
|
5
|
+
import type { beforeSyncPayload, onStatelessPayload } from "./types.ts";
|
|
6
|
+
export declare class Connection {
|
|
7
|
+
webSocket: WebSocket;
|
|
8
|
+
context: any;
|
|
9
|
+
document: Document;
|
|
10
|
+
request: HTTPIncomingMessage;
|
|
11
|
+
callbacks: {
|
|
12
|
+
onClose: ((document: Document, event?: CloseEvent) => void)[];
|
|
13
|
+
beforeHandleMessage: (connection: Connection, update: Uint8Array) => Promise<void>;
|
|
14
|
+
beforeSync: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<void>;
|
|
15
|
+
statelessCallback: (payload: onStatelessPayload) => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
socketId: string;
|
|
18
|
+
readOnly: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor.
|
|
21
|
+
*/
|
|
22
|
+
constructor(connection: WebSocket, request: HTTPIncomingMessage, document: Document, socketId: string, context: any, readOnly?: boolean);
|
|
23
|
+
/**
|
|
24
|
+
* Set a callback that will be triggered when the connection is closed
|
|
25
|
+
*/
|
|
26
|
+
onClose(callback: (document: Document, event?: CloseEvent) => void): Connection;
|
|
27
|
+
/**
|
|
28
|
+
* Set a callback that will be triggered when an stateless message is received
|
|
29
|
+
*/
|
|
30
|
+
onStatelessCallback(callback: (payload: onStatelessPayload) => Promise<void>): Connection;
|
|
31
|
+
/**
|
|
32
|
+
* Set a callback that will be triggered before an message is handled
|
|
33
|
+
*/
|
|
34
|
+
beforeHandleMessage(callback: (connection: Connection, update: Uint8Array) => Promise<any>): Connection;
|
|
35
|
+
/**
|
|
36
|
+
* Set a callback that will be triggered before a sync message is handled
|
|
37
|
+
*/
|
|
38
|
+
beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<any>): Connection;
|
|
39
|
+
/**
|
|
40
|
+
* Send the given message
|
|
41
|
+
*/
|
|
42
|
+
send(message: any): void;
|
|
43
|
+
/**
|
|
44
|
+
* Send a stateless message with payload
|
|
45
|
+
*/
|
|
46
|
+
sendStateless(payload: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Graceful wrapper around the WebSocket close method.
|
|
49
|
+
*/
|
|
50
|
+
close(event?: CloseEvent): void;
|
|
51
|
+
/**
|
|
52
|
+
* Send the current document awareness to the client, if any
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private sendCurrentAwareness;
|
|
56
|
+
/**
|
|
57
|
+
* Handle an incoming message
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
handleMessage(data: Uint8Array): void;
|
|
61
|
+
}
|
|
62
|
+
export default Connection;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type Document from "./Document.ts";
|
|
2
|
+
import type { Hocuspocus } from "./Hocuspocus.ts";
|
|
3
|
+
import type { DirectConnection as DirectConnectionInterface } from "./types.ts";
|
|
4
|
+
export declare class DirectConnection implements DirectConnectionInterface {
|
|
5
|
+
document: Document | null;
|
|
6
|
+
instance: Hocuspocus;
|
|
7
|
+
context: any;
|
|
8
|
+
/**
|
|
9
|
+
* Constructor.
|
|
10
|
+
*/
|
|
11
|
+
constructor(document: Document, instance: Hocuspocus, context?: any);
|
|
12
|
+
transact(transaction: (document: Document) => void): Promise<void>;
|
|
13
|
+
disconnect(): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type WebSocket from "ws";
|
|
2
|
+
import { Awareness } from "y-protocols/awareness";
|
|
3
|
+
import { Doc } from "yjs";
|
|
4
|
+
import type Connection from "./Connection.ts";
|
|
5
|
+
export declare class Document extends Doc {
|
|
6
|
+
awareness: Awareness;
|
|
7
|
+
callbacks: {
|
|
8
|
+
onUpdate: (document: Document, connection: Connection, update: Uint8Array) => void;
|
|
9
|
+
beforeBroadcastStateless: (document: Document, stateless: string) => void;
|
|
10
|
+
};
|
|
11
|
+
connections: Map<WebSocket, {
|
|
12
|
+
clients: Set<any>;
|
|
13
|
+
connection: Connection;
|
|
14
|
+
}>;
|
|
15
|
+
directConnectionsCount: number;
|
|
16
|
+
name: string;
|
|
17
|
+
isLoading: boolean;
|
|
18
|
+
isDestroyed: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor.
|
|
21
|
+
*/
|
|
22
|
+
constructor(name: string, yDocOptions?: object);
|
|
23
|
+
/**
|
|
24
|
+
* Check if the Document (XMLFragment or Map) is empty
|
|
25
|
+
*/
|
|
26
|
+
isEmpty(fieldName: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Merge the given document(s) into this one
|
|
29
|
+
*/
|
|
30
|
+
merge(documents: Doc | Array<Doc>): Document;
|
|
31
|
+
/**
|
|
32
|
+
* Set a callback that will be triggered when the document is updated
|
|
33
|
+
*/
|
|
34
|
+
onUpdate(callback: (document: Document, connection: Connection, update: Uint8Array) => void): Document;
|
|
35
|
+
/**
|
|
36
|
+
* Set a callback that will be triggered before a stateless message is broadcasted
|
|
37
|
+
*/
|
|
38
|
+
beforeBroadcastStateless(callback: (document: Document, stateless: string) => void): Document;
|
|
39
|
+
/**
|
|
40
|
+
* Register a connection and a set of clients on this document keyed by the
|
|
41
|
+
* underlying websocket connection
|
|
42
|
+
*/
|
|
43
|
+
addConnection(connection: Connection): Document;
|
|
44
|
+
/**
|
|
45
|
+
* Is the given connection registered on this document
|
|
46
|
+
*/
|
|
47
|
+
hasConnection(connection: Connection): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Remove the given connection from this document
|
|
50
|
+
*/
|
|
51
|
+
removeConnection(connection: Connection): Document;
|
|
52
|
+
addDirectConnection(): Document;
|
|
53
|
+
removeDirectConnection(): Document;
|
|
54
|
+
/**
|
|
55
|
+
* Get the number of active connections for this document
|
|
56
|
+
*/
|
|
57
|
+
getConnectionsCount(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Get an array of registered connections
|
|
60
|
+
*/
|
|
61
|
+
getConnections(): Array<Connection>;
|
|
62
|
+
/**
|
|
63
|
+
* Get the client ids for the given connection instance
|
|
64
|
+
*/
|
|
65
|
+
getClients(connectionInstance: WebSocket): Set<any>;
|
|
66
|
+
/**
|
|
67
|
+
* Has the document awareness states
|
|
68
|
+
*/
|
|
69
|
+
hasAwarenessStates(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Apply the given awareness update
|
|
72
|
+
*/
|
|
73
|
+
applyAwarenessUpdate(connection: Connection, update: Uint8Array): Document;
|
|
74
|
+
/**
|
|
75
|
+
* Handle an awareness update and sync changes to clients
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
private handleAwarenessUpdate;
|
|
79
|
+
/**
|
|
80
|
+
* Handle an updated document and sync changes to clients
|
|
81
|
+
*/
|
|
82
|
+
private handleUpdate;
|
|
83
|
+
/**
|
|
84
|
+
* Broadcast stateless message to all connections
|
|
85
|
+
*/
|
|
86
|
+
broadcastStateless(payload: string, filter?: (conn: Connection) => boolean): void;
|
|
87
|
+
destroy(): void;
|
|
88
|
+
}
|
|
89
|
+
export default Document;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import type WebSocket from "ws";
|
|
3
|
+
import { DirectConnection } from "./DirectConnection.ts";
|
|
4
|
+
import Document from "./Document.ts";
|
|
5
|
+
import type { Server } from "./Server.ts";
|
|
6
|
+
import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from "./types.ts";
|
|
7
|
+
export declare const defaultConfiguration: {
|
|
8
|
+
name: null;
|
|
9
|
+
timeout: number;
|
|
10
|
+
debounce: number;
|
|
11
|
+
maxDebounce: number;
|
|
12
|
+
quiet: boolean;
|
|
13
|
+
yDocOptions: {
|
|
14
|
+
gc: boolean;
|
|
15
|
+
gcFilter: () => boolean;
|
|
16
|
+
};
|
|
17
|
+
unloadImmediately: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare class Hocuspocus {
|
|
20
|
+
configuration: Configuration;
|
|
21
|
+
loadingDocuments: Map<string, Promise<Document>>;
|
|
22
|
+
documents: Map<string, Document>;
|
|
23
|
+
server?: Server;
|
|
24
|
+
debouncer: {
|
|
25
|
+
debounce: (id: string, func: Function, debounce: number, maxDebounce: number) => any;
|
|
26
|
+
isDebounced: (id: string) => boolean;
|
|
27
|
+
executeNow: (id: string) => any;
|
|
28
|
+
};
|
|
29
|
+
constructor(configuration?: Partial<Configuration>);
|
|
30
|
+
/**
|
|
31
|
+
* Configure Hocuspocus
|
|
32
|
+
*/
|
|
33
|
+
configure(configuration: Partial<Configuration>): Hocuspocus;
|
|
34
|
+
/**
|
|
35
|
+
* Get the total number of active documents
|
|
36
|
+
*/
|
|
37
|
+
getDocumentsCount(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get the total number of active connections
|
|
40
|
+
*/
|
|
41
|
+
getConnectionsCount(): number;
|
|
42
|
+
/**
|
|
43
|
+
* Force close one or more connections
|
|
44
|
+
*/
|
|
45
|
+
closeConnections(documentName?: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* The `handleConnection` method receives incoming WebSocket connections,
|
|
48
|
+
* runs all hooks:
|
|
49
|
+
*
|
|
50
|
+
* - onConnect for all connections
|
|
51
|
+
* - onAuthenticate only if required
|
|
52
|
+
*
|
|
53
|
+
* … and if nothing fails it’ll fully establish the connection and
|
|
54
|
+
* load the Document then.
|
|
55
|
+
*/
|
|
56
|
+
handleConnection(incoming: WebSocket, request: IncomingMessage, defaultContext?: any): void;
|
|
57
|
+
/**
|
|
58
|
+
* Handle update of the given document
|
|
59
|
+
*
|
|
60
|
+
* "connection" is not necessarily type "Connection", it's the Yjs "origin" (which is "Connection" if
|
|
61
|
+
* the update is incoming from the provider, but can be anything if the updates is originated from an extension.
|
|
62
|
+
*/
|
|
63
|
+
private handleDocumentUpdate;
|
|
64
|
+
/**
|
|
65
|
+
* Create a new document by the given request
|
|
66
|
+
*/
|
|
67
|
+
createDocument(documentName: string, request: Partial<Pick<IncomingMessage, "headers" | "url">>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
|
|
68
|
+
loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, "headers" | "url">>, socketId: string, connectionConfig: ConnectionConfiguration, context?: any): Promise<Document>;
|
|
69
|
+
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): any;
|
|
70
|
+
/**
|
|
71
|
+
* Run the given hook on all configured extensions.
|
|
72
|
+
* Runs the given callback after each hook.
|
|
73
|
+
*/
|
|
74
|
+
hooks<T extends HookName>(name: T, payload: HookPayloadByName[T], callback?: Function | null): Promise<any>;
|
|
75
|
+
unloadDocument(document: Document): Promise<any>;
|
|
76
|
+
openDirectConnection(documentName: string, context?: any): Promise<DirectConnection>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Decoder } from "lib0/decoding";
|
|
2
|
+
import type { Encoder } from "lib0/encoding";
|
|
3
|
+
import type { MessageType } from "./types.ts";
|
|
4
|
+
export declare class IncomingMessage {
|
|
5
|
+
/**
|
|
6
|
+
* Access to the received message.
|
|
7
|
+
*/
|
|
8
|
+
decoder: Decoder;
|
|
9
|
+
/**
|
|
10
|
+
* Private encoder; can be undefined.
|
|
11
|
+
*
|
|
12
|
+
* Lazy creation of the encoder speeds up IncomingMessages that need only a decoder.
|
|
13
|
+
*/
|
|
14
|
+
private encoderInternal?;
|
|
15
|
+
constructor(input: any);
|
|
16
|
+
get encoder(): Encoder;
|
|
17
|
+
readVarUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
18
|
+
peekVarUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
19
|
+
readVarUint(): number;
|
|
20
|
+
readVarString(): string;
|
|
21
|
+
toUint8Array(): Uint8Array<ArrayBufferLike>;
|
|
22
|
+
writeVarUint(type: MessageType): void;
|
|
23
|
+
writeVarString(string: string): void;
|
|
24
|
+
get length(): number;
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type Connection from "./Connection.ts";
|
|
2
|
+
import type Document from "./Document.ts";
|
|
3
|
+
import type { IncomingMessage } from "./IncomingMessage.ts";
|
|
4
|
+
export declare class MessageReceiver {
|
|
5
|
+
message: IncomingMessage;
|
|
6
|
+
defaultTransactionOrigin?: string;
|
|
7
|
+
constructor(message: IncomingMessage, defaultTransactionOrigin?: string);
|
|
8
|
+
apply(document: Document, connection?: Connection, reply?: (message: Uint8Array) => void): Promise<void>;
|
|
9
|
+
readSyncMessage(message: IncomingMessage, document: Document, connection?: Connection, reply?: (message: Uint8Array) => void, requestFirstSync?: boolean): Promise<0 | 1 | 2>;
|
|
10
|
+
applyQueryAwarenessMessage(document: Document, reply?: (message: Uint8Array) => void): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Encoder } from "lib0/encoding";
|
|
2
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
3
|
+
import type Document from "./Document.ts";
|
|
4
|
+
export declare class OutgoingMessage {
|
|
5
|
+
encoder: Encoder;
|
|
6
|
+
type?: number;
|
|
7
|
+
category?: string;
|
|
8
|
+
constructor(documentName: string);
|
|
9
|
+
createSyncMessage(): OutgoingMessage;
|
|
10
|
+
createSyncReplyMessage(): OutgoingMessage;
|
|
11
|
+
createAwarenessUpdateMessage(awareness: Awareness, changedClients?: Array<any>): OutgoingMessage;
|
|
12
|
+
writeQueryAwareness(): OutgoingMessage;
|
|
13
|
+
writeAuthenticated(readonly: boolean): OutgoingMessage;
|
|
14
|
+
writePermissionDenied(reason: string): OutgoingMessage;
|
|
15
|
+
writeFirstSyncStepFor(document: Document): OutgoingMessage;
|
|
16
|
+
writeUpdate(update: Uint8Array): OutgoingMessage;
|
|
17
|
+
writeStateless(payload: string): OutgoingMessage;
|
|
18
|
+
writeBroadcastStateless(payload: string): OutgoingMessage;
|
|
19
|
+
writeSyncStatus(updateSaved: boolean): OutgoingMessage;
|
|
20
|
+
writeCloseMessage(reason: string): OutgoingMessage;
|
|
21
|
+
toUint8Array(): Uint8Array;
|
|
22
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Server as HTTPServer, IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { WebSocketServer } from "ws";
|
|
3
|
+
import type { AddressInfo, ServerOptions } from "ws";
|
|
4
|
+
import { Hocuspocus } from "./Hocuspocus.ts";
|
|
5
|
+
import type { Configuration } from "./types.ts";
|
|
6
|
+
export interface ServerConfiguration extends Configuration {
|
|
7
|
+
port?: number;
|
|
8
|
+
address?: string;
|
|
9
|
+
stopOnSignals?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const defaultServerConfiguration: {
|
|
12
|
+
port: number;
|
|
13
|
+
address: string;
|
|
14
|
+
stopOnSignals: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare class Server {
|
|
17
|
+
httpServer: HTTPServer;
|
|
18
|
+
webSocketServer: WebSocketServer;
|
|
19
|
+
hocuspocus: Hocuspocus;
|
|
20
|
+
configuration: ServerConfiguration;
|
|
21
|
+
constructor(configuration?: Partial<ServerConfiguration>, websocketOptions?: ServerOptions);
|
|
22
|
+
setupWebsocketConnection: () => void;
|
|
23
|
+
setupHttpUpgrade: () => void;
|
|
24
|
+
requestHandler: (request: IncomingMessage, response: ServerResponse) => Promise<void>;
|
|
25
|
+
listen(port?: number, callback?: any): Promise<Hocuspocus>;
|
|
26
|
+
get address(): AddressInfo;
|
|
27
|
+
destroy(): Promise<any>;
|
|
28
|
+
get URL(): string;
|
|
29
|
+
get webSocketURL(): string;
|
|
30
|
+
get httpURL(): string;
|
|
31
|
+
private showStartScreen;
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./Connection.ts";
|
|
2
|
+
export * from "./Document.ts";
|
|
3
|
+
export * from "./Hocuspocus.ts";
|
|
4
|
+
export * from "./IncomingMessage.ts";
|
|
5
|
+
export * from "./MessageReceiver.ts";
|
|
6
|
+
export * from "./OutgoingMessage.ts";
|
|
7
|
+
export * from "./Server.ts";
|
|
8
|
+
export * from "./types.ts";
|
|
9
|
+
export * from "./util/debounce.ts";
|