-
Notifications
You must be signed in to change notification settings - Fork 216
feat(datastore): refactor datastore category to use APICategoryGraphQLBehavior #3666
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0720707
WIP
lawmicha 1d47dcf
DataStore compiles without SDK dependency
lawmicha 21990cd
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 6e29d88
refactor(datastore-v2): use api plugin with async sequences
5d 276e13f
change to use Publisher operators for auth type streams
5d c03a50b
add nondeterminsitc operation for better testability
5d ccbfd66
fix unit test cases
5d 3079ec7
Merge remote-tracking branch 'origin/main' into 5d/api-behavior
5d fa72566
fix broken unit test cases of AWSAPIPlugin
5d b44a9ce
fix broken AWSDataStorePlugin unit test cases
5d becb5f5
fix OutgoingMutationQueue test case
5d 802d706
remove unused methods
5d 5ad91f7
fix broken test cases of SyncMutationToCloudOperationTests
5d 1a20c33
Merge remote-tracking branch 'origin/main' into 5d/api-behavior
5d acbb4e8
fix broken unit test cases of API and DataStore
5d 1265d42
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 3983918
Merge branch 'flutter-datastore-v2' into 5d/sdk-core
5d cd1c885
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 3110657
resolve plugins build issues (#3654)
5d 12445f4
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 678941c
remove lock from SyncMutationToCloudOperation
5d 0868a9f
remove test case of retryable for signOut error
5d eefd597
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 9df1524
resolve comments
5d 7415441
fix(datastore): propagate remote mutationEvents to Hub for sync recei…
5d 75b9a45
rename the package to InternalAmplifyCredentials
5d 472f89c
rewrite NondeterminsticOperation constructor with makeStream
5d cb938c7
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d a6b1684
resolve broken test case after merging latest orgin/main
5d cf7fe31
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 7e5883a
feat(amplify): make GraphQLOperationType extends from String (#3719)
5d 82f9ec5
refactor(datastore): new enum to represent inferred and designated au…
5d 3ee1924
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d c0ba0ae
fix(datastore): use error description to produce clearer error info (…
5d 1de810e
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d 4ce4aa7
Merge remote-tracking branch 'origin/main' into flutter-datastore-v2
5d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
Amplify/Categories/API/Operation/NondeterminsticOperation.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
|
||
import Combine | ||
/** | ||
A non-deterministic operation offers multiple paths to accomplish its task. | ||
It attempts the next path if all preceding paths have failed with an error that allows for continuation. | ||
*/ | ||
enum NondeterminsticOperationError: Error { | ||
case totalFailure | ||
case cancelled | ||
} | ||
|
||
final class NondeterminsticOperation<T> { | ||
/// operation that to be eval | ||
typealias Operation = () async throws -> T | ||
typealias OnError = (Error) -> Bool | ||
|
||
private let operations: AsyncStream<Operation> | ||
private var shouldTryNextOnError: OnError = { _ in true } | ||
private var cancellables = Set<AnyCancellable>() | ||
private var task: Task<Void, Never>? | ||
|
||
deinit { | ||
cancel() | ||
} | ||
|
||
init(operations: AsyncStream<Operation>, shouldTryNextOnError: OnError? = nil) { | ||
self.operations = operations | ||
if let shouldTryNextOnError { | ||
self.shouldTryNextOnError = shouldTryNextOnError | ||
} | ||
} | ||
|
||
convenience init( | ||
operationStream: AnyPublisher<Operation, Never>, | ||
shouldTryNextOnError: OnError? = nil | ||
) { | ||
var cancellables = Set<AnyCancellable>() | ||
let (asyncStream, continuation) = AsyncStream.makeStream(of: Operation.self) | ||
operationStream.sink { _ in | ||
continuation.finish() | ||
} receiveValue: { | ||
continuation.yield($0) | ||
}.store(in: &cancellables) | ||
|
||
self.init( | ||
operations: asyncStream, | ||
shouldTryNextOnError: shouldTryNextOnError | ||
) | ||
self.cancellables = cancellables | ||
} | ||
|
||
/// Synchronous version of executing the operations | ||
func execute() -> Future<T, Error> { | ||
Future { [weak self] promise in | ||
self?.task = Task { [weak self] in | ||
do { | ||
if let self { | ||
promise(.success(try await self.run())) | ||
} else { | ||
promise(.failure(NondeterminsticOperationError.cancelled)) | ||
} | ||
} catch { | ||
promise(.failure(error)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// Asynchronous version of executing the operations | ||
func run() async throws -> T { | ||
for await operation in operations { | ||
if Task.isCancelled { | ||
throw NondeterminsticOperationError.cancelled | ||
} | ||
do { | ||
return try await operation() | ||
} catch { | ||
if shouldTryNextOnError(error) { | ||
continue | ||
} else { | ||
throw error | ||
} | ||
} | ||
} | ||
throw NondeterminsticOperationError.totalFailure | ||
} | ||
lawmicha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// Cancel the operation | ||
func cancel() { | ||
task?.cancel() | ||
cancellables = Set<AnyCancellable>() | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.