Skip to content

Commit 80b2aa6

Browse files
Rename proto_values->values, create values.test.ts (#2750)
1 parent db12269 commit 80b2aa6

File tree

8 files changed

+437
-437
lines changed

8 files changed

+437
-437
lines changed

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/server_timestamps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as api from '../protos/firestore_proto_api';
22
import { Timestamp } from '../api/timestamp';
3-
import { normalizeTimestamp } from './proto_values';
3+
import { normalizeTimestamp } from './values';
44

55
/**
66
* Represents a locally-applied ServerTimestamp.

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,
@@ -351,8 +352,7 @@ function canonifyValue(value: api.Value): string {
351352
} else if ('bytesValue' in value) {
352353
return canonifyByteString(value.bytesValue!);
353354
} else if ('referenceValue' in value) {
354-
// TODO(mrschmidt): Use document key only
355-
return value.referenceValue!;
355+
return canonifyReference(value.referenceValue!);
356356
} else if ('geoPointValue' in value) {
357357
return canonifyGeoPoint(value.geoPointValue!);
358358
} else if ('arrayValue' in value) {
@@ -377,6 +377,10 @@ function canonifyGeoPoint(geoPoint: api.LatLng): string {
377377
return `geo(${geoPoint.latitude},${geoPoint.longitude})`;
378378
}
379379

380+
function canonifyReference(referenceValue: string): string {
381+
return DocumentKey.fromName(referenceValue).toString();
382+
}
383+
380384
function canonifyMap(mapValue: api.MapValue): string {
381385
// Iteration order in JavaScript is not guaranteed. To ensure that we generate
382386
// 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 } = {};

0 commit comments

Comments
 (0)