11import { LiveObject , LiveObjectData , LiveObjectUpdate , LiveObjectUpdateNoop } from './liveobject' ;
22import { ObjectId } from './objectid' ;
3- import { ObjectMessage , ObjectOperation , ObjectOperationAction , ObjectsCounterOp , ObjectState } from './objectmessage' ;
3+ import {
4+ encodeInitialValue ,
5+ ObjectData ,
6+ ObjectMessage ,
7+ ObjectOperation ,
8+ ObjectOperationAction ,
9+ ObjectsCounterOp ,
10+ ObjectState ,
11+ } from './objectmessage' ;
412import { Objects } from './objects' ;
513
614export interface LiveCounterData extends LiveObjectData {
@@ -29,7 +37,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
2937 *
3038 * @internal
3139 */
32- static fromObjectState ( objects : Objects , objectState : ObjectState ) : LiveCounter {
40+ static fromObjectState ( objects : Objects , objectState : ObjectState < ObjectData > ) : LiveCounter {
3341 const obj = new LiveCounter ( objects , objectState . objectId ) ;
3442 obj . overrideWithObjectState ( objectState ) ;
3543 return obj ;
@@ -41,7 +49,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
4149 *
4250 * @internal
4351 */
44- static fromObjectOperation ( objects : Objects , objectOperation : ObjectOperation ) : LiveCounter {
52+ static fromObjectOperation ( objects : Objects , objectOperation : ObjectOperation < ObjectData > ) : LiveCounter {
4553 const obj = new LiveCounter ( objects , objectOperation . objectId ) ;
4654 obj . _mergeInitialDataFromCreateOperation ( objectOperation ) ;
4755 return obj ;
@@ -63,7 +71,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
6371 action : ObjectOperationAction . COUNTER_INC ,
6472 objectId,
6573 counterOp : { amount } ,
66- } as ObjectOperation ,
74+ } as ObjectOperation < ObjectData > ,
6775 } ,
6876 client . Utils ,
6977 client . MessageEncoding ,
@@ -83,7 +91,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
8391 }
8492
8593 const initialValueObj = LiveCounter . createInitialValueObject ( count ) ;
86- const { encodedInitialValue, format } = ObjectMessage . encodeInitialValue ( initialValueObj , client ) ;
94+ const { encodedInitialValue, format } = encodeInitialValue ( initialValueObj , client ) ;
8795 const nonce = client . Utils . cheapRandStr ( ) ;
8896 const msTimestamp = await client . getTimestamp ( true ) ;
8997
@@ -104,7 +112,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
104112 nonce,
105113 initialValue : encodedInitialValue ,
106114 initialValueEncoding : format ,
107- } as ObjectOperation ,
115+ } as ObjectOperation < ObjectData > ,
108116 } ,
109117 client . Utils ,
110118 client . MessageEncoding ,
@@ -116,7 +124,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
116124 /**
117125 * @internal
118126 */
119- static createInitialValueObject ( count ?: number ) : Pick < ObjectOperation , 'counter' > {
127+ static createInitialValueObject ( count ?: number ) : Pick < ObjectOperation < ObjectData > , 'counter' > {
120128 return {
121129 counter : {
122130 count : count ?? 0 ,
@@ -162,7 +170,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
162170 /**
163171 * @internal
164172 */
165- applyOperation ( op : ObjectOperation , msg : ObjectMessage ) : void {
173+ applyOperation ( op : ObjectOperation < ObjectData > , msg : ObjectMessage ) : void {
166174 if ( op . objectId !== this . getObjectId ( ) ) {
167175 throw new this . _client . ErrorInfo (
168176 `Cannot apply object operation with objectId=${ op . objectId } , to this LiveCounter with objectId=${ this . getObjectId ( ) } ` ,
@@ -226,7 +234,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
226234 * @internal
227235 * @spec RTLC6
228236 */
229- overrideWithObjectState ( objectState : ObjectState ) : LiveCounterUpdate | LiveObjectUpdateNoop {
237+ overrideWithObjectState ( objectState : ObjectState < ObjectData > ) : LiveCounterUpdate | LiveObjectUpdateNoop {
230238 if ( objectState . objectId !== this . getObjectId ( ) ) {
231239 throw new this . _client . ErrorInfo (
232240 `Invalid object state: object state objectId=${ objectState . objectId } ; LiveCounter objectId=${ this . getObjectId ( ) } ` ,
@@ -300,7 +308,7 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
300308 return { update : { amount : counterDiff } } ;
301309 }
302310
303- protected _mergeInitialDataFromCreateOperation ( objectOperation : ObjectOperation ) : LiveCounterUpdate {
311+ protected _mergeInitialDataFromCreateOperation ( objectOperation : ObjectOperation < ObjectData > ) : LiveCounterUpdate {
304312 // if a counter object is missing for the COUNTER_CREATE op, the initial value is implicitly 0 in this case.
305313 // note that it is intentional to SUM the incoming count from the create op.
306314 // if we got here, it means that current counter instance is missing the initial value in its data reference,
@@ -311,15 +319,15 @@ export class LiveCounter extends LiveObject<LiveCounterData, LiveCounterUpdate>
311319 return { update : { amount : objectOperation . counter ?. count ?? 0 } } ;
312320 }
313321
314- private _throwNoPayloadError ( op : ObjectOperation ) : void {
322+ private _throwNoPayloadError ( op : ObjectOperation < ObjectData > ) : void {
315323 throw new this . _client . ErrorInfo (
316324 `No payload found for ${ op . action } op for LiveCounter objectId=${ this . getObjectId ( ) } ` ,
317325 92000 ,
318326 500 ,
319327 ) ;
320328 }
321329
322- private _applyCounterCreate ( op : ObjectOperation ) : LiveCounterUpdate | LiveObjectUpdateNoop {
330+ private _applyCounterCreate ( op : ObjectOperation < ObjectData > ) : LiveCounterUpdate | LiveObjectUpdateNoop {
323331 if ( this . _createOperationIsMerged ) {
324332 // There can't be two different create operation for the same object id, because the object id
325333 // fully encodes that operation. This means we can safely ignore any new incoming create operations
0 commit comments