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'],
updateIgnoreKeys: ['_id'],
bulkUpdateIgnoreKeys: [],
xor: ['hello', 'goodbye']
});
const validatedData = await validatePostHelloCouchDb.getCreateData({
_id: '123',
_rev: '321',
hello: 'Hello World',
nonsense: 'Foo',
});
console.log(JSON.stringify(validatedData));