node_modules/@google-cloud/firestore/build/src/write-batch.js
/**
     * Commit method that takes an optional transaction ID.
     *
     * @private
     * @param commitOptions Options to use for this commit.
     * @param commitOptions.transactionId The transaction ID of this commit.
     * @param commitOptions.requestTag A unique client-assigned identifier for
     * this request.
     * @returns  A Promise that resolves when this batch completes.
     */
Commit method that takes an optional transaction ID.
@private
@param commitOptions Options to use for this commit.
@param commitOptions.transactionId The transaction ID of this commit.
@param commitOptions.requestTag A unique client-assigned identifier for
this request.
@returns  A Promise that resolves when this batch completes.
Commit method that takes an optional transaction ID . @private @param commitOptions Options to use for this commit . @param commitOptions . transactionId The transaction ID of this commit . @param commitOptions . requestTag A unique client - assigned identifier for this request . @returns A Promise that resolves when this batch completes .
async commit_(commitOptions) {
        this._committed = true;
        const tag = (commitOptions && commitOptions.requestTag) || util_1.requestTag();
        await this._firestore.initializeIfNeeded(tag);
        const database = this._firestore.formattedName;
        const explicitTransaction = commitOptions && commitOptions.transactionId;
        if (!explicitTransaction && this._shouldCreateTransaction()) {
            logger_1.logger('WriteBatch.commit', tag, 'Using transaction for commit');
            return this._firestore
                .request('beginTransaction', { database }, tag)
                .then(resp => {
                return this.commit_({ transactionId: resp.transaction });
            });
        }
        const request = { database, writes: [] };
        const writes = this._ops.map(op => op());
        for (const req of writes) {
            if (req.precondition) {
                req.write.currentDocument = req.precondition;
            }
            request.writes.push(req.write);
        }
        logger_1.logger('WriteBatch.commit', tag, 'Sending %d writes', request.writes.length);
        if (explicitTransaction) {
            request.transaction = explicitTransaction;
        }
        const response = await this._firestore.request('commit', request, tag);
        return (response.writeResults || []).map(writeResult => new WriteResult(timestamp_1.Timestamp.fromProto(writeResult.updateTime || response.commitTime)));
    }
async commit_ ( commitOptions ) { this . _committed = true ; const tag = ( commitOptions && commitOptions . requestTag ) || util_1 . requestTag ( ) ; await this . _firestore . initializeIfNeeded ( tag ) ; const database = this . _firestore . formattedName ; const explicitTransaction = commitOptions && commitOptions . transactionId ; if ( ! explicitTransaction && this . _shouldCreateTransaction ( ) ) { logger_1 . logger ( 'WriteBatch.commit' , tag , 'Using transaction for commit' ) ; return this . _firestore . request ( 'beginTransaction' , { database } , tag ) . then ( resp => { return this . commit_ ( { transactionId : resp . transaction } ) ; } ) ; } const request = { database , writes : [ ] } ; const writes = this . _ops . map ( op => op ( ) ) ; for ( const req of writes ) { if ( req . precondition ) { req . write . currentDocument = req . precondition ; } request . writes . push ( req . write ) ; } logger_1 . logger ( 'WriteBatch.commit' , tag , 'Sending %d writes' , request . writes . length ) ; if ( explicitTransaction ) { request . transaction = explicitTransaction ; } const response = await this . _firestore . request ( 'commit' , request , tag ) ; return ( response . writeResults || [ ] ) . map ( writeResult => new WriteResult ( timestamp_1 . Timestamp . fromProto ( writeResult . updateTime || response . commitTime ) ) ) ; }
Commit method that takes an optional transaction ID.
Commit method that takes an optional transaction ID .
// Note: We don't call `verifyNotCommitted()` to allow for retries. // On GCF, we periodically force transactional commits to allow for // request retries in case GCF closes our backend connection.