How to use the @hapi/joi.assert 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 Saeris / graphql-scalars / src / positiveFloat.js View on Github external
const validate = value => {
  Joi.assert(value, Joi.any().invalid(Infinity, -Infinity), new TypeError(`Value is not a finite number: ${value}`))
  Joi.assert(value, Joi.number().required(), new TypeError(`Value is not a number: ${value}`))
  const parsed = parseFloat(value)
  Joi.assert(parsed, Joi.number().positive(), new TypeError(`Value is not a positive number: ${parsed}`))
  Joi.assert(parsed, Joi.number().greater(0), new TypeError(`Value is not greater than 0: ${parsed}`))
  return parsed
}
github omisego / omg-js / packages / omg-js-childchain / src / childchain.js View on Github external
async sendTransaction ({
    fromAddress,
    fromUtxos,
    fromPrivateKeys,
    payment,
    fee,
    metadata = null,
    verifyingContract
  }) {
    Joi.assert({
      fromAddress,
      fromUtxos,
      fromPrivateKeys,
      payment,
      fee,
      metadata,
      verifyingContract
    }, sendTransactionSchema)
    const txBody = transaction.createTransactionBody({
      fromAddress,
      fromUtxos,
      payment,
      fee,
      metadata
    })
    const typedData = transaction.getTypedData(txBody, verifyingContract)
github cjihrig / nuisance / lib / index.js View on Github external
server.auth.scheme('nuisance', function nuisanceScheme (server, options) {
    Joi.assert(options, schema);

    return {
      authenticate: async function (request, h) {
        const credentials = {};
        let scope = [];

        for (let i = 0; i < options.strategies.length; i++) {
          let strategy = options.strategies[i];
          let failureCredentials = null;

          if (typeof strategy === 'object') {
            failureCredentials = strategy.failureCredentials;
            strategy = strategy.name;
          }

          let creds = null;
github Saeris / graphql-scalars / src / nonPositiveInt.js View on Github external
const validate = value => {
  Joi.assert(value, Joi.any().invalid(Infinity, -Infinity), new TypeError(`Value is not a finite number: ${value}`))
  Joi.assert(value, Joi.number().required(), new TypeError(`Value is not a number: ${value}`))
  const parsed = parseInt(value, 10)
  Joi.assert(parsed, Joi.number().integer(), new TypeError(`Value is not an integer: ${parsed}`))
  Joi.assert(parsed, Joi.number().max(0), new TypeError(`Value is not a non-positive number: ${parsed}`))
  Joi.assert(parsed, Joi.number().negative().allow(0), new TypeError(`Value is not a negative number: ${parsed}`))
  return parsed
}
github Saeris / graphql-scalars / src / mac.js View on Github external
const validate = value => {
  Joi.assert(value, Joi.string(), new TypeError(`Value is not string: ${value}`))
  Joi.assert(value, Joi.string().regex(/^(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})(?:(?:\1|\.)(?:[0-9A-Fa-f]{2}([:-]?)[0-9A-Fa-f]{2})){2}$/),
    new TypeError(`Value is not a valid MAC address: ${value}`))
  return value
}
github badges / shields / core / base-service / base.js View on Github external
static validateDefinition() {
    assertValidCategory(this.category, `Category for ${this.name}`)

    assertValidRoute(this.route, `Route for ${this.name}`)

    Joi.assert(
      this.defaultBadgeData,
      defaultBadgeDataSchema,
      `Default badge data for ${this.name}`
    )

    this.examples.forEach((example, index) =>
      validateExample(example, index, this)
    )
  }
github omisego / omg-js / packages / omg-js-rootchain / src / rootchain.js View on Github external
async getInFlightExitId ({ txBytes }) {
    Joi.assert({ txBytes }, getInFlightExitIdSchema)
    const { contract } = await this.getPaymentExitGame()
    return contract.methods.getInFlightExitId(txBytes).call()
  }
github Saeris / graphql-scalars / src / rgba.js View on Github external
const validate = value => {
  Joi.assert(value, Joi.string(), new TypeError(`Value is not string: ${value}`))
  Joi.assert(value, Joi.string().regex(/^rgba\(\s*(-?\d+|-?\d*\.\d+(?=%))(%?)\s*,\s*(-?\d+|-?\d*\.\d+(?=%))(\2)\s*,\s*(-?\d+|-?\d*\.\d+(?=%))(\2)\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/),
    new TypeError(`Value is not a valid RGBA color: ${value}`))
  return value
}
github Saeris / graphql-scalars / src / hsla.js View on Github external
const validate = value => {
  Joi.assert(value, Joi.string(), new TypeError(`Value is not string: ${value}`))
  Joi.assert(value, Joi.string().regex(/^hsla\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)\s*\)$/),
    new TypeError(`Value is not a valid HSLA color: ${value}`))
  return value
}
github omisego / omg-js / packages / omg-js-rootchain / src / rootchain.js View on Github external
async getExitTime ({
    exitRequestBlockNumber,
    submissionBlockNumber,
    retries = 10
  }) {
    Joi.assert({ exitRequestBlockNumber, submissionBlockNumber }, getExitTimeSchema)
    const bufferSeconds = 5
    const retryInterval = 5000

    const _minExitPeriodSeconds = await this.plasmaContract.methods.minExitPeriod().call()
    const minExitPeriodSeconds = Number(_minExitPeriodSeconds)

    const exitBlock = await this.web3.eth.getBlock(exitRequestBlockNumber)
    if (!exitBlock) {
      if (retries > 0) {
        setTimeout(() => {
          return this.getExitTime({ exitRequestBlockNumber, submissionBlockNumber, retries: retries - 1 })
        }, retryInterval)
      } else {
        throw Error(`Could not get exit request block data: ${exitRequestBlockNumber}`)
      }
    }