Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(// The row may have been deleted between the get and now
old_row.eq(null),
r.error(writes.missing_msg),
// The row may have been changed between the get and now
r.and(new_row.hasFields(hz_v),
old_row(hz_v).default(-1).ne(new_row(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise, we can safely replace the row
writes.apply_version(new_row, old_row(hz_v).default(-1).add(1))),
{ returnChanges: 'always' }))
collection.table.get(info('id')).replace((row) =>
r.branch(// The row may have been deleted between the get and now
row.eq(null),
null,
// The row may have been changed between the get and now
r.and(info.hasFields(hz_v),
row(hz_v).default(-1).ne(info(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise, we can safely remove the row
null),
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(// The row may have been deleted between the get and now
old_row.eq(null),
r.error(writes.missing_msg),
// The row may have been changed between the get and now
r.and(new_row.hasFields(hz_v),
old_row(hz_v).default(-1).ne(new_row(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise, we can safely replace the row
writes.apply_version(new_row, old_row(hz_v).default(-1).add(1))),
{ returnChanges: 'always' }))
return Promise.resolve().then(() => {
const key = this.auth_key(provider, info);
const db = r.db(this._parent._name);
const insert = (table, row) =>
db.table(table)
.insert(row, { conflict: 'error', returnChanges: 'always' })
.bracket('changes')(0)('new_val');
let query = db.table('users')
.get(db.table('hz_users_auth').get(key)('user_id'))
.default(r.error('User not found and new user creation is disabled.'));
if (this._create_new_users) {
query = insert('hz_users_auth', { id: key, user_id: r.uuid() })
.do((auth_user) => insert('users', this.new_user_row(auth_user('user_id'))));
}
return query.run(this._parent._reql_conn.connection()).catch((err) => {
// TODO: if we got a `Duplicate primary key` error, it was likely a race condition
// and we should succeed if we try again.
logger.debug(`Failed user lookup or creation: ${err}`);
throw new Error('User lookup or creation in database failed.');
});
}).then((user) =>
this._jwt.sign({ id: user.id, provider })
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(// The row may have been deleted between the get and now
old_row.eq(null),
r.error(writes.missing_msg),
// The row may have been changed between the get and now
r.and(new_row.hasFields(hz_v),
old_row(hz_v).default(-1).ne(new_row(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise we can safely update the row and increment the version
writes.apply_version(old_row.merge(new_row), old_row(hz_v).default(-1).add(1))),
{ returnChanges: 'always' }))
collection.table.get(new_row('id')).replace((old_row) =>
r.branch(// The row may have been deleted between the get and now
old_row.eq(null),
r.error(writes.missing_msg),
// The row may have been changed between the get and now
r.and(new_row.hasFields(hz_v),
old_row(hz_v).default(-1).ne(new_row(hz_v))),
r.error(writes.invalidated_msg),
// Otherwise, we can safely replace the row
writes.apply_version(new_row, old_row(hz_v).default(-1).add(1))),
{ returnChanges: 'always' }))
reql.get(row('id')).replace((old) =>
r.branch(old.ne(null), old.merge(row),
r.error(r.expr("The document with id '")
.add(row('id').coerceTo('string'))
.add("' was missing.")))));
} else if (conflict === 'replace') {
r.db(db).table('hz_collections').get(name).replace({ id: name }).do((res) =>
r.branch(
res('errors').ne(0),
r.error(res('first_error')),
res('inserted').eq(1),
r.db(db).tableCreate(name),
res
)
).run(conn)
.do((res) =>
r.branch(res('new_val').eq(null),
r.error(res('error')),
res('new_val'))).run(this._conn),
r.db(this._db).table('hz_groups').get('admin')