-
Notifications
You must be signed in to change notification settings - Fork 938
Merge firestore bundles implementation without exposing public APIs #3594
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
Changes from 40 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
f347dea
Add bundle.proto d.ts and introduce IDB object stores for bundles. (…
wu-hui b0c8299
Implement a bundle reader for Web (#3097)
wu-hui 2f179bc
Enable bundle reader for Node. (#3167)
wu-hui d3f0ab4
Implement BundleCache for IDB and memory. (#3170)
wu-hui 6c375b9
Merge branch 'master' into wuandy/Bundles
wu-hui e8b9ec2
Implement bundle features in local store. (#3200)
wu-hui 2e73801
Merge branch 'master' into wuandy/Bundles
wu-hui fff6b1b
Merge branch 'master' into wuandy/Bundles
wu-hui 3a78d7c
Fix firestore_bundle_proto rollup issue. (#3316)
wu-hui 0bf9c73
Implement bundle loading. (#3201)
wu-hui 2bfa185
Merge branch 'master' into wuandy/Bundles
wu-hui 9bfb995
Bundles load from secondary tabs (#3393)
wu-hui a9bf16c
Merge branch 'master' into wuandy/Bundles
wu-hui 8b8a097
Make loadBundle work with exp build (#3488)
wu-hui 5ebf8c3
Bundle's named query resume. (#3395)
wu-hui 8cfb471
Merge branch 'master' into wuandy/Bundles
wu-hui 2bec6d8
Merge remote-tracking branch 'origin/wuandy/Bundles' into wuandy/Bundles
wu-hui 0f697df
Merge with named query change.
wu-hui dc02c03
Add missing byte_stream_reader.ts for *_lite platforms
wu-hui 15b96a9
Finally builds and passes
wu-hui b4f9936
Update query-document mapping from bundles. (#3620)
wu-hui ef202a1
Merge branch 'master' into wuandy/Bundles
wu-hui c4b0995
Introduce an umbrella target for bundled documents (#3643)
wu-hui 4e09f58
Merge branch 'master' into wuandy/Bundles
wu-hui 775d58a
Restore some files from master
wu-hui 5dd5c9c
Fix build errors
wu-hui e53cf69
Fix lint errors
wu-hui 4bbcdc0
Merge branch 'master' into wuandy/Bundles
wu-hui bd6adc6
Hide bundles from public API
wu-hui 259160b
Fix build error.
wu-hui 9a804fc
Add bundle proto to extern, version upgrade and make exp bundle public
wu-hui 72fb466
Merge branch 'master' into wuandy/Bundles
wu-hui 3b208b2
Fix lint error
wu-hui 223bc9a
Move bundle integration tests under api/ and complete exp API (#3962)
wu-hui b80c880
Merge branch 'master' into wuandy/Bundles
wu-hui 5b0526b
Bundles as free functions (#4006)
wu-hui 089fcdd
Merge branch 'master' into wuandy/Bundles
wu-hui 80dc41d
Address comments
wu-hui d4ab17f
Remove bundles from public interfaces.
wu-hui 1b3d633
Remove bundles from public interfaces take 2.
wu-hui 205d1c8
Merge branch 'master' into wuandy/Bundles
wu-hui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@firebase/firestore": internal | ||
--- | ||
|
||
Merge bundle loading implementation without exposing public API |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/** | ||
* @license | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Deferred } from '../util/promise'; | ||
import { PartialObserver } from './observer'; | ||
import { debugAssert } from '../util/assert'; | ||
import { FirestoreError } from '../util/error'; | ||
|
||
export interface ApiLoadBundleTask { | ||
onProgress( | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
next?: (progress: ApiLoadBundleTaskProgress) => any, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
error?: (error: Error) => any, | ||
complete?: () => void | ||
): void; | ||
|
||
then<T, R>( | ||
onFulfilled?: (a: ApiLoadBundleTaskProgress) => T | PromiseLike<T>, | ||
onRejected?: (a: Error) => R | PromiseLike<R> | ||
): Promise<T | R>; | ||
|
||
catch<R>( | ||
onRejected: (a: Error) => R | PromiseLike<R> | ||
): Promise<R | ApiLoadBundleTaskProgress>; | ||
} | ||
|
||
export interface ApiLoadBundleTaskProgress { | ||
documentsLoaded: number; | ||
totalDocuments: number; | ||
bytesLoaded: number; | ||
totalBytes: number; | ||
taskState: TaskState; | ||
} | ||
|
||
export type TaskState = 'Error' | 'Running' | 'Success'; | ||
|
||
export class LoadBundleTask | ||
implements ApiLoadBundleTask, PromiseLike<ApiLoadBundleTaskProgress> { | ||
private _progressObserver: PartialObserver<ApiLoadBundleTaskProgress> = {}; | ||
private _taskCompletionResolver = new Deferred<ApiLoadBundleTaskProgress>(); | ||
|
||
private _lastProgress: ApiLoadBundleTaskProgress = { | ||
taskState: 'Running', | ||
totalBytes: 0, | ||
totalDocuments: 0, | ||
bytesLoaded: 0, | ||
documentsLoaded: 0 | ||
}; | ||
|
||
onProgress( | ||
next?: (progress: ApiLoadBundleTaskProgress) => unknown, | ||
error?: (err: Error) => unknown, | ||
complete?: () => void | ||
): void { | ||
this._progressObserver = { | ||
next, | ||
error, | ||
complete | ||
}; | ||
} | ||
|
||
catch<R>( | ||
onRejected: (a: Error) => R | PromiseLike<R> | ||
): Promise<R | ApiLoadBundleTaskProgress> { | ||
return this._taskCompletionResolver.promise.catch(onRejected); | ||
} | ||
|
||
then<T, R>( | ||
onFulfilled?: (a: ApiLoadBundleTaskProgress) => T | PromiseLike<T>, | ||
onRejected?: (a: Error) => R | PromiseLike<R> | ||
): Promise<T | R> { | ||
return this._taskCompletionResolver.promise.then(onFulfilled, onRejected); | ||
} | ||
|
||
/** | ||
* Notifies all observers that bundle loading has completed, with a provided | ||
* `LoadBundleTaskProgress` object. | ||
*/ | ||
_completeWith(progress: ApiLoadBundleTaskProgress): void { | ||
debugAssert( | ||
progress.taskState === 'Success', | ||
'Task is not completed with Success.' | ||
); | ||
this._updateProgress(progress); | ||
if (this._progressObserver.complete) { | ||
this._progressObserver.complete(); | ||
} | ||
|
||
this._taskCompletionResolver.resolve(progress); | ||
} | ||
|
||
/** | ||
* Notifies all observers that bundle loading has failed, with a provided | ||
* `Error` as the reason. | ||
*/ | ||
_failWith(error: FirestoreError): void { | ||
this._lastProgress.taskState = 'Error'; | ||
|
||
if (this._progressObserver.next) { | ||
this._progressObserver.next(this._lastProgress); | ||
} | ||
|
||
if (this._progressObserver.error) { | ||
this._progressObserver.error(error); | ||
} | ||
|
||
this._taskCompletionResolver.reject(error); | ||
} | ||
|
||
/** | ||
* Notifies a progress update of loading a bundle. | ||
* @param progress The new progress. | ||
*/ | ||
_updateProgress(progress: ApiLoadBundleTaskProgress): void { | ||
debugAssert( | ||
this._lastProgress.taskState === 'Running', | ||
'Cannot update progress on a completed or failed task' | ||
); | ||
|
||
this._lastProgress = progress; | ||
if (this._progressObserver.next) { | ||
this._progressObserver.next(progress); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,9 @@ import { | |
firestoreClientGetDocumentsFromLocalCache, | ||
firestoreClientGetDocumentsViaSnapshotListener, | ||
firestoreClientGetDocumentViaSnapshotListener, | ||
firestoreClientGetNamedQuery, | ||
firestoreClientListen, | ||
firestoreClientLoadBundle, | ||
firestoreClientTransaction, | ||
firestoreClientWrite | ||
} from '../core/firestore_client'; | ||
|
@@ -141,6 +143,7 @@ import { | |
import { newUserDataReader } from '../../lite/src/api/reference'; | ||
import { makeDatabaseInfo } from '../../lite/src/api/database'; | ||
import { DEFAULT_HOST } from '../../lite/src/api/components'; | ||
import { ApiLoadBundleTask, LoadBundleTask } from './bundle'; | ||
|
||
/** | ||
* Constant used to indicate the LRU garbage collection should be disabled. | ||
|
@@ -424,6 +427,36 @@ export function setLogLevel(level: PublicLogLevel): void { | |
setClientLogLevel(level); | ||
} | ||
|
||
export function loadBundle( | ||
db: Firestore, | ||
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string | ||
): ApiLoadBundleTask { | ||
const resultTask = new LoadBundleTask(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to figure out where to call "ensureClientConfigured". It might depend on how we expose this function in the end. |
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
firestoreClientLoadBundle( | ||
ensureFirestoreConfigured(db._delegate), | ||
bundleData, | ||
resultTask | ||
); | ||
return resultTask; | ||
} | ||
|
||
export function namedQuery( | ||
db: Firestore, | ||
name: string | ||
): Promise<PublicQuery | null> { | ||
return firestoreClientGetNamedQuery( | ||
ensureFirestoreConfigured(db._delegate), | ||
name | ||
).then(namedQuery => { | ||
if (!namedQuery) { | ||
return null; | ||
} | ||
|
||
return new Query(namedQuery.query, db, null); | ||
}); | ||
} | ||
|
||
/** | ||
* A reference to a transaction. | ||
*/ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changeset entry to describe the size increase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.