|
|
|
|
@ -294,7 +294,24 @@ public class StoreCenter { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func resetLoggingCollections() { |
|
|
|
|
|
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
try FileManager.default.removeItem(at: Log.urlForJSONFile()) |
|
|
|
|
try FileManager.default.removeItem(at: FailedAPICall.urlForJSONFile()) |
|
|
|
|
|
|
|
|
|
let facApiCallCollection: ApiCallCollection<FailedAPICall> = try self.apiCallCollection() |
|
|
|
|
await facApiCallCollection.reset() |
|
|
|
|
let logApiCallCollection: ApiCallCollection<Log> = try self.apiCallCollection() |
|
|
|
|
await logApiCallCollection.reset() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Resets the ApiCall whose type identifies with the provided collection |
|
|
|
|
/// - Parameters: |
|
|
|
|
/// - collection: The collection identifying the Storable type |
|
|
|
|
@ -699,7 +716,7 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
/// This method triggers the framework to save and send failed api calls |
|
|
|
|
public func logsFailedAPICalls() { |
|
|
|
|
self._failedAPICallsCollection = Store.main.registerCollection() |
|
|
|
|
self._failedAPICallsCollection = Store.main.registerCollection(limit: 50) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// If configured for, logs and send to the server a failed API call |
|
|
|
|
@ -823,27 +840,6 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
// MARK: - Data Access |
|
|
|
|
|
|
|
|
|
// public func giveUserAccess<T: SyncedStorable>(_ user: String, data: T) throws { |
|
|
|
|
// guard let dataAccessCollection = self._dataAccess else { |
|
|
|
|
// throw LeStorageError.dataAccessCollectionNotDefined |
|
|
|
|
// } |
|
|
|
|
// guard let userId = self.userId else { |
|
|
|
|
// throw LeStorageError.cantCreateDataAccessBecauseUserIdIsNil |
|
|
|
|
// } |
|
|
|
|
// let collection: StoredCollection<T> = try Store.main.collection() |
|
|
|
|
// guard collection.findById(data.id) != nil else { |
|
|
|
|
// throw LeStorageError.cantCreateDataAccessBecauseNotInMainStore |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// if let dataAccess = dataAccessCollection.first(where: { $0.modelId == data.stringId }) { |
|
|
|
|
// dataAccess.sharedWith.append(user) |
|
|
|
|
// dataAccessCollection.addOrUpdate(instance: dataAccess) |
|
|
|
|
// } else { |
|
|
|
|
// let dataAccess = DataAccess(owner: userId, sharedWith: [user], modelName: String(describing: type(of: data)), modelId: data.stringId) |
|
|
|
|
// dataAccessCollection.addOrUpdate(instance: dataAccess) |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
public func authorizedUsers(for modelId: String) -> [String] { |
|
|
|
|
guard let dataAccessCollection = self._dataAccess else { |
|
|
|
|
return [] |
|
|
|
|
@ -882,7 +878,7 @@ public class StoreCenter { |
|
|
|
|
if let logs = self._logs { |
|
|
|
|
return logs |
|
|
|
|
} else { |
|
|
|
|
let logsCollection: StoredCollection<Log> = Store.main.registerCollection() |
|
|
|
|
let logsCollection: StoredCollection<Log> = Store.main.registerCollection(limit: 1000) |
|
|
|
|
self._logs = logsCollection |
|
|
|
|
return logsCollection |
|
|
|
|
} |
|
|
|
|
@ -890,8 +886,10 @@ public class StoreCenter { |
|
|
|
|
|
|
|
|
|
/// Logs a message in the logs collection |
|
|
|
|
public func log(message: String) { |
|
|
|
|
let log = Log(message: message) |
|
|
|
|
self._logsCollection().addOrUpdate(instance: log) |
|
|
|
|
DispatchQueue.main.async { |
|
|
|
|
let log = Log(message: message) |
|
|
|
|
self._logsCollection().addOrUpdate(instance: log) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MARK: - Migration |
|
|
|
|
|