How to use the @hapi/joi.function function in @hapi/joi

To help you get started, we’ve selected a few @hapi/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 hapijs / hapi / lib / config.js View on Github external
.unknown()
        .default(),
    mime: Joi.object().allow(null).default(null),
    operations: Joi.object({
        cleanStop: Joi.boolean().default(true)
    })
        .default(),
    plugins: Joi.object(),
    port: Joi.alternatives([
        Joi.number().integer().min(0),          // TCP port
        Joi.string().pattern(/\//),               // Unix domain socket
        Joi.string().pattern(/^\\\\\.\\pipe\\/)   // Windows named pipe
    ])
        .allow(null),
    query: Joi.object({
        parser: Joi.function()
    })
        .default(),
    router: Joi.object({
        isCaseSensitive: Joi.boolean().default(true),
        stripTrailingSlash: Joi.boolean().default(false)
    })
        .default(),
    routes: internals.routeBase.default(),
    state: Joi.object(),                                    // Cookie defaults
    tls: Joi.alternatives([
        Joi.object().allow(null),
        Joi.boolean()
    ]),
    uri: Joi.string().pattern(/[^/]$/)
});
github hapijs / nes / lib / index.js View on Github external
},
        headers: null,
        payload: {
            maxChunkChars: false
        },
        heartbeat: {
            interval: 15000,                                // 15 seconds
            timeout: 5000                                   // 5 seconds
        },
        maxConnections: false
    }
};


internals.schema = Joi.object({
    onConnection: Joi.function(),                               // async function (socket) {}
    onDisconnection: Joi.function(),                            // function (socket) {}
    onMessage: Joi.function(),                                  // async function (socket, message) { return data; }    // Or throw errors
    auth: Joi.object({
        endpoint: Joi.string().required(),
        id: Joi.string(),
        type: Joi.valid('cookie', 'token', 'direct').required(),
        route: [
            Joi.object(),
            Joi.string()
        ],
        cookie: Joi.string().required(),
        isSecure: Joi.boolean(),
        isHttpOnly: Joi.boolean(),
        isSameSite: Joi.valid('Strict', 'Lax').allow(false),
        path: Joi.string().allow(null),
        domain: Joi.string().allow(null),
github hapijs / hapi / lib / config.js View on Github external
rules: Joi.object(),
    vhost: internals.vhost,

    // Validated in route construction

    handler: Joi.any(),
    options: Joi.any(),
    config: Joi.any()               // Backwards compatibility
})
    .without('config', 'options');


internals.pre = [
    Joi.function(),
    Joi.object({
        method: Joi.alternatives(Joi.string(), Joi.function()).required(),
        assign: Joi.string(),
        mode: Joi.valid('serial', 'parallel'),
        failAction: internals.failAction
    })
];


internals.routeConfig = internals.routeBase.keys({
    description: Joi.string(),
    id: Joi.string(),
    isInternal: Joi.boolean(),
    notes: [
        Joi.string(),
        Joi.array().items(Joi.string())
    ],
    pre: Joi.array().items(...internals.pre.concat(Joi.array().items(...internals.pre).min(1))),
github ExpediaGroup / service-client / lib / schema.js View on Github external
See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict'

const Http = require('http')
const Https = require('https')
const Tls = require('tls')
const Hoek = require('@hapi/hoek')
const Joi = require('@hapi/joi')

const createSchema = Joi.object({
  // requests
  protocol: Joi.string().valid('http:', 'https:'),
  hostname: Joi.alternatives().try(Joi.string(), Joi.function()).required(),
  regions: Joi.array().items(Joi.string()),
  port: Joi.number(),
  basePath: Joi.string().default('/').pattern(/\/$/),

  // resiliency
  connectTimeout: Joi.number(),
  maxConnectRetry: Joi.number(),
  timeout: Joi.number(),
  maxFailures: Joi.number(), // circuit breaking
  resetTime: Joi.number(), // circuit breaking

  // agent options
  agent: Joi.alternatives([
    Joi.object().instance(Http.Agent),
    Joi.object().instance(Https.Agent)
  ]),
github koopjs / koop-core / src / index.js View on Github external
const DatasetController = require('./controllers/dataset')
const Dataset = require('./models/dataset')
const helpers = require('./helpers')
const middleware = require('./middleware')
const Events = require('events')
const Util = require('util')
const path = require('path')
const geoservices = require('koop-output-geoservices')
const LocalFS = require('koop-localfs')
const chalk = require('chalk')
const Table = require('easy-table')

const providerOptionsSchema = Joi.object({
  cache: Joi.object().keys({
    retrieve: Joi.function().arity(3).required(),
    upsert: Joi.function().arity(3).required()
  }).unknown(true).optional(),
  routePrefix: Joi.string().optional()
}).unknown(true)

function Koop (config) {
  this.version = pkg.version
  this.config = config || require('config')
  this.server = initServer(this.config)

  // default to LocalDB cache
  // cache registration overrides this
  this.cache = new Cache()
  this.log = new Logger(this.config)
  this.pluginRoutes = []
  this.register(geoservices)
  this.register(LocalFS)
github hapijs / hapi / lib / config.js View on Github external
internals.cache = Joi.array().items(internals.cacheConfig).min(1).single();


internals.cachePolicy = Joi.object({
    cache: Joi.string().allow(null).allow(''),
    segment: Joi.string(),
    shared: Joi.boolean()
})
    .unknown();                     // Catbox policy validates other keys


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


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


internals.register = Joi.object({
    once: true,
    routes: Joi.object({
        prefix: Joi.string().pattern(/^\/.+/),
        vhost: internals.vhost
github hapijs / hapi / lib / config.js View on Github external
mode: Joi.valid('required', 'optional', 'try'),
        strategy: Joi.string(),
        strategies: Joi.array().items(Joi.string()).min(1),
        access: Joi.array().items(internals.access.min(1)).single().min(1),
        payload: [
            Joi.valid('required', 'optional'),
            Joi.boolean()
        ]
    })
        .without('strategy', 'strategies')
        .without('access', ['scope', 'entity'])
]);


internals.event = Joi.object({
    method: Joi.array().items(Joi.function()).single(),
    options: Joi.object({
        before: Joi.array().items(Joi.string()).single(),
        after: Joi.array().items(Joi.string()).single(),
        bind: Joi.any(),
        sandbox: Joi.valid('server', 'plugin'),
        timeout: Joi.number().integer().min(1)
    })
        .default({})
});


internals.exts = Joi.array().items(internals.event.keys({ type: Joi.string().required() })).single();


internals.failAction = Joi.alternatives([
    Joi.valid('error', 'log', 'ignore'),
github ExpediaGroup / steerage / lib / index.js View on Github external
**/

'use strict';

const Pkg = require('../package.json');
const Plugins = require('./plugins');
const Config = require('./config');
const Path = require('path');
const Joi = require('@hapi/joi');
const Props = require('dot-prop');
const Hapi = require('@hapi/hapi');

const schema = Joi.object({
    basedir: Joi.string().allow(null),
    config: Joi.string().required(),
    onconfig: Joi.function().allow(null),
    protocols: Joi.object().default(),
    environment: Joi.object().default({ env: process.env })
}).required();

const init = async function (options) {

    const { config, basedir = Path.dirname(config), onconfig, protocols, environment } = await schema.validateAsync(options);

    const resolved = await Config.resolve({ basedir, config, protocols, environment });

    const store = await (onconfig ? onconfig(resolved) : Promise.resolve(resolved));

    const steerage = {
        name: Pkg.name,

        version: Pkg.version,
github felixheck / laabr / src / validator.js View on Github external
*/
const validators = {
  formatLabel: joi.string().valid('log', 'request', 'response', 'request-error', 'onPostStart', 'onPostStop', 'uncaught'),
  tokenLabel: joi.string(),
  format: joi.alternatives().try(joi.string(), joi.any().valid(false)),
  token: joi.function().maxArity(3),
  preformatterOutput: joi.object(),
  postformatterOutput: joi.string(),
  options: joi.object({
    formats: joi.object().allow(null),
    presets: joi.object().allow(null),
    tokens: joi.object().allow(null),
    colored: joi.boolean().default(false),
    override: joi.boolean().default(false),
    indent: joi.alternatives().try(joi.number(), joi.string()).allow('').default(2),
    preformatter: joi.function().maxArity(2),
    postformatter: joi.function().maxArity(2),
    handleUncaught: joi.boolean().default(false),
    stream: joi.object().allow(null),
    hapiPino: joi.object({
      stream: joi.object().allow(null),
      prettyPrint: joi.boolean(),
      tags: joi.object(),
      allTags: joi.string(),
      instance: joi.object(),
      logEvents: joi.alternatives().try(joi.array().items(joi.string()), joi.any().allow(false, null)),
      mergeHapiLogData: joi.boolean().default(false),
      serializers: joi.object(),
      logRouteTags: joi.boolean(),
      ignorePaths: joi.array().items(joi.string()),
      logPayload: joi.boolean().default(true),
      level: joi.string()
github hapijs / hapi / lib / config.js View on Github external
defaultContentType: Joi.string().default('application/json'),
        compression: Joi.object()
            .pattern(/.+/, Joi.object())
            .default()
    })
        .default(),
    plugins: Joi.object(),
    response: Joi.object({
        disconnectStatusCode: Joi.number().integer().min(400).default(499),
        emptyStatusCode: Joi.valid(200, 204).default(204),
        failAction: internals.failAction,
        modify: Joi.boolean(),
        options: Joi.object(),
        ranges: Joi.boolean().default(true),
        sample: Joi.number().min(0).max(100).when('modify', { then: Joi.forbidden() }),
        schema: Joi.alternatives(Joi.object(), Joi.array(), Joi.function()).allow(true, false),
        status: Joi.object().pattern(/\d\d\d/, Joi.alternatives(Joi.object(), Joi.array(), Joi.function()).allow(true, false))
    })
        .default(),
    security: Joi.object({
        hsts: Joi.alternatives([
            Joi.object({
                maxAge: Joi.number(),
                includeSubdomains: Joi.boolean(),
                includeSubDomains: Joi.boolean(),
                preload: Joi.boolean()
            }),
            Joi.boolean(),
            Joi.number()
        ])
            .default(15768000),
        xframe: Joi.alternatives([