How to use the joi.ref 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 contentful / contentful-migration / lib / migration-payloads / validation / schema-validation.js View on Github external
};

const itemsValid = Joi.object().keys({
  type: Joi.valid('Symbol', 'Link').required(),
  linkType: enforceDependency({
    valid: Joi.valid('Asset', 'Entry'),
    when: 'type',
    is: 'Link'
  }),
  validations: Joi.array().unique().items(fieldValidations)
});

const fieldSchema = Joi.object().keys({
  id: Joi.string().required(),
  newId: Joi.string()
    .invalid(Joi.ref('id'))
    .max(64)
    // the empty case will be caught by joi by default, we don't want duplicate errors
    .regex(/^$|^[a-zA-Z][a-zA-Z0-9_]*$/),
  name: Joi.string().required(),
  type: Joi.valid(
    'Symbol',
    'Text',
    'Integer',
    'Number',
    'Date',
    'Boolean',
    'Object',
    'Link',
    'Array',
    'Location'
  ).required(),
github bleupen / halacious / lib / plugin.js View on Github external
};

// valid namespace options
    internals.nsSchema = {
        // the namespace name, will default to dir basename if available
        name: joi.string()
            .required(),

        // a path to a directory containing rel descriptors. all rels will automatically be added
        dir: joi.string()
            .optional(),

        // the namespace prefix for shorthand rel addressing (e.g. 'prefix:relname')
        prefix: joi.string()
            .optional()
            .default(joi.ref('name')),

        // a short description
        description: joi.string()
            .optional(),

        // a map of rel objects, keyed by name
        rels: joi.object()
            .optional(),

        // validates and adds a rel to the namespace
        rel: joi.func()
            .optional()
            .default(function (rel) {
                this.rels = this.rels || {};

                if (_.isString(rel)) rel = { name: rel };
github brave / browser-laptop / tools / lib / transactionHelpers.js View on Github external
submissionId: Joi.string().hex().length(32, 'hex').required(),
  submissionDate: Joi.date(),
  count: Joi.number().integer().min(0),

  /** credential:
    *  complicated JSON BLOB from anonize2, come back to this later
    **/
  credential: Joi.string(),

  /** surveyorIds:
   * an array of random 32-byte ids (base64-encoded).
   * length should equal sibling value `count`
   **/
  surveyorIds: Joi.array().items(Joi.string().length(32, 'base64')), // ideally something like .length(Joi.ref('count'))

  satoshis: Joi.ref('contribution.satoshis'),
  votes: Joi.ref('count'),
  ballots: Joi.object().pattern(VALID_HOSTNAME_REGEX, Joi.number().integer().min(0))
})

const validateTransaction = function (tx) {
  return Joi.validate(tx, transactionSchema)
}

const generateTransaction = function () {
  const count = Math.round(Math.random() * 100)

  const viewingId = generateViewingId()
  const surveyorId = generateSurveyorId()
  const contribution = generateContribution()
  const submissionStamp = generateSubmissionStamp()
  const submissionDate = new Date(submissionStamp)
github brave / browser-laptop / tools / lib / transactionHelpers.js View on Github external
submissionDate: Joi.date(),
  count: Joi.number().integer().min(0),

  /** credential:
    *  complicated JSON BLOB from anonize2, come back to this later
    **/
  credential: Joi.string(),

  /** surveyorIds:
   * an array of random 32-byte ids (base64-encoded).
   * length should equal sibling value `count`
   **/
  surveyorIds: Joi.array().items(Joi.string().length(32, 'base64')), // ideally something like .length(Joi.ref('count'))

  satoshis: Joi.ref('contribution.satoshis'),
  votes: Joi.ref('count'),
  ballots: Joi.object().pattern(VALID_HOSTNAME_REGEX, Joi.number().integer().min(0))
})

const validateTransaction = function (tx) {
  return Joi.validate(tx, transactionSchema)
}

const generateTransaction = function () {
  const count = Math.round(Math.random() * 100)

  const viewingId = generateViewingId()
  const surveyorId = generateSurveyorId()
  const contribution = generateContribution()
  const submissionStamp = generateSubmissionStamp()
  const submissionDate = new Date(submissionStamp)
  const submissionId = generateSubmissionId()
github contentful / contentful-migration / src / lib / offline-api / validator / schema / fields-schema.ts View on Github external
}

const itemsValid = Joi.object().keys({
  type: Joi.string().valid('Symbol', 'Link').required(),
  linkType: enforceDependency({
    valid: Joi.string().valid('Asset', 'Entry'),
    when: 'type',
    is: 'Link'
  }),
  validations: Joi.array().unique().items(fieldValidations)
})

const fieldSchema = Joi.object().keys({
  id: Joi.string().required(),
  newId: Joi.string()
    .invalid(Joi.ref('id'))
    .max(64)
    // the empty case will be caught by joi by default, we don't want duplicate errors
    .regex(/^$|^[a-zA-Z][a-zA-Z0-9_]*$/),
  name: Joi.string().required(),
  type: Joi.string().valid(
    'Symbol',
    'Text',
    'Integer',
    'Number',
    'Date',
    'Boolean',
    'Object',
    'Link',
    'Array',
    'Location',
    'RichText'
github elastic / kibana / x-pack / legacy / plugins / siem / server / lib / detection_engine / routes / update_signals_route.ts View on Github external
import { isFunction } from 'lodash/fp';
import { updateSignal } from '../alerts/update_signals';
import { UpdateSignalsRequest } from '../alerts/types';
import { updateSignalSchema } from './schemas';

export const createUpdateSignalsRoute: Hapi.ServerRoute = {
  method: 'PUT',
  path: '/api/siem/signals/{id?}',
  options: {
    tags: ['access:signals-all'],
    validate: {
      options: {
        abortEarly: false,
      },
      params: {
        id: Joi.when(Joi.ref('$payload.id'), {
          is: Joi.exist(),
          then: Joi.string().optional(),
          otherwise: Joi.string().required(),
        }),
      },
      payload: updateSignalSchema,
    },
  },
  async handler(request: UpdateSignalsRequest, headers) {
    const {
      description,
      enabled,
      false_positives: falsePositives,
      filter,
      from,
      immutable,
github nodemailer / mailcast / routes / account / index.js View on Github external
.email()
                .required(),
            token: Joi.string()
                .trim()
                .hex()
                .required(),
            password: Joi.string()
                .min(8)
                .max(256)
                .label('Password')
                .required(),
            password2: Joi.string()
                .min(8)
                .max(256)
                .label('Password confirmation')
                .valid(Joi.ref('password'))
                .options({
                    language: {
                        any: {
                            allowOnly: '!!Passwords do not match'
                        }
                    }
                })
                .required()
        });

        const result = Joi.validate(req.body, schema, {
            abortEarly: false,
            convert: true,
            stripUnknown: true
        });
github elastic / kibana / src / server / config / schema.js View on Github external
module.exports = () => Joi.object({
  pkg: Joi.object({
    version: Joi.string().default(Joi.ref('$version')),
    buildNum: Joi.number().default(Joi.ref('$buildNum')),
    buildSha: Joi.string().default(Joi.ref('$buildSha')),
  }).default(),

  env: Joi.object({
    name: Joi.string().default(Joi.ref('$env')),
    dev: Joi.boolean().default(Joi.ref('$dev')),
    prod: Joi.boolean().default(Joi.ref('$prod'))
  }).default(),

  pid: Joi.object({
    file: Joi.string(),
    exclusive: Joi.boolean().default(false)
  }).default(),

  server: Joi.object({
    host: Joi.string().hostname().default('0.0.0.0'),
github elastic / kibana / src / server / config / schema.js View on Github external
module.exports = () => Joi.object({
  pkg: Joi.object({
    version: Joi.string().default(Joi.ref('$version')),
    buildNum: Joi.number().default(Joi.ref('$buildNum')),
    buildSha: Joi.string().default(Joi.ref('$buildSha')),
  }).default(),

  env: Joi.object({
    name: Joi.string().default(Joi.ref('$env')),
    dev: Joi.boolean().default(Joi.ref('$dev')),
    prod: Joi.boolean().default(Joi.ref('$prod'))
  }).default(),

  pid: Joi.object({
    file: Joi.string(),
    exclusive: Joi.boolean().default(false)
  }).default(),

  server: Joi.object({
github daGrevis / msks / server / src / schemas.js View on Github external
const Promise = require('bluebird')
const Joi = require('joi')

const validate = Promise.promisify(Joi.validate)

const Channel = Joi.object().keys({
  name: Joi.string().required(),
  topic: Joi.string(),
})

const User = Joi.object().keys({
  id: Joi.array().required().items(Joi.ref('channel'), Joi.ref('nick')),
  channel: Joi.string().required(),
  nick: Joi.string().required(),
  isOp: Joi.boolean(),
  isVoiced: Joi.boolean(),
})

const Message = Joi.object().keys({
  kind: Joi.any().valid([
    'message',
    'notice',
    'action',
    'join',
    'quit',
    'part',
    'kick',
    'nick',