Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(datastore): resolve swiftformat errors and warnings #3848

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,38 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior {
return publisher.filter { $0.modelName == modelName }.eraseToAnyPublisher()
}

public func observe<M: Model>(_ modelType: M.Type) -> AmplifyAsyncThrowingSequence<MutationEvent> {
public func observe(_ modelType: (some Model).Type) -> AmplifyAsyncThrowingSequence<MutationEvent> {
let runner = ObserveTaskRunner(publisher: publisher(for: modelType.modelName))
return runner.sequence
}

public func observeQuery<M: Model>(for modelType: M.Type,
where predicate: QueryPredicate?,
sort sortInput: QuerySortInput?) -> AmplifyAsyncThrowingSequence<DataStoreQuerySnapshot<M>> {
public func observeQuery<M: Model>(
for modelType: M.Type,
where predicate: QueryPredicate?,
sort sortInput: QuerySortInput?
) -> AmplifyAsyncThrowingSequence<DataStoreQuerySnapshot<M>> {
switch initStorageEngineAndTryStartSync() {
case .success(let storageEngineBehavior):
let modelSchema = modelType.schema
guard let dataStorePublisher = dataStorePublisher else {
guard let dataStorePublisher else {
return Fatal.preconditionFailure("`dataStorePublisher` is expected to exist for deployment targets >=iOS13.0")
}
guard let dispatchedModelSyncedEvent = dispatchedModelSyncedEvents[modelSchema.name] else {
return Fatal.preconditionFailure("`dispatchedModelSyncedEvent` is expected to exist for \(modelSchema.name)")
}
let request = ObserveQueryRequest(options: [])
let taskRunner = ObserveQueryTaskRunner(request: request,
modelType: modelType,
modelSchema: modelType.schema,
predicate: predicate,
sortInput: sortInput?.asSortDescriptors(),
storageEngine: storageEngineBehavior,
dataStorePublisher: dataStorePublisher,
dataStoreConfiguration: configuration.pluginConfiguration,
dispatchedModelSyncedEvent: dispatchedModelSyncedEvent,
dataStoreStatePublisher: dataStoreStateSubject.eraseToAnyPublisher())
let taskRunner = ObserveQueryTaskRunner(
request: request,
modelType: modelType,
modelSchema: modelType.schema,
predicate: predicate,
sortInput: sortInput?.asSortDescriptors(),
storageEngine: storageEngineBehavior,
dataStorePublisher: dataStorePublisher,
dataStoreConfiguration: configuration.pluginConfiguration,
dispatchedModelSyncedEvent: dispatchedModelSyncedEvent,
dataStoreStatePublisher: dataStoreStateSubject.eraseToAnyPublisher()
)
return taskRunner.sequence
case .failure(let error):
return Fatal.preconditionFailure("Unable to get storage adapter \(error.localizedDescription)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Amplify
import Combine
import AWSPluginsCore
import Combine
import Foundation

enum DataStoreState {
Expand All @@ -16,7 +16,7 @@ enum DataStoreState {
case clear
}

final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
public final class AWSDataStorePlugin: DataStoreCategoryPlugin {

public var key: PluginKey = "awsDataStorePlugin"

Expand Down Expand Up @@ -60,14 +60,17 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
/// - Parameters:
/// - modelRegistration: Register DataStore models.
/// - dataStoreConfiguration: Configuration object for DataStore
public init(modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration) {
public init(
modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration
) {
self.modelRegistration = modelRegistration
self.configuration = InternalDatastoreConfiguration(
isSyncEnabled: false,
validAPIPluginKey: "awsAPIPlugin",
validAuthPluginKey: "awsCognitoAuthPlugin",
pluginConfiguration: dataStoreConfiguration)
pluginConfiguration: dataStoreConfiguration
)

self.storageEngineBehaviorFactory =
StorageEngine.init(
Expand All @@ -86,14 +89,17 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
/// - Parameters:
/// - modelRegistration: Register DataStore models.
/// - dataStoreConfiguration: Configuration object for DataStore
public init(modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration = .default) {
public init(
modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration = .default
) {
self.modelRegistration = modelRegistration
self.configuration = InternalDatastoreConfiguration(
isSyncEnabled: false,
validAPIPluginKey: "awsAPIPlugin",
validAuthPluginKey: "awsCognitoAuthPlugin",
pluginConfiguration: dataStoreConfiguration)
pluginConfiguration: dataStoreConfiguration
)

self.storageEngineBehaviorFactory =
StorageEngine.init(
Expand All @@ -110,19 +116,22 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
#endif

/// Internal initializer for testing
init(modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration = .testDefault(),
storageEngineBehaviorFactory: StorageEngineBehaviorFactory? = nil,
dataStorePublisher: ModelSubcriptionBehavior,
operationQueue: OperationQueue = OperationQueue(),
validAPIPluginKey: String,
validAuthPluginKey: String) {
init(
modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration = .testDefault(),
storageEngineBehaviorFactory: StorageEngineBehaviorFactory? = nil,
dataStorePublisher: ModelSubcriptionBehavior,
operationQueue: OperationQueue = OperationQueue(),
validAPIPluginKey: String,
validAuthPluginKey: String
) {
self.modelRegistration = modelRegistration
self.configuration = InternalDatastoreConfiguration(
isSyncEnabled: false,
validAPIPluginKey: validAPIPluginKey,
validAuthPluginKey: validAuthPluginKey,
pluginConfiguration: dataStoreConfiguration)
pluginConfiguration: dataStoreConfiguration
)

self.storageEngineBehaviorFactory = storageEngineBehaviorFactory ??
StorageEngine.init(
Expand Down Expand Up @@ -161,8 +170,8 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
}

do {
if self.dataStorePublisher == nil {
self.dataStorePublisher = DataStorePublisher()
if dataStorePublisher == nil {
dataStorePublisher = DataStorePublisher()
}
try resolveStorageEngine(dataStoreConfiguration: configuration.pluginConfiguration)
try storageEngine.setUp(modelSchemas: ModelRegistry.modelSchemas)
Expand Down Expand Up @@ -251,7 +260,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
}

func onReceiveValue(receiveValue: StorageEngineEvent) {
guard let dataStorePublisher = self.dataStorePublisher else {
guard let dataStorePublisher else {
log.error("Data store publisher not initalized")
return
}
Expand All @@ -264,8 +273,10 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
case .modelSyncedEvent(let modelSyncedEvent):
log.verbose("Emitting DataStore event: modelSyncedEvent \(modelSyncedEvent)")
dispatchedModelSyncedEvents[modelSyncedEvent.modelName]?.set(true)
let modelSyncedEventPayload = HubPayload(eventName: HubPayload.EventName.DataStore.modelSynced,
data: modelSyncedEvent)
let modelSyncedEventPayload = HubPayload(
eventName: HubPayload.EventName.DataStore.modelSynced,
data: modelSyncedEvent
)
Amplify.Hub.dispatch(to: .dataStore, payload: modelSyncedEventPayload)
case .syncQueriesReadyEvent:
log.verbose("[Lifecycle event 4]: syncQueriesReady")
Expand All @@ -284,7 +295,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
if let resettable = storageEngine as? Resettable {
log.verbose("Resetting storageEngine")
await resettable.reset()
self.log.verbose("Resetting storageEngine: finished")
log.verbose("Resetting storageEngine: finished")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import AWSPluginsCore
import Foundation

extension DataStoreConfiguration {
public extension DataStoreConfiguration {

public static let defaultSyncInterval: TimeInterval = .hours(24)
public static let defaultSyncMaxRecords: UInt = 10_000
public static let defaultSyncPageSize: UInt = 1_000
static let defaultSyncInterval: TimeInterval = .hours(24)
static let defaultSyncMaxRecords: UInt = 10_000
static let defaultSyncPageSize: UInt = 1_000

#if os(watchOS)
/// Creates a custom configuration. The only required property is `conflictHandler`.
Expand All @@ -27,7 +27,7 @@ extension DataStoreConfiguration {
/// - authModeStrategy: authorization strategy (.default | multiauth)
/// - disableSubscriptions: called before establishing subscriptions. Return true to disable subscriptions.
/// - Returns: an instance of `DataStoreConfiguration` with the passed parameters.
public static func custom(
static func custom(
errorHandler: @escaping DataStoreErrorHandler = { error in
Amplify.Logging.error(error: error)
},
Expand All @@ -41,14 +41,16 @@ extension DataStoreConfiguration {
authModeStrategy: AuthModeStrategyType = .default,
disableSubscriptions: @escaping () -> Bool
) -> DataStoreConfiguration {
return DataStoreConfiguration(errorHandler: errorHandler,
conflictHandler: conflictHandler,
syncInterval: syncInterval,
syncMaxRecords: syncMaxRecords,
syncPageSize: syncPageSize,
syncExpressions: syncExpressions,
authModeStrategy: authModeStrategy,
disableSubscriptions: disableSubscriptions)
return DataStoreConfiguration(
errorHandler: errorHandler,
conflictHandler: conflictHandler,
syncInterval: syncInterval,
syncMaxRecords: syncMaxRecords,
syncPageSize: syncPageSize,
syncExpressions: syncExpressions,
authModeStrategy: authModeStrategy,
disableSubscriptions: disableSubscriptions
)
}
#else
/// Creates a custom configuration. The only required property is `conflictHandler`.
Expand All @@ -61,7 +63,7 @@ extension DataStoreConfiguration {
/// - syncPageSize: the page size of each sync execution
/// - authModeStrategy: authorization strategy (.default | multiauth)
/// - Returns: an instance of `DataStoreConfiguration` with the passed parameters.
public static func custom(
static func custom(
errorHandler: @escaping DataStoreErrorHandler = { error in
Amplify.Logging.error(error: error)
},
Expand All @@ -74,13 +76,15 @@ extension DataStoreConfiguration {
syncExpressions: [DataStoreSyncExpression] = [],
authModeStrategy: AuthModeStrategyType = .default
) -> DataStoreConfiguration {
return DataStoreConfiguration(errorHandler: errorHandler,
conflictHandler: conflictHandler,
syncInterval: syncInterval,
syncMaxRecords: syncMaxRecords,
syncPageSize: syncPageSize,
syncExpressions: syncExpressions,
authModeStrategy: authModeStrategy)
return DataStoreConfiguration(
errorHandler: errorHandler,
conflictHandler: conflictHandler,
syncInterval: syncInterval,
syncMaxRecords: syncMaxRecords,
syncPageSize: syncPageSize,
syncExpressions: syncExpressions,
authModeStrategy: authModeStrategy
)
}
#endif

Expand All @@ -89,12 +93,12 @@ extension DataStoreConfiguration {
/// which work on the watchOS simulator but not on the device. Running DataStore on watchOS with subscriptions
/// enabled is only possible during special circumstances such as actively streaming audio.
/// See https://github.com/aws-amplify/amplify-swift/pull/3368 for more details.
public static var subscriptionsDisabled: DataStoreConfiguration {
static var subscriptionsDisabled: DataStoreConfiguration {
.custom(disableSubscriptions: { true })
}
#else
/// The default configuration.
public static var `default`: DataStoreConfiguration {
static var `default`: DataStoreConfiguration {
.custom()
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Amplify
import Foundation
import AWSPluginsCore
import Foundation

/// Error Handler function typealias
public typealias DataStoreErrorHandler = (AmplifyError) -> Void
Expand Down Expand Up @@ -73,14 +73,16 @@ public struct DataStoreConfiguration {
public let disableSubscriptions: () -> Bool

#if os(watchOS)
init(errorHandler: @escaping DataStoreErrorHandler,
conflictHandler: @escaping DataStoreConflictHandler,
syncInterval: TimeInterval,
syncMaxRecords: UInt,
syncPageSize: UInt,
syncExpressions: [DataStoreSyncExpression],
authModeStrategy: AuthModeStrategyType = .default,
disableSubscriptions: @escaping () -> Bool) {
init(
errorHandler: @escaping DataStoreErrorHandler,
conflictHandler: @escaping DataStoreConflictHandler,
syncInterval: TimeInterval,
syncMaxRecords: UInt,
syncPageSize: UInt,
syncExpressions: [DataStoreSyncExpression],
authModeStrategy: AuthModeStrategyType = .default,
disableSubscriptions: @escaping () -> Bool
) {
self.errorHandler = errorHandler
self.conflictHandler = conflictHandler
self.syncInterval = syncInterval
Expand All @@ -91,13 +93,15 @@ public struct DataStoreConfiguration {
self.disableSubscriptions = disableSubscriptions
}
#else
init(errorHandler: @escaping DataStoreErrorHandler,
conflictHandler: @escaping DataStoreConflictHandler,
syncInterval: TimeInterval,
syncMaxRecords: UInt,
syncPageSize: UInt,
syncExpressions: [DataStoreSyncExpression],
authModeStrategy: AuthModeStrategyType = .default) {
init(
errorHandler: @escaping DataStoreErrorHandler,
conflictHandler: @escaping DataStoreConflictHandler,
syncInterval: TimeInterval,
syncMaxRecords: UInt,
syncPageSize: UInt,
syncExpressions: [DataStoreSyncExpression],
authModeStrategy: AuthModeStrategyType = .default
) {
self.errorHandler = errorHandler
self.conflictHandler = conflictHandler
self.syncInterval = syncInterval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

struct InternalDatastoreConfiguration {

Expand All @@ -32,7 +32,7 @@ struct InternalDatastoreConfiguration {
let pluginConfiguration: DataStoreConfiguration

mutating func updateIsSyncEnabled(_ isEnabled: Bool) {
self.isSyncEnabled = isEnabled
isSyncEnabled = isEnabled
}

mutating func updateIsEagerLoad(modelSchema: ModelSchema) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Combine
import Foundation

public struct DataStoreListDecoder: ModelListDecoder {

Expand Down
Loading
Loading