|
|
|
|
@ -192,22 +192,14 @@ public class StoreCenter { |
|
|
|
|
fileprivate func _requestStore(id: String?) -> Store { |
|
|
|
|
if let storeId = id { |
|
|
|
|
return self._storeLibrary.requestStore(identifier: storeId) |
|
|
|
|
|
|
|
|
|
// if let store = self._stores[storeId] { |
|
|
|
|
// return store |
|
|
|
|
// } else { |
|
|
|
|
// let store = Store(storeCenter: self, identifier: storeId) |
|
|
|
|
// self._registerStore(store: store) |
|
|
|
|
// return store |
|
|
|
|
// } |
|
|
|
|
} else { |
|
|
|
|
return self.mainStore |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _store(id: String?) -> Store { |
|
|
|
|
if let storeId = id, let store = self._storeLibrary[storeId] { |
|
|
|
|
return store |
|
|
|
|
fileprivate func _store(id: String?) -> Store? { |
|
|
|
|
if let storeId = id { |
|
|
|
|
return self._storeLibrary[storeId] |
|
|
|
|
} else { |
|
|
|
|
return self.mainStore |
|
|
|
|
} |
|
|
|
|
@ -714,18 +706,23 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _syncDelete<T : SyncedStorable>(_ deletionArray: ObjectIdentifierArray, type: T.Type) async { |
|
|
|
|
for deletedObject in deletionArray.items { |
|
|
|
|
|
|
|
|
|
let itemsByStore = deletionArray.items.group { $0.storeId } |
|
|
|
|
for (storeId, items) in itemsByStore { |
|
|
|
|
let store = self._requestStore(id: storeId) |
|
|
|
|
let itemsByStore = deletionArray.items.group { $0.storeId } |
|
|
|
|
for (storeId, items) in itemsByStore { |
|
|
|
|
if let store = self._store(id: storeId) { |
|
|
|
|
await store.synchronizationDelete(items, type: T.self) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// await self.synchronizationDelete(id: deletedObject.modelId, type: deletionArray.type, storeId: deletedObject.storeId) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// for deletedObject in deletionArray.items { |
|
|
|
|
// |
|
|
|
|
// let itemsByStore = deletionArray.items.group { $0.storeId } |
|
|
|
|
// for (storeId, items) in itemsByStore { |
|
|
|
|
// let store = self._requestStore(id: storeId) |
|
|
|
|
// await store.synchronizationDelete(items, type: T.self) |
|
|
|
|
// } |
|
|
|
|
//// await self.synchronizationDelete(id: deletedObject.modelId, type: deletionArray.type, storeId: deletedObject.storeId) |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -761,7 +758,7 @@ public class StoreCenter { |
|
|
|
|
let itemsByStore = revokeArray.items.group { $0.storeId } |
|
|
|
|
for (storeId, items) in itemsByStore { |
|
|
|
|
let store = self._requestStore(id: storeId) |
|
|
|
|
await store.synchronizationRevoke(items, type: revokeArray.type) |
|
|
|
|
store.synchronizationRevoke(items, type: revokeArray.type) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// for revoked in revokeArray.items { |
|
|
|
|
@ -827,10 +824,10 @@ public class StoreCenter { |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
fileprivate func _instance<T: SyncedStorable>(id: String, type: T.Type, storeId: String?) -> T? { |
|
|
|
|
let realId: T.ID = T.buildRealId(id: id) |
|
|
|
|
return self._store(id: storeId).findById(realId) |
|
|
|
|
} |
|
|
|
|
// fileprivate func _instance<T: SyncedStorable>(id: String, type: T.Type, storeId: String?) -> T? { |
|
|
|
|
// let realId: T.ID = T.buildRealId(id: id) |
|
|
|
|
// return self._store(id: storeId).findById(realId) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/// Returns whether an instance has been shared with the user |
|
|
|
|
// fileprivate func _instanceShared<T: SyncedStorable>(id: String, type: T.Type, storeId: String?) -> Bool { |
|
|
|
|
@ -1131,7 +1128,7 @@ public class StoreCenter { |
|
|
|
|
try await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
let dataAccess = DataAccess(owner: userId, sharedWith: users, modelName: String(describing: type(of: instance)), modelId: instance.stringId) |
|
|
|
|
let dataAccess = DataAccess(owner: userId, sharedWith: users, modelName: String(describing: type(of: instance)), modelId: instance.stringId, storeId: instance.getStoreId()) |
|
|
|
|
try await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|