diff --git a/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2ef4d7901c..580630742c 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,41 +1,5 @@ { "pins" : [ - { - "identity" : "amplify-swift-utils-notifications", - "kind" : "remoteSourceControl", - "location" : "https://github.com/aws-amplify/amplify-swift-utils-notifications.git", - "state" : { - "revision" : "f970384ad1035732f99259255cd2f97564807e41", - "version" : "1.1.0" - } - }, - { - "identity" : "aws-appsync-realtime-client-ios", - "kind" : "remoteSourceControl", - "location" : "https://github.com/aws-amplify/aws-appsync-realtime-client-ios.git", - "state" : { - "revision" : "b036e83716789c13a3480eeb292b70caa54114f2", - "version" : "3.1.0" - } - }, - { - "identity" : "aws-crt-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/awslabs/aws-crt-swift", - "state" : { - "revision" : "6feec6c3787877807aa9a00fad09591b96752376", - "version" : "0.6.1" - } - }, - { - "identity" : "aws-sdk-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/awslabs/aws-sdk-swift.git", - "state" : { - "revision" : "24bae88a2391fe75da8a940a544d1ef6441f5321", - "version" : "0.13.0" - } - }, { "identity" : "cwlcatchexception", "kind" : "remoteSourceControl", @@ -53,60 +17,6 @@ "revision" : "a23ded2c91df9156628a6996ab4f347526f17b6b", "version" : "2.1.2" } - }, - { - "identity" : "smithy-swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/awslabs/smithy-swift", - "state" : { - "revision" : "7b28da158d92cd06a3549140d43b8fbcf64a94a6", - "version" : "0.15.0" - } - }, - { - "identity" : "sqlite.swift", - "kind" : "remoteSourceControl", - "location" : "https://github.com/stephencelis/SQLite.swift.git", - "state" : { - "revision" : "5f5ad81ac0d0a0f3e56e39e646e8423c617df523", - "version" : "0.13.2" - } - }, - { - "identity" : "starscream", - "kind" : "remoteSourceControl", - "location" : "https://github.com/daltoniam/Starscream", - "state" : { - "revision" : "df8d82047f6654d8e4b655d1b1525c64e1059d21", - "version" : "4.0.4" - } - }, - { - "identity" : "swift-collections", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-collections", - "state" : { - "revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2", - "version" : "1.0.4" - } - }, - { - "identity" : "swift-log", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", - "state" : { - "revision" : "32e8d724467f8fe623624570367e3d50c5638e46", - "version" : "1.5.2" - } - }, - { - "identity" : "xmlcoder", - "kind" : "remoteSourceControl", - "location" : "https://github.com/MaxDesiatov/XMLCoder.git", - "state" : { - "revision" : "b1e944cbd0ef33787b13f639a5418d55b3bed501", - "version" : "0.17.1" - } } ], "version" : 2 diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift index 1ad3d612e0..36eeeca8c2 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift @@ -29,8 +29,8 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { completion: @escaping DataStoreCallback ) { log.verbose("Saving: \(model) with condition: \(String(describing: condition))") - let prepareSaveResult = initStorageEngineAndStartSync().flatMap { storageEngineBehavior in - mutationTypeOfModel(model, storageEngine: storageEngineBehavior) + let prepareSaveResult = initStorageEngineAndTryStartSync().flatMap { storageEngineBehavior in + mutationTypeOfModel(model, modelSchema: modelSchema, storageEngine: storageEngineBehavior) .map { (storageEngineBehavior, $0) } } @@ -197,7 +197,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { paginate paginationInput: QueryPaginationInput? = nil, completion: DataStoreCallback<[M]> ) { - switch initStorageEngineAndStartSync() { + switch initStorageEngineAndTryStartSync() { case .success(let storageEngineBehavior): storageEngineBehavior.query( modelType, @@ -240,7 +240,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { withId id: String, where predicate: QueryPredicate? = nil) async throws { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation) in - switch initStorageEngineAndStartSync() { + switch initStorageEngineAndTryStartSync() { case .success(let storageEngineBehavior): storageEngineBehavior.delete(modelType, modelSchema: modelSchema, withId: id, condition: predicate) { result in self.onDeleteCompletion(result: result, modelSchema: modelSchema) { result in @@ -300,7 +300,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { identifier: ModelIdentifierProtocol, where predicate: QueryPredicate?, completion: @escaping DataStoreCallback) where M: ModelIdentifiable { - switch initStorageEngineAndStartSync() { + switch initStorageEngineAndTryStartSync() { case .success(let storageEngineBehavior): storageEngineBehavior.delete( modelType, @@ -346,7 +346,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { modelSchema: ModelSchema, where predicate: QueryPredicate? = nil, completion: @escaping DataStoreCallback) { - switch initStorageEngineAndStartSync() { + switch initStorageEngineAndTryStartSync() { case .success(let storageEngineBehavior): storageEngineBehavior.delete( type(of: model), @@ -387,7 +387,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { modelSchema: ModelSchema, where predicate: QueryPredicate, completion: @escaping DataStoreCallback) { - switch initStorageEngineAndStartSync() { + switch initStorageEngineAndTryStartSync() { case .success(let storageEngineBehavior): storageEngineBehavior.delete( modelType, @@ -515,6 +515,7 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { private func mutationTypeOfModel( _ model: M, + modelSchema: ModelSchema, storageEngine: StorageEngineBehavior ) -> Result { let modelExists: Bool @@ -522,8 +523,8 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior { guard let engine = storageEngine as? StorageEngine else { throw DataStoreError.configuration("Unable to get storage adapter", "") } - modelExists = try engine.storageAdapter.exists(model.schema, - withIdentifier: model.identifier(schema: model.schema), + modelExists = try engine.storageAdapter.exists(modelSchema, + withIdentifier: model.identifier(schema: modelSchema), predicate: nil) } catch { if let dataStoreError = error as? DataStoreError { diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift index 8976127c31..76302653f2 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift @@ -29,7 +29,7 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior { public func observeQuery(for modelType: M.Type, where predicate: QueryPredicate?, sort sortInput: QuerySortInput?) -> AmplifyAsyncThrowingSequence> { - switch initStorageEngineAndStartSync() { + switch initStorageEngineAndTryStartSync() { case .success(let storageEngineBehavior): let modelSchema = modelType.schema guard let dataStorePublisher = dataStorePublisher else { diff --git a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift index 8bd5009fa3..869a190378 100644 --- a/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift +++ b/AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/AWSDataStorePlugin.swift @@ -162,6 +162,17 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin { } } + func initStorageEngineAndTryStartSync() -> Result { + initStorageEngineAndStartSync().flatMapError { error in + switch error { + case .configuration: + return .success(storageEngine) + default: + return .failure(error) + } + } + } + func resolveStorageEngine(dataStoreConfiguration: DataStoreConfiguration) throws { guard storageEngine == nil else { return diff --git a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/TestSupport/LocalStoreIntegrationTestBase.swift b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/TestSupport/LocalStoreIntegrationTestBase.swift index af8e3a5849..300f007837 100644 --- a/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/TestSupport/LocalStoreIntegrationTestBase.swift +++ b/AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/TestSupport/LocalStoreIntegrationTestBase.swift @@ -9,6 +9,7 @@ import XCTest @testable import Amplify @testable import AWSDataStorePlugin +@testable import AWSAPIPlugin class LocalStoreIntegrationTestBase: XCTestCase { diff --git a/Package.swift b/Package.swift index a71dc5c8d4..54eee96c29 100644 --- a/Package.swift +++ b/Package.swift @@ -203,6 +203,7 @@ let dataStoreTargets: [Target] = [ .testTarget( name: "AWSDataStoreCategoryPluginTests", dependencies: [ + "AWSAPIPlugin", "AWSDataStorePlugin", "AmplifyTestCommon", "AmplifyAsyncTesting"