Skip to content
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

Codable firestore #838

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3598b86
Add Firestore_SwiftTests_iOS target to Xcode
wilhuff Feb 20, 2018
959cc57
Clean up generated Firestore_SwiftTests_iOS test target
wilhuff Feb 20, 2018
ad832a1
Add FirebaseFirestoreSwift podspec
wilhuff Feb 20, 2018
24daa10
Add Firestore_SwiftTests_iOS to the Podfile
wilhuff Feb 20, 2018
6fc2dd4
Add CodableGeoPoint
wilhuff Feb 20, 2018
b5d72b0
Move Firestore_SwiftTests_iOS to the top-level of the Podfile
wilhuff Feb 20, 2018
c719b85
Add CodableGeoPointTests to the project
wilhuff Feb 20, 2018
448bbbf
Add FirebaseEncoder
Feb 20, 2018
557883e
Update Encoder
Feb 20, 2018
86bbf4b
Fix typo
Feb 20, 2018
cb7e0a8
Make the extension available only from swift 4
Feb 21, 2018
6303624
Add FirestoreDecoder
Feb 21, 2018
f20e338
Make all the types in Encoder as available from swift 4
Feb 21, 2018
9f13acf
Add extension to document snapshot
Feb 21, 2018
a423896
Refactor to private Decoder and Encoder
Feb 22, 2018
dcc4b4a
Add internal type Firestore.Decoder
Feb 22, 2018
493a157
Add internal Firestore.Encoder type
Feb 22, 2018
c9b35c7
Move to proper sub folder
Feb 22, 2018
05e20fd
Confirm DocumentReference to Codable
Feb 22, 2018
735331d
Confirm FieldValue to Encodable protocol
Feb 22, 2018
889f29a
Fix copyright
Feb 26, 2018
4fed07f
Merge master into codable-firestore
Feb 26, 2018
ccdd0fc
Refactor to requireKey and requireValue private methods
Feb 27, 2018
93f7430
Fix field value comment
Feb 27, 2018
abe43e4
Fix names of the files
Feb 27, 2018
073901a
Move errors to separate file
Feb 27, 2018
a62364d
Refactor to use expectNotAtEnd
Feb 27, 2018
f19ea99
Fix using internal type mismatch method
Feb 27, 2018
3ea3eba
Refactor to require value private function
Feb 27, 2018
d23c201
Refactor to private methods to require values
Feb 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base state from which you branched was broken. I've since fixed this, but unfortunately these diffs remain. For all the .xcscheme files, make sure your upstream branch is up-to-date and then git checkout the master version of these files and commit them. After pushing you shouldn't see any additions to project files.

skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54269AE8203B9FFC0039F03F"
BuildableName = "Firestore_SwiftTests_iOS.xctest"
BlueprintName = "Firestore_SwiftTests_iOS"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForTesting = "YES">
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE03B2941F2149D600A30B9C"
Expand Down Expand Up @@ -36,7 +39,26 @@
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54269AE8203B9FFC0039F03F"
BuildableName = "Firestore_SwiftTests_iOS.xctest"
BlueprintName = "Firestore_SwiftTests_iOS"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE03B2941F2149D600A30B9C"
BuildableName = "Firestore_IntegrationTests.xctest"
BlueprintName = "Firestore_IntegrationTests"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand All @@ -51,6 +73,15 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE03B2941F2149D600A30B9C"
BuildableName = "Firestore_IntegrationTests.xctest"
BlueprintName = "Firestore_IntegrationTests"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -60,6 +91,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE03B2941F2149D600A30B9C"
BuildableName = "Firestore_IntegrationTests.xctest"
BlueprintName = "Firestore_IntegrationTests"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
39 changes: 39 additions & 0 deletions Firestore/Swift/Source/Codable/DocumentReference+Codable.swift
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 protcol 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 {}
16 changes: 16 additions & 0 deletions Firestore/Swift/Source/Codable/Errors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright notice.

I realize this isn't super important to you, but this is the only way that Google allows me to continue to work in the open with you, so it's very important to me :-).

// Errors.swift
// FirebaseFirestoreSwift
//
// Created by Oleksii on 27/02/2018.
//

import Foundation

enum FirestoreDecodingError: Error {
case decodingIsNotSupported
}

enum FirestoreEncodingError: Error {
case encodingIsNotSupported
}
35 changes: 35 additions & 0 deletions Firestore/Swift/Source/Codable/FieldValue+Codable.swift
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 protcol 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 {}

extension CodableFieldValue {
public func encode(to encoder: Encoder) throws {
throw FirestoreEncodingError.encodingIsNotSupported
}
}

extension FieldValue: CodableFieldValue {}
Loading