Aurélien Georget bd91a2ef93 Add 'packages/strapi-plugin-settings-manager/' from commit 'cd241c14c6a6239bca279e7accd709ba58e87cc8'
git-subtree-dir: packages/strapi-plugin-settings-manager
git-subtree-mainline: 80aa83d8460c95366547e143c74bf79ea6ae69f8
git-subtree-split: cd241c14c6a6239bca279e7accd709ba58e87cc8
2017-01-15 20:14:40 +01:00

138 lines
3.0 KiB
JavaScript

'use strict';
/**
* Schema general dependencies
*/
// Public node modules
var _ = require('lodash');
var validator = require('validator');
var SchemaDatabases = function(app) {
var schema = {
adapter: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
if (_.includes(['mongo', 'redis', 'arangodb', 'mysql', 'postgresql', 'sqlite', 'disk'], value)) {
return cb(null, value);
}
return cb('Unknow adapter', null);
}
},
name: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(_.deburr(value)));
}
},
host: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
if (validator.isURL(value) || validator.isIP(value)) {
return cb(null, value);
}
return cb('Invalid host', null);
}
},
port: {
type: 'integer',
path: null,
update: false
},
database: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(_.deburr(value)));
}
},
user: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(_.deburr(value)));
}
},
password: {
type: 'string',
path: null,
update: false
}
};
var schemaExtend = {
adapter: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
if (_.includes(['mongo', 'redis', 'arangodb', 'mysql', 'postgresql', 'sqlite', 'disk'], value)) {
return cb(null, value);
}
return cb('Unknow adapter', null);
}
},
name: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(_.deburr(value)));
}
},
host: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
if (validator.isURL(value) || validator.isIP(value)) {
return cb(null, value);
}
return cb('Invalid host', null);
}
},
database: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(_.deburr(value)));
}
},
filePath: {
type: 'string',
path: null,
update: false
},
fileName: {
type: 'string',
path: null,
update: false,
resolver: function(rootValue, value, scope, cb) {
return cb(null, _.trim(_.deburr(value)));
}
},
migrate: {
type: 'string',
path: null,
update: false
}
};
return (app.isExtend) ? schemaExtend : schema;
};
module.exports = SchemaDatabases;