@@ -2,9 +2,9 @@ internal import _AblyPluginSupportPrivate
22import Ably
33
44/// Protocol for accessing objects from the ObjectsPool. This is used by a LiveMap when it needs to return an object given an object ID.
5- internal protocol LiveMapObjectPoolDelegate : AnyObject , Sendable {
6- /// Fetches an object from the pool by its ID
7- func nosync_getObjectFromPool ( id : String ) -> ObjectsPool . Entry ?
5+ internal protocol LiveMapObjectsPoolDelegate : AnyObject , Sendable {
6+ /// A snapshot of the objects pool.
7+ var nosync_objectsPool : ObjectsPool { get }
88}
99
1010/// This provides the implementation behind ``PublicDefaultLiveMap``, via internal versions of the ``LiveMap`` API.
@@ -121,30 +121,40 @@ internal final class InternalDefaultLiveMap: Sendable {
121121 // MARK: - Internal methods that back LiveMap conformance
122122
123123 /// Returns the value associated with a given key, following RTLM5d specification.
124- internal func get( key: String , coreSDK: CoreSDK , delegate: LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> InternalLiveMapValue ? {
124+ internal func get( key: String , coreSDK: CoreSDK , delegate: LiveMapObjectsPoolDelegate ) throws ( ARTErrorInfo) -> InternalLiveMapValue ? {
125125 try mutableStateMutex. withSync { mutableState throws ( ARTErrorInfo) in
126- try mutableState. nosync_get ( key: key, coreSDK: coreSDK, delegate: delegate)
126+ try mutableState. nosync_get (
127+ key: key,
128+ coreSDK: coreSDK,
129+ objectsPool: delegate. nosync_objectsPool,
130+ )
127131 }
128132 }
129133
130- internal func size( coreSDK: CoreSDK , delegate: LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> Int {
134+ internal func size( coreSDK: CoreSDK , delegate: LiveMapObjectsPoolDelegate ) throws ( ARTErrorInfo) -> Int {
131135 try mutableStateMutex. withSync { mutableState throws ( ARTErrorInfo) in
132- try mutableState. nosync_size ( coreSDK: coreSDK, delegate: delegate)
136+ try mutableState. nosync_size (
137+ coreSDK: coreSDK,
138+ objectsPool: delegate. nosync_objectsPool,
139+ )
133140 }
134141 }
135142
136- internal func entries( coreSDK: CoreSDK , delegate: LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> [ ( key: String , value: InternalLiveMapValue ) ] {
143+ internal func entries( coreSDK: CoreSDK , delegate: LiveMapObjectsPoolDelegate ) throws ( ARTErrorInfo) -> [ ( key: String , value: InternalLiveMapValue ) ] {
137144 try mutableStateMutex. withSync { mutableState throws ( ARTErrorInfo) in
138- try mutableState. nosync_entries ( coreSDK: coreSDK, delegate: delegate)
145+ try mutableState. nosync_entries (
146+ coreSDK: coreSDK,
147+ objectsPool: delegate. nosync_objectsPool,
148+ )
139149 }
140150 }
141151
142- internal func keys( coreSDK: CoreSDK , delegate: LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> [ String ] {
152+ internal func keys( coreSDK: CoreSDK , delegate: LiveMapObjectsPoolDelegate ) throws ( ARTErrorInfo) -> [ String ] {
143153 // RTLM12b: Identical to LiveMap#entries, except that it returns only the keys from the internal data map
144154 try entries ( coreSDK: coreSDK, delegate: delegate) . map ( \. key)
145155 }
146156
147- internal func values( coreSDK: CoreSDK , delegate: LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> [ InternalLiveMapValue ] {
157+ internal func values( coreSDK: CoreSDK , delegate: LiveMapObjectsPoolDelegate ) throws ( ARTErrorInfo) -> [ InternalLiveMapValue ] {
148158 // RTLM13b: Identical to LiveMap#entries, except that it returns only the values from the internal data map
149159 try entries ( coreSDK: coreSDK, delegate: delegate) . map ( \. value)
150160 }
@@ -859,7 +869,7 @@ internal final class InternalDefaultLiveMap: Sendable {
859869 }
860870
861871 /// Returns the value associated with a given key, following RTLM5d specification.
862- internal func nosync_get( key: String , coreSDK: CoreSDK , delegate : LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> InternalLiveMapValue ? {
872+ internal func nosync_get( key: String , coreSDK: CoreSDK , objectsPool : ObjectsPool ) throws ( ARTErrorInfo) -> InternalLiveMapValue ? {
863873 // RTLM5c: If the channel is in the DETACHED or FAILED state, the library should indicate an error with code 90001
864874 try coreSDK. nosync_validateChannelState ( notIn: [ . detached, . failed] , operationDescription: " LiveMap.get " )
865875
@@ -874,30 +884,30 @@ internal final class InternalDefaultLiveMap: Sendable {
874884 }
875885
876886 // RTLM5d2: If a ObjectsMapEntry exists at the key, convert it using the shared logic
877- return nosync_convertEntryToLiveMapValue ( entry, delegate : delegate )
887+ return nosync_convertEntryToLiveMapValue ( entry, objectsPool : objectsPool )
878888 }
879889
880- internal func nosync_size( coreSDK: CoreSDK , delegate : LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> Int {
890+ internal func nosync_size( coreSDK: CoreSDK , objectsPool : ObjectsPool ) throws ( ARTErrorInfo) -> Int {
881891 // RTLM10c: If the channel is in the DETACHED or FAILED state, the library should throw an ErrorInfo error with statusCode 400 and code 90001
882892 try coreSDK. nosync_validateChannelState ( notIn: [ . detached, . failed] , operationDescription: " LiveMap.size " )
883893
884894 // RTLM10d: Returns the number of non-tombstoned entries (per RTLM14) in the internal data map
885895 return data. values. count { entry in
886- !Self. nosync_isEntryTombstoned ( entry, delegate : delegate )
896+ !Self. nosync_isEntryTombstoned ( entry, objectsPool : objectsPool )
887897 }
888898 }
889899
890- internal func nosync_entries( coreSDK: CoreSDK , delegate : LiveMapObjectPoolDelegate ) throws ( ARTErrorInfo) -> [ ( key: String , value: InternalLiveMapValue ) ] {
900+ internal func nosync_entries( coreSDK: CoreSDK , objectsPool : ObjectsPool ) throws ( ARTErrorInfo) -> [ ( key: String , value: InternalLiveMapValue ) ] {
891901 // RTLM11c: If the channel is in the DETACHED or FAILED state, the library should throw an ErrorInfo error with statusCode 400 and code 90001
892902 try coreSDK. nosync_validateChannelState ( notIn: [ . detached, . failed] , operationDescription: " LiveMap.entries " )
893903
894904 // RTLM11d: Returns key-value pairs from the internal data map
895905 // RTLM11d1: Pairs with tombstoned entries (per RTLM14) are not returned
896906 var result : [ ( key: String , value: InternalLiveMapValue ) ] = [ ]
897907
898- for (key, entry) in data where !Self. nosync_isEntryTombstoned ( entry, delegate : delegate ) {
908+ for (key, entry) in data where !Self. nosync_isEntryTombstoned ( entry, objectsPool : objectsPool ) {
899909 // Convert entry to LiveMapValue using the same logic as get(key:)
900- if let value = nosync_convertEntryToLiveMapValue ( entry, delegate : delegate ) {
910+ if let value = nosync_convertEntryToLiveMapValue ( entry, objectsPool : objectsPool ) {
901911 result. append ( ( key: key, value: value) )
902912 }
903913 }
@@ -908,15 +918,15 @@ internal final class InternalDefaultLiveMap: Sendable {
908918 // MARK: - Helper Methods
909919
910920 /// Returns whether a map entry should be considered tombstoned, per the check described in RTLM14.
911- private static func nosync_isEntryTombstoned( _ entry: InternalObjectsMapEntry , delegate : LiveMapObjectPoolDelegate ) -> Bool {
921+ private static func nosync_isEntryTombstoned( _ entry: InternalObjectsMapEntry , objectsPool : ObjectsPool ) -> Bool {
912922 // RTLM14a
913923 if entry. tombstone {
914924 return true
915925 }
916926
917927 // RTLM14c
918928 if let objectId = entry. data? . objectId {
919- if let poolEntry = delegate . nosync_getObjectFromPool ( id : objectId) , poolEntry. nosync_isTombstone {
929+ if let poolEntry = objectsPool . entries [ objectId] , poolEntry. nosync_isTombstone {
920930 return true
921931 }
922932 }
@@ -927,7 +937,7 @@ internal final class InternalDefaultLiveMap: Sendable {
927937
928938 /// Converts an InternalObjectsMapEntry to LiveMapValue using the same logic as get(key:)
929939 /// This is used by entries to ensure consistent value conversion
930- private func nosync_convertEntryToLiveMapValue( _ entry: InternalObjectsMapEntry , delegate : LiveMapObjectPoolDelegate ) -> InternalLiveMapValue ? {
940+ private func nosync_convertEntryToLiveMapValue( _ entry: InternalObjectsMapEntry , objectsPool : ObjectsPool ) -> InternalLiveMapValue ? {
931941 // RTLM5d2a: If ObjectsMapEntry.tombstone is true, return undefined/null
932942 if entry. tombstone == true {
933943 return nil
@@ -968,7 +978,7 @@ internal final class InternalDefaultLiveMap: Sendable {
968978 // RTLM5d2f: If ObjectsMapEntry.data.objectId exists, get the object stored at that objectId from the internal ObjectsPool
969979 if let objectId = entry. data? . objectId {
970980 // RTLM5d2f1: If an object with id objectId does not exist, return undefined/null
971- guard let poolEntry = delegate . nosync_getObjectFromPool ( id : objectId) else {
981+ guard let poolEntry = objectsPool . entries [ objectId] else {
972982 return nil
973983 }
974984
0 commit comments