-
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
Changes from 39 commits
f347dea
b0c8299
2f179bc
d3f0ab4
6c375b9
e8b9ec2
2e73801
fff6b1b
3a78d7c
0bf9c73
2bfa185
9bfb995
a9bf16c
8b8a097
5ebf8c3
8cfb471
2bec6d8
0f697df
dc02c03
15b96a9
b4f9936
ef202a1
c4b0995
4e09f58
775d58a
5dd5c9c
e53cf69
4bbcdc0
bd6adc6
259160b
9a804fc
72fb466
3b208b2
223bc9a
b80c880
5b0526b
089fcdd
80dc41d
d4ab17f
1b3d633
205d1c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@firebase/firestore": feature | ||
--- | ||
|
||
Add support for loading Firestore Bundle Files. | ||
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. This is no longer correct. 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. Done. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8285,6 +8285,43 @@ declare namespace firebase.firestore { | |
INTERNAL: { delete: () => Promise<void> }; | ||
} | ||
|
||
export function loadBundle( | ||
db: Firestore, | ||
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string | ||
): LoadBundleTask; | ||
|
||
export function namedQuery( | ||
db: Firestore, | ||
name: string | ||
): Promise<Query<DocumentData> | null>; | ||
|
||
export interface LoadBundleTask { | ||
onProgress( | ||
next?: (progress: LoadBundleTaskProgress) => any, | ||
error?: (error: Error) => any, | ||
complete?: () => void | ||
): void; | ||
|
||
then<T, R>( | ||
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, | ||
onRejected?: (a: Error) => R | PromiseLike<R> | ||
): Promise<T | R>; | ||
|
||
catch<R>( | ||
onRejected: (a: Error) => R | PromiseLike<R> | ||
): Promise<R | LoadBundleTaskProgress>; | ||
} | ||
|
||
export interface LoadBundleTaskProgress { | ||
documentsLoaded: number; | ||
totalDocuments: number; | ||
bytesLoaded: number; | ||
totalBytes: number; | ||
taskState: TaskState; | ||
} | ||
|
||
export type TaskState = 'Error' | 'Running' | 'Success'; | ||
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. Please remove all this. 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. Done. |
||
|
||
/** | ||
* An immutable object representing a geo point in Firestore. The geo point | ||
* is represented as latitude/longitude pair. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,33 @@ export class FirebaseFirestore { | |
INTERNAL: { delete: () => Promise<void> }; | ||
} | ||
|
||
export interface LoadBundleTask { | ||
onProgress( | ||
next?: (progress: LoadBundleTaskProgress) => any, | ||
error?: (error: Error) => any, | ||
complete?: () => void | ||
): void; | ||
|
||
then<T, R>( | ||
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, | ||
onRejected?: (a: Error) => R | PromiseLike<R> | ||
): Promise<T | R>; | ||
|
||
catch<R>( | ||
onRejected: (a: Error) => R | PromiseLike<R> | ||
): Promise<R | LoadBundleTaskProgress>; | ||
} | ||
|
||
export interface LoadBundleTaskProgress { | ||
documentsLoaded: number; | ||
totalDocuments: number; | ||
bytesLoaded: number; | ||
totalBytes: number; | ||
taskState: TaskState; | ||
} | ||
|
||
export type TaskState = 'Error' | 'Running' | 'Success'; | ||
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. For now, we should remove this from this file. 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. Will keep it this way, since this is now a release PR. 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. Please remove as discussed. 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. Done. |
||
|
||
export class GeoPoint { | ||
constructor(latitude: number, longitude: number); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -516,6 +516,43 @@ export function snapshotEqual<T>( | |
right: DocumentSnapshot<T> | QuerySnapshot<T> | ||
): boolean; | ||
|
||
export interface LoadBundleTask { | ||
onProgress( | ||
next?: (progress: LoadBundleTaskProgress) => any, | ||
error?: (error: Error) => any, | ||
complete?: () => void | ||
): void; | ||
|
||
then<T, R>( | ||
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>, | ||
onRejected?: (a: Error) => R | PromiseLike<R> | ||
): Promise<T | R>; | ||
|
||
catch<R>( | ||
onRejected: (a: Error) => R | PromiseLike<R> | ||
): Promise<R | LoadBundleTaskProgress>; | ||
} | ||
|
||
export interface LoadBundleTaskProgress { | ||
documentsLoaded: number; | ||
totalDocuments: number; | ||
bytesLoaded: number; | ||
totalBytes: number; | ||
taskState: TaskState; | ||
} | ||
|
||
export type TaskState = 'Error' | 'Running' | 'Success'; | ||
|
||
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. These can stay. You can also just make this feature public in firestore-exp. 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. Done. 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. Please remove. 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. Done. |
||
export function loadBundle( | ||
firestore: FirebaseFirestore, | ||
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string | ||
): LoadBundleTask; | ||
|
||
export function namedQuery( | ||
firestore: FirebaseFirestore, | ||
name: string | ||
): Promise<Query<DocumentData> | null>; | ||
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. Remove these as well. 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. Done. |
||
|
||
export type FirestoreErrorCode = | ||
| 'cancelled' | ||
| 'unknown' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/** | ||
* @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 * as firestore from '@firebase/firestore-types'; | ||
import { Deferred } from '../util/promise'; | ||
import { PartialObserver } from './observer'; | ||
import { debugAssert } from '../util/assert'; | ||
import { FirestoreError } from '../util/error'; | ||
|
||
export class LoadBundleTask | ||
implements | ||
firestore.LoadBundleTask, | ||
PromiseLike<firestore.LoadBundleTaskProgress> { | ||
private _progressObserver: PartialObserver< | ||
firestore.LoadBundleTaskProgress | ||
> = {}; | ||
private _taskCompletionResolver = new Deferred< | ||
firestore.LoadBundleTaskProgress | ||
>(); | ||
|
||
private _lastProgress: firestore.LoadBundleTaskProgress = { | ||
taskState: 'Running', | ||
totalBytes: 0, | ||
totalDocuments: 0, | ||
bytesLoaded: 0, | ||
documentsLoaded: 0 | ||
}; | ||
|
||
onProgress( | ||
next?: (progress: firestore.LoadBundleTaskProgress) => unknown, | ||
error?: (err: Error) => unknown, | ||
complete?: () => void | ||
): void { | ||
this._progressObserver = { | ||
next, | ||
error, | ||
complete | ||
}; | ||
} | ||
|
||
catch<R>( | ||
onRejected: (a: Error) => R | PromiseLike<R> | ||
): Promise<R | firestore.LoadBundleTaskProgress> { | ||
return this._taskCompletionResolver.promise.catch(onRejected); | ||
} | ||
|
||
then<T, R>( | ||
onFulfilled?: (a: firestore.LoadBundleTaskProgress) => 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: firestore.LoadBundleTaskProgress): 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: firestore.LoadBundleTaskProgress): 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); | ||
} | ||
} | ||
} |
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.