@pipedrive/joi-schema

1.0.1 • Public • Published

joi-schema

Schema class to use with Joi validation - provides use cases for database records with different create/update strategies

Example usage

const Schema = require('@pipedrive/joi-schema');
const Joi = require('@hapi/joi');

const validatePostHelloCouchDb = new Schema({
    dataSchema:{
        _id: Joi.string().required(),
        _rev: Joi.string().required(),
        hello: Joi.string().allow('').optional(),
        goodbye: Joi.string().allow('').optional(),
    },
    createIgnoreKeys: ['_id', '_rev'], // keys to be stripped on getCreateData() call
    updateIgnoreKeys: ['_id'], // keys to be stripped on getUpdateData() call
    bulkUpdateIgnoreKeys: [], // keys to be stripped on getBulkUpdateData() call
    xor: ['hello', 'goodbye'] // validation checks that one and only one of the xor keys is present
});

const validatedData = await validatePostHelloCouchDb.getCreateData({
        _id: '123',
        _rev: '321',
        hello: 'Hello World',
        nonsense: 'Foo',
});
console.log(JSON.stringify(validatedData));
//{hello:  'Hello World'}

/@pipedrive/joi-schema/

    Package Sidebar

    Install

    npm i @pipedrive/joi-schema

    Weekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.46 kB

    Total Files

    7

    Last publish

    Collaborators

    • pipedrive-github-publish-bot
    • pipedrive-inc
    • pipedrive-publish-bot