Skip to content

Commit de7eb4f

Browse files
authored
Migrate FSTServerTimestampValue to FSTDelegateValue (#3174)
* Migrate FSTServerTimetsampValue to FSTDelegateValue * Make ServerTimestamp use FSTFieldValue for previous value This makes it possible integrate the FSTServerTimestampValue changes earlier.
1 parent bbbe77e commit de7eb4f

28 files changed

+296
-190
lines changed

FirebaseFirestore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
2525
s.prefix_header_file = false
2626

2727
s.source_files = [
28-
'Firestore/Source/**/*',
28+
'Firestore/Source/**/*.{h,m,mm}',
2929
'Firestore/Protos/nanopb/**/*.{h,cc}',
3030
'Firestore/Protos/objc/**/*.[hm]',
3131
'Firestore/core/include/**/*.{h,cc,mm}',

Firestore/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# limitations under the License.
1414

1515
add_subdirectory(Example/Benchmarks)
16+
add_subdirectory(Source)
17+
add_subdirectory(third_party/Immutable)
18+
1619
add_subdirectory(Protos)
1720
add_subdirectory(core)
1821
add_subdirectory(fuzzing)

Firestore/Example/Tests/Model/FSTFieldValueTests.mm

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@
5151
// Server Timestamp values can't be parsed directly, so we have a couple predefined sentinel
5252
// strings that can be used instead.
5353
if ([value isEqual:@"server-timestamp-1"]) {
54-
wrappedValue = [FSTServerTimestampValue
55-
serverTimestampValueWithLocalWriteTime:testutil::MakeTimestamp(2016, 5, 20, 10, 20, 0)
56-
previousValue:nil];
54+
wrappedValue =
55+
FieldValue::FromServerTimestamp(testutil::MakeTimestamp(2016, 5, 20, 10, 20, 0)).Wrap();
5756
} else if ([value isEqual:@"server-timestamp-2"]) {
58-
wrappedValue = [FSTServerTimestampValue
59-
serverTimestampValueWithLocalWriteTime:testutil::MakeTimestamp(2016, 10, 21, 15, 32, 0)
60-
previousValue:nil];
57+
wrappedValue =
58+
FieldValue::FromServerTimestamp(testutil::MakeTimestamp(2016, 10, 21, 15, 32, 0))
59+
.Wrap();
6160
} else if ([value isKindOfClass:[FSTDocumentKeyReference class]]) {
6261
// We directly convert these here so that the databaseIDs can be different.
6362
FSTDocumentKeyReference *reference = (FSTDocumentKeyReference *)value;
@@ -311,13 +310,10 @@ - (void)testValueEquality {
311310
@[ FSTTestFieldValue(date2) ],
312311
@[
313312
// NOTE: ServerTimestampValues can't be parsed via FSTTestFieldValue().
314-
[FSTServerTimestampValue serverTimestampValueWithLocalWriteTime:MakeTimestamp(date1)
315-
previousValue:nil],
316-
[FSTServerTimestampValue serverTimestampValueWithLocalWriteTime:MakeTimestamp(date1)
317-
previousValue:nil]
313+
FieldValue::FromServerTimestamp(MakeTimestamp(date1)).Wrap(),
314+
FieldValue::FromServerTimestamp(MakeTimestamp(date1)).Wrap()
318315
],
319-
@[ [FSTServerTimestampValue serverTimestampValueWithLocalWriteTime:MakeTimestamp(date2)
320-
previousValue:nil] ],
316+
@[ FieldValue::FromServerTimestamp(MakeTimestamp(date2)).Wrap() ],
321317
@[ FSTTestFieldValue(FSTTestGeoPoint(0, 1)), FieldValue::FromGeoPoint(GeoPoint(0, 1)).Wrap() ],
322318
@[ FSTTestFieldValue(FSTTestGeoPoint(1, 0)) ],
323319
@[

Firestore/Example/Tests/Model/FSTMutationTests.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ - (void)testAppliesLocalServerTimestampTransformToDocuments {
144144
FSTObjectValue *expectedData =
145145
FSTTestObjectValue(@{@"foo" : @{@"bar" : @"<server-timestamp>"}, @"baz" : @"baz-value"});
146146
expectedData =
147-
[expectedData objectBySettingValue:[FSTServerTimestampValue
148-
serverTimestampValueWithLocalWriteTime:_timestamp
149-
previousValue:nil]
147+
[expectedData objectBySettingValue:FieldValue::FromServerTimestamp(_timestamp).Wrap()
150148
forPath:testutil::Field("foo.bar")];
151149

152150
FSTDocument *expectedDoc = [FSTDocument documentWithData:expectedData

Firestore/Source/API/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2019 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Public types to be used both internally and externally.
16+
if(APPLE)
17+
cc_library(
18+
firebase_firestore_objc_api
19+
SOURCES
20+
FIRGeoPoint+Internal.h
21+
FIRGeoPoint.mm
22+
FIRTimestamp.m
23+
FIRTimestamp+Internal.h
24+
converters.h
25+
converters.mm
26+
DEPENDS
27+
firebase_firestore_api
28+
firebase_firestore_util
29+
)
30+
31+
target_include_directories(
32+
firebase_firestore_objc_api
33+
PUBLIC ${PROJECT_SOURCE_DIR}/Firestore/Source/Public
34+
)
35+
36+
target_compile_options(
37+
firebase_firestore_objc_api PRIVATE
38+
-Wno-unused-parameter
39+
)
40+
endif()

Firestore/Source/API/FIRFieldPath.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ - (instancetype)initWithFields:(NSArray<NSString *> *)fieldNames {
4848
ThrowInvalidArgument("Invalid field path. Provided names must not be empty.");
4949
}
5050

51-
std::vector<std::string> field_names;
52-
field_names.reserve(fieldNames.count);
53-
for (int i = 0; i < fieldNames.count; ++i) {
54-
field_names.emplace_back(util::MakeString(fieldNames[i]));
51+
std::vector<std::string> converted;
52+
converted.reserve(fieldNames.count);
53+
for (NSString *fieldName in fieldNames) {
54+
converted.emplace_back(util::MakeString(fieldName));
5555
}
5656

57-
return [self initPrivate:FieldPath::FromSegments(std::move(field_names))];
57+
return [self initPrivate:FieldPath::FromSegments(std::move(converted))];
5858
}
5959

6060
+ (instancetype)documentID {

Firestore/Source/API/FIRFieldValue.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ - (instancetype)initWithOperand:(NSNumber *)operand;
130130
@end
131131

132132
@implementation FSTNumericIncrementFieldValue
133-
- (instancetype)initWithOperand:(NSNumber *)operand;
134-
{
133+
- (instancetype)initWithOperand:(NSNumber *)operand {
135134
if (self = [super initPrivate]) {
136135
_operand = operand;
137136
}

Firestore/Source/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2019 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
add_subdirectory(API)
16+
add_subdirectory(Model)

Firestore/Source/Model/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2019 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
if(APPLE)
16+
cc_library(
17+
firebase_firestore_objc_model
18+
SOURCES
19+
FSTDocument.h
20+
FSTDocument.mm
21+
FSTDocumentKey.h
22+
FSTDocumentKey.mm
23+
FSTFieldValue.h
24+
FSTFieldValue.mm
25+
FSTMutation.h
26+
FSTMutation.mm
27+
FSTMutationBatch.h
28+
FSTMutationBatch.mm
29+
DEPENDS
30+
firebase_firestore_model
31+
firebase_firestore_objc_api
32+
firebase_firestore_objc_immutable
33+
firebase_firestore_util
34+
)
35+
36+
target_compile_options(
37+
firebase_firestore_objc_model PRIVATE
38+
-Wno-unused-parameter
39+
)
40+
endif()

Firestore/Source/Model/FSTDocumentKey.mm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <string>
2020
#include <utility>
2121

22-
#import "Firestore/Source/Core/FSTFirestoreClient.h"
23-
2422
#include "Firestore/core/src/firebase/firestore/model/document_key.h"
2523
#include "Firestore/core/src/firebase/firestore/util/hard_assert.h"
2624
#include "Firestore/core/src/firebase/firestore/util/hashing.h"

0 commit comments

Comments
 (0)