mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 20:44:30 +08:00
41 lines
916 B
JavaScript
41 lines
916 B
JavaScript
const Joi = require('joi');
|
|
|
|
function replacer(key, value) {
|
|
// force remove any disallowed keys here
|
|
return value;
|
|
}
|
|
|
|
function jsonSchema(modelName) {
|
|
const models = ['Message', 'Thread', 'File', 'Error', 'SyncbackRequest']
|
|
if (models.includes(modelName)) {
|
|
return Joi.object();
|
|
}
|
|
if (modelName === 'Account') {
|
|
return Joi.object().keys({
|
|
id: Joi.number(),
|
|
object: Joi.string(),
|
|
email_address: Joi.string(),
|
|
connection_settings: Joi.object(),
|
|
sync_policy: Joi.object(),
|
|
sync_error: Joi.object(),
|
|
})
|
|
}
|
|
if (modelName === 'Category') {
|
|
return Joi.object().keys({
|
|
id: Joi.number(),
|
|
object: Joi.string(),
|
|
name: Joi.string().allow(null),
|
|
display_name: Joi.string(),
|
|
})
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function jsonStringify(models) {
|
|
return JSON.stringify(models, replacer, 2);
|
|
}
|
|
|
|
module.exports = {
|
|
jsonSchema,
|
|
jsonStringify,
|
|
}
|