Skip to content

Commit c6ab33e

Browse files
core: use external modules
1 parent e6da167 commit c6ab33e

42 files changed

Lines changed: 238 additions & 552 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/bigquery/dataset.js

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

2323
var extend = require('extend');
24+
var is = require('is');
2425

2526
/**
2627
* @type {module:bigquery/table}
@@ -34,12 +35,6 @@ var Table = require('./table.js');
3435
*/
3536
var streamRouter = require('../common/stream-router.js');
3637

37-
/**
38-
* @type {module:common/util}
39-
* @private
40-
*/
41-
var util = require('../common/util.js');
42-
4338
/*! Developer Documentation
4439
*
4540
* @param {module:bigquery} bigQuery - BigQuery instance.
@@ -100,7 +95,7 @@ Dataset.prototype.createTable = function(options, callback) {
10095
}
10196
});
10297

103-
if (util.is(options.schema, 'string')) {
98+
if (is.string(options.schema)) {
10499
options.schema = Table.createSchemaFromString_(options.schema);
105100
}
106101

@@ -221,7 +216,7 @@ Dataset.prototype.getMetadata = function(callback) {
221216
Dataset.prototype.getTables = function(query, callback) {
222217
var that = this;
223218

224-
if (util.is(query, 'function')) {
219+
if (is.fn(query)) {
225220
callback = query;
226221
query = {};
227222
}
@@ -258,7 +253,7 @@ Dataset.prototype.getTables = function(query, callback) {
258253
* See {module:bigquery#query} for full documentation of this method.
259254
*/
260255
Dataset.prototype.query = function(options, callback) {
261-
if (util.is(options, 'string')) {
256+
if (is.string(options)) {
262257
options = {
263258
query: options
264259
};

lib/bigquery/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'use strict';
2222

2323
var extend = require('extend');
24+
var is = require('is');
2425

2526
/**
2627
* @type {module:bigquery/dataset}
@@ -225,7 +226,7 @@ BigQuery.prototype.dataset = function(id) {
225226
BigQuery.prototype.getDatasets = function(query, callback) {
226227
var that = this;
227228

228-
if (util.is(query, 'function')) {
229+
if (is.fn(query)) {
229230
callback = query;
230231
query = {};
231232
}
@@ -326,7 +327,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {
326327
BigQuery.prototype.getJobs = function(options, callback) {
327328
var that = this;
328329

329-
if (util.is(options, 'function')) {
330+
if (is.fn(options)) {
330331
callback = options;
331332
options = {};
332333
}
@@ -441,7 +442,7 @@ BigQuery.prototype.job = function(id) {
441442
BigQuery.prototype.query = function(options, callback) {
442443
var that = this;
443444

444-
if (util.is(options, 'string')) {
445+
if (is.string(options)) {
445446
options = {
446447
query: options
447448
};
@@ -548,7 +549,7 @@ BigQuery.prototype.query = function(options, callback) {
548549
BigQuery.prototype.startQuery = function(options, callback) {
549550
var that = this;
550551

551-
if (util.is(options, 'string')) {
552+
if (is.string(options)) {
552553
options = {
553554
query: options
554555
};

lib/bigquery/job.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020

2121
'use strict';
2222

23-
/**
24-
* @type {module:common/util}
25-
* @private
26-
*/
27-
var util = require('../common/util');
23+
var is = require('is');
2824

2925
/*! Developer Documentation
3026
*
@@ -157,7 +153,7 @@ Job.prototype.getMetadata = function(callback) {
157153
* .pipe(fs.createWriteStream('./test/testdata/testfile.json'));
158154
*/
159155
Job.prototype.getQueryResults = function(options, callback) {
160-
if (util.is(options, 'function')) {
156+
if (is.fn(options)) {
161157
callback = options;
162158
options = {};
163159
}

lib/bigquery/table.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121
'use strict';
2222

23+
var arrify = require('arrify');
2324
var crypto = require('crypto');
2425
var duplexify = require('duplexify');
2526
var extend = require('extend');
27+
var format = require('string-format-obj');
2628
var fs = require('fs');
29+
var is = require('is');
2730
var path = require('path');
2831
var streamEvents = require('stream-events');
2932

@@ -163,7 +166,7 @@ Table.prototype.copy = function(destination, metadata, callback) {
163166
throw new Error('Destination must be a Table object.');
164167
}
165168

166-
if (util.is(metadata, 'function')) {
169+
if (is.fn(metadata)) {
167170
callback = metadata;
168171
metadata = {};
169172
}
@@ -275,13 +278,13 @@ Table.prototype.createWriteStream = function(metadata) {
275278
return fileTypeMap[key];
276279
});
277280

278-
if (util.is(metadata, 'string')) {
281+
if (is.string(metadata)) {
279282
metadata = {
280283
sourceFormat: fileTypeMap[metadata.toLowerCase()]
281284
};
282285
}
283286

284-
if (util.is(metadata.schema, 'string')) {
287+
if (is.string(metadata.schema)) {
285288
metadata.schema = Table.createSchemaFromString_(metadata.schema);
286289
}
287290

@@ -309,7 +312,7 @@ Table.prototype.createWriteStream = function(metadata) {
309312
}
310313
},
311314
request: {
312-
uri: util.format('{base}/{projectId}/jobs', {
315+
uri: format('{base}/{projectId}/jobs', {
313316
base: 'https://www.googleapis.com/upload/bigquery/v2/projects',
314317
projectId: that.bigQuery.projectId
315318
})
@@ -394,7 +397,7 @@ Table.prototype.delete = function(callback) {
394397
Table.prototype.export = function(destination, options, callback) {
395398
var that = this;
396399

397-
if (util.is(options, 'function')) {
400+
if (is.fn(options)) {
398401
callback = options;
399402
options = {};
400403
}
@@ -406,7 +409,7 @@ Table.prototype.export = function(destination, options, callback) {
406409
};
407410

408411
extend(true, options, {
409-
destinationUris: util.arrayize(destination).map(function(dest) {
412+
destinationUris: arrify(destination).map(function(dest) {
410413
if (!(dest instanceof File)) {
411414
throw new Error('Destination must be a File object.');
412415
}
@@ -548,7 +551,7 @@ Table.prototype.getMetadata = function(callback) {
548551
Table.prototype.getRows = function(options, callback) {
549552
var that = this;
550553

551-
if (util.is(options, 'function')) {
554+
if (is.fn(options)) {
552555
callback = options;
553556
options = {};
554557
}
@@ -654,7 +657,7 @@ Table.prototype.getRows = function(options, callback) {
654657
Table.prototype.import = function(source, metadata, callback) {
655658
var that = this;
656659

657-
if (util.is(metadata, 'function')) {
660+
if (is.fn(metadata)) {
658661
callback = metadata;
659662
metadata = {};
660663
}
@@ -667,7 +670,7 @@ Table.prototype.import = function(source, metadata, callback) {
667670
json: 'NEWLINE_DELIMITED_JSON'
668671
};
669672

670-
if (util.is(source, 'string')) {
673+
if (is.string(source)) {
671674
// A path to a file was given. If a sourceFormat wasn't specified, try to
672675
// find a match from the file's extension.
673676
var format = formats[path.extname(source).substr(1).toLowerCase()];
@@ -700,7 +703,7 @@ Table.prototype.import = function(source, metadata, callback) {
700703
};
701704

702705
extend(true, body.configuration.load, metadata, {
703-
sourceUris: util.arrayize(source).map(function(src) {
706+
sourceUris: arrify(source).map(function(src) {
704707
if (!(src instanceof File)) {
705708
throw new Error('Source must be a File object.');
706709
}
@@ -788,7 +791,7 @@ Table.prototype.import = function(source, metadata, callback) {
788791
*/
789792
Table.prototype.insert = function(rows, callback) {
790793
var body = {
791-
rows: util.arrayize(rows || []).map(function(row) {
794+
rows: arrify(rows).map(function(row) {
792795
var rowObject = {};
793796
// Use the stringified contents of the row as a unique insert ID.
794797
var md5 = crypto.createHash('md5');
@@ -864,7 +867,7 @@ Table.prototype.setMetadata = function(metadata, callback) {
864867
delete metadata.name;
865868
}
866869

867-
if (util.is(metadata.schema, 'string')) {
870+
if (is.string(metadata.schema)) {
868871
metadata.schema = Table.createSchemaFromString_(metadata.schema);
869872
}
870873

lib/common/stream-router.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020

2121
'use strict';
2222

23+
var arrify = require('arrify');
2324
var concat = require('concat-stream');
25+
var is = require('is');
2426
var isStreamEnded = require('is-stream-ended');
2527
var streamEvents = require('stream-events');
2628
var through = require('through2');
2729

28-
/**
29-
* @type {module:common/util}
30-
* @private
31-
*/
32-
var util = require('../common/util.js');
33-
3430
/*! Developer Documentation
3531
*
3632
* streamRouter is used to extend `nextQuery`+callback methods with stream
@@ -56,7 +52,7 @@ var streamRouter = {};
5652
* @param {array|string} methodNames - Name(s) of the methods to extend.
5753
*/
5854
streamRouter.extend = function(Class, methodNames) {
59-
methodNames = util.arrayize(methodNames);
55+
methodNames = arrify(methodNames);
6056

6157
methodNames.forEach(function(methodName) {
6258
var originalMethod = Class.prototype[methodName];
@@ -83,25 +79,25 @@ streamRouter.parseArguments_ = function(args) {
8379
var firstArgument = args[0];
8480
var lastArgument = args[args.length - 1];
8581

86-
if (util.is(firstArgument, 'function')) {
82+
if (is.fn(firstArgument)) {
8783
callback = firstArgument;
8884
} else {
8985
query = firstArgument;
9086
}
9187

92-
if (util.is(lastArgument, 'function')) {
88+
if (is.fn(lastArgument)) {
9389
callback = lastArgument;
9490
}
9591

96-
if (util.is(query, 'object')) {
92+
if (is.object(query)) {
9793
// Check if the user only asked for a certain amount of results.
98-
if (util.is(query.maxResults, 'number')) {
94+
if (is.number(query.maxResults)) {
9995
// `maxResults` is used API-wide.
10096
maxResults = query.maxResults;
101-
} else if (util.is(query.limitVal, 'number')) {
97+
} else if (is.number(query.limitVal)) {
10298
// `limitVal` is part of a Datastore query.
10399
maxResults = query.limitVal;
104-
} else if (util.is(query.pageSize, 'number')) {
100+
} else if (is.number(query.pageSize)) {
105101
// `pageSize` is Pub/Sub's `maxResults`.
106102
maxResults = query.pageSize;
107103
}

0 commit comments

Comments
 (0)