From b2057f0e964010afb59f6795f076222f51472172 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Mon, 15 Aug 2016 16:03:00 -0700 Subject: [PATCH 1/3] Switch to individual API packages. --- appengine/datastore/app.js | 23 ++-- appengine/datastore/package.json | 6 +- appengine/datastore/test/app.test.js | 13 +- appengine/pubsub/app.js | 15 ++- appengine/pubsub/package.json | 2 +- appengine/storage/app.js | 18 +-- appengine/storage/package.json | 4 +- appengine/system-test/all.test.js | 14 +-- bigquery/dataset_size.js | 13 +- bigquery/getting_started.js | 14 +-- bigquery/list_datasets_and_projects.js | 21 ++-- bigquery/load_data_from_csv.js | 14 +-- bigquery/load_data_from_gcs.js | 14 +-- bigquery/package.json | 6 +- .../test/list_datasets_and_projects.test.js | 12 +- computeengine/package.json | 6 +- computeengine/vms.js | 14 +-- datastore/concepts.js | 118 ++++++++++-------- datastore/error.js | 18 +-- datastore/package.json | 6 +- datastore/tasks.js | 51 ++++---- functions/datastore/index.js | 6 +- functions/datastore/package.json | 4 +- functions/datastore/test/index.test.js | 8 +- functions/errorreporting/index.js | 6 +- functions/errorreporting/package.json | 4 +- functions/errorreporting/report.js | 6 +- functions/gcs/index.js | 9 +- functions/gcs/package.json | 4 +- functions/gcs/test/index.test.js | 8 +- functions/log/index.js | 14 ++- functions/log/package.json | 6 +- functions/log/test/index.test.js | 4 +- functions/ocr/app/index.js | 2 +- functions/ocr/app/package.json | 6 +- functions/ocr/app/test/index.test.js | 6 +- functions/pubsub/index.js | 6 +- functions/pubsub/package.json | 4 +- functions/pubsub/test/index.test.js | 8 +- functions/sendgrid/index.js | 2 +- functions/sendgrid/package.json | 6 +- logging/export.js | 14 +-- logging/list.js | 16 +-- logging/package.json | 8 +- logging/write.js | 14 +-- package.json | 2 +- pubsub/iam.js | 12 +- pubsub/package.json | 2 +- pubsub/subscriptions.js | 12 +- pubsub/system-test/iam.test.js | 4 +- pubsub/system-test/subscriptions.test.js | 4 +- pubsub/test/iam.test.js | 8 +- pubsub/test/subscriptions.test.js | 8 +- pubsub/test/topics.test.js | 8 +- pubsub/topics.js | 12 +- storage/buckets.js | 12 +- storage/encryption.js | 12 +- storage/files.js | 12 +- storage/package.json | 2 +- storage/system-test/encryption.test.js | 4 +- storage/system-test/files.test.js | 4 +- storage/test/buckets.test.js | 8 +- storage/test/encryption.test.js | 8 +- storage/test/files.test.js | 8 +- vision/faceDetection.js | 14 +-- vision/labelDetection.js | 14 +-- vision/landmarkDetection.js | 14 +-- vision/package.json | 2 +- vision/textDetection.js | 15 +-- 69 files changed, 395 insertions(+), 379 deletions(-) diff --git a/appengine/datastore/app.js b/appengine/datastore/app.js index 0a950c6a3c..680be59aa2 100644 --- a/appengine/datastore/app.js +++ b/appengine/datastore/app.js @@ -17,17 +17,20 @@ // [START setup] var express = require('express'); -var gcloud = require('gcloud'); var crypto = require('crypto'); var app = express(); app.enable('trust proxy'); -var dataset = gcloud.datastore({ - // This environment variable is set by app.yaml when running on GAE, but will - // need to be manually set when running locally. - projectId: process.env.GCLOUD_PROJECT -}); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +// These environment variables are set automatically on Google App Engine +var Datastore = require('@google-cloud/datastore'); + +// Instantiate a datastore client +var datastore = Datastore(); // [END setup] // [START insertVisit] @@ -38,8 +41,8 @@ var dataset = gcloud.datastore({ * @param {function} callback The callback function. */ function insertVisit (visit, callback) { - dataset.save({ - key: dataset.key('visit'), + datastore.save({ + key: datastore.key('visit'), data: visit }, function (err) { if (err) { @@ -57,11 +60,11 @@ function insertVisit (visit, callback) { * @param {function} callback The callback function. */ function getVisits (callback) { - var query = dataset.createQuery('visit') + var query = datastore.createQuery('visit') .order('-timestamp') .limit(10); - dataset.runQuery(query, function (err, entities) { + datastore.runQuery(query, function (err, entities) { if (err) { return callback(err); } diff --git a/appengine/datastore/package.json b/appengine/datastore/package.json index 00f8ca4bab..6746bc0252 100644 --- a/appengine/datastore/package.json +++ b/appengine/datastore/package.json @@ -13,10 +13,10 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "express": "^4.13.4", - "gcloud": "^0.37.0" + "@google-cloud/datastore": "^0.1.1", + "express": "^4.13.4" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/appengine/datastore/test/app.test.js b/appengine/datastore/test/app.test.js index e422e436b4..710a27e62c 100644 --- a/appengine/datastore/test/app.test.js +++ b/appengine/datastore/test/app.test.js @@ -56,12 +56,10 @@ function getSample () { runQuery: sinon.stub().callsArgWith(1, null, resultsMock), key: sinon.stub().returns({}) }; - var gcloudMock = { - datastore: sinon.stub().returns(datasetMock) - }; + var DatastoreMock = sinon.stub().returns(datasetMock); var app = proxyquire(SAMPLE_PATH, { - gcloud: gcloudMock, + '@google-cloud/datastore': DatastoreMock, express: expressMock }); return { @@ -71,7 +69,7 @@ function getSample () { express: expressMock, results: resultsMock, dataset: datasetMock, - gcloud: gcloudMock + Datastore: DatastoreMock } }; } @@ -83,10 +81,7 @@ describe('appengine/datastore/app.js', function () { sample = getSample(); assert(sample.mocks.express.calledOnce); - assert(sample.mocks.gcloud.datastore.calledOnce); - assert.deepEqual(sample.mocks.gcloud.datastore.firstCall.args[0], { - projectId: process.env.GCLOUD_PROJECT - }); + assert(sample.mocks.Datastore.calledOnce); assert(sample.app.listen.calledOnce); assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080); }); diff --git a/appengine/pubsub/app.js b/appengine/pubsub/app.js index 7de72d00fa..33fa14f4e1 100644 --- a/appengine/pubsub/app.js +++ b/appengine/pubsub/app.js @@ -17,7 +17,16 @@ var express = require('express'); var bodyParser = require('body-parser'); -var gcloud = require('gcloud'); + +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +// These environment variables are set automatically on Google App Engine +var PubSub = require('@google-cloud/pubsub'); + +// Instantiate a pubsub client +var pubsub = PubSub(); var app = express(); app.set('view engine', 'jade'); @@ -32,10 +41,6 @@ var messages = []; // but will need to be manually set when running locally. var PUBSUB_VERIFICATION_TOKEN = process.env.PUBSUB_VERIFICATION_TOKEN; -var pubsub = gcloud.pubsub({ - projectId: process.env.GCLOUD_PROJECT -}); - var topic = pubsub.topic(process.env.PUBSUB_TOPIC); // [START index] diff --git a/appengine/pubsub/package.json b/appengine/pubsub/package.json index 0e128dcbcb..7fa773d0f9 100644 --- a/appengine/pubsub/package.json +++ b/appengine/pubsub/package.json @@ -12,9 +12,9 @@ "start": "node app.js" }, "dependencies": { + "@google-cloud/pubsub": "^0.1.1", "body-parser": "^1.14.2", "express": "^4.13.4", - "gcloud": "^0.37.0", "jade": "^1.11.0" } } diff --git a/appengine/storage/app.js b/appengine/storage/app.js index 7f8d8f2bb8..28598f6866 100644 --- a/appengine/storage/app.js +++ b/appengine/storage/app.js @@ -17,7 +17,16 @@ var format = require('util').format; var express = require('express'); -var gcloud = require('gcloud'); + +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +// These environment variables are set automatically on Google App Engine +var Storage = require('@google-cloud/storage'); + +// Instantiate a storage client +var storage = Storage(); var app = express(); app.set('view engine', 'jade'); @@ -30,13 +39,6 @@ var multer = require('multer')({ fileSize: 5 * 1024 * 1024 // no larger than 5mb, you can change as needed. }); -// The following environment variables are set by app.yaml when running on GAE, -// but will need to be manually set when running locally. -// The storage client is used to communicate with Google Cloud Storage -var storage = gcloud.storage({ - projectId: process.env.GCLOUD_PROJECT -}); - // A bucket is a container for objects (files). var bucket = storage.bucket(process.env.GCLOUD_STORAGE_BUCKET); // [END config] diff --git a/appengine/storage/package.json b/appengine/storage/package.json index ea69914136..c51a803e79 100644 --- a/appengine/storage/package.json +++ b/appengine/storage/package.json @@ -5,10 +5,10 @@ "start": "node app.js" }, "dependencies": { + "@google-cloud/storage": "^0.1.1", "body-parser": "^1.14.2", "express": "^4.13.4", - "gcloud": "^0.37.0", "jade": "^1.11.0", - "multer": "^1.1.0" + "multer": "^1.2.0" } } diff --git a/appengine/system-test/all.test.js b/appengine/system-test/all.test.js index f7d6f77bc0..e6e34758b7 100644 --- a/appengine/system-test/all.test.js +++ b/appengine/system-test/all.test.js @@ -93,13 +93,13 @@ var sampleTests = [ msg: 'Viewed', TRAVIS_NODE_VERSION: '0.12' }, - { - dir: 'appengine/geddy', - cmd: 'node', - args: ['node_modules/geddy/bin/cli.js'], - msg: 'Hello, World! Geddy.js on Google App Engine.', - TRAVIS_NODE_VERSION: '5' - }, + // { + // dir: 'appengine/geddy', + // cmd: 'node', + // args: ['node_modules/geddy/bin/cli.js'], + // msg: 'Hello, World! Geddy.js on Google App Engine.', + // TRAVIS_NODE_VERSION: '5' + // }, { dir: 'appengine/grunt', deploy: true, diff --git a/bigquery/dataset_size.js b/bigquery/dataset_size.js index ef674cc857..6847032d3c 100644 --- a/bigquery/dataset_size.js +++ b/bigquery/dataset_size.js @@ -16,11 +16,11 @@ var async = require('async'); // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var BigQuery = require('@google-cloud/bigquery'); // [END auth] // [START list_tables] @@ -84,7 +84,8 @@ function getSizeExample (projectId, datasetId, callback) { return callback(new Error('datasetId is require!')); } - var bigquery = gcloud.bigquery({ + // Instantiate a bigquery client + var bigquery = BigQuery({ projectId: projectId }); diff --git a/bigquery/getting_started.js b/bigquery/getting_started.js index aeee607c3b..906249a594 100644 --- a/bigquery/getting_started.js +++ b/bigquery/getting_started.js @@ -15,14 +15,14 @@ 'use strict'; // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var BigQuery = require('@google-cloud/bigquery'); -// Get a reference to the bigquery component -var bigquery = gcloud.bigquery(); +// Instantiate a bigquery client +var bigquery = BigQuery(); // [END auth] // [START print] diff --git a/bigquery/list_datasets_and_projects.js b/bigquery/list_datasets_and_projects.js index e3f9fc65c6..e807e5ac6d 100644 --- a/bigquery/list_datasets_and_projects.js +++ b/bigquery/list_datasets_and_projects.js @@ -23,11 +23,16 @@ // [START all] // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var BigQuery = require('@google-cloud/bigquery'); + +var Resource = require('@google-cloud/resource'); + +// Instantiate a resource client +var resource = Resource(); // [END auth] // [START list_tables] @@ -41,7 +46,9 @@ function listDatasets (projectId, callback) { if (!projectId) { return callback(new Error('projectId is required!')); } - var bigquery = gcloud.bigquery({ + + // Instantiate a bigquery client + var bigquery = BigQuery({ projectId: projectId }); @@ -63,8 +70,6 @@ function listDatasets (projectId, callback) { * @param {Function} callback Callback function. */ function listProjects (callback) { - var resource = gcloud.resource(); - resource.getProjects(function (err, projects) { if (err) { return callback(err); diff --git a/bigquery/load_data_from_csv.js b/bigquery/load_data_from_csv.js index bed894e306..9328aa50ff 100644 --- a/bigquery/load_data_from_csv.js +++ b/bigquery/load_data_from_csv.js @@ -17,14 +17,14 @@ var fs = require('fs'); var path = require('path'); -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var BigQuery = require('@google-cloud/bigquery'); -// Get a reference to the bigquery component -var bigquery = gcloud.bigquery(); +// Instantiate a bigquery client +var bigquery = BigQuery(); /** * Wait for the provided job to complete. diff --git a/bigquery/load_data_from_gcs.js b/bigquery/load_data_from_gcs.js index 4c8dce9d10..09ba2d224d 100644 --- a/bigquery/load_data_from_gcs.js +++ b/bigquery/load_data_from_gcs.js @@ -16,14 +16,14 @@ var request = require('request'); -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var BigQuery = require('@google-cloud/bigquery'); -// Get a reference to the bigquery component -var bigquery = gcloud.bigquery(); +// Instantiate a bigquery client +var bigquery = BigQuery(); /** * Wait for the provided job to complete. diff --git a/bigquery/package.json b/bigquery/package.json index 15025ea215..bdffb097da 100644 --- a/bigquery/package.json +++ b/bigquery/package.json @@ -10,11 +10,11 @@ }, "dependencies": { "@google-cloud/bigquery": "^0.1.1", - "async": "^1.5.2", - "gcloud": "^0.37.0", + "@google-cloud/resource": "^0.1.1", + "async": "^2.0.1", "request": "^2.72.0" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/bigquery/test/list_datasets_and_projects.test.js b/bigquery/test/list_datasets_and_projects.test.js index d01982daa1..b21aa42a4b 100644 --- a/bigquery/test/list_datasets_and_projects.test.js +++ b/bigquery/test/list_datasets_and_projects.test.js @@ -32,16 +32,16 @@ function getSample () { var resourceMock = { getProjects: sinon.stub().callsArgWith(0, null, projectsMock) }; - var gcloudMock = { - bigquery: sinon.stub().returns(bigqueryMock), - resource: sinon.stub().returns(resourceMock) - }; + var BigQueryMock = sinon.stub().returns(bigqueryMock); + var ResourceMock = sinon.stub().returns(resourceMock); return { program: proxyquire('../list_datasets_and_projects', { - gcloud: gcloudMock + '@google-cloud/bigquery': BigQueryMock, + '@google-cloud/resource': ResourceMock }), mocks: { - gcloud: gcloudMock, + BigQuery: BigQueryMock, + Resource: ResourceMock, bigquery: bigqueryMock, resource: resourceMock, datasets: datasetsMock, diff --git a/computeengine/package.json b/computeengine/package.json index cc0148f29a..aad2dda066 100644 --- a/computeengine/package.json +++ b/computeengine/package.json @@ -9,13 +9,13 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0", - "googleapis": "^12.0.0", + "@google-cloud/compute": "^0.1.1", + "googleapis": "^12.2.0", "nodemailer": "^2.4.1", "nodemailer-smtp-transport": "^2.5.0", "sendgrid": "^2.0.0" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/computeengine/vms.js b/computeengine/vms.js index e648ed1021..15230e3ff6 100644 --- a/computeengine/vms.js +++ b/computeengine/vms.js @@ -15,16 +15,16 @@ 'use strict'; // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Compute = require('@google-cloud/compute'); // [END auth] // [START initialize] -// Get a reference to the compute component -var compute = gcloud.compute(); +// Instantiate a compute client +var compute = Compute(); // [END initialize] // [START list] diff --git a/datastore/concepts.js b/datastore/concepts.js index f7611d9c42..295d61369e 100644 --- a/datastore/concepts.js +++ b/datastore/concepts.js @@ -14,11 +14,11 @@ 'use strict'; var asyncUtil = require('async'); -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Datastore = require('@google-cloud/datastore'); module.exports = { Entity: Entity, @@ -45,7 +45,7 @@ function Entity (projectId) { projectId: projectId }; - this.datastore = gcloud.datastore(options); + this.datastore = Datastore(options); // To create the keys, we have to use this instance of Datastore. datastore.key = this.datastore.key; @@ -458,7 +458,7 @@ function Index (projectId) { projectId: projectId }; - this.datastore = gcloud.datastore(options); + this.datastore = Datastore(options); } Index.prototype.testUnindexedPropertyQuery = function (callback) { @@ -506,7 +506,7 @@ function Metadata (projectId) { projectId: projectId }; - this.datastore = gcloud.datastore(options); + this.datastore = Datastore(options); } Metadata.prototype.testNamespaceRunQuery = function (callback) { @@ -643,7 +643,7 @@ function Query (projectId) { projectId: projectId }; - this.datastore = gcloud.datastore(options); + this.datastore = Datastore(options); this.basicQuery = this.getBasicQuery(); this.projectionQuery = this.getProjectionQuery(); @@ -1040,18 +1040,21 @@ Query.prototype.testEventualConsistentQuery = function () { // [START transactional_update] function transferFunds (fromKey, toKey, amount, callback) { - var error; + var transaction = datastore.transaction(); + + transaction.run(function (err) { + if (err) { + return callback(err); + } - datastore.runInTransaction(function (transaction, done) { transaction.get([ fromKey, toKey ], function (err, accounts) { if (err) { - // An error occurred while getting the values. - error = err; - transaction.rollback(done); - return; + return transaction.rollback(function (_err) { + return callback(err || _err); + }); } accounts[0].data.balance -= amount; @@ -1059,14 +1062,15 @@ function transferFunds (fromKey, toKey, amount, callback) { transaction.save(accounts); - done(); + transaction.commit(function (err) { + if (err) { + return callback(err); + } + + // The transaction completed successfully. + callback(); + }); }); - }, function (transactionError) { - if (transactionError || error) { - return callback(transactionError || error); - } - // The transaction completed successfully. - callback(); }); } // [END transactional_update] @@ -1076,7 +1080,7 @@ function Transaction (projectId) { projectId: projectId }; - this.datastore = gcloud.datastore(options); + this.datastore = Datastore(options); this.fromKey = this.datastore.key(['Bank', 1, 'Account', 1]); this.toKey = this.datastore.key(['Bank', 1, 'Account', 2]); @@ -1203,37 +1207,41 @@ Transaction.prototype.testTransactionalGetOrCreate = function (callback) { // [START transactional_get_or_create] function getOrCreate (taskKey, taskData, callback) { - var error; - var taskEntity = { key: taskKey, data: taskData }; - datastore.runInTransaction(function (transaction, done) { + var transaction = datastore.transaction(); + + transaction.run(function (err) { + if (err) { + return callback(err); + } + transaction.get(taskKey, function (err, task) { if (err) { // An error occurred while getting the values. - error = err; - transaction.rollback(done); - return; + return transaction.rollback(function (_err) { + return callback(err || _err); + }); } if (task) { // The task entity already exists. - transaction.rollback(done); + transaction.rollback(callback); } else { // Create the task entity. transaction.save(taskEntity); - done(); + transaction.commit(function (err) { + if (err) { + return callback(err); + } + // The transaction completed successfully. + callback(null, taskEntity); + }); } }); - }, function (transactionError) { - if (transactionError || error) { - return callback(transactionError || error); - } - // The transaction completed successfully. - callback(null, taskEntity); }); } // [END transactional_get_or_create] @@ -1288,17 +1296,22 @@ Transaction.prototype.testSingleEntityGroupReadOnly = function (callback) { // [START transactional_single_entity_group_read_only] function getTaskListEntities (callback) { - var error; var taskListEntities; - datastore.runInTransaction(function (transaction, done) { + var transaction = datastore.transaction(); + + transaction.run(function (err) { + if (err) { + return callback(err); + } + var taskListKey = datastore.key(['TaskList', 'default']); datastore.get(taskListKey, function (err) { if (err) { - error = err; - transaction.rollback(done); - return; + return transaction.rollback(function (_err) { + return callback(err || _err); + }); } var query = datastore.createQuery('Task') @@ -1307,21 +1320,22 @@ Transaction.prototype.testSingleEntityGroupReadOnly = function (callback) { datastore.runQuery(query, function (err, entities) { if (err) { // An error occurred while running the query. - error = err; - transaction.rollback(done); - return; + return transaction.rollback(function (_err) { + return callback(err || _err); + }); } taskListEntities = entities; - done(); + transaction.commit(function (err) { + if (err) { + return callback(err); + } + + // The transaction completed successfully. + callback(null, taskListEntities); + }); }); }); - }, function (transactionError) { - if (transactionError || error) { - return callback(transactionError || error); - } - // The transaction completed successfully. - callback(null, taskListEntities); }); } // [END transactional_single_entity_group_read_only] diff --git a/datastore/error.js b/datastore/error.js index 94ea22b319..4ed1c93c94 100644 --- a/datastore/error.js +++ b/datastore/error.js @@ -13,18 +13,20 @@ 'use strict'; -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); -var dataset = gcloud.datastore(); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Datastore = require('@google-cloud/datastore'); + +// Instantiate a datastore client +var datastore = Datastore(); // [START error] function runQuery (cb) { - var query = dataset.createQuery(['Company']).start('badrequest'); + var query = datastore.createQuery(['Company']).start('badrequest'); - dataset.runQuery(query, function (err, entities) { + datastore.runQuery(query, function (err, entities) { // Check for an error if (err) { console.log(err.errors); // [...] diff --git a/datastore/package.json b/datastore/package.json index 934673d364..1503dcf17e 100644 --- a/datastore/package.json +++ b/datastore/package.json @@ -9,10 +9,10 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { - "async": "^1.5.2", - "gcloud": "^0.34.0" + "@google-cloud/datastore": "^0.1.1", + "async": "^2.0.1" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/datastore/tasks.js b/datastore/tasks.js index 1124e7f2b3..27bf5b8da1 100755 --- a/datastore/tasks.js +++ b/datastore/tasks.js @@ -16,17 +16,15 @@ var input = process.argv.splice(2); var command = input.shift(); -if (!process.env.GCLOUD_PROJECT) { - throw new Error('GCLOUD_PROJECT environment variable required.'); -} - // [START build_service] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); -var datastore = gcloud.datastore(); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Datastore = require('@google-cloud/datastore'); + +// Instantiate a datastore client +var datastore = Datastore(); // [END build_service] /* @@ -100,9 +98,13 @@ function addTask (description, callback) { // [START update_entity] function markDone (taskId, callback) { - var error; + var transaction = datastore.transaction(); + + transaction.run(function (err) { + if (err) { + return callback(err); + } - datastore.runInTransaction(function (transaction, done) { var taskKey = datastore.key([ 'Task', taskId @@ -110,25 +112,26 @@ function markDone (taskId, callback) { transaction.get(taskKey, function (err, task) { if (err) { - // An error occurred while getting the values. - error = err; - transaction.rollback(done); - return; + // An error occurred while getting the task + return transaction.rollback(function (_err) { + return callback(err || _err); + }); } task.data.done = true; transaction.save(task); - // Commit the transaction. - done(); + // Commit the transaction + transaction.commit(function (err) { + if (err) { + return callback(err); + } + + // The transaction completed successfully. + callback(); + }); }); - }, function (transactionError) { - if (transactionError || error) { - return callback(transactionError || error); - } - // The transaction completed successfully. - callback(); }); } // [END update_entity] diff --git a/functions/datastore/index.js b/functions/datastore/index.js index 91df305df6..9808bca5ea 100644 --- a/functions/datastore/index.js +++ b/functions/datastore/index.js @@ -13,10 +13,10 @@ 'use strict'; -var gcloud = require('gcloud'); +var Datastore = require('@google-cloud/datastore'); -// Create a datastore client. -var datastore = gcloud.datastore(); +// Instantiate a datastore client +var datastore = Datastore(); /** * Gets a Datastore key from the kind/key pair in the request. diff --git a/functions/datastore/package.json b/functions/datastore/package.json index fcdb901b52..089ed2a7c1 100644 --- a/functions/datastore/package.json +++ b/functions/datastore/package.json @@ -9,9 +9,9 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0" + "@google-cloud/datastore": "^0.1.1" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/functions/datastore/test/index.test.js b/functions/datastore/test/index.test.js index 1bc34c8b45..41b86f3b4d 100644 --- a/functions/datastore/test/index.test.js +++ b/functions/datastore/test/index.test.js @@ -28,15 +28,13 @@ function getSample () { }), save: sinon.stub().callsArg(1) }; - var gcloud = { - datastore: sinon.stub().returns(datastore) - }; + var DatastoreMock = sinon.stub().returns(datastore); return { sample: proxyquire('../', { - gcloud: gcloud + '@google-cloud/datastore': DatastoreMock }), mocks: { - gcloud: gcloud, + Datastore: DatastoreMock, datastore: datastore } }; diff --git a/functions/errorreporting/index.js b/functions/errorreporting/index.js index b16330bb2b..c02c4cf726 100644 --- a/functions/errorreporting/index.js +++ b/functions/errorreporting/index.js @@ -14,10 +14,10 @@ 'use strict'; // [START setup] -var gcloud = require('gcloud'); +var Logging = require('@google-cloud/logging'); -// Get a reference to the StackDriver Logging component -var logging = gcloud.logging(); +// Instantiate a logging client +var logging = Logging(); // [END setup] // [START reportDetailedError] diff --git a/functions/errorreporting/package.json b/functions/errorreporting/package.json index a8ebf27071..7079b6eb85 100644 --- a/functions/errorreporting/package.json +++ b/functions/errorreporting/package.json @@ -9,9 +9,9 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0" + "@google-cloud/logging": "^0.1.1" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/functions/errorreporting/report.js b/functions/errorreporting/report.js index ae8557b1c3..9338ec92f5 100644 --- a/functions/errorreporting/report.js +++ b/functions/errorreporting/report.js @@ -13,8 +13,10 @@ 'use strict'; -var gcloud = require('gcloud'); -var logging = gcloud.logging(); +var Logging = require('@google-cloud/logging'); + +// Instantiate a logging client +var logging = Logging(); // [START helloHttpError] /** diff --git a/functions/gcs/index.js b/functions/gcs/index.js index 3b3517bb61..0610de3fb2 100644 --- a/functions/gcs/index.js +++ b/functions/gcs/index.js @@ -13,7 +13,8 @@ 'use strict'; -var gcloud = require('gcloud'); +var Storage = require('@google-cloud/storage'); + var readline = require('readline'); function getFileStream (bucketName, fileName) { @@ -26,9 +27,9 @@ function getFileStream (bucketName, fileName) { '"file" property in your request'); } - // Create a gcs client. - var gcs = gcloud.storage(); - var bucket = gcs.bucket(bucketName); + // Instantiate a storage client + var storage = Storage(); + var bucket = storage.bucket(bucketName); return bucket.file(fileName).createReadStream(); } diff --git a/functions/gcs/package.json b/functions/gcs/package.json index e02ddcecf6..0349fdacc7 100644 --- a/functions/gcs/package.json +++ b/functions/gcs/package.json @@ -9,9 +9,9 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0" + "@google-cloud/storage": "^0.1.1" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/functions/gcs/test/index.test.js b/functions/gcs/test/index.test.js index b6d93ec91b..c05b9e2fb2 100644 --- a/functions/gcs/test/index.test.js +++ b/functions/gcs/test/index.test.js @@ -30,15 +30,13 @@ function getSample () { var storage = { bucket: sinon.stub().returns(bucket) }; - var gcloud = { - storage: sinon.stub().returns(storage) - }; + var StorageMock = sinon.stub().returns(storage); return { sample: proxyquire('../', { - gcloud: gcloud + '@google-cloud/storage': StorageMock }), mocks: { - gcloud: gcloud, + Storage: StorageMock, storage: storage, bucket: bucket, file: file diff --git a/functions/log/index.js b/functions/log/index.js index 54c452661c..a51125817e 100644 --- a/functions/log/index.js +++ b/functions/log/index.js @@ -22,12 +22,14 @@ exports.helloWorld = function helloWorld (context, data) { exports.retrieve = function retrieve () { // [START retrieve] - // By default, gcloud will authenticate using the service account file specified - // by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the - // project specified by the GCLOUD_PROJECT environment variable. See - // https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication - var gcloud = require('gcloud'); - var logging = gcloud.logging(); + // By default, the client will authenticate using the service account file + // specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use + // the project specified by the GCLOUD_PROJECT environment variable. See + // https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication + var Logging = require('@google-cloud/logging'); + + // Instantiate a logging client + var logging = Logging(); // Retrieve the latest Cloud Function log entries // See https://googlecloudplatform.github.io/gcloud-node/#/docs/logging diff --git a/functions/log/package.json b/functions/log/package.json index b1dc23b5f7..a90bf288e3 100644 --- a/functions/log/package.json +++ b/functions/log/package.json @@ -9,10 +9,10 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0", - "googleapis": "^12.0.0" + "@google-cloud/logging": "^0.1.1", + "googleapis": "^12.2.0" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/functions/log/test/index.test.js b/functions/log/test/index.test.js index d08ec49318..cd6ff98a80 100644 --- a/functions/log/test/index.test.js +++ b/functions/log/test/index.test.js @@ -39,9 +39,7 @@ function getSample () { auth: auth, monitoring: sinon.stub().returns(monitoring) }, - gcloud: { - logging: sinon.stub().returns(logging) - } + '@google-cloud/logging': sinon.stub().returns(logging) }), mocks: { auth: auth, diff --git a/functions/ocr/app/index.js b/functions/ocr/app/index.js index 409b74ad4d..fc1c24b863 100644 --- a/functions/ocr/app/index.js +++ b/functions/ocr/app/index.js @@ -16,7 +16,7 @@ // [START ocr_setup] var async = require('async'); var config = require('./config.json'); -var gcloud = require('gcloud'); +var gcloud = require('google-cloud'); // Get a reference to the Pub/Sub component var pubsub = gcloud.pubsub(); diff --git a/functions/ocr/app/package.json b/functions/ocr/app/package.json index b0022549c4..1b29ba9eff 100644 --- a/functions/ocr/app/package.json +++ b/functions/ocr/app/package.json @@ -9,10 +9,10 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../../test/_setup.js test/*.test.js" }, "dependencies": { - "async": "^1.5.2", - "gcloud": "^0.37.0" + "async": "^2.0.1", + "google-cloud": "^0.38.3" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/functions/ocr/app/test/index.test.js b/functions/ocr/app/test/index.test.js index 3b0d796813..d656cbcf94 100644 --- a/functions/ocr/app/test/index.test.js +++ b/functions/ocr/app/test/index.test.js @@ -53,7 +53,7 @@ function getSample () { var translate = { detect: sinon.stub().callsArg(1) }; - var gcloud = { + var gcloudMock = { pubsub: sinon.stub().returns(pubsub), storage: sinon.stub().returns(storage), vision: sinon.stub().returns(vision), @@ -61,11 +61,11 @@ function getSample () { }; return { sample: proxyquire('../', { - gcloud: gcloud, + 'google-cloud': gcloudMock, './config.json': config }), mocks: { - gcloud: gcloud, + gcloud: gcloudMock, pubsub: pubsub, storage: storage, bucket: bucket, diff --git a/functions/pubsub/index.js b/functions/pubsub/index.js index 39ce065985..513c8fc0d4 100644 --- a/functions/pubsub/index.js +++ b/functions/pubsub/index.js @@ -13,10 +13,10 @@ 'use strict'; -var gcloud = require('gcloud'); +var PubSub = require('@google-cloud/pubsub'); -// Create a pubsub client. -var pubsub = gcloud.pubsub(); +// Instantiate a pubsub client +var pubsub = PubSub(); /** * Publishes a message to a Cloud Pub/Sub Topic. diff --git a/functions/pubsub/package.json b/functions/pubsub/package.json index 565f7f24d1..927c4f9aa4 100644 --- a/functions/pubsub/package.json +++ b/functions/pubsub/package.json @@ -9,9 +9,9 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0" + "@google-cloud/pubsub": "^0.1.1" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/functions/pubsub/test/index.test.js b/functions/pubsub/test/index.test.js index 5d513b9557..353b8d9c98 100644 --- a/functions/pubsub/test/index.test.js +++ b/functions/pubsub/test/index.test.js @@ -22,15 +22,13 @@ function getSample () { var pubsub = { topic: sinon.stub().returns(topic) }; - var gcloud = { - pubsub: sinon.stub().returns(pubsub) - }; + var PubSubMock = sinon.stub().returns(pubsub); return { sample: proxyquire('../', { - gcloud: gcloud + '@google-cloud/pubsub': PubSubMock }), mocks: { - gcloud: gcloud, + PubSub: PubSubMock, pubsub: pubsub, topic: topic } diff --git a/functions/sendgrid/index.js b/functions/sendgrid/index.js index 4322f3b3f7..aa514506c6 100644 --- a/functions/sendgrid/index.js +++ b/functions/sendgrid/index.js @@ -17,7 +17,7 @@ var async = require('async'); var sendgrid = require('sendgrid'); var config = require('./config.json'); -var gcloud = require('gcloud'); +var gcloud = require('google-cloud'); var uuid = require('node-uuid'); // Get a reference to the Cloud Storage component diff --git a/functions/sendgrid/package.json b/functions/sendgrid/package.json index 845f8f685f..da7fa80629 100644 --- a/functions/sendgrid/package.json +++ b/functions/sendgrid/package.json @@ -9,12 +9,12 @@ "test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js" }, "dependencies": { - "async": "^1.5.2", - "gcloud": "^0.37.0", + "async": "^2.0.1", + "google-cloud": "^0.38.3", "node-uuid": "^1.4.7", "sendgrid": "^3.0.5" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/logging/export.js b/logging/export.js index 0ef90b35b7..e323aa6169 100644 --- a/logging/export.js +++ b/logging/export.js @@ -14,14 +14,14 @@ 'use strict'; // [START setup] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Logging = require('@google-cloud/logging'); -// Get a reference to the logging component -var logging = gcloud.logging(); +// Instantiate a logging client +var logging = Logging(); // [END setup] // [START listSinks] diff --git a/logging/list.js b/logging/list.js index 908a98794f..28252e56ef 100644 --- a/logging/list.js +++ b/logging/list.js @@ -15,14 +15,14 @@ // [START list] // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); - -// Get a reference to the logging component -var logging = gcloud.logging(); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Logging = require('@google-cloud/logging'); + +// Instantiate a logging client +var logging = Logging(); // [END auth] /** diff --git a/logging/package.json b/logging/package.json index ac823823e6..c01b689958 100644 --- a/logging/package.json +++ b/logging/package.json @@ -9,12 +9,12 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { - "async": "^1.5.2", + "@google-cloud/logging": "^0.1.1", + "async": "^2.0.1", "express": "^4.13.4", - "fluent-logger": "^1.1.1", - "gcloud": "^0.37.0" + "fluent-logger": "^2.0.1" }, "devDependencies": { - "mocha": "^2.5.3" + "mocha": "^3.0.2" } } diff --git a/logging/write.js b/logging/write.js index d457d5dd1b..d021087c33 100644 --- a/logging/write.js +++ b/logging/write.js @@ -18,14 +18,14 @@ var async = require('async'); // [START write] // [START setup] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Logging = require('@google-cloud/logging'); -// Get a reference to the logging component -var logging = gcloud.logging(); +// Instantiate a logging client +var logging = Logging(); // [END setup] /** diff --git a/package.json b/package.json index 0ef320a850..c42db7143f 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ }, "scripts": { "lint": "semistandard", - "pretest": "npm run lint && ./scripts/geddy && ./scripts/clean", + "pretest": "npm run lint && ./scripts/clean", "mocha": "mocha -R spec -t 120000 --require intelli-espower-loader ./test/_setup.js '{*,appengine/*,functions/*}/test/*.test.js'", "test": "npm run mocha", "cover": "nyc --cache npm test && nyc report --reporter=html && nyc report --reporter=lcov", diff --git a/pubsub/iam.js b/pubsub/iam.js index 752d28c129..98966f6ac0 100644 --- a/pubsub/iam.js +++ b/pubsub/iam.js @@ -14,14 +14,14 @@ 'use strict'; // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var PubSub = require('@google-cloud/pubsub'); // Instantiate a pubsub client -var pubsub = gcloud.pubsub(); +var pubsub = PubSub(); // [END auth] // [START get_topic_policy] diff --git a/pubsub/package.json b/pubsub/package.json index b9c1983be4..a741fc1281 100644 --- a/pubsub/package.json +++ b/pubsub/package.json @@ -9,7 +9,7 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0" + "@google-cloud/pubsub": "^0.1.1" }, "devDependencies": { "mocha": "^3.0.2", diff --git a/pubsub/subscriptions.js b/pubsub/subscriptions.js index 6cea5910dc..f36b37c571 100644 --- a/pubsub/subscriptions.js +++ b/pubsub/subscriptions.js @@ -14,14 +14,14 @@ 'use strict'; // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var PubSub = require('@google-cloud/pubsub'); // Instantiate a pubsub client -var pubsub = gcloud.pubsub(); +var pubsub = PubSub(); // [END auth] // [START create_subscription] diff --git a/pubsub/system-test/iam.test.js b/pubsub/system-test/iam.test.js index e99f448d7f..d052e21d9b 100644 --- a/pubsub/system-test/iam.test.js +++ b/pubsub/system-test/iam.test.js @@ -14,8 +14,8 @@ 'use strict'; var uuid = require('node-uuid'); -var gcloud = require('gcloud'); -var pubsub = gcloud.pubsub(); +var PubSub = require('@google-cloud/pubsub'); +var pubsub = PubSub(); var program = require('../iam'); var topicName = 'nodejs-docs-samples-test-' + uuid.v4(); var subscriptionName = 'nodejs-docs-samples-test-sub-' + uuid.v4(); diff --git a/pubsub/system-test/subscriptions.test.js b/pubsub/system-test/subscriptions.test.js index 7f6711221b..366eb57d11 100644 --- a/pubsub/system-test/subscriptions.test.js +++ b/pubsub/system-test/subscriptions.test.js @@ -14,8 +14,8 @@ 'use strict'; var uuid = require('node-uuid'); -var gcloud = require('gcloud'); -var pubsub = gcloud.pubsub(); +var PubSub = require('@google-cloud/pubsub'); +var pubsub = PubSub(); var program = require('../subscriptions'); var topicName = 'nodejs-docs-samples-test-' + uuid.v4(); var subscriptionName = 'nodejs-docs-samples-test-sub-' + uuid.v4(); diff --git a/pubsub/test/iam.test.js b/pubsub/test/iam.test.js index 4047db9e96..cdf17e73f2 100644 --- a/pubsub/test/iam.test.js +++ b/pubsub/test/iam.test.js @@ -38,15 +38,13 @@ function getSample () { topic: sinon.stub().returns(topicMock), subscription: sinon.stub().returns(subscriptionMock) }; - var gcloudMock = { - pubsub: sinon.stub().returns(pubsubMock) - }; + var PubSubMock = sinon.stub().returns(pubsubMock); return { program: proxyquire('../iam', { - gcloud: gcloudMock + '@google-cloud/pubsub': PubSubMock }), mocks: { - gcloud: gcloudMock, + PubSub: PubSubMock, pubsub: pubsubMock, topic: topicMock, subscription: subscriptionMock diff --git a/pubsub/test/subscriptions.test.js b/pubsub/test/subscriptions.test.js index fd71607696..5dbbe73c3a 100644 --- a/pubsub/test/subscriptions.test.js +++ b/pubsub/test/subscriptions.test.js @@ -47,15 +47,13 @@ function getSample () { subscribe: sinon.stub().callsArgWith(3, null, subscriptionMock), getSubscriptions: sinon.stub().callsArgWith(1, null, subscriptionsMock) }; - var gcloudMock = { - pubsub: sinon.stub().returns(pubsubMock) - }; + var PubSubMock = sinon.stub().returns(pubsubMock); return { program: proxyquire('../subscriptions', { - gcloud: gcloudMock + '@google-cloud/pubsub': PubSubMock }), mocks: { - gcloud: gcloudMock, + PubSub: PubSubMock, pubsub: pubsubMock, topic: topicMock, subscription: subscriptionMock, diff --git a/pubsub/test/topics.test.js b/pubsub/test/topics.test.js index 2a8e21495f..cddc056f60 100644 --- a/pubsub/test/topics.test.js +++ b/pubsub/test/topics.test.js @@ -33,15 +33,13 @@ function getSample () { topic: sinon.stub().returns(topicMock), getTopics: sinon.stub().callsArgWith(0, null, topicsMock) }; - var gcloudMock = { - pubsub: sinon.stub().returns(pubsubMock) - }; + var PubSubMock = sinon.stub().returns(pubsubMock); return { program: proxyquire('../topics', { - gcloud: gcloudMock + '@google-cloud/pubsub': PubSubMock }), mocks: { - gcloud: gcloudMock, + PubSub: PubSubMock, pubsub: pubsubMock, topics: topicsMock, topic: topicMock diff --git a/pubsub/topics.js b/pubsub/topics.js index 12ace89397..185114a03d 100644 --- a/pubsub/topics.js +++ b/pubsub/topics.js @@ -14,14 +14,14 @@ 'use strict'; // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var PubSub = require('@google-cloud/pubsub'); // Instantiate a pubsub client -var pubsub = gcloud.pubsub(); +var pubsub = PubSub(); // [END auth] // [START create_topic] diff --git a/storage/buckets.js b/storage/buckets.js index 866e5dfd40..6f6be5dc19 100644 --- a/storage/buckets.js +++ b/storage/buckets.js @@ -15,14 +15,14 @@ // [START all] // [START setup] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Storage = require('@google-cloud/storage'); // Instantiate a storage client -var storage = gcloud.storage(); +var storage = Storage(); // [END setup] // [START create] diff --git a/storage/encryption.js b/storage/encryption.js index 64ba417fee..5250a0aafe 100644 --- a/storage/encryption.js +++ b/storage/encryption.js @@ -15,14 +15,14 @@ // [START all] // [START setup] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Storage = require('@google-cloud/storage'); // Instantiate a storage client -var storage = gcloud.storage(); +var storage = Storage(); var crypto = require('crypto'); // [END setup] diff --git a/storage/files.js b/storage/files.js index 7918996222..55f9834503 100644 --- a/storage/files.js +++ b/storage/files.js @@ -15,14 +15,14 @@ // [START all] // [START setup] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Storage = require('@google-cloud/storage'); // Instantiate a storage client -var storage = gcloud.storage(); +var storage = Storage(); // [END setup] // [START list] diff --git a/storage/package.json b/storage/package.json index 5fb5187e32..2b982bbd95 100644 --- a/storage/package.json +++ b/storage/package.json @@ -9,7 +9,7 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { - "gcloud": "^0.37.0" + "@google-cloud/storage": "^0.1.1" }, "devDependencies": { "mocha": "^3.0.2", diff --git a/storage/system-test/encryption.test.js b/storage/system-test/encryption.test.js index 33d5dad4b0..22e469aaf7 100644 --- a/storage/system-test/encryption.test.js +++ b/storage/system-test/encryption.test.js @@ -15,9 +15,9 @@ var fs = require('fs'); var path = require('path'); -var gcloud = require('gcloud'); +var Storage = require('@google-cloud/storage'); var uuid = require('node-uuid'); -var storage = gcloud.storage(); +var storage = Storage(); var program = require('../encryption'); var bucketName = 'nodejs-docs-samples-test-' + uuid.v4(); diff --git a/storage/system-test/files.test.js b/storage/system-test/files.test.js index 0dc55c1449..164e41006e 100644 --- a/storage/system-test/files.test.js +++ b/storage/system-test/files.test.js @@ -15,9 +15,9 @@ var fs = require('fs'); var path = require('path'); -var gcloud = require('gcloud'); +var Storage = require('@google-cloud/storage'); var uuid = require('node-uuid'); -var storage = gcloud.storage(); +var storage = Storage(); var filesExample = require('../files'); var bucketName = 'nodejs-docs-samples-test-' + uuid.v4(); diff --git a/storage/test/buckets.test.js b/storage/test/buckets.test.js index a7116913f1..ebc70edde2 100644 --- a/storage/test/buckets.test.js +++ b/storage/test/buckets.test.js @@ -31,15 +31,13 @@ function getSample () { getBuckets: sinon.stub().callsArgWith(0, null, bucketsMock, null, bucketsMock), bucket: sinon.stub().returns(bucketMock) }; - var gcloudMock = { - storage: sinon.stub().returns(storageMock) - }; + var StorageMock = sinon.stub().returns(storageMock); return { sample: proxyquire('../buckets', { - gcloud: gcloudMock + '@google-cloud/storage': StorageMock }), mocks: { - gcloud: gcloudMock, + Storage: StorageMock, storage: storageMock, buckets: bucketsMock, bucket: bucketMock diff --git a/storage/test/encryption.test.js b/storage/test/encryption.test.js index 6834082014..b094fae394 100644 --- a/storage/test/encryption.test.js +++ b/storage/test/encryption.test.js @@ -34,15 +34,13 @@ function getSample () { var storageMock = { bucket: sinon.stub().returns(bucketMock) }; - var gcloudMock = { - storage: sinon.stub().returns(storageMock) - }; + var StorageMock = sinon.stub().returns(storageMock); return { program: proxyquire('../encryption', { - gcloud: gcloudMock + '@google-cloud/storage': StorageMock }), mocks: { - gcloud: gcloudMock, + Storage: StorageMock, storage: storageMock, files: filesMock, bucket: bucketMock, diff --git a/storage/test/files.test.js b/storage/test/files.test.js index 8e2b5fcd9c..8c32a21446 100644 --- a/storage/test/files.test.js +++ b/storage/test/files.test.js @@ -38,15 +38,13 @@ function getSample () { var storageMock = { bucket: sinon.stub().returns(bucketMock) }; - var gcloudMock = { - storage: sinon.stub().returns(storageMock) - }; + var StorageMock = sinon.stub().returns(storageMock); return { sample: proxyquire('../files', { - gcloud: gcloudMock + '@google-cloud/storage': StorageMock }), mocks: { - gcloud: gcloudMock, + Storage: StorageMock, storage: storageMock, files: filesMock, file: fileMock, diff --git a/vision/faceDetection.js b/vision/faceDetection.js index 40b9b0a9de..b737607c85 100644 --- a/vision/faceDetection.js +++ b/vision/faceDetection.js @@ -14,14 +14,14 @@ 'use strict'; // [START auth] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Vision = require('@google-cloud/vision'); -// Get a reference to the vision component -var vision = gcloud.vision(); +// Instantiate a vision client +var vision = Vision(); // [END auth] var fs = require('fs'); diff --git a/vision/labelDetection.js b/vision/labelDetection.js index b8ccc69ea5..b7d9531227 100644 --- a/vision/labelDetection.js +++ b/vision/labelDetection.js @@ -15,17 +15,17 @@ // [START app] // [START import_libraries] -var gcloud = require('gcloud'); +var Vision = require('@google-cloud/vision'); // [END import_libraries] // [START authenticate] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication -// Get a reference to the vision component -var vision = gcloud.vision(); +// Instantiate a vision client +var vision = Vision(); // [END authenticate] /** diff --git a/vision/landmarkDetection.js b/vision/landmarkDetection.js index 9b7e2f8c23..cadd70e1b7 100644 --- a/vision/landmarkDetection.js +++ b/vision/landmarkDetection.js @@ -15,17 +15,17 @@ // [START app] // [START import_libraries] -var gcloud = require('gcloud'); +var Vision = require('@google-cloud/vision'); // [END import_libraries] // [START authenticate] -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication -// Get a reference to the vision component -var vision = gcloud.vision(); +// Instantiate a vision client +var vision = Vision(); // [END authenticate] /** diff --git a/vision/package.json b/vision/package.json index 573136685a..dec58f3fd2 100644 --- a/vision/package.json +++ b/vision/package.json @@ -9,8 +9,8 @@ "system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" }, "dependencies": { + "@google-cloud/vision": "^0.1.1", "async": "^1.5.0", - "gcloud": "^0.37.0", "natural": "^0.4.0", "redis": "^2.6.0-2" }, diff --git a/vision/textDetection.js b/vision/textDetection.js index 140351ff49..94f6b10d32 100644 --- a/vision/textDetection.js +++ b/vision/textDetection.js @@ -19,15 +19,16 @@ var async = require('async'); var fs = require('fs'); var path = require('path'); -// By default, gcloud will authenticate using the service account file specified -// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the -// project specified by the GCLOUD_PROJECT environment variable. See -// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication -var gcloud = require('gcloud'); +// By default, the client will authenticate using the service account file +// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use +// the project specified by the GCLOUD_PROJECT environment variable. See +// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication +var Vision = require('@google-cloud/vision'); var natural = require('natural'); var redis = require('redis'); -// Get a reference to the vision component -var vision = gcloud.vision(); + +// Instantiate a vision client +var vision = Vision(); // [END import_libraries] function Index () { From 28f80375b5ed7cf5f8321c38c7db0da1b0091a0f Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Mon, 15 Aug 2016 22:25:04 -0700 Subject: [PATCH 2/3] Address comments --- functions/pubsub/test/index.test.js | 12 ++++++------ storage/system-test/encryption.test.js | 2 +- storage/system-test/files.test.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/functions/pubsub/test/index.test.js b/functions/pubsub/test/index.test.js index 353b8d9c98..aaea5a0370 100644 --- a/functions/pubsub/test/index.test.js +++ b/functions/pubsub/test/index.test.js @@ -16,21 +16,21 @@ var proxyquire = require('proxyquire').noCallThru(); function getSample () { - var topic = { + var topicMock = { publish: sinon.stub().callsArg(1) }; - var pubsub = { - topic: sinon.stub().returns(topic) + var pubsubMock = { + topic: sinon.stub().returns(topicMock) }; - var PubSubMock = sinon.stub().returns(pubsub); + var PubSubMock = sinon.stub().returns(pubsubMock); return { sample: proxyquire('../', { '@google-cloud/pubsub': PubSubMock }), mocks: { PubSub: PubSubMock, - pubsub: pubsub, - topic: topic + pubsub: pubsubMock, + topic: topicMock } }; } diff --git a/storage/system-test/encryption.test.js b/storage/system-test/encryption.test.js index 22e469aaf7..21a405ae83 100644 --- a/storage/system-test/encryption.test.js +++ b/storage/system-test/encryption.test.js @@ -17,9 +17,9 @@ var fs = require('fs'); var path = require('path'); var Storage = require('@google-cloud/storage'); var uuid = require('node-uuid'); -var storage = Storage(); var program = require('../encryption'); +var storage = Storage(); var bucketName = 'nodejs-docs-samples-test-' + uuid.v4(); var fileName = 'test.txt'; var filePath = path.join(__dirname, '../resources', fileName); diff --git a/storage/system-test/files.test.js b/storage/system-test/files.test.js index 164e41006e..34930ae135 100644 --- a/storage/system-test/files.test.js +++ b/storage/system-test/files.test.js @@ -17,9 +17,9 @@ var fs = require('fs'); var path = require('path'); var Storage = require('@google-cloud/storage'); var uuid = require('node-uuid'); -var storage = Storage(); var filesExample = require('../files'); +var storage = Storage(); var bucketName = 'nodejs-docs-samples-test-' + uuid.v4(); var fileName = 'test.txt'; var movedFileName = 'test2.txt'; From 0204da2162330e41172501fa02bb9057774e3078 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Mon, 15 Aug 2016 22:25:39 -0700 Subject: [PATCH 3/3] Address comments --- datastore/concepts.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/datastore/concepts.js b/datastore/concepts.js index 295d61369e..d8251f7d48 100644 --- a/datastore/concepts.js +++ b/datastore/concepts.js @@ -1053,7 +1053,7 @@ function transferFunds (fromKey, toKey, amount, callback) { ], function (err, accounts) { if (err) { return transaction.rollback(function (_err) { - return callback(err || _err); + return callback(_err || err); }); } @@ -1223,7 +1223,7 @@ Transaction.prototype.testTransactionalGetOrCreate = function (callback) { if (err) { // An error occurred while getting the values. return transaction.rollback(function (_err) { - return callback(err || _err); + return callback(_err || err); }); } @@ -1310,7 +1310,7 @@ Transaction.prototype.testSingleEntityGroupReadOnly = function (callback) { datastore.get(taskListKey, function (err) { if (err) { return transaction.rollback(function (_err) { - return callback(err || _err); + return callback(_err || err); }); } @@ -1321,7 +1321,7 @@ Transaction.prototype.testSingleEntityGroupReadOnly = function (callback) { if (err) { // An error occurred while running the query. return transaction.rollback(function (_err) { - return callback(err || _err); + return callback(_err || err); }); }