@@ -4,22 +4,23 @@ import { __livetype } from '../../../ably';
44import {
55 CompactedJsonValue ,
66 CompactedValue ,
7- Primitive ,
87 LiveMap as PublicLiveMap ,
98 LiveObject as PublicLiveObject ,
9+ Primitive ,
1010 Value ,
1111} from '../../../liveobjects' ;
1212import { LiveCounter } from './livecounter' ;
1313import { LiveCounterValueType } from './livecountervaluetype' ;
1414import { LiveMapValueType } from './livemapvaluetype' ;
1515import { LiveObject , LiveObjectData , LiveObjectUpdate , LiveObjectUpdateNoop } from './liveobject' ;
1616import {
17+ MapRemove ,
18+ MapSet ,
1719 ObjectData ,
1820 ObjectMessage ,
1921 ObjectOperation ,
2022 ObjectOperationAction ,
2123 ObjectsMapEntry ,
22- ObjectsMapOp ,
2324 ObjectsMapSemantics ,
2425} from './objectmessage' ;
2526import { RealtimeObject } from './realtimeobject' ;
@@ -130,9 +131,9 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
130131 operation : {
131132 action : ObjectOperationAction . MAP_SET ,
132133 objectId,
133- mapOp : {
134+ mapSet : {
134135 key,
135- data : objectData ,
136+ value : objectData ,
136137 } ,
137138 } as ObjectOperation < ObjectData > ,
138139 } ,
@@ -158,7 +159,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
158159 operation : {
159160 action : ObjectOperationAction . MAP_REMOVE ,
160161 objectId,
161- mapOp : { key } ,
162+ mapRemove : { key } ,
162163 } as ObjectOperation < ObjectData > ,
163164 } ,
164165 client . Utils ,
@@ -332,22 +333,22 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
332333 break ;
333334
334335 case ObjectOperationAction . MAP_SET :
335- if ( this . _client . Utils . isNil ( op . mapOp ) ) {
336+ if ( this . _client . Utils . isNil ( op . mapSet ) ) {
336337 this . _throwNoPayloadError ( op ) ;
337338 // leave an explicit return here, so that TS knows that update object is always set after the switch statement.
338339 return ;
339340 } else {
340- update = this . _applyMapSet ( op . mapOp , opSerial , msg ) ;
341+ update = this . _applyMapSet ( op . mapSet , opSerial , msg ) ;
341342 }
342343 break ;
343344
344345 case ObjectOperationAction . MAP_REMOVE :
345- if ( this . _client . Utils . isNil ( op . mapOp ) ) {
346+ if ( this . _client . Utils . isNil ( op . mapRemove ) ) {
346347 this . _throwNoPayloadError ( op ) ;
347348 // leave an explicit return here, so that TS knows that update object is always set after the switch statement.
348349 return ;
349350 } else {
350- update = this . _applyMapRemove ( op . mapOp , opSerial , msg . serialTimestamp , msg ) ;
351+ update = this . _applyMapRemove ( op . mapRemove , opSerial , msg . serialTimestamp , msg ) ;
351352 }
352353 break ;
353354
@@ -410,9 +411,9 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
410411 ) ;
411412 }
412413
413- if ( objectState . createOp . map ?. semantics !== this . _semantics ) {
414+ if ( objectState . createOp . mapCreate ?. semantics !== this . _semantics ) {
414415 throw new this . _client . ErrorInfo (
415- `Invalid object state: object state createOp map semantics=${ objectState . createOp . map ?. semantics } ; LiveMap semantics=${ this . _semantics } ` ,
416+ `Invalid object state: object state createOp map semantics=${ objectState . createOp . mapCreate ?. semantics } ; LiveMap semantics=${ this . _semantics } ` ,
416417 92000 ,
417418 500 ,
418419 ) ;
@@ -643,7 +644,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
643644 objectOperation : ObjectOperation < ObjectData > ,
644645 msg : ObjectMessage ,
645646 ) : LiveMapUpdate < T > {
646- if ( this . _client . Utils . isNil ( objectOperation . map ) ) {
647+ if ( this . _client . Utils . isNil ( objectOperation . mapCreate ) ) {
647648 // if a map object is missing for the MAP_CREATE op, the initial value is implicitly an empty map.
648649 // in this case there is nothing to merge into the current map, so we can just end processing the op.
649650 return { update : { } , objectMessage : msg , _type : 'LiveMapUpdate' } ;
@@ -657,7 +658,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
657658 // RTLM6d1
658659 // in order to apply MAP_CREATE op for an existing map, we should merge their underlying entries keys.
659660 // we can do this by iterating over entries from MAP_CREATE op and apply changes on per-key basis as if we had MAP_SET, MAP_REMOVE operations.
660- Object . entries ( objectOperation . map . entries ?? { } ) . forEach ( ( [ key , entry ] ) => {
661+ Object . entries ( objectOperation . mapCreate . entries ?? { } ) . forEach ( ( [ key , entry ] ) => {
661662 // for a MAP_CREATE operation we must use the serial value available on an entry, instead of a serial on a message
662663 const opSerial = entry . timeserial ;
663664 let update : LiveMapUpdate < T > | LiveObjectUpdateNoop ;
@@ -666,7 +667,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
666667 update = this . _applyMapRemove ( { key } , opSerial , entry . serialTimestamp , msg ) ;
667668 } else {
668669 // RTLM6d1a - entry in MAP_CREATE op is not removed, try to set it via MAP_SET op
669- update = this . _applyMapSet ( { key, data : entry . data } , opSerial , msg ) ;
670+ update = this . _applyMapSet ( { key, value : entry . data ! } , opSerial , msg ) ;
670671 }
671672
672673 // skip noop updates
@@ -708,9 +709,9 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
708709 return { noop : true } ;
709710 }
710711
711- if ( this . _semantics !== op . map ?. semantics ) {
712+ if ( this . _semantics !== op . mapCreate ?. semantics ) {
712713 throw new this . _client . ErrorInfo (
713- `Cannot apply MAP_CREATE op on LiveMap objectId=${ this . getObjectId ( ) } ; map's semantics=${ this . _semantics } , but op expected ${ op . map ?. semantics } ` ,
714+ `Cannot apply MAP_CREATE op on LiveMap objectId=${ this . getObjectId ( ) } ; map's semantics=${ this . _semantics } , but op expected ${ op . mapCreate ?. semantics } ` ,
714715 92000 ,
715716 500 ,
716717 ) ;
@@ -721,7 +722,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
721722
722723 /** @spec RTLM7 */
723724 private _applyMapSet (
724- op : ObjectsMapOp < ObjectData > ,
725+ op : MapSet < ObjectData > ,
725726 opSerial : string | undefined ,
726727 msg : ObjectMessage ,
727728 ) : LiveMapUpdate < T > | LiveObjectUpdateNoop {
@@ -740,7 +741,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
740741 return { noop : true } ;
741742 }
742743
743- if ( Utils . isNil ( op . data ) || ( Utils . isNil ( op . data . objectId ) && Utils . isNil ( op . data . value ) ) ) {
744+ if ( Utils . isNil ( op . value ) || ( Utils . isNil ( op . value . objectId ) && Utils . isNil ( op . value . value ) ) ) {
744745 throw new ErrorInfo (
745746 `Invalid object data for MAP_SET op on objectId=${ this . getObjectId ( ) } on key="${ op . key } "` ,
746747 92000 ,
@@ -750,15 +751,15 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
750751
751752 let liveData : LiveMapObjectData ;
752753 // RTLM7c
753- if ( ! Utils . isNil ( op . data . objectId ) ) {
754- liveData = { objectId : op . data . objectId } as ObjectIdObjectData ;
754+ if ( ! Utils . isNil ( op . value . objectId ) ) {
755+ liveData = { objectId : op . value . objectId } as ObjectIdObjectData ;
755756 // this MAP_SET op is setting a key to point to another object via its object id,
756757 // but it is possible that we don't have the corresponding object in the pool yet (for example, we haven't seen the *_CREATE op for it).
757758 // we don't want to return undefined from this map's .get() method even if we don't have the object,
758759 // so instead we create a zero-value object for that object id if it not exists.
759- this . _realtimeObject . getPool ( ) . createZeroValueObjectIfNotExists ( op . data . objectId ) ; // RTLM7c1
760+ this . _realtimeObject . getPool ( ) . createZeroValueObjectIfNotExists ( op . value . objectId ) ; // RTLM7c1
760761 } else {
761- liveData = { value : op . data . value } as ValueObjectData ;
762+ liveData = { value : op . value . value } as ValueObjectData ;
762763 }
763764
764765 if ( existingEntry ) {
@@ -808,7 +809,7 @@ export class LiveMap<T extends Record<string, Value> = Record<string, Value>>
808809
809810 /** @spec RTLM8 */
810811 private _applyMapRemove (
811- op : ObjectsMapOp < ObjectData > ,
812+ op : MapRemove ,
812813 opSerial : string | undefined ,
813814 opTimestamp : number | undefined ,
814815 msg : ObjectMessage ,
0 commit comments