diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index fbe9861..4a54b20 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -260,5 +260,13 @@ public class Store { public func hasPendingAPICalls() -> Bool { return self._collections.values.contains(where: { $0.hasPendingAPICalls() }) } + + public func collectionNames() -> [String] { + return self._collections.values.map { $0.resourceName } + } + + public func apiCallsFile(resourceName: String) -> String { + return self._collections[resourceName]?.contentOfApiCallFile() ?? "" + } } diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index ef22bcd..bc04dfa 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -21,9 +21,10 @@ protocol SomeCollection: Identifiable { func loadDataFromServerIfAllowed() async throws var synchronized: Bool { get } func hasPendingAPICalls() -> Bool + var resourceName: String { get } + func contentOfApiCallFile() -> String? } - extension Notification.Name { public static let CollectionDidLoad: Notification.Name = Notification.Name.init("notification.collectionDidLoad") public static let CollectionDidChange: Notification.Name = Notification.Name.init("notification.collectionDidChange") @@ -95,6 +96,10 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti self._load() } + var resourceName: String { + return T.resourceName() + } + // MARK: - Paths fileprivate func _storageDirectoryPath() throws -> URL { @@ -561,6 +566,14 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti return apiCallsCollection.isNotEmpty } + func contentOfApiCallFile() -> String? { + guard let fileURL = try? self.apiCallsCollection?._urlForJSONFile() else { return nil } + if FileManager.default.fileExists(atPath: fileURL.path()) { + return try? FileUtils.readFile(fileURL: fileURL) + } + return nil + } + // MARK: - RandomAccessCollection public var startIndex: Int { return self.items.startIndex }