Skip to content
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

Add converter support #1037

Merged
merged 3 commits into from
Apr 23, 2020
Merged
Changes from 1 commit
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
44 changes: 18 additions & 26 deletions dev/src/bulk-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {RateLimiter} from './rate-limiter';
import {DocumentReference} from './reference';
import {Timestamp} from './timestamp';
import {
BulkWriterOptions,
DocumentData,
Precondition,
SetOptions,
UpdateData,
Expand Down Expand Up @@ -109,10 +107,7 @@ class BulkCommitBatch {
* Adds a `create` operation to the WriteBatch. Returns a promise that
* resolves with the result of the write.
*/
create(
documentRef: DocumentReference,
data: DocumentData
): Promise<WriteResult> {
create<T>(documentRef: DocumentReference<T>, data: T): Promise<WriteResult> {
this.writeBatch.create(documentRef, data);
return this.processOperation(documentRef);
}
Expand All @@ -121,8 +116,8 @@ class BulkCommitBatch {
* Adds a `delete` operation to the WriteBatch. Returns a promise that
* resolves with the result of the delete.
*/
delete(
documentRef: DocumentReference,
delete<T>(
documentRef: DocumentReference<T>,
precondition?: Precondition
): Promise<WriteResult> {
this.writeBatch.delete(documentRef, precondition);
Expand All @@ -133,9 +128,9 @@ class BulkCommitBatch {
* Adds a `set` operation to the WriteBatch. Returns a promise that
* resolves with the result of the write.
*/
set(
documentRef: DocumentReference,
data: DocumentData,
set<T>(
documentRef: DocumentReference<T>,
data: T,
options?: SetOptions
): Promise<WriteResult> {
this.writeBatch.set(documentRef, data, options);
Expand All @@ -146,8 +141,8 @@ class BulkCommitBatch {
* Adds an `update` operation to the WriteBatch. Returns a promise that
* resolves with the result of the write.
*/
update(
documentRef: DocumentReference,
update<T>(
documentRef: DocumentReference<T>,
dataOrField: UpdateData | string | FieldPath,
...preconditionOrValues: Array<
{lastUpdateTime?: Timestamp} | unknown | string | FieldPath
Expand All @@ -161,8 +156,8 @@ class BulkCommitBatch {
* Helper to update data structures associated with the operation and
* return the result.
*/
private processOperation(
documentRef: DocumentReference
private processOperation<T>(
documentRef: DocumentReference<T>
): Promise<WriteResult> {
assert(
!this.docPaths.has(documentRef.path),
Expand Down Expand Up @@ -305,10 +300,7 @@ export class BulkWriter {
* });
* });
*/
create(
documentRef: DocumentReference,
data: DocumentData
): Promise<WriteResult> {
create<T>(documentRef: DocumentReference<T>, data: T): Promise<WriteResult> {
this.verifyNotClosed();
const bulkCommitBatch = this.getEligibleBatch(documentRef);
const resultPromise = bulkCommitBatch.create(documentRef, data);
Expand Down Expand Up @@ -343,8 +335,8 @@ export class BulkWriter {
* });
* });
*/
delete(
documentRef: DocumentReference,
delete<T>(
documentRef: DocumentReference<T>,
precondition?: Precondition
): Promise<WriteResult> {
this.verifyNotClosed();
Expand Down Expand Up @@ -388,9 +380,9 @@ export class BulkWriter {
* });
* });
*/
set(
documentRef: DocumentReference,
data: DocumentData,
set<T>(
documentRef: DocumentReference<T>,
data: T,
options?: SetOptions
): Promise<WriteResult> {
this.verifyNotClosed();
Expand Down Expand Up @@ -441,7 +433,7 @@ export class BulkWriter {
* });
* });
*/
update(
update<T>(
documentRef: DocumentReference,
dataOrField: UpdateData | string | FieldPath,
...preconditionOrValues: Array<
Expand Down Expand Up @@ -530,7 +522,7 @@ export class BulkWriter {
* Return the first eligible batch that can hold a write to the provided
* reference, or creates one if no eligible batches are found.
*/
private getEligibleBatch(ref: DocumentReference): BulkCommitBatch {
private getEligibleBatch<T>(ref: DocumentReference<T>): BulkCommitBatch {
if (this.batchQueue.length > 0) {
const lastBatch = this.batchQueue[this.batchQueue.length - 1];
if (
Expand Down