How to use the joi.func 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 outmoded / mailback / lib / index.js View on Github external
const Joi = require('joi');
const MailParser = require('mailparser');
const SmtpServer = require('smtp-server');
const Teamwork = require('teamwork');
const Wreck = require('wreck');


// Declare internals

const internals = {};


internals.schema = Joi.object({
    host: Joi.string().default('0.0.0.0'),
    port: Joi.number().integer().min(0).default(0),
    onMessage: Joi.func().required(),
    smtp: Joi.object({
        onData: Joi.forbidden()
    })
        .unknown()
});


exports.Server = internals.Server = function (options) {

    options = Joi.attempt(options, internals.schema, 'Invalid server options');
    this._settings = Hoek.clone(options);
    this._settings.smtp = this._settings.smtp || {};
    this._settings.smtp.disabledCommands = this._settings.smtp.disabledCommands || ['AUTH'];
    this._settings.smtp.logger = (this._settings.smtp.logger !== undefined ? this._settings.smtp.logger : false);
    this._settings.smtp.onData = (stream, session, callback) => this._onMessage(stream, session, callback);
github ozum / joi18n / node_modules / hapi / lib / schema.js View on Github external
shared: Joi.boolean()
})
    .options({ allowUnknown: true });               // Catbox validates other keys


internals.method = Joi.object({
    bind: Joi.object().allow(null),
    generateKey: Joi.func(),
    cache: internals.cachePolicy,
    callback: Joi.boolean()
});


internals.methodObject = Joi.object({
    name: Joi.string().required(),
    method: Joi.func().required(),
    options: Joi.object()
});


internals.register = Joi.object({
    once: Joi.boolean(),
    routes: Joi.object({
        prefix: Joi.string().regex(/^\/.+/),
        vhost: internals.vhost
    })
        .default({}),
    select: Joi.array().items(Joi.string()).single()
});


internals.plugin = internals.register.keys({
github bentonam / fakeit / test / fixtures / models / flight-data / validation / airlines.model.js View on Github external
root: is.string(),
  is_dependency: is.boolean(),
  dependants: is.array(),
  key: '_id',
  seed: 0,
  data: {
    min: 0,
    max: 0,
    count: 1,
    dependencies: is.array().items(is.string()).length(1),
    inputs: is.array().items(is.string()).length(1),
    pre_run: is.func(),
    post_build: is.func(),
  },
  properties: {
    _id: utils.check('string', 'The document id', { post_build: is.func(), }),
    doc_type: utils.check('string', 'The document type', { value: is.string(), }),
    airline_id: utils.check('integer', 'The airlines id', { pre_build: is.func(), }),
    airline_name: utils.check('string', 'The name of the airline', { build: is.func(), }),
    airline_iata: utils.check('string', 'The airlines iata code if availabe, otherwise null', { build: is.func(), }),
    airline_icao: utils.check('string', 'The airlines icao code if available, otherwise null', { build: is.func(), }),
    callsign: utils.check('string', 'The airlines callsign if available', { build: is.func(), }),
    iso_country: utils.check('string', 'The ISO country code the airline is based in', { build: is.func(), }),
    active: utils.check('boolean', 'Whether or not the airline is active', { pre_build: is.func(), post_build: is.func(), }),
  },
});
github kutlerskaggs / json-api-ify / lib / util / validate-options.js View on Github external
module.exports = function validateOptions(options, cb) {
    let optionsSchema = joi.object({
        blacklist: joi.array().items(joi.string()).single().default([]),
        id: joi.alternatives().try(
            joi.string(),
            joi.func()
        ),
        processCollection: joi.func(),
        processResource: joi.func(),
        relationships: joi.object().pattern(/.+/, joi.object({
            type: joi.string().required(),
            include: joi.boolean().default(true)
        })).default({}).description('the relationships definition for this resource type'),
        topLevelLinks: joi.object().default({}),
        topLevelMeta: joi.object().default({}),
        whitelist: joi.array().items(joi.string()).single().default([])
    }).required();

    joi.validate(options, optionsSchema, {allowUnknown: true, convert: true}, function(err, validated) {
        if (err) {
            return cb(errors.generateError('1003', err.message, {error: err}));
        }
        cb(null, validated);
    });
};
github BigRoomStudios / schwifty-migrate-diff / lib / schema.js View on Github external
'use strict';

const Joi = require('joi');

exports.options = Joi.object({
    models: Joi.array().items(Joi.func().class()),
    migrationsDir: Joi.string().required(),
    knex: Joi.func().required(),
    mode: Joi.string().allow('create', 'alter').default('alter'),
    migrationName: Joi.string().required()
});
github bentonam / fakeit / packages / fakeit-core / src / api.js View on Github external
spacing: joi.alternatives()
      .try(
        joi
          .number()
          .min(0)
          .max(4),
        joi
          .string()
          .min(0)
          .max(4),
      ),
    count: joi.alternatives()
      .try(null, joi.number()
        .min(1)),
    output: joi.alternatives()
      .try(joi.func(), joi.string()),
    models: joi.array()
      .items(joi.string()),
    threads: joi
      .number()
      .min(1)
      .max(max_threads),
    limit: joi
      .number()
      .min(1)
      .max(1000),
    plugins: joi
      .alternatives()
      .try(
        null,
        joi.string(),
        joi.func(),
github ben-ng / gaggle / strategies / strategy-interface.js View on Github external
function StrategyInterface (opts) {
  var validatedOptions = Joi.validate(opts || {}, Joi.object().keys({
    logFunction: Joi.func().default(function noop () {})
  , strategyOptions: Joi.object()
  , channel: Joi.object()
  , id: Joi.string()
  }).requiredKeys('id'))

  if (validatedOptions.error != null) {
    throw new Error(prettifyJoiError(validatedOptions.error))
  }

  this.id = validatedOptions.value.id
  this._logFunction = validatedOptions.value.logFunction
  this._closed = false
}
github microsoft / pai / rest-server / src / config / redis.js View on Github external
},
  getStatsKeyPrefix: function(type) {
    return `marketplace:stats:${type}.`;
  },
  getStatsKey: function(type, name) {
    return this.getStatsKeyPrefix(type) + name;
  },
};

const redisConfigSchema = Joi.object().keys({
  connectionUrl: Joi.string()
    .required(),
  getUsedKey: Joi.func()
    .arity(1)
    .required(),
  getIndexKey: Joi.func()
    .arity(1)
    .required(),
  getTemplateKeyPrefix: Joi.func()
    .arity(1)
    .required(),
  getTemplateKey: Joi.func()
    .arity(2)
    .required(),
  getStatsKeyPrefix: Joi.func()
    .arity(1)
    .required(),
  getStatsKey: Joi.func()
    .arity(2)
    .required(),
});
github zodern / meteor-up / src / validate / index.js View on Github external
function generateSchema() {
  const topLevelKeys = {
    servers: joi.object(),
    app: joi.object(),
    plugins: joi.array(),
    _origionalConfig: joi.object(),
    hooks: joi.object().pattern(/.*/, joi.alternatives(joi.object({
      localCommand: joi.string(),
      remoteCommand: joi.string(),
      method: joi.func()
    }),
    joi.func()
    ))
  };

  Object.keys(_pluginValidators).forEach(key => {
    topLevelKeys[key] = joi.any();
  });

  return joi.object().keys(topLevelKeys);
}
github tableflip / guvnor / lib / operations / schema.js View on Github external
then: proc.required()
  },
  forceGc: {
    args: Joi.array().sparse().ordered(
      context.required(),
      Joi.string().label('script name').required()
    ),
    then: Joi.any().forbidden()
  },
  fetchHeapSnapshot: {
    args: Joi.array().sparse().ordered(
      context.required(),
      Joi.string().label('script name').required(),
      Joi.string().label('snapshot id').required(),
      Joi.func().label('on details callback').required(),
      Joi.func().label('on data callback').required()
    ),
    then: Joi.any().forbidden()
  },
  listHeapSnapshots: {
    args: Joi.array().sparse().ordered(
      context.required(),
      Joi.string().label('script name').required()
    ),
    then: Joi.array().items(heapSnapshot).label('snapshot list')
  },
  removeHeapSnapshot: {
    args: Joi.array().sparse().ordered(
      context.required(),
      Joi.string().label('script name').required(),
      Joi.string().label('snapshot id').required()
    ),