-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Continue Firestore Codable 3 #2229
Closed
Closed
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1743eb2
Squash #2178 to continue Firestore Codable (#2228)
paulb777 e8fbb2a
Fix bad merge
paulb777 35365ac
Remove throws from decodable APIs
paulb777 1533b28
Address review feedback
paulb777 280bbf6
Address test review feedback
paulb777 ee349c2
Remove force unwrap
paulb777 a858b9a
Codable Timestamp
paulb777 d79806b
Extension to separate files, Timestamp pass-through, match param labe…
paulb777 162e775
Firestore.encode() and Firestore.decode()
paulb777 0de7c25
Add Function for checking Firestore pass-through types
paulb777 c980da0
encodeOrDie
paulb777 ef120f9
Fix unused build warning
paulb777 cca9503
Stop overriding in extensions
paulb777 064b0c3
merge master
paulb777 7bd089d
One more 2019
paulb777 be05ca6
style
paulb777 7dd421e
from argument label
paulb777 b98e874
Address code review feedback (not including tests)
paulb777 4be21cd
wip
paulb777 f1a94b8
style
paulb777 75d2bbb
checkpoint
paulb777 5558597
style
paulb777 a3eaadc
Test and comments about nil encoding challenge
paulb777 7c6ee0f
Back to encode/decode instance methods and remove some extensions
paulb777 90673ea
style
paulb777 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright 2018 Google | ||
paulb777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* 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. | ||
*/ | ||
|
||
enum FirestoreDecodingError: Error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These need comments if they're going to be public. We can ignore this for now though. |
||
case decodingIsNotSupported | ||
} | ||
|
||
enum FirestoreEncodingError: Error { | ||
case encodingIsNotSupported | ||
} |
39 changes: 39 additions & 0 deletions
39
Firestore/Swift/Source/Codable/DocumentReference+Codable.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 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 FirebaseFirestore | ||
|
||
/** | ||
* A protocol describing the encodable properties of a DocumentReference. | ||
* | ||
* Note: this protocol exists as a workaround for the Swift compiler: if the DocumentReference class | ||
* was extended directly to conform to Codable, the methods implementing the protocol would be need | ||
* to be marked required but that can't be done in an extension. Declaring the extension on the | ||
* protocol sidesteps this issue. | ||
*/ | ||
fileprivate protocol CodableDocumentReference: Codable {} | ||
|
||
extension CodableDocumentReference { | ||
public init(from decoder: Decoder) throws { | ||
throw FirestoreDecodingError.decodingIsNotSupported | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
throw FirestoreEncodingError.encodingIsNotSupported | ||
} | ||
} | ||
|
||
extension DocumentReference: CodableDocumentReference {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2018 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 FirebaseFirestore | ||
|
||
/** | ||
* A protocol describing the encodable properties of a FirebaseFirestore. | ||
* | ||
* Note: this protocol exists as a workaround for the Swift compiler: if the FieldValue class | ||
* was extended directly to conform to Codable, the methods implementing the protocol would be need | ||
* to be marked required but that can't be done in an extension. Declaring the extension on the | ||
* protocol sidesteps this issue. | ||
*/ | ||
fileprivate protocol CodableFieldValue: Encodable {} | ||
ryanwilson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
extension CodableFieldValue { | ||
public func encode(to encoder: Encoder) throws { | ||
throw FirestoreEncodingError.encodingIsNotSupported | ||
} | ||
} | ||
paulb777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
extension FieldValue: CodableFieldValue {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2018 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 FirebaseFirestore | ||
|
||
/** | ||
* A protocol describing the encodable properties of a DocumentSnapshot. | ||
* | ||
* Note: this protocol exists as a workaround for the Swift compiler: if the Timestamp class | ||
* was extended directly to conform to Codable, the methods implementing the protocol would be need | ||
* to be marked required but that can't be done in an extension. Declaring the extension on the | ||
* protocol sidesteps this issue. | ||
*/ | ||
public protocol CodableTimestamp: Codable { | ||
init(date: Date) | ||
func dateValue() -> Date | ||
paulb777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
extension CodableTimestamp { | ||
var date: Date { return dateValue() } | ||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
self.init(date: try container.decode(Date.self)) | ||
paulb777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
try container.encode(dateValue()) | ||
} | ||
} | ||
|
||
extension Timestamp: CodableTimestamp {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be required and is likely harmful. We don't want any C++ when compiling Swift.
Same for the Release configuration below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's what happens without the abseil include building the swift tests: