@google-cloud/firestore
Advanced tools
Comparing version 3.3.2 to 3.3.3
@@ -22,3 +22,2 @@ "use strict"; | ||
const path_1 = require("./path"); | ||
const serializer_1 = require("./serializer"); | ||
const util_1 = require("./util"); | ||
@@ -568,3 +567,3 @@ /** | ||
} | ||
else if (serializer_1.isPlainObject(value)) { | ||
else if (util_1.isPlainObject(value)) { | ||
extractFieldPaths(value, childPath); | ||
@@ -773,3 +772,3 @@ } | ||
} | ||
else if (serializer_1.isPlainObject(val)) { | ||
else if (util_1.isPlainObject(val)) { | ||
for (const prop of Object.keys(val)) { | ||
@@ -776,0 +775,0 @@ encode_(val[prop], path.append(new path_1.FieldPath(prop)), allowTransforms); |
@@ -25,3 +25,3 @@ /*! | ||
import { Transaction } from './transaction'; | ||
import { ReadOptions, Settings } from './types'; | ||
import { FirestoreStreamingMethod, FirestoreUnaryMethod, ReadOptions, Settings } from './types'; | ||
import { WriteBatch } from './write-batch'; | ||
@@ -490,3 +490,3 @@ import api = google.firestore.v1; | ||
* A funnel for all non-streaming API requests, assigning a project ID where | ||
* necessary within the request options. | ||
* necessary within the request options. | ||
* | ||
@@ -500,3 +500,3 @@ * @private | ||
*/ | ||
request<T>(methodName: string, request: {}, requestTag: string): Promise<T>; | ||
request<Req, Resp>(methodName: FirestoreUnaryMethod, request: Req, requestTag: string): Promise<Resp>; | ||
/** | ||
@@ -512,3 +512,2 @@ * A funnel for streaming API requests, assigning a project ID where necessary | ||
* takes a request and GAX options. | ||
* @param mode Whether this a unidirectional or bidirectional call. | ||
* @param request The Protobuf request to send. | ||
@@ -518,3 +517,3 @@ * @param requestTag A unique client-assigned identifier for this request. | ||
*/ | ||
requestStream(methodName: string, mode: 'unidirectional' | 'bidirectional', request: {}, requestTag: string): Promise<Duplex>; | ||
requestStream(methodName: FirestoreStreamingMethod, request: {}, requestTag: string): Promise<Duplex>; | ||
} | ||
@@ -521,0 +520,0 @@ /** |
@@ -324,3 +324,3 @@ "use strict"; | ||
}, | ||
/* clientDestructor= */ (client) => client.close()); | ||
/* clientDestructor= */ client => client.close()); | ||
logger_1.logger('Firestore', null, 'Initialized Firestore'); | ||
@@ -703,3 +703,3 @@ } | ||
return self | ||
.requestStream('batchGetDocuments', 'unidirectional', request, requestTag) | ||
.requestStream('batchGetDocuments', request, requestTag) | ||
.then(stream => { | ||
@@ -771,16 +771,10 @@ return new Promise((resolve, reject) => { | ||
if (this._projectId === undefined) { | ||
this._projectId = await this._clientPool.run(requestTag, gapicClient => { | ||
return new Promise((resolve, reject) => { | ||
gapicClient.getProjectId((err, projectId) => { | ||
if (err) { | ||
logger_1.logger('Firestore._detectProjectId', null, 'Failed to detect project ID: %s', err); | ||
reject(err); | ||
} | ||
else { | ||
logger_1.logger('Firestore._detectProjectId', null, 'Detected project ID: %s', projectId); | ||
resolve(projectId); | ||
} | ||
}); | ||
}); | ||
}); | ||
try { | ||
this._projectId = await this._clientPool.run(requestTag, gapicClient => gapicClient.getProjectId()); | ||
logger_1.logger('Firestore.initializeIfNeeded', null, 'Detected project ID: %s', this._projectId); | ||
} | ||
catch (err) { | ||
logger_1.logger('Firestore.initializeIfNeeded', null, 'Failed to detect project ID: %s', err); | ||
return Promise.reject(err); | ||
} | ||
} | ||
@@ -911,3 +905,3 @@ } | ||
* A funnel for all non-streaming API requests, assigning a project ID where | ||
* necessary within the request options. | ||
* necessary within the request options. | ||
* | ||
@@ -923,17 +917,14 @@ * @private | ||
const callOptions = this.createCallOptions(); | ||
return this._clientPool.run(requestTag, gapicClient => { | ||
return new Promise((resolve, reject) => { | ||
return this._clientPool.run(requestTag, async (gapicClient) => { | ||
try { | ||
logger_1.logger('Firestore.request', requestTag, 'Sending request: %j', request); | ||
gapicClient[methodName](request, callOptions, (err, result) => { | ||
if (err) { | ||
logger_1.logger('Firestore.request', requestTag, 'Received error:', err); | ||
reject(err); | ||
} | ||
else { | ||
logger_1.logger('Firestore.request', requestTag, 'Received response: %j', result); | ||
this._lastSuccessfulRequest = new Date().getTime(); | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
const [result] = await gapicClient[methodName](request, callOptions); | ||
logger_1.logger('Firestore.request', requestTag, 'Received response: %j', result); | ||
this._lastSuccessfulRequest = new Date().getTime(); | ||
return result; | ||
} | ||
catch (err) { | ||
logger_1.logger('Firestore.request', requestTag, 'Received error:', err); | ||
return Promise.reject(err); | ||
} | ||
}); | ||
@@ -951,3 +942,2 @@ } | ||
* takes a request and GAX options. | ||
* @param mode Whether this a unidirectional or bidirectional call. | ||
* @param request The Protobuf request to send. | ||
@@ -957,4 +947,5 @@ * @param requestTag A unique client-assigned identifier for this request. | ||
*/ | ||
requestStream(methodName, mode, request, requestTag) { | ||
requestStream(methodName, request, requestTag) { | ||
const callOptions = this.createCallOptions(); | ||
const bidrectional = methodName === 'listen'; | ||
const result = new util_1.Deferred(); | ||
@@ -968,5 +959,5 @@ this._clientPool.run(requestTag, gapicClient => { | ||
logger_1.logger('Firestore.requestStream', requestTag, 'Sending request: %j', request); | ||
const stream = mode === 'unidirectional' | ||
? gapicClient[methodName](request, callOptions) | ||
: gapicClient[methodName](callOptions); | ||
const stream = bidrectional | ||
? gapicClient[methodName](callOptions) | ||
: gapicClient[methodName](request, callOptions); | ||
const logStream = through2.obj(function (chunk, enc, callback) { | ||
@@ -981,3 +972,3 @@ logger_1.logger('Firestore.requestStream', requestTag, 'Received response: %j', chunk); | ||
stream.on('error', lifetime.resolve); | ||
const resultStream = await this._initializeStream(stream, requestTag, mode === 'bidirectional' ? request : undefined); | ||
const resultStream = await this._initializeStream(stream, requestTag, bidrectional ? request : undefined); | ||
resultStream.on('end', () => stream.end()); | ||
@@ -984,0 +975,0 @@ result.resolve(resultStream); |
@@ -72,3 +72,2 @@ "use strict"; | ||
requestCount < this.concurrentOperationLimit) { | ||
logger_1.logger('ClientPool.acquire', requestTag, 'Re-using existing client with %s remaining operations', this.concurrentOperationLimit - requestCount); | ||
selectedClient = client; | ||
@@ -155,3 +154,3 @@ selectedClientRequestCount = requestCount; | ||
if (this.terminated) { | ||
throw new Error('The client has already been terminated'); | ||
return Promise.reject('The client has already been terminated'); | ||
} | ||
@@ -158,0 +157,0 @@ const client = this.acquire(requestTag); |
@@ -64,11 +64,2 @@ /*! | ||
/** | ||
* Verifies that 'obj' is a plain JavaScript object that can be encoded as a | ||
* 'Map' in Firestore. | ||
* | ||
* @private | ||
* @param input The argument to verify. | ||
* @returns 'true' if the input can be a treated as a plain object. | ||
*/ | ||
export declare function isPlainObject(input: unknown): input is DocumentData; | ||
/** | ||
* Validates a JavaScript value for usage as a Firestore value. | ||
@@ -75,0 +66,0 @@ * |
@@ -136,3 +136,3 @@ "use strict"; | ||
} | ||
if (typeof val === 'object' && isPlainObject(val)) { | ||
if (typeof val === 'object' && util_1.isPlainObject(val)) { | ||
const map = { | ||
@@ -219,16 +219,2 @@ mapValue: {}, | ||
/** | ||
* Verifies that 'obj' is a plain JavaScript object that can be encoded as a | ||
* 'Map' in Firestore. | ||
* | ||
* @private | ||
* @param input The argument to verify. | ||
* @returns 'true' if the input can be a treated as a plain object. | ||
*/ | ||
function isPlainObject(input) { | ||
return (util_1.isObject(input) && | ||
(Object.getPrototypeOf(input) === Object.prototype || | ||
Object.getPrototypeOf(input) === null)); | ||
} | ||
exports.isPlainObject = isPlainObject; | ||
/** | ||
* Validates a JavaScript value for usage as a Firestore value. | ||
@@ -261,3 +247,3 @@ * | ||
} | ||
else if (isPlainObject(value)) { | ||
else if (util_1.isPlainObject(value)) { | ||
for (const prop of Object.keys(value)) { | ||
@@ -264,0 +250,0 @@ validateUserInput(arg, value[prop], desc, options, path ? path.append(new path_1.FieldPath(prop)) : new path_1.FieldPath(prop), level + 1, inArray); |
@@ -20,3 +20,2 @@ "use strict"; | ||
const reference_1 = require("./reference"); | ||
const serializer_1 = require("./serializer"); | ||
const util_1 = require("./util"); | ||
@@ -328,3 +327,3 @@ const validate_1 = require("./validate"); | ||
if (documentRefsOrReadOptions.length > 0 && | ||
serializer_1.isPlainObject(documentRefsOrReadOptions[documentRefsOrReadOptions.length - 1])) { | ||
util_1.isPlainObject(documentRefsOrReadOptions[documentRefsOrReadOptions.length - 1])) { | ||
readOptions = documentRefsOrReadOptions.pop(); | ||
@@ -331,0 +330,0 @@ documents = documentRefsOrReadOptions; |
@@ -16,2 +16,5 @@ /*! | ||
*/ | ||
/// <reference types="node" /> | ||
import { CallOptions } from 'google-gax'; | ||
import { Duplex } from 'stream'; | ||
import { google } from '../protos/firestore_v1_proto_api'; | ||
@@ -27,3 +30,26 @@ import { FieldPath } from './path'; | ||
} | ||
export declare type GapicClient = any; | ||
/** | ||
* The subset of methods we use from FirestoreClient. | ||
* | ||
* We don't depend on the actual Gapic client to avoid loading the GAX stack at | ||
* module initialization time. | ||
*/ | ||
export interface GapicClient { | ||
getProjectId(): Promise<string>; | ||
beginTransaction(request: api.IBeginTransactionRequest, options?: CallOptions): Promise<[api.IBeginTransactionResponse, unknown, unknown]>; | ||
commit(request: api.ICommitRequest, options?: CallOptions): Promise<[api.ICommitResponse, unknown, unknown]>; | ||
rollback(request: api.IRollbackRequest, options?: CallOptions): Promise<[google.protobuf.IEmpty, unknown, unknown]>; | ||
batchGetDocuments(request?: api.IBatchGetDocumentsRequest, options?: CallOptions): Duplex; | ||
runQuery(request?: api.IRunQueryRequest, options?: CallOptions): Duplex; | ||
listDocuments(request: api.IListDocumentsRequest, options?: CallOptions): Promise<[api.IDocument[], unknown, unknown]>; | ||
listCollectionIds(request: api.IListCollectionIdsRequest, options?: CallOptions): Promise<[string[], unknown, unknown]>; | ||
listen(options?: CallOptions): Duplex; | ||
close(): Promise<void>; | ||
} | ||
/** Request/response methods used in the Firestore SDK. */ | ||
export declare type FirestoreUnaryMethod = 'listDocuments' | 'listCollectionIds' | 'rollback' | 'beginTransaction' | 'commit'; | ||
/** Streaming methods used in the Firestore SDK. */ | ||
export declare type FirestoreStreamingMethod = 'listen' | 'runQuery' | 'batchGetDocuments'; | ||
/** Type signature for the unary methods in the GAPIC layer. */ | ||
export declare type UnaryMethod<Req, Resp> = (request: Req, callOptions: CallOptions) => Promise<[Resp, unknown, unknown]>; | ||
export declare type RBTree = any; | ||
@@ -30,0 +56,0 @@ /** |
@@ -17,2 +17,3 @@ /*! | ||
import { GoogleError, ServiceConfig } from 'google-gax'; | ||
import { DocumentData } from './types'; | ||
/** | ||
@@ -55,2 +56,11 @@ * A Promise implementation that supports deferred resolution. | ||
/** | ||
* Verifies that 'obj' is a plain JavaScript object that can be encoded as a | ||
* 'Map' in Firestore. | ||
* | ||
* @private | ||
* @param input The argument to verify. | ||
* @returns 'true' if the input can be a treated as a plain object. | ||
*/ | ||
export declare function isPlainObject(input: unknown): input is DocumentData; | ||
/** | ||
* Returns whether `value` has no custom properties. | ||
@@ -57,0 +67,0 @@ * |
@@ -73,2 +73,17 @@ "use strict"; | ||
/** | ||
* Verifies that 'obj' is a plain JavaScript object that can be encoded as a | ||
* 'Map' in Firestore. | ||
* | ||
* @private | ||
* @param input The argument to verify. | ||
* @returns 'true' if the input can be a treated as a plain object. | ||
*/ | ||
function isPlainObject(input) { | ||
return (isObject(input) && | ||
(Object.getPrototypeOf(input) === Object.prototype || | ||
Object.getPrototypeOf(input) === null || | ||
input.constructor.name === 'Object')); | ||
} | ||
exports.isPlainObject = isPlainObject; | ||
/** | ||
* Returns whether `value` has no custom properties. | ||
@@ -75,0 +90,0 @@ * |
@@ -348,3 +348,3 @@ "use strict"; | ||
options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ | ||
document_name: request.document.name || '', | ||
'document.name': request.document.name || '', | ||
}); | ||
@@ -351,0 +351,0 @@ return this._innerApiCalls.updateDocument(request, options, callback); |
@@ -356,3 +356,3 @@ "use strict"; | ||
options.otherArgs.headers['x-goog-request-params'] = gax.routingHeader.fromParams({ | ||
document_name: request.document.name || '', | ||
'document.name': request.document.name || '', | ||
}); | ||
@@ -359,0 +359,0 @@ return this._innerApiCalls.updateDocument(request, options, callback); |
@@ -21,18 +21,2 @@ "use strict"; | ||
/** | ||
* Returns the name of the base class (ignoring Object). | ||
* | ||
* @private | ||
* @param value The object whose base class name to extract. | ||
* @returns The name of the base class constructor or "Object" if value does not | ||
* extend a custom class. | ||
*/ | ||
function extractBaseClassName(value) { | ||
let constructorName = 'Object'; | ||
while (Object.getPrototypeOf(value) !== Object.prototype) { | ||
value = Object.getPrototypeOf(value); | ||
constructorName = value.constructor.name; | ||
} | ||
return constructorName; | ||
} | ||
/** | ||
* Generates an error message to use with custom objects that cannot be | ||
@@ -52,3 +36,3 @@ * serialized. | ||
// using the base name, we reduce the number of special cases below. | ||
const typeName = extractBaseClassName(value); | ||
const typeName = value.constructor.name; | ||
switch (typeName) { | ||
@@ -55,0 +39,0 @@ case 'DocumentReference': |
@@ -260,3 +260,3 @@ "use strict"; | ||
return this.firestore | ||
.requestStream('listen', 'bidirectional', request, this.requestTag) | ||
.requestStream('listen', request, this.requestTag) | ||
.then(backendStream => { | ||
@@ -263,0 +263,0 @@ if (!this.isActive) { |
@@ -417,3 +417,2 @@ "use strict"; | ||
const database = this._firestore.formattedName; | ||
const request = { database }; | ||
// On GCF, we periodically force transactional commits to allow for | ||
@@ -425,3 +424,3 @@ // request retries in case GCF closes our backend connection. | ||
return this._firestore | ||
.request('beginTransaction', request, tag) | ||
.request('beginTransaction', { database }, tag) | ||
.then(resp => { | ||
@@ -431,2 +430,3 @@ return this.commit_({ transactionId: resp.transaction }); | ||
} | ||
const request = { database }; | ||
const writes = this._ops.map(op => op()); | ||
@@ -609,3 +609,3 @@ request.writes = []; | ||
function validateDocumentData(arg, obj, allowDeletes) { | ||
if (!serializer_1.isPlainObject(obj)) { | ||
if (!util_1.isPlainObject(obj)) { | ||
throw new Error(validate_1.customObjectMessage(arg, obj)); | ||
@@ -662,3 +662,3 @@ } | ||
function validateUpdateMap(arg, obj) { | ||
if (!serializer_1.isPlainObject(obj)) { | ||
if (!util_1.isPlainObject(obj)) { | ||
throw new Error(validate_1.customObjectMessage(arg, obj)); | ||
@@ -665,0 +665,0 @@ } |
@@ -7,2 +7,10 @@ # Changelog | ||
### [3.3.3](https://www.github.com/googleapis/nodejs-firestore/compare/v3.3.2...v3.3.3) (2020-01-08) | ||
### Bug Fixes | ||
* support Objects created with Object.create({}) ([#842](https://www.github.com/googleapis/nodejs-firestore/issues/842)) ([a85f0c3](https://www.github.com/googleapis/nodejs-firestore/commit/a85f0c32eca5d8cf677d621a8ff326623ad5266e)) | ||
* use rejected Promise for terminate() ([#845](https://www.github.com/googleapis/nodejs-firestore/issues/845)) ([f2c4d91](https://www.github.com/googleapis/nodejs-firestore/commit/f2c4d911077c8e5b7713263fc8b2c21bbd50ca11)) | ||
### [3.3.2](https://www.github.com/googleapis/nodejs-firestore/compare/v3.3.1...v3.3.2) (2020-01-06) | ||
@@ -9,0 +17,0 @@ |
{ | ||
"name": "@google-cloud/firestore", | ||
"description": "Firestore Client Library for Node.js", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"license": "Apache-2.0", | ||
@@ -43,3 +43,4 @@ "author": "Google Inc.", | ||
"clean": "gts clean", | ||
"compile": "tsc -p . && cp -r dev/protos build && cp -r dev/test/fake-certificate.json build/test/fake-certificate.json && cp dev/src/v1beta1/*.json build/src/v1beta1/ && cp dev/src/v1/*.json build/src/v1/ && cp dev/conformance/test-definition.proto build/conformance && cp dev/conformance/test-suite.binproto build/conformance", | ||
"compile": "tsc -p .", | ||
"postcompile": "cp -r dev/protos build && cp dev/src/v1beta1/*.json build/src/v1beta1/ && cp dev/src/v1/*.json build/src/v1/ && cp dev/conformance/test-definition.proto build/conformance && cp dev/conformance/test-suite.binproto build/conformance", | ||
"fix": "gts fix", | ||
@@ -46,0 +47,0 @@ "prepare": "npm run compile", |
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
2417464
49388