Adds methods to see the content of api calls files

multistore
Laurent 1 year ago
parent 51c9169621
commit 69b6fc688d
  1. 8
      LeStorage/Store.swift
  2. 15
      LeStorage/StoredCollection.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() ?? ""
}
}

@ -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<T: Storable>: RandomAccessCollection, SomeCollecti
self._load()
}
var resourceName: String {
return T.resourceName()
}
// MARK: - Paths
fileprivate func _storageDirectoryPath() throws -> URL {
@ -561,6 +566,14 @@ public class StoredCollection<T: Storable>: 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 }

Loading…
Cancel
Save