2016-10-04 16:31:52 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schema general dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Public node modules
|
2017-01-17 11:51:10 +01:00
|
|
|
const _ = require('lodash');
|
|
|
|
const validator = require('validator');
|
2016-10-04 16:31:52 +02:00
|
|
|
|
2017-01-17 11:51:10 +01:00
|
|
|
const SchemaDatabases = function(app) {
|
|
|
|
const schema = {
|
2016-10-04 16:31:52 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-17 11:51:10 +01:00
|
|
|
const schemaExtend = {
|
2016-10-04 16:31:52 +02:00
|
|
|
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;
|