Skip to content

Commit f4b0423

Browse files
authored
Initial sync startup/3-way merge (#238)
- Initial implementation of InitialSyncOrchestrator, integrated with ReconciliationQueue to apply incoming sync query results - Added a buffer queue for incoming remote events to ReconciliationQueue, so remote API sync can be turned off indpendently of applying mutations from sync queries - Made CancelAwareBlockOperation a standalone class - Model extensions - Change ModelSchema+Syncable to ModelSchema+Attributes - Added 'ModelSchema.isSystem' convenience getter - Change 'hasSyncableModels' to look for the existence of any non-system models; all models are considered syncable by default (no local model support at launch) - Added ModelGraphs to track Model connection dependencies for initial sync - Made AtomicValue public so it can be used in plugins; added convenience methods for RangeReplaceableCollection - Removed isSyncable schema attribute in favor of designating all non-system models as syncable; added buffer queue for incoming subscription event submission to reconciliation queue; refactoring & renaming - Added 'DataStore.internalOperation' to contain errors about nil weak references being unavailable - Added convenience DataStoreError constructor for missing reconciliation queue - Use code-generated models in AmplifyTestCommon - Fix some linting warnings - Minor test cleanup - Added responders to MockAPICategoryPlugin to let us invoke callback of methods - Added unit tests for InitialSyncOperation happy path - Convert ModelRegistry.register to take protocol argument rather than concrete type
1 parent 49584d4 commit f4b0423

File tree

108 files changed

+3881
-2237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+3881
-2237
lines changed

Amplify.xcodeproj/project.pbxproj

Lines changed: 52 additions & 60 deletions
Large diffs are not rendered by default.

Amplify/Categories/DataStore/DataStoreCallback.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension DataStoreResult {
2525
}
2626

2727
public static var emptyResult: DataStoreResult<Void> {
28-
.success(())
28+
.successfulVoid
2929
}
3030

3131
}

Amplify/Categories/DataStore/DataStoreError.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public enum DataStoreError: Error {
1414
case configuration(ErrorDescription, RecoverySuggestion, Error? = nil)
1515
case conflict(DataStoreSyncConflict)
1616
case decodingError(ErrorDescription, RecoverySuggestion)
17+
case internalOperation(ErrorDescription, RecoverySuggestion, Error? = nil)
1718
case invalidDatabase(path: String, Error? = nil)
1819
case invalidModelName(String)
1920
case invalidOperation(causedBy: Error? = nil)
@@ -45,6 +46,7 @@ extension DataStoreError: AmplifyError {
4546
"""
4647
case .configuration(let errorDescription, _, _),
4748
.decodingError(let errorDescription, _),
49+
.internalOperation(let errorDescription, _, _),
4850
.sync(let errorDescription, _, _),
4951
.unknown(let errorDescription, _, _):
5052
return errorDescription
@@ -71,6 +73,7 @@ extension DataStoreError: AmplifyError {
7173
"""
7274
case .configuration(_, let recoverySuggestion, _),
7375
.decodingError(_, let recoverySuggestion),
76+
.internalOperation(_, let recoverySuggestion, _),
7477
.sync(_, let recoverySuggestion, _),
7578
.unknown(_, let recoverySuggestion, _):
7679
return recoverySuggestion
@@ -82,6 +85,7 @@ extension DataStoreError: AmplifyError {
8285
case .api(let amplifyError):
8386
return amplifyError
8487
case .configuration(_, _, let underlyingError),
88+
.internalOperation(_, _, let underlyingError),
8589
.invalidDatabase(_, let underlyingError),
8690
.invalidOperation(let underlyingError),
8791
.sync(_, _, let underlyingError),

Amplify/Categories/DataStore/Model/ModelRegistry+Syncable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public extension ModelRegistry {
99
static var hasSyncableModels: Bool {
1010
if #available(iOS 13.0, *) {
11-
return models.contains { $0.schema.isSyncable }
11+
return models.contains { !$0.schema.isSystem }
1212
} else {
1313
return false
1414
}

Amplify/Categories/DataStore/Model/ModelRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public struct ModelRegistry {
2424
}
2525
}
2626

27-
public static func register<M: Model>(modelType: M.Type) {
27+
public static func register(modelType: Model.Type) {
2828
concurrencyQueue.sync {
2929
let modelDecoder: ModelDecoder = { jsonString, jsonDecoder in
3030
let model = try modelType.from(json: jsonString, decoder: jsonDecoder)

Amplify/Categories/DataStore/Model/ModelSchema+Syncable.swift renamed to Amplify/Categories/DataStore/Model/ModelSchema+Attributes.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
/// Convenience getters for attributes
89
public extension ModelSchema {
10+
911
var isSyncable: Bool {
10-
attributes.contains(.isSyncable)
12+
!attributes.contains(.isSystem)
13+
}
14+
15+
var isSystem: Bool {
16+
attributes.contains(.isSystem)
1117
}
18+
1219
}

Amplify/Categories/DataStore/Model/ModelSchema.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public enum ModelAttribute {
2121
/// TODO: What does this mean?
2222
case index
2323

24-
/// Instances of this model are syncable to the remote API via the API category
25-
case isSyncable
26-
2724
/// This model is used by the Amplify system or a plugin, and should not be used by the app developer
2825
case isSystem
2926
}

Amplify/Categories/Predictions/Models/LanguageType.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Foundation
1111
///
1212
/// The associated value represents the iso language code.
1313

14+
// swiftlint:disable file_length
1415
// swiftlint:disable type_body_length
1516
public enum LanguageType: String {
1617
case afar = "aa"
@@ -181,6 +182,7 @@ public enum LanguageType: String {
181182
case friulian = "fur"
182183
case westernFrisian = "fy"
183184
case irish = "ga"
185+
// swiftlint:disable:next identifier_name
184186
case ga = "gaa"
185187
case gagauz = "gag"
186188
case ganChinese = "gan"

Amplify/Categories/Storage/Operation/StorageDownloadDataOperation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import Foundation
99

10-
public protocol StorageDownloadDataOperation: AmplifyOperation<StorageDownloadDataRequest, Progress, Data, StorageError> {}
10+
public protocol StorageDownloadDataOperation: AmplifyOperation<StorageDownloadDataRequest,
11+
Progress, Data, StorageError> {}
1112

1213
public extension HubPayload.EventName.Storage {
1314
/// eventName for HubPayloads emitted by this operation

Amplify/Categories/Storage/Operation/StorageUploadDataOperation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
import Foundation
99

10-
public protocol StorageUploadDataOperation: AmplifyOperation<StorageUploadDataRequest, Progress, String, StorageError> {}
10+
public protocol StorageUploadDataOperation: AmplifyOperation<StorageUploadDataRequest,
11+
Progress, String, StorageError> {}
1112

1213
public extension HubPayload.EventName.Storage {
1314
/// eventName for HubPayloads emitted by this operation

0 commit comments

Comments
 (0)