Skip to content

Commit ef0cad8

Browse files
Rename proto_values->values, create values.test.ts
1 parent 05bb427 commit ef0cad8

File tree

7 files changed

+154
-183
lines changed

7 files changed

+154
-183
lines changed

packages/firestore/src/api/user_data_writer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export class UserDataWriter<T> {
7878
private convertServerTimestamp(value: ServerTimestampValue): unknown {
7979
switch (this.serverTimestampBehavior) {
8080
case 'previous':
81-
return value.previousValue ? this.convertValue(value.previousValue) : null;
81+
return value.previousValue
82+
? this.convertValue(value.previousValue)
83+
: null;
8284
case 'estimate':
8385
return this.convertTimestamp(value.localWriteTime);
8486
default:

packages/firestore/src/model/document_key.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class DocumentKey {
2828
);
2929
}
3030

31+
static fromName(name: string): DocumentKey {
32+
return new DocumentKey(ResourcePath.fromString(name).popFirst(5));
33+
}
34+
3135
/** Returns true if the document is in the specified collectionId. */
3236
hasCollectionId(collectionId: string): boolean {
3337
return (

packages/firestore/src/model/proto_field_value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
normalizeByteString,
3434
normalizeTimestamp,
3535
typeOrder
36-
} from './proto_values';
36+
} from './values';
3737
import { Blob } from '../api/blob';
3838
import { GeoPoint } from '../api/geo_point';
3939
import { Timestamp } from '../api/timestamp';

packages/firestore/src/model/proto_values.ts renamed to packages/firestore/src/model/values.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { TypeOrder } from './field_value';
2121
import { assert, fail } from '../util/assert';
2222
import { forEach, keys, size } from '../util/obj';
2323
import { ByteString } from '../util/byte_string';
24+
import { DocumentKey } from './document_key';
2425
import {
2526
numericComparator,
2627
numericEquals,
@@ -359,8 +360,7 @@ function canonifyValue(value: api.Value): string {
359360
} else if ('bytesValue' in value) {
360361
return canonifyByteString(value.bytesValue!);
361362
} else if ('referenceValue' in value) {
362-
// TODO(mrschmidt): Use document key only
363-
return value.referenceValue!;
363+
return canonifyReference(value.referenceValue!);
364364
} else if ('geoPointValue' in value) {
365365
return canonifyGeoPoint(value.geoPointValue!);
366366
} else if ('arrayValue' in value) {
@@ -385,6 +385,10 @@ function canonifyGeoPoint(geoPoint: api.LatLng): string {
385385
return `geo(${geoPoint.latitude},${geoPoint.longitude})`;
386386
}
387387

388+
function canonifyReference(referenceValue: string): string {
389+
return DocumentKey.fromName(referenceValue).toString();
390+
}
391+
388392
function canonifyMap(mapValue: api.MapValue): string {
389393
// Iteration order in JavaScript is not guaranteed. To ensure that we generate
390394
// matching canonical IDs for identical maps, we need to sort the keys.

packages/firestore/src/remote/serializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import {
7676
normalizeByteString,
7777
normalizeNumber,
7878
normalizeTimestamp
79-
} from '../model/proto_values';
79+
} from '../model/values';
8080

8181
const DIRECTIONS = (() => {
8282
const dirs: { [dir: string]: api.OrderDirection } = {};

packages/firestore/test/unit/model/field_value.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,4 @@ describe('FieldValue', () => {
396396
.delete(field(fieldPath))
397397
.build();
398398
}
399-
400399
});

0 commit comments

Comments
 (0)