module.exports = function (name, arr) { var database, changes; /** * Used to add a database to the mock couch * @param {string} name - the name of the database * @param {array} arr - array with the rows */ arr = arr || []; if (!Array.isArray(arr)) { return false; } // Add an _id and a _rev to each document, if necessary. arr = R.map(function (doc) { doc._id = doc._id || createMD5(); doc._rev = doc._rev || '1-' + createMD5(JSON.stringify(doc)); return doc; }, arr); // Prepare the database object. // Is pretty much the passed array, converted to an object, // where each property is the document, indexed by the _id database = R.compose( R.mapObj(R.omit(['_id'])), R.mapObj(R.head), R.groupBy(R.prop('_id')), R.cloneDeep )(arr); changes = R.compose( R.map.idx(function (doc, index) { return { seq : index, id : doc._id, changes : [ { rev : doc._rev } ], doc : doc }; }), R.filter(function (doc) { // don't emit changes for _local documents return doc._id.indexOf('_local') !== 0; }), R.cloneDeep )(arr); this.databases[name] = mockDB(database); this.changes[name] = changes; Object.defineProperty(this.sequence, name, { get : function () { return this.changes[name].length; }.bind(this) }); return this.databases[name]; };
module.exports = R.mapObj(function(model) { var privateColumns = _.reduce(model, function(acc, value, columnName) { return value.private ? acc.concat(columnName) : acc; }, []); var publicColumns = _.reduce(model, function(acc, value, columnName) { return value.private ? acc : acc.concat(columnName); }, []); var allSchemas = R.mapObj(R.get('schema'), model); var publicSchemas = R.pick(publicColumns, allSchemas); var privateSchemas = R.pick(privateColumns, allSchemas); return { _raw: model, columns: { all: R.keys(model), private: privateColumns, public: publicColumns }, schemas: { all: allSchemas, private: privateSchemas, public: publicSchemas }, sanitize: function(model) { return R.pick(publicColumns, model); } }; }, models);
.consume(function (err, x, push, next) { if (err) { // pass errors along the stream and consume next value push(err) next() } else if (x === _.nil) { // pass nil (end event) along the stream push(null, x) } else { // first do all add, then all removes var things = R.groupBy(R.prop('operation'), x) // create all permutations of adds and removes separately var perms = R.mapObj(function (xs) { return Combinatorics.permutation(xs).toArray() }, things) // take product [adds] ++ [removes] var cp = Combinatorics.cartesianProduct( perms['add'] || [], perms['remove'] || [] ).toArray() // for each combination, push out concatenated list again cp.forEach(function (c) { push(null, R.concat(c[0], c[1])) }) next() } })
function getNextHead(current, direction) { return R.isNil(direction) ? current : R.evolve( R.mapObj(R.add, constants.DIRECTIONS_MUTATIONS[direction]), current ); }
get : function () { return R.compose( R.sum, R.values, R.mapObj(function (doc) { return doc._deleted ? 0 : 1; }) )(this); }
module.exports = function (data) { var properties; properties = R.mapObj(function (value) { return { value : value, configurable : true, enumerable : true, writable : true }; }, data); return Object.create(proto, properties); };
printIdTime: function (data, total) { var all_results = []; var colorFunc = null; var grouped = this.byId(data); var newData = R.values(R.mapObj(function (item) { var item_obj = { name: item[0].name, file: item[0].file, line: item[0].line, args: item[0].args, stack: item[0].stack, sid: item[0].sid, date: item[0].date, ts: item[1].date - item[0].date }; return item_obj; }, grouped)); data = newData; for (var i = 0; i < data.length; i++) { var item = data[i]; var sid = item.sid; // var date = moment(item.date).toISOString(); var timespan = 0; var timespan_percent = 0; var timespan_color_func; colorFunc = this.getChalkFuncByHash(item.file + item.line); var filename = item.file.replace(/^.*[\\\/]/, ''); if (i > 0) { timespan = item.date - data[i - 1].date; timespan_percent = (timespan / total) * 100; } // format numbers timespan_percent = this.format(timespan_percent, 2, 3, ',', '.'); timespan_color_func = chalk.gray; if ( timespan_percent < 1 ) { timespan_color_func = chalk.gray; } else if ( timespan_percent >= 1 && timespan_percent < 2 ) { timespan_color_func = chalk.white; } else if ( timespan_percent >= 2 && timespan_percent < 3 ) { timespan_color_func = chalk.yellow; } else if ( timespan_percent >= 3 ) { timespan_color_func = chalk.red; } all_results.push([ ' ' + item.stack.length - 1, colorFunc(sid.substring(0, 3)), colorFunc(filename + ':' + item.line), colorFunc(item.name), timespan_color_func(moment(item.date).format('ss:SSS')), timespan_color_func(timespan), timespan_color_func(timespan_percent + '%'), ]); } return all_results; },
textList : leaf('TextList', []), dataList : leaf('DataList', []) } }; }; }; var wrap = function (v) { return { prior : v, int8Field : leaf('Int8', 0), textField : leaf('Text', "") }; }; var priorize = ramda.mapObj(function (value) { return { type : 'Group', value : wrap(value) }; }); exports.leaf = leaf; exports.leafize = leafize; exports.priorize = priorize; exports.upgrade = upgrade; exports.firstDefaults = { voidField : leaf('Void', null), boolField : leaf('Bool', false), int8Field : leaf('Int8', 0), int16Field : leaf('Int16', 0), int32Field : leaf('Int32', 0), int64Field : leaf('Int64', [0,0]),
it('attributes array with 5 entries', function () { R.mapObj(function (char) { char.should.have.property('attributes'); char.attributes.should.be.an('array').and.have.length(5); }, characters); });
it(prop + ' property', function () { R.mapObj(function (char) { char.should.have.property(prop); char[prop].should.be.a('string'); }, characters); });