_.flow([ _.toPairs, pairs => _.filter(pairs, ([, value]) => value.isRequired()), pairs => _.map(pairs, p => p[0]) ])
getSocketsToRooms () { return this.redis.getSocketsToRooms( this.makeKeyName('sockets'), this.makeSocketToRooms()) .spread(result => { const data = JSON.parse(result) || {} for (const [k, v] of _.toPairs(data)) { if (_.isEmpty(v)) { data[k] = [] } } return data }) }
const convertMongooseValidationError2Message = err => _.toPairs(err.errors) .map(pair => ({ field: pair[0], message: pair[1].message }))
/** * Fixes an instance data after an incorrect service shutdown. * * @param {string} id Instance id. * @param {callback} [cb] Optional callback. * * @return {Promise<undefined>} Promise that resolves without any data. */ instanceRecovery (id, cb) { return this.state.getInstanceSockets(id).then(sockets => { return Promise.each(_.toPairs(sockets), ([id, userName]) => { return this.state.getUser(userName) .then(user => user.removeSocket(id)) .catchReturn() }) }).asCallback(cb) }
function collOf(predicate, options = {}) { const {kind = _.stubTrue, distinct = false, into} = options; const uniq = value => !distinct || isUnique(value); return { conform: value => { const result = kind(value) && uniq(value) && checkCount(value, options) && _.every(value, v => isValid(predicate, v)); return result ? transform(value, into) : invalidString; }, unform: _.identity, gen: () => tcg.null.then(() => tcg.array(gen(predicate), {size: options.count})), describe: () => [collOf.name, ...describe([predicate]), ...describe(_.flatten(_.toPairs(options)))], explain: function*(values, {via}) { yield* explainCount(values, options, via); yield* explainInvalid(values, predicate, via); } }; }
function compile(data) { return _.toPairs(data) .reduce((result, pair) => { if (_.isFunction(pair[1])) { result[pair[0]] = pair[1](); } else if (_.isObject(pair[1])) { result[pair[0]] = compile(pair[1]); } else { result[pair[0]] = pair[1]; } return result; }, {}); }
function getValue(value) { return _.isMap(value) ? Array.from(value) : _.toPairs(value); }
checkUserSockets (user) { const { userName } = user return run(this, function * () { const sockets = yield user.userState.getSocketsToInstance() yield Promise.each(_.toPairs(sockets), ([socket, instance]) => { if (instance === this.instanceUID) { if (!this.transport.getSocket(socket)) { return user.userState.removeSocket(socket) } } }) const data = yield user.userState.getSocketsToRooms() const args = _.values(data) const rooms = _.intersection(...args) return Promise.each(rooms, roomName => { return this.state.getRoom(roomName) .then(room => room.roomState.hasInList('userlist', userName)) .then(isPresent => isPresent ? null : user.removeFromRoom(roomName)) .catchReturn() }) }) }
constructor (server, options) { this.server = server this.options = options this.closed = false if (this.options.useCluster) { this.redis = new Redis.Cluster(...this.options.redisOptions) } else { const redisOptions = _.castArray(this.options.redisOptions) this.redis = new Redis(...redisOptions) } this.RoomState = RoomStateRedis this.UserState = UserStateRedis this.DirectMessagingState = DirectMessagingStateRedis this.lockTTL = this.options.lockTTL || 10000 this.instanceUID = this.server.instanceUID this.server.redis = this.redis for (const [cmd, def] of _.toPairs(luaCommands)) { this.redis.defineCommand(cmd, { numberOfKeys: def.numberOfKeys, lua: def.lua }) } }
const useragent = req.useragent; const boards = _.groupBy(reflinks, 'boardUri'); const newReports = _.map(_.toPairs(boards), ([boardUri, refs]) => { return new Report({ ip : ip,
const map = new Map(_.toPairs({'Sally': '1000', 'Joe': 500})); expect(s.isValid('::scores', map)).to.be.false; });
_.flow([ _.toPairs, pairs => _.filter(pairs, ([, value]) => value.isForbidden()), pairs => _.map(pairs, p => p[0]) ])
_.flow( _.toPairs, pairs => _.filter(pairs, ([, value]) => value.isOptional()), pairs => _.map(pairs, p => p[0]) )