@@ -13,7 +13,6 @@ import {
1313 ObjectsMapEntry ,
1414 ObjectsMapOp ,
1515 ObjectsMapSemantics ,
16- PrimitiveObjectValue ,
1716} from './objectmessage' ;
1817import { RealtimeObject } from './realtimeobject' ;
1918
@@ -24,7 +23,7 @@ export interface ObjectIdObjectData {
2423
2524export interface ValueObjectData {
2625 /** A decoded leaf value from {@link WireObjectData}. */
27- value : string | number | boolean | Buffer | ArrayBuffer | API . JsonArray | API . JsonObject ;
26+ value : API . Primitive ;
2827}
2928
3029export type LiveMapObjectData = ObjectIdObjectData | ValueObjectData ;
@@ -40,13 +39,18 @@ export interface LiveMapData extends LiveObjectData {
4039 data : Map < string , LiveMapEntry > ; // RTLM3
4140}
4241
43- export interface LiveMapUpdate < T extends API . LiveMapType > extends LiveObjectUpdate {
42+ export interface LiveMapUpdate < T extends Record < string , API . Value > > extends LiveObjectUpdate {
4443 update : { [ keyName in keyof T & string ] ?: 'updated' | 'removed' } ;
4544 _type : 'LiveMapUpdate' ;
4645}
4746
4847/** @spec RTLM1, RTLM2 */
49- export class LiveMap < T extends API . LiveMapType > extends LiveObject < LiveMapData , LiveMapUpdate < T > > {
48+ export class LiveMap < T extends Record < string , API . Value > = Record < string , API . Value > >
49+ extends LiveObject < LiveMapData , LiveMapUpdate < T > >
50+ implements API . LiveMap < T >
51+ {
52+ declare readonly [ API . __livetype ] : 'LiveMap' ; // type-only, unique symbol to satisfy branded interfaces, no JS emitted
53+
5054 constructor (
5155 realtimeObject : RealtimeObject ,
5256 private _semantics : ObjectsMapSemantics ,
@@ -61,8 +65,8 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
6165 * @internal
6266 * @spec RTLM4
6367 */
64- static zeroValue < T extends API . LiveMapType > ( realtimeObject : RealtimeObject , objectId : string ) : LiveMap < T > {
65- return new LiveMap < T > ( realtimeObject , ObjectsMapSemantics . LWW , objectId ) ;
68+ static zeroValue ( realtimeObject : RealtimeObject , objectId : string ) : LiveMap {
69+ return new LiveMap ( realtimeObject , ObjectsMapSemantics . LWW , objectId ) ;
6670 }
6771
6872 /**
@@ -71,23 +75,20 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
7175 *
7276 * @internal
7377 */
74- static fromObjectState < T extends API . LiveMapType > (
75- realtimeObject : RealtimeObject ,
76- objectMessage : ObjectMessage ,
77- ) : LiveMap < T > {
78- const obj = new LiveMap < T > ( realtimeObject , objectMessage . object ! . map ! . semantics ! , objectMessage . object ! . objectId ) ;
78+ static fromObjectState ( realtimeObject : RealtimeObject , objectMessage : ObjectMessage ) : LiveMap {
79+ const obj = new LiveMap ( realtimeObject , objectMessage . object ! . map ! . semantics ! , objectMessage . object ! . objectId ) ;
7980 obj . overrideWithObjectState ( objectMessage ) ;
8081 return obj ;
8182 }
8283
8384 /**
8485 * @internal
8586 */
86- static async createMapSetMessage < TKey extends keyof API . LiveMapType & string > (
87+ static async createMapSetMessage (
8788 realtimeObject : RealtimeObject ,
8889 objectId : string ,
89- key : TKey ,
90- value : API . LiveMapType [ TKey ] | LiveCounterValueType | LiveMapValueType ,
90+ key : string ,
91+ value : API . Value ,
9192 ) : Promise < ObjectMessage [ ] > {
9293 const client = realtimeObject . getClient ( ) ;
9394
@@ -111,12 +112,8 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
111112
112113 const typedObjectData : ObjectIdObjectData = { objectId : mapCreateMsg . operation ?. objectId ! } ;
113114 objectData = typedObjectData ;
114- } else if ( value instanceof LiveObject ) {
115- // TODO: remove this branch when LiveObject is no longer directly supported as a map value
116- const typedObjectData : ObjectIdObjectData = { objectId : value . getObjectId ( ) } ;
117- objectData = typedObjectData ;
118115 } else {
119- const typedObjectData : ValueObjectData = { value : value as PrimitiveObjectValue } ;
116+ const typedObjectData : ValueObjectData = { value : value as API . Primitive } ;
120117 objectData = typedObjectData ;
121118 }
122119
@@ -141,11 +138,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
141138 /**
142139 * @internal
143140 */
144- static createMapRemoveMessage < TKey extends keyof API . LiveMapType & string > (
145- realtimeObject : RealtimeObject ,
146- objectId : string ,
147- key : TKey ,
148- ) : ObjectMessage {
141+ static createMapRemoveMessage ( realtimeObject : RealtimeObject , objectId : string , key : string ) : ObjectMessage {
149142 const client = realtimeObject . getClient ( ) ;
150143
151144 if ( typeof key !== 'string' ) {
@@ -170,11 +163,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
170163 /**
171164 * @internal
172165 */
173- static validateKeyValue < TKey extends keyof API . LiveMapType & string > (
174- realtimeObject : RealtimeObject ,
175- key : TKey ,
176- value : API . LiveMapType [ TKey ] | LiveCounterValueType | LiveMapValueType ,
177- ) : void {
166+ static validateKeyValue ( realtimeObject : RealtimeObject , key : string , value : API . Value ) : void {
178167 const client = realtimeObject . getClient ( ) ;
179168
180169 if ( typeof key !== 'string' ) {
@@ -209,19 +198,19 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
209198 this . _realtimeObject . throwIfInvalidAccessApiConfiguration ( ) ; // RTLM5b, RTLM5c
210199
211200 if ( this . isTombstoned ( ) ) {
212- return undefined as T [ TKey ] ;
201+ return undefined ;
213202 }
214203
215204 const element = this . _dataRef . data . get ( key ) ;
216205
217206 // RTLM5d1
218207 if ( element === undefined ) {
219- return undefined as T [ TKey ] ;
208+ return undefined ;
220209 }
221210
222211 // RTLM5d2a
223212 if ( element . tombstone === true ) {
224- return undefined as T [ TKey ] ;
213+ return undefined ;
225214 }
226215
227216 // data always exists for non-tombstoned elements
@@ -507,7 +496,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
507496 *
508497 * @internal
509498 */
510- compact ( ) : { [ K in keyof T ] : any } {
499+ compact ( ) : API . CompactedValue < API . LiveMap < T > > {
511500 const result : Record < keyof T , any > = { } as Record < keyof T , any > ;
512501
513502 // Use public entries() method to ensure we only include publicly exposed properties
@@ -911,7 +900,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
911900 /**
912901 * Returns value as is if object data stores a primitive type, or a reference to another LiveObject from the pool if it stores an objectId.
913902 */
914- private _getResolvedValueFromObjectData ( data : LiveMapObjectData ) : PrimitiveObjectValue | LiveObject | undefined {
903+ private _getResolvedValueFromObjectData ( data : LiveMapObjectData ) : API . Value | undefined {
915904 // if object data stores primitive value, just return it as is.
916905 const primitiveValue = ( data as ValueObjectData ) . value ;
917906 if ( primitiveValue != null ) {
@@ -930,7 +919,7 @@ export class LiveMap<T extends API.LiveMapType> extends LiveObject<LiveMapData,
930919 return undefined ;
931920 }
932921
933- return refObject ; // RTLM5d2f2
922+ return refObject as unknown as API . LiveObject ; // RTLM5d2f2
934923 }
935924
936925 private _isMapEntryTombstoned ( entry : LiveMapEntry ) : boolean {
0 commit comments