Mailspring/packages/nylas-api/serialization.js

39 lines
809 B
JavaScript
Raw Normal View History

2016-06-19 18:02:32 +08:00
const Joi = require('joi');
function replacer(key, value) {
// force remove any disallowed keys here
return value;
}
function jsonSchema(modelName) {
2016-06-29 04:55:00 +08:00
const models = ['Message', 'Thread', 'File', 'Error']
if (models.includes(modelName)) {
return Joi.object();
}
2016-06-19 18:02:32 +08:00
if (modelName === 'Account') {
return Joi.object().keys({
id: Joi.number(),
email_address: Joi.string(),
2016-06-23 05:17:45 +08:00
connection_settings: Joi.object(),
sync_policy: Joi.object(),
})
}
if (modelName === 'Category') {
return Joi.object().keys({
id: Joi.number(),
name: Joi.string().allow(null),
display_name: Joi.string(),
2016-06-19 18:02:32 +08:00
})
}
return null;
}
function jsonStringify(models) {
return JSON.stringify(models, replacer, 2);
}
module.exports = {
jsonSchema,
jsonStringify,
}