Skip to content

Add JSDoc for bundles #4155

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 9 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
70 changes: 66 additions & 4 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* limitations under the License.
*/

import { DocumentData, LoadBundleTask, Query } from '@firebase/firestore-types';

/**
* <code>firebase</code> is a global namespace from which all Firebase
* services are accessed.
Expand Down Expand Up @@ -8291,10 +8289,28 @@ declare namespace firebase.firestore {
*/
terminate(): Promise<void>;

/**
* Loads a Firestore bundle into the local cache.
*
* @param bundleData
* An object representing the bundle to be load. Valid objects are `ArrayBuffer`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...bundle to be loaded. Valid..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* `ReadableStream<Uint8Array>` or `string`.
*
* @return
* A `LoadBundleTask` object, which notifies callers with progress update, and completion
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...with progress updates, and..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* or error events. It can be used as a `Promise<LoadBundleTaskProgress>`.
*/
loadBundle(
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
): LoadBundleTask;

/**
* Reads a Firestore `Query` from local cache that is associated to a given name.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Reads a Firestore Query from local cache, identified by name."

"Bundles can contain named queries. These named queries are packaged..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

*
* The named queries are from bundles. They are packaged into bundles on the server side (along
* with resulting documents), and loaded to local cache using `loadBundle`. Once in local
* cache, use this method to extract a `Query` by name.
*/
namedQuery(name: string): Promise<Query<DocumentData> | null>;

/**
Expand All @@ -8303,31 +8319,77 @@ declare namespace firebase.firestore {
INTERNAL: { delete: () => Promise<void> };
}

export interface LoadBundleTask {
/**
* Represents the task of loading a Firestore bundle. It provides progress of bundle
* loading, as well as task completion and error events.
*
* The API is compatible with `Promise<LoadBundleTaskProgress>`.
*/
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
/**
* Registers functions to listen to bundle loading progress events.
* @param next
* Called when there is a progress update from bundle loading, typically `next` calls occur
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...from bundle loading. Typically, next calls..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* each time a Firestore document is loaded from the bundle.
* @param error
* Called when an error occurs during bundle loading. The task aborts after reporting the
* error, and there should be no more updates after this.
* @param complete
* Called when the loading task is complete.
*/
onProgress(
next?: (progress: LoadBundleTaskProgress) => any,
error?: (error: Error) => any,
complete?: () => void
): void;

/**
* Implements the `Promise<LoadBundleTaskProgress>.then` interface.
*
* @param onFulfilled
* Called on the completion with a `LoadBundleTaskProgress` update when the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was a little unclear. Maybe this edit will help, but please clarify "the completion of" what? Completion of the progress update?

"Called on completion of a LoadBundleTaskProgress update when..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* loading task completes. The update will have its `taskState` set to `"Success"`.
* @param onRejected
* Called when an error occurs during bundle loading.
*/
then<T, R>(
onFulfilled?: (a: LoadBundleTaskProgress) => T | PromiseLike<T>,
onRejected?: (a: Error) => R | PromiseLike<R>
): Promise<T | R>;

/**
* Implements the `Promise<LoadBundleTaskProgress>.catch` interface.
*
* @param onRejected
* Called when an error occurs during bundle loading.
*/
catch<R>(
onRejected: (a: Error) => R | PromiseLike<R>
): Promise<R | LoadBundleTaskProgress>;
}

/**
* Represents a progress update or a final state from loading bundles.
*/
export interface LoadBundleTaskProgress {
/** How many documents have been loaded. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that you removed these in the other PR. You should leave the comments in both places as firestore-exp builds its d.ts file from source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was a bad merge i think. Will keep the comments.

documentsLoaded: number;
/** How many documents are in the bundle being loaded. */
totalDocuments: number;
/** How many bytes have been loaded. */
bytesLoaded: number;
/** How many bytes are in the bundle being loaded. */
totalBytes: number;
/** Current task state. */
taskState: TaskState;
}

/**
* Represents the state of bundle loading tasks.
*
* Both 'Error' and 'Success' are sinking state: task will abort or complete and there will
* be no more updates after they are reported.
*/
export type TaskState = 'Error' | 'Running' | 'Success';

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ export class FirebaseFirestore {
terminate(): Promise<void>;

loadBundle(
bundleData: ArrayBuffer | ReadableStream<ArrayBuffer> | string
bundleData: ArrayBuffer | ReadableStream<Uint8Array> | string
): LoadBundleTask;

namedQuery(name: string): Promise<Query<DocumentData> | null>;

INTERNAL: { delete: () => Promise<void> };
}

export interface LoadBundleTask {
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
onProgress(
next?: (progress: LoadBundleTaskProgress) => any,
error?: (error: Error) => any,
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/exp-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ export function snapshotEqual<T>(
right: DocumentSnapshot<T> | QuerySnapshot<T>
): boolean;

export interface LoadBundleTask {
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
onProgress(
next?: (progress: LoadBundleTaskProgress) => any,
error?: (error: Error) => any,
Expand Down