Skip to content

Commit 34023c3

Browse files
Hui-Wuwilhuff
authored andcommitted
FieldValue and DocumentReference codable support. (#3231)
* working serverTimestamp * working FieldValue. Still need: document ref and ability to Eq of FieldValue * DocumentReference implemented and testing works * clean up header search path * improving FieldValue enum comments * run through formatting * addressing comments * formatted with swiftformat 0.35.7 * add missing bool->BOOL change * undo unintended swift version change * remove unwanted proj file change
1 parent 5fdfc9d commit 34023c3

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

Firestore/Swift/Source/Codable/third_party/FirestoreDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ extension _FirestoreDecoder {
10331033
}
10341034
}
10351035

1036-
// Decoding an embeded container, this requires expanding the storage stack and
1036+
// Decoding an embedded container, this requires expanding the storage stack and
10371037
// then restore after decoding.
10381038
storage.push(container: value)
10391039
let decoded = try T(from: self)

Firestore/Swift/Source/Codable/third_party/FirestoreEncoder.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ extension Firestore {
3535
/// - Returns: A Map keyed by String representing a document Firestore
3636
/// API can work with.
3737
public func encode<T: Encodable>(_ value: T) throws -> [String: Any] {
38+
// DocumentReference and FieldValue cannot be encoded directly.
39+
guard T.self != DocumentReference.self && T.self != FieldValue.self else {
40+
throw FirestoreEncodingError.encodingIsNotSupported
41+
}
3842
guard let topLevel = try _FirestoreEncoder().box_(value) else {
3943
throw EncodingError.invalidValue(value,
4044
EncodingError.Context(codingPath: [],
@@ -495,7 +499,7 @@ extension _FirestoreEncoder: SingleValueEncodingContainer {
495499
}
496500

497501
/// Special subclass of `_FirestoreEncoder` used by `superEncoder`.
498-
/// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses it's own
502+
/// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses its own
499503
/// storage. The encoded result will be written back to the referencing encoder's storage
500504
/// when it is `deinit`-ed.
501505
private class _FirestoreReferencingEncoder: _FirestoreEncoder {

Firestore/third_party/FirestoreEncoder/FirestoreDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ extension _FirestoreDecoder {
10331033
}
10341034
}
10351035

1036-
// Decoding an embeded container, this requires expanding the storage stack and
1036+
// Decoding an embedded container, this requires expanding the storage stack and
10371037
// then restore after decoding.
10381038
storage.push(container: value)
10391039
let decoded = try T(from: self)

Firestore/third_party/FirestoreEncoder/FirestoreEncoder.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ extension Firestore {
3535
/// - Returns: A Map keyed by String representing a document Firestore
3636
/// API can work with.
3737
public func encode<T: Encodable>(_ value: T) throws -> [String: Any] {
38+
// DocumentReference and FieldValue cannot be encoded directly.
39+
guard T.self != DocumentReference.self && T.self != FieldValue.self else {
40+
throw FirestoreEncodingError.encodingIsNotSupported
41+
}
3842
guard let topLevel = try _FirestoreEncoder().box_(value) else {
3943
throw EncodingError.invalidValue(value,
4044
EncodingError.Context(codingPath: [],
@@ -495,7 +499,7 @@ extension _FirestoreEncoder: SingleValueEncodingContainer {
495499
}
496500

497501
/// Special subclass of `_FirestoreEncoder` used by `superEncoder`.
498-
/// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses it's own
502+
/// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses its own
499503
/// storage. The encoded result will be written back to the referencing encoder's storage
500504
/// when it is `deinit`-ed.
501505
private class _FirestoreReferencingEncoder: _FirestoreEncoder {

0 commit comments

Comments
 (0)