How to use the joi.assert function in joi

To help you get started, we’ve selected a few joi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bholloway / resolve-url-loader / test / lib / higher-order.js View on Github external
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));
  };
};
github vinli / vinli-node / lib / vehicle.js View on Github external
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);
      });
  };
github glennjones / hapi-swagger / lib / info.js View on Github external
info.build = function(options) {
    var out = options.info ? Hoek.applyToDefaults(info.defaults, options.info) : info.defaults;
    Joi.assert(out, info.schema);
    return out;
};
github taskcluster / mozilla-taskcluster / src / pushlog / client.js View on Github external
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);
github vinli / vinli-node / lib / device.js View on Github external
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);
      });
  };
github sagefy / sagefy / server2 / database / subjects.js View on Github external
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
}
github taskcluster / mozilla-taskcluster / src / db.js View on Github external
async remove(id) {
    Joi.assert(id, Joi.string(), 'must provide string');
    let { deletedCount } = await this.collection.deleteOne({
      id
    });
    return deletedCount;
  }
}
github coralproject / talk / src / core / common / config.ts View on Github external
validate: (url: string) => {
    Joi.assert(
      url,
      Joi.string().uri({
        scheme: ["redis"],
      })
    );
  },
});
github sagefy / sagefy / server2 / database / users.js View on Github external
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
}
github scoutforpets / node-onesignal / lib / client.js View on Github external
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;
    }