|
|
|
@ -80,37 +80,8 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Basic operations |
|
|
|
// MARK: - Basic operations with sync |
|
|
|
|
|
|
|
|
|
|
|
/// Adds or update an instance without synchronizing it |
|
|
|
|
|
|
|
func addOrUpdateNoSync(_ instance: T) throws { |
|
|
|
|
|
|
|
self.addOrUpdateItem(instance: instance) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds or update a sequence of elements without synchronizing it |
|
|
|
|
|
|
|
func addOrUpdateNoSync(contentOfs sequence: any Sequence<T>) { |
|
|
|
|
|
|
|
self.addSequence(sequence) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Deletes the instance in the collection without synchronization |
|
|
|
|
|
|
|
func deleteNoSync(instance: T) throws { |
|
|
|
|
|
|
|
defer { |
|
|
|
|
|
|
|
self.setChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self.deleteItem(instance) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Deletes the instance in the collection without synchronization |
|
|
|
|
|
|
|
func deleteByStringIdNoSync(_ id: String) { |
|
|
|
|
|
|
|
defer { |
|
|
|
|
|
|
|
self.setChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let realId = T.buildRealId(id: id) |
|
|
|
|
|
|
|
if let instance = self.findById(realId) { |
|
|
|
|
|
|
|
self.deleteItem(instance) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds or update an instance and writes |
|
|
|
/// Adds or update an instance and writes |
|
|
|
public func addOrUpdate(instance: T) { |
|
|
|
public func addOrUpdate(instance: T) { |
|
|
|
// Logger.log("\(T.resourceName()) : one item") |
|
|
|
// Logger.log("\(T.resourceName()) : one item") |
|
|
|
@ -201,6 +172,37 @@ extension StoredCollection: SomeSyncedCollection where T : SyncedStorable { |
|
|
|
delete(contentOfs: items) // MUST NOT ADD "self" before delete, otherwise it will call the delete method of StoredCollection without sync |
|
|
|
delete(contentOfs: items) // MUST NOT ADD "self" before delete, otherwise it will call the delete method of StoredCollection without sync |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Basic operations without sync |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds or update an instance without synchronizing it |
|
|
|
|
|
|
|
func addOrUpdateNoSync(_ instance: T) throws { |
|
|
|
|
|
|
|
self.addOrUpdateItem(instance: instance) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Adds or update a sequence of elements without synchronizing it |
|
|
|
|
|
|
|
func addOrUpdateNoSync(contentOfs sequence: any Sequence<T>) { |
|
|
|
|
|
|
|
self.addSequence(sequence) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Deletes the instance in the collection without synchronization |
|
|
|
|
|
|
|
func deleteNoSync(instance: T) throws { |
|
|
|
|
|
|
|
defer { |
|
|
|
|
|
|
|
self.setChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self.deleteItem(instance) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Deletes the instance in the collection without synchronization |
|
|
|
|
|
|
|
func deleteByStringIdNoSync(_ id: String) { |
|
|
|
|
|
|
|
defer { |
|
|
|
|
|
|
|
self.setChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let realId = T.buildRealId(id: id) |
|
|
|
|
|
|
|
if let instance = self.findById(realId) { |
|
|
|
|
|
|
|
self.deleteItem(instance) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Send requests |
|
|
|
// MARK: - Send requests |
|
|
|
|
|
|
|
|
|
|
|
fileprivate func _sendInsertion(_ instance: T) { |
|
|
|
fileprivate func _sendInsertion(_ instance: T) { |
|
|
|
|