@@ -6,14 +6,14 @@ import {SESSION} from '../../../../json-crdt-patch/constants';
6
6
import * as types from './types' ;
7
7
8
8
export class Decoder {
9
- public decode ( { time, root} : types . JsonCrdtSnapshot ) : Model {
9
+ public decode ( { time, root} : types . JsonCrdtVerboseDocument ) : Model {
10
10
const isServerClock = typeof time === 'number' ;
11
11
const doc = isServerClock ? Model . withServerClock ( time ) : Model . withLogicalClock ( this . cClock ( time ) ) ;
12
12
this . cRoot ( doc , root ) ;
13
13
return doc ;
14
14
}
15
15
16
- protected cClock ( timestamps : types . JsonCrdtLogicalTimestamp [ ] ) : VectorClock {
16
+ protected cClock ( timestamps : types . JsonCrdtVerboseLogicalTimestamp [ ] ) : VectorClock {
17
17
const [ stamp ] = timestamps ;
18
18
const vectorClock = new VectorClock ( stamp [ 0 ] , stamp [ 1 ] ) ;
19
19
const length = timestamps . length ;
@@ -25,12 +25,12 @@ export class Decoder {
25
25
return vectorClock ;
26
26
}
27
27
28
- protected cTs ( stamp : types . JsonCrdtTimestamp ) : ITimestampStruct {
28
+ protected cTs ( stamp : types . JsonCrdtVerboseTimestamp ) : ITimestampStruct {
29
29
const isServerClock = typeof stamp === 'number' ;
30
30
return isServerClock ? ts ( SESSION . SERVER , stamp ) : ts ( stamp [ 0 ] , stamp [ 1 ] ) ;
31
31
}
32
32
33
- protected cRoot ( doc : Model , { value} : types . ValueJsonCrdtNode ) : void {
33
+ protected cRoot ( doc : Model , { value} : types . JsonCrdtVerboseVal ) : void {
34
34
const val = value ? this . cNode ( doc , value ) : new nodes . ConNode ( doc . clock . tick ( 0 ) , null ) ;
35
35
const root = new nodes . RootNode ( doc , val . id ) ;
36
36
doc . root = root ;
@@ -56,7 +56,7 @@ export class Decoder {
56
56
throw new Error ( 'UNKNOWN_NODE' ) ;
57
57
}
58
58
59
- protected cObj ( doc : Model , node : types . ObjectJsonCrdtNode ) : nodes . ObjNode {
59
+ protected cObj ( doc : Model , node : types . JsonCrdtVerboseObj ) : nodes . ObjNode {
60
60
const id = this . cTs ( node . id ) ;
61
61
const obj = new nodes . ObjNode ( doc , id ) ;
62
62
const map = node . map ;
@@ -69,7 +69,7 @@ export class Decoder {
69
69
return obj ;
70
70
}
71
71
72
- protected cVec ( doc : Model , node : types . VectorJsonCrdtNode ) : nodes . VecNode {
72
+ protected cVec ( doc : Model , node : types . JsonCrdtVerboseVec ) : nodes . VecNode {
73
73
const id = this . cTs ( node . id ) ;
74
74
const obj = new nodes . VecNode ( doc , id ) ;
75
75
const elements = obj . elements ;
@@ -84,7 +84,7 @@ export class Decoder {
84
84
return obj ;
85
85
}
86
86
87
- protected cArr ( doc : Model , node : types . ArrayJsonCrdtNode ) : nodes . ArrNode {
87
+ protected cArr ( doc : Model , node : types . JsonCrdtVerboseArr ) : nodes . ArrNode {
88
88
const id = this . cTs ( node . id ) ;
89
89
const rga = new nodes . ArrNode ( doc , id ) ;
90
90
const chunks = node . chunks ;
@@ -95,10 +95,10 @@ export class Decoder {
95
95
rga . ingest ( length , ( ) => {
96
96
const c = chunks [ i ++ ] ;
97
97
const id = self . cTs ( c . id ) ;
98
- if ( typeof ( c as types . JsonCrdtRgaTombstone ) . span === 'number' )
99
- return new nodes . ArrChunk ( id , ( c as types . JsonCrdtRgaTombstone ) . span , undefined ) ;
98
+ if ( typeof ( c as types . JsonCrdtVerboseTombstone ) . span === 'number' )
99
+ return new nodes . ArrChunk ( id , ( c as types . JsonCrdtVerboseTombstone ) . span , undefined ) ;
100
100
else {
101
- const ids = ( c as types . ArrayJsonCrdtChunk ) . value . map ( ( n ) => this . cNode ( doc , n ) . id ) ;
101
+ const ids = ( c as types . JsonCrdtVerboseArrChunk ) . value . map ( ( n ) => this . cNode ( doc , n ) . id ) ;
102
102
return new nodes . ArrChunk ( id , ids . length , ids ) ;
103
103
}
104
104
} ) ;
@@ -107,7 +107,7 @@ export class Decoder {
107
107
return rga ;
108
108
}
109
109
110
- protected cStr ( doc : Model , node : types . StringJsonCrdtNode ) : nodes . StrNode {
110
+ protected cStr ( doc : Model , node : types . JsonCrdtVerboseStr ) : nodes . StrNode {
111
111
const id = this . cTs ( node . id ) ;
112
112
const rga = new nodes . StrNode ( id ) ;
113
113
const chunks = node . chunks ;
@@ -118,10 +118,10 @@ export class Decoder {
118
118
rga . ingest ( length , ( ) => {
119
119
const c = chunks [ i ++ ] ;
120
120
const id = self . cTs ( c . id ) ;
121
- if ( typeof ( c as types . JsonCrdtRgaTombstone ) . span === 'number' )
122
- return new nodes . StrChunk ( id , ( c as types . JsonCrdtRgaTombstone ) . span , '' ) ;
121
+ if ( typeof ( c as types . JsonCrdtVerboseTombstone ) . span === 'number' )
122
+ return new nodes . StrChunk ( id , ( c as types . JsonCrdtVerboseTombstone ) . span , '' ) ;
123
123
else {
124
- const value = ( c as types . StringJsonCrdtChunk ) . value ;
124
+ const value = ( c as types . JsonCrdtVerboseStrChunk ) . value ;
125
125
return new nodes . StrChunk ( id , value . length , value ) ;
126
126
}
127
127
} ) ;
@@ -130,7 +130,7 @@ export class Decoder {
130
130
return rga ;
131
131
}
132
132
133
- protected cBin ( doc : Model , node : types . BinaryJsonCrdtNode ) : nodes . BinNode {
133
+ protected cBin ( doc : Model , node : types . JsonCrdtVerboseBin ) : nodes . BinNode {
134
134
const id = this . cTs ( node . id ) ;
135
135
const rga = new nodes . BinNode ( id ) ;
136
136
const chunks = node . chunks ;
@@ -141,10 +141,10 @@ export class Decoder {
141
141
rga . ingest ( length , ( ) => {
142
142
const c = chunks [ i ++ ] ;
143
143
const id = self . cTs ( c . id ) ;
144
- if ( typeof ( c as types . JsonCrdtRgaTombstone ) . span === 'number' )
145
- return new nodes . BinChunk ( id , ( c as types . JsonCrdtRgaTombstone ) . span , undefined ) ;
144
+ if ( typeof ( c as types . JsonCrdtVerboseTombstone ) . span === 'number' )
145
+ return new nodes . BinChunk ( id , ( c as types . JsonCrdtVerboseTombstone ) . span , undefined ) ;
146
146
else {
147
- const value = ( c as types . BinaryJsonCrdtChunk ) . value ;
147
+ const value = ( c as types . JsonCrdtVerboseBinChunk ) . value ;
148
148
const buf = fromBase64 ( value ) ;
149
149
return new nodes . BinChunk ( id , buf . length , buf ) ;
150
150
}
@@ -154,17 +154,17 @@ export class Decoder {
154
154
return rga ;
155
155
}
156
156
157
- protected cVal ( doc : Model , node : types . ValueJsonCrdtNode ) : nodes . ValNode {
157
+ protected cVal ( doc : Model , node : types . JsonCrdtVerboseVal ) : nodes . ValNode {
158
158
const id = this . cTs ( node . id ) ;
159
159
const val = this . cNode ( doc , node . value ) ;
160
160
const obj = new nodes . ValNode ( doc , id , val . id ) ;
161
161
doc . index . set ( id , obj ) ;
162
162
return obj ;
163
163
}
164
164
165
- protected cCon ( doc : Model , node : types . ConstantJsonCrdtNode ) : nodes . ConNode {
165
+ protected cCon ( doc : Model , node : types . JsonCrdtVerboseCon ) : nodes . ConNode {
166
166
const id = this . cTs ( node . id ) ;
167
- const val = node . timestamp ? this . cTs ( node . value as types . JsonCrdtLogicalTimestamp ) : node . value ;
167
+ const val = node . timestamp ? this . cTs ( node . value as types . JsonCrdtVerboseLogicalTimestamp ) : node . value ;
168
168
const obj = new nodes . ConNode ( id , val ) ;
169
169
doc . index . set ( id , obj ) ;
170
170
return obj ;
0 commit comments