Skip to content

Commit 3bdc4b7

Browse files
authored
Revert "feat(DataStore): observe query API (#1389)" (#1421)
This reverts commit 1c19d2a.
1 parent 1c19d2a commit 3bdc4b7

20 files changed

+16
-1878
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
210DBC142332B3C6009B9E51 /* StorageGetURLOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210DBC132332B3C6009B9E51 /* StorageGetURLOperation.swift */; };
1717
210DBC162332B3CB009B9E51 /* StorageDownloadDataOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210DBC152332B3CB009B9E51 /* StorageDownloadDataOperation.swift */; };
1818
210DBC472332F0C5009B9E51 /* StorageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 210DBC462332F0C5009B9E51 /* StorageError.swift */; };
19-
211FFEE326CD650500F0DB75 /* DataStoreQuerySnapshot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211FFEE226CD650500F0DB75 /* DataStoreQuerySnapshot.swift */; };
2019
2125E2542319EC3100B3DEB5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2125E2532319EC3100B3DEB5 /* AppDelegate.swift */; };
2120
2125E2562319EC3100B3DEB5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2125E2552319EC3100B3DEB5 /* ViewController.swift */; };
2221
2125E2592319EC3100B3DEB5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2125E2572319EC3100B3DEB5 /* Main.storyboard */; };
@@ -160,8 +159,6 @@
160159
21A905372616446F00EC141D /* EnumTestModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A9052A2616446F00EC141D /* EnumTestModel.swift */; };
161160
21A905382616446F00EC141D /* TestEnum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A9052B2616446F00EC141D /* TestEnum.swift */; };
162161
21A905602616484A00EC141D /* Scalar+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21A9055F2616484A00EC141D /* Scalar+Equatable.swift */; };
163-
21AAE24026DFE94B007BA909 /* ModelSyncMetadata+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AAE23E26DFE94B007BA909 /* ModelSyncMetadata+Schema.swift */; };
164-
21AAE24126DFE94B007BA909 /* ModelSyncMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21AAE23F26DFE94B007BA909 /* ModelSyncMetadata.swift */; };
165162
21AD424B249BF0DA0016FE95 /* AnyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FACBAD522386160100E29E56 /* AnyModel.swift */; };
166163
21AD424C249BF0DE0016FE95 /* AnyModel+Codable.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE776238626D60097E4F1 /* AnyModel+Codable.swift */; };
167164
21AD424D249BF0E50016FE95 /* AnyModel+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8EE78223862DDB0097E4F1 /* AnyModel+Schema.swift */; };
@@ -848,7 +845,6 @@
848845
210DBC132332B3C6009B9E51 /* StorageGetURLOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageGetURLOperation.swift; sourceTree = "<group>"; };
849846
210DBC152332B3CB009B9E51 /* StorageDownloadDataOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageDownloadDataOperation.swift; sourceTree = "<group>"; };
850847
210DBC462332F0C5009B9E51 /* StorageError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageError.swift; sourceTree = "<group>"; };
851-
211FFEE226CD650500F0DB75 /* DataStoreQuerySnapshot.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStoreQuerySnapshot.swift; sourceTree = "<group>"; };
852848
2125E2102318D73B00B3DEB5 /* awsconfiguration.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = awsconfiguration.json; sourceTree = "<group>"; };
853849
2125E2512319EC3000B3DEB5 /* AmplifyTestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AmplifyTestApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
854850
2125E2532319EC3100B3DEB5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -1003,8 +999,6 @@
1003999
21A9052A2616446F00EC141D /* EnumTestModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EnumTestModel.swift; sourceTree = "<group>"; };
10041000
21A9052B2616446F00EC141D /* TestEnum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestEnum.swift; sourceTree = "<group>"; };
10051001
21A9055F2616484A00EC141D /* Scalar+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Scalar+Equatable.swift"; sourceTree = "<group>"; };
1006-
21AAE23E26DFE94B007BA909 /* ModelSyncMetadata+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ModelSyncMetadata+Schema.swift"; sourceTree = "<group>"; };
1007-
21AAE23F26DFE94B007BA909 /* ModelSyncMetadata.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelSyncMetadata.swift; sourceTree = "<group>"; };
10081002
21AD4255249BFFDF0016FE95 /* DeprecatedTodo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeprecatedTodo.swift; path = Deprecated/DeprecatedTodo.swift; sourceTree = "<group>"; };
10091003
21C395B2245729EC00597EA2 /* AppSyncErrorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSyncErrorType.swift; sourceTree = "<group>"; };
10101004
21D79FD9237617C60057D00D /* SubscriptionEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionEvent.swift; sourceTree = "<group>"; };
@@ -1937,7 +1931,6 @@
19371931
2129BE3F23948909006363A1 /* Sync */ = {
19381932
isa = PBXGroup;
19391933
children = (
1940-
21AAE23D26DFE94B007BA909 /* ModelSync */,
19411934
2129BE4023948912006363A1 /* MutationSync */,
19421935
2129BE542395CAEF006363A1 /* PaginatedList.swift */,
19431936
);
@@ -2183,15 +2176,6 @@
21832176
path = Scalar;
21842177
sourceTree = "<group>";
21852178
};
2186-
21AAE23D26DFE94B007BA909 /* ModelSync */ = {
2187-
isa = PBXGroup;
2188-
children = (
2189-
21AAE23E26DFE94B007BA909 /* ModelSyncMetadata+Schema.swift */,
2190-
21AAE23F26DFE94B007BA909 /* ModelSyncMetadata.swift */,
2191-
);
2192-
path = ModelSync;
2193-
sourceTree = "<group>";
2194-
};
21952179
21AD424A249BEC440016FE95 /* Internal */ = {
21962180
isa = PBXGroup;
21972181
children = (
@@ -3868,7 +3852,6 @@
38683852
isa = PBXGroup;
38693853
children = (
38703854
FAD393702381FD3C00463F5E /* DataStoreCategory+Subscribe.swift */,
3871-
211FFEE226CD650500F0DB75 /* DataStoreQuerySnapshot.swift */,
38723855
FA9FD2332381CD0000A7CAF5 /* MutationEvent.swift */,
38733856
FA8F4D232395B1B600861D91 /* MutationEvent+Model.swift */,
38743857
FACBAD4F2386101100E29E56 /* MutationEvent+MutationType.swift */,
@@ -4771,7 +4754,6 @@
47714754
files = (
47724755
2129BE4423948951006363A1 /* MutationSyncMetadata.swift in Sources */,
47734756
B9675A2E24752621002FC843 /* GraphQLRequest+Model.swift in Sources */,
4774-
21AAE24026DFE94B007BA909 /* ModelSyncMetadata+Schema.swift in Sources */,
47754757
2129BE1E2394806B006363A1 /* QueryPredicate+GraphQL.swift in Sources */,
47764758
21420A8F237222A900FA140C /* AWSIAMConfiguration.swift in Sources */,
47774759
219A888523EB897700BBC5F2 /* GraphQLRequest+AnyModelWithSync.swift in Sources */,
@@ -4805,7 +4787,6 @@
48054787
7608EE14268142F300FEC9CD /* AWSPluginOptions.swift in Sources */,
48064788
6BBECD7123ADA7E100C8DFBE /* AmplifyAWSServiceConfiguration.swift in Sources */,
48074789
21AD424F249BF0EC0016FE95 /* Model+AnyModel.swift in Sources */,
4808-
21AAE24126DFE94B007BA909 /* ModelSyncMetadata.swift in Sources */,
48094790
B4EBEB682462050B00D06375 /* AuthCognitoIdentityProvider.swift in Sources */,
48104791
21AD424C249BF0DE0016FE95 /* AnyModel+Codable.swift in Sources */,
48114792
212CE6FE23E9E5A2007D8E71 /* GraphQLDocumentnputValue.swift in Sources */,
@@ -5256,7 +5237,6 @@
52565237
B4251A0124250369007F59EF /* AuthConfirmResetPasswordRequest.swift in Sources */,
52575238
FAAFAF2F23904B14002CF932 /* AtomicValue+Bool.swift in Sources */,
52585239
B9B50DC823DA15890086F1E1 /* DataStoreError+Temporal.swift in Sources */,
5259-
211FFEE326CD650500F0DB75 /* DataStoreQuerySnapshot.swift in Sources */,
52605240
FA249EEB24C5FE66009B3CE8 /* AmplifyAPICategory+GraphQLBehavior+Combine.swift in Sources */,
52615241
FACD26502386E9410068FBE6 /* JSONValue+Subscript.swift in Sources */,
52625242
B450741324115C260098F02D /* AuthSignInRequest.swift in Sources */,

Amplify/Categories/DataStore/DataStoreCategoryBehavior.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,4 @@ public protocol DataStoreSubscribeBehavior {
6565
/// - Parameter modelType: The model type to observe
6666
@available(iOS 13.0, *)
6767
func publisher<M: Model>(for modelType: M.Type) -> AnyPublisher<MutationEvent, DataStoreError>
68-
69-
/// Returns a Publisher for query snapshots.
70-
///
71-
/// - Parameters:
72-
/// - modelType: The model type to observe
73-
/// - predicate: The predicate to match for filtered results
74-
/// - sortInput: The field and order of data to be returned
75-
@available(iOS 13.0, *)
76-
func observeQuery<M: Model>(for modelType: M.Type,
77-
where predicate: QueryPredicate?,
78-
sort sortInput: QuerySortInput?)
79-
-> AnyPublisher<DataStoreQuerySnapshot<M>, DataStoreError>
8068
}

Amplify/Categories/DataStore/Subscribe/DataStoreCategory+Subscribe.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,4 @@ extension DataStoreCategory: DataStoreSubscribeBehavior {
1212
public func publisher<M: Model>(for modelType: M.Type) -> AnyPublisher<MutationEvent, DataStoreError> {
1313
return plugin.publisher(for: modelType)
1414
}
15-
16-
@available(iOS 13.0, *)
17-
public func observeQuery<M: Model>(for modelType: M.Type,
18-
where predicate: QueryPredicate? = nil,
19-
sort sortInput: QuerySortInput? = nil)
20-
-> AnyPublisher<DataStoreQuerySnapshot<M>, DataStoreError> {
21-
return plugin.observeQuery(for: modelType, where: predicate, sort: sortInput)
22-
}
2315
}

Amplify/Categories/DataStore/Subscribe/DataStoreQuerySnapshot.swift

Lines changed: 0 additions & 28 deletions
This file was deleted.

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/AWSDataStorePlugin+DataStoreBaseBehavior.swift

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,10 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
174174
}
175175

176176
public func start(completion: @escaping DataStoreCallback<Void>) {
177-
reinitStorageEngineIfNeeded { result in
178-
completion(result)
179-
}
177+
reinitStorageEngineIfNeeded(completion: completion)
180178
}
181179

182180
public func stop(completion: @escaping DataStoreCallback<Void>) {
183-
operationQueue.operations.forEach { operation in
184-
if let operation = operation as? DataStoreObserveQueryOperation {
185-
operation.resetState()
186-
}
187-
}
188181
storageEngineInitSemaphore.wait()
189182
if storageEngine == nil {
190183
storageEngineInitSemaphore.signal()
@@ -199,11 +192,6 @@ extension AWSDataStorePlugin: DataStoreBaseBehavior {
199192
}
200193

201194
public func clear(completion: @escaping DataStoreCallback<Void>) {
202-
operationQueue.operations.forEach { operation in
203-
if let operation = operation as? DataStoreObserveQueryOperation {
204-
operation.resetState()
205-
}
206-
}
207195
storageEngineInitSemaphore.wait()
208196
if storageEngine == nil {
209197
storageEngineInitSemaphore.signal()

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/AWSDataStorePlugin+DataStoreSubscribeBehavior.swift

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,4 @@ extension AWSDataStorePlugin: DataStoreSubscribeBehavior {
2727
public func publisher(for modelName: ModelName) -> AnyPublisher<MutationEvent, DataStoreError> {
2828
return publisher.filter { $0.modelName == modelName }.eraseToAnyPublisher()
2929
}
30-
31-
@available(iOS 13.0, *)
32-
public func observeQuery<M: Model>(for modelType: M.Type,
33-
where predicate: QueryPredicate? = nil,
34-
sort sortInput: QuerySortInput? = nil)
35-
-> AnyPublisher<DataStoreQuerySnapshot<M>, DataStoreError> {
36-
return observeQuery(for: modelType,
37-
modelSchema: modelType.schema,
38-
where: predicate,
39-
sort: sortInput?.asSortDescriptors())
40-
}
41-
42-
@available(iOS 13.0, *)
43-
public func observeQuery<M: Model>(for modelType: M.Type,
44-
modelSchema: ModelSchema,
45-
where predicate: QueryPredicate? = nil,
46-
sort sortInput: [QuerySortDescriptor]? = nil)
47-
-> AnyPublisher<DataStoreQuerySnapshot<M>, DataStoreError> {
48-
reinitStorageEngineIfNeeded()
49-
50-
guard let dataStorePublisher = dataStorePublisher else {
51-
return Fail(error: DataStoreError.unknown(
52-
"`dataStorePublisher` is expected to exist for deployment targets >=iOS13.0",
53-
"", nil)).eraseToAnyPublisher()
54-
}
55-
let operation = AWSDataStoreObserveQueryOperation(modelType: modelType,
56-
modelSchema: modelSchema,
57-
predicate: predicate,
58-
sortInput: sortInput,
59-
storageEngine: storageEngine,
60-
dataStorePublisher: dataStorePublisher)
61-
operationQueue.addOperation(operation)
62-
return operation.publisher
63-
}
6430
}

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/AWSDataStorePlugin.swift

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
1717
/// `true` if any models are syncable. Resolved during configuration phase
1818
var isSyncEnabled: Bool
1919

20-
/// The listener on hub events unsubscribe token
21-
var hubListener: UnsubscribeToken?
22-
2320
/// The Publisher that sends mutation events to subscribers
2421
var dataStorePublisher: ModelSubcriptionBehavior?
2522

@@ -28,10 +25,6 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
2825
/// The DataStore configuration
2926
let dataStoreConfiguration: DataStoreConfiguration
3027

31-
/// A queue that regulates the execution of operations. This will be instantiated during initalization phase,
32-
/// and is clearable by `reset()`. This is implicitly unwrapped to be destroyed when resetting.
33-
var operationQueue: OperationQueue!
34-
3528
let validAPIPluginKey: String
3629

3730
let validAuthPluginKey: String
@@ -60,7 +53,6 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
6053
self.modelRegistration = modelRegistration
6154
self.dataStoreConfiguration = dataStoreConfiguration
6255
self.isSyncEnabled = false
63-
self.operationQueue = OperationQueue()
6456
self.validAPIPluginKey = "awsAPIPlugin"
6557
self.validAuthPluginKey = "awsCognitoAuthPlugin"
6658
self.storageEngineBehaviorFactory =
@@ -78,12 +70,10 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
7870
configuration dataStoreConfiguration: DataStoreConfiguration = .default,
7971
storageEngineBehaviorFactory: StorageEngineBehaviorFactory? = nil,
8072
dataStorePublisher: ModelSubcriptionBehavior,
81-
operationQueue: OperationQueue = OperationQueue(),
8273
validAPIPluginKey: String,
8374
validAuthPluginKey: String) {
8475
self.modelRegistration = modelRegistration
8576
self.dataStoreConfiguration = dataStoreConfiguration
86-
self.operationQueue = operationQueue
8777
self.isSyncEnabled = false
8878
self.storageEngineBehaviorFactory = storageEngineBehaviorFactory ??
8979
StorageEngine.init(isSyncEnabled:dataStoreConfiguration:validAPIPluginKey:validAuthPluginKey:modelRegistryVersion:userDefault:)
@@ -118,15 +108,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
118108
try resolveStorageEngine(dataStoreConfiguration: dataStoreConfiguration)
119109
try storageEngine.setUp(modelSchemas: ModelRegistry.modelSchemas)
120110
storageEngineInitSemaphore.signal()
121-
storageEngine.startSync { result in
122-
123-
self.operationQueue.operations.forEach { operation in
124-
if let operation = operation as? DataStoreObserveQueryOperation {
125-
operation.startObserveQuery()
126-
}
127-
}
128-
completion(result)
129-
}
111+
storageEngine.startSync(completion: completion)
130112
} catch {
131113
storageEngineInitSemaphore.signal()
132114
completion(.failure(causedBy: error))
@@ -192,13 +174,6 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
192174
}
193175

194176
public func reset(onComplete: @escaping (() -> Void)) {
195-
if operationQueue != nil {
196-
operationQueue = nil
197-
}
198-
if let listener = hubListener {
199-
Amplify.Hub.removeListener(listener)
200-
hubListener = nil
201-
}
202177
let group = DispatchGroup()
203178
if let resettable = storageEngine as? Resettable {
204179
log.verbose("Resetting storageEngine")

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/SQLite/QuerySort+SQLite.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ extension QuerySortBy {
2626
return QuerySortOrder.descending
2727
}
2828
}
29-
30-
var sortDescriptor: QuerySortDescriptor {
31-
switch self {
32-
case .ascending(let key):
33-
return .init(fieldName: key.stringValue, order: .ascending)
34-
case .descending(let key):
35-
return .init(fieldName: key.stringValue, order: .descending)
36-
}
37-
}
3829
}
3930

4031
extension QuerySortInput {

0 commit comments

Comments
 (0)