@hocuspocus/common 3.1.2 → 3.1.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/dist/hocuspocus-common.cjs +5 -5
- package/dist/hocuspocus-common.cjs.map +1 -1
- package/dist/hocuspocus-common.esm.js +5 -5
- package/dist/hocuspocus-common.esm.js.map +1 -1
- package/dist/packages/common/src/auth.d.ts +2 -2
- package/dist/packages/common/src/index.d.ts +4 -4
- package/dist/packages/extension-database/src/Database.d.ts +1 -1
- package/dist/packages/extension-database/src/index.d.ts +1 -1
- package/dist/packages/extension-logger/src/Logger.d.ts +1 -1
- package/dist/packages/extension-logger/src/index.d.ts +1 -1
- package/dist/packages/extension-redis/src/index.d.ts +1 -1
- package/dist/packages/extension-sqlite/src/SQLite.d.ts +3 -3
- package/dist/packages/extension-sqlite/src/index.d.ts +1 -1
- package/dist/packages/extension-throttle/src/index.d.ts +1 -1
- package/dist/packages/extension-webhook/src/index.d.ts +3 -3
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +10 -10
- package/dist/packages/provider/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/provider/src/MessageReceiver.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessage.d.ts +2 -2
- package/dist/packages/provider/src/OutgoingMessages/AuthenticationMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/AwarenessMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/CloseMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/QueryAwarenessMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/StatelessMessage.d.ts +3 -3
- package/dist/packages/provider/src/OutgoingMessages/SyncStepOneMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/SyncStepTwoMessage.d.ts +4 -4
- package/dist/packages/provider/src/OutgoingMessages/UpdateMessage.d.ts +3 -3
- package/dist/packages/provider/src/index.d.ts +3 -3
- package/dist/packages/provider/src/types.d.ts +14 -14
- package/dist/packages/server/src/ClientConnection.d.ts +17 -17
- package/dist/packages/server/src/Connection.d.ts +6 -6
- package/dist/packages/server/src/DirectConnection.d.ts +3 -3
- package/dist/packages/server/src/Document.d.ts +4 -4
- package/dist/packages/server/src/Hocuspocus.d.ts +8 -8
- package/dist/packages/server/src/IncomingMessage.d.ts +3 -3
- package/dist/packages/server/src/MessageReceiver.d.ts +3 -3
- package/dist/packages/server/src/OutgoingMessage.d.ts +3 -3
- package/dist/packages/server/src/Server.d.ts +5 -5
- package/dist/packages/server/src/index.d.ts +9 -9
- package/dist/packages/server/src/types.d.ts +7 -7
- package/dist/packages/server/src/util/getParameters.d.ts +5 -5
- package/dist/packages/transformer/src/Prosemirror.d.ts +3 -3
- package/dist/packages/transformer/src/Tiptap.d.ts +3 -3
- package/dist/packages/transformer/src/index.d.ts +3 -3
- package/dist/packages/transformer/src/types.d.ts +1 -1
- package/dist/playground/frontend/app/SocketContext1.d.ts +2 -0
- package/dist/playground/frontend/app/SocketContext2.d.ts +2 -0
- package/package.json +30 -30
- package/src/CloseEvents.ts +17 -17
- package/src/auth.ts +41 -32
- package/src/awarenessStatesToArray.ts +10 -8
- package/src/index.ts +4 -4
- package/src/types.ts +4 -4
- package/dist/playground/frontend/app/SocketContext.d.ts +0 -2
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { Encoder } from
|
|
2
|
-
import type { Event, MessageEvent } from
|
|
3
|
-
import type { Awareness } from
|
|
4
|
-
import type * as Y from
|
|
5
|
-
import type { CloseEvent } from
|
|
6
|
-
import type { IncomingMessage } from
|
|
7
|
-
import type { OutgoingMessage } from
|
|
8
|
-
import type { AuthenticationMessage } from
|
|
9
|
-
import type { AwarenessMessage } from
|
|
10
|
-
import type { QueryAwarenessMessage } from
|
|
11
|
-
import type { SyncStepOneMessage } from
|
|
12
|
-
import type { SyncStepTwoMessage } from
|
|
13
|
-
import type { UpdateMessage } from
|
|
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
14
|
export declare enum MessageType {
|
|
15
15
|
Sync = 0,
|
|
16
16
|
Awareness = 1,
|
|
@@ -50,7 +50,7 @@ export type onAuthenticationFailedParameters = {
|
|
|
50
50
|
reason: string;
|
|
51
51
|
};
|
|
52
52
|
export type onAuthenticatedParameters = {
|
|
53
|
-
scope:
|
|
53
|
+
scope: "read-write" | "readonly";
|
|
54
54
|
};
|
|
55
55
|
export type onOpenParameters = {
|
|
56
56
|
event: Event;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { IncomingMessage } from
|
|
2
|
-
import { type CloseEvent } from
|
|
3
|
-
import type WebSocket from
|
|
4
|
-
import type Document from
|
|
5
|
-
import type { Hocuspocus } from
|
|
6
|
-
import type { onDisconnectPayload } from
|
|
1
|
+
import type { IncomingMessage } from "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
7
|
/**
|
|
8
8
|
* The `ClientConnection` class is responsible for handling an incoming WebSocket
|
|
9
9
|
*
|
|
@@ -27,18 +27,18 @@ export declare class ClientConnection {
|
|
|
27
27
|
pingInterval: NodeJS.Timeout;
|
|
28
28
|
pongReceived: boolean;
|
|
29
29
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
39
|
constructor(websocket: WebSocket, request: IncomingMessage, documentProvider: {
|
|
40
|
-
createDocument: Hocuspocus[
|
|
41
|
-
}, hooks: Hocuspocus[
|
|
40
|
+
createDocument: Hocuspocus["createDocument"];
|
|
41
|
+
}, hooks: Hocuspocus["hooks"], opts: {
|
|
42
42
|
timeout: number;
|
|
43
43
|
}, defaultContext?: any);
|
|
44
44
|
private handleWebsocketClose;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { IncomingMessage as HTTPIncomingMessage } from
|
|
2
|
-
import { type CloseEvent } from
|
|
3
|
-
import type WebSocket from
|
|
4
|
-
import type Document from
|
|
5
|
-
import type { beforeSyncPayload, onStatelessPayload } from
|
|
1
|
+
import type { IncomingMessage as HTTPIncomingMessage } from "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
6
|
export declare class Connection {
|
|
7
7
|
webSocket: WebSocket;
|
|
8
8
|
context: any;
|
|
@@ -35,7 +35,7 @@ export declare class Connection {
|
|
|
35
35
|
/**
|
|
36
36
|
* Set a callback that will be triggered before a sync message is handled
|
|
37
37
|
*/
|
|
38
|
-
beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload,
|
|
38
|
+
beforeSync(callback: (connection: Connection, payload: Pick<beforeSyncPayload, "type" | "payload">) => Promise<any>): Connection;
|
|
39
39
|
/**
|
|
40
40
|
* Send the given message
|
|
41
41
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type Document from
|
|
2
|
-
import type { Hocuspocus } from
|
|
3
|
-
import type { DirectConnection as DirectConnectionInterface } from
|
|
1
|
+
import type Document from "./Document.ts";
|
|
2
|
+
import type { Hocuspocus } from "./Hocuspocus.ts";
|
|
3
|
+
import type { DirectConnection as DirectConnectionInterface } from "./types.ts";
|
|
4
4
|
export declare class DirectConnection implements DirectConnectionInterface {
|
|
5
5
|
document: Document | null;
|
|
6
6
|
instance: Hocuspocus;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type WebSocket from
|
|
2
|
-
import { Awareness } from
|
|
3
|
-
import { Doc } from
|
|
4
|
-
import type Connection from
|
|
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
5
|
export declare class Document extends Doc {
|
|
6
6
|
awareness: Awareness;
|
|
7
7
|
callbacks: {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { IncomingMessage } from
|
|
2
|
-
import type WebSocket from
|
|
3
|
-
import { DirectConnection } from
|
|
4
|
-
import Document from
|
|
5
|
-
import type { Server } from
|
|
6
|
-
import type { Configuration, ConnectionConfiguration, HookName, HookPayloadByName, onStoreDocumentPayload } from
|
|
1
|
+
import type { IncomingMessage } from "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
7
|
export declare const defaultConfiguration: {
|
|
8
8
|
name: null;
|
|
9
9
|
timeout: number;
|
|
@@ -64,8 +64,8 @@ export declare class Hocuspocus {
|
|
|
64
64
|
/**
|
|
65
65
|
* Create a new document by the given request
|
|
66
66
|
*/
|
|
67
|
-
createDocument(documentName: string, request: Partial<Pick<IncomingMessage,
|
|
68
|
-
loadDocument(documentName: string, request: Partial<Pick<IncomingMessage,
|
|
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
69
|
storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): any;
|
|
70
70
|
/**
|
|
71
71
|
* Run the given hook on all configured extensions.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Decoder } from
|
|
2
|
-
import type { Encoder } from
|
|
3
|
-
import type { MessageType } from
|
|
1
|
+
import type { Decoder } from "lib0/decoding";
|
|
2
|
+
import type { Encoder } from "lib0/encoding";
|
|
3
|
+
import type { MessageType } from "./types.ts";
|
|
4
4
|
export declare class IncomingMessage {
|
|
5
5
|
/**
|
|
6
6
|
* Access to the received message.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type Connection from
|
|
2
|
-
import type Document from
|
|
3
|
-
import type { IncomingMessage } from
|
|
1
|
+
import type Connection from "./Connection.ts";
|
|
2
|
+
import type Document from "./Document.ts";
|
|
3
|
+
import type { IncomingMessage } from "./IncomingMessage.ts";
|
|
4
4
|
export declare class MessageReceiver {
|
|
5
5
|
message: IncomingMessage;
|
|
6
6
|
defaultTransactionOrigin?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Encoder } from
|
|
2
|
-
import type { Awareness } from
|
|
3
|
-
import type Document from
|
|
1
|
+
import type { Encoder } from "lib0/encoding";
|
|
2
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
3
|
+
import type Document from "./Document.ts";
|
|
4
4
|
export declare class OutgoingMessage {
|
|
5
5
|
encoder: Encoder;
|
|
6
6
|
type?: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { WebSocketServer } from
|
|
3
|
-
import type { AddressInfo, ServerOptions } from
|
|
4
|
-
import { Hocuspocus } from
|
|
5
|
-
import type { Configuration } from
|
|
1
|
+
import type { Server as HTTPServer, IncomingMessage, ServerResponse } from "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
6
|
export interface ServerConfiguration extends Configuration {
|
|
7
7
|
port?: number;
|
|
8
8
|
address?: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
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";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from
|
|
2
|
-
import type { URLSearchParams } from
|
|
3
|
-
import type { Awareness } from
|
|
4
|
-
import type Connection from
|
|
5
|
-
import type Document from
|
|
6
|
-
import type { Hocuspocus } from
|
|
1
|
+
import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "http";
|
|
2
|
+
import type { URLSearchParams } from "url";
|
|
3
|
+
import type { Awareness } from "y-protocols/awareness";
|
|
4
|
+
import type Connection from "./Connection.ts";
|
|
5
|
+
import type Document from "./Document.ts";
|
|
6
|
+
import type { Hocuspocus } from "./Hocuspocus.ts";
|
|
7
7
|
export declare enum MessageType {
|
|
8
8
|
Unknown = -1,
|
|
9
9
|
Sync = 0,
|
|
@@ -51,7 +51,7 @@ export interface Extension {
|
|
|
51
51
|
afterUnloadDocument?(data: afterUnloadDocumentPayload): Promise<any>;
|
|
52
52
|
onDestroy?(data: onDestroyPayload): Promise<any>;
|
|
53
53
|
}
|
|
54
|
-
export type HookName =
|
|
54
|
+
export type HookName = "onConfigure" | "onListen" | "onUpgrade" | "onConnect" | "connected" | "onAuthenticate" | "onCreateDocument" | "onLoadDocument" | "afterLoadDocument" | "beforeHandleMessage" | "beforeBroadcastStateless" | "beforeSync" | "onStateless" | "onChange" | "onStoreDocument" | "afterStoreDocument" | "onAwarenessUpdate" | "onRequest" | "onDisconnect" | "beforeUnloadDocument" | "afterUnloadDocument" | "onDestroy";
|
|
55
55
|
export type HookPayloadByName = {
|
|
56
56
|
onConfigure: onConfigurePayload;
|
|
57
57
|
onListen: onListenPayload;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { IncomingMessage } from
|
|
2
|
-
import { URLSearchParams } from
|
|
1
|
+
import type { IncomingMessage } from "http";
|
|
2
|
+
import { URLSearchParams } from "url";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare function getParameters(request?: Pick<IncomingMessage,
|
|
4
|
+
* Get parameters by the given request
|
|
5
|
+
*/
|
|
6
|
+
export declare function getParameters(request?: Pick<IncomingMessage, "url">): URLSearchParams;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Doc } from
|
|
2
|
-
import { Schema } from
|
|
3
|
-
import type { Transformer } from
|
|
1
|
+
import { Doc } from "yjs";
|
|
2
|
+
import { Schema } from "@tiptap/pm/model";
|
|
3
|
+
import type { Transformer } from "./types.ts";
|
|
4
4
|
declare class Prosemirror implements Transformer {
|
|
5
5
|
defaultSchema: Schema;
|
|
6
6
|
schema(schema: Schema): Prosemirror;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Doc } from
|
|
2
|
-
import type { Extensions } from
|
|
3
|
-
import type { Transformer } from
|
|
1
|
+
import type { Doc } from "yjs";
|
|
2
|
+
import type { Extensions } from "@tiptap/core";
|
|
3
|
+
import type { Transformer } from "./types.ts";
|
|
4
4
|
export declare class Tiptap implements Transformer {
|
|
5
5
|
defaultExtensions: Extensions;
|
|
6
6
|
extensions(extensions: Extensions): Tiptap;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from "./Prosemirror.ts";
|
|
2
|
+
export * from "./Tiptap.ts";
|
|
3
|
+
export * from "./types.ts";
|
package/package.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
"name": "@hocuspocus/common",
|
|
3
|
+
"description": "shared code for multiple Hocuspocus packages",
|
|
4
|
+
"version": "3.1.4",
|
|
5
|
+
"homepage": "https://hocuspocus.dev",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"hocuspocus"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "dist/hocuspocus-common.cjs",
|
|
12
|
+
"module": "dist/hocuspocus-common.esm.js",
|
|
13
|
+
"types": "dist/packages/common/src/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"source": {
|
|
16
|
+
"import": "./src/index.ts"
|
|
17
|
+
},
|
|
18
|
+
"default": {
|
|
19
|
+
"import": "./dist/hocuspocus-common.esm.js",
|
|
20
|
+
"require": "./dist/hocuspocus-common.cjs",
|
|
21
|
+
"types": "./dist/packages/common/src/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"src",
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"gitHead": "cd788b6a315f608ef531524409abdce1e6790726",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"lib0": "^0.2.87"
|
|
31
|
+
}
|
|
32
32
|
}
|
package/src/CloseEvents.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface CloseEvent {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
code: number;
|
|
3
|
+
reason: string;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -9,41 +9,41 @@ export interface CloseEvent {
|
|
|
9
9
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
|
10
10
|
*/
|
|
11
11
|
export const MessageTooBig: CloseEvent = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
12
|
+
code: 1009,
|
|
13
|
+
reason: "Message Too Big",
|
|
14
|
+
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* The server successfully processed the request, asks that the requester reset
|
|
18
18
|
* its document view, and is not returning any content.
|
|
19
19
|
*/
|
|
20
20
|
export const ResetConnection: CloseEvent = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
21
|
+
code: 4205,
|
|
22
|
+
reason: "Reset Connection",
|
|
23
|
+
};
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Similar to Forbidden, but specifically for use when authentication is required and has
|
|
27
27
|
* failed or has not yet been provided.
|
|
28
28
|
*/
|
|
29
29
|
export const Unauthorized: CloseEvent = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
30
|
+
code: 4401,
|
|
31
|
+
reason: "Unauthorized",
|
|
32
|
+
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* The request contained valid data and was understood by the server, but the server
|
|
36
36
|
* is refusing action.
|
|
37
37
|
*/
|
|
38
38
|
export const Forbidden: CloseEvent = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
39
|
+
code: 4403,
|
|
40
|
+
reason: "Forbidden",
|
|
41
|
+
};
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* The server timed out waiting for the request.
|
|
45
45
|
*/
|
|
46
46
|
export const ConnectionTimeout: CloseEvent = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
47
|
+
code: 4408,
|
|
48
|
+
reason: "Connection Timeout",
|
|
49
|
+
};
|
package/src/auth.ts
CHANGED
|
@@ -1,41 +1,50 @@
|
|
|
1
|
-
import * as encoding from
|
|
2
|
-
import * as decoding from
|
|
1
|
+
import * as encoding from "lib0/encoding";
|
|
2
|
+
import * as decoding from "lib0/decoding";
|
|
3
3
|
|
|
4
4
|
enum AuthMessageType {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Token = 0,
|
|
6
|
+
PermissionDenied = 1,
|
|
7
|
+
Authenticated = 2,
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const writeAuthentication = (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export const writeAuthentication = (
|
|
11
|
+
encoder: encoding.Encoder,
|
|
12
|
+
auth: string,
|
|
13
|
+
) => {
|
|
14
|
+
encoding.writeVarUint(encoder, AuthMessageType.Token);
|
|
15
|
+
encoding.writeVarString(encoder, auth);
|
|
16
|
+
};
|
|
14
17
|
|
|
15
|
-
export const writePermissionDenied = (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
export const writePermissionDenied = (
|
|
19
|
+
encoder: encoding.Encoder,
|
|
20
|
+
reason: string,
|
|
21
|
+
) => {
|
|
22
|
+
encoding.writeVarUint(encoder, AuthMessageType.PermissionDenied);
|
|
23
|
+
encoding.writeVarString(encoder, reason);
|
|
24
|
+
};
|
|
19
25
|
|
|
20
|
-
export const writeAuthenticated = (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
export const writeAuthenticated = (
|
|
27
|
+
encoder: encoding.Encoder,
|
|
28
|
+
scope: "readonly" | "read-write",
|
|
29
|
+
) => {
|
|
30
|
+
encoding.writeVarUint(encoder, AuthMessageType.Authenticated);
|
|
31
|
+
encoding.writeVarString(encoder, scope);
|
|
32
|
+
};
|
|
24
33
|
|
|
25
34
|
export const readAuthMessage = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
decoder: decoding.Decoder,
|
|
36
|
+
permissionDeniedHandler: (reason: string) => void,
|
|
37
|
+
authenticatedHandler: (scope: string) => void,
|
|
29
38
|
) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
39
|
+
switch (decoding.readVarUint(decoder)) {
|
|
40
|
+
case AuthMessageType.PermissionDenied: {
|
|
41
|
+
permissionDeniedHandler(decoding.readVarString(decoder));
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
case AuthMessageType.Authenticated: {
|
|
45
|
+
authenticatedHandler(decoding.readVarString(decoder));
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export const awarenessStatesToArray = (
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
export const awarenessStatesToArray = (
|
|
2
|
+
states: Map<number, Record<string, any>>,
|
|
3
|
+
) => {
|
|
4
|
+
return Array.from(states.entries()).map(([key, value]) => {
|
|
5
|
+
return {
|
|
6
|
+
clientId: key,
|
|
7
|
+
...value,
|
|
8
|
+
};
|
|
9
|
+
});
|
|
10
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./auth.ts";
|
|
2
|
+
export * from "./CloseEvents.ts";
|
|
3
|
+
export * from "./awarenessStatesToArray.ts";
|
|
4
|
+
export * from "./types.ts";
|
package/src/types.ts
CHANGED