Skip to content

Commit

Permalink
Address warnings under -strict-concurrency=complete compiler flag. (#18)
Browse files Browse the repository at this point in the history
Address warnings under -strict-concurrency=complete compiler flag.
  • Loading branch information
tachyonics authored May 23, 2024
1 parent 5e602c4 commit 5f14bb9
Show file tree
Hide file tree
Showing 23 changed files with 75 additions and 78 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<StandardPrimaryKeyAttributes, Self>)] = [
static let types: [(Codable.Type, PolymorphicOperationReturnOption<StandardPrimaryKeyAttributes, Self>)] = [
(TypeA.self, .init( {.typeA($0)} )),
(TypeB.self, .init( {.typeB($0)} )),
]
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttributesType: PrimaryKeyAttributes, ItemType: Codable> {
private class MonomorphicGetItemsRetriable<AttributesType: PrimaryKeyAttributes, ItemType: Sendable & Codable> {
typealias OutputType = [CompositePrimaryKey<AttributesType>: TypedDatabaseItem<AttributesType, ItemType>]

let dynamodb: AWSDynamoDB.DynamoDBClient
Expand Down
4 changes: 2 additions & 2 deletions Sources/DynamoDBTables/CompositePrimaryKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -66,7 +66,7 @@ struct DynamoDBAttributesTypeCodingKey: CodingKey {
}
}

public struct CompositePrimaryKey<AttributesType: PrimaryKeyAttributes>: Codable, CustomStringConvertible, Hashable {
public struct CompositePrimaryKey<AttributesType: PrimaryKeyAttributes>: Sendable, Codable, CustomStringConvertible, Hashable {
public var description: String {
"CompositePrimaryKey(partitionKey: \(self.partitionKey), sortKey: \(self.sortKey))"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public extension DynamoDBCompositePrimaryKeyTable {
version number.
- completion: completion handler providing an error that was thrown or nil
*/
func clobberVersionedItemWithHistoricalRow<AttributesType: PrimaryKeyAttributes, ItemType: Codable>(
func clobberVersionedItemWithHistoricalRow<AttributesType: PrimaryKeyAttributes, ItemType: Sendable & Codable>(
forPrimaryKey partitionKey: String,
andHistoricalKey historicalKey: String,
item: ItemType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AttributesType, ItemType: Codable>(
func conditionallyUpdateItem<AttributesType, ItemType: Sendable & Codable>(
forKey key: CompositePrimaryKey<AttributesType>,
withRetries retries: Int = 10,
updatedPayloadProvider: @escaping (ItemType) async throws -> ItemType) async throws
Expand All @@ -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<AttributesType, ItemType: Codable>(
func conditionallyUpdateItem<AttributesType, ItemType: Sendable & Codable>(
forKey key: CompositePrimaryKey<AttributesType>,
withRetries retries: Int = 10,
updatedPayloadProvider: @escaping (ItemType) throws -> ItemType) async throws
Expand Down
4 changes: 2 additions & 2 deletions Sources/DynamoDBTables/DynamoDBCompositePrimaryKeyTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -80,7 +80,7 @@ public enum AttributeCondition {
case beginsWith(String)
}

public enum WriteEntry<AttributesType: PrimaryKeyAttributes, ItemType: Codable> {
public enum WriteEntry<AttributesType: PrimaryKeyAttributes, ItemType: Sendable & Codable>: Sendable {
case update(new: TypedDatabaseItem<AttributesType, ItemType>, existing: TypedDatabaseItem<AttributesType, ItemType>)
case insert(new: TypedDatabaseItem<AttributesType, ItemType>)
case deleteAtKey(key: CompositePrimaryKey<AttributesType>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ import Foundation
public struct InMemoryDynamoDBCompositePrimaryKeysProjection: DynamoDBCompositePrimaryKeysProjection {
let keysWrapper: InMemoryDynamoDBCompositePrimaryKeysProjectionStore

public init(keys: [Any] = []) {
public init(keys: [Sendable] = []) {
self.keysWrapper = InMemoryDynamoDBCompositePrimaryKeysProjectionStore(keys: keys)
}

init(keysWrapper: InMemoryDynamoDBCompositePrimaryKeysProjectionStore) {
self.keysWrapper = keysWrapper
}

public var keys: [Any] {
public var keys: [Sendable] {
get async {
await self.keysWrapper.keys
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
12 changes: 7 additions & 5 deletions Sources/DynamoDBTables/PolymorphicOperationReturnType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ public protocol BatchCapableReturnType {
func getItemKey() -> CompositePrimaryKey<AttributesType>
}

public protocol PolymorphicOperationReturnType {
public protocol PolymorphicOperationReturnType: Sendable {
associatedtype AttributesType: PrimaryKeyAttributes

static var types: [(Codable.Type, PolymorphicOperationReturnOption<AttributesType, Self>)] { get }
}

public struct PolymorphicOperationReturnOption<AttributesType: PrimaryKeyAttributes, ReturnType> {
private let decodingPayloadHandler: (Decoder) throws -> ReturnType
private let typeConvertingPayloadHander: (Any) throws -> ReturnType
public struct PolymorphicOperationReturnOption<AttributesType: PrimaryKeyAttributes, ReturnType>: Sendable {
private let decodingPayloadHandler: @Sendable (Decoder) throws -> ReturnType
private let typeConvertingPayloadHander: @Sendable (Any) throws -> ReturnType

public init<RowType: Codable>(
_ payloadHandler: @escaping (TypedDatabaseItem<AttributesType, RowType>) -> ReturnType)
_ payloadHandler: @escaping @Sendable (TypedDatabaseItem<AttributesType, RowType>) -> ReturnType)
{
@Sendable
func newDecodingPayloadHandler(decoder: Decoder) throws -> ReturnType {
let typedDatabaseItem: TypedDatabaseItem<AttributesType, RowType> = try TypedDatabaseItem(from: decoder)

return payloadHandler(typedDatabaseItem)
}

@Sendable
func newTypeConvertingPayloadHandler(input: Any) throws -> ReturnType {
guard let typedDatabaseItem = input as? TypedDatabaseItem<AttributesType, RowType> else {
let description = "Expected to use item type \(TypedDatabaseItem<AttributesType, RowType>.self)."
Expand Down
6 changes: 3 additions & 3 deletions Sources/DynamoDBTables/PolymorphicWriteEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: PolymorphicWriteEntryContext>(context: Context) throws -> Context.WriteEntryTransformType

var compositePrimaryKey: StandardCompositePrimaryKey? { get }
Expand All @@ -58,13 +58,13 @@ public extension PolymorphicWriteEntry {

public typealias StandardTransactionConstraintEntry<ItemType: Codable> = TransactionConstraintEntry<StandardPrimaryKeyAttributes, ItemType>

public enum TransactionConstraintEntry<AttributesType: PrimaryKeyAttributes, ItemType: Codable> {
public enum TransactionConstraintEntry<AttributesType: PrimaryKeyAttributes, ItemType: Sendable & Codable>: Sendable {
case required(existing: TypedDatabaseItem<AttributesType, ItemType>)
}

// 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: PolymorphicWriteEntryContext>(context: Context) throws -> Context.WriteTransactionConstraintType

var compositePrimaryKey: StandardCompositePrimaryKey? { get }
Expand Down
6 changes: 3 additions & 3 deletions Sources/DynamoDBTables/RetryConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion Sources/DynamoDBTables/RowWithIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public func createRowWithIndexCodingKey(stringValue: String) -> RowWithIndexCodi
RowWithIndexCodingKey(stringValue: stringValue)!
}

public struct RowWithIndex<RowType: Codable, Identity: IndexIdentity>: Codable, CustomRowTypeIdentifier {
public struct RowWithIndex<RowType: Sendable & Codable, Identity: IndexIdentity>: Sendable, Codable, CustomRowTypeIdentifier {
public static var rowTypeIdentifier: String? {
let rowTypeIdentity = getTypeRowIdentifier(type: RowType.self)
let indexIdentity = Identity.identity
Expand Down
2 changes: 1 addition & 1 deletion Sources/DynamoDBTables/RowWithItemVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import Foundation

public struct RowWithItemVersion<RowType: Codable>: Codable, CustomRowTypeIdentifier {
public struct RowWithItemVersion<RowType: Sendable & Codable>: Sendable, Codable, CustomRowTypeIdentifier {
public static var rowTypeIdentifier: String? {
let rowTypeIdentity = getTypeRowIdentifier(type: RowType.self)

Expand Down
2 changes: 1 addition & 1 deletion Sources/DynamoDBTables/TimeToLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct StandardTimeToLiveAttributes: TimeToLiveAttributes {

public typealias StandardTimeToLive = TimeToLive<StandardTimeToLiveAttributes>

public struct TimeToLive<AttributesType: TimeToLiveAttributes>: Codable, CustomStringConvertible, Hashable {
public struct TimeToLive<AttributesType: TimeToLiveAttributes>: Sendable, Codable, CustomStringConvertible, Hashable {
public var description: String {
"TimeToLive(timeToLiveTimestamp: \(self.timeToLiveTimestamp)"
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/DynamoDBTables/TypedDatabaseItemWithTimeToLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import Foundation

public struct RowStatus: Codable {
public struct RowStatus: Sendable, Codable {
public let rowVersion: Int
public let lastUpdatedDate: Date

Expand All @@ -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
Expand All @@ -61,11 +61,11 @@ public extension DatabaseItem {
public protocol StandardDatabaseItem: DatabaseItem where AttributesType == StandardPrimaryKeyAttributes {}

// Default to StandardTimeToLiveAttributes for backwards compatibility
public typealias TypedDatabaseItem<AttributesType: PrimaryKeyAttributes, RowType: Codable> = TypedDatabaseItemWithTimeToLive<AttributesType, RowType, StandardTimeToLiveAttributes>
public typealias TypedDatabaseItem<AttributesType: PrimaryKeyAttributes, RowType: Sendable & Codable> = TypedDatabaseItemWithTimeToLive<AttributesType, RowType, StandardTimeToLiveAttributes>

public struct TypedDatabaseItemWithTimeToLive<AttributesType: PrimaryKeyAttributes,
RowType: Codable,
TimeToLiveAttributesType: TimeToLiveAttributes>: DatabaseItem, Codable
RowType: Sendable & Codable,
TimeToLiveAttributesType: TimeToLiveAttributes>: DatabaseItem, Sendable, Codable
{
public let compositePrimaryKey: CompositePrimaryKey<AttributesType>
public let createDate: Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
15 changes: 6 additions & 9 deletions Tests/DynamoDBTablesTests/DynamoDBEncoderDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import XCTest
enum TestPolymorphicOperationReturnType: PolymorphicOperationReturnType {
typealias AttributesType = StandardPrimaryKeyAttributes

static var types: [(Codable.Type, PolymorphicOperationReturnOption<StandardPrimaryKeyAttributes, Self>)] = [
static let types: [(Codable.Type, PolymorphicOperationReturnOption<StandardPrimaryKeyAttributes, Self>)] = [
(TestTypeA.self, .init { .testTypeA($0) }),
]

Expand Down
Loading

0 comments on commit 5f14bb9

Please sign in to comment.