Skip to content

Remove Cyclic Dependencies #4160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
5599705
Move FieldMask
schmidt-sebastian Dec 3, 2020
b8efc13
Move normalizeTimestamp
schmidt-sebastian Dec 3, 2020
6af13ee
Move TypeOrder
schmidt-sebastian Dec 3, 2020
f315c89
Move query
schmidt-sebastian Dec 3, 2020
bf8f746
Move toDouble, toInteger
schmidt-sebastian Dec 3, 2020
fb16170
Move Serializer
schmidt-sebastian Dec 3, 2020
b682857
Move PersistenceTransaction
schmidt-sebastian Dec 3, 2020
6e32f92
Move ExponentialBackoff
schmidt-sebastian Dec 3, 2020
e2846a9
Move LocalStoreImpl
schmidt-sebastian Dec 3, 2020
8fcc47b
LruGarbageCollector
schmidt-sebastian Dec 3, 2020
3456d83
Move PRIMARY_LEASE_LOST_ERROR_MSG
schmidt-sebastian Dec 3, 2020
0fba935
BundleReader
schmidt-sebastian Dec 3, 2020
3e69755
Move BundleLoader
schmidt-sebastian Dec 3, 2020
a4758a0
IndexedDbBundleCache
schmidt-sebastian Dec 3, 2020
1b1a67d
IndexedDbIndexManager
schmidt-sebastian Dec 3, 2020
11df697
Clean up IndexedDbPersistence
schmidt-sebastian Dec 3, 2020
1159302
Remove unused imports
schmidt-sebastian Dec 3, 2020
e5b9a81
removeMutationBatch/DocumentKey
schmidt-sebastian Dec 3, 2020
b639a29
IndexedDbSchemaConverter
schmidt-sebastian Dec 3, 2020
a503100
IndexedDbBundleCache
schmidt-sebastian Dec 3, 2020
cccabf2
MemoryTargetCache
schmidt-sebastian Dec 3, 2020
0b518f0
Move FieldValue
schmidt-sebastian Dec 3, 2020
cb07140
Move FieldValue implementations
schmidt-sebastian Dec 3, 2020
d9c66ec
Fix Components
schmidt-sebastian Dec 3, 2020
c06dd59
Make Reference unique
schmidt-sebastian Dec 3, 2020
d03efd3
Move ensureClientConfigured/configureClient
schmidt-sebastian Dec 3, 2020
c2f951e
Move SnapshotMetadata
schmidt-sebastian Dec 3, 2020
2c0faa2
Fix lite/.../query.ts
schmidt-sebastian Dec 3, 2020
97b2189
Move UserDataWriter
schmidt-sebastian Dec 3, 2020
ec5ac56
Add onwarn
schmidt-sebastian Dec 3, 2020
fef7824
Cleanup
schmidt-sebastian Dec 3, 2020
7fb2de0
Fix unit tests
schmidt-sebastian Dec 3, 2020
2e666fe
Cleanup imports/exports
schmidt-sebastian Dec 3, 2020
fde4f7f
FieldValue exports
schmidt-sebastian Dec 3, 2020
f324093
Manual cleanup
schmidt-sebastian Dec 4, 2020
a1f8f77
Merge
schmidt-sebastian Dec 4, 2020
e66d39d
Add separate FieldMask
schmidt-sebastian Dec 4, 2020
57ff562
Add TypeOrder comment
schmidt-sebastian Dec 4, 2020
a4001fc
s/numberSerializer/valueSerializer
schmidt-sebastian Dec 4, 2020
618017d
AsyncQueue/AsyncQueueImpl
schmidt-sebastian Dec 5, 2020
a35b1d6
s/_methods/_impl
schmidt-sebastian Dec 5, 2020
a8e3409
getStore
schmidt-sebastian Dec 5, 2020
0294aa3
BATCHID_UNKNOWN
schmidt-sebastian Dec 5, 2020
6482dae
removeMutationBatch
schmidt-sebastian Dec 5, 2020
b15d996
DocumentKey
schmidt-sebastian Dec 5, 2020
045f33f
FirestoreService
schmidt-sebastian Dec 5, 2020
55fb014
Fix bad merge
schmidt-sebastian Dec 5, 2020
d41071c
Feedback
schmidt-sebastian Dec 8, 2020
9f9cfaf
Merge
schmidt-sebastian Dec 8, 2020
25d414c
Fix bundles
schmidt-sebastian Dec 8, 2020
d180871
Undo API Extractor
schmidt-sebastian Dec 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/firestore/exp/src/api/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import { DocumentKey } from '../../../src/model/document_key';
import { Document } from '../../../src/model/document';
import { AbstractUserDataWriter } from '../../../src/api/user_data_writer';
import {
Expand All @@ -38,6 +37,7 @@ import { SnapshotListenOptions } from './reference';
import { UntypedFirestoreDataConverter } from '../../../src/api/user_data_reader';
import { debugAssert, fail } from '../../../src/util/assert';
import { newQueryComparator } from '../../../src/core/query';
import { DocumentKey } from '../../../src/model/path';

/**
* Converter used by `withConverter()` to transform user objects of type `T`
Expand Down Expand Up @@ -176,9 +176,9 @@ export interface DocumentChange<T = DocumentData> {
* access will return 'undefined'. You can use the `exists()` method to
* explicitly verify a document's existence.
*/
export class DocumentSnapshot<
T = DocumentData
> extends LiteDocumentSnapshot<T> {
export class DocumentSnapshot<T = DocumentData> extends LiteDocumentSnapshot<
T
> {
private readonly _firestoreImpl: FirebaseFirestore;

/**
Expand Down Expand Up @@ -291,9 +291,9 @@ export class DocumentSnapshot<
* `exists` property will always be true and `data()` will never return
* 'undefined'.
*/
export class QueryDocumentSnapshot<
T = DocumentData
> extends DocumentSnapshot<T> {
export class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<
T
> {
/**
* Retrieves all fields in the document as an `Object`.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { Value as ProtoValue } from '../../../src/protos/firestore_proto_api';

import { Document } from '../../../src/model/document';
import { DocumentKey } from '../../../src/model/document_key';
import { FirebaseFirestore } from './database';
import {
ParsedUpdateData,
Expand Down Expand Up @@ -47,6 +46,7 @@ import {
queryWithStartAt
} from '../../../src/core/query';
import {
DocumentKey,
FieldPath as InternalFieldPath,
ResourcePath
} from '../../../src/model/path';
Expand Down
12 changes: 7 additions & 5 deletions packages/firestore/lite/src/api/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import {
SetOptions
} from './reference';
import { FieldPath } from './field_path';
import { DocumentKey } from '../../../src/model/document_key';
import { Document } from '../../../src/model/document';
import { AbstractUserDataWriter } from '../../../src/api/user_data_writer';
import { FieldPath as InternalFieldPath } from '../../../src/model/path';
import {
DocumentKey,
FieldPath as InternalFieldPath
} from '../../../src/model/path';
import {
fieldPathFromDotSeparatedString,
UntypedFirestoreDataConverter
Expand Down Expand Up @@ -211,9 +213,9 @@ export class DocumentSnapshot<T = DocumentData> {
* `exists` property will always be true and `data()` will never return
* 'undefined'.
*/
export class QueryDocumentSnapshot<
T = DocumentData
> extends DocumentSnapshot<T> {
export class QueryDocumentSnapshot<T = DocumentData> extends DocumentSnapshot<
T
> {
/**
* Retrieves all fields in the document as an `Object`.
*
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import {
firestoreClientGetNamedQuery,
firestoreClientLoadBundle
} from '../core/firestore_client';
import { DocumentKey } from '../model/document_key';
import { FieldPath, ResourcePath } from '../model/path';
import { DocumentKey, FieldPath, ResourcePath } from '../model/path';
import { debugAssert } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import {
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/src/api/user_data_reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from '../protos/firestore_proto_api';
import { Timestamp } from './timestamp';
import { DatabaseId } from '../core/database_info';
import { DocumentKey } from '../model/document_key';
import {
FieldTransform,
Mutation,
Expand All @@ -36,7 +35,7 @@ import {
SetMutation,
TransformMutation
} from '../model/mutation';
import { FieldPath as InternalFieldPath } from '../model/path';
import { DocumentKey, FieldPath as InternalFieldPath } from '../model/path';
import { debugAssert, fail } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import { isPlainObject, valueDescription } from '../util/input_validation';
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/src/api/user_data_writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ import {
import { GeoPoint } from './geo_point';
import { Timestamp } from './timestamp';
import { DatabaseId } from '../core/database_info';
import { DocumentKey } from '../model/document_key';
import { typeOrder } from '../model/values';
import {
getLocalWriteTime,
getPreviousValue
} from '../model/server_timestamps';
import { fail, hardAssert } from '../util/assert';
import { forEach } from '../util/obj';
import { ResourcePath } from '../model/path';
import { DocumentKey, ResourcePath } from '../model/path';
import { isValidResourceName } from '../remote/serializer';
import { logError } from '../util/log';
import { ByteString } from '../util/byte_string';
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import { User } from '../auth/user';
import { LocalStore } from '../local/local_store';
import { Document, NoDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { Mutation } from '../model/mutation';
import {
RemoteStore,
Expand Down Expand Up @@ -84,6 +83,7 @@ import {
readLocalDocument
} from '../local/local_store_impl';
import { newBundleReader } from '../util/bundle_reader_impl';
import { DocumentKey } from '../model/path';

const LOG_TAG = 'FirestoreClient';
export const MAX_CONCURRENT_LIMBO_RESOLUTIONS = 100;
Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/src/core/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/

import { compareDocumentsByField, Document } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { FieldPath, ResourcePath } from '../model/path';
import { DocumentKey, FieldPath, ResourcePath } from '../model/path';
import { debugAssert, debugCast, fail } from '../util/assert';
import { isNullOrUndefined } from '../util/types';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/sync_engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
MaybeDocumentMap
} from '../model/collections';
import { MaybeDocument, NoDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { Mutation } from '../model/mutation';
import { BATCHID_UNKNOWN, MutationBatchResult } from '../model/mutation_batch';
import { RemoteEvent, TargetChange } from '../remote/remote_event';
Expand Down Expand Up @@ -107,6 +106,7 @@ import {
removeCachedMutationBatchMetadata,
saveBundle
} from '../local/local_store_impl';
import { DocumentKey } from '../model/path';

const LOG_TAG = 'SyncEngine';

Expand Down
3 changes: 1 addition & 2 deletions packages/firestore/src/core/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* limitations under the License.
*/

import { DocumentKey } from '../model/document_key';
import { FieldPath, ResourcePath } from '../model/path';
import { DocumentKey, FieldPath, ResourcePath } from '../model/path';
import { isNullOrUndefined } from '../util/types';
import { debugAssert, debugCast, fail } from '../util/assert';
import { Value as ProtoValue } from '../protos/firestore_proto_api';
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { ParsedSetData, ParsedUpdateData } from '../api/user_data_reader';
import { Document, MaybeDocument, NoDocument } from '../model/document';

import { DocumentKey } from '../model/document_key';
import {
DeleteMutation,
Mutation,
Expand All @@ -33,6 +32,7 @@ import {
import { fail, debugAssert } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import { SnapshotVersion } from './snapshot_version';
import { DocumentKey } from '../model/path';

/**
* Internal transaction object responsible for accumulating the mutations to
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
MaybeDocumentMap
} from '../model/collections';
import { Document, MaybeDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { DocumentSet } from '../model/document_set';
import { TargetChange } from '../remote/remote_event';
import { debugAssert, fail } from '../util/assert';
Expand All @@ -41,6 +40,7 @@ import {
ViewSnapshot
} from './view_snapshot';
import { QueryResult } from '../local/local_store_impl';
import { DocumentKey } from '../model/path';

export type LimboDocumentChange = AddedLimboDocument | RemovedLimboDocument;
export class AddedLimboDocument {
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/view_snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*/

import { Document } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { DocumentSet } from '../model/document_set';
import { fail } from '../util/assert';
import { SortedMap } from '../util/sorted_map';

import { DocumentKeySet } from '../model/collections';
import { Query, queryEquals } from './query';
import { DocumentKey } from '../model/path';

export const enum ChangeType {
Added,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* limitations under the License.
*/

import { DocumentKey } from '../model/document_key';
import { ListenSequenceNumber, TargetId } from '../core/types';
import { DbTargetDocument } from './indexeddb_schema';
import {
Expand All @@ -40,6 +39,7 @@ import { TargetData } from './target_data';
import { mutationQueuesContainKey } from './indexeddb_mutation_queue';
import { ListenSequence } from '../core/listen_sequence';
import { IndexedDbLruDelegate } from './indexeddb_lru_delegate';
import { DocumentKey } from '../model/path';

/** Provides LRU functionality for IndexedDB persistence. */
export class IndexedDbLruDelegateImpl implements IndexedDbLruDelegate {
Expand Down
56 changes: 4 additions & 52 deletions packages/firestore/src/local/indexeddb_mutation_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { User } from '../auth/user';
import { isCollectionGroupQuery, isDocumentQuery, Query } from '../core/query';
import { BatchId } from '../core/types';
import { DocumentKeySet } from '../model/collections';
import { DocumentKey } from '../model/document_key';
import { Mutation } from '../model/mutation';
import { BATCHID_UNKNOWN, MutationBatch } from '../model/mutation_batch';
import { ResourcePath } from '../model/path';
import { DocumentKey, ResourcePath } from '../model/path';
import { debugAssert, fail, hardAssert } from '../util/assert';
import { primitiveComparator } from '../util/misc';
import { SortedMap } from '../util/sorted_map';
Expand All @@ -36,7 +35,8 @@ import {
DbMutationBatch,
DbMutationBatchKey,
DbMutationQueue,
DbMutationQueueKey
DbMutationQueueKey,
removeMutationBatch
} from './indexeddb_schema';
import {
fromDbMutationBatch,
Expand All @@ -46,7 +46,7 @@ import {
import { MutationQueue } from './mutation_queue';
import { ReferenceDelegate } from './persistence';
import { PersistencePromise } from './persistence_promise';
import { SimpleDbStore, SimpleDbTransaction } from './simple_db';
import { SimpleDbStore } from './simple_db';
import { PersistenceTransaction } from './persistence_transaction';
import { IndexedDbTransaction } from './indexeddb_transaction';

Expand Down Expand Up @@ -613,54 +613,6 @@ export function mutationQueuesContainKey(
.next(() => found);
}

/**
* Delete a mutation batch and the associated document mutations.
* @returns A PersistencePromise of the document mutations that were removed.
*/
export function removeMutationBatch(
txn: SimpleDbTransaction,
userId: string,
batch: MutationBatch
): PersistencePromise<DocumentKey[]> {
const mutationStore = txn.store<DbMutationBatchKey, DbMutationBatch>(
DbMutationBatch.store
);
const indexTxn = txn.store<DbDocumentMutationKey, DbDocumentMutation>(
DbDocumentMutation.store
);
const promises: Array<PersistencePromise<void>> = [];

const range = IDBKeyRange.only(batch.batchId);
let numDeleted = 0;
const removePromise = mutationStore.iterate(
{ range },
(key, value, control) => {
numDeleted++;
return control.delete();
}
);
promises.push(
removePromise.next(() => {
hardAssert(
numDeleted === 1,
'Dangling document-mutation reference found: Missing batch ' +
batch.batchId
);
})
);
const removedDocuments: DocumentKey[] = [];
for (const mutation of batch.mutations) {
const indexKey = DbDocumentMutation.key(
userId,
mutation.key.path,
batch.batchId
);
promises.push(indexTxn.delete(indexKey));
removedDocuments.push(mutation.key);
}
return PersistencePromise.waitFor(promises).next(() => removedDocuments);
}

/**
* Helper to get a typed SimpleDbStore for the mutations object store.
*/
Expand Down
24 changes: 3 additions & 21 deletions packages/firestore/src/local/indexeddb_remote_document_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ import {
NullableMaybeDocumentMap
} from '../model/collections';
import { Document, MaybeDocument, NoDocument } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { ResourcePath } from '../model/path';
import { DocumentKey, ResourcePath } from '../model/path';
import { primitiveComparator } from '../util/misc';
import { SortedMap } from '../util/sorted_map';
import { SortedSet } from '../util/sorted_set';

import { SnapshotVersion } from '../core/snapshot_version';
import { debugAssert, debugCast, fail, hardAssert } from '../util/assert';
import { debugAssert, debugCast, hardAssert } from '../util/assert';
import { IndexManager } from './index_manager';
import {
dbDocumentSize,
DbRemoteDocument,
DbRemoteDocumentGlobal,
DbRemoteDocumentGlobalKey,
Expand Down Expand Up @@ -601,20 +600,3 @@ function remoteDocumentsStore(
function dbKey(docKey: DocumentKey): DbRemoteDocumentKey {
return docKey.path.toArray();
}

/**
* Retrusn an approximate size for the given document.
*/
export function dbDocumentSize(doc: DbRemoteDocument): number {
let value: unknown;
if (doc.document) {
value = doc.document;
} else if (doc.unknownDocument) {
value = doc.unknownDocument;
} else if (doc.noDocument) {
value = doc.noDocument;
} else {
throw fail('Unknown remote document type');
}
return JSON.stringify(value).length;
}
Loading