@@ -20,7 +20,7 @@ import config from "../config";
2020import { logger } from "../logger" ;
2121import { createNoteWithRevision , syncNote } from "../services/note" ;
2222import { stripTags } from "../string" ;
23- import { ModelObj , MySequelize , NoteAttributes , NoteMeta } from "./baseModel" ;
23+ import { Authorship , ModelObj , MySequelize , NoteAttributes , NoteMeta } from "./baseModel" ;
2424
2525const md = markdownIt ( )
2626export const dmp = new DiffMatchPatch ( )
@@ -34,7 +34,7 @@ interface ParsedMeta {
3434
3535export class Note extends Model < NoteAttributes > implements NoteAttributes {
3636 alias : string ;
37- authorship : string ;
37+ authorship : Authorship [ ] ;
3838 content : string ;
3939 id : string ;
4040 lastchangeAt : Date | Moment ;
@@ -96,9 +96,13 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
9696 authorship : {
9797 type : DataTypes . TEXT ( { length : 'long' } ) ,
9898 get : function ( ) {
99+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
100+ // @ts -ignore
99101 return sequelize . processData ( this . getDataValue ( 'authorship' ) , [ ] , JSON . parse )
100102 } ,
101103 set : function ( value ) {
104+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105+ // @ts -ignore
102106 this . setDataValue ( 'authorship' , JSON . stringify ( value ) )
103107 }
104108 } ,
@@ -459,16 +463,16 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
459463 return _meta
460464 }
461465
462- static updateAuthorshipByOperation ( operation : any , userId : string , authorships : any ) : any {
466+ static updateAuthorshipByOperation ( operation : ( string | number ) [ ] , userId : string , authorships : Authorship [ ] ) : Authorship [ ] {
463467 let index = 0
464468 const timestamp = Date . now ( )
465469 for ( let i = 0 ; i < operation . length ; i ++ ) {
466470 const op = operation [ i ]
467471 if ( ot . TextOperation . isRetain ( op ) ) {
468- index += op
472+ index += op as number
469473 } else if ( ot . TextOperation . isInsert ( op ) ) {
470474 const opStart = index
471- const opEnd = index + op . length
475+ const opEnd = index + ( op as string ) . length
472476 let inserted = false
473477 // authorship format: [userId, startPos, endPos, createdAt, updatedAt]
474478 if ( authorships . length <= 0 ) authorships . push ( [ userId , opStart , opEnd , timestamp , timestamp ] )
@@ -499,15 +503,15 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
499503 }
500504 }
501505 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
504508 }
505509 }
506510 }
507- index += op . length
511+ index += ( op as string ) . length
508512 } else if ( ot . TextOperation . isDelete ( op ) ) {
509513 const opStart = index
510- const opEnd = index - op
514+ const opEnd = index - ( op as number )
511515 if ( operation . length === 1 ) {
512516 authorships = [ ]
513517 } else if ( authorships . length > 0 ) {
@@ -517,7 +521,7 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
517521 authorships . splice ( j , 1 )
518522 j -= 1
519523 } else if ( authorship [ 1 ] < opStart && authorship [ 1 ] < opEnd && authorship [ 2 ] > opStart && authorship [ 2 ] > opEnd ) {
520- authorship [ 2 ] += op
524+ authorship [ 2 ] += op as number
521525 authorship [ 4 ] = timestamp
522526 } else if ( authorship [ 2 ] >= opStart && authorship [ 2 ] <= opEnd ) {
523527 authorship [ 2 ] = opStart
@@ -527,12 +531,12 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
527531 authorship [ 4 ] = timestamp
528532 }
529533 if ( authorship [ 1 ] >= opEnd ) {
530- authorship [ 1 ] += op
531- authorship [ 2 ] += op
534+ authorship [ 1 ] += op as number
535+ authorship [ 2 ] += op as number
532536 }
533537 }
534538 }
535- index += op
539+ index += ( op as number )
536540 }
537541 }
538542 // merge
@@ -561,7 +565,7 @@ export class Note extends Model<NoteAttributes> implements NoteAttributes {
561565 return authorships
562566 }
563567
564- static transformPatchToOperations ( patch : any , contentLength : number ) {
568+ static transformPatchToOperations ( patch : Patch [ ] , contentLength : number ) : ( number | string ) [ ] [ ] {
565569 const operations = [ ]
566570 if ( patch . length > 0 ) {
567571 // calculate original content length
0 commit comments