Skip to content

Commit f26896e

Browse files
Merge pull request #125 from ably/merge-protocol-v6-into-main
Merge `integration/protocol-v6` into `main`
2 parents a536b1f + 2f9a0f1 commit f26896e

25 files changed

Lines changed: 2904 additions & 830 deletions

AblyLiveObjects.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ let package = Package(
2121
// TODO: Unpin before release
2222
.package(
2323
url: "https://github.com/ably/ably-cocoa.git",
24-
revision: "3cfa896eafecb08a2eec89d9f57cc0ba0709f0cf",
24+
revision: "68e9b6fc786f0c2c425d095b3cf3366844fd0507",
2525
),
2626
// TODO: Unpin before release
2727
.package(
2828
url: "https://github.com/ably/ably-cocoa-plugin-support",
29-
revision: "8bfbbaad56aa413aa53fc399e6a4ad284177ee84",
29+
revision: "36c529db38154d01537e782f7ed4aa7535fb3237",
3030
),
3131
.package(
3232
url: "https://github.com/apple/swift-argument-parser",

Sources/AblyLiveObjects/Internal/DefaultInternalPlugin.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import ObjectiveC.NSObject
99
internal final class DefaultInternalPlugin: NSObject, _AblyPluginSupportPrivate.LiveObjectsInternalPluginProtocol {
1010
private let pluginAPI: _AblyPluginSupportPrivate.PluginAPIProtocol
1111

12+
internal var compatibleWithProtocolV6: Bool { true }
13+
1214
internal init(pluginAPI: _AblyPluginSupportPrivate.PluginAPIProtocol) {
15+
precondition(
16+
pluginAPI.usesLiveObjectsProtocolV6,
17+
"This version of the LiveObjects plugin requires a version of ably-cocoa that uses LiveObjects protocol v6.",
18+
)
1319
self.pluginAPI = pluginAPI
1420
}
1521

Sources/AblyLiveObjects/Internal/InternalDefaultLiveCounter.swift

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ internal final class InternalDefaultLiveCounter: Sendable {
124124
action: .known(.counterInc),
125125
// RTLC12e3
126126
objectId: mutableState.liveObjectMutableState.objectID,
127-
counterOp: .init(
128-
// RTLC12e4
129-
amount: .init(value: amount),
127+
counterInc: .init(
128+
// RTLC12e5
129+
number: .init(value: amount),
130130
),
131131
),
132132
)
@@ -223,7 +223,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
223223
}
224224
}
225225

226-
/// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC10.
226+
/// Merges the initial value from an ObjectOperation into this LiveCounter, per RTLC16.
227227
internal func nosync_mergeInitialValue(from operation: ObjectOperation) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
228228
mutableStateMutex.withoutSync { mutableState in
229229
mutableState.mergeInitialValue(from: operation)
@@ -238,7 +238,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
238238
}
239239

240240
/// Test-only method to apply a COUNTER_INC operation, per RTLC9.
241-
internal func testsOnly_applyCounterIncOperation(_ operation: WireObjectsCounterOp?) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
241+
internal func testsOnly_applyCounterIncOperation(_ operation: WireCounterInc?) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
242242
mutableStateMutex.withSync { mutableState in
243243
mutableState.applyCounterIncOperation(operation)
244244
}
@@ -352,7 +352,7 @@ internal final class InternalDefaultLiveCounter: Sendable {
352352
// RTLC6c: Set data to the value of ObjectState.counter.count, or to 0 if it does not exist
353353
data = state.counter?.count?.doubleValue ?? 0
354354

355-
// RTLC6d: If ObjectState.createOp is present, merge the initial value into the LiveCounter as described in RTLC10
355+
// RTLC6d: If ObjectState.createOp is present, merge the initial value into the LiveCounter as described in RTLC16
356356
// Discard the LiveCounterUpdate object returned by the merge operation
357357
if let createOp = state.createOp {
358358
_ = mergeInitialValue(from: createOp)
@@ -362,21 +362,25 @@ internal final class InternalDefaultLiveCounter: Sendable {
362362
return ObjectDiffHelpers.calculateCounterDiff(previousData: previousData, newData: data)
363363
}
364364

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

369-
// RTLC10a: Add ObjectOperation.counter.count to data, if it exists
370-
if let operationCount = operation.counter?.count?.doubleValue {
369+
// RTLC16: Resolve counterCreate from either the direct property or the one
370+
// from which counterCreateWithObjectId was derived (RTO12f16)
371+
let counterCreate = operation.counterCreate ?? operation.counterCreateWithObjectId?.derivedFrom
372+
373+
// RTLC16a: Add counterCreate.count to data, if it exists
374+
if let operationCount = counterCreate?.count?.doubleValue {
371375
data += operationCount
372-
// RTLC10c
376+
// RTLC16c
373377
update = .update(DefaultLiveCounterUpdate(amount: operationCount))
374378
} else {
375-
// RTLC10d
379+
// RTLC16d
376380
update = .noop
377381
}
378382

379-
// RTLC10b: Set the private flag createOperationIsMerged to true
383+
// RTLC16b: Set the private flag createOperationIsMerged to true
380384
liveObjectMutableState.createOperationIsMerged = true
381385

382386
return update
@@ -425,11 +429,11 @@ internal final class InternalDefaultLiveCounter: Sendable {
425429
// RTLC7d1b
426430
return true
427431
case .known(.counterInc):
428-
// RTLC7d2
429-
let update = applyCounterIncOperation(operation.counterOp)
430-
// RTLC7d2a
432+
// RTLC7d5
433+
let update = applyCounterIncOperation(operation.counterInc)
434+
// RTLC7d5a
431435
liveObjectMutableState.emit(update, on: userCallbackQueue)
432-
// RTLC7d2b
436+
// RTLC7d5b
433437
return true
434438
case .known(.objectDelete):
435439
let dataBeforeApplyingOperation = data
@@ -469,14 +473,14 @@ internal final class InternalDefaultLiveCounter: Sendable {
469473
}
470474

471475
/// Applies a `COUNTER_INC` operation, per RTLC9.
472-
internal mutating func applyCounterIncOperation(_ operation: WireObjectsCounterOp?) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
476+
internal mutating func applyCounterIncOperation(_ operation: WireCounterInc?) -> LiveObjectUpdate<DefaultLiveCounterUpdate> {
473477
guard let operation else {
474-
// RTL9e
478+
// RTLC9h
475479
return .noop
476480
}
477481

478-
// RTLC9b, RTLC9d
479-
let amount = operation.amount.doubleValue
482+
// RTLC9f, RTLC9g
483+
let amount = operation.number.doubleValue
480484
data += amount
481485
return .update(DefaultLiveCounterUpdate(amount: amount))
482486
}

0 commit comments

Comments
 (0)