1- import {
2- NewConOp ,
3- NewObjOp ,
4- NewValOp ,
5- NewVecOp ,
6- NewStrOp ,
7- NewBinOp ,
8- NewArrOp ,
9- InsValOp ,
10- InsObjOp ,
11- InsVecOp ,
12- InsStrOp ,
13- InsBinOp ,
14- InsArrOp ,
15- DelOp ,
16- NopOp ,
17- } from './operations' ;
1+ import * as operations from './operations' ;
182import { ITimestampStruct , ts , toDisplayString } from './clock' ;
193import { SESSION } from './constants' ;
204import { encode , decode } from './codec/binary' ;
@@ -24,21 +8,21 @@ import type {Printable} from '../util/print/types';
248 * A union type of all possible JSON CRDT patch operations.
259 */
2610export type JsonCrdtPatchOperation =
27- | NewConOp
28- | NewValOp
29- | NewVecOp
30- | NewObjOp
31- | NewStrOp
32- | NewBinOp
33- | NewArrOp
34- | InsValOp
35- | InsObjOp
36- | InsVecOp
37- | InsStrOp
38- | InsBinOp
39- | InsArrOp
40- | DelOp
41- | NopOp ;
11+ | operations . NewConOp
12+ | operations . NewValOp
13+ | operations . NewVecOp
14+ | operations . NewObjOp
15+ | operations . NewStrOp
16+ | operations . NewBinOp
17+ | operations . NewArrOp
18+ | operations . InsValOp
19+ | operations . InsObjOp
20+ | operations . InsVecOp
21+ | operations . InsStrOp
22+ | operations . InsBinOp
23+ | operations . InsArrOp
24+ | operations . DelOp
25+ | operations . NopOp ;
4226
4327/**
4428 * Represents a JSON CRDT patch.
@@ -135,27 +119,31 @@ export class Patch implements Printable {
135119 const patchOps = patch . ops ;
136120 for ( let i = 0 ; i < length ; i ++ ) {
137121 const op = ops [ i ] ;
138- if ( op instanceof DelOp ) patchOps . push ( new DelOp ( ts ( op . id ) , ts ( op . obj ) , op . what ) ) ;
139- else if ( op instanceof NewConOp ) patchOps . push ( new NewConOp ( ts ( op . id ) , op . val ) ) ;
140- else if ( op instanceof NewVecOp ) patchOps . push ( new NewVecOp ( ts ( op . id ) ) ) ;
141- else if ( op instanceof NewValOp ) patchOps . push ( new NewValOp ( ts ( op . id ) , ts ( op . val ) ) ) ;
142- else if ( op instanceof NewObjOp ) patchOps . push ( new NewObjOp ( ts ( op . id ) ) ) ;
143- else if ( op instanceof NewStrOp ) patchOps . push ( new NewStrOp ( ts ( op . id ) ) ) ;
144- else if ( op instanceof NewBinOp ) patchOps . push ( new NewBinOp ( ts ( op . id ) ) ) ;
145- else if ( op instanceof NewArrOp ) patchOps . push ( new NewArrOp ( ts ( op . id ) ) ) ;
146- else if ( op instanceof InsArrOp ) patchOps . push ( new InsArrOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . ref ) , op . data . map ( ts ) ) ) ;
147- else if ( op instanceof InsStrOp ) patchOps . push ( new InsStrOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . ref ) , op . data ) ) ;
148- else if ( op instanceof InsBinOp ) patchOps . push ( new InsBinOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . ref ) , op . data ) ) ;
149- else if ( op instanceof InsValOp ) patchOps . push ( new InsValOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . val ) ) ) ;
150- else if ( op instanceof InsObjOp )
122+ if ( op instanceof operations . DelOp ) patchOps . push ( new operations . DelOp ( ts ( op . id ) , ts ( op . obj ) , op . what ) ) ;
123+ else if ( op instanceof operations . NewConOp ) patchOps . push ( new operations . NewConOp ( ts ( op . id ) , op . val ) ) ;
124+ else if ( op instanceof operations . NewVecOp ) patchOps . push ( new operations . NewVecOp ( ts ( op . id ) ) ) ;
125+ else if ( op instanceof operations . NewValOp ) patchOps . push ( new operations . NewValOp ( ts ( op . id ) ) ) ;
126+ else if ( op instanceof operations . NewObjOp ) patchOps . push ( new operations . NewObjOp ( ts ( op . id ) ) ) ;
127+ else if ( op instanceof operations . NewStrOp ) patchOps . push ( new operations . NewStrOp ( ts ( op . id ) ) ) ;
128+ else if ( op instanceof operations . NewBinOp ) patchOps . push ( new operations . NewBinOp ( ts ( op . id ) ) ) ;
129+ else if ( op instanceof operations . NewArrOp ) patchOps . push ( new operations . NewArrOp ( ts ( op . id ) ) ) ;
130+ else if ( op instanceof operations . InsArrOp )
131+ patchOps . push ( new operations . InsArrOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . ref ) , op . data . map ( ts ) ) ) ;
132+ else if ( op instanceof operations . InsStrOp )
133+ patchOps . push ( new operations . InsStrOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . ref ) , op . data ) ) ;
134+ else if ( op instanceof operations . InsBinOp )
135+ patchOps . push ( new operations . InsBinOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . ref ) , op . data ) ) ;
136+ else if ( op instanceof operations . InsValOp )
137+ patchOps . push ( new operations . InsValOp ( ts ( op . id ) , ts ( op . obj ) , ts ( op . val ) ) ) ;
138+ else if ( op instanceof operations . InsObjOp )
151139 patchOps . push (
152- new InsObjOp (
140+ new operations . InsObjOp (
153141 ts ( op . id ) ,
154142 ts ( op . obj ) ,
155143 op . data . map ( ( [ key , value ] ) => [ key , ts ( value ) ] ) ,
156144 ) ,
157145 ) ;
158- else if ( op instanceof NopOp ) patchOps . push ( new NopOp ( ts ( op . id ) , op . len ) ) ;
146+ else if ( op instanceof operations . NopOp ) patchOps . push ( new operations . NopOp ( ts ( op . id ) , op . len ) ) ;
159147 }
160148 return patch ;
161149 }
0 commit comments