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 6 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
60 changes: 58 additions & 2 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8291,10 +8291,26 @@ 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, could be a `ArrayBuffer`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

"...representing the bundle to be loaded. Valid objects are ArrayBuffer, ReadableStream<Uint8Array> or string."

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.

* a `ReadableStream<Uint8Array>` or a `string`.
*
* @return A `LoadBundleTask` object, which notifies callers with progress update, completion
* or error event. It can be used as a `Promise<LoadBundleTaskProgress>`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"...notifies callers with progress updates, and completion or error events."

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.

*/
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 named query from local cache."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here it actually reads a Query object, I added back ticks to make it clear.

*
* The named queries are from bundles, and saved as a result of `loadBundle`. `namedQuery`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something like:
"Named queries are a feature of Firestore bundles. Named queries and related data are packaged into a binary bundle on the server side, the bundle is fetched by the client over the network, and the bundle is loaded to local cache using the loadBundle method. Once in local cache, use this method to extract a query from the bundle by name. Once extracted, the named query is simply a Firestore Query object."

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..more or less similar.

* retrieves the queries used to built the bundles, saving the need to manually construct
* those queries.
*/
namedQuery(name: string): Promise<Query<DocumentData> | null>;

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

export interface LoadBundleTask {
/**
* Represents the task of loading a Firestore bundle. It provides progress of the bundle
Copy link
Collaborator

Choose a reason for hiding this comment

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

"...provides progress of bundle loading, as well as task completion and error events."

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 completion and error events should they be any.
*
* The API is compatible with `Promise<LoadBundleTaskProgress>`.
*/
export interface LoadBundleTask extends PromiseLike<LoadBundleTaskProgress> {
/**
* Registers functions to listen to bundle loading progresses.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"...to listen to bundle loading progress events."

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.

* @param next Called there is a progress update from bundle loading, typically whenever
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Called when there is a.... Typically, next calls occur each time a Firestore document is loaded from the bundle."

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.

* a Firestore document is loaded it will generate a progress update.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix indent to match the rest of this file.

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.

* @param error Called when there is an error occurred from loading the bundle. The task
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Called when an error occurs during bundle loading...."

Hmm, if there are important edge cases in "there should be no more updates after this" then let's add?

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. Not sure what you mean by second statement.

* 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 It is called with the compeltion `LoadBundleTaskProgress` 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.

Remove "It is..." in both params and start with "Called..."

Are there status codes for LoadBundleTaskProgress termination?

For unFulfilled: "Called on completion of LoadBundleTaskProgress when completion status is XXX."
For unRejected: "Called on completion of LoadBundleTaskProgress when completion status is XXX."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no status code.

* loading task completes.
* @param onRejected It is called when there is an error occurred from loading the bundle.
*/
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 It is called when there is an error occurred from loading the bundle.
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above...

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, but without mentioning status code.

*/
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