Skip to content

Commit 2a6b773

Browse files
Mark remaining LiveMap accessors as throwing
Motivation as in 3f6de86; the new spec points in [1] tell us these can throw. [1] ably/specification#341
1 parent 3c3ff03 commit 2a6b773

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

Sources/AblyLiveObjects/Public/PublicTypes.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ public protocol LiveMap: LiveObject where Update == LiveMapUpdate {
211211
func get(key: String) throws(ARTErrorInfo) -> LiveMapValue?
212212

213213
/// Returns the number of key-value pairs in the map.
214-
var size: Int { get }
214+
var size: Int { get throws(ARTErrorInfo) }
215215

216216
/// Returns an array of key-value pairs for every entry in the map.
217-
var entries: [(key: String, value: LiveMapValue)] { get }
217+
var entries: [(key: String, value: LiveMapValue)] { get throws(ARTErrorInfo) }
218218

219219
/// Returns an array of keys in the map.
220-
var keys: [String] { get }
220+
var keys: [String] { get throws(ARTErrorInfo) }
221221

222222
/// Returns an iterable of values in the map.
223-
var values: [LiveMapValue] { get }
223+
var values: [LiveMapValue] { get throws(ARTErrorInfo) }
224224

225225
/// Sends an operation to the Ably system to set a key on this `LiveMap` object to a specified value.
226226
///

Tests/AblyLiveObjectsTests/JS Integration Tests/ObjectsIntegrationTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ private struct ObjectsIntegrationTests {
295295
let mapKeys = ["emptyMap", "referencedMap", "valuesMap"]
296296
let rootKeysCount = counterKeys.count + mapKeys.count
297297

298-
#expect(root.size == rootKeysCount, "Check root has correct number of keys")
298+
#expect(try root.size == rootKeysCount, "Check root has correct number of keys")
299299

300300
for key in counterKeys {
301301
let counter = try #require(try root.get(key: key))
@@ -319,7 +319,7 @@ private struct ObjectsIntegrationTests {
319319
"falseKey",
320320
"mapKey",
321321
]
322-
#expect(valuesMap.size == valueMapKeys.count, "Check nested map has correct number of keys")
322+
#expect(try valuesMap.size == valueMapKeys.count, "Check nested map has correct number of keys")
323323
for key in valueMapKeys {
324324
#expect(try valuesMap.get(key: key) != nil, "Check value at key=\"\(key)\" in nested map exists")
325325
}
@@ -391,7 +391,7 @@ private struct ObjectsIntegrationTests {
391391
#expect(try counter2.value == 11, "Check counter has correct value")
392392

393393
let map2 = try #require(root2.get(key: "map")?.liveMapValue)
394-
#expect(map2.size == 2, "Check map has correct number of keys")
394+
#expect(try map2.size == 2, "Check map has correct number of keys")
395395
#expect(try #require(map2.get(key: "shouldStay")?.stringValue) == "foo", "Check map has correct value for \"shouldStay\" key")
396396
#expect(try #require(map2.get(key: "anotherKey")?.stringValue) == "baz", "Check map has correct value for \"anotherKey\" key")
397397
#expect(try map2.get(key: "shouldDelete") == nil, "Check map does not have \"shouldDelete\" key")
@@ -492,16 +492,16 @@ private struct ObjectsIntegrationTests {
492492
let root = try await objects.getRoot()
493493

494494
let emptyMap = try #require(root.get(key: "emptyMap")?.liveMapValue)
495-
#expect(emptyMap.size == 0, "Check empty map in root has no keys")
495+
#expect(try emptyMap.size == 0, "Check empty map in root has no keys")
496496

497497
let referencedMap = try #require(root.get(key: "referencedMap")?.liveMapValue)
498-
#expect(referencedMap.size == 1, "Check referenced map in root has correct number of keys")
498+
#expect(try referencedMap.size == 1, "Check referenced map in root has correct number of keys")
499499

500500
let counterFromReferencedMap = try #require(referencedMap.get(key: "counterKey")?.liveCounterValue)
501501
#expect(try counterFromReferencedMap.value == 20, "Check nested counter has correct value")
502502

503503
let valuesMap = try #require(root.get(key: "valuesMap")?.liveMapValue)
504-
#expect(valuesMap.size == 9, "Check values map in root has correct number of keys")
504+
#expect(try valuesMap.size == 9, "Check values map in root has correct number of keys")
505505

506506
#expect(try #require(valuesMap.get(key: "stringKey")?.stringValue) == "stringValue", "Check values map has correct string value key")
507507
#expect(try #require(valuesMap.get(key: "emptyStringKey")?.stringValue).isEmpty, "Check values map has correct empty string value key")
@@ -513,7 +513,7 @@ private struct ObjectsIntegrationTests {
513513
#expect(try #require(valuesMap.get(key: "falseKey")?.boolValue as Bool?) == false, "Check values map has correct 'false' value key")
514514

515515
let mapFromValuesMap = try #require(valuesMap.get(key: "mapKey")?.liveMapValue)
516-
#expect(mapFromValuesMap.size == 1, "Check nested map has correct number of keys")
516+
#expect(try mapFromValuesMap.size == 1, "Check nested map has correct number of keys")
517517

518518
// TODO: remove (Swift-only) — keep channel alive until we've executed our test case. We'll address this in https://github.com/ably/ably-cocoa-liveobjects-plugin/issues/9
519519
withExtendedLifetime(channel) {}
@@ -543,7 +543,7 @@ private struct ObjectsIntegrationTests {
543543
#expect(try counterFromReferencedMap.value == 20, "Check nested counter has correct value")
544544

545545
let mapFromValuesMap = try #require(valuesMap.get(key: "mapKey")?.liveMapValue, "Check nested map is of type LiveMap")
546-
#expect(mapFromValuesMap.size == 1, "Check nested map has correct number of keys")
546+
#expect(try mapFromValuesMap.size == 1, "Check nested map has correct number of keys")
547547
#expect(mapFromValuesMap === referencedMap, "Check nested map is the same object instance as map on the root")
548548

549549
// TODO: remove (Swift-only) — keep channel alive until we've executed our test case. We'll address this in https://github.com/ably/ably-cocoa-liveobjects-plugin/issues/9

0 commit comments

Comments
 (0)