Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var now = Date.now() / 1000;
data = Object.assign({id: id}, data, {created: now, last_updated: now});
data.profile = data.profile ? Object.assign({}, data.profile) : null;
// normalize the authority_user_id and profile ID
if (data.id && data.id[1] && data.profile && typeof data.profile.id === 'undefined')
data.profile.id = data.id[1];
// validate data
var err = validate('credential', data, {useDefault: true});
if (err) throw new errors.ValidationError('A valid credential must be supplied.', err.validation);
if (data.profile && data.profile.id !== data.id[1]) throw new errors.ValidationError('If a profile ID is present, it must match the `authority_user_id`.');
if (!Array.isArray(data.id) || data.id.some((v,i) => v !== id[i])) throw new Error('The supplied `id` did not match the `id` in the data.');
// don't overwrite an existing `created` timestamp
data.created = r.row('created').default(data.created);
// save the model (use super.create when babel.js supports it)
return Model.save.call(this, conn, id, data);
}
r.connect({ port: proxyPort, db: dbName }).then((conn) => {
return r.table(tableName).filter(r.row('population').gt(500)).changes().run(conn)
.then(function (cursor) {
cursor.each(function (err, row) {
second_count += 1;
results.push(row);
}, conn.close.bind(conn));
});
})
])
r.connect({ port: proxyPort, db: dbName }).then((conn) => {
return r.table(tableName).filter(r.row('population').lt(500)).changes().run(conn)
.then(function (cursor) {
cursor.each(function (err, row) {
first_count += 1;
results.push(row);
}, conn.close.bind(conn));
});
}),
r.connect({ port: proxyPort, db: dbName }).then((conn) => {
Storage.prototype.watch = function(first_argument) {
var self = this
r.table('monitor').changes()('new_val').merge(function(doc) {
return {
website: r.db(self._db).table('website').get(doc('website_id')).default({}),
incident: r.db(self._db).table('incident').getAll(['open', doc('website_id')], {index: 'open_incident'}).default([]).nth(0).default(null)
}
})
.filter(r.row('duration').gt(r.row('website').getField('threshold').default(1000)))
.run(this._connection, function(err, cursor) {
if (err) {
console.log(err)
}
if (typeof cursor == 'undefined') {
return
}
cursor.each(function(err, row) {
if (err) {
console.log("!! Fail to get alert ", err)
} else {
self.emit('alertChange', row)
}
})
function subscribeToDrawingLines({ client, connection, drawingId, from }) {
let query = r.row('drawingId').eq(drawingId);
if (from) {
query = query.and(r.row('timestamp').ge(new Date(from)))
}
return r.table('lines')
.filter(query)
.changes({ include_initial: true, include_types: true })
.run(connection)
.then((cursor) => {
cursor.each((err, lineRow) => client.emit(`drawingLine:${drawingId}`, lineRow.new_val));
});
}
getStatus() {
return this.connection.run(
r.db('rethinkdb')
.table('table_status', { identifier_format: 'uuid' })
.get(this.id)
.merge(r.db(this.database.name).table(r.row('name')).info().without('db'))
.merge(table => {
return {
shards: table('shards').map(shard => {
return shard.merge({
replicas: shard('replicas').innerJoin(
r.db('rethinkdb')
.table('stats', { identifier_format: 'uuid' })
.filter(stat => stat('table').eq(table('id')).and(stat.hasFields('storage_engine')))
.without('id', 'table', 'db'),
(replicaRow, statRow) => {
return replicaRow('server').eq(statRow('server'));
}
).zip()
.eqJoin('server', r.db('rethinkdb').table('server_status', { identifier_format: 'uuid' }))
.zip()
.coerceTo('array')
r.connect(cOptions, function (err, conn) {
if (err) {
resolve(0)
} else {
r.table(jobType).filter((r.row('status').eq('waiting')).and(r.row('dateEnable').gt(r.now()))).count().run(conn, function (err, result) {
if (err) resolve(0)
resolve(result)
})
}
})
})
.then(info => connector.exec(db => {
let currentBlock = db.table('blk' + info.blockid);
let txns = db.table('transactions').orderBy({index: r.desc('Nonce')})
.filter(r.or(r.row('Status').eq(TransactionStatuses.FAILED),
r.row('Status').eq(TransactionStatuses.PENDING)))
.union(db.table('txn_list').orderBy({index: r.desc('Nonce')}));
let query = f(txns);
query = MERGE_FNS.valueSeq()
.map(mergeFnSpec => [_search(query, _mergePattern(mergeFnSpec.get('functions').keySeq())),
mergeFnSpec.get('functions')])
.map(([updateType, functions]) => functions.get(updateType))
.filter(f => !_.isNull(f) && _.isFunction(f))
.reduce((query, fn) => query.merge(fn(currentBlock)), query);
if(opts.secondaryQuery) {
query = query.filter(opts.secondaryQuery);
}