diff --git a/Firestore/Swift/Source/Codable/CodableErrors.swift b/Firestore/Swift/Source/Codable/CodableErrors.swift index ae231a6310c..4412304f346 100644 --- a/Firestore/Swift/Source/Codable/CodableErrors.swift +++ b/Firestore/Swift/Source/Codable/CodableErrors.swift @@ -14,10 +14,10 @@ * limitations under the License. */ -enum FirestoreDecodingError: Error { +internal enum FirestoreDecodingError: Error { case decodingIsNotSupported } -enum FirestoreEncodingError: Error { +internal enum FirestoreEncodingError: Error { case encodingIsNotSupported } diff --git a/Firestore/Swift/Source/Codable/CodablePassThroughTypes.swift b/Firestore/Swift/Source/Codable/CodablePassThroughTypes.swift index 5a8fb01db7f..2808d075485 100644 --- a/Firestore/Swift/Source/Codable/CodablePassThroughTypes.swift +++ b/Firestore/Swift/Source/Codable/CodablePassThroughTypes.swift @@ -17,7 +17,7 @@ import Foundation import FirebaseFirestore -func isCodablePassThroughType(_ value: T) -> Bool { +internal func isFirestorePassthroughType(_ value: T) -> Bool { return T.self == GeoPoint.self || T.self == DocumentReference.self || diff --git a/Firestore/Swift/Source/Codable/EncodeOrDie.swift b/Firestore/Swift/Source/Codable/EncodeOrDie.swift deleted file mode 100644 index 80f223b7ddd..00000000000 --- a/Firestore/Swift/Source/Codable/EncodeOrDie.swift +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Foundation -import FirebaseFirestore - -internal func encodeOrDie(_ value: T) -> [String: Any] { - do { - return try Firestore.encode(value) - } catch let error { - fatalError("Unable to encode data with Firestore encoder: \(error)") - } -} diff --git a/Firestore/Swift/Source/Codable/third_party/FirestoreDecoder.swift b/Firestore/Swift/Source/Codable/third_party/FirestoreDecoder.swift index 1838f42a695..58f0c040b70 100644 --- a/Firestore/Swift/Source/Codable/third_party/FirestoreDecoder.swift +++ b/Firestore/Swift/Source/Codable/third_party/FirestoreDecoder.swift @@ -1005,7 +1005,7 @@ extension _FirestoreDecoder { return (decimal as! T) } if let _ = value as? Codable { - if isCodablePassThroughType(value as! T) { + if isFirestorePassthroughType(value as! T) { // All the native Firestore types that should not be encoded return (value as! T) } diff --git a/Firestore/Swift/Source/Codable/third_party/FirestoreEncoder.swift b/Firestore/Swift/Source/Codable/third_party/FirestoreEncoder.swift index a94b346651a..4034213eae5 100644 --- a/Firestore/Swift/Source/Codable/third_party/FirestoreEncoder.swift +++ b/Firestore/Swift/Source/Codable/third_party/FirestoreEncoder.swift @@ -16,6 +16,14 @@ import Foundation import FirebaseFirestore +internal func encodeOrDie(_ value: T) -> [String: Any] { + do { + return try Firestore.encode(value) + } catch let error { + fatalError("Unable to encode data with Firestore encoder: \(error)") + } +} + extension Firestore { public static func encode(_ value: T) throws -> [String: Any] { guard let topLevel = try _FirestoreEncoder().box_(value) else { @@ -342,7 +350,7 @@ extension _FirestoreEncoder { return box((value as! URL).absoluteString) } else if T.self == Decimal.self || T.self == NSDecimalNumber.self { return (value as! NSDecimalNumber) - } else if isCodablePassThroughType(value) { + } else if isFirestorePassthroughType(value) { // These are all native _Firestore types that we don't need to Encode return (value as! NSObject) }