From 0d74edd520417bd549c7cb27dbaf10eec4a5d39a Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 29 May 2024 09:42:48 +0200 Subject: [PATCH] changes for the current user id + minor stuff --- LeStorage/Store.swift | 38 ++++++++++++++------------------ LeStorage/StoredCollection.swift | 7 ++++++ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index 4a54b20..f089de3 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -13,8 +13,9 @@ public enum ResetOption { case synchronizedOnly } -enum StoreError: Error { +public enum StoreError: Error { case missingService + case missingUserId case unexpectedCollectionType(name: String) case apiCallCollectionNotRegistered(type: String) case collectionNotRegistered(type: String) @@ -101,30 +102,21 @@ public class Store { } } - /// Returns the user's UUID - public var currentUserUUID: UUID? { - if let uuidString = self._settingsStorage.item.userId, - let uuid = UUID(uuidString: uuidString) { - return uuid - } - return nil + public var userId: String? { + return self._settingsStorage.item.userId } - /// Returns a UUID, using the user's if possible - public func mandatoryUserUUID() -> UUID { - if let uuid = self.currentUserUUID { - return uuid - } else { - let uuid = UIDevice.current.identifierForVendor ?? UUID() - self._settingsStorage.update { settings in - settings.userId = uuid.uuidString - } - return uuid - } - } + /// Returns the user's UUID +// public var currentUserUUID: UUID? { +// if let uuidString = self._settingsStorage.item.userId, +// let uuid = UUID(uuidString: uuidString) { +// return uuid +// } +// return nil +// } /// Returns the username - func userName() -> String? { + public func userName() -> String? { return self._settingsStorage.item.username } @@ -135,6 +127,10 @@ public class Store { } } + public func token() -> String? { + return try? self.service().keychainStore.getToken() + } + /// Disconnect the user from the storage and resets collection public func disconnect(resetOption: ResetOption? = nil) { try? self.service().disconnect() diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index bc04dfa..31347ab 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -219,6 +219,13 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti } + public func writeChangeAndInsertOnServer(instance: T) throws { + defer { + self._hasChanged = true + } + try self._sendInsertionIfNecessary(instance) + } + /// A method the treat the collection as a single instance holder func setSingletonNoSync(instance: T) { defer {