Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return (test, exec) => {
Joi.assert(test, Joi.object().required(), 'Tape test object');
Joi.assert(exec, Joi.object().required(), 'Result of an exec() call');
const {root} = exec;
const directory = subdir ?
compose(normalize, join)(root, (typeof subdir === 'function') ? subdir(exec) : subdir) :
root;
return listDir(directory)
.then((list) => ext ? list.filter((v) => v.endsWith(`.${ext}`)) : list)
.then((list) => next(test, exec, list));
};
};
Vehicle.prototype.trips = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ limit: 20 }, _options || {});
Joi.assert(_options, Utils.streamPaginationOptions);
return client.get(
'trip',
'vehicles/' + this.id + '/trips',
_options).then(function(resp) {
resp.trips = resp.trips.map(function(v) { return new client.Trip(v); });
return Utils.streamListResponse(resp, 'trips', self.trips, self);
});
};
info.build = function(options) {
var out = options.info ? Hoek.applyToDefaults(info.defaults, options.info) : info.defaults;
Joi.assert(out, info.schema);
return out;
};
async get(url, start=0, end=1, full=false) {
Joi.assert(url, Joi.string().required(), 'must pass url');
debug('get', url, start, end);
let pushUrl = urljoin(url, '/json-pushes/');
let query = { version: 2, startID: start, endID: end };
if (full) {
query.full = 1;
}
let req = request.
get(pushUrl).
agent(this.selectAgent(url)).
query(query);
let res = await req;
if (res.error) throw res.error;
return this.formatBody(res.body);
Device.prototype.rules = function(_options) {
var self = this;
_options = Hoek.applyToDefaults({ offset: 0, limit: 20 }, _options || {});
Joi.assert(_options, Utils.paginationOptions);
return client.get(
'rule',
'devices/' + this.id + '/rules',
_options).then(function(resp) {
resp.rules = resp.rules.map(function(v) { return new client.Rule(v); });
return Utils.listResponse(resp, 'rules', self.rules, self);
});
};
async function insertSubjectVersion(params) {
Joi.assert(params, subjectSchema.requiredKeys(Object.keys(params)))
const query = `
INSERT INTO subjects
( entity_id , previous_id , name , user_id ,
body , members )
VALUES
($entity_id, $previous_id, $name, $user_id,
$body, $members)
RETURNING *;
`
const data = await db.save(query, params)
await sendSubjectToEs(data)
return data
}
async remove(id) {
Joi.assert(id, Joi.string(), 'must provide string');
let { deletedCount } = await this.collection.deleteOne({
id
});
return deletedCount;
}
}
validate: (url: string) => {
Joi.assert(
url,
Joi.string().uri({
scheme: ["redis"],
})
);
},
});
async function updateUserPassword({ id, password: plainPassword }) {
Joi.assert(plainPassword, plainPasswordSchema)
const params = {
id,
password: await bcrypt.hash(plainPassword, SALT_ROUNDS),
}
Joi.assert(params, userSchema.requiredKeys(Object.keys(params)))
const query = `
UPDATE users
SET password = $password
WHERE id = $id
RETURNING *;
`
const user = await db.save(query, params)
return user
}
constructor(appId, restApiKey) {
Joi.assert(appId, Joi.string().guid().required(), new Error('`appId` is required'));
Joi.assert(restApiKey, Joi.string().required(), new Error('`restApiKey` is required'));
this.appId = appId;
this.restApiKey = restApiKey;
}