Ivan Valkou 5 лет назад
Родитель
Сommit
2d54a000ac

+ 4 - 24
FreeAPS.xcodeproj/project.pbxproj

@@ -92,7 +92,7 @@
 		388E5A5C25B6F0770019842D /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388E5A5B25B6F0770019842D /* JSON.swift */; };
 		388E5A6025B6F2310019842D /* Autosens.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388E5A5F25B6F2310019842D /* Autosens.swift */; };
 		3895E4C625B9E00D00214B37 /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3895E4C525B9E00D00214B37 /* Preferences.swift */; };
-		38A13D3225E28B4B00EAA382 /* PumpHystoryEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38A13D3125E28B4B00EAA382 /* PumpHystoryEvent.swift */; };
+		38A13D3225E28B4B00EAA382 /* PumpHistoryEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38A13D3125E28B4B00EAA382 /* PumpHistoryEvent.swift */; };
 		38A504A425DD9C4000C5B9E8 /* UserDefaultsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38A5049125DD9C4000C5B9E8 /* UserDefaultsExtensions.swift */; };
 		38A504A525DD9FDA00C5B9E8 /* OmniKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38B17B2625DD6BBE005CAE3D /* OmniKit.framework */; };
 		38A504A625DD9FDA00C5B9E8 /* OmniKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 38B17B2625DD6BBE005CAE3D /* OmniKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -132,9 +132,6 @@
 		38BF021B25E7D06400579895 /* PumpSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38BF021A25E7D06400579895 /* PumpSettingsView.swift */; };
 		38BF021D25E7E3AF00579895 /* Reservoir.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38BF021C25E7E3AF00579895 /* Reservoir.swift */; };
 		38BF021F25E7F0DE00579895 /* DeviceDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38BF021E25E7F0DE00579895 /* DeviceDataManager.swift */; };
-		38BF022725E855D300579895 /* AnyDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38BF022425E855D200579895 /* AnyDecodable.swift */; };
-		38BF022825E855D300579895 /* AnyCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38BF022525E855D300579895 /* AnyCodable.swift */; };
-		38BF022925E855D300579895 /* AnyEncodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38BF022625E855D300579895 /* AnyEncodable.swift */; };
 		38FE826A25CC82DB001FF17A /* NetworkService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FE826925CC82DB001FF17A /* NetworkService.swift */; };
 		38FE826D25CC8461001FF17A /* NightscoutAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FE826C25CC8461001FF17A /* NightscoutAPI.swift */; };
 		45252C95D220E796FDB3B022 /* ConfigEditorDataFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F8A87AA037BD079BA3528BA /* ConfigEditorDataFlow.swift */; };
@@ -593,7 +590,7 @@
 		388E5A5B25B6F0770019842D /* JSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; };
 		388E5A5F25B6F2310019842D /* Autosens.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Autosens.swift; sourceTree = "<group>"; };
 		3895E4C525B9E00D00214B37 /* Preferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Preferences.swift; sourceTree = "<group>"; };
-		38A13D3125E28B4B00EAA382 /* PumpHystoryEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpHystoryEvent.swift; sourceTree = "<group>"; };
+		38A13D3125E28B4B00EAA382 /* PumpHistoryEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpHistoryEvent.swift; sourceTree = "<group>"; };
 		38A5049125DD9C4000C5B9E8 /* UserDefaultsExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDefaultsExtensions.swift; sourceTree = "<group>"; };
 		38B17AAE25DD69FA005CAE3D /* SwiftCharts.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftCharts.xcodeproj; path = SwiftCharts/SwiftCharts.xcodeproj; sourceTree = "<group>"; };
 		38B17AC025DD6A40005CAE3D /* LoopKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LoopKit.xcodeproj; path = LoopKit/LoopKit.xcodeproj; sourceTree = "<group>"; };
@@ -610,9 +607,6 @@
 		38BF021A25E7D06400579895 /* PumpSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpSettingsView.swift; sourceTree = "<group>"; };
 		38BF021C25E7E3AF00579895 /* Reservoir.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reservoir.swift; sourceTree = "<group>"; };
 		38BF021E25E7F0DE00579895 /* DeviceDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceDataManager.swift; sourceTree = "<group>"; };
-		38BF022425E855D200579895 /* AnyDecodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyDecodable.swift; sourceTree = "<group>"; };
-		38BF022525E855D300579895 /* AnyCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCodable.swift; sourceTree = "<group>"; };
-		38BF022625E855D300579895 /* AnyEncodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyEncodable.swift; sourceTree = "<group>"; };
 		38FE826925CC82DB001FF17A /* NetworkService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkService.swift; sourceTree = "<group>"; };
 		38FE826C25CC8461001FF17A /* NightscoutAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightscoutAPI.swift; sourceTree = "<group>"; };
 		3BF768BD6264FF7D71D66767 /* NightscoutConfigProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = NightscoutConfigProvider.swift; sourceTree = "<group>"; };
@@ -1041,7 +1035,7 @@
 				3895E4C525B9E00D00214B37 /* Preferences.swift */,
 				3811DF0125CA9FEA00A708ED /* Credentials.swift */,
 				383948D925CD64D500E91849 /* Glucose.swift */,
-				38A13D3125E28B4B00EAA382 /* PumpHystoryEvent.swift */,
+				38A13D3125E28B4B00EAA382 /* PumpHistoryEvent.swift */,
 				38BF021C25E7E3AF00579895 /* Reservoir.swift */,
 			);
 			path = Models;
@@ -1050,7 +1044,6 @@
 		388E5A5A25B6F05F0019842D /* Helpers */ = {
 			isa = PBXGroup;
 			children = (
-				38BF022325E855C000579895 /* AnyCodable */,
 				3811DEE325CA063400A708ED /* PropertyWrappers */,
 				3811DE5425C9D4D500A708ED /* Formatters.swift */,
 				3811DE5725C9D4D500A708ED /* ProgressBar.swift */,
@@ -1167,16 +1160,6 @@
 			path = SwiftNotificationCenter;
 			sourceTree = "<group>";
 		};
-		38BF022325E855C000579895 /* AnyCodable */ = {
-			isa = PBXGroup;
-			children = (
-				38BF022525E855D300579895 /* AnyCodable.swift */,
-				38BF022425E855D200579895 /* AnyDecodable.swift */,
-				38BF022625E855D300579895 /* AnyEncodable.swift */,
-			);
-			path = AnyCodable;
-			sourceTree = "<group>";
-		};
 		4E8C7B59F8065047ECE20965 /* View */ = {
 			isa = PBXGroup;
 			children = (
@@ -1626,7 +1609,7 @@
 				3811DF0225CA9FEA00A708ED /* Credentials.swift in Sources */,
 				38B4F3C625E5017E00E76A18 /* NotificationCenter.swift in Sources */,
 				3811DEB625C9D88300A708ED /* UnlockManager.swift in Sources */,
-				38A13D3225E28B4B00EAA382 /* PumpHystoryEvent.swift in Sources */,
+				38A13D3225E28B4B00EAA382 /* PumpHistoryEvent.swift in Sources */,
 				3811DE1825C9D40400A708ED /* Router.swift in Sources */,
 				3811DEE825CA063400A708ED /* Injected.swift in Sources */,
 				3811DEAF25C9D88300A708ED /* KeyValueStorage.swift in Sources */,
@@ -1637,7 +1620,6 @@
 				3811DE0B25C9D32F00A708ED /* BaseView.swift in Sources */,
 				3811DE3225C9D49500A708ED /* HomeDataFlow.swift in Sources */,
 				3821ED4C25DD18BA00BC42AD /* Constants.swift in Sources */,
-				38BF022725E855D300579895 /* AnyDecodable.swift in Sources */,
 				384E803425C385E60086DB71 /* JavaScriptWorker.swift in Sources */,
 				3811DE7A25C9D6D300A708ED /* LoginDataFlow.swift in Sources */,
 				3811DE5D25C9D4D500A708ED /* Publisher.swift in Sources */,
@@ -1649,7 +1631,6 @@
 				3811DE5C25C9D4D500A708ED /* Formatters.swift in Sources */,
 				3811DEC525C9D99900A708ED /* StorageContainer.swift in Sources */,
 				3811DE7F25C9D6D300A708ED /* LoginBuilder.swift in Sources */,
-				38BF022925E855D300579895 /* AnyEncodable.swift in Sources */,
 				3811DE3525C9D49500A708ED /* HomeRootView.swift in Sources */,
 				3811DEC325C9D99900A708ED /* UIContainer.swift in Sources */,
 				3811DE6125C9D4D500A708ED /* ViewModifiers.swift in Sources */,
@@ -1676,7 +1657,6 @@
 				3811DF0825CAAA4700A708ED /* ServiceContainer.swift in Sources */,
 				3811DEB025C9D88300A708ED /* BaseKeychain.swift in Sources */,
 				3811DE4D25C9D4B800A708ED /* AuthotizedRootViewModel.swift in Sources */,
-				38BF022825E855D300579895 /* AnyCodable.swift in Sources */,
 				3811DE6A25C9D62600A708ED /* OnboardingBuilder.swift in Sources */,
 				3811DEC425C9D99900A708ED /* NetworkContainer.swift in Sources */,
 				3811DE4325C9D4A100A708ED /* SettingsProvider.swift in Sources */,

+ 2 - 2
FreeAPS/Sources/APS/DeviceDataManager.swift

@@ -70,12 +70,12 @@ final class DeviceDataManager {
         let numberFormatter = NumberFormatter()
         numberFormatter.numberStyle = .decimal
 
-        let eventsToStore = events.flatMap { event -> [PumpHystoryEvent] in
+        let eventsToStore = events.flatMap { event -> [PumpHistoryEvent] in
             switch event.type {
             case .bolus:
                 guard let dose = event.dose else { return [] }
                 let decimal = Decimal(string: dose.unitsInDeliverableIncrements.description)
-                return [PumpHystoryEvent(
+                return [PumpHistoryEvent(
                     type: .bolus,
                     timestamp: event.date,
                     amount: decimal,

+ 0 - 112
FreeAPS/Sources/Helpers/AnyCodable/AnyCodable.swift

@@ -1,112 +0,0 @@
-/**
- A type-erased `Codable` value.
-
- The `AnyCodable` type forwards encoding and decoding responsibilities
- to an underlying value, hiding its specific underlying type.
-
- You can encode or decode mixed-type values in dictionaries
- and other collections that require `Encodable` or `Decodable` conformance
- by declaring their contained type to be `AnyCodable`.
-
- - SeeAlso: `AnyEncodable`
- - SeeAlso: `AnyDecodable`
- */
-
-import Foundation
-
-#if swift(>=5.1)
-    @frozen public struct AnyCodable: Codable {
-        public let value: Any
-
-        public init<T>(_ value: T?) {
-            self.value = value ?? ()
-        }
-    }
-#else
-    public struct AnyCodable: Codable {
-        public let value: Any
-
-        public init<T>(_ value: T?) {
-            self.value = value ?? ()
-        }
-    }
-#endif
-
-extension AnyCodable: _AnyEncodable, _AnyDecodable {}
-
-extension AnyCodable: Equatable {
-    public static func == (lhs: AnyCodable, rhs: AnyCodable) -> Bool {
-        switch (lhs.value, rhs.value) {
-        case is (Void, Void):
-            return true
-        case let (lhs as Bool, rhs as Bool):
-            return lhs == rhs
-        case let (lhs as Int, rhs as Int):
-            return lhs == rhs
-        case let (lhs as Int8, rhs as Int8):
-            return lhs == rhs
-        case let (lhs as Int16, rhs as Int16):
-            return lhs == rhs
-        case let (lhs as Int32, rhs as Int32):
-            return lhs == rhs
-        case let (lhs as Int64, rhs as Int64):
-            return lhs == rhs
-        case let (lhs as UInt, rhs as UInt):
-            return lhs == rhs
-        case let (lhs as UInt8, rhs as UInt8):
-            return lhs == rhs
-        case let (lhs as UInt16, rhs as UInt16):
-            return lhs == rhs
-        case let (lhs as UInt32, rhs as UInt32):
-            return lhs == rhs
-        case let (lhs as UInt64, rhs as UInt64):
-            return lhs == rhs
-        case let (lhs as Decimal, rhs as Decimal):
-            return lhs == rhs
-        case let (lhs as Float, rhs as Float):
-            return lhs == rhs
-        case let (lhs as Double, rhs as Double):
-            return lhs == rhs
-        case let (lhs as String, rhs as String):
-            return lhs == rhs
-        case let (lhs as [String: AnyCodable], rhs as [String: AnyCodable]):
-            return lhs == rhs
-        case let (lhs as [AnyCodable], rhs as [AnyCodable]):
-            return lhs == rhs
-        default:
-            return false
-        }
-    }
-}
-
-extension AnyCodable: CustomStringConvertible {
-    public var description: String {
-        switch value {
-        case is Void:
-            return String(describing: nil as Any?)
-        case let value as CustomStringConvertible:
-            return value.description
-        default:
-            return String(describing: value)
-        }
-    }
-}
-
-extension AnyCodable: CustomDebugStringConvertible {
-    public var debugDescription: String {
-        switch value {
-        case let value as CustomDebugStringConvertible:
-            return "AnyCodable(\(value.debugDescription))"
-        default:
-            return "AnyCodable(\(description))"
-        }
-    }
-}
-
-extension AnyCodable: ExpressibleByNilLiteral {}
-extension AnyCodable: ExpressibleByBooleanLiteral {}
-extension AnyCodable: ExpressibleByIntegerLiteral {}
-extension AnyCodable: ExpressibleByFloatLiteral {}
-extension AnyCodable: ExpressibleByStringLiteral {}
-extension AnyCodable: ExpressibleByArrayLiteral {}
-extension AnyCodable: ExpressibleByDictionaryLiteral {}

+ 0 - 167
FreeAPS/Sources/Helpers/AnyCodable/AnyDecodable.swift

@@ -1,167 +0,0 @@
-#if canImport(Foundation)
-    import Foundation
-#endif
-
-/**
- A type-erased `Decodable` value.
- 
- The `AnyDecodable` type forwards decoding responsibilities
- to an underlying value, hiding its specific underlying type.
- 
- You can decode mixed-type values in dictionaries
- and other collections that require `Decodable` conformance
- by declaring their contained type to be `AnyDecodable`:
- 
-     let json = """
-     {
-         "boolean": true,
-         "integer": 42,
-         "double": 3.141592653589793,
-         "string": "string",
-         "array": [1, 2, 3],
-         "nested": {
-             "a": "alpha",
-             "b": "bravo",
-             "c": "charlie"
-         }
-     }
-     """.data(using: .utf8)!
- 
-     let decoder = JSONDecoder()
-     let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
- */
-#if swift(>=5.1)
-    @frozen public struct AnyDecodable: Decodable {
-        public let value: Any
-
-        public init<T>(_ value: T?) {
-            self.value = value ?? ()
-        }
-    }
-#else
-    public struct AnyDecodable: Decodable {
-        public let value: Any
-
-        public init<T>(_ value: T?) {
-            self.value = value ?? ()
-        }
-    }
-#endif
-
-#if swift(>=4.2)
-    public protocol _AnyDecodable {
-        var value: Any { get }
-        init<T>(_ value: T?)
-    }
-#else
-    protocol _AnyDecodable {
-        var value: Any { get }
-        init<T>(_ value: T?)
-    }
-#endif
-
-extension AnyDecodable: _AnyDecodable {}
-
-public extension _AnyDecodable {
-    init(from decoder: Decoder) throws {
-        let container = try decoder.singleValueContainer()
-
-        if container.decodeNil() {
-            #if canImport(Foundation)
-                self.init(NSNull())
-            #else
-                self.init(Self?.none)
-            #endif
-        } else if let bool = try? container.decode(Bool.self) {
-            self.init(bool)
-        } else if let int = try? container.decode(Int.self) {
-            self.init(int)
-        } else if let uint = try? container.decode(UInt.self) {
-            self.init(uint)
-        } else if let decimal = try? container.decode(Decimal.self) {
-            self.init(decimal)
-        } else if let double = try? container.decode(Double.self) {
-            self.init(double)
-        } else if let string = try? container.decode(String.self) {
-            self.init(string)
-        } else if let array = try? container.decode([AnyDecodable].self) {
-            self.init(array.map(\.value))
-        } else if let dictionary = try? container.decode([String: AnyDecodable].self) {
-            self.init(dictionary.mapValues { $0.value })
-        } else {
-            throw DecodingError.dataCorruptedError(in: container, debugDescription: "AnyDecodable value cannot be decoded")
-        }
-    }
-}
-
-extension AnyDecodable: Equatable {
-    public static func == (lhs: AnyDecodable, rhs: AnyDecodable) -> Bool {
-        switch (lhs.value, rhs.value) {
-        #if canImport(Foundation)
-            case is (NSNull, NSNull),
-                 is (Void, Void):
-                return true
-        #endif
-        case let (lhs as Bool, rhs as Bool):
-            return lhs == rhs
-        case let (lhs as Int, rhs as Int):
-            return lhs == rhs
-        case let (lhs as Int8, rhs as Int8):
-            return lhs == rhs
-        case let (lhs as Int16, rhs as Int16):
-            return lhs == rhs
-        case let (lhs as Int32, rhs as Int32):
-            return lhs == rhs
-        case let (lhs as Int64, rhs as Int64):
-            return lhs == rhs
-        case let (lhs as UInt, rhs as UInt):
-            return lhs == rhs
-        case let (lhs as UInt8, rhs as UInt8):
-            return lhs == rhs
-        case let (lhs as UInt16, rhs as UInt16):
-            return lhs == rhs
-        case let (lhs as UInt32, rhs as UInt32):
-            return lhs == rhs
-        case let (lhs as UInt64, rhs as UInt64):
-            return lhs == rhs
-        case let (lhs as Decimal, rhs as Decimal):
-            return lhs == rhs
-        case let (lhs as Float, rhs as Float):
-            return lhs == rhs
-        case let (lhs as Double, rhs as Double):
-            return lhs == rhs
-        case let (lhs as String, rhs as String):
-            return lhs == rhs
-        case let (lhs as [String: AnyDecodable], rhs as [String: AnyDecodable]):
-            return lhs == rhs
-        case let (lhs as [AnyDecodable], rhs as [AnyDecodable]):
-            return lhs == rhs
-        default:
-            return false
-        }
-    }
-}
-
-extension AnyDecodable: CustomStringConvertible {
-    public var description: String {
-        switch value {
-        case is Void:
-            return String(describing: nil as Any?)
-        case let value as CustomStringConvertible:
-            return value.description
-        default:
-            return String(describing: value)
-        }
-    }
-}
-
-extension AnyDecodable: CustomDebugStringConvertible {
-    public var debugDescription: String {
-        switch value {
-        case let value as CustomDebugStringConvertible:
-            return "AnyDecodable(\(value.debugDescription))"
-        default:
-            return "AnyDecodable(\(description))"
-        }
-    }
-}

+ 0 - 284
FreeAPS/Sources/Helpers/AnyCodable/AnyEncodable.swift

@@ -1,284 +0,0 @@
-#if canImport(Foundation)
-    import Foundation
-#endif
-
-/**
- A type-erased `Encodable` value.
- 
- The `AnyEncodable` type forwards encoding responsibilities
- to an underlying value, hiding its specific underlying type.
- 
- You can encode mixed-type values in dictionaries
- and other collections that require `Encodable` conformance
- by declaring their contained type to be `AnyEncodable`:
- 
-     let dictionary: [String: AnyEncodable] = [
-         "boolean": true,
-         "integer": 42,
-         "double": 3.141592653589793,
-         "string": "string",
-         "array": [1, 2, 3],
-         "nested": [
-             "a": "alpha",
-             "b": "bravo",
-             "c": "charlie"
-         ]
-     ]
- 
-     let encoder = JSONEncoder()
-     let json = try! encoder.encode(dictionary)
- */
-#if swift(>=5.1)
-    @frozen public struct AnyEncodable: Encodable {
-        public let value: Any
-
-        public init<T>(_ value: T?) {
-            self.value = value ?? ()
-        }
-    }
-#else
-    public struct AnyEncodable: Encodable {
-        public let value: Any
-
-        public init<T>(_ value: T?) {
-            self.value = value ?? ()
-        }
-    }
-#endif
-
-#if swift(>=4.2)
-    public protocol _AnyEncodable {
-        var value: Any { get }
-        init<T>(_ value: T?)
-    }
-#else
-    protocol _AnyEncodable {
-        var value: Any { get }
-        init<T>(_ value: T?)
-    }
-#endif
-
-extension AnyEncodable: _AnyEncodable {}
-
-// MARK: - Encodable
-
-extension _AnyEncodable {
-    public func encode(to encoder: Encoder) throws {
-        var container = encoder.singleValueContainer()
-
-        switch value {
-        #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
-            case let number as NSNumber:
-                try encode(nsnumber: number, into: &container)
-        #endif
-        #if canImport(Foundation)
-            case is NSNull:
-                try container.encodeNil()
-        #endif
-        case is Void:
-            try container.encodeNil()
-        case let bool as Bool:
-            try container.encode(bool)
-        case let int as Int:
-            try container.encode(int)
-        case let int8 as Int8:
-            try container.encode(int8)
-        case let int16 as Int16:
-            try container.encode(int16)
-        case let int32 as Int32:
-            try container.encode(int32)
-        case let int64 as Int64:
-            try container.encode(int64)
-        case let uint as UInt:
-            try container.encode(uint)
-        case let uint8 as UInt8:
-            try container.encode(uint8)
-        case let uint16 as UInt16:
-            try container.encode(uint16)
-        case let uint32 as UInt32:
-            try container.encode(uint32)
-        case let uint64 as UInt64:
-            try container.encode(uint64)
-        case let decimal as Decimal:
-            try container.encode(decimal)
-        case let float as Float:
-            try container.encode(float)
-        case let double as Double:
-            try container.encode(double)
-        case let string as String:
-            try container.encode(string)
-        #if canImport(Foundation)
-            case let date as Date:
-                try container.encode(date)
-            case let url as URL:
-                try container.encode(url)
-        #endif
-        case let array as [Any?]:
-            try container.encode(array.map { AnyEncodable($0) })
-        case let dictionary as [String: Any?]:
-            try container.encode(dictionary.mapValues { AnyEncodable($0) })
-        default:
-            let context = EncodingError.Context(
-                codingPath: container.codingPath,
-                debugDescription: "AnyEncodable value cannot be encoded"
-            )
-            throw EncodingError.invalidValue(value, context)
-        }
-    }
-
-    #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
-        private func encode(nsnumber: NSNumber, into container: inout SingleValueEncodingContainer) throws {
-            switch CFNumberGetType(nsnumber) {
-            case .charType:
-                try container.encode(nsnumber.boolValue)
-            case .sInt8Type:
-                try container.encode(nsnumber.int8Value)
-            case .sInt16Type:
-                try container.encode(nsnumber.int16Value)
-            case .sInt32Type:
-                try container.encode(nsnumber.int32Value)
-            case .sInt64Type:
-                try container.encode(nsnumber.int64Value)
-            case .shortType:
-                try container.encode(nsnumber.uint16Value)
-            case .longType:
-                try container.encode(nsnumber.uint32Value)
-            case .longLongType:
-                try container.encode(nsnumber.uint64Value)
-            case .cfIndexType,
-                 .intType,
-                 .nsIntegerType:
-                try container.encode(nsnumber.intValue)
-            case .float32Type,
-                 .floatType:
-                try container.encode(nsnumber.floatValue)
-            case .cgFloatType,
-                 .doubleType,
-                 .float64Type:
-                try container.encode(nsnumber.doubleValue)
-            #if swift(>=5.0)
-                @unknown default:
-                    let context = EncodingError.Context(
-                        codingPath: container.codingPath,
-                        debugDescription: "NSNumber cannot be encoded because its type is not handled"
-                    )
-                    throw EncodingError.invalidValue(nsnumber, context)
-            #endif
-            }
-        }
-    #endif
-}
-
-extension AnyEncodable: Equatable {
-    public static func == (lhs: AnyEncodable, rhs: AnyEncodable) -> Bool {
-        switch (lhs.value, rhs.value) {
-        case is (Void, Void):
-            return true
-        case let (lhs as Bool, rhs as Bool):
-            return lhs == rhs
-        case let (lhs as Int, rhs as Int):
-            return lhs == rhs
-        case let (lhs as Int8, rhs as Int8):
-            return lhs == rhs
-        case let (lhs as Int16, rhs as Int16):
-            return lhs == rhs
-        case let (lhs as Int32, rhs as Int32):
-            return lhs == rhs
-        case let (lhs as Int64, rhs as Int64):
-            return lhs == rhs
-        case let (lhs as UInt, rhs as UInt):
-            return lhs == rhs
-        case let (lhs as UInt8, rhs as UInt8):
-            return lhs == rhs
-        case let (lhs as UInt16, rhs as UInt16):
-            return lhs == rhs
-        case let (lhs as UInt32, rhs as UInt32):
-            return lhs == rhs
-        case let (lhs as UInt64, rhs as UInt64):
-            return lhs == rhs
-        case let (lhs as Decimal, rhs as Decimal):
-            return lhs == rhs
-        case let (lhs as Float, rhs as Float):
-            return lhs == rhs
-        case let (lhs as Double, rhs as Double):
-            return lhs == rhs
-        case let (lhs as String, rhs as String):
-            return lhs == rhs
-        case let (lhs as [String: AnyEncodable], rhs as [String: AnyEncodable]):
-            return lhs == rhs
-        case let (lhs as [AnyEncodable], rhs as [AnyEncodable]):
-            return lhs == rhs
-        default:
-            return false
-        }
-    }
-}
-
-extension AnyEncodable: CustomStringConvertible {
-    public var description: String {
-        switch value {
-        case is Void:
-            return String(describing: nil as Any?)
-        case let value as CustomStringConvertible:
-            return value.description
-        default:
-            return String(describing: value)
-        }
-    }
-}
-
-extension AnyEncodable: CustomDebugStringConvertible {
-    public var debugDescription: String {
-        switch value {
-        case let value as CustomDebugStringConvertible:
-            return "AnyEncodable(\(value.debugDescription))"
-        default:
-            return "AnyEncodable(\(description))"
-        }
-    }
-}
-
-extension AnyEncodable: ExpressibleByNilLiteral {}
-extension AnyEncodable: ExpressibleByBooleanLiteral {}
-extension AnyEncodable: ExpressibleByIntegerLiteral {}
-extension AnyEncodable: ExpressibleByFloatLiteral {}
-extension AnyEncodable: ExpressibleByStringLiteral {}
-#if swift(>=5.0)
-    extension AnyEncodable: ExpressibleByStringInterpolation {}
-#endif
-extension AnyEncodable: ExpressibleByArrayLiteral {}
-extension AnyEncodable: ExpressibleByDictionaryLiteral {}
-
-public extension _AnyEncodable {
-    init(nilLiteral _: ()) {
-        self.init(nil as Any?)
-    }
-
-    init(booleanLiteral value: Bool) {
-        self.init(value)
-    }
-
-    init(integerLiteral value: Int) {
-        self.init(value)
-    }
-
-    init(floatLiteral value: Double) {
-        self.init(value)
-    }
-
-    init(extendedGraphemeClusterLiteral value: String) {
-        self.init(value)
-    }
-
-    init(stringLiteral value: String) {
-        self.init(value)
-    }
-
-    init(arrayLiteral elements: Any...) {
-        self.init(elements)
-    }
-
-    init(dictionaryLiteral elements: (AnyHashable, Any)...) {
-        self.init([AnyHashable: Any](elements, uniquingKeysWith: { first, _ in first }))
-    }
-}

+ 0 - 3
FreeAPS/Sources/Helpers/JSON.swift

@@ -55,9 +55,6 @@ extension Date: JSON {
 }
 
 typealias RawJSON = String
-typealias AnyJSON = AnyCodable
-
-extension AnyJSON: JSON {}
 
 extension Array: JSON where Element: JSON {}
 extension Dictionary: JSON where Key: JSON, Value: JSON {}

+ 6 - 6
FreeAPS/Sources/Models/PumpHystoryEvent.swift

@@ -1,16 +1,16 @@
 import Foundation
 
-struct PumpHystoryEvent: JSON {
-    let type: PumpHystoryEventType
+struct PumpHistoryEvent: JSON {
+    let type: PumpHistoryEventType
     let timestamp: Date
     let amount: Decimal?
     let duration: Int?
     let durationMin: Int?
     let rate: Decimal?
-    let temp: PumpHystoryTempType?
+    let temp: PumpHistoryTempType?
 }
 
-enum PumpHystoryEventType: String, JSON {
+enum PumpHistoryEventType: String, JSON {
     case bolus = "Bolus"
     case mealBulus = "Meal Bolus"
     case correctionBolus = "Correction Bolus"
@@ -24,12 +24,12 @@ enum PumpHystoryEventType: String, JSON {
     case prime = "Prime"
 }
 
-enum PumpHystoryTempType: String, JSON {
+enum PumpHistoryTempType: String, JSON {
     case absolute
     case percent
 }
 
-extension PumpHystoryEvent {
+extension PumpHistoryEvent {
     private enum CodingKeys: String, CodingKey {
         case type = "_type"
         case timestamp

+ 9 - 0
FreeAPS/Sources/Modules/Base/BaseProvider.swift

@@ -35,4 +35,13 @@ class BaseProvider: Provider, Injectable {
         }
         return (try? String(contentsOf: url)) ?? ""
     }
+
+    func type(for file: String) -> JSON.Type {
+        switch file {
+        case OpenAPS.Monitor.pumpHistory:
+            return [PumpHistoryEvent].self
+        default:
+            return RawJSON.self
+        }
+    }
 }

+ 1 - 1
FreeAPS/Sources/Modules/ConfigEditor/ConfigEditorProvider.swift

@@ -5,7 +5,7 @@ extension ConfigEditor {
         func load(file: String) -> RawJSON {
             if let value = try? storage.retrieve(file, as: RawJSON.self) {
                 return value
-            } else if let value = try? storage.retrieve(file, as: [AnyJSON].self) {
+            } else if let value = try? storage.retrieve(file, as: [PumpHistoryEvent].self) {
                 return value.rawJSON
             }
             return defaults(for: file)