Skip to content

Commit f35d684

Browse files
committed
lint: lib/realtime/realtime.ts
- add ot typing Signed-off-by: Raccoon <[email protected]>
1 parent 847acda commit f35d684

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

lib/realtime/realtime.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export interface RealtimeNoteData {
7272
updatetime: number
7373

7474
// type: ot.EditorSocketIOServer
75-
server: any
75+
server: ot.EditorSocketIOServer
7676

7777
authors: Record<string, RealtimeAuthorData>
7878
authorship: Authorship[]
@@ -714,7 +714,7 @@ export function ifMayEdit(socket: SocketIO.Socket, callback: (canEdit: boolean)
714714
}
715715

716716
// TODO: test it
717-
function operationCallback(socket: SocketIO.Socket, operation: any) {
717+
function operationCallback(socket: SocketIO.Socket, operation: ot.Operation[]) {
718718
const noteId = socket.noteId
719719
if (!noteId || !notes[noteId]) return
720720
const note = notes[noteId]

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
"typeRoots": ["./typings", "./node_modules/@types"],
1919
"paths": {
20-
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"]
20+
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"],
21+
"ot": ["./typings/ot/"]
2122
}
2223
},
2324
"include": [

typings/ot/index.d.ts

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import SocketIO from "socket.io";
2+
import EventEmitter from "events";
3+
4+
declare module 'ot' {
5+
6+
export const version: number
7+
8+
export type Operation = number | string
9+
10+
export class TextOperation {
11+
static isRetain(op: Operation): boolean
12+
13+
static isInsert(op: Operation): boolean
14+
15+
static isDelete(op: Operation): boolean
16+
}
17+
18+
export class EditorSocketIOServer extends EventEmitter {
19+
20+
public isDirty: boolean
21+
public document: string
22+
public debug: boolean
23+
public operations: Operation[]
24+
25+
constructor(
26+
document: string,
27+
operations: Operation[],
28+
docId: string,
29+
mayWrite: (
30+
socket: SocketIO.Socket,
31+
callback: (canEdit: boolean) => void) => void,
32+
operationCallback: (
33+
socket: SocketIO.Socket,
34+
operation: Operation[]) => void,
35+
operationEventCallback?: any)
36+
37+
setLogger(logger): void
38+
39+
debugLog(mes: string): void
40+
41+
setDocumentMaxLength(number): void
42+
43+
addClient(socket: SocketIO.Socket): void
44+
45+
onOperation(socket: SocketIO.Server, revision, operation, selection)
46+
47+
onGetOperations(socket, base, head)
48+
49+
updateSelection(socket, selection)
50+
51+
setName(socket, name)
52+
53+
setColor(socket, color)
54+
55+
getClient(clientId)
56+
57+
onDisconnect(socket)
58+
}
59+
60+
}
61+
62+

0 commit comments

Comments
 (0)