@abraca/dabra 0.1.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/hocuspocus-provider.cjs +3237 -0
- package/dist/hocuspocus-provider.cjs.map +1 -0
- package/dist/hocuspocus-provider.esm.js +3199 -0
- package/dist/hocuspocus-provider.esm.js.map +1 -0
- package/dist/index.d.ts +784 -0
- package/package.json +42 -0
- package/src/AbracadabraProvider.ts +381 -0
- package/src/CryptoIdentityKeystore.ts +294 -0
- package/src/EventEmitter.ts +44 -0
- package/src/HocuspocusProvider.ts +603 -0
- package/src/HocuspocusProviderWebsocket.ts +533 -0
- package/src/IncomingMessage.ts +63 -0
- package/src/MessageReceiver.ts +139 -0
- package/src/MessageSender.ts +22 -0
- package/src/OfflineStore.ts +185 -0
- package/src/OutgoingMessage.ts +25 -0
- package/src/OutgoingMessages/AuthenticationMessage.ts +25 -0
- package/src/OutgoingMessages/AwarenessMessage.ts +41 -0
- package/src/OutgoingMessages/CloseMessage.ts +17 -0
- package/src/OutgoingMessages/QueryAwarenessMessage.ts +17 -0
- package/src/OutgoingMessages/StatelessMessage.ts +18 -0
- package/src/OutgoingMessages/SubdocMessage.ts +35 -0
- package/src/OutgoingMessages/SyncStepOneMessage.ts +25 -0
- package/src/OutgoingMessages/SyncStepTwoMessage.ts +25 -0
- package/src/OutgoingMessages/UpdateMessage.ts +20 -0
- package/src/index.ts +7 -0
- package/src/types.ts +144 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
|
|
15
|
+
export enum MessageType {
|
|
16
|
+
Sync = 0,
|
|
17
|
+
Awareness = 1,
|
|
18
|
+
Auth = 2,
|
|
19
|
+
QueryAwareness = 3,
|
|
20
|
+
Subdoc = 4,
|
|
21
|
+
Stateless = 5,
|
|
22
|
+
CLOSE = 7,
|
|
23
|
+
SyncStatus = 8,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum WebSocketStatus {
|
|
27
|
+
Connecting = "connecting",
|
|
28
|
+
Connected = "connected",
|
|
29
|
+
Disconnected = "disconnected",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type AuthorizedScope = "read-write" | "readonly";
|
|
33
|
+
|
|
34
|
+
export interface OutgoingMessageInterface {
|
|
35
|
+
encoder: Encoder;
|
|
36
|
+
type?: MessageType;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface OutgoingMessageArguments {
|
|
40
|
+
documentName: string;
|
|
41
|
+
token: string;
|
|
42
|
+
document: Y.Doc;
|
|
43
|
+
awareness: Awareness;
|
|
44
|
+
clients: number[];
|
|
45
|
+
states: Map<number, { [key: string]: any }>;
|
|
46
|
+
update: any;
|
|
47
|
+
payload: string;
|
|
48
|
+
encoder: Encoder;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface Constructable<T> {
|
|
52
|
+
new (...args: any): T;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type ConstructableOutgoingMessage =
|
|
56
|
+
| Constructable<AuthenticationMessage>
|
|
57
|
+
| Constructable<AwarenessMessage>
|
|
58
|
+
| Constructable<QueryAwarenessMessage>
|
|
59
|
+
| Constructable<SyncStepOneMessage>
|
|
60
|
+
| Constructable<SyncStepTwoMessage>
|
|
61
|
+
| Constructable<UpdateMessage>;
|
|
62
|
+
|
|
63
|
+
export type onAuthenticationFailedParameters = {
|
|
64
|
+
reason: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type onAuthenticatedParameters = {
|
|
68
|
+
scope: AuthorizedScope;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type onOpenParameters = {
|
|
72
|
+
event: Event;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export type onMessageParameters = {
|
|
76
|
+
event: MessageEvent;
|
|
77
|
+
message: IncomingMessage;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export type onOutgoingMessageParameters = {
|
|
81
|
+
message: OutgoingMessage;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type onStatusParameters = {
|
|
85
|
+
status: WebSocketStatus;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type onSyncedParameters = {
|
|
89
|
+
state: boolean;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type onUnsyncedChangesParameters = {
|
|
93
|
+
number: number;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type onDisconnectParameters = {
|
|
97
|
+
event: CloseEvent;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export type onCloseParameters = {
|
|
101
|
+
event: CloseEvent;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type onAwarenessUpdateParameters = {
|
|
105
|
+
states: StatesArray;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type onAwarenessChangeParameters = {
|
|
109
|
+
states: StatesArray;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type onStatelessParameters = {
|
|
113
|
+
payload: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type StatesArray = { clientId: number; [key: string | number]: any }[];
|
|
117
|
+
|
|
118
|
+
// ── Abracadabra extensions ────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
export type EffectiveRole = "owner" | "editor" | "viewer" | null;
|
|
121
|
+
|
|
122
|
+
/** Ed25519 identity for passwordless crypto auth (Model B multi-key). */
|
|
123
|
+
export interface CryptoIdentity {
|
|
124
|
+
username: string;
|
|
125
|
+
/** base64url-encoded Ed25519 public key (32 bytes) */
|
|
126
|
+
publicKey: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface SubdocRegisteredEvent {
|
|
130
|
+
childId: string;
|
|
131
|
+
parentId: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type onSubdocRegisteredParameters = SubdocRegisteredEvent;
|
|
135
|
+
|
|
136
|
+
export type onSubdocLoadedParameters = {
|
|
137
|
+
childId: string;
|
|
138
|
+
provider: import("./AbracadabraProvider.ts").AbracadabraProvider;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export interface AbracadabraOutgoingMessageArguments
|
|
142
|
+
extends OutgoingMessageArguments {
|
|
143
|
+
childDocumentName: string;
|
|
144
|
+
}
|