@@ -20,7 +20,7 @@ import config from "../config";
20
20
import { logger } from "../logger" ;
21
21
import { createNoteWithRevision , syncNote } from "../services/note" ;
22
22
import { stripTags } from "../string" ;
23
- import { ModelObj , MySequelize , NoteAttributes , NoteMeta } from "./baseModel" ;
23
+ import { Authorship , ModelObj , MySequelize , NoteAttributes , NoteMeta } from "./baseModel" ;
24
24
25
25
const md = markdownIt ( )
26
26
export const dmp = new DiffMatchPatch ( )
@@ -34,7 +34,7 @@ interface ParsedMeta {
34
34
35
35
export class Note extends Model < NoteAttributes > implements NoteAttributes {
36
36
alias : string ;
37
- authorship : string ;
37
+ authorship : Authorship [ ] ;
38
38
content : string ;
39
39
id : string ;
40
40
lastchangeAt : Date | Moment ;
@@ -96,9 +96,13 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
96
96
authorship : {
97
97
type : DataTypes . TEXT ( { length : 'long' } ) ,
98
98
get : function ( ) {
99
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
100
+ // @ts -ignore
99
101
return sequelize . processData ( this . getDataValue ( 'authorship' ) , [ ] , JSON . parse )
100
102
} ,
101
103
set : function ( value ) {
104
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
+ // @ts -ignore
102
106
this . setDataValue ( 'authorship' , JSON . stringify ( value ) )
103
107
}
104
108
} ,
@@ -459,16 +463,16 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
459
463
return _meta
460
464
}
461
465
462
- static updateAuthorshipByOperation ( operation : any , userId : string , authorships : any ) : any {
466
+ static updateAuthorshipByOperation ( operation : ( string | number ) [ ] , userId : string , authorships : Authorship [ ] ) : Authorship [ ] {
463
467
let index = 0
464
468
const timestamp = Date . now ( )
465
469
for ( let i = 0 ; i < operation . length ; i ++ ) {
466
470
const op = operation [ i ]
467
471
if ( ot . TextOperation . isRetain ( op ) ) {
468
- index += op
472
+ index += op as number
469
473
} else if ( ot . TextOperation . isInsert ( op ) ) {
470
474
const opStart = index
471
- const opEnd = index + op . length
475
+ const opEnd = index + ( op as string ) . length
472
476
let inserted = false
473
477
// authorship format: [userId, startPos, endPos, createdAt, updatedAt]
474
478
if ( authorships . length <= 0 ) authorships . push ( [ userId , opStart , opEnd , timestamp , timestamp ] )
@@ -499,15 +503,15 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
499
503
}
500
504
}
501
505
if ( authorship [ 1 ] >= opStart ) {
502
- authorship [ 1 ] += op . length
503
- authorship [ 2 ] += op . length
506
+ authorship [ 1 ] += ( op as string ) . length
507
+ authorship [ 2 ] += ( op as string ) . length
504
508
}
505
509
}
506
510
}
507
- index += op . length
511
+ index += ( op as string ) . length
508
512
} else if ( ot . TextOperation . isDelete ( op ) ) {
509
513
const opStart = index
510
- const opEnd = index - op
514
+ const opEnd = index - ( op as number )
511
515
if ( operation . length === 1 ) {
512
516
authorships = [ ]
513
517
} else if ( authorships . length > 0 ) {
@@ -517,7 +521,7 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
517
521
authorships . splice ( j , 1 )
518
522
j -= 1
519
523
} else if ( authorship [ 1 ] < opStart && authorship [ 1 ] < opEnd && authorship [ 2 ] > opStart && authorship [ 2 ] > opEnd ) {
520
- authorship [ 2 ] += op
524
+ authorship [ 2 ] += op as number
521
525
authorship [ 4 ] = timestamp
522
526
} else if ( authorship [ 2 ] >= opStart && authorship [ 2 ] <= opEnd ) {
523
527
authorship [ 2 ] = opStart
@@ -527,12 +531,12 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
527
531
authorship [ 4 ] = timestamp
528
532
}
529
533
if ( authorship [ 1 ] >= opEnd ) {
530
- authorship [ 1 ] += op
531
- authorship [ 2 ] += op
534
+ authorship [ 1 ] += op as number
535
+ authorship [ 2 ] += op as number
532
536
}
533
537
}
534
538
}
535
- index += op
539
+ index += ( op as number )
536
540
}
537
541
}
538
542
// merge
@@ -561,7 +565,7 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
561
565
return authorships
562
566
}
563
567
564
- static transformPatchToOperations ( patch : any , contentLength : number ) {
568
+ static transformPatchToOperations ( patch : Patch [ ] , contentLength : number ) : ( number | string ) [ ] [ ] {
565
569
const operations = [ ]
566
570
if ( patch . length > 0 ) {
567
571
// calculate original content length
0 commit comments