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 20 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
37 changes: 37 additions & 0 deletions FirebaseFirestoreSwift.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Be sure to run `pod lib lint FirebaseFirestoreSwift.podspec' to ensure this is a
# valid spec before submitting.
#

Pod::Spec.new do |s|
s.name = 'FirebaseFirestoreSwift'
s.version = '0.10.1'
s.summary = 'Google Cloud Firestore for iOS Swift Extensions'

s.description = <<-DESC
Google Cloud Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
DESC

s.homepage = 'https://developers.google.com/'
s.license = { :type => 'Apache', :file => 'LICENSE' }
s.authors = 'Google, Inc.'

s.source = {
:git => 'https://github.com/Firebase/firebase-ios-sdk.git',
:tag => s.version.to_s
}

s.swift_version = '4.0'
s.ios.deployment_target = '8.0'

s.cocoapods_version = '>= 1.4.0'
s.static_framework = true
s.prefix_header_file = false

s.requires_arc = true
s.source_files = [
'Firestore/Swift/Source/**/*.swift',
]

s.dependency 'FirebaseFirestore', "= #{s.version}"
end
257 changes: 256 additions & 1 deletion Firestore/Example/Firestore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
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
Expand Down
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
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 = "6003F5AD195388D20070C39A"
Expand All @@ -17,6 +20,20 @@
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "54269AE8203B9FFC0039F03F"
BuildableName = "Firestore_SwiftTests_iOS.xctest"
BlueprintName = "Firestore_SwiftTests_iOS"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand All @@ -36,7 +53,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 = "6003F5AD195388D20070C39A"
BuildableName = "Firestore_Tests.xctest"
BlueprintName = "Firestore_Tests"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
Expand All @@ -51,6 +87,15 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F5AD195388D20070C39A"
BuildableName = "Firestore_Tests.xctest"
BlueprintName = "Firestore_Tests"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -60,6 +105,15 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6003F5AD195388D20070C39A"
BuildableName = "Firestore_Tests.xctest"
BlueprintName = "Firestore_Tests"
ReferencedContainer = "container:Firestore.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
5 changes: 5 additions & 0 deletions Firestore/Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ target 'Firestore_Example' do
end
end

target 'Firestore_SwiftTests_iOS' do
pod 'FirebaseFirestore', :path => '../../'
pod 'FirebaseFirestoreSwift', :path => '../../'
end

target 'SwiftBuildTest' do
pod 'FirebaseFirestore', :path => '../../'
end
38 changes: 38 additions & 0 deletions Firestore/Swift/Source/Codable/CodableDocumentReference.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
Copy link
Contributor

Choose a reason for hiding this comment

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

All files need a copyright notice to be in this repo. You can copy from the top of any existing file and adjust the date or use this:

/*
 * 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.
 */

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

I just re-read our internal style guide and realized that these files should really be Class+Protocol.swift. In this case DocumentReference+Codable.swift. Sorry to lead you astray with the other PR :-(.

Copy link
Author

Choose a reason for hiding this comment

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

Done

// CodableDocumentReference.swift
// FirebaseFirestoreSwift
//
// Created by Oleksii on 22/02/2018.
//

import FirebaseFirestore

enum FirestoreDecodingError: Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

These don't have much to do with DocumentReference. Perhaps put these in an Errors.swift?

Copy link
Author

Choose a reason for hiding this comment

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

Done

case decodingIsNotSupported
Copy link
Contributor

Choose a reason for hiding this comment

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

Google's coding style requires two space indents. Rather than fix this by hand please wait for PR #847 to land and run that here to fix this.

}

enum FirestoreEncodingError: Error {
case encodingIsNotSupported
}

/**
* 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 {}
26 changes: 26 additions & 0 deletions Firestore/Swift/Source/Codable/CodableFieldValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// CodableFieldValue.swift
// FirebaseFirestoreSwift
//
// Created by Oleksii on 22/02/2018.
//

import FirebaseFirestore

/**
* A protocol describing the encodable properties of a FirebaseFirestore.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the encodable properties of a FieldValue, no?

Copy link
Author

Choose a reason for hiding this comment

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

Done

*
* Note: this protocol exists as a workaround for the Swift compiler: if the FirebaseFirestore 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 {}
62 changes: 62 additions & 0 deletions Firestore/Swift/Source/Codable/CodableGeoPoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 GeoPoint.
*
* Note: this protocol exists as a workaround for the Swift compiler: if the GeoPoint 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 CodableGeoPoint: Codable {
var latitude: Double { get }
var longitude: Double { get }

init(latitude: Double, longitude: Double)
}

/** The keys in a GeoPoint. Must match the properties of CodableGeoPoint. */
fileprivate enum GeoPointKeys: String, CodingKey {
case latitude
case longitude
}

/**
* An extension of GeoPoint that implements the behavior of the Codable protocol.
*
* Note: this is implemented manually here because the Swift compiler can't synthesize these methods
* when declaring an extension to conform to Codable.
*/
extension CodableGeoPoint {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: GeoPointKeys.self)
let latitude = try container.decode(Double.self, forKey: .latitude)
let longitude = try container.decode(Double.self, forKey: .longitude)
self.init(latitude: latitude, longitude: longitude)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: GeoPointKeys.self)
try container.encode(latitude, forKey: .latitude)
try container.encode(longitude, forKey: .longitude)
}
}

/** Extends GeoPoint to conform to Codable. */
extension GeoPoint: CodableGeoPoint {}
Loading