Skip to content

Commit

Permalink
chore: resolve swiftlint errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Jan 2, 2024
1 parent bb692b0 commit 104b63a
Show file tree
Hide file tree
Showing 39 changed files with 181 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion: @escaping DataStoreCallback<M>) {
save(model, modelSchema: model.schema, where: condition, completion: completion)
}

public func save<M: Model>(_ model: M,
where condition: QueryPredicate? = nil) async throws -> M {
try await save(model, modelSchema: model.schema, where: condition)
Expand Down Expand Up @@ -56,7 +56,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion(.failure(error))
}
}

public func save<M: Model>(_ model: M,
modelSchema: ModelSchema,
where condition: QueryPredicate? = nil) async throws -> M {
Expand Down Expand Up @@ -107,7 +107,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
identifier: DefaultModelIdentifier<M>.makeDefault(id: identifier),
completion: completion)
}

public func query<M: Model>(_ modelType: M.Type,
byIdentifier identifier: String) async throws -> M?
where M: ModelIdentifiable, M.IdentifierFormat == ModelIdentifierFormat.Default {
Expand All @@ -124,7 +124,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
identifier: identifier,
completion: completion)
}

public func query<M: Model>(_ modelType: M.Type,
byIdentifier identifier: ModelIdentifier<M, M.IdentifierFormat>) async throws -> M?
where M: ModelIdentifiable {
Expand Down Expand Up @@ -154,7 +154,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
}
}
}

private func queryByIdentifier<M: Model>(_ modelType: M.Type,
modelSchema: ModelSchema,
identifier: ModelIdentifierProtocol) async throws -> M? {
Expand All @@ -177,7 +177,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
paginate: paginationInput,
completion: completion)
}

public func query<M: Model>(_ modelType: M.Type,
where predicate: QueryPredicate? = nil,
sort sortInput: QuerySortInput? = nil,
Expand Down Expand Up @@ -212,7 +212,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion(.failure(error))
}
}

public func query<M: Model>(_ modelType: M.Type,
modelSchema: ModelSchema,
where predicate: QueryPredicate? = nil,
Expand All @@ -233,7 +233,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
try await delete(modelType, modelSchema: modelType.schema, withId: id, where: predicate)

}

@available(*, deprecated, renamed: "delete(withIdentifier:)")
public func delete<M: Model>(_ modelType: M.Type,
modelSchema: ModelSchema,
Expand Down Expand Up @@ -264,7 +264,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
where: predicate,
completion: completion)
}

public func delete<M: Model>(_ modelType: M.Type,
withIdentifier identifier: String,
where predicate: QueryPredicate? = nil) async throws
Expand All @@ -285,7 +285,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
where: predicate,
completion: completion)
}

public func delete<M: Model>(_ modelType: M.Type,
withIdentifier identifier: ModelIdentifier<M, M.IdentifierFormat>,
where predicate: QueryPredicate? = nil) async throws where M: ModelIdentifiable {
Expand Down Expand Up @@ -319,7 +319,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
}

}

private func deleteByIdentifier<M: Model>(_ modelType: M.Type,
modelSchema: ModelSchema,
identifier: ModelIdentifierProtocol,
Expand All @@ -336,7 +336,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion: @escaping DataStoreCallback<Void>) {
delete(model, modelSchema: model.schema, where: predicate, completion: completion)
}

public func delete<M: Model>(_ model: M,
where predicate: QueryPredicate? = nil) async throws {
try await delete(model, modelSchema: model.schema, where: predicate)
Expand All @@ -361,7 +361,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
}

}

public func delete<M: Model>(_ model: M,
modelSchema: ModelSchema,
where predicate: QueryPredicate? = nil) async throws {
Expand All @@ -377,7 +377,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion: @escaping DataStoreCallback<Void>) {
delete(modelType, modelSchema: modelType.schema, where: predicate, completion: completion)
}

public func delete<M: Model>(_ modelType: M.Type,
where predicate: QueryPredicate) async throws {
try await delete(modelType, modelSchema: modelType.schema, where: predicate)
Expand Down Expand Up @@ -408,7 +408,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion(.failure(error))
}
}

public func delete<M: Model>(_ modelType: M.Type,
modelSchema: ModelSchema,
where predicate: QueryPredicate) async throws {
Expand All @@ -425,7 +425,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
completion(result)
}
}

public func start() async throws {
_ = try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<DataStoreResult<Void>, Error>) in
start { result in
Expand Down Expand Up @@ -454,7 +454,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
}
}
}

public func stop() async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
stop { result in
Expand Down Expand Up @@ -488,7 +488,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
}
}
}

public func clear() async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
clear { result in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Amplify
import Combine

extension AWSDataStorePlugin: DataStoreSubscribeBehavior {

public var publisher: AnyPublisher<MutationEvent, DataStoreError> {
_ = initStorageEngineAndStartSync()
// Force-unwrapping: The optional 'dataStorePublisher' is expected
Expand All @@ -25,7 +25,7 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior {
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>> {
Expand Down Expand Up @@ -53,7 +53,6 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior {
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 @@ -22,7 +22,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {

/// The Publisher that sends mutation events to subscribers
var dataStorePublisher: ModelSubcriptionBehavior?

var dataStoreStateSubject = PassthroughSubject<DataStoreState, DataStoreError>()

var dispatchedModelSyncedEvents: [ModelName: AtomicValue<Bool>]
Expand Down Expand Up @@ -108,7 +108,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
self.dispatchedModelSyncedEvents = [:]
}
#endif

/// Internal initializer for testing
init(modelRegistration: AmplifyModelRegistration,
configuration dataStoreConfiguration: DataStoreConfiguration = .testDefault(),
Expand Down Expand Up @@ -142,7 +142,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
/// them to `StorageEngine.setUp(modelSchemas:)`
public func configure(using amplifyConfiguration: Any?) throws {
modelRegistration.registerModels(registry: ModelRegistry.self)

for modelSchema in ModelRegistry.modelSchemas {
dispatchedModelSyncedEvents[modelSchema.name] = AtomicValue(initialValue: false)
configuration.updateIsEagerLoad(modelSchema: modelSchema)
Expand All @@ -151,7 +151,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
ModelListDecoderRegistry.registerDecoder(DataStoreListDecoder.self)
ModelProviderRegistry.registerDecoder(DataStoreModelDecoder.self)
}

/// Initializes the underlying storage engine
/// - Returns: success if the engine is successfully initialized or
/// a failure with a DataStoreError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension DataStoreConfiguration {
authModeStrategy: authModeStrategy)
}
#endif

#if os(watchOS)
/// Default configuration with subscriptions disabled for watchOS. DataStore uses subscriptions via websockets,
/// which work on the watchOS simulator but not on the device. Running DataStore on watchOS with subscriptions
Expand All @@ -98,7 +98,7 @@ extension DataStoreConfiguration {
.custom()
}
#endif

#if os(watchOS)
/// Internal method for testing
static func testDefault(disableSubscriptions: @escaping () -> Bool = { false }) -> DataStoreConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct DataStoreConfiguration {
public var authModeStrategyType: AuthModeStrategyType

public let disableSubscriptions: () -> Bool

#if os(watchOS)
init(errorHandler: @escaping DataStoreErrorHandler,
conflictHandler: @escaping DataStoreConflictHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct InternalDatastoreConfiguration {
/// Configuration of the query against the local storage, whether it should load
/// the belongs-to/has-one associations or not.
///
///`isEagerLoad` is true by default, unless the models contain the rootPath
/// `isEagerLoad` is true by default, unless the models contain the rootPath
/// which is indication of the codegen that supports for lazy loading.
var isEagerLoad: Bool = true

Expand All @@ -30,12 +30,12 @@ struct InternalDatastoreConfiguration {

/// Configuration provided during Datastore initialization, this is a `public` configuration.
let pluginConfiguration: DataStoreConfiguration
mutating func updateIsSyncEnabled(_ isEnabled: Bool) {

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

mutating func updateIsEagerLoad(modelSchema: ModelSchema) {
mutating func updateIsEagerLoad(modelSchema: ModelSchema) {
guard isEagerLoad else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ import Amplify
import Combine

public struct DataStoreListDecoder: ModelListDecoder {

struct Metadata: Codable {
let dataStoreAssociatedIdentifiers: [String]
let dataStoreAssociatedFields: [String]
}

/// Creates a data structure that is capable of initializing a `List<M>` with
/// lazy-load capabilities when the list is being decoded.
static func lazyInit(associatedIds: [String], associatedWith: [String]) -> [String: Any?] {
return [
"dataStoreAssociatedIdentifiers": associatedIds,
"dataStoreAssociatedFields": associatedWith,
"dataStoreAssociatedFields": associatedWith
]
}

public static func decode<ModelType: Model>(modelType: ModelType.Type, decoder: Decoder) -> AnyModelListProvider<ModelType>? {
shouldDecodeToDataStoreListProvider(modelType: modelType, decoder: decoder)?.eraseToAnyModelListProvider()
}

public static func shouldDecodeToDataStoreListProvider<ModelType: Model>(modelType: ModelType.Type, decoder: Decoder) -> DataStoreListProvider<ModelType>? {
if let metadata = try? Metadata.init(from: decoder) {
return DataStoreListProvider<ModelType>(metadata: metadata)
}

let json = try? JSONValue(from: decoder)
switch json {
case .array:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DataStoreListProvider<Element: Model>: ModelListProvider {
init(_ elements: [Element]) {
self.loadedState = .loaded(elements)
}

public func getState() -> ModelListProviderState<Element> {
switch loadedState {
case .notLoaded(let associatedIdentifiers, let associatedFields):
Expand All @@ -37,7 +37,7 @@ public class DataStoreListProvider<Element: Model>: ModelListProvider {
return .loaded(elements)
}
}

public func load() async throws -> [Element] {
switch loadedState {
case .loaded(let elements):
Expand All @@ -59,7 +59,7 @@ public class DataStoreListProvider<Element: Model>: ModelListProvider {
self.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)
Expand All @@ -71,21 +71,21 @@ public class DataStoreListProvider<Element: Model>: ModelListProvider {
error)
} catch {
throw error

}
}
}

public func hasNextPage() -> Bool {
false
}

public func getNextPage() async throws -> List<Element> {
throw CoreError.clientValidation("There is no next page.",
"Only call `getNextPage()` when `hasNextPage()` is true.",
nil)
}

public func encode(to encoder: Encoder) throws {
switch loadedState {
case .notLoaded(let associatedIdentifiers,
Expand Down
Loading

0 comments on commit 104b63a

Please sign in to comment.