Skip to content

Commit

Permalink
update rules
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 14, 2024
1 parent 86dd2d7 commit 26270a9
Show file tree
Hide file tree
Showing 34 changed files with 212 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Amplify
import Foundation

extension MutationSyncMetadataMigration {
public extension MutationSyncMetadataMigration {
struct MutationSyncMetadataCopy: Model {
public let id: String
public var deleted: Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ extension [ModelSchema] {
func walkAssociatedModels(of schema: ModelSchema) {
if !sortedKeys.contains(schema.name) {
let associatedModelSchemas = schema.sortedFields
.filter(\.isForeignKey)
.filter { $0.isForeignKey }
.map { schema -> ModelSchema in
guard let associatedSchema = ModelRegistry.modelSchema(from: schema.requiredAssociatedModelName)
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ extension ModelSchema {
.sortComparator(sortOrder: sortOrder)
case .dateTime:
guard let value1Optional = value1 as? Temporal.DateTime?,
let value2Optional = value2 as? Temporal.DateTime?
else {
let value2Optional = value2 as? Temporal.DateTime? else {
return false
}
return ModelValueCompare(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ final class InitialSyncOperation: AsynchronousOperation {

private var syncPredicateString: String? {
guard let syncPredicate,
let data = try? syncPredicateEncoder.encode(syncPredicate)
else {
let data = try? syncPredicateEncoder.encode(syncPredicate) else {
return nil
}
return String(data: data, encoding: .utf8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class RemoteSyncEngine: RemoteSyncEngineBehavior {
storageAdapter: StorageEngineAdapter
) async {
log.debug("[InitializeSubscription] \(#function)")
let syncableModelSchemas = ModelRegistry.modelSchemas.filter(\.isSyncable)
let syncableModelSchemas = ModelRegistry.modelSchemas.filter { $0.isSyncable }
reconciliationQueue = await reconciliationQueueFactory(
syncableModelSchemas,
api,
Expand Down Expand Up @@ -464,8 +464,7 @@ extension RemoteSyncEngine: Resettable {
for child in mirror.children {
let label = child.label ?? "some RemoteSyncEngine child"
guard label != "api",
label != "auth"
else {
label != "auth" else {
log.verbose("Not resetting \(label) from RemoteSyncEngine")
continue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,12 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
authType: AWSAuthorizationType?,
awsAuthService: AWSAuthServiceBehavior
) async -> GraphQLRequest<Payload> {
let request = if modelSchema.hasAuthenticationRules,
let request: GraphQLRequest<Payload>
if modelSchema.hasAuthenticationRules,
let _ = auth,
let tokenString = try? await awsAuthService.getUserPoolAccessToken(),
case .success(let claims) = awsAuthService.getTokenClaims(tokenString: tokenString) {
GraphQLRequest<Payload>.subscription(
request = GraphQLRequest<Payload>.subscription(
to: modelSchema,
subscriptionType: subscriptionType,
claims: claims,
Expand All @@ -230,14 +231,14 @@ final class IncomingAsyncSubscriptionEventPublisher: AmplifyCancellable {
let oidcAuthProvider = hasOIDCAuthProviderAvailable(api: api),
let tokenString = try? await oidcAuthProvider.getLatestAuthToken(),
case .success(let claims) = awsAuthService.getTokenClaims(tokenString: tokenString) {
GraphQLRequest<Payload>.subscription(
request = GraphQLRequest<Payload>.subscription(
to: modelSchema,
subscriptionType: subscriptionType,
claims: claims,
authType: authType
)
} else {
GraphQLRequest<Payload>.subscription(
request = GraphQLRequest<Payload>.subscription(
to: modelSchema,
subscriptionType: subscriptionType,
authType: authType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ final class AWSModelReconciliationQueue: ModelReconciliationQueue {
incomingSubscriptionEventQueue.underlyingQueue = DispatchQueue.global()
incomingSubscriptionEventQueue.isSuspended = true

let resolvedIncomingSubscriptionEvents: IncomingSubscriptionEventPublisher = if let incomingSubscriptionEvents {
incomingSubscriptionEvents
let resolvedIncomingSubscriptionEvents: IncomingSubscriptionEventPublisher
if let incomingSubscriptionEvents {
resolvedIncomingSubscriptionEvents = incomingSubscriptionEvents
} else {
await AWSIncomingSubscriptionEventPublisher(
resolvedIncomingSubscriptionEvents = await AWSIncomingSubscriptionEventPublisher(
modelSchema: modelSchema,
api: api,
modelPredicate: modelPredicate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation {

do {
let localMetadatas = try storageAdapter.queryMutationSyncMetadata(
for: remoteModels.map(\.model.identifier),
for: remoteModels.map { $0.model.identifier },
modelName: self.modelSchema.name
)
result = .success((remoteModels, localMetadatas))
Expand Down Expand Up @@ -305,11 +305,12 @@ class ReconcileAndLocalSaveOperation: AsynchronousOperation {
storageAdapter: StorageEngineAdapter,
disposition: RemoteSyncReconciler.Disposition
) -> AnyPublisher<Result<Void, DataStoreError>, Never> {
let operation: Future<ApplyRemoteModelResult, DataStoreError> = switch disposition {
let operation: Future<ApplyRemoteModelResult, DataStoreError>
switch disposition {
case .create, .update:
save(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel)
operation = save(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel)
case .delete:
delete(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel)
operation = delete(storageAdapter: storageAdapter, remoteModel: disposition.remoteModel)
}

return operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,23 @@ extension ModelSchema {
}
case .date:
guard let value1Optional = value1 as? Temporal.Date?,
let value2Optional = value2 as? Temporal.Date?
else {
let value2Optional = value2 as? Temporal.Date? else {
return false
}
if !compare(value1Optional, value2Optional) {
return false
}
case .dateTime:
guard let value1Optional = value1 as? Temporal.DateTime?,
let value2Optional = value2 as? Temporal.DateTime?
else {
let value2Optional = value2 as? Temporal.DateTime? else {
return false
}
if !compare(value1Optional, value2Optional) {
return false
}
case .time:
guard let value1Optional = value1 as? Temporal.Time?,
let value2Optional = value2 as? Temporal.Time?
else {
let value2Optional = value2 as? Temporal.Time? else {
return false
}
if !compare(value1Optional, value2Optional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ extension MutationEvent {
pendingMutationEvent: existingEvent,
with: mutationEvent,
responseMutationSync: mutationSync
)
else {
) else {
completion(.success(()))
return
}
Expand Down Expand Up @@ -95,8 +94,7 @@ extension MutationEvent {
// check if the data sent in the request is the same as the response
// if it is, update the pending mutation event version to the response version
guard let modelSchema = ModelRegistry.modelSchema(from: requestMutationEvent.modelName),
modelSchema.compare(responseModel, requestModel)
else {
modelSchema.compare(responseModel, requestModel) else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AWSDataStoreLocalStoreTests: LocalStoreIntegrationTestBase {
XCTAssertEqual(queriedPosts2.count, 5)
posts.append(contentsOf: queriedPosts2)

let idSet = Set(posts.map(\.id))
let idSet = Set(posts.map { $0.id })
XCTAssertEqual(idSet.count, 15)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ class SQLiteMutationSyncMetadataMigrationDelegateTests: MutationSyncMetadataMigr
guard let restaurantMetadata = try storageAdapter.queryMutationSyncMetadata(
for: restaurant.id,
modelName: Restaurant.modelName
)
else {
) else {
XCTFail("Could not get metadata")
return
}
Expand Down
Loading

0 comments on commit 26270a9

Please sign in to comment.