Skip to content

Commit

Permalink
FieldValue and DocumentReference codable support. (#3231)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Hui-Wu authored and wilhuff committed Sep 26, 2019
1 parent 5fdfc9d commit 34023c3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ extension _FirestoreDecoder {
}
}

// Decoding an embeded container, this requires expanding the storage stack and
// Decoding an embedded container, this requires expanding the storage stack and
// then restore after decoding.
storage.push(container: value)
let decoded = try T(from: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ extension Firestore {
/// - Returns: A Map keyed by String representing a document Firestore
/// API can work with.
public func encode<T: Encodable>(_ value: T) throws -> [String: Any] {
// DocumentReference and FieldValue cannot be encoded directly.
guard T.self != DocumentReference.self && T.self != FieldValue.self else {
throw FirestoreEncodingError.encodingIsNotSupported
}
guard let topLevel = try _FirestoreEncoder().box_(value) else {
throw EncodingError.invalidValue(value,
EncodingError.Context(codingPath: [],
Expand Down Expand Up @@ -495,7 +499,7 @@ extension _FirestoreEncoder: SingleValueEncodingContainer {
}

/// Special subclass of `_FirestoreEncoder` used by `superEncoder`.
/// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses it's own
/// It inherits the codingPath from the referencing `_FirestoreEncoder` but uses its own
/// storage. The encoded result will be written back to the referencing encoder's storage
/// when it is `deinit`-ed.
private class _FirestoreReferencingEncoder: _FirestoreEncoder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ extension _FirestoreDecoder {
}
}

// Decoding an embeded container, this requires expanding the storage stack and
// Decoding an embedded container, this requires expanding the storage stack and
// then restore after decoding.
storage.push(container: value)
let decoded = try T(from: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ extension Firestore {
/// - Returns: A Map keyed by String representing a document Firestore
/// API can work with.
public func encode<T: Encodable>(_ value: T) throws -> [String: Any] {
// DocumentReference and FieldValue cannot be encoded directly.
guard T.self != DocumentReference.self && T.self != FieldValue.self else {
throw FirestoreEncodingError.encodingIsNotSupported
}
guard let topLevel = try _FirestoreEncoder().box_(value) else {
throw EncodingError.invalidValue(value,
EncodingError.Context(codingPath: [],
Expand Down Expand Up @@ -495,7 +499,7 @@ extension _FirestoreEncoder: SingleValueEncodingContainer {
}

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

0 comments on commit 34023c3

Please sign in to comment.