Skip to content
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
13 changes: 4 additions & 9 deletions lib/bigquery/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'use strict';

var extend = require('extend');
var is = require('is');

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

/**
* @type {module:common/util}
* @private
*/
var util = require('../common/util.js');

/*! Developer Documentation
*
* @param {module:bigquery} bigQuery - BigQuery instance.
Expand Down Expand Up @@ -100,7 +95,7 @@ Dataset.prototype.createTable = function(options, callback) {
}
});

if (util.is(options.schema, 'string')) {
if (is.string(options.schema)) {
options.schema = Table.createSchemaFromString_(options.schema);
}

Expand Down Expand Up @@ -221,7 +216,7 @@ Dataset.prototype.getMetadata = function(callback) {
Dataset.prototype.getTables = function(query, callback) {
var that = this;

if (util.is(query, 'function')) {
if (is.fn(query)) {
callback = query;
query = {};
}
Expand Down Expand Up @@ -258,7 +253,7 @@ Dataset.prototype.getTables = function(query, callback) {
* See {module:bigquery#query} for full documentation of this method.
*/
Dataset.prototype.query = function(options, callback) {
if (util.is(options, 'string')) {
if (is.string(options)) {
options = {
query: options
};
Expand Down
9 changes: 5 additions & 4 deletions lib/bigquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'use strict';

var extend = require('extend');
var is = require('is');

/**
* @type {module:bigquery/dataset}
Expand Down Expand Up @@ -225,7 +226,7 @@ BigQuery.prototype.dataset = function(id) {
BigQuery.prototype.getDatasets = function(query, callback) {
var that = this;

if (util.is(query, 'function')) {
if (is.fn(query)) {
callback = query;
query = {};
}
Expand Down Expand Up @@ -326,7 +327,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {
BigQuery.prototype.getJobs = function(options, callback) {
var that = this;

if (util.is(options, 'function')) {
if (is.fn(options)) {
callback = options;
options = {};
}
Expand Down Expand Up @@ -441,7 +442,7 @@ BigQuery.prototype.job = function(id) {
BigQuery.prototype.query = function(options, callback) {
var that = this;

if (util.is(options, 'string')) {
if (is.string(options)) {
options = {
query: options
};
Expand Down Expand Up @@ -548,7 +549,7 @@ BigQuery.prototype.query = function(options, callback) {
BigQuery.prototype.startQuery = function(options, callback) {
var that = this;

if (util.is(options, 'string')) {
if (is.string(options)) {
options = {
query: options
};
Expand Down
8 changes: 2 additions & 6 deletions lib/bigquery/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@

'use strict';

/**
* @type {module:common/util}
* @private
*/
var util = require('../common/util');
var is = require('is');

/*! Developer Documentation
*
Expand Down Expand Up @@ -159,7 +155,7 @@ Job.prototype.getMetadata = function(callback) {
* .pipe(fs.createWriteStream('./test/testdata/testfile.json'));
*/
Job.prototype.getQueryResults = function(options, callback) {
if (util.is(options, 'function')) {
if (is.fn(options)) {
callback = options;
options = {};
}
Expand Down
27 changes: 15 additions & 12 deletions lib/bigquery/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@

'use strict';

var arrify = require('arrify');
var crypto = require('crypto');
var duplexify = require('duplexify');
var extend = require('extend');
var format = require('string-format-obj');
var fs = require('fs');
var is = require('is');
var path = require('path');
var streamEvents = require('stream-events');

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

if (util.is(metadata, 'function')) {
if (is.fn(metadata)) {
callback = metadata;
metadata = {};
}
Expand Down Expand Up @@ -275,13 +278,13 @@ Table.prototype.createWriteStream = function(metadata) {
return fileTypeMap[key];
});

if (util.is(metadata, 'string')) {
if (is.string(metadata)) {
metadata = {
sourceFormat: fileTypeMap[metadata.toLowerCase()]
};
}

if (util.is(metadata.schema, 'string')) {
if (is.string(metadata.schema)) {
metadata.schema = Table.createSchemaFromString_(metadata.schema);
}

Expand Down Expand Up @@ -309,7 +312,7 @@ Table.prototype.createWriteStream = function(metadata) {
}
},
request: {
uri: util.format('{base}/{projectId}/jobs', {
uri: format('{base}/{projectId}/jobs', {
base: 'https://www.googleapis.com/upload/bigquery/v2/projects',
projectId: that.bigQuery.projectId
})
Expand Down Expand Up @@ -394,7 +397,7 @@ Table.prototype.delete = function(callback) {
Table.prototype.export = function(destination, options, callback) {
var that = this;

if (util.is(options, 'function')) {
if (is.fn(options)) {
callback = options;
options = {};
}
Expand All @@ -406,7 +409,7 @@ Table.prototype.export = function(destination, options, callback) {
};

extend(true, options, {
destinationUris: util.arrayize(destination).map(function(dest) {
destinationUris: arrify(destination).map(function(dest) {
if (!(dest instanceof File)) {
throw new Error('Destination must be a File object.');
}
Expand Down Expand Up @@ -548,7 +551,7 @@ Table.prototype.getMetadata = function(callback) {
Table.prototype.getRows = function(options, callback) {
var that = this;

if (util.is(options, 'function')) {
if (is.fn(options)) {
callback = options;
options = {};
}
Expand Down Expand Up @@ -654,7 +657,7 @@ Table.prototype.getRows = function(options, callback) {
Table.prototype.import = function(source, metadata, callback) {
var that = this;

if (util.is(metadata, 'function')) {
if (is.fn(metadata)) {
callback = metadata;
metadata = {};
}
Expand All @@ -667,7 +670,7 @@ Table.prototype.import = function(source, metadata, callback) {
json: 'NEWLINE_DELIMITED_JSON'
};

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

extend(true, body.configuration.load, metadata, {
sourceUris: util.arrayize(source).map(function(src) {
sourceUris: arrify(source).map(function(src) {
if (!(src instanceof File)) {
throw new Error('Source must be a File object.');
}
Expand Down Expand Up @@ -788,7 +791,7 @@ Table.prototype.import = function(source, metadata, callback) {
*/
Table.prototype.insert = function(rows, callback) {
var body = {
rows: util.arrayize(rows || []).map(function(row) {
rows: arrify(rows).map(function(row) {
var rowObject = {};
// Use the stringified contents of the row as a unique insert ID.
var md5 = crypto.createHash('md5');
Expand Down Expand Up @@ -864,7 +867,7 @@ Table.prototype.setMetadata = function(metadata, callback) {
delete metadata.name;
}

if (util.is(metadata.schema, 'string')) {
if (is.string(metadata.schema)) {
metadata.schema = Table.createSchemaFromString_(metadata.schema);
}

Expand Down
22 changes: 9 additions & 13 deletions lib/common/stream-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@

'use strict';

var arrify = require('arrify');
var concat = require('concat-stream');
var split = require('split-array-stream');
var is = require('is');
var streamEvents = require('stream-events');
var through = require('through2');

/**
* @type {module:common/util}
* @private
*/
var util = require('../common/util.js');

/*! Developer Documentation
*
* streamRouter is used to extend `nextQuery`+callback methods with stream
Expand All @@ -56,7 +52,7 @@ var streamRouter = {};
* @param {array|string} methodNames - Name(s) of the methods to extend.
*/
streamRouter.extend = function(Class, methodNames) {
methodNames = util.arrayize(methodNames);
methodNames = arrify(methodNames);

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

if (util.is(firstArgument, 'function')) {
if (is.fn(firstArgument)) {
callback = firstArgument;
} else {
query = firstArgument;
}

if (util.is(lastArgument, 'function')) {
if (is.fn(lastArgument)) {
callback = lastArgument;
}

if (util.is(query, 'object')) {
if (is.object(query)) {
// Check if the user only asked for a certain amount of results.
if (util.is(query.maxResults, 'number')) {
if (is.number(query.maxResults)) {
// `maxResults` is used API-wide.
maxResults = query.maxResults;
} else if (util.is(query.limitVal, 'number')) {
} else if (is.number(query.limitVal)) {
// `limitVal` is part of a Datastore query.
maxResults = query.limitVal;
} else if (util.is(query.pageSize, 'number')) {
} else if (is.number(query.pageSize)) {
// `pageSize` is Pub/Sub's `maxResults`.
maxResults = query.pageSize;
}
Expand Down
Loading