diff --git a/LeStorage/Services.swift b/LeStorage/Services.swift index 90b6f99..b38cbe3 100644 --- a/LeStorage/Services.swift +++ b/LeStorage/Services.swift @@ -496,22 +496,22 @@ public class Services { return try await self._runRequest(getRequest) } - /// Executes a POST request - - public func post(_ instance: T) async throws -> T { + /// Executes a POST request on the generated DRF services corresponding to T + public func rawPost(_ instance: T) async throws -> T { var postRequest = try self._postRequest(type: T.self) postRequest.httpBody = try JSON.encoder.encode(instance) return try await self._runRequest(postRequest) } - /// Executes a PUT request - public func put(_ instance: T) async throws -> T { + /// Executes a PUT request on the generated DRF services corresponding to T + public func rawPut(_ instance: T) async throws -> T { var postRequest = try self._putRequest(type: T.self, id: instance.stringId) postRequest.httpBody = try JSON.encoder.encode(instance) return try await self._runRequest(postRequest) } - public func delete(_ instance: T) async throws -> T { + /// Executes a DELETE request on the generated DRF services corresponding to T + public func rawDelete(_ instance: T) async throws -> T { let deleteRequest = try self._deleteRequest(type: T.self, id: instance.stringId) return try await self._runRequest(deleteRequest) } diff --git a/LeStorage/StoredSingleton.swift b/LeStorage/StoredSingleton.swift index 2f3435e..459da1c 100644 --- a/LeStorage/StoredSingleton.swift +++ b/LeStorage/StoredSingleton.swift @@ -27,13 +27,12 @@ public class StoredSingleton: SyncedCollection { return self.items.first } - public func tryPutBeforeUpdating(_ instance: T) async throws { - if let result = try await StoreCenter.main.service().put(instance) { - self.setItemNoSync(result) - } + @discardableResult public func tryPutBeforeUpdating(_ instance: T) async throws -> T? { + let result = try await StoreCenter.main.service().rawPut(instance) + self.setItemNoSync(result) + return result } - // MARK: - Protects from use public override func addOrUpdate(contentOfs sequence: any Sequence) { diff --git a/LeStorage/SyncedStorable.swift b/LeStorage/SyncedStorable.swift index 8c98f2e..53094be 100644 --- a/LeStorage/SyncedStorable.swift +++ b/LeStorage/SyncedStorable.swift @@ -30,7 +30,7 @@ public protocol SideStorable { var storeId: String? { get set } } -extension SyncedStorable { +public extension SyncedStorable { func copy() -> Self { let copy = Self()