@google-cloud/firestore
Advanced tools
Comparing version 4.7.0 to 4.7.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const google_gax_1 = require("google-gax"); | ||
const assert = require("assert"); | ||
const backoff_1 = require("./backoff"); | ||
const rate_limiter_1 = require("./rate-limiter"); | ||
const timestamp_1 = require("./timestamp"); | ||
const util_1 = require("./util"); | ||
@@ -11,2 +11,3 @@ const write_batch_1 = require("./write-batch"); | ||
const logger_1 = require("./logger"); | ||
const google_gax_1 = require("google-gax"); | ||
/*! | ||
@@ -53,6 +54,5 @@ * The maximum number of writes that can be in a single batch. | ||
*/ | ||
class BulkCommitBatch { | ||
constructor(firestore, writeBatch, maxBatchSize) { | ||
this.firestore = firestore; | ||
this.writeBatch = writeBatch; | ||
class BulkCommitBatch extends write_batch_1.WriteBatch { | ||
constructor(firestore, maxBatchSize) { | ||
super(firestore); | ||
this.maxBatchSize = maxBatchSize; | ||
@@ -68,45 +68,54 @@ /** | ||
this.pendingOps = []; | ||
this.backoff = new backoff_1.ExponentialBackoff(); | ||
} | ||
/** | ||
* The number of writes in this batch. | ||
*/ | ||
get opCount() { | ||
return this.pendingOps.length; | ||
has(documentRef) { | ||
return this.docPaths.has(documentRef.path); | ||
} | ||
/** | ||
* Adds a `create` operation to the WriteBatch. Returns a promise that | ||
* resolves with the result of the write. | ||
*/ | ||
create(documentRef, data) { | ||
this.writeBatch.create(documentRef, data); | ||
return this.processLastOperation(documentRef); | ||
markReadyToSend() { | ||
if (this.state === BatchState.OPEN) { | ||
this.state = BatchState.READY_TO_SEND; | ||
} | ||
} | ||
/** | ||
* Adds a `delete` operation to the WriteBatch. Returns a promise that | ||
* resolves with the sentinel value (Timestamp(0)) for the delete operation. | ||
*/ | ||
delete(documentRef, precondition) { | ||
this.writeBatch.delete(documentRef, precondition); | ||
return this.processLastOperation(documentRef); | ||
isOpen() { | ||
return this.state === BatchState.OPEN; | ||
} | ||
/** | ||
* Adds a `set` operation to the WriteBatch. Returns a promise that | ||
* resolves with the result of the write. | ||
*/ | ||
set(documentRef, data, options) { | ||
this.writeBatch.set(documentRef, data, options); | ||
return this.processLastOperation(documentRef); | ||
isReadyToSend() { | ||
return this.state === BatchState.READY_TO_SEND; | ||
} | ||
/** | ||
* Adds an `update` operation to the WriteBatch. Returns a promise that | ||
* resolves with the result of the write. | ||
*/ | ||
update(documentRef, dataOrField, ...preconditionOrValues) { | ||
this.writeBatch.update(documentRef, dataOrField, ...preconditionOrValues); | ||
return this.processLastOperation(documentRef); | ||
async bulkCommit() { | ||
assert(this.state === BatchState.READY_TO_SEND, 'The batch should be marked as READY_TO_SEND before committing'); | ||
this.state = BatchState.SENT; | ||
// Capture the error stack to preserve stack tracing across async calls. | ||
const stack = Error().stack; | ||
let results = []; | ||
try { | ||
const retryCodes = util_1.getRetryCodes('batchWrite'); | ||
const response = await this._commit({ retryCodes, methodName: 'batchWrite' }); | ||
results = response.writeResults.map((result, i) => { | ||
const status = response.status[i]; | ||
const error = new google_gax_1.GoogleError(status.message || undefined); | ||
error.code = status.code; | ||
// Since delete operations currently do not have write times, use a | ||
// sentinel Timestamp value. | ||
// TODO(b/158502664): Use actual delete timestamp. | ||
const DELETE_TIMESTAMP_SENTINEL = timestamp_1.Timestamp.fromMillis(0); | ||
const updateTime = error.code === google_gax_1.Status.OK | ||
? timestamp_1.Timestamp.fromProto(result.updateTime || DELETE_TIMESTAMP_SENTINEL) | ||
: null; | ||
return new write_batch_1.BatchWriteResult(updateTime, error); | ||
}); | ||
} | ||
catch (err) { | ||
// Map the failure to each individual write's result. | ||
results = this.pendingOps.map(() => { | ||
return { | ||
writeTime: null, | ||
status: util_1.wrapError(err, stack), | ||
}; | ||
}); | ||
} | ||
return this.processResults(results); | ||
} | ||
/** | ||
* Helper to update data structures associated with the operation and | ||
* return the result. | ||
* Helper to update data structures associated with the operation and returns | ||
* the result. | ||
*/ | ||
@@ -119,3 +128,3 @@ processLastOperation(documentRef) { | ||
this.pendingOps.push(deferred); | ||
if (this.opCount === this.maxBatchSize) { | ||
if (this._opCount === this.maxBatchSize) { | ||
this.state = BatchState.READY_TO_SEND; | ||
@@ -133,29 +142,2 @@ } | ||
/** | ||
* Commits the batch and returns a promise that resolves when all the writes | ||
* in the batch have finished. | ||
* | ||
* If any writes in the batch fail with a retryable error, this method will | ||
* retry the failed writes. | ||
*/ | ||
async bulkCommit() { | ||
assert(this.state === BatchState.READY_TO_SEND, 'The batch should be marked as READY_TO_SEND before committing'); | ||
this.state = BatchState.SENT; | ||
// Capture the error stack to preserve stack tracing across async calls. | ||
const stack = Error().stack; | ||
let results = []; | ||
try { | ||
results = await this.writeBatch.bulkCommit(); | ||
} | ||
catch (err) { | ||
// Map the failure to each individual write's result. | ||
results = this.pendingOps.map(() => { | ||
return { | ||
writeTime: null, | ||
status: util_1.wrapError(err, stack), | ||
}; | ||
}); | ||
} | ||
return this.processResults(results); | ||
} | ||
/** | ||
* Resolves the individual operations in the batch with the results. | ||
@@ -175,7 +157,2 @@ */ | ||
} | ||
markReadyToSend() { | ||
if (this.state === BatchState.OPEN) { | ||
this.state = BatchState.READY_TO_SEND; | ||
} | ||
} | ||
} | ||
@@ -597,4 +574,3 @@ /** | ||
const lastBatch = batchQueue[batchQueue.length - 1]; | ||
if (lastBatch.state === BatchState.OPEN && | ||
!lastBatch.docPaths.has(documentRef.path)) { | ||
if (lastBatch.isOpen() && !lastBatch.has(documentRef)) { | ||
return lastBatch; | ||
@@ -612,3 +588,3 @@ } | ||
createNewBatch(batchQueue) { | ||
const newBatch = new BulkCommitBatch(this.firestore, this.firestore.batch(), this._maxBatchSize); | ||
const newBatch = new BulkCommitBatch(this.firestore, this._maxBatchSize); | ||
if (batchQueue.length > 0) { | ||
@@ -631,4 +607,3 @@ batchQueue[batchQueue.length - 1].markReadyToSend(); | ||
let index = 0; | ||
while (index < batchQueue.length && | ||
batchQueue[index].state === BatchState.READY_TO_SEND) { | ||
while (index < batchQueue.length && batchQueue[index].isReadyToSend()) { | ||
const batch = batchQueue[index]; | ||
@@ -641,3 +616,3 @@ // Deferred promise that resolves when the current batch or its | ||
// attempt after the appropriate timeout. | ||
const delayMs = this._rateLimiter.getNextRequestDelayMs(batch.opCount); | ||
const delayMs = this._rateLimiter.getNextRequestDelayMs(batch._opCount); | ||
assert(delayMs !== -1, 'Batch size should be under capacity'); | ||
@@ -667,5 +642,5 @@ if (delayMs === 0) { | ||
sendBatch(batch, batchQueue, batchCompletedDeferred) { | ||
const success = this._rateLimiter.tryMakeRequest(batch.opCount); | ||
const success = this._rateLimiter.tryMakeRequest(batch._opCount); | ||
assert(success, 'Batch should be under rate limit to be sent.'); | ||
return batch.bulkCommit().then(() => { | ||
batch.bulkCommit().then(() => { | ||
// Remove the batch from the BatchQueue after it has been processed. | ||
@@ -700,3 +675,4 @@ const batchIndex = batchQueue.indexOf(batch); | ||
try { | ||
const operationResult = await operationFn(bulkCommitBatch); | ||
operationFn(bulkCommitBatch); | ||
const operationResult = await bulkCommitBatch.processLastOperation(documentRef); | ||
this._successFn(documentRef, operationResult); | ||
@@ -703,0 +679,0 @@ return operationResult; |
@@ -268,3 +268,3 @@ "use strict"; | ||
if (options.allowUndefined && level === 0) { | ||
throw new Error(`${validate_1.invalidArgumentMessage(arg, desc)} "undefined" values are only ignored in object properties.`); | ||
throw new Error(`${validate_1.invalidArgumentMessage(arg, desc)} "undefined" values are only ignored inside of objects.`); | ||
} | ||
@@ -280,6 +280,18 @@ else if (!options.allowUndefined) { | ||
} | ||
else if ((options.allowDeletes === 'root' && level !== 0) || | ||
options.allowDeletes === 'none') { | ||
throw new Error(`${validate_1.invalidArgumentMessage(arg, desc)} ${value.methodName}() must appear at the top-level and can only be used in update() or set() with {merge:true}${fieldPathMessage}.`); | ||
else if (options.allowDeletes === 'none') { | ||
throw new Error(`${validate_1.invalidArgumentMessage(arg, desc)} ${value.methodName}() must appear at the top-level and can only be used in update() ` + | ||
`or set() with {merge:true}${fieldPathMessage}.`); | ||
} | ||
else if (options.allowDeletes === 'root') { | ||
if (level === 0) { | ||
// Ok (update() with UpdateData). | ||
} | ||
else if (level === 1 && (path === null || path === void 0 ? void 0 : path.size) === 1) { | ||
// Ok (update with varargs). | ||
} | ||
else { | ||
throw new Error(`${validate_1.invalidArgumentMessage(arg, desc)} ${value.methodName}() must appear at the top-level and can only be used in update() ` + | ||
`or set() with {merge:true}${fieldPathMessage}.`); | ||
} | ||
} | ||
} | ||
@@ -286,0 +298,0 @@ else if (value instanceof field_value_1.FieldTransform) { |
@@ -34,4 +34,6 @@ /// <reference types="node" /> | ||
* | ||
* @param {object} [options] - The configuration object. See the subsequent | ||
* parameters for more details. | ||
* @param {object} [options] - The configuration object. | ||
* The options accepted by the constructor are described in detail | ||
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance). | ||
* The common options are: | ||
* @param {object} [options.credentials] - Credentials object. | ||
@@ -56,2 +58,9 @@ * @param {string} [options.credentials.client_email] | ||
* API remote host. | ||
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override. | ||
* TODO(@alexander-fenster): link to gax documentation. | ||
* @param {boolean} fallback - Use HTTP fallback mode. | ||
* In fallback mode, a special browser-compatible transport implementation is used | ||
* instead of gRPC transport. In browser context (if the `window` object is defined) | ||
* the fallback mode is enabled automatically; set `options.fallback` to `false` | ||
* if you need to override this behavior. | ||
*/ | ||
@@ -75,2 +84,3 @@ constructor(opts?: ClientOptions); | ||
* The DNS address for this API service. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -81,2 +91,3 @@ static get servicePath(): string; | ||
* exists for compatibility reasons. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -86,2 +97,3 @@ static get apiEndpoint(): string; | ||
* The port for this API service. | ||
* @returns {number} The default port for this service. | ||
*/ | ||
@@ -92,2 +104,3 @@ static get port(): number; | ||
* in this service. | ||
* @returns {string[]} List of default scopes. | ||
*/ | ||
@@ -110,3 +123,3 @@ static get scopes(): string[]; | ||
/** | ||
* Check the status of the long running operation returned by the createIndex() method. | ||
* Check the status of the long running operation returned by `createIndex()`. | ||
* @param {String} name | ||
@@ -116,9 +129,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkCreateIndexProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkCreateIndexProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -130,3 +144,3 @@ checkCreateIndexProgress(name: string): Promise<LROperation<protos.google.firestore.admin.v1.Index, protos.google.firestore.admin.v1.IndexOperationMetadata>>; | ||
/** | ||
* Check the status of the long running operation returned by the updateField() method. | ||
* Check the status of the long running operation returned by `updateField()`. | ||
* @param {String} name | ||
@@ -136,9 +150,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkUpdateFieldProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkUpdateFieldProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -150,3 +165,3 @@ checkUpdateFieldProgress(name: string): Promise<LROperation<protos.google.firestore.admin.v1.Field, protos.google.firestore.admin.v1.FieldOperationMetadata>>; | ||
/** | ||
* Check the status of the long running operation returned by the exportDocuments() method. | ||
* Check the status of the long running operation returned by `exportDocuments()`. | ||
* @param {String} name | ||
@@ -156,9 +171,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkExportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkExportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -170,3 +186,3 @@ checkExportDocumentsProgress(name: string): Promise<LROperation<protos.google.firestore.admin.v1.ExportDocumentsResponse, protos.google.firestore.admin.v1.ExportDocumentsMetadata>>; | ||
/** | ||
* Check the status of the long running operation returned by the importDocuments() method. | ||
* Check the status of the long running operation returned by `importDocuments()`. | ||
* @param {String} name | ||
@@ -176,9 +192,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkImportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkImportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -190,14 +207,3 @@ checkImportDocumentsProgress(name: string): Promise<LROperation<protos.google.protobuf.Empty, protos.google.firestore.admin.v1.ImportDocumentsMetadata>>; | ||
/** | ||
* Equivalent to {@link listIndexes}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listIndexes} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -220,9 +226,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Index]{@link google.firestore.admin.v1.Index} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listIndexesAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
listIndexesStream(request?: protos.google.firestore.admin.v1.IListIndexesRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link listIndexes}, but returns an iterable object. | ||
* Equivalent to `listIndexes`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -244,3 +256,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Index]{@link google.firestore.admin.v1.Index}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listIndexesAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -252,14 +275,3 @@ listIndexesAsync(request?: protos.google.firestore.admin.v1.IListIndexesRequest, options?: gax.CallOptions): AsyncIterable<protos.google.firestore.admin.v1.IIndex>; | ||
/** | ||
* Equivalent to {@link listFields}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listFields} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -286,9 +298,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Field]{@link google.firestore.admin.v1.Field} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listFieldsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
listFieldsStream(request?: protos.google.firestore.admin.v1.IListFieldsRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link listFields}, but returns an iterable object. | ||
* Equivalent to `listFields`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -314,3 +332,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Field]{@link google.firestore.admin.v1.Field}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listFieldsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -460,7 +489,8 @@ listFieldsAsync(request?: protos.google.firestore.admin.v1.IListFieldsRequest, options?: gax.CallOptions): AsyncIterable<protos.google.firestore.admin.v1.IField>; | ||
/** | ||
* Terminate the GRPC channel and close the client. | ||
* Terminate the gRPC channel and close the client. | ||
* | ||
* The client will no longer be usable and all future behavior is undefined. | ||
* @returns {Promise} A promise that resolves when the client is closed. | ||
*/ | ||
close(): Promise<void>; | ||
} |
@@ -35,4 +35,6 @@ "use strict"; | ||
* | ||
* @param {object} [options] - The configuration object. See the subsequent | ||
* parameters for more details. | ||
* @param {object} [options] - The configuration object. | ||
* The options accepted by the constructor are described in detail | ||
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance). | ||
* The common options are: | ||
* @param {object} [options.credentials] - Credentials object. | ||
@@ -57,4 +59,12 @@ * @param {string} [options.credentials.client_email] | ||
* API remote host. | ||
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override. | ||
* TODO(@alexander-fenster): link to gax documentation. | ||
* @param {boolean} fallback - Use HTTP fallback mode. | ||
* In fallback mode, a special browser-compatible transport implementation is used | ||
* instead of gRPC transport. In browser context (if the `window` object is defined) | ||
* the fallback mode is enabled automatically; set `options.fallback` to `false` | ||
* if you need to override this behavior. | ||
*/ | ||
constructor(opts) { | ||
var _a, _b; | ||
this._terminated = false; | ||
@@ -67,30 +77,16 @@ this.descriptors = { | ||
}; | ||
// Ensure that options include the service address and port. | ||
// Ensure that options include all the required fields. | ||
const staticMembers = this.constructor; | ||
const servicePath = opts && opts.servicePath | ||
? opts.servicePath | ||
: opts && opts.apiEndpoint | ||
? opts.apiEndpoint | ||
: staticMembers.servicePath; | ||
const port = opts && opts.port ? opts.port : staticMembers.port; | ||
if (!opts) { | ||
opts = { servicePath, port }; | ||
const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || staticMembers.servicePath; | ||
const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port; | ||
const clientConfig = (_a = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _a !== void 0 ? _a : {}; | ||
const fallback = (_b = opts === null || opts === void 0 ? void 0 : opts.fallback) !== null && _b !== void 0 ? _b : typeof window !== 'undefined'; | ||
opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); | ||
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. | ||
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { | ||
opts['scopes'] = staticMembers.scopes; | ||
} | ||
opts.servicePath = opts.servicePath || servicePath; | ||
opts.port = opts.port || port; | ||
// users can override the config from client side, like retry codes name. | ||
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546 | ||
// The way to override client config for Showcase API: | ||
// | ||
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}} | ||
// const showcaseClient = new showcaseClient({ projectId, customConfig }); | ||
opts.clientConfig = opts.clientConfig || {}; | ||
// If we're running in browser, it's OK to omit `fallback` since | ||
// google-gax has `browser` field in its `package.json`. | ||
// For Electron (which does not respect `browser` field), | ||
// pass `{fallback: true}` to the FirestoreAdminClient constructor. | ||
// Choose either gRPC or proto-over-HTTP implementation of google-gax. | ||
this._gaxModule = opts.fallback ? gax.fallback : gax; | ||
// Create a `gaxGrpc` object, with any grpc-specific options | ||
// sent to the client. | ||
opts.scopes = this.constructor.scopes; | ||
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client. | ||
this._gaxGrpc = new this._gaxModule.GrpcClient(opts); | ||
@@ -101,2 +97,6 @@ // Save options to use in initialize() method. | ||
this.auth = this._gaxGrpc.auth; | ||
// Set the default scopes in auth client if needed. | ||
if (servicePath === staticMembers.servicePath) { | ||
this.auth.defaultScopes = staticMembers.scopes; | ||
} | ||
// Determine the client header string. | ||
@@ -230,2 +230,3 @@ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; | ||
* The DNS address for this API service. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -238,2 +239,3 @@ static get servicePath() { | ||
* exists for compatibility reasons. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -245,2 +247,3 @@ static get apiEndpoint() { | ||
* The port for this API service. | ||
* @returns {number} The default port for this service. | ||
*/ | ||
@@ -253,2 +256,3 @@ static get port() { | ||
* in this service. | ||
* @returns {string[]} List of default scopes. | ||
*/ | ||
@@ -263,4 +267,3 @@ static get scopes() { | ||
* Return the project ID used by this class. | ||
* @param {function(Error, string)} callback - the callback to | ||
* be called with the current project Id. | ||
* @returns {Promise} A promise that resolves to string containing the project ID. | ||
*/ | ||
@@ -286,3 +289,7 @@ getProjectId(callback) { | ||
* The first element of the array is an object representing [Index]{@link google.firestore.admin.v1.Index}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.getIndex(request); | ||
*/ | ||
@@ -320,3 +327,7 @@ getIndex(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.deleteIndex(request); | ||
*/ | ||
@@ -354,3 +365,7 @@ deleteIndex(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [Field]{@link google.firestore.admin.v1.Field}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.getField(request); | ||
*/ | ||
@@ -391,4 +406,11 @@ getField(request, optionsOrCallback, callback) { | ||
* @returns {Promise} - The promise which resolves to an array. | ||
* The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* The first element of the array is an object representing | ||
* a long running operation. Its `promise()` method returns a promise | ||
* you can `await` for. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const [operation] = await client.createIndex(request); | ||
* const [response] = await operation.promise(); | ||
*/ | ||
@@ -415,3 +437,3 @@ createIndex(request, optionsOrCallback, callback) { | ||
/** | ||
* Check the status of the long running operation returned by the createIndex() method. | ||
* Check the status of the long running operation returned by `createIndex()`. | ||
* @param {String} name | ||
@@ -421,9 +443,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkCreateIndexProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkCreateIndexProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -461,4 +484,11 @@ async checkCreateIndexProgress(name) { | ||
* @returns {Promise} - The promise which resolves to an array. | ||
* The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* The first element of the array is an object representing | ||
* a long running operation. Its `promise()` method returns a promise | ||
* you can `await` for. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const [operation] = await client.updateField(request); | ||
* const [response] = await operation.promise(); | ||
*/ | ||
@@ -485,3 +515,3 @@ updateField(request, optionsOrCallback, callback) { | ||
/** | ||
* Check the status of the long running operation returned by the updateField() method. | ||
* Check the status of the long running operation returned by `updateField()`. | ||
* @param {String} name | ||
@@ -491,9 +521,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkUpdateFieldProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkUpdateFieldProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -535,4 +566,11 @@ async checkUpdateFieldProgress(name) { | ||
* @returns {Promise} - The promise which resolves to an array. | ||
* The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* The first element of the array is an object representing | ||
* a long running operation. Its `promise()` method returns a promise | ||
* you can `await` for. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const [operation] = await client.exportDocuments(request); | ||
* const [response] = await operation.promise(); | ||
*/ | ||
@@ -559,3 +597,3 @@ exportDocuments(request, optionsOrCallback, callback) { | ||
/** | ||
* Check the status of the long running operation returned by the exportDocuments() method. | ||
* Check the status of the long running operation returned by `exportDocuments()`. | ||
* @param {String} name | ||
@@ -565,9 +603,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkExportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkExportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -604,4 +643,11 @@ async checkExportDocumentsProgress(name) { | ||
* @returns {Promise} - The promise which resolves to an array. | ||
* The first element of the array is an object representing [Operation]{@link google.longrunning.Operation}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* The first element of the array is an object representing | ||
* a long running operation. Its `promise()` method returns a promise | ||
* you can `await` for. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const [operation] = await client.importDocuments(request); | ||
* const [response] = await operation.promise(); | ||
*/ | ||
@@ -628,3 +674,3 @@ importDocuments(request, optionsOrCallback, callback) { | ||
/** | ||
* Check the status of the long running operation returned by the importDocuments() method. | ||
* Check the status of the long running operation returned by `importDocuments()`. | ||
* @param {String} name | ||
@@ -634,9 +680,10 @@ * The operation name that will be passed. | ||
* The decoded operation object has result and metadata field to get information from. | ||
* | ||
* @example: | ||
* const decodedOperation = await checkImportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
* | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) | ||
* for more details and examples. | ||
* @example | ||
* const decodedOperation = await checkImportDocumentsProgress(name); | ||
* console.log(decodedOperation.result); | ||
* console.log(decodedOperation.done); | ||
* console.log(decodedOperation.metadata); | ||
*/ | ||
@@ -669,15 +716,10 @@ async checkImportDocumentsProgress(name) { | ||
* The first element of the array is Array of [Index]{@link google.firestore.admin.v1.Index}. | ||
* The client library support auto-pagination by default: it will call the API as many | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed and will merge results from all the pages into this array. | ||
* | ||
* When autoPaginate: false is specified through options, the array has three elements. | ||
* The first element is Array of [Index]{@link google.firestore.admin.v1.Index} that corresponds to | ||
* the one page received from the API server. | ||
* If the second element is not null it contains the request object of type [ListIndexesRequest]{@link google.firestore.admin.v1.ListIndexesRequest} | ||
* that can be used to obtain the next page of the results. | ||
* If it is null, the next page does not exist. | ||
* The third element contains the raw response received from the API server. Its type is | ||
* [ListIndexesResponse]{@link google.firestore.admin.v1.ListIndexesResponse}. | ||
* | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Note that it can affect your quota. | ||
* We recommend using `listIndexesAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -704,14 +746,3 @@ listIndexes(request, optionsOrCallback, callback) { | ||
/** | ||
* Equivalent to {@link listIndexes}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listIndexes} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -734,2 +765,9 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Index]{@link google.firestore.admin.v1.Index} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listIndexesAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -749,6 +787,5 @@ listIndexesStream(request, options) { | ||
/** | ||
* Equivalent to {@link listIndexes}, but returns an iterable object. | ||
* Equivalent to `listIndexes`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -770,3 +807,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Index]{@link google.firestore.admin.v1.Index}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listIndexesAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -815,15 +863,10 @@ listIndexesAsync(request, options) { | ||
* The first element of the array is Array of [Field]{@link google.firestore.admin.v1.Field}. | ||
* The client library support auto-pagination by default: it will call the API as many | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed and will merge results from all the pages into this array. | ||
* | ||
* When autoPaginate: false is specified through options, the array has three elements. | ||
* The first element is Array of [Field]{@link google.firestore.admin.v1.Field} that corresponds to | ||
* the one page received from the API server. | ||
* If the second element is not null it contains the request object of type [ListFieldsRequest]{@link google.firestore.admin.v1.ListFieldsRequest} | ||
* that can be used to obtain the next page of the results. | ||
* If it is null, the next page does not exist. | ||
* The third element contains the raw response received from the API server. Its type is | ||
* [ListFieldsResponse]{@link google.firestore.admin.v1.ListFieldsResponse}. | ||
* | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Note that it can affect your quota. | ||
* We recommend using `listFieldsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -850,14 +893,3 @@ listFields(request, optionsOrCallback, callback) { | ||
/** | ||
* Equivalent to {@link listFields}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listFields} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -884,2 +916,9 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Field]{@link google.firestore.admin.v1.Field} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listFieldsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -899,6 +938,5 @@ listFieldsStream(request, options) { | ||
/** | ||
* Equivalent to {@link listFields}, but returns an iterable object. | ||
* Equivalent to `listFields`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -924,3 +962,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Field]{@link google.firestore.admin.v1.Field}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listFieldsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -1136,5 +1185,6 @@ listFieldsAsync(request, options) { | ||
/** | ||
* Terminate the GRPC channel and close the client. | ||
* Terminate the gRPC channel and close the client. | ||
* | ||
* The client will no longer be usable and all future behavior is undefined. | ||
* @returns {Promise} A promise that resolves when the client is closed. | ||
*/ | ||
@@ -1141,0 +1191,0 @@ close() { |
@@ -36,4 +36,6 @@ /// <reference types="node" /> | ||
* | ||
* @param {object} [options] - The configuration object. See the subsequent | ||
* parameters for more details. | ||
* @param {object} [options] - The configuration object. | ||
* The options accepted by the constructor are described in detail | ||
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance). | ||
* The common options are: | ||
* @param {object} [options.credentials] - Credentials object. | ||
@@ -58,2 +60,9 @@ * @param {string} [options.credentials.client_email] | ||
* API remote host. | ||
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override. | ||
* TODO(@alexander-fenster): link to gax documentation. | ||
* @param {boolean} fallback - Use HTTP fallback mode. | ||
* In fallback mode, a special browser-compatible transport implementation is used | ||
* instead of gRPC transport. In browser context (if the `window` object is defined) | ||
* the fallback mode is enabled automatically; set `options.fallback` to `false` | ||
* if you need to override this behavior. | ||
*/ | ||
@@ -77,2 +86,3 @@ constructor(opts?: ClientOptions); | ||
* The DNS address for this API service. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -83,2 +93,3 @@ static get servicePath(): string; | ||
* exists for compatibility reasons. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -88,2 +99,3 @@ static get apiEndpoint(): string; | ||
* The port for this API service. | ||
* @returns {number} The default port for this service. | ||
*/ | ||
@@ -94,2 +106,3 @@ static get port(): number; | ||
* in this service. | ||
* @returns {string[]} List of default scopes. | ||
*/ | ||
@@ -158,2 +171,9 @@ static get scopes(): string[]; | ||
* An object stream which emits [BatchGetDocumentsResponse]{@link google.firestore.v1.BatchGetDocumentsResponse} on 'data' event. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.batchGetDocuments(request); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
*/ | ||
@@ -189,2 +209,9 @@ batchGetDocuments(request?: protos.google.firestore.v1.IBatchGetDocumentsRequest, options?: gax.CallOptions): gax.CancellableStream; | ||
* An object stream which emits [RunQueryResponse]{@link google.firestore.v1.RunQueryResponse} on 'data' event. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.runQuery(request); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
*/ | ||
@@ -201,2 +228,11 @@ runQuery(request?: protos.google.firestore.v1.IRunQueryRequest, options?: gax.CallOptions): gax.CancellableStream; | ||
* will emit objects representing [WriteResponse]{@link google.firestore.v1.WriteResponse} on 'data' event asynchronously. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.write(); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
* stream.write(request); | ||
* stream.end(); | ||
*/ | ||
@@ -213,2 +249,11 @@ write(options?: gax.CallOptions): gax.CancellableStream; | ||
* will emit objects representing [ListenResponse]{@link google.firestore.v1.ListenResponse} on 'data' event asynchronously. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.listen(); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
* stream.write(request); | ||
* stream.end(); | ||
*/ | ||
@@ -220,14 +265,3 @@ listen(options?: gax.CallOptions): gax.CancellableStream; | ||
/** | ||
* Equivalent to {@link listDocuments}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listDocuments} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -273,9 +307,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Document]{@link google.firestore.v1.Document} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listDocumentsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
listDocumentsStream(request?: protos.google.firestore.v1.IListDocumentsRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link listDocuments}, but returns an iterable object. | ||
* Equivalent to `listDocuments`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -320,3 +360,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Document]{@link google.firestore.v1.Document}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listDocumentsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -328,14 +379,3 @@ listDocumentsAsync(request?: protos.google.firestore.v1.IListDocumentsRequest, options?: gax.CallOptions): AsyncIterable<protos.google.firestore.v1.IDocument>; | ||
/** | ||
* Equivalent to {@link partitionQuery}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link partitionQuery} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -388,9 +428,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Cursor]{@link google.firestore.v1.Cursor} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `partitionQueryAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
partitionQueryStream(request?: protos.google.firestore.v1.IPartitionQueryRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link partitionQuery}, but returns an iterable object. | ||
* Equivalent to `partitionQuery`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -442,3 +488,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Cursor]{@link google.firestore.v1.Cursor}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.partitionQueryAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -450,14 +507,3 @@ partitionQueryAsync(request?: protos.google.firestore.v1.IPartitionQueryRequest, options?: gax.CallOptions): AsyncIterable<protos.google.firestore.v1.ICursor>; | ||
/** | ||
* Equivalent to {@link listCollectionIds}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listCollectionIds} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -479,9 +525,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing string on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listCollectionIdsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
listCollectionIdsStream(request?: protos.google.firestore.v1.IListCollectionIdsRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link listCollectionIds}, but returns an iterable object. | ||
* Equivalent to `listCollectionIds`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -502,11 +554,23 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* string. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listCollectionIdsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
listCollectionIdsAsync(request?: protos.google.firestore.v1.IListCollectionIdsRequest, options?: gax.CallOptions): AsyncIterable<string>; | ||
/** | ||
* Terminate the GRPC channel and close the client. | ||
* Terminate the gRPC channel and close the client. | ||
* | ||
* The client will no longer be usable and all future behavior is undefined. | ||
* @returns {Promise} A promise that resolves when the client is closed. | ||
*/ | ||
close(): Promise<void>; | ||
} |
@@ -45,4 +45,6 @@ /// <reference types="node" /> | ||
* | ||
* @param {object} [options] - The configuration object. See the subsequent | ||
* parameters for more details. | ||
* @param {object} [options] - The configuration object. | ||
* The options accepted by the constructor are described in detail | ||
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance). | ||
* The common options are: | ||
* @param {object} [options.credentials] - Credentials object. | ||
@@ -67,2 +69,9 @@ * @param {string} [options.credentials.client_email] | ||
* API remote host. | ||
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override. | ||
* TODO(@alexander-fenster): link to gax documentation. | ||
* @param {boolean} fallback - Use HTTP fallback mode. | ||
* In fallback mode, a special browser-compatible transport implementation is used | ||
* instead of gRPC transport. In browser context (if the `window` object is defined) | ||
* the fallback mode is enabled automatically; set `options.fallback` to `false` | ||
* if you need to override this behavior. | ||
*/ | ||
@@ -86,2 +95,3 @@ constructor(opts?: ClientOptions); | ||
* The DNS address for this API service. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -92,2 +102,3 @@ static get servicePath(): string; | ||
* exists for compatibility reasons. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -97,2 +108,3 @@ static get apiEndpoint(): string; | ||
* The port for this API service. | ||
* @returns {number} The default port for this service. | ||
*/ | ||
@@ -103,2 +115,3 @@ static get port(): number; | ||
* in this service. | ||
* @returns {string[]} List of default scopes. | ||
*/ | ||
@@ -164,2 +177,9 @@ static get scopes(): string[]; | ||
* An object stream which emits [BatchGetDocumentsResponse]{@link google.firestore.v1beta1.BatchGetDocumentsResponse} on 'data' event. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.batchGetDocuments(request); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
*/ | ||
@@ -195,2 +215,9 @@ batchGetDocuments(request?: protos.google.firestore.v1beta1.IBatchGetDocumentsRequest, options?: gax.CallOptions): gax.CancellableStream; | ||
* An object stream which emits [RunQueryResponse]{@link google.firestore.v1beta1.RunQueryResponse} on 'data' event. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.runQuery(request); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
*/ | ||
@@ -207,2 +234,11 @@ runQuery(request?: protos.google.firestore.v1beta1.IRunQueryRequest, options?: gax.CallOptions): gax.CancellableStream; | ||
* will emit objects representing [WriteResponse]{@link google.firestore.v1beta1.WriteResponse} on 'data' event asynchronously. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.write(); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
* stream.write(request); | ||
* stream.end(); | ||
*/ | ||
@@ -219,2 +255,11 @@ write(options?: gax.CallOptions): gax.CancellableStream; | ||
* will emit objects representing [ListenResponse]{@link google.firestore.v1beta1.ListenResponse} on 'data' event asynchronously. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.listen(); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
* stream.write(request); | ||
* stream.end(); | ||
*/ | ||
@@ -226,14 +271,3 @@ listen(options?: gax.CallOptions): gax.CancellableStream; | ||
/** | ||
* Equivalent to {@link listDocuments}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listDocuments} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -279,9 +313,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Document]{@link google.firestore.v1beta1.Document} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listDocumentsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
listDocumentsStream(request?: protos.google.firestore.v1beta1.IListDocumentsRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link listDocuments}, but returns an iterable object. | ||
* Equivalent to `listDocuments`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -326,3 +366,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Document]{@link google.firestore.v1beta1.Document}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listDocumentsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -334,14 +385,3 @@ listDocumentsAsync(request?: protos.google.firestore.v1beta1.IListDocumentsRequest, options?: gax.CallOptions): AsyncIterable<protos.google.firestore.v1beta1.IDocument>; | ||
/** | ||
* Equivalent to {@link listCollectionIds}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listCollectionIds} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -363,9 +403,15 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing string on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listCollectionIdsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
listCollectionIdsStream(request?: protos.google.firestore.v1beta1.IListCollectionIdsRequest, options?: gax.CallOptions): Transform; | ||
/** | ||
* Equivalent to {@link listCollectionIds}, but returns an iterable object. | ||
* Equivalent to `listCollectionIds`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -386,11 +432,23 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* string. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listCollectionIdsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
listCollectionIdsAsync(request?: protos.google.firestore.v1beta1.IListCollectionIdsRequest, options?: gax.CallOptions): AsyncIterable<string>; | ||
/** | ||
* Terminate the GRPC channel and close the client. | ||
* Terminate the gRPC channel and close the client. | ||
* | ||
* The client will no longer be usable and all future behavior is undefined. | ||
* @returns {Promise} A promise that resolves when the client is closed. | ||
*/ | ||
close(): Promise<void>; | ||
} |
@@ -50,4 +50,6 @@ "use strict"; | ||
* | ||
* @param {object} [options] - The configuration object. See the subsequent | ||
* parameters for more details. | ||
* @param {object} [options] - The configuration object. | ||
* The options accepted by the constructor are described in detail | ||
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance). | ||
* The common options are: | ||
* @param {object} [options.credentials] - Credentials object. | ||
@@ -72,4 +74,12 @@ * @param {string} [options.credentials.client_email] | ||
* API remote host. | ||
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override. | ||
* TODO(@alexander-fenster): link to gax documentation. | ||
* @param {boolean} fallback - Use HTTP fallback mode. | ||
* In fallback mode, a special browser-compatible transport implementation is used | ||
* instead of gRPC transport. In browser context (if the `window` object is defined) | ||
* the fallback mode is enabled automatically; set `options.fallback` to `false` | ||
* if you need to override this behavior. | ||
*/ | ||
constructor(opts) { | ||
var _a, _b; | ||
this._terminated = false; | ||
@@ -82,30 +92,16 @@ this.descriptors = { | ||
}; | ||
// Ensure that options include the service address and port. | ||
// Ensure that options include all the required fields. | ||
const staticMembers = this.constructor; | ||
const servicePath = opts && opts.servicePath | ||
? opts.servicePath | ||
: opts && opts.apiEndpoint | ||
? opts.apiEndpoint | ||
: staticMembers.servicePath; | ||
const port = opts && opts.port ? opts.port : staticMembers.port; | ||
if (!opts) { | ||
opts = { servicePath, port }; | ||
const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || staticMembers.servicePath; | ||
const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port; | ||
const clientConfig = (_a = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _a !== void 0 ? _a : {}; | ||
const fallback = (_b = opts === null || opts === void 0 ? void 0 : opts.fallback) !== null && _b !== void 0 ? _b : typeof window !== 'undefined'; | ||
opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts); | ||
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. | ||
if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { | ||
opts['scopes'] = staticMembers.scopes; | ||
} | ||
opts.servicePath = opts.servicePath || servicePath; | ||
opts.port = opts.port || port; | ||
// users can override the config from client side, like retry codes name. | ||
// The detailed structure of the clientConfig can be found here: https://github.com/googleapis/gax-nodejs/blob/master/src/gax.ts#L546 | ||
// The way to override client config for Showcase API: | ||
// | ||
// const customConfig = {"interfaces": {"google.showcase.v1beta1.Echo": {"methods": {"Echo": {"retry_codes_name": "idempotent", "retry_params_name": "default"}}}}} | ||
// const showcaseClient = new showcaseClient({ projectId, customConfig }); | ||
opts.clientConfig = opts.clientConfig || {}; | ||
// If we're running in browser, it's OK to omit `fallback` since | ||
// google-gax has `browser` field in its `package.json`. | ||
// For Electron (which does not respect `browser` field), | ||
// pass `{fallback: true}` to the FirestoreClient constructor. | ||
// Choose either gRPC or proto-over-HTTP implementation of google-gax. | ||
this._gaxModule = opts.fallback ? gax.fallback : gax; | ||
// Create a `gaxGrpc` object, with any grpc-specific options | ||
// sent to the client. | ||
opts.scopes = this.constructor.scopes; | ||
// Create a `gaxGrpc` object, with any grpc-specific options sent to the client. | ||
this._gaxGrpc = new this._gaxModule.GrpcClient(opts); | ||
@@ -116,2 +112,6 @@ // Save options to use in initialize() method. | ||
this.auth = this._gaxGrpc.auth; | ||
// Set the default scopes in auth client if needed. | ||
if (servicePath === staticMembers.servicePath) { | ||
this.auth.defaultScopes = staticMembers.scopes; | ||
} | ||
// Determine the client header string. | ||
@@ -220,2 +220,3 @@ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`]; | ||
* The DNS address for this API service. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -228,2 +229,3 @@ static get servicePath() { | ||
* exists for compatibility reasons. | ||
* @returns {string} The DNS address for this service. | ||
*/ | ||
@@ -235,2 +237,3 @@ static get apiEndpoint() { | ||
* The port for this API service. | ||
* @returns {number} The default port for this service. | ||
*/ | ||
@@ -243,2 +246,3 @@ static get port() { | ||
* in this service. | ||
* @returns {string[]} List of default scopes. | ||
*/ | ||
@@ -253,4 +257,3 @@ static get scopes() { | ||
* Return the project ID used by this class. | ||
* @param {function(Error, string)} callback - the callback to | ||
* be called with the current project Id. | ||
* @returns {Promise} A promise that resolves to string containing the project ID. | ||
*/ | ||
@@ -286,3 +289,7 @@ getProjectId(callback) { | ||
* The first element of the array is an object representing [Document]{@link google.firestore.v1beta1.Document}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.getDocument(request); | ||
*/ | ||
@@ -334,3 +341,7 @@ getDocument(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [Document]{@link google.firestore.v1beta1.Document}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.createDocument(request); | ||
*/ | ||
@@ -384,3 +395,7 @@ createDocument(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [Document]{@link google.firestore.v1beta1.Document}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.updateDocument(request); | ||
*/ | ||
@@ -421,3 +436,7 @@ updateDocument(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.deleteDocument(request); | ||
*/ | ||
@@ -458,3 +477,7 @@ deleteDocument(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [BeginTransactionResponse]{@link google.firestore.v1beta1.BeginTransactionResponse}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.beginTransaction(request); | ||
*/ | ||
@@ -498,3 +521,7 @@ beginTransaction(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [CommitResponse]{@link google.firestore.v1beta1.CommitResponse}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.commit(request); | ||
*/ | ||
@@ -534,3 +561,7 @@ commit(request, optionsOrCallback, callback) { | ||
* The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) | ||
* for more details and examples. | ||
* @example | ||
* const [response] = await client.rollback(request); | ||
*/ | ||
@@ -591,2 +622,9 @@ rollback(request, optionsOrCallback, callback) { | ||
* An object stream which emits [BatchGetDocumentsResponse]{@link google.firestore.v1beta1.BatchGetDocumentsResponse} on 'data' event. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.batchGetDocuments(request); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
*/ | ||
@@ -632,2 +670,9 @@ batchGetDocuments(request, options) { | ||
* An object stream which emits [RunQueryResponse]{@link google.firestore.v1beta1.RunQueryResponse} on 'data' event. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#server-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.runQuery(request); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
*/ | ||
@@ -654,2 +699,11 @@ runQuery(request, options) { | ||
* will emit objects representing [WriteResponse]{@link google.firestore.v1beta1.WriteResponse} on 'data' event asynchronously. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.write(); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
* stream.write(request); | ||
* stream.end(); | ||
*/ | ||
@@ -669,2 +723,11 @@ write(options) { | ||
* will emit objects representing [ListenResponse]{@link google.firestore.v1beta1.ListenResponse} on 'data' event asynchronously. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#bi-directional-streaming) | ||
* for more details and examples. | ||
* @example | ||
* const stream = client.listen(); | ||
* stream.on('data', (response) => { ... }); | ||
* stream.on('end', () => { ... }); | ||
* stream.write(request); | ||
* stream.end(); | ||
*/ | ||
@@ -718,15 +781,10 @@ listen(options) { | ||
* The first element of the array is Array of [Document]{@link google.firestore.v1beta1.Document}. | ||
* The client library support auto-pagination by default: it will call the API as many | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed and will merge results from all the pages into this array. | ||
* | ||
* When autoPaginate: false is specified through options, the array has three elements. | ||
* The first element is Array of [Document]{@link google.firestore.v1beta1.Document} that corresponds to | ||
* the one page received from the API server. | ||
* If the second element is not null it contains the request object of type [ListDocumentsRequest]{@link google.firestore.v1beta1.ListDocumentsRequest} | ||
* that can be used to obtain the next page of the results. | ||
* If it is null, the next page does not exist. | ||
* The third element contains the raw response received from the API server. Its type is | ||
* [ListDocumentsResponse]{@link google.firestore.v1beta1.ListDocumentsResponse}. | ||
* | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Note that it can affect your quota. | ||
* We recommend using `listDocumentsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -753,14 +811,3 @@ listDocuments(request, optionsOrCallback, callback) { | ||
/** | ||
* Equivalent to {@link listDocuments}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listDocuments} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -806,2 +853,9 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing [Document]{@link google.firestore.v1beta1.Document} on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listDocumentsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -821,6 +875,5 @@ listDocumentsStream(request, options) { | ||
/** | ||
* Equivalent to {@link listDocuments}, but returns an iterable object. | ||
* Equivalent to `listDocuments`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -865,3 +918,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* [Document]{@link google.firestore.v1beta1.Document}. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listDocumentsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -900,15 +964,10 @@ listDocumentsAsync(request, options) { | ||
* The first element of the array is Array of string. | ||
* The client library support auto-pagination by default: it will call the API as many | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed and will merge results from all the pages into this array. | ||
* | ||
* When autoPaginate: false is specified through options, the array has three elements. | ||
* The first element is Array of string that corresponds to | ||
* the one page received from the API server. | ||
* If the second element is not null it contains the request object of type [ListCollectionIdsRequest]{@link google.firestore.v1beta1.ListCollectionIdsRequest} | ||
* that can be used to obtain the next page of the results. | ||
* If it is null, the next page does not exist. | ||
* The third element contains the raw response received from the API server. Its type is | ||
* [ListCollectionIdsResponse]{@link google.firestore.v1beta1.ListCollectionIdsResponse}. | ||
* | ||
* The promise has a method named "cancel" which cancels the ongoing API call. | ||
* Note that it can affect your quota. | ||
* We recommend using `listCollectionIdsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -935,14 +994,3 @@ listCollectionIds(request, optionsOrCallback, callback) { | ||
/** | ||
* Equivalent to {@link listCollectionIds}, but returns a NodeJS Stream object. | ||
* | ||
* This fetches the paged responses for {@link listCollectionIds} continuously | ||
* and invokes the callback registered for 'data' event for each element in the | ||
* responses. | ||
* | ||
* The returned object has 'end' method when no more elements are required. | ||
* | ||
* autoPaginate option will be ignored. | ||
* | ||
* @see {@link https://nodejs.org/api/stream.html} | ||
* | ||
* Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. | ||
* @param {Object} request | ||
@@ -964,2 +1012,9 @@ * The request object that will be sent. | ||
* An object stream which emits an object representing string on 'data' event. | ||
* The client library will perform auto-pagination by default: it will call the API as many | ||
* times as needed. Note that it can affect your quota. | ||
* We recommend using `listCollectionIdsAsync()` | ||
* method described below for async iteration which you can stop as needed. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
*/ | ||
@@ -979,6 +1034,5 @@ listCollectionIdsStream(request, options) { | ||
/** | ||
* Equivalent to {@link listCollectionIds}, but returns an iterable object. | ||
* Equivalent to `listCollectionIds`, but returns an iterable object. | ||
* | ||
* for-await-of syntax is used with the iterable to recursively get response element on-demand. | ||
* | ||
* `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. | ||
* @param {Object} request | ||
@@ -999,3 +1053,14 @@ * The request object that will be sent. | ||
* @returns {Object} | ||
* An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols. | ||
* An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). | ||
* When you iterate the returned iterable, each element will be an object representing | ||
* string. The API will be called under the hood as needed, once per the page, | ||
* so you can stop the iteration when you don't need more results. | ||
* Please see the | ||
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) | ||
* for more details and examples. | ||
* @example | ||
* const iterable = client.listCollectionIdsAsync(request); | ||
* for await (const response of iterable) { | ||
* // process response | ||
* } | ||
*/ | ||
@@ -1016,5 +1081,6 @@ listCollectionIdsAsync(request, options) { | ||
/** | ||
* Terminate the GRPC channel and close the client. | ||
* Terminate the gRPC channel and close the client. | ||
* | ||
* The client will no longer be usable and all future behavior is undefined. | ||
* @returns {Promise} A promise that resolves when the client is closed. | ||
*/ | ||
@@ -1021,0 +1087,0 @@ close() { |
@@ -21,5 +21,6 @@ /*! | ||
import { Timestamp } from './timestamp'; | ||
import { FirestoreUnaryMethod } from './types'; | ||
import { RequiredArgumentOptions } from './validate'; | ||
import { GoogleError } from 'google-gax'; | ||
import api = google.firestore.v1; | ||
import { GoogleError } from 'google-gax'; | ||
/** | ||
@@ -99,2 +100,6 @@ * A WriteResult wraps the write time set by the Firestore servers on sets(), | ||
/** | ||
* The number of writes in this batch. | ||
*/ | ||
get _opCount(): number; | ||
/** | ||
* @hideconstructor | ||
@@ -221,12 +226,2 @@ */ | ||
/** | ||
* Commits all pending operations to the database and verifies all | ||
* preconditions. | ||
* | ||
* The writes in the batch are not applied atomically and can be applied out | ||
* of order. | ||
* | ||
* @private | ||
*/ | ||
bulkCommit(): Promise<BatchWriteResult[]>; | ||
/** | ||
* Commit method that takes an optional transaction ID. | ||
@@ -241,6 +236,8 @@ * | ||
*/ | ||
_commit(commitOptions?: { | ||
_commit<Req extends api.ICommitRequest, Resp>(commitOptions?: { | ||
transactionId?: Uint8Array; | ||
requestTag?: string; | ||
}): Promise<WriteResult[]>; | ||
retryCodes?: number[]; | ||
methodName?: FirestoreUnaryMethod; | ||
}): Promise<Resp>; | ||
/** | ||
@@ -247,0 +244,0 @@ * Resets the WriteBatch and dequeues all pending operations. |
@@ -110,2 +110,8 @@ "use strict"; | ||
/** | ||
* The number of writes in this batch. | ||
*/ | ||
get _opCount() { | ||
return this._ops.length; | ||
} | ||
/** | ||
* Checks if this write batch has any pending operations. | ||
@@ -365,5 +371,9 @@ * | ||
const data = dataOrField; | ||
Object.keys(data).forEach(key => { | ||
path_1.validateFieldPath(key, key); | ||
updateMap.set(path_1.FieldPath.fromArgument(key), data[key]); | ||
Object.entries(data).forEach(([key, value]) => { | ||
// Skip `undefined` values (can be hit if `ignoreUndefinedProperties` | ||
// is set) | ||
if (value !== undefined) { | ||
path_1.validateFieldPath(key, key); | ||
updateMap.set(path_1.FieldPath.fromArgument(key), value); | ||
} | ||
}); | ||
@@ -419,3 +429,9 @@ if (preconditionOrValues.length > 0) { | ||
const stack = Error().stack; | ||
return this._commit().catch(err => { | ||
// Commits should also be retried when they fail with status code ABORTED. | ||
const retryCodes = [google_gax_1.Status.ABORTED, ...util_1.getRetryCodes('commit')]; | ||
return this._commit({ retryCodes }) | ||
.then(response => { | ||
return (response.writeResults || []).map(writeResult => new WriteResult(timestamp_1.Timestamp.fromProto(writeResult.updateTime || response.commitTime))); | ||
}) | ||
.catch(err => { | ||
throw util_1.wrapError(err, stack); | ||
@@ -425,36 +441,2 @@ }); | ||
/** | ||
* Commits all pending operations to the database and verifies all | ||
* preconditions. | ||
* | ||
* The writes in the batch are not applied atomically and can be applied out | ||
* of order. | ||
* | ||
* @private | ||
*/ | ||
async bulkCommit() { | ||
this._committed = true; | ||
const tag = util_1.requestTag(); | ||
await this._firestore.initializeIfNeeded(tag); | ||
const database = this._firestore.formattedName; | ||
const request = { | ||
database, | ||
writes: this._ops.map(op => op.op()), | ||
}; | ||
const retryCodes = util_1.getRetryCodes('batchWrite'); | ||
const response = await this._firestore.request('batchWrite', request, tag, retryCodes); | ||
return response.writeResults.map((result, i) => { | ||
const status = response.status[i]; | ||
const error = new google_gax_1.GoogleError(status.message || undefined); | ||
error.code = status.code; | ||
// Since delete operations currently do not have write times, use a | ||
// sentinel Timestamp value. | ||
// TODO(b/158502664): Use actual delete timestamp. | ||
const DELETE_TIMESTAMP_SENTINEL = timestamp_1.Timestamp.fromMillis(0); | ||
const updateTime = error.code === google_gax_1.Status.OK | ||
? timestamp_1.Timestamp.fromProto(result.updateTime || DELETE_TIMESTAMP_SENTINEL) | ||
: null; | ||
return new BatchWriteResult(updateTime, error); | ||
}); | ||
} | ||
/** | ||
* Commit method that takes an optional transaction ID. | ||
@@ -470,10 +452,11 @@ * | ||
async _commit(commitOptions) { | ||
var _a; | ||
// Note: We don't call `verifyNotCommitted()` to allow for retries. | ||
this._committed = true; | ||
const tag = (commitOptions && commitOptions.requestTag) || util_1.requestTag(); | ||
const tag = (_a = commitOptions === null || commitOptions === void 0 ? void 0 : commitOptions.requestTag) !== null && _a !== void 0 ? _a : util_1.requestTag(); | ||
await this._firestore.initializeIfNeeded(tag); | ||
const database = this._firestore.formattedName; | ||
const explicitTransaction = commitOptions && commitOptions.transactionId; | ||
// Note that the request may not always be of type ICommitRequest. This is | ||
// just here to ensure type safety. | ||
const request = { | ||
database, | ||
database: this._firestore.formattedName, | ||
writes: this._ops.map(op => op.op()), | ||
@@ -485,13 +468,3 @@ }; | ||
logger_1.logger('WriteBatch.commit', tag, 'Sending %d writes', request.writes.length); | ||
let retryCodes; | ||
if (explicitTransaction) { | ||
request.transaction = explicitTransaction; | ||
} | ||
else { | ||
// Commits outside of transaction should also be retried when they fail | ||
// with status code ABORTED. | ||
retryCodes = [google_gax_1.Status.ABORTED, ...util_1.getRetryCodes('commit')]; | ||
} | ||
const response = await this._firestore.request('commit', request, tag, retryCodes); | ||
return (response.writeResults || []).map(writeResult => new WriteResult(timestamp_1.Timestamp.fromProto(writeResult.updateTime || response.commitTime))); | ||
return this._firestore.request((commitOptions === null || commitOptions === void 0 ? void 0 : commitOptions.methodName) || 'commit', request, tag, commitOptions === null || commitOptions === void 0 ? void 0 : commitOptions.retryCodes); | ||
} | ||
@@ -676,13 +649,7 @@ /** | ||
} | ||
let isEmpty = true; | ||
if (obj) { | ||
for (const prop of Object.keys(obj)) { | ||
isEmpty = false; | ||
validateFieldValue(arg, obj[prop], allowUndefined, new path_1.FieldPath(prop)); | ||
} | ||
} | ||
if (isEmpty) { | ||
if (Object.keys(obj).length === 0) { | ||
throw new Error('At least one field must be updated.'); | ||
} | ||
validateFieldValue(arg, obj, allowUndefined); | ||
} | ||
//# sourceMappingURL=write-batch.js.map |
@@ -7,2 +7,11 @@ # Changelog | ||
### [4.7.1](https://www.github.com/googleapis/nodejs-firestore/compare/v4.7.0...v4.7.1) (2020-11-10) | ||
### Bug Fixes | ||
* do not modify options object, use defaultScopes ([#1360](https://www.github.com/googleapis/nodejs-firestore/issues/1360)) ([bd40d3a](https://www.github.com/googleapis/nodejs-firestore/commit/bd40d3ae73cfd0a8e2503fca8d0aa28cb3bbcb86)) | ||
* ignore 'undefined' in update() with UpdateMap ([#1363](https://www.github.com/googleapis/nodejs-firestore/issues/1363)) ([9bad804](https://www.github.com/googleapis/nodejs-firestore/commit/9bad804205ab886c1a80351a8e7a7726e3d242ec)) | ||
* remove unneeded async signature from BulkWriter.sendBatch() ([#1361](https://www.github.com/googleapis/nodejs-firestore/issues/1361)) ([b5cf449](https://www.github.com/googleapis/nodejs-firestore/commit/b5cf4499724ff41e626a69f2db66be22167a7223)) | ||
## [4.7.0](https://www.github.com/googleapis/nodejs-firestore/compare/v4.6.1...v4.7.0) (2020-11-05) | ||
@@ -9,0 +18,0 @@ |
{ | ||
"name": "@google-cloud/firestore", | ||
"description": "Firestore Client Library for Node.js", | ||
"version": "4.7.0", | ||
"version": "4.7.1", | ||
"license": "Apache-2.0", | ||
@@ -57,3 +57,3 @@ "author": "Google Inc.", | ||
"functional-red-black-tree": "^1.0.1", | ||
"google-gax": "^2.2.0" | ||
"google-gax": "^2.9.2" | ||
}, | ||
@@ -60,0 +60,0 @@ "devDependencies": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4481270
83299
Updatedgoogle-gax@^2.9.2