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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ably
internal import AblyPlugin

/// The class that provides the public API for interacting with LiveObjects, via the ``ARTRealtimeChannel/objects`` property.
internal class DefaultLiveObjects: Objects {
internal class DefaultRealtimeObjects: RealtimeObjects {
private weak var channel: ARTRealtimeChannel?
private let logger: AblyPlugin.Logger
private let pluginAPI: AblyPlugin.PluginAPIProtocol
Expand All @@ -21,7 +21,7 @@ internal class DefaultLiveObjects: Objects {
(receivedObjectSyncProtocolMessages, receivedObjectSyncProtocolMessagesContinuation) = AsyncStream.makeStream()
}

// MARK: `Objects` protocol
// MARK: `RealtimeObjects` protocol

internal func getRoot() async throws(ARTErrorInfo) -> any LiveMap {
notYetImplemented()
Expand Down
8 changes: 4 additions & 4 deletions Sources/AblyLiveObjects/Internal/DefaultInternalPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ internal final class DefaultInternalPlugin: NSObject, AblyPlugin.LiveObjectsInte
/// Retrieves the value that should be returned by `ARTRealtimeChannel.objects`.
///
/// We expect this value to have been previously set by ``prepare(_:)``.
internal static func objectsProperty(for channel: ARTRealtimeChannel, pluginAPI: AblyPlugin.PluginAPIProtocol) -> DefaultLiveObjects {
internal static func objectsProperty(for channel: ARTRealtimeChannel, pluginAPI: AblyPlugin.PluginAPIProtocol) -> DefaultRealtimeObjects {
guard let pluginData = pluginAPI.pluginDataValue(forKey: pluginDataKey, channel: channel) else {
// InternalPlugin.prepare was not called
fatalError("To access LiveObjects functionality, you must pass the LiveObjects plugin in the client options when creating the ARTRealtime instance: `clientOptions.plugins = [.liveObjects: AblyLiveObjects.Plugin.self]`")
}

// swiftlint:disable:next force_cast
return pluginData as! DefaultLiveObjects
return pluginData as! DefaultRealtimeObjects
}

// MARK: - LiveObjectsInternalPluginProtocol
Expand All @@ -37,12 +37,12 @@ internal final class DefaultInternalPlugin: NSObject, AblyPlugin.LiveObjectsInte
let logger = pluginAPI.logger(for: channel)

logger.log("LiveObjects.DefaultInternalPlugin received prepare(_:)", level: .debug)
let liveObjects = DefaultLiveObjects(channel: channel, logger: logger, pluginAPI: pluginAPI)
let liveObjects = DefaultRealtimeObjects(channel: channel, logger: logger, pluginAPI: pluginAPI)
pluginAPI.setPluginDataValue(liveObjects, forKey: Self.pluginDataKey, channel: channel)
}

/// Retrieves the internally-typed `objects` property for the channel.
private func objectsProperty(for channel: ARTRealtimeChannel) -> DefaultLiveObjects {
private func objectsProperty(for channel: ARTRealtimeChannel) -> DefaultRealtimeObjects {
Self.objectsProperty(for: channel, pluginAPI: pluginAPI)
}

Expand Down
88 changes: 44 additions & 44 deletions Sources/AblyLiveObjects/Protocol/ObjectMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ internal struct OutboundObjectMessage {
internal struct ObjectOperation {
internal var action: WireEnum<ObjectOperationAction> // OOP3a
internal var objectId: String // OOP3b
internal var mapOp: MapOp? // OOP3c
internal var counterOp: WireCounterOp? // OOP3d
internal var map: Map? // OOP3e
internal var counter: WireCounter? // OOP3f
internal var mapOp: ObjectsMapOp? // OOP3c
internal var counterOp: WireObjectsCounterOp? // OOP3d
internal var map: ObjectsMap? // OOP3e
internal var counter: WireObjectsCounter? // OOP3f
internal var nonce: String? // OOP3g
internal var initialValue: Data? // OOP3h
internal var initialValueEncoding: String? // OOP3i
Expand All @@ -56,29 +56,29 @@ internal struct ObjectData {
internal var string: StringPropertyContent? // OD2f
}

internal struct MapOp {
internal var key: String // MOP2a
internal var data: ObjectData? // MOP2b
internal struct ObjectsMapOp {
internal var key: String // OMO2a
internal var data: ObjectData? // OMO2b
}

internal struct MapEntry {
internal var tombstone: Bool? // ME2a
internal var timeserial: String? // ME2b
internal var data: ObjectData // ME2c
internal struct ObjectsMapEntry {
internal var tombstone: Bool? // OME2a
internal var timeserial: String? // OME2b
internal var data: ObjectData // OME2c
}

internal struct Map {
internal var semantics: WireEnum<MapSemantics> // MAP3a
internal var entries: [String: MapEntry]? // MAP3b
internal struct ObjectsMap {
internal var semantics: WireEnum<ObjectsMapSemantics> // OMP3a
internal var entries: [String: ObjectsMapEntry]? // OMP3b
}

internal struct ObjectState {
internal var objectId: String // OST2a
internal var siteTimeserials: [String: String] // OST2b
internal var tombstone: Bool // OST2c
internal var createOp: ObjectOperation? // OST2d
internal var map: Map? // OST2e
internal var counter: WireCounter? // OST2f
internal var map: ObjectsMap? // OST2e
internal var counter: WireObjectsCounter? // OST2f
}

internal extension InboundObjectMessage {
Expand Down Expand Up @@ -139,12 +139,12 @@ internal extension ObjectOperation {
) throws(InternalError) {
action = wireObjectOperation.action
objectId = wireObjectOperation.objectId
mapOp = try wireObjectOperation.mapOp.map { wireMapOp throws(InternalError) in
try .init(wireMapOp: wireMapOp, format: format)
mapOp = try wireObjectOperation.mapOp.map { wireObjectsMapOp throws(InternalError) in
try .init(wireObjectsMapOp: wireObjectsMapOp, format: format)
}
counterOp = wireObjectOperation.counterOp
map = try wireObjectOperation.map.map { wireMap throws(InternalError) in
try .init(wireMap: wireMap, format: format)
try .init(wireObjectsMap: wireMap, format: format)
}
counter = wireObjectOperation.counter

Expand Down Expand Up @@ -319,54 +319,54 @@ internal extension ObjectData {
}
}

internal extension MapOp {
/// Initializes a `MapOp` from a `WireMapOp`, applying the data decoding rules of OD5.
internal extension ObjectsMapOp {
/// Initializes a `ObjectsMapOp` from a `WireObjectsMapOp`, applying the data decoding rules of OD5.
///
/// - Parameters:
/// - format: The format to use when applying the decoding rules of OD5.
/// - Throws: `InternalError` if JSON or Base64 decoding fails.
init(
wireMapOp: WireMapOp,
wireObjectsMapOp: WireObjectsMapOp,
format: AblyPlugin.EncodingFormat
) throws(InternalError) {
key = wireMapOp.key
data = try wireMapOp.data.map { wireObjectData throws(InternalError) in
key = wireObjectsMapOp.key
data = try wireObjectsMapOp.data.map { wireObjectData throws(InternalError) in
try .init(wireObjectData: wireObjectData, format: format)
}
}

/// Converts this `MapOp` to a `WireMapOp`, applying the data encoding rules of OD4.
/// Converts this `ObjectsMapOp` to a `WireObjectsMapOp`, applying the data encoding rules of OD4.
///
/// - Parameters:
/// - format: The format to use when applying the encoding rules of OD4.
func toWire(format: AblyPlugin.EncodingFormat) -> WireMapOp {
func toWire(format: AblyPlugin.EncodingFormat) -> WireObjectsMapOp {
.init(
key: key,
data: data?.toWire(format: format),
)
}
}

internal extension MapEntry {
/// Initializes a `MapEntry` from a `WireMapEntry`, applying the data decoding rules of OD5.
internal extension ObjectsMapEntry {
/// Initializes an `ObjectsMapEntry` from a `WireObjectsMapEntry`, applying the data decoding rules of OD5.
///
/// - Parameters:
/// - format: The format to use when applying the decoding rules of OD5.
/// - Throws: `InternalError` if JSON or Base64 decoding fails.
init(
wireMapEntry: WireMapEntry,
wireObjectsMapEntry: WireObjectsMapEntry,
format: AblyPlugin.EncodingFormat
) throws(InternalError) {
tombstone = wireMapEntry.tombstone
timeserial = wireMapEntry.timeserial
data = try .init(wireObjectData: wireMapEntry.data, format: format)
tombstone = wireObjectsMapEntry.tombstone
timeserial = wireObjectsMapEntry.timeserial
data = try .init(wireObjectData: wireObjectsMapEntry.data, format: format)
}

/// Converts this `MapEntry` to a `WireMapEntry`, applying the data encoding rules of OD4.
/// Converts this `ObjectsMapEntry` to a `WireObjectsMapEntry`, applying the data encoding rules of OD4.
///
/// - Parameters:
/// - format: The format to use when applying the encoding rules of OD4.
func toWire(format: AblyPlugin.EncodingFormat) -> WireMapEntry {
func toWire(format: AblyPlugin.EncodingFormat) -> WireObjectsMapEntry {
.init(
tombstone: tombstone,
timeserial: timeserial,
Expand All @@ -375,27 +375,27 @@ internal extension MapEntry {
}
}

internal extension Map {
/// Initializes a `Map` from a `WireMap`, applying the data decoding rules of OD5.
internal extension ObjectsMap {
/// Initializes an `ObjectsMap` from a `WireObjectsMap`, applying the data decoding rules of OD5.
///
/// - Parameters:
/// - format: The format to use when applying the decoding rules of OD5.
/// - Throws: `InternalError` if JSON or Base64 decoding fails.
init(
wireMap: WireMap,
wireObjectsMap: WireObjectsMap,
format: AblyPlugin.EncodingFormat
) throws(InternalError) {
semantics = wireMap.semantics
entries = try wireMap.entries?.ablyLiveObjects_mapValuesWithTypedThrow { wireMapEntry throws(InternalError) in
try .init(wireMapEntry: wireMapEntry, format: format)
semantics = wireObjectsMap.semantics
entries = try wireObjectsMap.entries?.ablyLiveObjects_mapValuesWithTypedThrow { wireMapEntry throws(InternalError) in
try .init(wireObjectsMapEntry: wireMapEntry, format: format)
}
}

/// Converts this `Map` to a `WireMap`, applying the data encoding rules of OD4.
/// Converts this `ObjectsMap` to a `WireObjectsMap`, applying the data encoding rules of OD4.
///
/// - Parameters:
/// - format: The format to use when applying the encoding rules of OD4.
func toWire(format: AblyPlugin.EncodingFormat) -> WireMap {
func toWire(format: AblyPlugin.EncodingFormat) -> WireObjectsMap {
.init(
semantics: semantics,
entries: entries?.mapValues { $0.toWire(format: format) },
Expand All @@ -419,8 +419,8 @@ internal extension ObjectState {
createOp = try wireObjectState.createOp.map { wireObjectOperation throws(InternalError) in
try .init(wireObjectOperation: wireObjectOperation, format: format)
}
map = try wireObjectState.map.map { wireMap throws(InternalError) in
try .init(wireMap: wireMap, format: format)
map = try wireObjectState.map.map { wireObjectsMap throws(InternalError) in
try .init(wireObjectsMap: wireObjectsMap, format: format)
}
counter = wireObjectState.counter
}
Expand Down
56 changes: 28 additions & 28 deletions Sources/AblyLiveObjects/Protocol/WireObjectMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ internal enum ObjectOperationAction: Int {
case objectDelete = 5
}

// MAP2
internal enum MapSemantics: Int {
// OMP2
internal enum ObjectsMapSemantics: Int {
case lww = 0
}

internal struct WireObjectOperation {
internal var action: WireEnum<ObjectOperationAction> // OOP3a
internal var objectId: String // OOP3b
internal var mapOp: WireMapOp? // OOP3c
internal var counterOp: WireCounterOp? // OOP3d
internal var map: WireMap? // OOP3e
internal var counter: WireCounter? // OOP3f
internal var mapOp: WireObjectsMapOp? // OOP3c
internal var counterOp: WireObjectsCounterOp? // OOP3d
internal var map: WireObjectsMap? // OOP3e
internal var counter: WireObjectsCounter? // OOP3f
internal var nonce: String? // OOP3g
internal var initialValue: StringOrData? // OOP3h
internal var initialValueEncoding: String? // OOP3i
Expand Down Expand Up @@ -228,8 +228,8 @@ internal struct WireObjectState {
internal var siteTimeserials: [String: String] // OST2b
internal var tombstone: Bool // OST2c
internal var createOp: WireObjectOperation? // OST2d
internal var map: WireMap? // OST2e
internal var counter: WireCounter? // OST2f
internal var map: WireObjectsMap? // OST2e
internal var counter: WireObjectsCounter? // OST2f
}

extension WireObjectState: WireObjectCodable {
Expand Down Expand Up @@ -277,12 +277,12 @@ extension WireObjectState: WireObjectCodable {
}
}

internal struct WireMapOp {
internal var key: String // MOP2a
internal var data: WireObjectData? // MOP2b
internal struct WireObjectsMapOp {
internal var key: String // OMO2a
internal var data: WireObjectData? // OMO2b
}

extension WireMapOp: WireObjectCodable {
extension WireObjectsMapOp: WireObjectCodable {
internal enum WireKey: String {
case key
case data
Expand All @@ -306,11 +306,11 @@ extension WireMapOp: WireObjectCodable {
}
}

internal struct WireCounterOp {
internal var amount: NSNumber // COP2a
internal struct WireObjectsCounterOp {
internal var amount: NSNumber // OCO2a
}

extension WireCounterOp: WireObjectCodable {
extension WireObjectsCounterOp: WireObjectCodable {
internal enum WireKey: String {
case amount
}
Expand All @@ -326,12 +326,12 @@ extension WireCounterOp: WireObjectCodable {
}
}

internal struct WireMap {
internal var semantics: WireEnum<MapSemantics> // MAP3a
internal var entries: [String: WireMapEntry]? // MAP3b
internal struct WireObjectsMap {
internal var semantics: WireEnum<ObjectsMapSemantics> // OMP3a
internal var entries: [String: WireObjectsMapEntry]? // OMP3b
}

extension WireMap: WireObjectCodable {
extension WireObjectsMap: WireObjectCodable {
internal enum WireKey: String {
case semantics
case entries
Expand All @@ -343,7 +343,7 @@ extension WireMap: WireObjectCodable {
guard case let .object(object) = value else {
throw WireValueDecodingError.wrongTypeForKey(WireKey.entries.rawValue, actualValue: value).toInternalError()
}
return try WireMapEntry(wireObject: object)
return try WireObjectsMapEntry(wireObject: object)
}
}

Expand All @@ -360,11 +360,11 @@ extension WireMap: WireObjectCodable {
}
}

internal struct WireCounter {
internal var count: NSNumber? // CNT2a
internal struct WireObjectsCounter {
internal var count: NSNumber? // OCN2a
}

extension WireCounter: WireObjectCodable {
extension WireObjectsCounter: WireObjectCodable {
internal enum WireKey: String {
case count
}
Expand All @@ -382,13 +382,13 @@ extension WireCounter: WireObjectCodable {
}
}

internal struct WireMapEntry {
internal var tombstone: Bool? // ME2a
internal var timeserial: String? // ME2b
internal var data: WireObjectData // ME2c
internal struct WireObjectsMapEntry {
internal var tombstone: Bool? // OME2a
internal var timeserial: String? // OME2b
internal var data: WireObjectData // OME2c
}

extension WireMapEntry: WireObjectCodable {
extension WireObjectsMapEntry: WireObjectCodable {
internal enum WireKey: String {
case tombstone
case timeserial
Expand Down
10 changes: 5 additions & 5 deletions Sources/AblyLiveObjects/Public/ARTRealtimeChannel+Objects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import Ably
internal import AblyPlugin

public extension ARTRealtimeChannel {
/// An ``Objects`` object.
var objects: Objects {
/// A ``RealtimeObjects`` object.
var objects: RealtimeObjects {
internallyTypedObjects
}

private var internallyTypedObjects: DefaultLiveObjects {
private var internallyTypedObjects: DefaultRealtimeObjects {
DefaultInternalPlugin.objectsProperty(for: self, pluginAPI: AblyPlugin.PluginAPI.sharedInstance())
}

/// For tests to access the non-public API of `DefaultLiveObjects`.
internal var testsOnly_internallyTypedObjects: DefaultLiveObjects {
/// For tests to access the non-public API of `DefaultRealtimeObjects`.
internal var testsOnly_internallyTypedObjects: DefaultRealtimeObjects {
internallyTypedObjects
}
}
Loading