Skip to content

Commit 24a0252

Browse files
bigquery/language/logging/prediction/vision: decouple packages
1 parent 137efae commit 24a0252

14 files changed

Lines changed: 182 additions & 115 deletions

File tree

packages/bigquery/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
"arrify": "^1.0.0",
5454
"duplexify": "^3.2.0",
5555
"extend": "^3.0.0",
56-
"@google-cloud/common": "^0.1.0",
57-
"@google-cloud/storage": "^0.1.0",
56+
"@google-cloud/common": "^0.3.0",
5857
"is": "^3.0.1",
5958
"modelo": "^4.2.0",
6059
"stream-events": "^1.0.1",
6160
"string-format-obj": "^1.0.0"
6261
},
6362
"devDependencies": {
6463
"async": "^1.4.2",
64+
"@google-cloud/storage": "*",
6565
"mocha": "^3.0.1",
6666
"node-uuid": "^1.4.3",
6767
"propprop": "^0.3.0",

packages/bigquery/src/table.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var format = require('string-format-obj');
2828
var fs = require('fs');
2929
var is = require('is');
3030
var path = require('path');
31-
var Storage = require('@google-cloud/storage');
3231
var streamEvents = require('stream-events');
3332
var util = require('util');
3433

@@ -504,7 +503,7 @@ Table.prototype.export = function(destination, options, callback) {
504503

505504
extend(true, options, {
506505
destinationUris: arrify(destination).map(function(dest) {
507-
if (!(dest instanceof Storage.File)) {
506+
if (!common.util.isCustomType(dest, 'storage/file')) {
508507
throw new Error('Destination must be a File object.');
509508
}
510509

@@ -787,7 +786,7 @@ Table.prototype.import = function(source, metadata, callback) {
787786

788787
extend(true, body.configuration.load, metadata, {
789788
sourceUris: arrify(source).map(function(src) {
790-
if (!(src instanceof Storage.File)) {
789+
if (!common.util.isCustomType(src, 'storage/file')) {
791790
throw new Error('Source must be a File object.');
792791
}
793792

packages/bigquery/test/table.js

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ var prop = require('propprop');
2424
var proxyquire = require('proxyquire');
2525
var stream = require('stream');
2626

27-
var File = require('@google-cloud/storage').File;
2827
var ServiceObject = require('@google-cloud/common').ServiceObject;
2928
var util = require('@google-cloud/common').util;
3029

31-
function FakeFile(a, b) {
32-
this.request = util.noop;
33-
File.call(this, a, b);
34-
}
35-
3630
var makeWritableStreamOverride;
31+
var isCustomTypeOverride;
3732
var fakeUtil = extend({}, util, {
33+
isCustomType: function() {
34+
return (isCustomTypeOverride || util.isCustomType).apply(null, arguments);
35+
},
3836
makeWritableStream: function() {
39-
var args = [].slice.call(arguments);
37+
var args = arguments;
4038
(makeWritableStreamOverride || util.makeWritableStream).apply(null, args);
4139
}
4240
});
@@ -70,7 +68,8 @@ describe('BigQuery/Table', function() {
7068
projectId: 'project-id',
7169
job: function(id) {
7270
return { id: id };
73-
}
71+
},
72+
request: util.noop
7473
}
7574
};
7675

@@ -98,9 +97,6 @@ describe('BigQuery/Table', function() {
9897

9998
before(function() {
10099
Table = proxyquire('../src/table.js', {
101-
'@google-cloud/storage': {
102-
File: FakeFile
103-
},
104100
'@google-cloud/common': {
105101
ServiceObject: FakeServiceObject,
106102
streamRouter: fakeStreamRouter,
@@ -125,9 +121,11 @@ describe('BigQuery/Table', function() {
125121
});
126122

127123
beforeEach(function() {
124+
isCustomTypeOverride = null;
128125
makeWritableStreamOverride = null;
129126
tableOverrides = {};
130127
table = new Table(DATASET, TABLE_ID);
128+
table.bigQuery.request = util.noop;
131129
});
132130

133131
describe('instantiation', function() {
@@ -480,12 +478,18 @@ describe('BigQuery/Table', function() {
480478
});
481479

482480
describe('export', function() {
483-
var FILE = new FakeFile({
484-
name: 'bucket-name',
485-
makeReq_: util.noop,
486-
}, 'file.json');
481+
var FILE = {
482+
name: 'file-name.json',
483+
bucket: {
484+
name: 'bucket-name'
485+
}
486+
};
487487

488488
beforeEach(function() {
489+
isCustomTypeOverride = function() {
490+
return true;
491+
};
492+
489493
table.bigQuery.job = function(id) {
490494
return { id: id };
491495
};
@@ -555,10 +559,25 @@ describe('BigQuery/Table', function() {
555559
done();
556560
};
557561

558-
table.export(FILE, done);
562+
table.export(FILE, assert.ifError);
563+
});
564+
565+
it('should check if a destination is a File', function(done) {
566+
isCustomTypeOverride = function(dest, type) {
567+
assert.strictEqual(dest, FILE);
568+
assert.strictEqual(type, 'storage/file');
569+
setImmediate(done);
570+
return true;
571+
};
572+
573+
table.export(FILE, assert.ifError);
559574
});
560575

561576
it('should throw if a destination is not a File', function() {
577+
isCustomTypeOverride = function() {
578+
return false;
579+
};
580+
562581
assert.throws(function() {
563582
table.export({}, util.noop);
564583
}, /Destination must be a File object/);
@@ -794,10 +813,18 @@ describe('BigQuery/Table', function() {
794813

795814
describe('import', function() {
796815
var FILEPATH = require.resolve('./testdata/testfile.json');
797-
var FILE = new FakeFile({
798-
name: 'bucket-name',
799-
makeReq_: util.noop
800-
}, 'file.json');
816+
var FILE = {
817+
name: 'file-name.json',
818+
bucket: {
819+
name: 'bucket-name'
820+
}
821+
};
822+
823+
beforeEach(function() {
824+
isCustomTypeOverride = function() {
825+
return true;
826+
};
827+
});
801828

802829
it('should accept just a File and a callback', function(done) {
803830
var mockJob = { id: 'foo' };
@@ -873,7 +900,22 @@ describe('BigQuery/Table', function() {
873900
table.import(FILEPATH, { sourceFormat: 'CSV' }, done);
874901
});
875902

903+
it('should check if a destination is a File', function(done) {
904+
isCustomTypeOverride = function(dest, type) {
905+
assert.strictEqual(dest, FILE);
906+
assert.strictEqual(type, 'storage/file');
907+
setImmediate(done);
908+
return true;
909+
};
910+
911+
table.export(FILE, assert.ifError);
912+
});
913+
876914
it('should throw if a File object is not provided', function() {
915+
isCustomTypeOverride = function() {
916+
return false;
917+
};
918+
877919
assert.throws(function() {
878920
table.import({});
879921
}, /Source must be a File object/);

packages/language/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@
5252
"language"
5353
],
5454
"dependencies": {
55-
"@google-cloud/common": "^0.1.0",
56-
"@google-cloud/storage": "^0.1.0",
5755
"arguejs": "^0.2.3",
5856
"arrify": "^1.0.1",
5957
"extend": "^3.0.0",
58+
"@google-cloud/common": "^0.3.0",
6059
"google-gax": "^0.6.0",
6160
"google-proto-files": "^0.4.0",
6261
"is": "^3.0.1",
6362
"propprop": "^0.3.1",
6463
"string-format-obj": "^1.0.0"
6564
},
6665
"devDependencies": {
66+
"@google-cloud/storage": "*",
6767
"mocha": "^2.1.0",
6868
"node-uuid": "^1.4.7",
6969
"proxyquire": "^1.7.10",

packages/language/src/document.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
'use strict';
2222

2323
var arrify = require('arrify');
24+
var common = require('@google-cloud/common');
2425
var extend = require('extend');
25-
var File = require('@google-cloud/storage').File;
2626
var format = require('string-format-obj');
2727
var is = require('is');
2828
var prop = require('propprop');
@@ -76,7 +76,7 @@ function Document(language, config) {
7676
this.reqOpts.document.type = 'PLAIN_TEXT';
7777
}
7878

79-
if (content instanceof File) {
79+
if (common.util.isCustomType(content, 'storage/file')) {
8080
this.reqOpts.document.gcsContentUri = format('gs://{bucket}/{file}', {
8181
bucket: encodeURIComponent(content.bucket.id),
8282
file: encodeURIComponent(content.id)

packages/language/test/document.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ var prop = require('propprop');
2222
var proxyquire = require('proxyquire');
2323
var util = require('@google-cloud/common').util;
2424

25-
function FakeFile() {}
25+
var isCustomTypeOverride;
26+
var fakeUtil = extend(true, {}, util, {
27+
isCustomType: function() {
28+
if (isCustomTypeOverride) {
29+
return isCustomTypeOverride.apply(null, arguments);
30+
}
31+
32+
return false;
33+
}
34+
});
2635

2736
describe('Document', function() {
2837
var DocumentCache;
@@ -36,15 +45,17 @@ describe('Document', function() {
3645

3746
before(function() {
3847
Document = proxyquire('../src/document.js', {
39-
'@google-cloud/storage': {
40-
File: FakeFile
48+
'@google-cloud/common': {
49+
util: fakeUtil
4150
}
4251
});
4352

4453
DocumentCache = extend(true, {}, Document);
4554
});
4655

4756
beforeEach(function() {
57+
isCustomTypeOverride = null;
58+
4859
for (var property in DocumentCache) {
4960
if (DocumentCache.hasOwnProperty(property)) {
5061
Document[property] = DocumentCache[property];
@@ -123,11 +134,19 @@ describe('Document', function() {
123134
});
124135

125136
it('should set the GCS content URI from a File', function() {
126-
var file = new FakeFile();
137+
var file = {
138+
// Leave spaces in to check that it is URI-encoded:
139+
id: 'file name',
140+
bucket: {
141+
id: 'bucket name'
142+
}
143+
};
127144

128-
// Leave spaces in to check that it is URI-encoded:
129-
file.bucket = { id: 'bucket id' };
130-
file.id = 'file name';
145+
isCustomTypeOverride = function(content, type) {
146+
assert.strictEqual(content, file);
147+
assert.strictEqual(type, 'storage/file');
148+
return true;
149+
};
131150

132151
var document = new Document(LANGUAGE, {
133152
content: file

packages/logging/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@
5252
"dependencies": {
5353
"arrify": "^1.0.0",
5454
"extend": "^3.0.0",
55-
"@google-cloud/bigquery": "^0.1.0",
56-
"@google-cloud/common": "^0.1.0",
57-
"@google-cloud/pubsub": "^0.1.0",
58-
"@google-cloud/storage": "^0.1.0",
5955
"google-proto-files": "^0.2.1",
6056
"is": "^3.0.1",
6157
"string-format-obj": "^1.0.0"
6258
},
6359
"devDependencies": {
6460
"async": "^1.4.2",
61+
"@google-cloud/bigquery": "*",
62+
"@google-cloud/common": "*",
63+
"@google-cloud/pubsub": "*",
64+
"@google-cloud/storage": "*",
6565
"methmeth": "^1.0.0",
6666
"mocha": "^3.0.1",
6767
"node-uuid": "^1.4.3",

packages/logging/src/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
'use strict';
2222

2323
var arrify = require('arrify');
24-
var BigQuery = require('@google-cloud/bigquery');
2524
var common = require('@google-cloud/common');
2625
var extend = require('extend');
2726
var format = require('string-format-obj');
2827
var googleProtoFiles = require('google-proto-files');
2928
var is = require('is');
30-
var PubSub = require('@google-cloud/pubsub');
31-
var Storage = require('@google-cloud/storage');
3229
var util = require('util');
3330

3431
/**
@@ -152,18 +149,18 @@ Logging.prototype.createSink = function(name, config, callback) {
152149
throw new Error('A sink configuration object must be provided.');
153150
}
154151

155-
if (config.destination instanceof Storage.Bucket) {
156-
this.setAclForBucket_(name, config, callback);
152+
if (common.util.isCustomType(config.destination, 'bigquery/dataset')) {
153+
this.setAclForDataset_(name, config, callback);
157154
return;
158155
}
159156

160-
if (config.destination instanceof BigQuery.Dataset) {
161-
this.setAclForDataset_(name, config, callback);
157+
if (common.util.isCustomType(config.destination, 'pubsub/topic')) {
158+
this.setAclForTopic_(name, config, callback);
162159
return;
163160
}
164161

165-
if (config.destination instanceof PubSub.Topic) {
166-
this.setAclForTopic_(name, config, callback);
162+
if (common.util.isCustomType(config.destination, 'storage/bucket')) {
163+
this.setAclForBucket_(name, config, callback);
167164
return;
168165
}
169166

packages/logging/src/sink.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function Sink(logging, name) {
5757
*
5858
* @example
5959
* var config = {
60-
* // ...
60+
* destination: {
61+
* // ...
62+
* }
6163
* };
6264
*
6365
* sink.create(config, function(err, sink, apiResponse) {

0 commit comments

Comments
 (0)