diff --git a/package-lock.json b/package-lock.json index 3d85020b5..7f9aee3ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4836,49 +4836,6 @@ "path-type": "3.0.0" } }, - "dom-serializer": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.0.tgz", - "integrity": "sha1-BzxpdUbOB4DOI75KKOKT5AvDDII=", - "dev": true, - "requires": { - "domelementtype": "1.1.3", - "entities": "1.1.1" - }, - "dependencies": { - "domelementtype": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz", - "integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=", - "dev": true - } - } - }, - "domelementtype": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.0.tgz", - "integrity": "sha1-sXrtguirWeUt2cGbF1bg/BhyBMI=", - "dev": true - }, - "domhandler": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", - "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", - "dev": true, - "requires": { - "domelementtype": "1.3.0" - } - }, - "domutils": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.7.0.tgz", - "integrity": "sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==", - "dev": true, - "requires": { - "dom-serializer": "0.1.0", - "domelementtype": "1.3.0" - } - }, "dot-prop": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", @@ -4967,12 +4924,6 @@ "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz", "integrity": "sha1-6WQhkyWiHQX0RGai9obtbOX13R0=" }, - "entities": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", - "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", - "dev": true - }, "equal-length": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/equal-length/-/equal-length-1.0.1.tgz", @@ -5547,7 +5498,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", "integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=", - "dev": true, "requires": { "locate-path": "2.0.0" } @@ -7139,20 +7089,6 @@ "integrity": "sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==", "dev": true }, - "htmlparser2": { - "version": "3.9.2", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.9.2.tgz", - "integrity": "sha1-G9+HrMoPP55T+k/M6w9LTLsAszg=", - "dev": true, - "requires": { - "domelementtype": "1.3.0", - "domhandler": "2.4.2", - "domutils": "1.7.0", - "entities": "1.1.1", - "inherits": "2.0.3", - "readable-stream": "2.3.6" - } - }, "http-cache-semantics": { "version": "3.8.1", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-3.8.1.tgz", @@ -7273,14 +7209,6 @@ "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "dev": true }, - "ink-docstrap": { - "version": "git+https://github.com/docstrap/docstrap.git#1e56828b819bcbc9855543bd20809a0aed415a80", - "dev": true, - "requires": { - "moment": "2.22.2", - "sanitize-html": "1.18.2" - } - }, "inquirer": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.0.0.tgz", @@ -7964,7 +7892,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", "integrity": "sha1-K1aLJl7slExtnA3pw9u7ygNUzY4=", - "dev": true, "requires": { "p-locate": "2.0.0", "path-exists": "3.0.0" @@ -7999,12 +7926,6 @@ "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=", "dev": true }, - "lodash.escaperegexp": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz", - "integrity": "sha1-ZHYsSGGAglGKw99Mz11YhtriA0c=", - "dev": true - }, "lodash.flatten": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", @@ -8029,12 +7950,6 @@ "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA=", "dev": true }, - "lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=", - "dev": true - }, "lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", @@ -8045,12 +7960,6 @@ "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz", "integrity": "sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ==" }, - "lodash.mergewith": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.1.tgz", - "integrity": "sha512-eWw5r+PYICtEBgrBE5hhlT6aAa75f411bgDz/ZL2KZqYV03USvucsxcHUIlGTDTECs1eunpI7HOV7U+WLDvNdQ==", - "dev": true - }, "lolex": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.7.1.tgz", @@ -8462,12 +8371,6 @@ "integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=", "dev": true }, - "moment": { - "version": "2.22.2", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz", - "integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y=", - "dev": true - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -10866,7 +10769,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", - "dev": true, "requires": { "p-try": "1.0.0" } @@ -10875,7 +10777,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", "integrity": "sha1-IKAQOyIqcMj9OcwuWAaA893l7EM=", - "dev": true, "requires": { "p-limit": "1.3.0" } @@ -10892,8 +10793,7 @@ "p-try": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", - "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=", - "dev": true + "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" }, "package-hash": { "version": "2.0.0", @@ -10997,8 +10897,7 @@ "path-exists": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", - "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=", - "dev": true + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" }, "path-is-absolute": { "version": "1.0.1", @@ -11122,6 +11021,14 @@ "find-up": "2.1.0" } }, + "pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pkg-up/-/pkg-up-2.0.0.tgz", + "integrity": "sha1-yBmscoBZpGHKscOImivjxJoATX8=", + "requires": { + "find-up": "2.1.0" + } + }, "plur": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/plur/-/plur-2.1.2.tgz", @@ -11136,25 +11043,6 @@ "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, - "postcss": { - "version": "6.0.23", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-6.0.23.tgz", - "integrity": "sha512-soOk1h6J3VMTZtVeVpv15/Hpdl2cBLX3CAw4TAbkpTJiNPk9YP/zWcD1ND+xEtvyuuvKzbxliTOIyvkSeSJ6ag==", - "dev": true, - "requires": { - "chalk": "2.4.1", - "source-map": "0.6.1", - "supports-color": "5.4.0" - }, - "dependencies": { - "source-map": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", - "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "dev": true - } - } - }, "power-assert": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/power-assert/-/power-assert-1.6.0.tgz", @@ -11810,24 +11698,6 @@ "integrity": "sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg==", "dev": true }, - "sanitize-html": { - "version": "1.18.2", - "resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-1.18.2.tgz", - "integrity": "sha512-52ThA+Z7h6BnvpSVbURwChl10XZrps5q7ytjTwWcIe9bmJwnVP6cpEVK2NvDOUhGupoqAvNbUz3cpnJDp4+/pg==", - "dev": true, - "requires": { - "chalk": "2.4.1", - "htmlparser2": "3.9.2", - "lodash.clonedeep": "4.5.0", - "lodash.escaperegexp": "4.1.2", - "lodash.isplainobject": "4.0.6", - "lodash.isstring": "4.0.1", - "lodash.mergewith": "4.6.1", - "postcss": "6.0.23", - "srcset": "1.0.0", - "xtend": "4.0.1" - } - }, "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", @@ -12154,16 +12024,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "srcset": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/srcset/-/srcset-1.0.0.tgz", - "integrity": "sha1-pWad4StC87HV6D7QPHEEb8SPQe8=", - "dev": true, - "requires": { - "array-uniq": "1.0.3", - "number-is-nan": "1.0.1" - } - }, "sshpk": { "version": "1.14.2", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.2.tgz", diff --git a/package.json b/package.json index e530ef195..03026384e 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "google-proto-files": "^0.16.1", "is": "^3.2.1", "lodash.merge": "^4.6.1", + "pkg-up": "^2.0.0", "through2": "^2.0.3" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index 3676df82d..e623f9567 100644 --- a/src/index.js +++ b/src/index.js @@ -20,17 +20,11 @@ const assert = require('assert'); const bun = require('bun'); const extend = require('extend'); const is = require('is'); +const pkgUp = require('pkg-up'); const through = require('through2'); const util = require('util'); -let libVersion; - -// Allow Firestore to be run both from 'src' and 'build/src'. -try { - libVersion = require('../package.json').version; -} catch (err) { - libVersion = require('../../package.json').version; -} +const libVersion = require(pkgUp.sync()).version; const path = require('./path'); const convert = require('./convert'); @@ -135,7 +129,7 @@ const MAX_REQUEST_RETRIES = 5; /*! * The maximum number of concurrent requests supported by a single GRPC channel, * as enforced by Google's Frontend. If the SDK issues more than 100 concurrent - * operations, we need to use more than one GAPIC client since these client + * operations, we need to use more than one GAPIC client since these clients * multiplex all requests over a single channel. * * @type {number} diff --git a/src/v1beta1/firestore_client.js b/src/v1beta1/firestore_client.js index fa1608b3b..83a5def1b 100644 --- a/src/v1beta1/firestore_client.js +++ b/src/v1beta1/firestore_client.js @@ -18,15 +18,9 @@ const gapicConfig = require('./firestore_client_config'); const gax = require('google-gax'); const merge = require('lodash.merge'); const path = require('path'); +const pkgUp = require('pkg-up'); -let VERSION; - -// Allow Firestore to be run both from 'src' and 'build/src'. -try { - VERSION = require('../../../package.json').version; -} catch (e) { - VERSION = require('../../package.json').version; -} +const VERSION = require(pkgUp.sync()).version; /** * The Cloud Firestore service. diff --git a/system-test/firestore.js b/system-test/firestore.js index 463a240b9..7e3aac80c 100644 --- a/system-test/firestore.js +++ b/system-test/firestore.js @@ -18,18 +18,13 @@ let assert = require('power-assert'); let is = require('is'); +let pkgUp = require('pkg-up'); let DocumentReference = require('../src/reference').DocumentReference; let DocumentSnapshot = require('../src/document')(DocumentReference).DocumentSnapshot; -let version; -try { - version = require('../../package.json').version; -} catch (e) { - version = require('../package.json').version; -} - +let version = require(pkgUp.sync()).version; let Firestore = require('../src'); if (process.env.NODE_ENV === 'DEBUG') { diff --git a/test/timestamp.js b/test/timestamp.js index 29047e0f4..13cc3046d 100644 --- a/test/timestamp.js +++ b/test/timestamp.js @@ -115,11 +115,7 @@ describe('timestamps', function() { it('convert to date', function() { return createInstance( - { - timestampsInSnapshots: true, - keyFilename: './test/fake-certificate.json', - }, - DOCUMENT_WITH_TIMESTAMP) + {timestampsInSnapshots: true}, DOCUMENT_WITH_TIMESTAMP) .then(firestore => { return firestore.doc('coll/doc').get().then(res => { const timestamp = res.get('moonLanding'); @@ -132,11 +128,7 @@ describe('timestamps', function() { it('convert to millis', function() { return createInstance( - { - timestampsInSnapshots: true, - keyFilename: './test/fake-certificate.json', - }, - DOCUMENT_WITH_TIMESTAMP) + {timestampsInSnapshots: true}, DOCUMENT_WITH_TIMESTAMP) .then(firestore => { return firestore.doc('coll/doc').get().then(res => { const timestamp = res.get('moonLanding'); @@ -147,11 +139,7 @@ describe('timestamps', function() { it('support missing values', function() { return createInstance( - { - timestampsInSnapshots: true, - keyFilename: './test/fake-certificate.json', - }, - DOCUMENT_WITH_EMPTY_TIMESTAMP) + {timestampsInSnapshots: true}, DOCUMENT_WITH_EMPTY_TIMESTAMP) .then(firestore => { const expected = new Firestore.Timestamp(0, 0); diff --git a/test/transaction.js b/test/transaction.js index aaf6c085c..48a402187 100644 --- a/test/transaction.js +++ b/test/transaction.js @@ -213,34 +213,37 @@ function query(transaction) { }; } -function runTransaction(callback, ...requests) { +/** + * Asserts that the given transaction function issues the expected requests. + */ +function runTransaction(transactionCallback, ...expectedRequests) { const overrides = { beginTransaction: (actual, options, callback) => { - const request = requests.shift(); + const request = expectedRequests.shift(); assert.equal(request.type, 'begin'); assert.deepEqual(actual, request.request); callback(request.error, request.response); }, commit: (actual, options, callback) => { - const request = requests.shift(); + const request = expectedRequests.shift(); assert.equal(request.type, 'commit'); assert.deepEqual(actual, request.request); callback(request.error, request.response); }, rollback: (actual, options, callback) => { - const request = requests.shift(); + const request = expectedRequests.shift(); assert.equal(request.type, 'rollback'); assert.deepEqual(actual, request.request); callback(request.error, request.response); }, batchGetDocuments: (actual) => { - const request = requests.shift(); + const request = expectedRequests.shift(); assert.equal(request.type, 'getDocument'); assert.deepEqual(actual, request.request); return request.stream; }, runQuery: (actual) => { - const request = requests.shift(); + const request = expectedRequests.shift(); assert.equal(request.type, 'query'); assert.deepEqual(actual, request.request); return request.stream; @@ -251,14 +254,14 @@ function runTransaction(callback, ...requests) { return firestore .runTransaction(transaction => { const docRef = firestore.doc('collectionId/documentId'); - return callback(transaction, docRef); + return transactionCallback(transaction, docRef); }) .then(val => { - assert.equal(requests.length, 0); + assert.equal(expectedRequests.length, 0); return val; }) .catch(err => { - assert.equal(requests.length, 0); + assert.equal(expectedRequests.length, 0); return Promise.reject(err); }); });