Fixed import from dev

multistore
Laurent 1 year ago
parent 000b794573
commit b69e2269a2
  1. 18
      LeStorage/ApiCallCollection.swift
  2. 2
      LeStorage/Services.swift
  3. 5
      LeStorage/Store.swift
  4. 4
      LeStorage/StoredCollection.swift

@ -34,6 +34,8 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection {
/// Indicates if the collection is currently retrying ApiCalls /// Indicates if the collection is currently retrying ApiCalls
fileprivate var _isRetryingCalls: Bool = false fileprivate var _isRetryingCalls: Bool = false
fileprivate var _executionTask: Task<Void, any Error>? = nil
/// Indicates whether the collection content has changed /// Indicates whether the collection content has changed
/// Initiates a write when true /// Initiates a write when true
fileprivate var _hasChanged: Bool = false { fileprivate var _hasChanged: Bool = false {
@ -107,17 +109,20 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection {
self._hasChanged = true self._hasChanged = true
} }
} }
func findCallById(_ id: String) async -> (any SomeCall)? {
return self.findById(id)
}
/// Returns the Api call associated with the provided id /// Returns the Api call associated with the provided id
func findById(_ id: String) -> ApiCall<T>? { func findById(_ id: String) -> ApiCall<T>? {
return self.items.first(where: { $0.id == id }) return self.items.first(where: { $0.id == id })
} }
/// Returns the Api call associated with the provided id
func findCallById(_ id: String) async -> (any SomeCall)? {
return self.findById(id)
}
/// Removes all objects in memory and deletes the JSON file /// Removes all objects in memory and deletes the JSON file
func reset() { func reset() {
self._executionTask?.cancel()
self.items.removeAll() self.items.removeAll()
do { do {
@ -140,7 +145,7 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection {
self._isRetryingCalls = true self._isRetryingCalls = true
self._attemptLoops += 1 self._attemptLoops += 1
Task { self._executionTask = Task {
let delay = pow(2, self._attemptLoops) let delay = pow(2, self._attemptLoops)
let seconds = NSDecimalNumber(decimal: delay).intValue let seconds = NSDecimalNumber(decimal: delay).intValue
@ -168,7 +173,6 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection {
} }
} }
} }
// MARK: - Synchronization // MARK: - Synchronization
@ -273,7 +277,7 @@ actor ApiCallCollection<T: Storable>: SomeCallCollection {
default: default:
break break
} }
Logger.log("") // Logger.log("")
} }
/// Returns the content of the API call file as a String /// Returns the content of the API call file as a String

@ -213,7 +213,7 @@ public class Services {
// MARK: - Services // MARK: - Services
/// Executes a GET request /// Executes a GET request
public func get<T: Storable>(identifier: StoreIdentifier?) async throws -> [T] { public func get<T: Storable>(identifier: StoreIdentifier? = nil) async throws -> [T] {
let getRequest = try _getRequest(type: T.self, identifier: identifier) let getRequest = try _getRequest(type: T.self, identifier: identifier)
return try await self._runRequest(getRequest) return try await self._runRequest(getRequest)
} }

@ -26,6 +26,11 @@ public struct StoreIdentifier {
var value: String var value: String
var parameterName: String var parameterName: String
public init(value: String, parameterName: String) {
self.value = value
self.parameterName = parameterName
}
var urlComponent: String { var urlComponent: String {
return "?\(self.parameterName)=\(self.value)" return "?\(self.parameterName)=\(self.value)"
} }

@ -190,7 +190,9 @@ public class StoredCollection<T: Storable>: RandomAccessCollection, SomeCollecti
} }
do { do {
let items: [T] = try await self._store.getItems() let items: [T] = try await self._store.getItems()
try self._addOrUpdate(contentOfs: items, shouldSync: false) if items.count > 0 {
try self._addOrUpdate(contentOfs: items, shouldSync: false)
}
self.hasLoadedFromServer = true self.hasLoadedFromServer = true
DispatchQueue.main.async { DispatchQueue.main.async {
NotificationCenter.default.post(name: NSNotification.Name.CollectionDidLoad, object: self) NotificationCenter.default.post(name: NSNotification.Name.CollectionDidLoad, object: self)

Loading…
Cancel
Save