11import { deepEqual } from '@jsonjoy.com/util/lib/json-equal/deepEqual' ;
22import { cmpUint8Array } from '@jsonjoy.com/util/lib/buffers/cmpUint8Array' ;
3- import { ITimespanStruct , type ITimestampStruct , Patch , PatchBuilder , Timespan } from '../json-crdt-patch' ;
3+ import { type ITimespanStruct , type ITimestampStruct , type Patch , PatchBuilder , Timespan } from '../json-crdt-patch' ;
44import { ArrNode , BinNode , ConNode , ObjNode , StrNode , ValNode , VecNode , type JsonNode } from '../json-crdt/nodes' ;
55import * as str from '../util/diff/str' ;
66import * as bin from '../util/diff/bin' ;
@@ -26,7 +26,9 @@ export class JsonCrdtDiff {
2626 const view = src . view ( ) ;
2727 if ( view === dst ) return ;
2828 const builder = this . builder ;
29- str . apply ( str . diff ( view , dst ) , view . length ,
29+ str . apply (
30+ str . diff ( view , dst ) ,
31+ view . length ,
3032 ( pos , txt ) => builder . insStr ( src . id , ! pos ? src . id : src . find ( pos - 1 ) ! , txt ) ,
3133 ( pos , len ) => builder . del ( src . id , src . findInterval ( pos , len ) ) ,
3234 ) ;
@@ -36,15 +38,17 @@ export class JsonCrdtDiff {
3638 const view = src . view ( ) ;
3739 if ( cmpUint8Array ( view , dst ) ) return ;
3840 const builder = this . builder ;
39- bin . apply ( bin . diff ( view , dst ) , view . length ,
41+ bin . apply (
42+ bin . diff ( view , dst ) ,
43+ view . length ,
4044 ( pos , txt ) => builder . insBin ( src . id , ! pos ? src . id : src . find ( pos - 1 ) ! , txt ) ,
4145 ( pos , len ) => builder . del ( src . id , src . findInterval ( pos , len ) ) ,
4246 ) ;
4347 }
4448
4549 protected diffArr ( src : ArrNode , dst : unknown [ ] ) : void {
4650 const srcLines : string [ ] = [ ] ;
47- src . children ( node => {
51+ src . children ( ( node ) => {
4852 srcLines . push ( structHashCrdt ( node ) ) ;
4953 } ) ;
5054 const dstLines : string [ ] = [ ] ;
@@ -93,7 +97,11 @@ export class JsonCrdtDiff {
9397 const length = inserts . length ;
9498 for ( let i = 0 ; i < length ; i ++ ) {
9599 const [ after , views ] = inserts [ i ] ;
96- builder . insArr ( src . id , after , views . map ( view => builder . json ( view ) ) )
100+ builder . insArr (
101+ src . id ,
102+ after ,
103+ views . map ( ( view ) => builder . json ( view ) ) ,
104+ ) ;
97105 }
98106 if ( deletes . length ) builder . del ( src . id , deletes ) ;
99107 }
@@ -102,6 +110,7 @@ export class JsonCrdtDiff {
102110 const builder = this . builder ;
103111 const inserts : [ key : string , value : ITimestampStruct ] [ ] = [ ] ;
104112 const srcKeys = new Set < string > ( ) ;
113+ // biome-ignore lint: .forEach is fastest here
105114 src . forEach ( ( key ) => {
106115 srcKeys . add ( key ) ;
107116 const dstValue = dst [ key ] ;
@@ -123,8 +132,7 @@ export class JsonCrdtDiff {
123132 }
124133 }
125134 }
126- inserts . push ( [ key , src . get ( key ) instanceof ConNode
127- ? builder . const ( dstValue ) : builder . constOrJson ( dstValue ) ] ) ;
135+ inserts . push ( [ key , src . get ( key ) instanceof ConNode ? builder . const ( dstValue ) : builder . constOrJson ( dstValue ) ] ) ;
128136 }
129137 if ( inserts . length ) builder . insObj ( src . id , inserts ) ;
130138 }
@@ -177,7 +185,7 @@ export class JsonCrdtDiff {
177185 public diffAny ( src : JsonNode , dst : unknown ) : void {
178186 if ( src instanceof ConNode ) {
179187 const val = src . val ;
180- if ( ( val !== dst ) && ! deepEqual ( src . val , dst ) ) throw new DiffError ( ) ;
188+ if ( val !== dst && ! deepEqual ( src . val , dst ) ) throw new DiffError ( ) ;
181189 } else if ( src instanceof StrNode ) {
182190 if ( typeof dst !== 'string' ) throw new DiffError ( ) ;
183191 this . diffStr ( src , dst ) ;
0 commit comments