Skip to content

Commit

Permalink
chore(datastore): resolve swiftformat errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 3, 2024
1 parent ca6c65a commit a53d2c8
Show file tree
Hide file tree
Showing 801 changed files with 9,390 additions and 6,575 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ 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>> {
sort sortInput: QuerySortInput?) -> AmplifyAsyncThrowingSequence<DataStoreQuerySnapshot<M>>
{

Check failure on line 32 in AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
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 {
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 @@ -61,7 +61,8 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
/// - modelRegistration: Register DataStore models.
/// - dataStoreConfiguration: Configuration object for DataStore
public init(modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration) {
configuration dataStoreConfiguration: DataStoreConfiguration)
{
self.modelRegistration = modelRegistration
self.configuration = InternalDatastoreConfiguration(
isSyncEnabled: false,
Expand All @@ -87,7 +88,8 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
/// - modelRegistration: Register DataStore models.
/// - dataStoreConfiguration: Configuration object for DataStore
public init(modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration = .default) {
configuration dataStoreConfiguration: DataStoreConfiguration = .default)
{
self.modelRegistration = modelRegistration
self.configuration = InternalDatastoreConfiguration(
isSyncEnabled: false,
Expand Down Expand Up @@ -116,7 +118,8 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
dataStorePublisher: ModelSubcriptionBehavior,
operationQueue: OperationQueue = OperationQueue(),
validAPIPluginKey: String,
validAuthPluginKey: String) {
validAuthPluginKey: String)
{
self.modelRegistration = modelRegistration
self.configuration = InternalDatastoreConfiguration(
isSyncEnabled: false,
Expand Down Expand Up @@ -161,8 +164,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 +254,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 Down Expand Up @@ -284,7 +287,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 Down Expand Up @@ -61,7 +61,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 Down Expand Up @@ -89,12 +89,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 @@ -80,7 +80,8 @@ public struct DataStoreConfiguration {
syncPageSize: UInt,
syncExpressions: [DataStoreSyncExpression],
authModeStrategy: AuthModeStrategyType = .default,
disableSubscriptions: @escaping () -> Bool) {
disableSubscriptions: @escaping () -> Bool)
{

Check failure on line 84 in AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.errorHandler = errorHandler
self.conflictHandler = conflictHandler
self.syncInterval = syncInterval
Expand All @@ -97,7 +98,8 @@ public struct DataStoreConfiguration {
syncMaxRecords: UInt,
syncPageSize: UInt,
syncExpressions: [DataStoreSyncExpression],
authModeStrategy: AuthModeStrategyType = .default) {
authModeStrategy: AuthModeStrategyType = .default)
{

Check failure on line 102 in AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Configuration/DataStoreConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
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
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

/// `DataStoreList<ModelType>` is a DataStore-aware custom `Collection` that is capable of loading
/// records from the `DataStore` on-demand. This is especially useful when dealing with
Expand Down Expand Up @@ -46,8 +46,9 @@ public class DataStoreListProvider<Element: Model>: ModelListProvider {
let predicate: QueryPredicate
if associatedIdentifiers.count == 1,
let associatedId = associatedIdentifiers.first,
let associatedField = associatedFields.first {
self.log.verbose("Loading List of \(Element.schema.name) by \(associatedField) == \(associatedId) ")
let associatedField = associatedFields.first
{
log.verbose("Loading List of \(Element.schema.name) by \(associatedField) == \(associatedId) ")
predicate = field(associatedField) == associatedId
} else {
let predicateValues = zip(associatedFields, associatedIdentifiers)
Expand All @@ -56,13 +57,13 @@ public class DataStoreListProvider<Element: Model>: ModelListProvider {
queryPredicates.append(QueryPredicateOperation(field: identifierName,
operator: .equals(identifierValue)))
}
self.log.verbose("Loading List of \(Element.schema.name) by \(associatedFields) == \(associatedIdentifiers) ")
log.verbose("Loading List of \(Element.schema.name) by \(associatedFields) == \(associatedIdentifiers) ")
predicate = QueryPredicateGroup(type: .and, predicates: queryPredicates)
}

do {
let elements = try await Amplify.DataStore.query(Element.self, where: predicate)
self.loadedState = .loaded(elements)
loadedState = .loaded(elements)
return elements
} catch let error as DataStoreError {
self.log.error(error: error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import SQLite
import AWSPluginsCore
import Foundation
import SQLite

public struct DataStoreModelDecoder: ModelProviderDecoder {

Expand All @@ -18,7 +18,8 @@ public struct DataStoreModelDecoder: ModelProviderDecoder {
let source: String

init(identifiers: [LazyReferenceIdentifier],
source: String = ModelProviderRegistry.DecoderSource.dataStore) {
source: String = ModelProviderRegistry.DecoderSource.dataStore)
{
self.identifiers = identifiers
self.source = source
}
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 class DataStoreModelProvider<ModelType: Model>: ModelProvider {
var loadedState: ModelProviderState<ModelType>
Expand All @@ -27,20 +27,20 @@ public class DataStoreModelProvider<ModelType: Model>: ModelProvider {
public func load() async throws -> ModelType? {
switch loadedState {
case .notLoaded(let identifiers):
guard let identifiers = identifiers, !identifiers.isEmpty else {
guard let identifiers, !identifiers.isEmpty else {
return nil
}

let identifierValue = identifiers.count == 1
? identifiers.first?.value
: identifiers.map({ "\"\($0.value)\""}).joined(separator: ModelIdentifierFormat.Custom.separator)
: identifiers.map { "\"\($0.value)\""}.joined(separator: ModelIdentifierFormat.Custom.separator)

let queryPredicate: QueryPredicate = field(ModelType.schema.primaryKey.sqlName).eq(identifierValue)
let models = try await Amplify.DataStore.query(ModelType.self, where: queryPredicate)
guard let model = models.first else {
return nil
}
self.loadedState = .loaded(model: model)
loadedState = .loaded(model: model)
return model
case .loaded(let model):
return model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

public typealias QueryPredicateResolver = () -> QueryPredicate

public struct DataStoreSyncExpression {
let modelSchema: ModelSchema
let modelPredicate: QueryPredicateResolver

static public func syncExpression(_ modelSchema: ModelSchema,
where predicate: @escaping QueryPredicateResolver) -> DataStoreSyncExpression {
public static func syncExpression(_ modelSchema: ModelSchema,
where predicate: @escaping QueryPredicateResolver) -> DataStoreSyncExpression
{

Check failure on line 19 in AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/DataStoreSyncExpression.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
DataStoreSyncExpression(modelSchema: modelSchema, modelPredicate: predicate)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//

import Amplify
import AWSPluginsCore
import Foundation
import SQLite
import AWSPluginsCore

class ModelSyncMetadataMigration: ModelMigration {

Expand Down Expand Up @@ -37,7 +37,8 @@ class ModelSyncMetadataMigration: ModelMigration {
func performModelMetadataSyncPredicateUpgrade() throws -> Bool {
do {
guard let field = ModelSyncMetadata.schema.field(
withName: ModelSyncMetadata.keys.syncPredicate.stringValue) else {
withName: ModelSyncMetadata.keys.syncPredicate.stringValue)
else {
log.error("Could not find corresponding ModelField from ModelSyncMetadata for syncPredicate")
return false
}
Expand All @@ -49,7 +50,7 @@ class ModelSyncMetadataMigration: ModelMigration {
}

log.debug("Detected ModelSyncMetadata table exists without syncPredicate column.")
guard let storageAdapter = storageAdapter else {
guard let storageAdapter else {
log.debug("Missing SQLiteStorageEngineAdapter for model migration")
throw DataStoreError.nilStorageAdapter()
}
Expand All @@ -68,7 +69,7 @@ class ModelSyncMetadataMigration: ModelMigration {
}

func columnExists(modelSchema: ModelSchema, field: ModelField) throws -> Bool {
guard let storageAdapter = storageAdapter else {
guard let storageAdapter else {
log.debug("Missing SQLiteStorageEngineAdapter for model migration")
throw DataStoreError.nilStorageAdapter()
}
Expand All @@ -86,7 +87,8 @@ class ModelSyncMetadataMigration: ModelMigration {
if column.count >= 2,
let columnName = column[1],
let columNameString = columnName as? String,
columnToFind == columNameString {
columnToFind == columNameString
{
columnExists = true
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

extension MutationSyncMetadataMigration {
public struct MutationSyncMetadataCopy: Model {
public extension MutationSyncMetadataMigration {
struct MutationSyncMetadataCopy: Model {
public let id: String
public var deleted: Bool
public var lastChangedAt: Int64
Expand Down
Loading

0 comments on commit a53d2c8

Please sign in to comment.