Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: drop dependency on common #148

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 78 additions & 89 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"system-test": "mocha system-test/*.js --timeout 600000"
},
"dependencies": {
"@google-cloud/common": "^0.20.1",
"@google-cloud/projectify": "^0.3.0",
"@google-cloud/promisify": "^0.3.0",
"arrify": "^1.0.1",
"concat-stream": "^1.6.2",
"create-error-class": "^3.0.2",
Expand Down
5 changes: 0 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'use strict';

var arrify = require('arrify');
var common = require('@google-cloud/common');
var extend = require('extend');
var gax = require('google-gax');
var grpc = new gax.GrpcClient().grpc;
Expand Down Expand Up @@ -364,10 +363,6 @@ function Datastore(options) {
return new Datastore(options);
}

options = common.util.normalizeArguments(this, options, {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

projectIdRequired: false,
});

this.clients_ = new Map();
this.datastore = this;

Expand Down
11 changes: 6 additions & 5 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'use strict';

var arrify = require('arrify');
var common = require('@google-cloud/common');
var {replaceProjectIdToken} = require('@google-cloud/projectify');
var {promisifyAll} = require('@google-cloud/promisify');
var concat = require('concat-stream');
var extend = require('extend');
var is = require('is');
Expand Down Expand Up @@ -339,7 +340,7 @@ DatastoreRequest.prototype.delete = function(keys, gaxOptions, callback) {
gaxOptions = {};
}

callback = callback || common.util.noop;
callback = callback || function() {};

var reqOpts = {
mutations: arrify(keys).map(function(key) {
Expand Down Expand Up @@ -1098,7 +1099,7 @@ DatastoreRequest.prototype.upsert = function(entities, callback) {
DatastoreRequest.prototype.request_ = function(config, callback) {
var datastore = this.datastore;

callback = callback || common.util.noop;
callback = callback || function() {};

var isTransaction = is.defined(this.id);
var method = config.method;
Expand Down Expand Up @@ -1147,7 +1148,7 @@ DatastoreRequest.prototype.request_ = function(config, callback) {

var gaxClient = datastore.clients_.get(clientName);

reqOpts = common.util.replaceProjectIdToken(reqOpts, projectId);
reqOpts = replaceProjectIdToken(reqOpts, projectId);

var gaxOpts = extend(true, {}, config.gaxOpts, {
headers: {
Expand All @@ -1164,7 +1165,7 @@ DatastoreRequest.prototype.request_ = function(config, callback) {
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(DatastoreRequest);
promisifyAll(DatastoreRequest);

/**
* Reference to the {@link DatastoreRequest} class.
Expand Down
12 changes: 6 additions & 6 deletions src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'use strict';

var arrify = require('arrify');
var common = require('@google-cloud/common');
var {promisifyAll} = require('@google-cloud/promisify');
var flatten = require('lodash.flatten');
var is = require('is');
var util = require('util');
Expand Down Expand Up @@ -129,7 +129,7 @@ Transaction.prototype.commit = function(gaxOptions, callback) {
gaxOptions = {};
}

callback = callback || common.util.noop;
callback = callback || function() {};

if (this.skipCommit) {
setImmediate(callback);
Expand Down Expand Up @@ -193,7 +193,7 @@ Transaction.prototype.commit = function(gaxOptions, callback) {
var method = modifiedEntity.method;
var args = modifiedEntity.args.reverse();

Request.prototype[method].call(self, args, common.util.noop);
Request.prototype[method].call(self, args, function() {});
});

// Take the `req` array built previously, and merge them into one request to
Expand Down Expand Up @@ -362,7 +362,7 @@ Transaction.prototype.rollback = function(gaxOptions, callback) {
gaxOptions = {};
}

callback = callback || common.util.noop;
callback = callback || function() {};

this.request_(
{
Expand Down Expand Up @@ -437,7 +437,7 @@ Transaction.prototype.run = function(options, callback) {
}

options = options || {};
callback = callback || common.util.noop;
callback = callback || function() {};

var reqOpts = {
transactionOptions: {},
Expand Down Expand Up @@ -625,7 +625,7 @@ Transaction.prototype.save = function(entities) {
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Transaction, {
promisifyAll(Transaction, {
exclude: ['createQuery', 'delete', 'save'],
});

Expand Down
31 changes: 5 additions & 26 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var assert = require('assert');
var extend = require('extend');
var gax = new require('google-gax');
var proxyquire = require('proxyquire');
var util = require('@google-cloud/common').util;

var v1 = require('../src/v1/index.js');

Expand Down Expand Up @@ -52,12 +51,9 @@ var fakeEntity = {
},
};

var fakeUtil = extend({}, util);
var originalFakeUtil = extend(true, {}, fakeUtil);

var GoogleAuthOverride;
function fakeGoogleAuth() {
return (GoogleAuthOverride || util.noop).apply(null, arguments);
return (GoogleAuthOverride || function() {}).apply(null, arguments);
}

var createInsecureOverride;
Expand All @@ -70,7 +66,10 @@ var fakeGoogleGax = {
this.grpc = {
credentials: {
createInsecure() {
return (createInsecureOverride || util.noop).apply(null, arguments);
return (createInsecureOverride || function() {}).apply(
null,
arguments
);
},
},
};
Expand Down Expand Up @@ -108,9 +107,6 @@ describe('Datastore', function() {

before(function() {
Datastore = proxyquire('../', {
'@google-cloud/common': {
util: fakeUtil,
},
'./entity.js': fakeEntity,
'./query.js': FakeQuery,
'./transaction.js': FakeTransaction,
Expand All @@ -123,8 +119,6 @@ describe('Datastore', function() {
});

beforeEach(function() {
extend(fakeUtil, originalFakeUtil);

createInsecureOverride = null;
GoogleAuthOverride = null;

Expand Down Expand Up @@ -158,21 +152,6 @@ describe('Datastore', function() {
});
});

it('should normalize the arguments', function() {
var normalizeArgumentsCalled = false;
var options = {};

fakeUtil.normalizeArguments = function(context, options_, config) {
normalizeArgumentsCalled = true;
assert.strictEqual(options_, options);
assert.strictEqual(config.projectIdRequired, false);
return options_;
};

new Datastore(options);
assert.strictEqual(normalizeArgumentsCalled, true);
});

it('should initialize an empty Client map', function() {
assert(datastore.clients_ instanceof Map);
assert.strictEqual(datastore.clients_.size, 0);
Expand Down
43 changes: 25 additions & 18 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,31 @@ var is = require('is');
var proxyquire = require('proxyquire');
var sinon = require('sinon').sandbox.create();
var through = require('through2');
var util = require('@google-cloud/common').util;
var pfy = require('@google-cloud/promisify');

This comment was marked as spam.

var pjy = require('@google-cloud/projectify');

var entity = require('../src/entity.js');
var Query = require('../src/query.js');

var promisified = false;
var fakeUtil = extend({}, util, {
var fakePfy = extend({}, pfy, {
promisifyAll: function(Class) {
if (Class.name === 'DatastoreRequest') {
promisified = true;
}
},
});

var fakePjy = {
replaceProjectIdToken: function() {
return (pjyOverride || pjy.replaceProjectIdToken).apply(null, arguments);
},
};

var v1FakeClientOverride;
var fakeV1 = {
FakeClient: function() {
return (v1FakeClientOverride || util.noop).apply(null, arguments);
return (v1FakeClientOverride || function() {}).apply(null, arguments);
},
};

Expand Down Expand Up @@ -75,12 +82,13 @@ function resetOverrides() {
}

override('entity', entity);
override('util', fakeUtil);

function FakeQuery() {
this.calledWith_ = arguments;
}

let pjyOverride;

describe('Request', function() {
var Request;
var request;
Expand All @@ -89,9 +97,8 @@ describe('Request', function() {

before(function() {
Request = proxyquire('../src/request.js', {
'@google-cloud/common': {
util: fakeUtil,
},
'@google-cloud/promisify': fakePfy,
'@google-cloud/projectify': fakePjy,
'./entity.js': entity,
'./query.js': FakeQuery,
'./v1': fakeV1,
Expand All @@ -106,6 +113,7 @@ describe('Request', function() {
});

beforeEach(function() {
pjyOverride = null;
key = new entity.Key({
namespace: 'namespace',
path: ['Company', 123],
Expand Down Expand Up @@ -167,8 +175,8 @@ describe('Request', function() {
};

beforeEach(function() {
overrides.entity.isKeyComplete = util.noop;
overrides.entity.keyToKeyProto = util.noop;
overrides.entity.isKeyComplete = function() {};
overrides.entity.keyToKeyProto = function() {};
});

it('should throw if the key is complete', function() {
Expand Down Expand Up @@ -282,7 +290,7 @@ describe('Request', function() {

describe('createReadStream', function() {
beforeEach(function() {
request.request_ = util.noop;
request.request_ = function() {};
});

it('should throw if no keys are provided', function() {
Expand Down Expand Up @@ -373,7 +381,7 @@ describe('Request', function() {
it('should emit error', function(done) {
request
.createReadStream(key)
.on('data', util.noop)
.on('data', function() {})
.on('error', function(err) {
assert.strictEqual(err, error);
done();
Expand All @@ -383,7 +391,7 @@ describe('Request', function() {
it('should end stream', function(done) {
var stream = request.createReadStream(key);

stream.on('data', util.noop).on('error', function() {
stream.on('data', function() {}).on('error', function() {
setImmediate(function() {
assert.strictEqual(stream._destroyed, true);
done();
Expand Down Expand Up @@ -741,8 +749,8 @@ describe('Request', function() {

describe('runQueryStream', function() {
beforeEach(function() {
overrides.entity.queryToQueryProto = util.noop;
request.request_ = util.noop;
overrides.entity.queryToQueryProto = function() {};
request.request_ = function() {};
});

it('should clone the query', function(done) {
Expand Down Expand Up @@ -1596,7 +1604,7 @@ describe('Request', function() {
beforeEach(function() {
var clients_ = new Map();
clients_.set(CONFIG.client, {
[CONFIG.method]: util.noop,
[CONFIG.method]: function() {},
});

request.datastore = {
Expand Down Expand Up @@ -1633,7 +1641,7 @@ describe('Request', function() {

it('should initiate and cache the client', function() {
var fakeClient = {
[CONFIG.method]: util.noop,
[CONFIG.method]: function() {},
};

v1FakeClientOverride = function(options) {
Expand Down Expand Up @@ -1665,11 +1673,10 @@ describe('Request', function() {
var expectedReqOpts = extend({}, CONFIG.reqOpts);
expectedReqOpts.projectId = request.projectId;

overrides.util.replaceProjectIdToken = function(reqOpts, projectId) {
pjyOverride = function(reqOpts, projectId) {
assert.notStrictEqual(reqOpts, CONFIG.reqOpts);
assert.deepStrictEqual(reqOpts, expectedReqOpts);
assert.strictEqual(projectId, PROJECT_ID);

return replacedReqOpts;
};

Expand Down
Loading