lint: lib/realtime/realtime.ts

- add ot typing

Signed-off-by: Raccoon <raccoon@hackmd.io>
This commit is contained in:
Raccoon 2021-06-14 20:04:22 +08:00
parent 847acda4de
commit f35d68409d
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
3 changed files with 66 additions and 3 deletions

View File

@ -72,7 +72,7 @@ export interface RealtimeNoteData {
updatetime: number
// type: ot.EditorSocketIOServer
server: any
server: ot.EditorSocketIOServer
authors: Record<string, RealtimeAuthorData>
authorship: Authorship[]
@ -714,7 +714,7 @@ export function ifMayEdit(socket: SocketIO.Socket, callback: (canEdit: boolean)
}
// TODO: test it
function operationCallback(socket: SocketIO.Socket, operation: any) {
function operationCallback(socket: SocketIO.Socket, operation: ot.Operation[]) {
const noteId = socket.noteId
if (!noteId || !notes[noteId]) return
const note = notes[noteId]

View File

@ -17,7 +17,8 @@
"typeRoots": ["./typings", "./node_modules/@types"],
"paths": {
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"]
"@hackmd/diff-match-patch": ["./typings/diff-match-patch/"],
"ot": ["./typings/ot/"]
}
},
"include": [

62
typings/ot/index.d.ts vendored Normal file
View File

@ -0,0 +1,62 @@
import SocketIO from "socket.io";
import EventEmitter from "events";
declare module 'ot' {
export const version: number
export type Operation = number | string
export class TextOperation {
static isRetain(op: Operation): boolean
static isInsert(op: Operation): boolean
static isDelete(op: Operation): boolean
}
export class EditorSocketIOServer extends EventEmitter {
public isDirty: boolean
public document: string
public debug: boolean
public operations: Operation[]
constructor(
document: string,
operations: Operation[],
docId: string,
mayWrite: (
socket: SocketIO.Socket,
callback: (canEdit: boolean) => void) => void,
operationCallback: (
socket: SocketIO.Socket,
operation: Operation[]) => void,
operationEventCallback?: any)
setLogger(logger): void
debugLog(mes: string): void
setDocumentMaxLength(number): void
addClient(socket: SocketIO.Socket): void
onOperation(socket: SocketIO.Server, revision, operation, selection)
onGetOperations(socket, base, head)
updateSelection(socket, selection)
setName(socket, name)
setColor(socket, color)
getClient(clientId)
onDisconnect(socket)
}
}