Skip to content

Squash #2178 to continue Firestore Codable #2228

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

Merged
merged 46 commits into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 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
7986b10
Merge remote-tracking branch 'alickbass/codable-firestore' into pb-co…
paulb777 Dec 11, 2018
27b7ff9
update to Swift 4.2
paulb777 Dec 11, 2018
9c49a7f
style
paulb777 Dec 11, 2018
0dfcfc4
Initial Codable tests
paulb777 Dec 15, 2018
190c169
style
paulb777 Dec 15, 2018
0430918
Complete transition of Swift-called APIs away from C++
paulb777 Dec 15, 2018
94c6130
Make encoder and decoder public
paulb777 Dec 19, 2018
0cd8b1e
Undo public Encoder/Decoder in favor of specific extensions
paulb777 Dec 25, 2018
4c27b42
more unit tests
paulb777 Dec 27, 2018
49351c4
Add enum test
paulb777 Dec 28, 2018
ddc1501
style
paulb777 Dec 28, 2018
195bebb
Encodable APIs throw and don't replace existing APIs
paulb777 Jan 3, 2019
cb7a78b
Merge remote-tracking branch 'origin/master' into pb-codable
paulb777 Jan 3, 2019
fdff2a7
style
paulb777 Jan 3, 2019
152d40b
Restore accidental file corruption
paulb777 Jan 3, 2019
f469c6b
Merge remote-tracking branch 'origin/master' into pb-codable
paulb777 Jan 3, 2019
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 @@ -7,8 +7,11 @@
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForTesting = "YES">
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE4A62DC214816BD00670B27"
Expand All @@ -35,7 +38,26 @@
ReferencedContainer = "container:Firebase.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 @@ -49,6 +71,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 @@ -58,6 +89,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
2 changes: 1 addition & 1 deletion FirebaseFirestoreSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

s.description = <<-DESC
Expand Down
28 changes: 26 additions & 2 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@
DE03B2D61F2149D600A30B9C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
DE03B2DD1F2149D600A30B9C /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
DE03B3631F215E1A00A30B9C /* CAcert.pem in Resources */ = {isa = PBXBuildFile; fileRef = DE03B3621F215E1600A30B9C /* CAcert.pem */; };
DE26C61621C15FCC00DE141A /* CodableDocumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE26C61521C15FCC00DE141A /* CodableDocumentTests.swift */; };
DE2EF0851F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF07E1F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m */; };
DE2EF0861F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF0801F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m */; };
DE2EF0871F3D0B6E003D0CDC /* FSTImmutableSortedSet+Testing.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF0821F3D0B6E003D0CDC /* FSTImmutableSortedSet+Testing.m */; };
DE2EF0881F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE2EF0841F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m */; };
DE84BBB421C18F060048A176 /* FSTAPIHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04E202154AA00B64F25 /* FSTAPIHelpers.mm */; };
DE84BBB921C1A6ED0048A176 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
EBFC611B1BF195D0EC710AF4 /* app_testing.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5467FB07203E6A44009C9584 /* app_testing.mm */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -545,6 +548,8 @@
DE03B2E91F2149D600A30B9C /* Firestore_IntegrationTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_IntegrationTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DE03B3621F215E1600A30B9C /* CAcert.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = CAcert.pem; sourceTree = "<group>"; };
DE0761F61F2FE68D003233AF /* BasicCompileTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicCompileTests.swift; sourceTree = "<group>"; };
DE26C61521C15FCC00DE141A /* CodableDocumentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodableDocumentTests.swift; sourceTree = "<group>"; };

DE2EF07E1F3D0B6E003D0CDC /* FSTArraySortedDictionaryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FSTArraySortedDictionaryTests.m; path = ../../third_party/Immutable/Tests/FSTArraySortedDictionaryTests.m; sourceTree = "<group>"; };
DE2EF07F1F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "FSTImmutableSortedDictionary+Testing.h"; path = "../../third_party/Immutable/Tests/FSTImmutableSortedDictionary+Testing.h"; sourceTree = "<group>"; };
DE2EF0801F3D0B6E003D0CDC /* FSTImmutableSortedDictionary+Testing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "FSTImmutableSortedDictionary+Testing.m"; path = "../../third_party/Immutable/Tests/FSTImmutableSortedDictionary+Testing.m"; sourceTree = "<group>"; };
Expand All @@ -557,6 +562,7 @@
DE51B1981F0D48AC0013853F /* FSTSpecTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTSpecTests.h; sourceTree = "<group>"; };
DE51B19A1F0D48AC0013853F /* FSTSyncEngineTestDriver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FSTSyncEngineTestDriver.h; sourceTree = "<group>"; };
DE51B1A71F0D48AC0013853F /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
DE84BBB821C1951E0048A176 /* BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = "<group>"; };
E592181BFD7C53C305123739 /* Pods-Firestore_Tests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests_iOS/Pods-Firestore_Tests_iOS.debug.xcconfig"; sourceTree = "<group>"; };
ECEBABC7E7B693BE808A1052 /* Pods_Firestore_IntegrationTests_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_IntegrationTests_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ED4B3E3EA0EBF3ED19A07060 /* grpc_stream_tester.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = grpc_stream_tester.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -757,6 +763,7 @@
5495EB012040E90200EBA509 /* Codable */ = {
isa = PBXGroup;
children = (
DE26C61521C15FCC00DE141A /* CodableDocumentTests.swift */,
5495EB022040E90200EBA509 /* CodableGeoPointTests.swift */,
);
path = Codable;
Expand All @@ -779,6 +786,7 @@
544A20ED20F6C046004E52CD /* API */,
5495EB012040E90200EBA509 /* Codable */,
54C9EDF52040E16300A969CD /* Info.plist */,
DE84BBB821C1951E0048A176 /* BridgingHeader.h */,
);
name = SwiftTests;
path = ../Swift/Tests;
Expand Down Expand Up @@ -1399,6 +1407,7 @@
TargetAttributes = {
54C9EDF02040E16300A969CD = {
CreatedOnToolsVersion = 9.2;
LastSwiftMigration = 1010;
ProvisioningStyle = Automatic;
TestTargetID = 6003F589195388D20070C39A;
};
Expand Down Expand Up @@ -1831,8 +1840,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DE84BBB921C1A6ED0048A176 /* FSTHelpers.mm in Sources */,
544A20EE20F6C10C004E52CD /* BasicCompileTests.swift in Sources */,
5495EB032040E90200EBA509 /* CodableGeoPointTests.swift in Sources */,
DE84BBB421C18F060048A176 /* FSTAPIHelpers.mm in Sources */,
DE26C61621C15FCC00DE141A /* CodableDocumentTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2138,15 +2150,21 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
);
INFOPLIST_FILE = ../Swift/Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Firestore-SwiftTests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OBJC_BRIDGING_HEADER = ../Swift/Tests/BridgingHeader.h;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
};
Expand Down Expand Up @@ -2177,14 +2195,20 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"\"${PODS_ROOT}/../../..\"",
"\"${PODS_ROOT}/../../../Firestore/third_party/abseil-cpp\"",
);
INFOPLIST_FILE = ../Swift/Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.google.Firestore-SwiftTests-iOS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = ../Swift/Tests/BridgingHeader.h;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Firestore_Example_iOS.app/Firestore_Example_iOS";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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
1 change: 1 addition & 0 deletions Firestore/Example/Tests/API/FIRQueryTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "Firestore/Source/Core/FSTQuery.h"

#import "Firestore/Example/Tests/API/FSTAPIHelpers.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down
15 changes: 7 additions & 8 deletions Firestore/Example/Tests/API/FSTAPIHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

#import <Foundation/Foundation.h>

#import "Firestore/Example/Tests/Util/FSTHelpers.h"

#include "absl/strings/string_view.h"

@class FIRCollectionReference;
@class FIRDocumentReference;
@class FIRDocumentSnapshot;
@class FIRFirestore;
@class FIRQuerySnapshot;

/** Allow tests to just use an int literal for versions. */
typedef int64_t FSTTestSnapshotVersion;

NS_ASSUME_NONNULL_BEGIN

#if __cplusplus
Expand All @@ -36,17 +35,17 @@ extern "C" {
FIRFirestore *FSTTestFirestore();

/** A convenience method for creating a doc snapshot for tests. */
FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
FIRDocumentSnapshot *FSTTestDocSnapshot(const char *path,
FSTTestSnapshotVersion version,
NSDictionary<NSString *, id> *_Nullable data,
BOOL hasMutations,
BOOL fromCache);

/** A convenience method for creating a collection reference from a path string. */
FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path);
FIRCollectionReference *FSTTestCollectionRef(const char *path);

/** A convenience method for creating a document reference from a path string. */
FIRDocumentReference *FSTTestDocRef(const absl::string_view path);
FIRDocumentReference *FSTTestDocRef(const char *path);

/**
* A convenience method for creating a particular query snapshot for tests.
Expand All @@ -63,7 +62,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path);
* @returns A query snapshot that consists of both sets of documents.
*/
FIRQuerySnapshot *FSTTestQuerySnapshot(
const absl::string_view path,
const char *path,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
BOOL hasPendingWrites,
Expand Down
9 changes: 5 additions & 4 deletions Firestore/Example/Tests/API/FSTAPIHelpers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string>

#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/Source/API/FIRCollectionReference+Internal.h"
#import "Firestore/Source/API/FIRDocumentReference+Internal.h"
#import "Firestore/Source/API/FIRDocumentSnapshot+Internal.h"
Expand Down Expand Up @@ -59,7 +60,7 @@
return sharedInstance;
}

FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
FIRDocumentSnapshot *FSTTestDocSnapshot(const char *path,
FSTTestSnapshotVersion version,
NSDictionary<NSString *, id> *_Nullable data,
BOOL hasMutations,
Expand All @@ -75,19 +76,19 @@
hasPendingWrites:hasMutations];
}

FIRCollectionReference *FSTTestCollectionRef(const absl::string_view path) {
FIRCollectionReference *FSTTestCollectionRef(const char *path) {
return [FIRCollectionReference referenceWithPath:testutil::Resource(path)
firestore:FSTTestFirestore()];
}

FIRDocumentReference *FSTTestDocRef(const absl::string_view path) {
FIRDocumentReference *FSTTestDocRef(const char *path) {
return [FIRDocumentReference referenceWithPath:testutil::Resource(path)
firestore:FSTTestFirestore()];
}

/** A convenience method for creating a query snapshots for tests. */
FIRQuerySnapshot *FSTTestQuerySnapshot(
const absl::string_view path,
const char *path,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
BOOL hasPendingWrites,
Expand Down
23 changes: 23 additions & 0 deletions Firestore/Swift/Source/Codable/CodableErrors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

enum FirestoreDecodingError: Error {
case decodingIsNotSupported
}

enum FirestoreEncodingError: Error {
case encodingIsNotSupported
}
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 {}
Loading