diff --git a/README.md b/README.md index bc13e48..c2833b6 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ All or a subset of the rows from a partition can be retrieved using a query- enum TestPolymorphicOperationReturnType: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (TypeA.self, .init( {.typeA($0)} )), (TypeB.self, .init( {.typeB($0)} )), ] @@ -728,8 +728,8 @@ public struct MyTimeToLiveAttributes: TimeToLiveAttributes { If the `Codable` type is used for a row type also conforms to the `CustomRowTypeIdentifier`, the *rowTypeIdentifier* property of this type will be used as the RowType recorded in the database row. ```swift -struct TypeB: Codable, CustomRowTypeIdentifier { - static var rowTypeIdentifier: String? = "TypeBCustom" +struct TypeB: SCodable, CustomRowTypeIdentifier { + static let rowTypeIdentifier: String? = "TypeBCustom" let thirdly: String let fourthly: String diff --git a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+monomorphicGetItems.swift b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+monomorphicGetItems.swift index 57603d5..51f8d9a 100644 --- a/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+monomorphicGetItems.swift +++ b/Sources/DynamoDBTables/AWSDynamoDBCompositePrimaryKeyTable+monomorphicGetItems.swift @@ -42,7 +42,7 @@ public extension AWSDynamoDBCompositePrimaryKeyTable { monitors the unprocessed items returned in the response from DynamoDB and uses an exponential backoff algorithm to retry those items using the same retry configuration as the underlying DynamoDB client. */ - private class MonomorphicGetItemsRetriable { + private class MonomorphicGetItemsRetriable { typealias OutputType = [CompositePrimaryKey: TypedDatabaseItem] let dynamodb: AWSDynamoDB.DynamoDBClient diff --git a/Sources/DynamoDBTables/CompositePrimaryKey.swift b/Sources/DynamoDBTables/CompositePrimaryKey.swift index 89a4d3a..34966c7 100644 --- a/Sources/DynamoDBTables/CompositePrimaryKey.swift +++ b/Sources/DynamoDBTables/CompositePrimaryKey.swift @@ -26,7 +26,7 @@ import Foundation -public protocol PrimaryKeyAttributes { +public protocol PrimaryKeyAttributes: Sendable { static var partitionKeyAttributeName: String { get } static var sortKeyAttributeName: String { get } static var indexName: String? { get } @@ -66,7 +66,7 @@ struct DynamoDBAttributesTypeCodingKey: CodingKey { } } -public struct CompositePrimaryKey: Codable, CustomStringConvertible, Hashable { +public struct CompositePrimaryKey: Sendable, Codable, CustomStringConvertible, Hashable { public var description: String { "CompositePrimaryKey(partitionKey: \(self.partitionKey), sortKey: \(self.sortKey))" } diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+clobberVersionedItemWithHistoricalRow.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+clobberVersionedItemWithHistoricalRow.swift index 7d5f080..f5f621e 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+clobberVersionedItemWithHistoricalRow.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+clobberVersionedItemWithHistoricalRow.swift @@ -44,7 +44,7 @@ public extension DynamoDBCompositePrimaryKeyTable { version number. - completion: completion handler providing an error that was thrown or nil */ - func clobberVersionedItemWithHistoricalRow( + func clobberVersionedItemWithHistoricalRow( forPrimaryKey partitionKey: String, andHistoricalKey historicalKey: String, item: ItemType, diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift index f704ad5..1a56243 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable+conditionallyUpdateItem.swift @@ -43,7 +43,7 @@ public extension DynamoDBCompositePrimaryKeyTable { withRetries: the number of times to attempt to retry the update before failing. updatedPayloadProvider: the provider that will return updated payloads. */ - func conditionallyUpdateItem( + func conditionallyUpdateItem( forKey key: CompositePrimaryKey, withRetries retries: Int = 10, updatedPayloadProvider: @escaping (ItemType) async throws -> ItemType) async throws @@ -60,7 +60,7 @@ public extension DynamoDBCompositePrimaryKeyTable { // Explicitly specify an overload with sync updatedPayloadProvider // to avoid the compiler matching a call site with such a provider with the EventLoopFuture-returning overload. - func conditionallyUpdateItem( + func conditionallyUpdateItem( forKey key: CompositePrimaryKey, withRetries retries: Int = 10, updatedPayloadProvider: @escaping (ItemType) throws -> ItemType) async throws diff --git a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift index 8df75ad..d8ffc8d 100644 --- a/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift +++ b/Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift @@ -70,7 +70,7 @@ public extension Swift.Error { /** Enumeration of the types of conditions that can be specified for an attribute. */ -public enum AttributeCondition { +public enum AttributeCondition: Sendable { case equals(String) case lessThan(String) case lessThanOrEqual(String) @@ -80,7 +80,7 @@ public enum AttributeCondition { case beginsWith(String) } -public enum WriteEntry { +public enum WriteEntry: Sendable { case update(new: TypedDatabaseItem, existing: TypedDatabaseItem) case insert(new: TypedDatabaseItem) case deleteAtKey(key: CompositePrimaryKey) diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift index e092e2c..0a59c14 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeyTable.swift @@ -25,10 +25,10 @@ // DynamoDBTables // -import AWSDynamoDB +@preconcurrency import AWSDynamoDB import Foundation -public protocol PolymorphicOperationReturnTypeConvertable { +public protocol PolymorphicOperationReturnTypeConvertable: Sendable { var createDate: Foundation.Date { get } var rowStatus: RowStatus { get } @@ -41,7 +41,7 @@ extension TypedDatabaseItem: PolymorphicOperationReturnTypeConvertable { } } -public typealias ExecuteItemFilterType = (String, String, String, PolymorphicOperationReturnTypeConvertable) +public typealias ExecuteItemFilterType = @Sendable (String, String, String, PolymorphicOperationReturnTypeConvertable) -> Bool public protocol InMemoryTransactionDelegate { diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjection.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjection.swift index 39ab088..e064c1e 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjection.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjection.swift @@ -31,7 +31,7 @@ import Foundation public struct InMemoryDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositePrimaryKeysProjection { let keysWrapper: InMemoryDynamoDBCompositePrimaryKeysProjectionStore - public init(keys: [Any] = []) { + public init(keys: [Sendable] = []) { self.keysWrapper = InMemoryDynamoDBCompositePrimaryKeysProjectionStore(keys: keys) } @@ -39,7 +39,7 @@ public struct InMemoryDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositeP self.keysWrapper = keysWrapper } - public var keys: [Any] { + public var keys: [Sendable] { get async { await self.keysWrapper.keys } diff --git a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift index cce6b34..d8a2569 100644 --- a/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift +++ b/Sources/DynamoDBTables/InMemoryDynamoDBCompositePrimaryKeysProjectionStore.swift @@ -31,9 +31,9 @@ import Foundation // MARK: - Store implementation actor InMemoryDynamoDBCompositePrimaryKeysProjectionStore { - public var keys: [Any] = [] + public var keys: [Sendable] = [] - public init(keys: [Any] = []) { + public init(keys: [Sendable] = []) { self.keys = keys } diff --git a/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift b/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift index bef4b2f..cebe3a6 100644 --- a/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift +++ b/Sources/DynamoDBTables/PolymorphicOperationReturnType.swift @@ -33,25 +33,27 @@ public protocol BatchCapableReturnType { func getItemKey() -> CompositePrimaryKey } -public protocol PolymorphicOperationReturnType { +public protocol PolymorphicOperationReturnType: Sendable { associatedtype AttributesType: PrimaryKeyAttributes static var types: [(Codable.Type, PolymorphicOperationReturnOption)] { get } } -public struct PolymorphicOperationReturnOption { - private let decodingPayloadHandler: (Decoder) throws -> ReturnType - private let typeConvertingPayloadHander: (Any) throws -> ReturnType +public struct PolymorphicOperationReturnOption: Sendable { + private let decodingPayloadHandler: @Sendable (Decoder) throws -> ReturnType + private let typeConvertingPayloadHander: @Sendable (Any) throws -> ReturnType public init( - _ payloadHandler: @escaping (TypedDatabaseItem) -> ReturnType) + _ payloadHandler: @escaping @Sendable (TypedDatabaseItem) -> ReturnType) { + @Sendable func newDecodingPayloadHandler(decoder: Decoder) throws -> ReturnType { let typedDatabaseItem: TypedDatabaseItem = try TypedDatabaseItem(from: decoder) return payloadHandler(typedDatabaseItem) } + @Sendable func newTypeConvertingPayloadHandler(input: Any) throws -> ReturnType { guard let typedDatabaseItem = input as? TypedDatabaseItem else { let description = "Expected to use item type \(TypedDatabaseItem.self)." diff --git a/Sources/DynamoDBTables/PolymorphicWriteEntry.swift b/Sources/DynamoDBTables/PolymorphicWriteEntry.swift index 6146978..c3c58f5 100644 --- a/Sources/DynamoDBTables/PolymorphicWriteEntry.swift +++ b/Sources/DynamoDBTables/PolymorphicWriteEntry.swift @@ -44,7 +44,7 @@ public protocol PolymorphicTransactionConstraintTransform { // Conforming types are provided by the application to express the different possible write entries // and how they can be converted to the table-provided transform type. -public protocol PolymorphicWriteEntry { +public protocol PolymorphicWriteEntry: Sendable { func handle(context: Context) throws -> Context.WriteEntryTransformType var compositePrimaryKey: StandardCompositePrimaryKey? { get } @@ -58,13 +58,13 @@ public extension PolymorphicWriteEntry { public typealias StandardTransactionConstraintEntry = TransactionConstraintEntry -public enum TransactionConstraintEntry { +public enum TransactionConstraintEntry: Sendable { case required(existing: TypedDatabaseItem) } // Conforming types are provided by the application to express the different possible constraint entries // and how they can be converted to the table-provided transform type. -public protocol PolymorphicTransactionConstraintEntry { +public protocol PolymorphicTransactionConstraintEntry: Sendable { func handle(context: Context) throws -> Context.WriteTransactionConstraintType var compositePrimaryKey: StandardCompositePrimaryKey? { get } diff --git a/Sources/DynamoDBTables/RetryConfiguration.swift b/Sources/DynamoDBTables/RetryConfiguration.swift index 02a6e75..11dc5a8 100644 --- a/Sources/DynamoDBTables/RetryConfiguration.swift +++ b/Sources/DynamoDBTables/RetryConfiguration.swift @@ -32,7 +32,7 @@ public typealias RetryInterval = UInt32 /** Retry configuration for the requests made by a table.. */ -public struct RetryConfiguration { +public struct RetryConfiguration: Sendable { // Number of retries to be attempted public let numRetries: Int // First interval of retry in millis @@ -80,10 +80,10 @@ public struct RetryConfiguration { } /// Default try configuration with 5 retries starting at 500 ms interval. - public static var `default` = RetryConfiguration(numRetries: 5, baseRetryInterval: 500, + public static let `default` = RetryConfiguration(numRetries: 5, baseRetryInterval: 500, maxRetryInterval: 10000, exponentialBackoff: 2) /// Retry Configuration with no retries. - public static var noRetries = RetryConfiguration(numRetries: 0, baseRetryInterval: 0, + public static let noRetries = RetryConfiguration(numRetries: 0, baseRetryInterval: 0, maxRetryInterval: 0, exponentialBackoff: 0) } diff --git a/Sources/DynamoDBTables/RowWithIndex.swift b/Sources/DynamoDBTables/RowWithIndex.swift index ee14ca6..e1942fe 100644 --- a/Sources/DynamoDBTables/RowWithIndex.swift +++ b/Sources/DynamoDBTables/RowWithIndex.swift @@ -51,7 +51,7 @@ public func createRowWithIndexCodingKey(stringValue: String) -> RowWithIndexCodi RowWithIndexCodingKey(stringValue: stringValue)! } -public struct RowWithIndex: Codable, CustomRowTypeIdentifier { +public struct RowWithIndex: Sendable, Codable, CustomRowTypeIdentifier { public static var rowTypeIdentifier: String? { let rowTypeIdentity = getTypeRowIdentifier(type: RowType.self) let indexIdentity = Identity.identity diff --git a/Sources/DynamoDBTables/RowWithItemVersion.swift b/Sources/DynamoDBTables/RowWithItemVersion.swift index ada5eec..faca87b 100644 --- a/Sources/DynamoDBTables/RowWithItemVersion.swift +++ b/Sources/DynamoDBTables/RowWithItemVersion.swift @@ -26,7 +26,7 @@ import Foundation -public struct RowWithItemVersion: Codable, CustomRowTypeIdentifier { +public struct RowWithItemVersion: Sendable, Codable, CustomRowTypeIdentifier { public static var rowTypeIdentifier: String? { let rowTypeIdentity = getTypeRowIdentifier(type: RowType.self) diff --git a/Sources/DynamoDBTables/TimeToLive.swift b/Sources/DynamoDBTables/TimeToLive.swift index 67834bf..9b50600 100644 --- a/Sources/DynamoDBTables/TimeToLive.swift +++ b/Sources/DynamoDBTables/TimeToLive.swift @@ -38,7 +38,7 @@ public struct StandardTimeToLiveAttributes: TimeToLiveAttributes { public typealias StandardTimeToLive = TimeToLive -public struct TimeToLive: Codable, CustomStringConvertible, Hashable { +public struct TimeToLive: Sendable, Codable, CustomStringConvertible, Hashable { public var description: String { "TimeToLive(timeToLiveTimestamp: \(self.timeToLiveTimestamp)" } diff --git a/Sources/DynamoDBTables/TypedDatabaseItemWithTimeToLive.swift b/Sources/DynamoDBTables/TypedDatabaseItemWithTimeToLive.swift index f5819cc..1177c99 100644 --- a/Sources/DynamoDBTables/TypedDatabaseItemWithTimeToLive.swift +++ b/Sources/DynamoDBTables/TypedDatabaseItemWithTimeToLive.swift @@ -26,7 +26,7 @@ import Foundation -public struct RowStatus: Codable { +public struct RowStatus: Sendable, Codable { public let rowVersion: Int public let lastUpdatedDate: Date @@ -41,7 +41,7 @@ public struct RowStatus: Codable { } } -public protocol DatabaseItem { +public protocol DatabaseItem: Sendable { associatedtype AttributesType: PrimaryKeyAttributes // Default to StandardTimeToLiveAttributes for backwards compatibility associatedtype TimeToLiveAttributesType: TimeToLiveAttributes = StandardTimeToLiveAttributes @@ -61,11 +61,11 @@ public extension DatabaseItem { public protocol StandardDatabaseItem: DatabaseItem where AttributesType == StandardPrimaryKeyAttributes {} // Default to StandardTimeToLiveAttributes for backwards compatibility -public typealias TypedDatabaseItem = TypedDatabaseItemWithTimeToLive +public typealias TypedDatabaseItem = TypedDatabaseItemWithTimeToLive public struct TypedDatabaseItemWithTimeToLive: DatabaseItem, Codable + RowType: Sendable & Codable, + TimeToLiveAttributesType: TimeToLiveAttributes>: DatabaseItem, Sendable, Codable { public let compositePrimaryKey: CompositePrimaryKey public let createDate: Date diff --git a/Tests/DynamoDBTablesTests/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensionsTests.swift b/Tests/DynamoDBTablesTests/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensionsTests.swift index 3488c84..e134544 100644 --- a/Tests/DynamoDBTablesTests/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensionsTests.swift +++ b/Tests/DynamoDBTablesTests/DynamoDBCompositePrimaryKeyTableHistoricalItemExtensionsTests.swift @@ -36,8 +36,9 @@ private typealias DatabaseRowType = * For these tests, a primary item Provider should always return a default value for nil arguments. The Provider Provider requires a non-nil default in order to initialize a Provider. */ private func primaryItemProviderProvider(_ defaultItem: DatabaseRowType) -> - (DatabaseRowType?) -> DatabaseRowType + @Sendable (DatabaseRowType?) -> DatabaseRowType { + @Sendable func primaryItemProvider(_ item: DatabaseRowType?) -> DatabaseRowType { diff --git a/Tests/DynamoDBTablesTests/DynamoDBEncoderDecoderTests.swift b/Tests/DynamoDBTablesTests/DynamoDBEncoderDecoderTests.swift index 6cc1903..872a876 100644 --- a/Tests/DynamoDBTablesTests/DynamoDBEncoderDecoderTests.swift +++ b/Tests/DynamoDBTablesTests/DynamoDBEncoderDecoderTests.swift @@ -27,9 +27,6 @@ @testable import DynamoDBTables import XCTest -private let dynamodbEncoder = DynamoDBEncoder() -private let dynamodbDecoder = DynamoDBDecoder() - struct CoreAccountAttributes: Codable { var description: String var mappedValues: [String: String] @@ -64,14 +61,14 @@ class DynamoDBEncoderDecoderTests: XCTestCase { mappedValues: ["A": "one", "B": "two"], notificationTargets: NotificationTargets(currentIDs: [], maximum: 20)) - func testEncoderDecoder() { + func testEncoderDecoder() throws { // create key and database item to create let key = StandardCompositePrimaryKey(partitionKey: partitionKey, sortKey: sortKey) let newDatabaseItem: DatabaseItemType = StandardTypedDatabaseItem.newItem(withKey: key, andValue: self.attributes) - let encodedAttributeValue = try! dynamodbEncoder.encode(newDatabaseItem) + let encodedAttributeValue = try DynamoDBEncoder().encode(newDatabaseItem) - let output: DatabaseItemType = try! dynamodbDecoder.decode(encodedAttributeValue) + let output: DatabaseItemType = try DynamoDBDecoder().decode(encodedAttributeValue) XCTAssertEqual(newDatabaseItem.rowValue, output.rowValue) XCTAssertEqual(self.partitionKey, output.compositePrimaryKey.partitionKey) @@ -80,7 +77,7 @@ class DynamoDBEncoderDecoderTests: XCTestCase { XCTAssertNil(output.timeToLive) } - func testEncoderDecoderWithTimeToLive() { + func testEncoderDecoderWithTimeToLive() throws { let timeToLiveTimestamp: Int64 = 123_456_789 let timeToLive = StandardTimeToLive(timeToLiveTimestamp: timeToLiveTimestamp) @@ -91,9 +88,9 @@ class DynamoDBEncoderDecoderTests: XCTestCase { andValue: self.attributes, andTimeToLive: timeToLive) - let encodedAttributeValue = try! dynamodbEncoder.encode(newDatabaseItem) + let encodedAttributeValue = try DynamoDBEncoder().encode(newDatabaseItem) - let output: DatabaseItemType = try! dynamodbDecoder.decode(encodedAttributeValue) + let output: DatabaseItemType = try DynamoDBDecoder().decode(encodedAttributeValue) XCTAssertEqual(newDatabaseItem.rowValue, output.rowValue) XCTAssertEqual(self.partitionKey, output.compositePrimaryKey.partitionKey) diff --git a/Tests/DynamoDBTablesTests/InMemoryDynamoDBCompositePrimaryKeyTableTests.swift b/Tests/DynamoDBTablesTests/InMemoryDynamoDBCompositePrimaryKeyTableTests.swift index 8c3a402..20ddf26 100644 --- a/Tests/DynamoDBTablesTests/InMemoryDynamoDBCompositePrimaryKeyTableTests.swift +++ b/Tests/DynamoDBTablesTests/InMemoryDynamoDBCompositePrimaryKeyTableTests.swift @@ -31,7 +31,7 @@ import XCTest enum TestPolymorphicOperationReturnType: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (TestTypeA.self, .init { .testTypeA($0) }), ] diff --git a/Tests/DynamoDBTablesTests/SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests.swift b/Tests/DynamoDBTablesTests/SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests.swift index e1803f8..695b87f 100644 --- a/Tests/DynamoDBTablesTests/SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests.swift +++ b/Tests/DynamoDBTablesTests/SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests.swift @@ -33,7 +33,7 @@ private typealias DatabaseRowType = StandardTypedDatabaseItem enum ExpectedQueryableTypes: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (TestTypeA.self, .init { .testTypeA($0) }), ] @@ -67,7 +67,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { var errorCount = 0 for _ in 0 ..< 10 { - guard let item: DatabaseRowType = try! await table.getItem(forKey: key) else { + guard let item: DatabaseRowType = try await table.getItem(forKey: key) else { return XCTFail("Expected to retrieve item and there was none") } @@ -83,7 +83,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { try await table.deleteItem(forKey: key) - let nowDeletedItem: DatabaseRowType? = try! await table.getItem(forKey: key) + let nowDeletedItem: DatabaseRowType? = try await table.getItem(forKey: key) XCTAssertNil(nowDeletedItem) } @@ -128,7 +128,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { var errorCount = 0 for _ in 0 ..< 10 { - let query: [ExpectedQueryableTypes] = try! await table.query(forPartitionKey: "partitionId", + let query: [ExpectedQueryableTypes] = try await table.query(forPartitionKey: "partitionId", sortKeyCondition: .equals("sortId")) guard query.count == 1, case let .testTypeA(firstDatabaseItem) = query[0] else { @@ -155,7 +155,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { try await table.deleteItem(forKey: key) - let nowDeletedItem: DatabaseRowType? = try! await table.getItem(forKey: key) + let nowDeletedItem: DatabaseRowType? = try await table.getItem(forKey: key) XCTAssertNil(nowDeletedItem) } @@ -173,7 +173,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { var errorCount = 0 for _ in 0 ..< 10 { - let query: [DatabaseRowType] = try! await table.monomorphicQuery(forPartitionKey: "partitionId", + let query: [DatabaseRowType] = try await table.monomorphicQuery(forPartitionKey: "partitionId", sortKeyCondition: .equals("sortId")) guard query.count == 1, let firstQuery = query.first else { @@ -198,7 +198,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { try await table.deleteItem(forKey: key) - let nowDeletedItem: DatabaseRowType? = try! await table.getItem(forKey: key) + let nowDeletedItem: DatabaseRowType? = try await table.getItem(forKey: key) XCTAssertNil(nowDeletedItem) } @@ -227,7 +227,7 @@ class SimulateConcurrencyDynamoDBCompositePrimaryKeyTableTests: XCTestCase { try await table.deleteItem(forKey: key) - let nowDeletedItem: DatabaseRowType? = try! await table.getItem(forKey: key) + let nowDeletedItem: DatabaseRowType? = try await table.getItem(forKey: key) XCTAssertNil(nowDeletedItem) } } diff --git a/Tests/DynamoDBTablesTests/SmokeDynamoDBTestInput.swift b/Tests/DynamoDBTablesTests/SmokeDynamoDBTestInput.swift index 930b089..101e448 100644 --- a/Tests/DynamoDBTablesTests/SmokeDynamoDBTestInput.swift +++ b/Tests/DynamoDBTablesTests/SmokeDynamoDBTestInput.swift @@ -29,7 +29,7 @@ import Foundation enum AllQueryableTypes: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (TypeA.self, .init { .typeA($0) }), (TypeB.self, .init { .typeB($0) }), ] @@ -41,22 +41,22 @@ enum AllQueryableTypes: PolymorphicOperationReturnType { enum SomeQueryableTypes: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (TypeA.self, .init { .typeA($0) }), ] case typeA(StandardTypedDatabaseItem) } -struct GSI1PKIndexIdentity: IndexIdentity { - static var codingKey = createRowWithIndexCodingKey(stringValue: "GSI-1-PK") - static var identity = "GSI1PK" +struct GSI1PKIndexIdentity: IndexIdentity, Sendable { + static let codingKey = createRowWithIndexCodingKey(stringValue: "GSI-1-PK") + static let identity = "GSI1PK" } enum AllQueryableTypesWithIndex: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (RowWithIndex.self, .init { .typeAWithIndex($0) }), (TypeB.self, .init { .typeB($0) }), ] @@ -65,7 +65,7 @@ enum AllQueryableTypesWithIndex: PolymorphicOperationReturnType { case typeB(StandardTypedDatabaseItem) } -struct TypeA: Codable { +struct TypeA: Codable, Sendable { let firstly: String let secondly: String @@ -76,7 +76,7 @@ struct TypeA: Codable { } struct TypeB: Codable, CustomRowTypeIdentifier { - static var rowTypeIdentifier: String? = "TypeBCustom" + static let rowTypeIdentifier: String? = "TypeBCustom" let thirdly: String let fourthly: String diff --git a/Tests/DynamoDBTablesTests/SmokeDynamoDBTests.swift b/Tests/DynamoDBTablesTests/SmokeDynamoDBTests.swift index e8eb403..12288a1 100644 --- a/Tests/DynamoDBTablesTests/SmokeDynamoDBTests.swift +++ b/Tests/DynamoDBTablesTests/SmokeDynamoDBTests.swift @@ -28,9 +28,6 @@ import AWSDynamoDB @testable import DynamoDBTables import XCTest -private let dynamodbEncoder = DynamoDBEncoder() -private let dynamodbDecoder = DynamoDBDecoder() - private func createDecoder() -> JSONDecoder { let jsonDecoder = JSONDecoder() #if os(Linux) @@ -67,13 +64,13 @@ class DynamoDBTablesTests: XCTestCase { } guard let databaseItem: StandardTypedDatabaseItem = try assertNoThrow( - dynamodbDecoder.decode(jsonAttributeValue)) + DynamoDBDecoder().decode(jsonAttributeValue)) else { return } guard let decodeAttributeValue = try assertNoThrow( - dynamodbEncoder.encode(databaseItem)) + DynamoDBEncoder().encode(databaseItem)) else { return } @@ -96,13 +93,13 @@ class DynamoDBTablesTests: XCTestCase { } guard let databaseItem: StandardTypedDatabaseItem = try assertNoThrow( - dynamodbDecoder.decode(jsonAttributeValue)) + DynamoDBDecoder().decode(jsonAttributeValue)) else { return } guard let decodeAttributeValue = try assertNoThrow( - dynamodbEncoder.encode(databaseItem)) + DynamoDBEncoder().encode(databaseItem)) else { return } @@ -125,7 +122,7 @@ class DynamoDBTablesTests: XCTestCase { } guard let databaseItem: StandardTypedDatabaseItem = try assertNoThrow( - dynamodbDecoder.decode(attributeValue)) + DynamoDBDecoder().decode(attributeValue)) else { return } @@ -151,7 +148,7 @@ class DynamoDBTablesTests: XCTestCase { } guard let databaseItem: StandardTypedDatabaseItem = try assertNoThrow( - dynamodbDecoder.decode(attributeValue)) + DynamoDBDecoder().decode(attributeValue)) else { return } @@ -182,7 +179,7 @@ class DynamoDBTablesTests: XCTestCase { let itemsOptional: [ReturnTypeDecodable]? = try assertNoThrow( attributeValues.map { value in - try dynamodbDecoder.decode(value) + try DynamoDBDecoder().decode(value) }) guard let items = itemsOptional else { @@ -233,7 +230,7 @@ class DynamoDBTablesTests: XCTestCase { do { let _: [ReturnTypeDecodable] = try attributeValues.map { value in - try dynamodbDecoder.decode(value) + try DynamoDBDecoder().decode(value) } } catch let DynamoDBTableError.unexpectedType(provided: provided) { XCTAssertEqual(provided, "TypeBCustom") @@ -257,7 +254,7 @@ class DynamoDBTablesTests: XCTestCase { let itemsOptional: [ReturnTypeDecodable]? = try assertNoThrow( attributeValues.map { value in - try dynamodbDecoder.decode(value) + try DynamoDBDecoder().decode(value) }) guard let items = itemsOptional else { diff --git a/Tests/DynamoDBTablesTests/TestConfiguration.swift b/Tests/DynamoDBTablesTests/TestConfiguration.swift index 1bfe83c..9ff59e8 100644 --- a/Tests/DynamoDBTablesTests/TestConfiguration.swift +++ b/Tests/DynamoDBTablesTests/TestConfiguration.swift @@ -33,7 +33,7 @@ struct TestTypeA: Codable, Equatable { } struct TestTypeB: Codable, Equatable, CustomRowTypeIdentifier { - static var rowTypeIdentifier: String? = "TypeBCustom" + static let rowTypeIdentifier: String? = "TypeBCustom" let thirdly: String let fourthly: String @@ -56,7 +56,7 @@ struct TestTypeC: Codable { enum TestQueryableTypes: PolymorphicOperationReturnType { typealias AttributesType = StandardPrimaryKeyAttributes - static var types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ + static let types: [(Codable.Type, PolymorphicOperationReturnOption)] = [ (TestTypeA.self, .init { .testTypeA($0) }), (TestTypeB.self, .init { .testTypeB($0) }), ]