11import { Log } from 'json-joy/lib/json-crdt/log/Log' ;
2- import { Model , Patch } from 'json-joy/lib/json-crdt' ;
2+ import { JsonNode , Model , Patch } from 'json-joy/lib/json-crdt' ;
33import { concurrency } from 'thingies/lib/concurrencyDecorator' ;
44import { createRace } from 'thingies/lib/createRace' ;
55import { SESSION } from 'json-joy/lib/json-crdt-patch/constants' ;
@@ -15,25 +15,25 @@ import type {
1515 LocalRepoResetEvent ,
1616} from '../local/types' ;
1717
18- export class EditSession {
19- public log : Log ;
18+ export class EditSession < N extends JsonNode = JsonNode < any > > {
19+ public log : Log < N > ;
2020 protected _stopped = false ;
2121 protected _stop$ = new Subject < void > ( ) ;
2222 public onsyncerror ?: ( error : Error | unknown ) => void ;
2323 private _syncRace = createRace ( ) ;
2424
25- public get model ( ) : Model {
25+ public get model ( ) : Model < N > {
2626 return this . log . end ;
2727 }
2828
2929 constructor (
3030 public readonly repo : LocalRepo ,
3131 public readonly id : BlockId ,
32- protected start : Model ,
32+ protected start : Model < N > ,
3333 public cursor : undefined | unknown = undefined ,
3434 protected readonly session : number = Math . floor ( Math . random ( ) * 0x7fffffff ) ,
3535 ) {
36- this . log = new Log ( ( ) => this . start . clone ( ) ) ;
36+ this . log = new Log < N > ( ( ) => this . start . clone ( ) ) ;
3737 const api = this . log . end . api ;
3838 const flushUnsubscribe = api . onFlush . listen ( ( a ) => {
3939 this . syncLog ( ) ;
@@ -62,9 +62,9 @@ export class EditSession {
6262 protected clear ( ) : void {
6363 const { start, log} = this ;
6464 const empty = Model . create ( undefined , start . clock . sid ) ;
65- start . reset ( empty ) ;
65+ start . reset ( < any > empty ) ;
6666 log . patches . clear ( ) ;
67- log . end . reset ( empty ) ;
67+ log . end . reset ( < any > empty ) ;
6868 }
6969
7070 private saveInProgress = false ;
@@ -99,19 +99,19 @@ export class EditSession {
9999 if ( typeof res . cursor !== undefined ) this . cursor = res . cursor ;
100100 if ( res . model ) {
101101 this . _syncRace ( ( ) => {
102- this . reset ( res . model ! ) ;
102+ this . reset ( < any > res . model ! ) ;
103103 } ) ;
104104 } else if ( res . merge ) {
105105 this . _syncRace ( ( ) => {
106- this . merge ( res . merge ! ) ;
106+ this . merge ( < any > res . merge ! ) ;
107107 } ) ;
108108 }
109109 return { remote : res . remote } ;
110110 } else {
111111 const res = await this . repo . getIf ( { id : this . id , time : this . model . clock . time - 1 , cursor : this . cursor } ) ;
112112 if ( this . _stopped ) return null ;
113113 if ( res ) {
114- this . reset ( res . model ) ;
114+ this . reset ( < any > res . model ) ;
115115 this . cursor = res . cursor ;
116116 }
117117 return null ;
@@ -142,7 +142,7 @@ export class EditSession {
142142 */
143143 public async load ( ) : Promise < void > {
144144 const { model} = await this . repo . get ( { id : this . id } ) ;
145- if ( model . clock . time > this . start . clock . time ) this . reset ( model ) ;
145+ if ( model . clock . time > this . start . clock . time ) this . reset ( < any > model ) ;
146146 }
147147
148148 public loadSilent ( ) : void {
@@ -151,7 +151,7 @@ export class EditSession {
151151
152152 // ------------------------------------------------------- change integration
153153
154- protected reset ( model : Model ) : void {
154+ protected reset ( model : Model < N > ) : void {
155155 this . start = model . clone ( ) ;
156156 const log = this . log ;
157157 const end = log . end ;
@@ -224,7 +224,7 @@ export class EditSession {
224224 for ( let i = 0 ; i < length ; i ++ ) {
225225 const event = events [ i ] ;
226226 try {
227- if ( ( event as LocalRepoResetEvent ) . reset ) this . reset ( ( event as LocalRepoResetEvent ) . reset ) ;
227+ if ( ( event as LocalRepoResetEvent ) . reset ) this . reset ( < any > ( event as LocalRepoResetEvent ) . reset ) ;
228228 else if ( ( event as LocalRepoRebaseEvent ) . rebase ) this . rebase ( ( event as LocalRepoRebaseEvent ) . rebase ) ;
229229 else if ( ( event as LocalRepoMergeEvent ) . merge ) this . merge ( ( event as LocalRepoMergeEvent ) . merge ) ;
230230 else if ( ( event as LocalRepoDeleteEvent ) . del ) {
0 commit comments