Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/AblyLiveObjects/Internal/CoreSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import Ably
/// This provides us with a mockable interface to ably-cocoa, and it also allows internal components and their tests not to need to worry about some of the boring details of how we bridge Swift types to `_AblyPluginSupportPrivate`'s Objective-C API (i.e. boxing).
internal protocol CoreSDK: AnyObject, Sendable {
/// Implements the internal `#publish` method of RTO15.
func nosync_publish(objectMessages: [OutboundObjectMessage], callback: @escaping @Sendable (Result<PublishResult, ARTErrorInfo>) -> Void)
func nosync_publish(objectMessages: [ProtocolTypes.OutboundObjectMessage], callback: @escaping @Sendable (Result<PublishResult, ARTErrorInfo>) -> Void)

/// Implements the server time fetch of RTO16, including the storing and usage of the local clock offset.
func nosync_fetchServerTime(callback: @escaping @Sendable (Result<Date, ARTErrorInfo>) -> Void)

/// Replaces the implementation of ``nosync_publish(objectMessages:callback:)``.
///
/// Used by integration tests, for example to disable `ObjectMessage` publishing so that a test can verify that a behaviour is not a side effect of an `ObjectMessage` sent by the SDK.
func testsOnly_overridePublish(with newImplementation: @escaping ([OutboundObjectMessage]) async throws(ARTErrorInfo) -> PublishResult)
func testsOnly_overridePublish(with newImplementation: @escaping ([ProtocolTypes.OutboundObjectMessage]) async throws(ARTErrorInfo) -> PublishResult)

/// Returns the current state of the Realtime channel that this wraps.
var nosync_channelState: _AblyPluginSupportPrivate.RealtimeChannelState { get }
Expand All @@ -34,7 +34,7 @@ internal final class DefaultCoreSDK: CoreSDK {
/// This enables the `testsOnly_overridePublish(with:)` test hook.
///
/// - Note: This should be `throws(ARTErrorInfo)` but that causes a compilation error of "Runtime support for typed throws function types is only available in macOS 15.0.0 or newer".
private nonisolated(unsafe) var overriddenPublishImplementation: (([OutboundObjectMessage]) async throws -> PublishResult)?
private nonisolated(unsafe) var overriddenPublishImplementation: (([ProtocolTypes.OutboundObjectMessage]) async throws -> PublishResult)?

internal init(
channel: _AblyPluginSupportPrivate.RealtimeChannel,
Expand All @@ -50,7 +50,7 @@ internal final class DefaultCoreSDK: CoreSDK {

// MARK: - CoreSDK conformance

internal func nosync_publish(objectMessages: [OutboundObjectMessage], callback: @escaping @Sendable (Result<PublishResult, ARTErrorInfo>) -> Void) {
internal func nosync_publish(objectMessages: [ProtocolTypes.OutboundObjectMessage], callback: @escaping @Sendable (Result<PublishResult, ARTErrorInfo>) -> Void) {
logger.log("nosync_publish(objectMessages: \(LoggingUtilities.formatObjectMessagesForLogging(objectMessages)))", level: .debug)

// Use the overridden implementation if supplied
Expand Down Expand Up @@ -83,7 +83,7 @@ internal final class DefaultCoreSDK: CoreSDK {
)
}

internal func testsOnly_overridePublish(with newImplementation: @escaping ([OutboundObjectMessage]) async throws(ARTErrorInfo) -> PublishResult) {
internal func testsOnly_overridePublish(with newImplementation: @escaping ([ProtocolTypes.OutboundObjectMessage]) async throws(ARTErrorInfo) -> PublishResult) {
mutex.withLock {
overriddenPublishImplementation = newImplementation
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/AblyLiveObjects/Internal/DefaultInternalPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
wireObject: wireObject,
decodingContext: context,
)
let objectMessage = try InboundObjectMessage(
let objectMessage = try ProtocolTypes.InboundObjectMessage(
wireObjectMessage: wireObjectMessage,
format: format,
)
Expand All @@ -112,7 +112,7 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
_ publicObjectMessage: any _AblyPluginSupportPrivate.ObjectMessageProtocol,
format: EncodingFormat,
) -> [String: Any] {
guard let outboundObjectMessageBox = publicObjectMessage as? ObjectMessageBox<OutboundObjectMessage> else {
guard let outboundObjectMessageBox = publicObjectMessage as? ObjectMessageBox<ProtocolTypes.OutboundObjectMessage> else {
preconditionFailure("Expected to receive the same OutboundObjectMessage type as we emit")
}

Expand All @@ -125,7 +125,7 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
}

internal func nosync_handleObjectProtocolMessage(withObjectMessages publicObjectMessages: [any _AblyPluginSupportPrivate.ObjectMessageProtocol], channel: _AblyPluginSupportPrivate.RealtimeChannel) {
guard let inboundObjectMessageBoxes = publicObjectMessages as? [ObjectMessageBox<InboundObjectMessage>] else {
guard let inboundObjectMessageBoxes = publicObjectMessages as? [ObjectMessageBox<ProtocolTypes.InboundObjectMessage>] else {
preconditionFailure("Expected to receive the same InboundObjectMessage type as we emit")
}

Expand All @@ -137,7 +137,7 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
}

internal func nosync_handleObjectSyncProtocolMessage(withObjectMessages publicObjectMessages: [any _AblyPluginSupportPrivate.ObjectMessageProtocol], protocolMessageChannelSerial: String?, channel: _AblyPluginSupportPrivate.RealtimeChannel) {
guard let inboundObjectMessageBoxes = publicObjectMessages as? [ObjectMessageBox<InboundObjectMessage>] else {
guard let inboundObjectMessageBoxes = publicObjectMessages as? [ObjectMessageBox<ProtocolTypes.InboundObjectMessage>] else {
preconditionFailure("Expected to receive the same InboundObjectMessage type as we emit")
}

Expand Down Expand Up @@ -167,13 +167,13 @@ internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.
// MARK: - Sending `OBJECT` ProtocolMessage

internal static func nosync_sendObject(
objectMessages: [OutboundObjectMessage],
objectMessages: [ProtocolTypes.OutboundObjectMessage],
channel: _AblyPluginSupportPrivate.RealtimeChannel,
client: _AblyPluginSupportPrivate.RealtimeClient,
pluginAPI: PluginAPIProtocol,
callback: @escaping @Sendable (Result<PublishResult, ARTErrorInfo>) -> Void,
) {
let objectMessageBoxes: [ObjectMessageBox<OutboundObjectMessage>] = objectMessages.map { .init(objectMessage: $0) }
let objectMessageBoxes: [ObjectMessageBox<ProtocolTypes.OutboundObjectMessage>] = objectMessages.map { .init(objectMessage: $0) }
let internalQueue = pluginAPI.internalQueue(for: client)

pluginAPI.nosync_sendObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
operationDescription: "LiveCounter.increment",
)

let objectMessage = OutboundObjectMessage(
let objectMessage = ProtocolTypes.OutboundObjectMessage(
operation: .init(
// RTLC12e2
action: .known(.counterInc),
Expand Down Expand Up @@ -209,7 +209,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
/// - Parameters:
/// - objectMessageSerialTimestamp: The `serialTimestamp` of the containing `ObjectMessage`. Used if we need to tombstone this counter.
internal func nosync_replaceData(
using state: ObjectState,
using state: ProtocolTypes.ObjectState,
objectMessageSerialTimestamp: Date?,
) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
mutableStateMutex.withoutSync { mutableState in
Expand All @@ -224,14 +224,14 @@ internal final class InternalDefaultLiveCounter: Sendable {
}

/// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC16.
internal func nosync_mergeInitialValue(from operation: ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
internal func nosync_mergeInitialValue(from operation: ProtocolTypes.ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
mutableStateMutex.withoutSync { mutableState in
mutableState.mergeInitialValue(from: operation)
}
}

/// Test-only method to apply a COUNTER_CREATE operation, per RTLC8.
internal func testsOnly_applyCounterCreateOperation(_ operation: ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
internal func testsOnly_applyCounterCreateOperation(_ operation: ProtocolTypes.ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
mutableStateMutex.withSync { mutableState in
mutableState.applyCounterCreateOperation(operation, logger: logger)
}
Expand All @@ -248,7 +248,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
///
/// - Returns: `true` if the operation was applied, `false` if it was skipped (RTLC7g).
internal func nosync_apply(
_ operation: ObjectOperation,
_ operation: ProtocolTypes.ObjectOperation,
source: ObjectsOperationSource,
objectMessageSerial: String?,
objectMessageSiteCode: String?,
Expand Down Expand Up @@ -314,7 +314,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
/// - Parameters:
/// - objectMessageSerialTimestamp: The `serialTimestamp` of the containing `ObjectMessage`. Used if we need to tombstone this counter.
internal mutating func replaceData(
using state: ObjectState,
using state: ProtocolTypes.ObjectState,
objectMessageSerialTimestamp: Date?,
logger: Logger,
clock: SimpleClock,
Expand Down Expand Up @@ -363,7 +363,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
}

/// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC16.
internal mutating func mergeInitialValue(from operation: ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
internal mutating func mergeInitialValue(from operation: ProtocolTypes.ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
let update: LiveObjectUpdate<DefaultLiveCounterUpdate>

// RTLC16: Resolve counterCreate from either the direct property or the one
Expand All @@ -390,7 +390,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
///
/// - Returns: `true` if the operation was applied, `false` if skipped (RTLC7g).
internal mutating func apply(
_ operation: ObjectOperation,
_ operation: ProtocolTypes.ObjectOperation,
source: ObjectsOperationSource,
objectMessageSerial: String?,
objectMessageSiteCode: String?,
Expand Down Expand Up @@ -459,7 +459,7 @@ internal final class InternalDefaultLiveCounter: Sendable {

/// Applies a `COUNTER_CREATE` operation, per RTLC8.
internal mutating func applyCounterCreateOperation(
_ operation: ObjectOperation,
_ operation: ProtocolTypes.ObjectOperation,
logger: Logger,
) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
if liveObjectMutableState.createOperationIsMerged {
Expand Down
34 changes: 17 additions & 17 deletions Sources/AblyLiveObjects/Internal/InternalDefaultLiveMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal final class InternalDefaultLiveMap: Sendable {
}
}

internal var testsOnly_semantics: WireEnum<ObjectsMapSemantics>? {
internal var testsOnly_semantics: WireEnum<ProtocolTypes.ObjectsMapSemantics>? {
mutableStateMutex.withSync { mutableState in
mutableState.semantics
}
Expand Down Expand Up @@ -50,7 +50,7 @@ internal final class InternalDefaultLiveMap: Sendable {
internal convenience init(
testsOnly_data data: [String: InternalObjectsMapEntry],
objectID: String,
testsOnly_semantics semantics: WireEnum<ObjectsMapSemantics>? = nil,
testsOnly_semantics semantics: WireEnum<ProtocolTypes.ObjectsMapSemantics>? = nil,
logger: Logger,
internalQueue: DispatchQueue,
userCallbackQueue: DispatchQueue,
Expand All @@ -70,7 +70,7 @@ internal final class InternalDefaultLiveMap: Sendable {
private init(
data: [String: InternalObjectsMapEntry],
objectID: String,
semantics: WireEnum<ObjectsMapSemantics>?,
semantics: WireEnum<ProtocolTypes.ObjectsMapSemantics>?,
logger: Logger,
internalQueue: DispatchQueue,
userCallbackQueue: DispatchQueue,
Expand All @@ -92,7 +92,7 @@ internal final class InternalDefaultLiveMap: Sendable {
/// - semantics: The value to use for the "private `semantics` field" of RTO5c1b1b.
internal static func createZeroValued(
objectID: String,
semantics: WireEnum<ObjectsMapSemantics>? = nil,
semantics: WireEnum<ProtocolTypes.ObjectsMapSemantics>? = nil,
logger: Logger,
internalQueue: DispatchQueue,
userCallbackQueue: DispatchQueue,
Expand Down Expand Up @@ -172,7 +172,7 @@ internal final class InternalDefaultLiveMap: Sendable {
// RTLM20c
try coreSDK.nosync_validateChannelState(notIn: [.detached, .failed, .suspended], operationDescription: "LiveMap.set")

let objectMessage = OutboundObjectMessage(
let objectMessage = ProtocolTypes.OutboundObjectMessage(
operation: .init(
// RTLM20e2
action: .known(.mapSet),
Expand Down Expand Up @@ -205,7 +205,7 @@ internal final class InternalDefaultLiveMap: Sendable {
// RTLM21c
try coreSDK.nosync_validateChannelState(notIn: [.detached, .failed, .suspended], operationDescription: "LiveMap.remove")

let objectMessage = OutboundObjectMessage(
let objectMessage = ProtocolTypes.OutboundObjectMessage(
operation: .init(
// RTLM21e2
action: .known(.mapRemove),
Expand Down Expand Up @@ -292,7 +292,7 @@ internal final class InternalDefaultLiveMap: Sendable {
/// - objectsPool: The pool into which should be inserted any objects created by a `MAP_SET` operation.
/// - objectMessageSerialTimestamp: The `serialTimestamp` of the containing `ObjectMessage`. Used if we need to tombstone this map.
internal func nosync_replaceData(
using state: ObjectState,
using state: ProtocolTypes.ObjectState,
objectMessageSerialTimestamp: Date?,
objectsPool: inout ObjectsPool,
) -> LiveObjectUpdate<DefaultLiveMapUpdate> {
Expand All @@ -310,7 +310,7 @@ internal final class InternalDefaultLiveMap: Sendable {
}

/// Merges the initial value from an ObjectOperation into this LiveMap, per RTLM23.
internal func nosync_mergeInitialValue(from operation: ObjectOperation, objectsPool: inout ObjectsPool) -> LiveObjectUpdate<DefaultLiveMapUpdate> {
internal func nosync_mergeInitialValue(from operation: ProtocolTypes.ObjectOperation, objectsPool: inout ObjectsPool) -> LiveObjectUpdate<DefaultLiveMapUpdate> {
mutableStateMutex.withoutSync { mutableState in
mutableState.mergeInitialValue(
from: operation,
Expand All @@ -324,7 +324,7 @@ internal final class InternalDefaultLiveMap: Sendable {
}

/// Test-only method to apply a MAP_CREATE operation, per RTLM16.
internal func testsOnly_applyMapCreateOperation(_ operation: ObjectOperation, objectsPool: inout ObjectsPool) -> LiveObjectUpdate<DefaultLiveMapUpdate> {
internal func testsOnly_applyMapCreateOperation(_ operation: ProtocolTypes.ObjectOperation, objectsPool: inout ObjectsPool) -> LiveObjectUpdate<DefaultLiveMapUpdate> {
mutableStateMutex.withSync { mutableState in
mutableState.applyMapCreateOperation(
operation,
Expand All @@ -341,7 +341,7 @@ internal final class InternalDefaultLiveMap: Sendable {
///
/// - Returns: `true` if the operation was applied, `false` if it was skipped (RTLM15g).
internal func nosync_apply(
_ operation: ObjectOperation,
_ operation: ProtocolTypes.ObjectOperation,
source: ObjectsOperationSource,
objectMessageSerial: String?,
objectMessageSiteCode: String?,
Expand Down Expand Up @@ -370,7 +370,7 @@ internal final class InternalDefaultLiveMap: Sendable {
internal func testsOnly_applyMapSetOperation(
key: String,
operationTimeserial: String?,
operationData: ObjectData,
operationData: ProtocolTypes.ObjectData,
objectsPool: inout ObjectsPool,
) -> LiveObjectUpdate<DefaultLiveMapUpdate> {
mutableStateMutex.withSync { mutableState in
Expand Down Expand Up @@ -465,7 +465,7 @@ internal final class InternalDefaultLiveMap: Sendable {
internal var data: [String: InternalObjectsMapEntry]

/// The "private `semantics` field" of RTO5c1b1b.
internal var semantics: WireEnum<ObjectsMapSemantics>?
internal var semantics: WireEnum<ProtocolTypes.ObjectsMapSemantics>?

/// RTLM25
internal var clearTimeserial: String?
Expand All @@ -476,7 +476,7 @@ internal final class InternalDefaultLiveMap: Sendable {
/// - objectsPool: The pool into which should be inserted any objects created by a `MAP_SET` operation.
/// - objectMessageSerialTimestamp: The `serialTimestamp` of the containing `ObjectMessage`. Used if we need to tombstone this map.
internal mutating func replaceData(
using state: ObjectState,
using state: ProtocolTypes.ObjectState,
objectMessageSerialTimestamp: Date?,
objectsPool: inout ObjectsPool,
logger: Logger,
Expand Down Expand Up @@ -556,7 +556,7 @@ internal final class InternalDefaultLiveMap: Sendable {

/// Merges the initial value from an ObjectOperation into this LiveMap, per RTLM23.
internal mutating func mergeInitialValue(
from operation: ObjectOperation,
from operation: ProtocolTypes.ObjectOperation,
objectsPool: inout ObjectsPool,
logger: Logger,
internalQueue: DispatchQueue,
Expand Down Expand Up @@ -623,7 +623,7 @@ internal final class InternalDefaultLiveMap: Sendable {
///
/// - Returns: `true` if the operation was applied, `false` if skipped (RTLM15g).
internal mutating func apply(
_ operation: ObjectOperation,
_ operation: ProtocolTypes.ObjectOperation,
source: ObjectsOperationSource,
objectMessageSerial: String?,
objectMessageSiteCode: String?,
Expand Down Expand Up @@ -743,7 +743,7 @@ internal final class InternalDefaultLiveMap: Sendable {
internal mutating func applyMapSetOperation(
key: String,
operationTimeserial: String?,
operationData: ObjectData?,
operationData: ProtocolTypes.ObjectData?,
objectsPool: inout ObjectsPool,
logger: Logger,
internalQueue: DispatchQueue,
Expand Down Expand Up @@ -883,7 +883,7 @@ internal final class InternalDefaultLiveMap: Sendable {

/// Applies a `MAP_CREATE` operation, per RTLM16.
internal mutating func applyMapCreateOperation(
_ operation: ObjectOperation,
_ operation: ProtocolTypes.ObjectOperation,
objectsPool: inout ObjectsPool,
logger: Logger,
internalQueue: DispatchQueue,
Expand Down
Loading
Loading