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

FieldValue and DocumentReference codable support. #3231

Merged
12 commits merged into from
Jun 24, 2019
30 changes: 30 additions & 0 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@
113190791F42202FDE1ABC14 /* FIRQuerySnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04F202154AA00B64F25 /* FIRQuerySnapshotTests.mm */; };
11F8EE69182C9699E90A9E3D /* database_info_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB38D92E20235D22000A432D /* database_info_test.cc */; };
12158DFCEE09D24B7988A340 /* maybe_document.pb.cc in Sources */ = {isa = PBXBuildFile; fileRef = 618BBE7E20B89AAC00B5BCE7 /* maybe_document.pb.cc */; };
1235769322B7E99F007DDFA9 /* EncodableFieldValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1235769122B7E915007DDFA9 /* EncodableFieldValueTests.swift */; };
1235769522B86E65007DDFA9 /* FirestoreEncoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1235769422B86E65007DDFA9 /* FirestoreEncoderTests.swift */; };
127CC0D222B3ADDC00A3E42A /* CodableTimestampTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B65C996438B84DBC7616640 /* CodableTimestampTests.swift */; };
1291D9F5300AFACD1FBD262D /* array_sorted_map_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54EB764C202277B30088B8F3 /* array_sorted_map_test.cc */; };
12BB9ED1CA98AA52B92F497B /* log_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 54C2294E1FECABAE007D065B /* log_test.cc */; };
12DB753599571E24DCED0C2C /* FIRValidationTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E06D202154D600B64F25 /* FIRValidationTests.mm */; };
12E62D5722BBC41A0074F412 /* FSTAPIHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E04E202154AA00B64F25 /* FSTAPIHelpers.mm */; };
12E62D5822BBC6EF0074F412 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
132E3483789344640A52F223 /* reference_set_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = 132E32997D781B896672D30A /* reference_set_test.cc */; };
132E3E53179DE287D875F3F2 /* FSTLevelDBTransactionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 132E36BB104830BD806351AC /* FSTLevelDBTransactionTests.mm */; };
132E3EE56C143B2C9ACB6187 /* FSTLevelDBBenchmarkTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 132E3BB3D5C42282B4ACFB20 /* FSTLevelDBBenchmarkTests.mm */; };
Expand Down Expand Up @@ -753,6 +756,7 @@
0473AFFF5567E667A125347B /* ordered_code_benchmark.cc */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.cpp; path = ordered_code_benchmark.cc; sourceTree = "<group>"; };
0EE5300F8233D14025EF0456 /* string_apple_test.mm */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.cpp.objcpp; path = string_apple_test.mm; sourceTree = "<group>"; };
11984BA0A99D7A7ABA5B0D90 /* Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS/Pods-Firestore_Example_iOS-Firestore_SwiftTests_iOS.release.xcconfig"; sourceTree = "<group>"; };
1235769122B7E915007DDFA9 /* EncodableFieldValueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodableFieldValueTests.swift; sourceTree = "<group>"; };
1235769422B86E65007DDFA9 /* FirestoreEncoderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FirestoreEncoderTests.swift; sourceTree = "<group>"; };
1277F98C20D2DF0867496976 /* Pods-Firestore_IntegrationTests_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_IntegrationTests_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_IntegrationTests_iOS/Pods-Firestore_IntegrationTests_iOS.debug.xcconfig"; sourceTree = "<group>"; };
12F4357299652983A615F886 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1355,6 +1359,7 @@
1235769422B86E65007DDFA9 /* FirestoreEncoderTests.swift */,
5495EB022040E90200EBA509 /* CodableGeoPointTests.swift */,
7B65C996438B84DBC7616640 /* CodableTimestampTests.swift */,
1235769122B7E915007DDFA9 /* EncodableFieldValueTests.swift */,
);
path = Codable;
sourceTree = "<group>";
Expand Down Expand Up @@ -2220,6 +2225,9 @@
ProvisioningStyle = Automatic;
TestTargetID = 6003F589195388D20070C39A;
};
6003F589195388D20070C39A = {
LastSwiftMigration = 1020;
};
6003F5AD195388D20070C39A = {
CreatedOnToolsVersion = 9.0;
DevelopmentTeam = EQHXZ8M8AV;
Expand Down Expand Up @@ -3392,8 +3400,11 @@
buildActionMask = 2147483647;
files = (
544A20EE20F6C10C004E52CD /* BasicCompileTests.swift in Sources */,
1235769322B7E99F007DDFA9 /* EncodableFieldValueTests.swift in Sources */,
5495EB032040E90200EBA509 /* CodableGeoPointTests.swift in Sources */,
12E62D5822BBC6EF0074F412 /* FSTHelpers.mm in Sources */,
127CC0D222B3ADDC00A3E42A /* CodableTimestampTests.swift in Sources */,
12E62D5722BBC41A0074F412 /* FSTAPIHelpers.mm in Sources */,
1235769522B86E65007DDFA9 /* FirestoreEncoderTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -4381,13 +4392,19 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c99;
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;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -4420,12 +4437,18 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = c99;
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;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -4694,6 +4717,7 @@
baseConfigurationReference = 3C81DE3772628FE297055662 /* Pods-Firestore_Example_iOS.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "";
HEADER_SEARCH_PATHS = (
Expand All @@ -4702,13 +4726,16 @@
"\"${PODS_ROOT}/leveldb-library/include\"",
);
INFOPLIST_FILE = "App/iOS/Firestore-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to nitpick in the project files, but did you add this line? If so, why?

Copy link
Author

Choose a reason for hiding this comment

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

Not sure why it is there. Removed it.

MODULE_NAME = ExampleApp;
OTHER_LDFLAGS = (
"$(inherited)",
"-all_load",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -4718,6 +4745,7 @@
baseConfigurationReference = 3F0992A4B83C60841C52E960 /* Pods-Firestore_Example_iOS.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "";
HEADER_SEARCH_PATHS = (
Expand All @@ -4726,13 +4754,15 @@
"\"${PODS_ROOT}/leveldb-library/include\"",
);
INFOPLIST_FILE = "App/iOS/Firestore-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
OTHER_LDFLAGS = (
"$(inherited)",
"-all_load",
);
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
WRAPPER_EXTENSION = app;
};
name = Release;
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 @@ -23,6 +23,7 @@
#import "Firestore/Source/Core/FSTQuery.h"

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

namespace api = firebase::firestore::api;

Expand Down
20 changes: 9 additions & 11 deletions Firestore/Example/Tests/API/FSTAPIHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#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 +34,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,11 +61,11 @@ 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,
bool fromCache);
BOOL hasPendingWrites,
BOOL fromCache);

#if __cplusplus
} // extern "C"
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 @@ -24,6 +24,7 @@
#include <utility>
#include <vector>

#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 @@ -67,7 +68,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 @@ -83,19 +84,19 @@
hasPendingWrites:hasMutations];
}

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

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

/** 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
4 changes: 3 additions & 1 deletion Firestore/Swift/Source/Codable/CodablePassThroughTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ import FirebaseFirestore
internal func isFirestorePassthroughType<T: Any>(_ value: T) -> Bool {
return
T.self == GeoPoint.self ||
T.self == Timestamp.self
T.self == Timestamp.self ||
T.self == FieldValue.self ||
T.self == DocumentReference.self
}
45 changes: 45 additions & 0 deletions Firestore/Swift/Source/Codable/DocumentReference+Codable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2019 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

/** Mark DocumentReference to conform to Codable. */

/**
* 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.
*/
private protocol CodableDocumentReference: Codable {}

/**
* DocumentReference's codable implmentation will just throw for most
* encoder/decoder however. It is only meant to be encoded by FirestoreEncoder/FirestoreDecoder.
*/
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