Skip to content

Commit a6c63c3

Browse files
Remove remaining namespace imports
1 parent 401e974 commit a6c63c3

12 files changed

+88
-71
lines changed

packages/firestore/src/local/encoded_resource_path.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const encodedEscape = '\u0011';
7272
/**
7373
* Encodes a resource path into a IndexedDb-compatible string form.
7474
*/
75-
export function encode(path: ResourcePath): EncodedResourcePath {
75+
export function encodeResourcePath(path: ResourcePath): EncodedResourcePath {
7676
let result = '';
7777
for (let i = 0; i < path.length; i++) {
7878
if (result.length > 0) {
@@ -114,7 +114,7 @@ function encodeSeparator(result: string): string {
114114
* decoding resource names from the server; those are One Platform format
115115
* strings.
116116
*/
117-
export function decode(path: EncodedResourcePath): ResourcePath {
117+
export function decodeResourcePath(path: EncodedResourcePath): ResourcePath {
118118
// Event the empty path must encode as a path of at least length 2. A path
119119
// with exactly 2 must be the empty path.
120120
const length = path.length;

packages/firestore/src/local/indexeddb_index_manager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import { ResourcePath } from '../model/path';
1919
import { assert } from '../util/assert';
2020
import { immediateSuccessor } from '../util/misc';
21-
import { decode, encode } from './encoded_resource_path';
21+
import {
22+
decodeResourcePath,
23+
encodeResourcePath
24+
} from './encoded_resource_path';
2225
import { IndexManager } from './index_manager';
2326
import { IndexedDbPersistence } from './indexeddb_persistence';
2427
import { DbCollectionParent, DbCollectionParentKey } from './indexeddb_schema';
@@ -64,7 +67,7 @@ export class IndexedDbIndexManager implements IndexManager {
6467

6568
const collectionParent: DbCollectionParent = {
6669
collectionId,
67-
parent: encode(parentPath)
70+
parent: encodeResourcePath(parentPath)
6871
};
6972
return collectionParentsStore(transaction).put(collectionParent);
7073
}
@@ -93,7 +96,7 @@ export class IndexedDbIndexManager implements IndexManager {
9396
if (entry.collectionId !== collectionId) {
9497
break;
9598
}
96-
parentPaths.push(decode(entry.parent));
99+
parentPaths.push(decodeResourcePath(entry.parent));
97100
}
98101
return parentPaths;
99102
});

packages/firestore/src/local/indexeddb_mutation_queue.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ import { primitiveComparator } from '../util/misc';
2929
import { ByteString } from '../util/byte_string';
3030
import { SortedMap } from '../util/sorted_map';
3131
import { SortedSet } from '../util/sorted_set';
32-
33-
import * as EncodedResourcePath from './encoded_resource_path';
32+
import { decodeResourcePath } from './encoded_resource_path';
3433
import { IndexManager } from './index_manager';
3534
import {
3635
IndexedDbPersistence,
@@ -336,7 +335,7 @@ export class IndexedDbMutationQueue implements MutationQueue {
336335
// the rows for documentKey will occur before any rows for
337336
// documents nested in a subcollection beneath documentKey so we
338337
// can stop as soon as we hit any such row.
339-
const path = EncodedResourcePath.decode(encodedPath);
338+
const path = decodeResourcePath(encodedPath);
340339
if (userID !== this.userId || !documentKey.path.isEqual(path)) {
341340
control.done();
342341
return;
@@ -389,7 +388,7 @@ export class IndexedDbMutationQueue implements MutationQueue {
389388
// the rows for documentKey will occur before any rows for
390389
// documents nested in a subcollection beneath documentKey so we
391390
// can stop as soon as we hit any such row.
392-
const path = EncodedResourcePath.decode(encodedPath);
391+
const path = decodeResourcePath(encodedPath);
393392
if (userID !== this.userId || !documentKey.path.isEqual(path)) {
394393
control.done();
395394
return;
@@ -447,7 +446,7 @@ export class IndexedDbMutationQueue implements MutationQueue {
447446
return documentMutationsStore(transaction)
448447
.iterate({ range: indexStart }, (indexKey, _, control) => {
449448
const [userID, encodedPath, batchID] = indexKey;
450-
const path = EncodedResourcePath.decode(encodedPath);
449+
const path = decodeResourcePath(encodedPath);
451450
if (userID !== this.userId || !queryPath.isPrefixOf(path)) {
452451
control.done();
453452
return;
@@ -544,7 +543,7 @@ export class IndexedDbMutationQueue implements MutationQueue {
544543
control.done();
545544
return;
546545
} else {
547-
const path = EncodedResourcePath.decode(key[1]);
546+
const path = decodeResourcePath(key[1]);
548547
danglingMutationReferences.push(path);
549548
}
550549
})

packages/firestore/src/local/indexeddb_persistence.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ import { AsyncQueue, TimerId } from '../util/async_queue';
2828
import { Code, FirestoreError } from '../util/error';
2929
import { logDebug, logError } from '../util/log';
3030
import { CancelablePromise } from '../util/promise';
31-
32-
import { decode, encode, EncodedResourcePath } from './encoded_resource_path';
31+
import {
32+
decodeResourcePath,
33+
encodeResourcePath,
34+
EncodedResourcePath
35+
} from './encoded_resource_path';
3336
import { IndexedDbIndexManager } from './indexeddb_index_manager';
3437
import {
3538
IndexedDbMutationQueue,
@@ -1244,7 +1247,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
12441247
// if nextToReport is valid, report it, this is a new key so the
12451248
// last one must not be a member of any targets.
12461249
if (nextToReport !== ListenSequence.INVALID) {
1247-
f(new DocumentKey(decode(nextPath)), nextToReport);
1250+
f(new DocumentKey(decodeResourcePath(nextPath)), nextToReport);
12481251
}
12491252
// set nextToReport to be this sequence number. It's the next one we
12501253
// might report, if we don't find any targets for this document.
@@ -1264,7 +1267,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
12641267
// need to check if the last key we iterated over was an orphaned
12651268
// document and report it.
12661269
if (nextToReport !== ListenSequence.INVALID) {
1267-
f(new DocumentKey(decode(nextPath)), nextToReport);
1270+
f(new DocumentKey(decodeResourcePath(nextPath)), nextToReport);
12681271
}
12691272
});
12701273
}
@@ -1275,7 +1278,7 @@ export class IndexedDbLruDelegate implements ReferenceDelegate, LruDelegate {
12751278
}
12761279

12771280
function sentinelKey(key: DocumentKey): [TargetId, EncodedResourcePath] {
1278-
return [0, encode(key.path)];
1281+
return [0, encodeResourcePath(key.path)];
12791282
}
12801283

12811284
/**
@@ -1286,7 +1289,7 @@ function sentinelRow(
12861289
key: DocumentKey,
12871290
sequenceNumber: ListenSequenceNumber
12881291
): DbTargetDocument {
1289-
return new DbTargetDocument(0, encode(key.path), sequenceNumber);
1292+
return new DbTargetDocument(0, encodeResourcePath(key.path), sequenceNumber);
12901293
}
12911294

12921295
function writeSentinelKey(

packages/firestore/src/local/indexeddb_schema.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import { assert } from '../util/assert';
2222

2323
import { SnapshotVersion } from '../core/snapshot_version';
2424
import { BATCHID_UNKNOWN } from '../model/mutation_batch';
25-
import { decode, encode, EncodedResourcePath } from './encoded_resource_path';
25+
import {
26+
decodeResourcePath,
27+
encodeResourcePath,
28+
EncodedResourcePath
29+
} from './encoded_resource_path';
2630
import { removeMutationBatch } from './indexeddb_mutation_queue';
2731
import { getHighestListenSequenceNumber } from './indexeddb_target_cache';
2832
import { dbDocumentSize } from './indexeddb_remote_document_cache';
@@ -233,7 +237,11 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
233237
path: ResourcePath
234238
): PersistencePromise<void> => {
235239
return documentTargetStore.put(
236-
new DbTargetDocument(0, encode(path), currentSequenceNumber)
240+
new DbTargetDocument(
241+
0,
242+
encodeResourcePath(path),
243+
currentSequenceNumber
244+
)
237245
);
238246
};
239247

@@ -280,7 +288,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
280288
const parentPath = collectionPath.popLast();
281289
return collectionParentsStore.put({
282290
collectionId,
283-
parent: encode(parentPath)
291+
parent: encodeResourcePath(parentPath)
284292
});
285293
}
286294
};
@@ -299,7 +307,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
299307
DbDocumentMutation.store
300308
)
301309
.iterate({ keysOnly: true }, ([userID, encodedPath, batchId], _) => {
302-
const path = decode(encodedPath);
310+
const path = decodeResourcePath(encodedPath);
303311
return addEntry(path.popLast());
304312
});
305313
});
@@ -318,7 +326,7 @@ export class SchemaConverter implements SimpleDbSchemaConverter {
318326
}
319327

320328
function sentinelKey(path: ResourcePath): DbTargetDocumentKey {
321-
return [0, encode(path)];
329+
return [0, encodeResourcePath(path)];
322330
}
323331

324332
/**
@@ -559,7 +567,7 @@ export class DbDocumentMutation {
559567
userId: string,
560568
path: ResourcePath
561569
): [string, EncodedResourcePath] {
562-
return [userId, encode(path)];
570+
return [userId, encodeResourcePath(path)];
563571
}
564572

565573
/**
@@ -571,7 +579,7 @@ export class DbDocumentMutation {
571579
path: ResourcePath,
572580
batchId: BatchId
573581
): DbDocumentMutationKey {
574-
return [userId, encode(path), batchId];
582+
return [userId, encodeResourcePath(path), batchId];
575583
}
576584

577585
/**

packages/firestore/src/local/indexeddb_target_cache.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import { DocumentKeySet, documentKeySet } from '../model/collections';
2222
import { DocumentKey } from '../model/document_key';
2323
import { assert } from '../util/assert';
2424
import { immediateSuccessor } from '../util/misc';
25-
2625
import { TargetIdGenerator } from '../core/target_id_generator';
27-
import * as EncodedResourcePath from './encoded_resource_path';
26+
import {
27+
decodeResourcePath,
28+
encodeResourcePath
29+
} from './encoded_resource_path';
2830
import {
2931
IndexedDbLruDelegate,
3032
IndexedDbPersistence,
@@ -280,7 +282,7 @@ export class IndexedDbTargetCache implements TargetCache {
280282
const promises: Array<PersistencePromise<void>> = [];
281283
const store = documentTargetStore(txn);
282284
keys.forEach(key => {
283-
const path = EncodedResourcePath.encode(key.path);
285+
const path = encodeResourcePath(key.path);
284286
promises.push(store.put(new DbTargetDocument(targetId, path)));
285287
promises.push(this.referenceDelegate.addReference(txn, key));
286288
});
@@ -296,7 +298,7 @@ export class IndexedDbTargetCache implements TargetCache {
296298
// IndexedDb.
297299
const store = documentTargetStore(txn);
298300
return PersistencePromise.forEach(keys, (key: DocumentKey) => {
299-
const path = EncodedResourcePath.encode(key.path);
301+
const path = encodeResourcePath(key.path);
300302
return PersistencePromise.waitFor([
301303
store.delete([targetId, path]),
302304
this.referenceDelegate.removeReference(txn, key)
@@ -333,7 +335,7 @@ export class IndexedDbTargetCache implements TargetCache {
333335

334336
return store
335337
.iterate({ range, keysOnly: true }, (key, _, control) => {
336-
const path = EncodedResourcePath.decode(key[1]);
338+
const path = decodeResourcePath(key[1]);
337339
const docKey = new DocumentKey(path);
338340
result = result.add(docKey);
339341
})
@@ -344,7 +346,7 @@ export class IndexedDbTargetCache implements TargetCache {
344346
txn: PersistenceTransaction,
345347
key: DocumentKey
346348
): PersistencePromise<boolean> {
347-
const path = EncodedResourcePath.encode(key.path);
349+
const path = encodeResourcePath(key.path);
348350
const range = IDBKeyRange.bound(
349351
[path],
350352
[immediateSuccessor(path)],

packages/firestore/src/local/local_serializer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ import { ByteString } from '../util/byte_string';
3232

3333
import { documentKeySet, DocumentKeySet } from '../model/collections';
3434
import { Target } from '../core/target';
35-
import { decode, encode, EncodedResourcePath } from './encoded_resource_path';
35+
import {
36+
decodeResourcePath,
37+
encodeResourcePath,
38+
EncodedResourcePath
39+
} from './encoded_resource_path';
3640
import {
3741
DbMutationBatch,
3842
DbNoDocument,
@@ -181,7 +185,7 @@ export class LocalSerializer {
181185
const encodedKeys: EncodedResourcePath[] = [];
182186

183187
keys.forEach(key => {
184-
encodedKeys.push(encode(key.path));
188+
encodedKeys.push(encodeResourcePath(key.path));
185189
});
186190

187191
return encodedKeys;
@@ -192,7 +196,7 @@ export class LocalSerializer {
192196
let keys = documentKeySet();
193197

194198
for (const documentKey of encodedPaths) {
195-
keys = keys.add(new DocumentKey(decode(documentKey)));
199+
keys = keys.add(new DocumentKey(decodeResourcePath(documentKey)));
196200
}
197201

198202
return keys;

packages/firestore/src/local/memory_persistence.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ import { assert, fail } from '../util/assert';
2222
import { Code, FirestoreError } from '../util/error';
2323
import { logDebug } from '../util/log';
2424
import { ObjectMap } from '../util/obj_map';
25-
import { encode } from './encoded_resource_path';
25+
import { encodeResourcePath } from './encoded_resource_path';
2626
import {
2727
ActiveTargets,
2828
LruDelegate,
2929
LruGarbageCollector,
3030
LruParams
3131
} from './lru_garbage_collector';
32-
3332
import { DatabaseInfo } from '../core/database_info';
3433
import { PersistenceSettings } from '../core/firestore_client';
3534
import { ListenSequence } from '../core/listen_sequence';
@@ -330,7 +329,7 @@ export class MemoryLruDelegate implements ReferenceDelegate, LruDelegate {
330329
private orphanedSequenceNumbers: ObjectMap<
331330
DocumentKey,
332331
ListenSequenceNumber
333-
> = new ObjectMap(k => encode(k.path));
332+
> = new ObjectMap(k => encodeResourcePath(k.path));
334333

335334
readonly garbageCollector: LruGarbageCollector;
336335

packages/firestore/src/platform_node/load_protos.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as protoLoader from '@grpc/proto-loader';
19-
import * as grpc from 'grpc';
20-
import * as path from 'path';
18+
import { loadSync } from '@grpc/proto-loader';
19+
import { loadPackageDefinition, GrpcObject } from 'grpc';
20+
import { join, resolve, isAbsolute } from 'path';
2121
// only used in tests
2222
// eslint-disable-next-line import/no-extraneous-dependencies
23-
import * as ProtobufJS from 'protobufjs';
23+
import { IConversionOptions, Root } from 'protobufjs';
2424

2525
/** Used by tests so we can match @grpc/proto-loader behavior. */
26-
export const protoLoaderOptions: ProtobufJS.IConversionOptions = {
26+
export const protoLoaderOptions: IConversionOptions = {
2727
longs: String,
2828
enums: String,
2929
defaults: true,
@@ -35,43 +35,37 @@ export const protoLoaderOptions: ProtobufJS.IConversionOptions = {
3535
*
3636
* @returns The GrpcObject representing our protos.
3737
*/
38-
export function loadProtos(): grpc.GrpcObject {
39-
const root = path.resolve(
38+
export function loadProtos(): GrpcObject {
39+
const root = resolve(
4040
__dirname,
4141
process.env.FIRESTORE_PROTO_ROOT || '../protos'
4242
);
43-
const firestoreProtoFile = path.join(
44-
root,
45-
'google/firestore/v1/firestore.proto'
46-
);
43+
const firestoreProtoFile = join(root, 'google/firestore/v1/firestore.proto');
4744

4845
const packageDefinition = loadSync(firestoreProtoFile, {
4946
...protoLoaderOptions,
5047
includeDirs: [root]
5148
});
5249

53-
return grpc.loadPackageDefinition(packageDefinition);
50+
return loadPackageDefinition(packageDefinition);
5451
}
5552

5653
/** Used by tests so we can directly create ProtobufJS proto message objects from JSON protos. */
57-
export function loadRawProtos(): ProtobufJS.Root {
58-
const root = path.resolve(
54+
export function loadRawProtos(): Root {
55+
const root = resolve(
5956
__dirname,
6057
process.env.FIRESTORE_PROTO_ROOT || '../protos'
6158
);
62-
const firestoreProtoFile = path.join(
63-
root,
64-
'google/firestore/v1/firestore.proto'
65-
);
59+
const firestoreProtoFile = join(root, 'google/firestore/v1/firestore.proto');
6660

67-
const protoRoot = new ProtobufJS.Root();
61+
const protoRoot = new Root();
6862
// Override the resolvePath function to look for protos in the 'root'
6963
// directory.
7064
protoRoot.resolvePath = (origin: string, target: string) => {
71-
if (path.isAbsolute(target)) {
65+
if (isAbsolute(target)) {
7266
return target;
7367
}
74-
return path.join(root, target);
68+
return join(root, target);
7569
};
7670

7771
protoRoot.loadSync(firestoreProtoFile);

0 commit comments

Comments
 (0)