Table.prototype.getMetadata = function(options, callback) { var self = this; if (is.function(options)) { callback = options; options = {}; } var protoOpts = { service: 'BigtableTableAdmin', method: 'getTable' }; var reqOpts = { name: this.id, view: Table.VIEWS[options.view || 'unspecified'] }; this.request(protoOpts, reqOpts, function(err, resp) { if (err) { callback(err, null, resp); return; } self.metadata = resp; callback(null, self.metadata, resp); }); };
provide: function(name, value, isPrivate) { var provider; if (is.array(value)) { provider = value; } else if (is.function(value)) { provider = this.parse(value); provider.push(value); } else { this.value(name, value); } if (provider) { if (this.$providers.hasOwnProperty(name)) { throw new DependencyAlreadyExistsError(name); } this.$providers[name] = this.annotate.apply(null, provider); if (isPrivate) { this.$privates[name] = true; } } return this; },
Table.prototype.mutate = function(entries, callback) { entries = flatten(arrify(entries)); var grpcOpts = { service: 'Bigtable', method: 'mutateRows' }; var reqOpts = { objectMode: true, tableName: this.id, entries: entries.map(Mutation.parse) }; var isCallbackMode = is.function(callback); var emitter = null; if (!isCallbackMode) { emitter = new events.EventEmitter(); } var stream = pumpify.obj([ this.requestStream(grpcOpts, reqOpts), through.obj(function(data, enc, next) { var throughStream = this; data.entries.forEach(function(entry) { // mutation was successful, no need to notify the user if (entry.status.code === 0) { return; } var status = common.GrpcService.decorateStatus_(entry.status); status.entry = entries[entry.index]; if (!isCallbackMode) { emitter.emit('error', status); return; } throughStream.push(status); }); next(); }) ]); if (!isCallbackMode) { stream.on('error', emitter.emit.bind(emitter, 'error')); stream.on('finish', emitter.emit.bind(emitter, 'complete')); return emitter; } stream .on('error', callback) .pipe(concat(function(mutationErrors) { callback(null, mutationErrors); })); };
Object.keys(fields).forEach(function (k) { // if it's not a field object, create an object field. if (!is.function(fields[k].toHTML) && is.object(fields[k])) { fields[k] = exports.fields.object(fields[k]); } fields[k].name = k; });
Table.prototype.sampleRowKeys = function(callback) { var grpcOpts = { service: 'Bigtable', method: 'sampleRowKeys' }; var reqOpts = { tableName: this.id, objectMode: true }; var stream = pumpify.obj([ this.requestStream(grpcOpts, reqOpts), through.obj(function(key, enc, next) { next(null, { key: key.rowKey, offset: key.offsetBytes }); }) ]); if (!is.function(callback)) { return stream; } stream .on('error', callback) .pipe(concat(function(keys) { callback(null, keys); })); };
mixin.stubWithReturn = function stubWithReturn(config) { config = config || {}; let stub; let returns; const isReturnsConfigured = config.hasOwnProperty('returns'); const payload = {}; if (!is.string(config.method) || !config.method.length) { throw new Error('method not specified'); } // Allow test to avoid creating the config.obj ahead of time. if (config.obj) { stub = this.stubMany(config.obj, config.method)[config.method]; } else { config.obj = {}; stub = this.stubMany(config.obj, config.method)[config.method]; } // Detect the need for withArgs(). if (is.array(config.args) && config.args.length) { stub = stub.withArgs.apply(stub, config.args); } // Create the stub return value. Either a spy itself or hash of them. if (config.spies) { returns = {}; // 'a.b.c.spy1' if (is.string(config.spies) && /\./.test(config.spies)) { setPathValue(returns, config.spies, this.spy()); } else { const spies = [].concat(config.spies); for (let s = 0; s < spies.length; s++) { setPathValue(returns, spies[s], this.spy()); } } } else { if (isReturnsConfigured) { returns = config.returns; } else { returns = this.spy(); } } stub.returns(returns); if (!isReturnsConfigured) { if (is.function(returns)) { payload.returnedSpy = returns; } else { payload.returnedSpies = returns; } } payload[config.method] = stub; payload.target = config.obj; return payload; };
arrify(filters).forEach(function(filterObj) { var key = Object.keys(filterObj)[0]; if (!is.function(filter[key])) { throw new FilterError(key); } filter[key](filterObj[key]); });
instantiate: function(Type, locals) { var Constructor = function() {}, instance, returnedValue; Constructor.prototype = (is.array(Type) ? Type[Type.length - 1] : Type).prototype; instance = new Constructor(); returnedValue = this.invoke(Type, instance, locals); return (is.object(returnedValue) || is.function(returnedValue)) ? returnedValue : instance; },
Table.prototype.getRows = function(options, callback) { if (is.function(options)) { callback = options; options = {}; } this.createReadStream(options) .on('error', callback) .pipe(concat(function(rows) { callback(null, rows); })); };
Log.prototype.getEntries = function(options, callback) { if (is.function(options)) { callback = options; options = {}; } options = extend({ filter: 'logName="' + this.formattedName_ + '"' }, options); return this.parent.getEntries(options, callback); };
return function(fn) { if (!is.function(fn)) { throw new Error('Invalid function: ' + fn); } var match = fn.toString().match(FN_ARGS), fnArgs = match[1]; return fnArgs && fnArgs.split(',').map(function(arg) { return arg.trim(); }) || []; }
Row.prototype.getMetadata = function(options, callback) { if (is.function(options)) { callback = options; options = {}; } this.get(options, function(err, row, resp) { if (err) { callback(err, null, resp); return; } callback(null, row.metadata, resp); }); };
, visit:function(visitor,callback,res){ if(callback && !is.function(callback)){ res = callback || {}; callback = null; } if(!res){res = {};} if(visitor && is(visitor,Function)){ for(var n in this){ if(this.hasOwnProperty(n) && isAllowed(n)){ this[n].visit(visitor,null,res); } } visitor(this, res); if(callback){callback(res);} } return res; }
Bigtable.prototype.createInstance = function(name, options, callback) { var self = this; if (is.function(options)) { callback = options; options = {}; } var protoOpts = { service: 'BigtableInstanceAdmin', method: 'createInstance' }; var reqOpts = { parent: this.projectName, instanceId: name, instance: { displayName: options.displayName || name } }; reqOpts.clusters = arrify(options.clusters) .reduce(function(clusters, cluster) { clusters[cluster.name] = { location: Cluster.getLocation_(self.projectId, cluster.location), serveNodes: cluster.nodes, defaultStorageType: Cluster.getStorageType_(cluster.storage) }; return clusters; }, {}); this.request(protoOpts, reqOpts, function(err, resp) { if (err) { callback(err, null, null, resp); return; } var instance = self.instance(name); var operation = self.operation(resp.name); operation.metadata = resp; callback(null, instance, operation, resp); }); };
Table.prototype.createFamily = function(name, rule, callback) { var self = this; if (is.function(rule)) { callback = rule; rule = null; } if (!name) { throw new Error('A name is required to create a family.'); } var grpcOpts = { service: 'BigtableTableAdmin', method: 'modifyColumnFamilies' }; var mod = { id: name, create: {} }; if (rule) { mod.create.gcRule = Family.formatRule_(rule); } var reqOpts = { name: this.id, modifications: [mod] }; this.request(grpcOpts, reqOpts, function(err, resp) { if (err) { callback(err, null, resp); return; } var family = self.family(resp.name); family.metadata = resp; callback(null, family, resp); }); };
Instance.prototype.createDatabase = function(name, options, callback) { var self = this; if (!name) { throw new Error('A name is required to create a database.'); } if (is.function(options)) { callback = options; options = {}; } options = options || {}; var poolOptions = options.poolOptions; delete options.poolOptions; var reqOpts = extend({ parent: this.formattedName_, createStatement: 'CREATE DATABASE `' + name.split('/').pop() + '`' }, options); if (reqOpts.schema) { reqOpts.extraStatements = arrify(reqOpts.schema); delete reqOpts.schema; } this.api.Database.createDatabase(reqOpts, function(err, operation, resp) { if (err) { callback(err, null, null, resp); return; } var database = self.database(name, poolOptions); callback(null, database, operation, resp); }); };
Row.prototype.create = function(entry, callback) { var self = this; if (is.function(entry)) { callback = entry; entry = {}; } entry = { key: this.id, data: entry, method: Mutation.methods.INSERT }; this.parent.mutate(entry, function(err, apiResponse) { if (err) { callback(err, null, apiResponse); return; } callback(null, self, apiResponse); }); };
Table.prototype.deleteRows = function(options, callback) { if (is.function(options)) { callback = options; options = {}; } var grpcOpts = { service: 'BigtableTableAdmin', method: 'dropRowRange' }; var reqOpts = { name: this.id }; if (options.prefix) { reqOpts.rowKeyPrefix = Mutation.convertToBytes(options.prefix); } else { reqOpts.deleteAllDataFromTable = true; } this.request(grpcOpts, reqOpts, callback); };
Row.prototype.increment = function(column, value, callback) { if (is.function(value)) { callback = value; value = 1; } var reqOpts = { column: column, increment: value }; this.createRules(reqOpts, function(err, apiResponse) { if (err) { callback(err, null, apiResponse); return; } var data = Row.formatFamilies_(apiResponse.families); var value = dotProp.get(data, column.replace(':', '.'))[0].value; callback(null, value, apiResponse); }); };
Bigtable.prototype.getInstances = function(query, callback) { var self = this; if (is.function(query)) { callback = query; query = {}; } var protoOpts = { service: 'BigtableInstanceAdmin', method: 'listInstances' }; var reqOpts = extend({}, query, { parent: this.projectName }); this.request(protoOpts, reqOpts, function(err, resp) { if (err) { callback(err, null, null, resp); return; } var instances = resp.instances.map(function(instanceData) { var instance = self.instance(instanceData.name); instance.metadata = instanceData; return instance; }); var nextQuery = null; if (resp.nextPageToken) { nextQuery = extend({}, query, { pageToken: resp.nextPageToken }); } callback(null, instances, nextQuery, resp); }); };
methods.annotateImage = promisify(function(request, options, callback) { // If a callback was provided and options were skipped, normalize // the argument names. if (is.undefined(callback) && is.function(options)) { callback = options; options = undefined; } // If there is no image, throw an exception. if (is.undefined(request.image)) { throw new Error('Attempted to call `annotateImage` with no image.'); } // If we got a filename for the image, open the file and transform // it to content. return coerceImage(request.image, (err, image) => { if (err) { return callback(err); } request.image = image; // Call the GAPIC batch annotation function. return this.batchAnnotateImages([request], options, (err, r) => { // If there is an error, handle it. if (err) { return callback(err); } // We are guaranteed to only have one response element, since we // only sent one image. var response = r.responses[0]; // Fire the callback if applicable. return callback(undefined, response); }); }); });
Row.prototype.filter = function(filter, onMatch, onNoMatch, callback) { var grpcOpts = { service: 'BigtableService', method: 'checkAndMutateRow' }; if (is.function(onNoMatch)) { callback = onNoMatch; onNoMatch = []; } var reqOpts = { tableName: this.parent.id, rowKey: Mutation.convertToBytes(this.id), predicateFilter: Filter.parse(filter), trueMutations: createFlatMutationsList(onMatch), falseMutations: createFlatMutationsList(onNoMatch) }; this.request(grpcOpts, reqOpts, function(err, apiResponse) { if (err) { callback(err, null, apiResponse); return; } callback(null, apiResponse.predicateMatched, apiResponse); }); function createFlatMutationsList(entries) { entries = arrify(entries).map(function(entry) { return Mutation.parse(entry).mutations; }); return flatten(entries); } };
Table.prototype.getRows = function(options, callback) { var self = this; if (is.function(options)) { callback = options; options = {}; } options = options || {}; options.ranges = options.ranges || []; var grpcOpts = { service: 'Bigtable', method: 'readRows' }; var reqOpts = { tableName: this.id, objectMode: true }; if (options.start || options.end) { options.ranges.push({ start: options.start, end: options.end }); } if (options.keys || options.ranges.length) { reqOpts.rows = {}; if (options.keys) { reqOpts.rows.rowKeys = options.keys.map(Mutation.convertToBytes); } if (options.ranges.length) { reqOpts.rows.rowRanges = options.ranges.map(function(range) { return Filter.createRange(range.start, range.end, 'Key'); }); } } if (options.filter) { reqOpts.filter = Filter.parse(options.filter); } if (options.limit) { reqOpts.numRowsLimit = options.limit; } var stream = pumpify.obj([ this.requestStream(grpcOpts, reqOpts), through.obj(function(data, enc, next) { var throughStream = this; var rows = Row.formatChunks_(data.chunks, { decode: options.decode }); rows.forEach(function(rowData) { var row = self.row(rowData.key); row.data = rowData.data; throughStream.push(row); }); next(); }) ]); if (!is.function(callback)) { return stream; } stream .on('error', callback) .pipe(concat(function(rows) { callback(null, rows); })); };
function apply (model, key, value) { if(model[key]() !== undefined) return; value = is.function(value) ? value.call(model) : clone(value); model.attrs[key] = value; }
Kenshoo.prototype.loaded = function() { return is.function(window.k_trackevent); };
Row.prototype.get = function(columns, callback) { var self = this; if (is.function(columns)) { callback = columns; columns = []; } var filter; columns = arrify(columns); if (columns.length) { var filters = columns .map(Mutation.parseColumnName) .map(function(column) { var filters = [{ family: column.family }]; if (column.qualifier) { filters.push({ column: column.qualifier }); } return filters; }); if (filters.length > 1) { filter = [{ interleave: filters }]; } else { filter = filters[0]; } } var reqOpts = { key: this.id, filter: filter }; this.parent.getRows(reqOpts, function(err, rows, apiResponse) { if (err) { callback(err, null, apiResponse); return; } var row = rows[0]; if (!row) { err = new RowError(self.id); callback(err, null, apiResponse); return; } extend(true, self.data, row.data); // If the user specifies column names, we'll return back the row data we // received. Otherwise, we'll return the row itself in a typical // GrpcServiceObject#get fashion. callback(null, columns.length ? row.data : self, apiResponse); }); };