Skip to content

Commit 2767824

Browse files
Merge 7fb6f2b into aab78f9
2 parents aab78f9 + 7fb6f2b commit 2767824

18 files changed

+31
-178
lines changed

packages/firestore/src/core/snapshot_version.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -24,14 +24,6 @@ import { Timestamp } from '../api/timestamp';
2424
export class SnapshotVersion {
2525
static readonly MIN = new SnapshotVersion(new Timestamp(0, 0));
2626

27-
// TODO(b/34176344): Once we no longer need to use the old alpha protos,
28-
// delete this constructor and use a timestamp-backed version everywhere.
29-
static fromMicroseconds(value: number): SnapshotVersion {
30-
const seconds = Math.floor(value / 1e6);
31-
const nanos = (value % 1e6) * 1e3;
32-
return new SnapshotVersion(new Timestamp(seconds, nanos));
33-
}
34-
3527
static fromTimestamp(value: Timestamp): SnapshotVersion {
3628
return new SnapshotVersion(value);
3729
}

packages/firestore/src/local/encoded_resource_path.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,25 +175,3 @@ export function decodeResourcePath(path: EncodedResourcePath): ResourcePath {
175175

176176
return new ResourcePath(segments);
177177
}
178-
179-
/**
180-
* Computes the prefix successor of the given path, computed by encode above.
181-
* A prefix successor is the first key that cannot be prefixed by the given
182-
* path. It's useful for defining the end of a prefix scan such that all keys
183-
* in the scan have the same prefix.
184-
*
185-
* Note that this is not a general prefix successor implementation, which is
186-
* tricky to get right with Strings, given that they encode down to UTF-8.
187-
* Instead this relies on the fact that all paths encoded by this class are
188-
* always terminated with a separator, and so a successor can always be
189-
* cheaply computed by incrementing the last character of the path.
190-
*/
191-
export function prefixSuccessor(
192-
path: EncodedResourcePath
193-
): EncodedResourcePath {
194-
const c = path.charCodeAt(path.length - 1);
195-
// TODO(mcg): this really should be a general thing, but not worth it right
196-
// now
197-
assert(c === 1, 'successor may only operate on paths generated by encode');
198-
return path.substring(0, path.length - 1) + String.fromCharCode(c + 1);
199-
}

packages/firestore/src/local/local_serializer.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ import * as api from '../protos/firestore_proto_api';
2929
import { JsonProtoSerializer } from '../remote/serializer';
3030
import { assert, fail } from '../util/assert';
3131
import { ByteString } from '../util/byte_string';
32-
33-
import { documentKeySet, DocumentKeySet } from '../model/collections';
3432
import { Target } from '../core/target';
35-
import {
36-
decodeResourcePath,
37-
encodeResourcePath,
38-
EncodedResourcePath
39-
} from './encoded_resource_path';
4033
import {
4134
DbMutationBatch,
4235
DbNoDocument,
@@ -177,31 +170,7 @@ export class LocalSerializer {
177170
mutations
178171
);
179172
}
180-
181-
/*
182-
* Encodes a set of document keys into an array of EncodedResourcePaths.
183-
*/
184-
toDbResourcePaths(keys: DocumentKeySet): EncodedResourcePath[] {
185-
const encodedKeys: EncodedResourcePath[] = [];
186-
187-
keys.forEach(key => {
188-
encodedKeys.push(encodeResourcePath(key.path));
189-
});
190-
191-
return encodedKeys;
192-
}
193-
194-
/** Decodes an array of EncodedResourcePaths into a set of document keys. */
195-
fromDbResourcePaths(encodedPaths: EncodedResourcePath[]): DocumentKeySet {
196-
let keys = documentKeySet();
197-
198-
for (const documentKey of encodedPaths) {
199-
keys = keys.add(new DocumentKey(decodeResourcePath(documentKey)));
200-
}
201-
202-
return keys;
203-
}
204-
173+
205174
/** Decodes a DbTarget into TargetData */
206175
fromDbTarget(dbTarget: DbTarget): TargetData {
207176
const version = this.fromDbTimestamp(dbTarget.readTime);

packages/firestore/src/local/reference_set.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

packages/firestore/src/local/target_data.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -118,18 +118,4 @@ export class TargetData {
118118
this.resumeToken
119119
);
120120
}
121-
122-
isEqual(other: TargetData): boolean {
123-
return (
124-
this.targetId === other.targetId &&
125-
this.purpose === other.purpose &&
126-
this.sequenceNumber === other.sequenceNumber &&
127-
this.snapshotVersion.isEqual(other.snapshotVersion) &&
128-
this.lastLimboFreeSnapshotVersion.isEqual(
129-
other.lastLimboFreeSnapshotVersion
130-
) &&
131-
this.resumeToken.isEqual(other.resumeToken) &&
132-
this.target.isEqual(other.target)
133-
);
134-
}
135121
}

packages/firestore/src/model/mutation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { DocumentKey } from './document_key';
3232
import { ObjectValue, ObjectValueBuilder } from './field_value';
3333
import { FieldPath } from './path';
3434
import { TransformOperation } from './transform_operation';
35-
import { arrayEquals, equals } from '../util/misc';
35+
import { arrayEquals } from '../util/misc';
3636

3737
/**
3838
* Provides a set of fields that can be used to partially patch a document.
@@ -180,7 +180,10 @@ export class Precondition {
180180

181181
isEqual(other: Precondition): boolean {
182182
return (
183-
equals(this.updateTime, other.updateTime) && this.exists === other.exists
183+
this.exists === other.exists &&
184+
(this.updateTime
185+
? !!other.updateTime && this.updateTime.isEqual(other.updateTime)
186+
: !other.updateTime)
184187
);
185188
}
186189
}

packages/firestore/src/remote/existence_filter.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -18,8 +18,4 @@
1818
export class ExistenceFilter {
1919
// TODO(b/33078163): just use simplest form of existence filter for now
2020
constructor(public count: number) {}
21-
22-
isEqual(other: ExistenceFilter): boolean {
23-
return other && other.count === this.count;
24-
}
2521
}

packages/firestore/src/util/async_queue.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,6 @@ export class AsyncQueue {
289289
const message = error.stack || error.message || '';
290290
logError('INTERNAL UNHANDLED ERROR: ', message);
291291

292-
// Escape the promise chain and throw the error globally so that
293-
// e.g. any global crash reporting library detects and reports it.
294-
// (but not for simulated errors in our tests since this breaks mocha)
295-
if (message.indexOf('Firestore Test Simulated Error') < 0) {
296-
setTimeout(() => {
297-
throw error;
298-
}, 0);
299-
}
300-
301292
// Re-throw the error so that this.tail becomes a rejected Promise and
302293
// all further attempts to chain (via .then) will just short-circuit
303294
// and return the rejected Promise.

packages/firestore/src/util/misc.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,10 @@ export function primitiveComparator<T>(left: T, right: T): number {
5656
return 0;
5757
}
5858

59-
/** Duck-typed interface for objects that have an isEqual() method. */
6059
export interface Equatable<T> {
6160
isEqual(other: T): boolean;
6261
}
6362

64-
/** Helper to compare nullable (or undefined-able) objects using isEqual(). */
65-
export function equals<T>(
66-
left: Equatable<T> | null | undefined,
67-
right: T | null | undefined
68-
): boolean {
69-
if (left !== null && left !== undefined) {
70-
return !!(right && left.isEqual(right));
71-
} else {
72-
// HACK: Explicitly cast since TypeScript's type narrowing apparently isn't
73-
// smart enough.
74-
return (left as null | undefined) === right;
75-
}
76-
}
77-
7863
/** Helper to compare arrays using isEqual(). */
7964
export function arrayEquals<T>(
8065
left: T[],

packages/firestore/src/util/sorted_set.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -31,18 +31,6 @@ export class SortedSet<T> {
3131
this.data = new SortedMap<T, boolean>(this.comparator);
3232
}
3333

34-
/**
35-
* Creates a SortedSet from the keys of the map.
36-
* This is currently implemented as an O(n) copy.
37-
*/
38-
static fromMapKeys<K, V>(map: SortedMap<K, V>): SortedSet<K> {
39-
let keys = new SortedSet<K>(map.comparator);
40-
map.forEach(key => {
41-
keys = keys.add(key);
42-
});
43-
return keys;
44-
}
45-
4634
has(elem: T): boolean {
4735
return this.data.get(elem) !== null;
4836
}

packages/firestore/test/unit/local/encoded_resource_path.test.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
import { expect } from 'chai';
1919
import {
2020
decodeResourcePath,
21-
encodeResourcePath,
22-
prefixSuccessor
21+
encodeResourcePath
2322
} from '../../../src/local/encoded_resource_path';
2423
import { PersistencePromise } from '../../../src/local/persistence_promise';
2524
import {
@@ -128,23 +127,8 @@ describe('EncodedResourcePath', () => {
128127
path('food')
129128
]);
130129
});
131-
132-
it('prefixes successors correctly', async () => {
133-
assertPrefixSuccessorEquals('\u0001\u0002', ResourcePath.EMPTY_PATH);
134-
assertPrefixSuccessorEquals(
135-
'foo' + sep + 'bar\u0001\u0002',
136-
path('foo/bar')
137-
);
138-
});
139130
});
140131

141-
function assertPrefixSuccessorEquals(
142-
expected: string,
143-
path: ResourcePath
144-
): void {
145-
expect(prefixSuccessor(encodeResourcePath(path))).to.deep.equal(expected);
146-
}
147-
148132
function assertEncoded(expected: string, path: ResourcePath): Promise<void> {
149133
const encoded = encodeResourcePath(path);
150134
expect(encoded).to.deep.equal(expected);

packages/firestore/test/unit/local/lru_garbage_collector.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { Timestamp } from '../../../src/api/timestamp';
2020
import { User } from '../../../src/auth/user';
2121
import { ListenSequence } from '../../../src/core/listen_sequence';
2222
import { Query } from '../../../src/core/query';
23-
import { SnapshotVersion } from '../../../src/core/snapshot_version';
2423
import { ListenSequenceNumber, TargetId } from '../../../src/core/types';
2524
import { IndexedDbPersistence } from '../../../src/local/indexeddb_persistence';
2625
import {
@@ -49,7 +48,7 @@ import {
4948
SetMutation
5049
} from '../../../src/model/mutation';
5150
import { AsyncQueue } from '../../../src/util/async_queue';
52-
import { key, path, wrapObject } from '../../util/helpers';
51+
import { key, path, version, wrapObject } from '../../util/helpers';
5352
import { SortedMap } from '../../../src/util/sorted_map';
5453
import * as PersistenceTestHelpers from './persistence_test_helpers';
5554
import { primitiveComparator } from '../../../src/util/misc';
@@ -246,7 +245,7 @@ function genericLruGarbageCollectorTests(
246245
const key = nextTestDocumentKey();
247246
return new Document(
248247
key,
249-
SnapshotVersion.fromMicroseconds(1000),
248+
version(1000),
250249
wrapObject({
251250
foo: 3,
252251
bar: false
@@ -784,7 +783,7 @@ function genericLruGarbageCollectorTests(
784783
txn => {
785784
const doc = new Document(
786785
middleDocToUpdate,
787-
SnapshotVersion.fromMicroseconds(2000),
786+
version(2000),
788787
wrapObject({
789788
foo: 4,
790789
bar: true

packages/firestore/test/unit/local/reference_set.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

packages/firestore/test/unit/local/target_cache.test.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -92,12 +92,7 @@ describe('IndexedDbTargetCache', () => {
9292
originalSequenceNumber
9393
);
9494
const actualTargetData = await targetCache2.getTargetData(target);
95-
96-
if (process.env.USE_MOCK_PERSISTENCE !== 'YES') {
97-
// TODO(b/140573486): This fails on Node with persistence since the
98-
// resume token is read back as a string.
99-
expect(targetData.isEqual(actualTargetData!)).to.be.true;
100-
}
95+
expect(targetData).to.deep.equal(actualTargetData);
10196

10297
const actualSnapshotVersion = await targetCache2.getLastRemoteSnapshotVersion();
10398
expect(snapshotVersion.isEqual(actualSnapshotVersion)).to.be.true;
@@ -127,12 +122,12 @@ function genericTargetCacheTests(
127122
function testTargetData(
128123
target: Target,
129124
targetId: TargetId,
130-
version?: number
125+
testVersion?: number
131126
): TargetData {
132-
if (version === undefined) {
133-
version = 0;
127+
if (testVersion === undefined) {
128+
testVersion = 0;
134129
}
135-
const snapshotVersion = SnapshotVersion.fromMicroseconds(version);
130+
const snapshotVersion = version(testVersion);
136131
const resumeToken = resumeTokenForSnapshot(snapshotVersion);
137132
return new TargetData(
138133
target,

packages/firestore/test/unit/remote/serializer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ describe('Serializer', () => {
14201420
document: {
14211421
name: s.toName(key('coll/1')),
14221422
fields: wrap({ foo: 'bar' }).mapValue!.fields,
1423-
updateTime: s.toVersion(SnapshotVersion.fromMicroseconds(5))
1423+
updateTime: s.toVersion(version(5))
14241424
},
14251425
targetIds: [1, 2]
14261426
}
@@ -1440,7 +1440,7 @@ describe('Serializer', () => {
14401440
document: {
14411441
name: s.toName(key('coll/1')),
14421442
fields: wrap({ foo: 'bar' }).mapValue!.fields,
1443-
updateTime: s.toVersion(SnapshotVersion.fromMicroseconds(5))
1443+
updateTime: s.toVersion(version(5))
14441444
},
14451445
targetIds: [2],
14461446
removedTargetIds: [1]
@@ -1459,7 +1459,7 @@ describe('Serializer', () => {
14591459
const actual = s.fromWatchChange({
14601460
documentDelete: {
14611461
document: s.toName(key('coll/1')),
1462-
readTime: s.toVersion(SnapshotVersion.fromMicroseconds(5)),
1462+
readTime: s.toVersion(version(5)),
14631463
removedTargetIds: [1, 2]
14641464
}
14651465
});

packages/firestore/test/unit/util/async_queue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('AsyncQueue', () => {
7272

7373
it('handles failures', () => {
7474
const queue = new AsyncQueue();
75-
const expected = new Error('Firestore Test Simulated Error');
75+
const expected = new Error('Firit cestore Test Simulated Error');
7676

7777
// Disable logging for this test to avoid the assertion being logged
7878
const oldLogLevel = getLogLevel();

0 commit comments

Comments
 (0)