forest-express
Version:
Official package for all Forest Express Lianas
109 lines (108 loc) • 4.77 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var ConfigStore = /*#__PURE__*/function () {
function ConfigStore(_ref) {
var logger = _ref.logger,
fs = _ref.fs,
path = _ref.path,
projectDirectoryFinder = _ref.projectDirectoryFinder;
(0, _classCallCheck2["default"])(this, ConfigStore);
this.Implementation = null;
this.lianaOptions = null;
this.integrator = null;
this.logger = logger;
this.fs = fs;
this.path = path;
this.projectDirectoryFinder = projectDirectoryFinder;
}
(0, _createClass2["default"])(ConfigStore, [{
key: "configDir",
get: function get() {
if (!this.lianaOptions) return null;
var configDir = this.lianaOptions.configDir;
if (configDir) {
return this.path.resolve('.', "".concat(configDir));
}
return this.path.resolve('.', 'forest');
}
}, {
key: "schemaDir",
get: function get() {
var _this$lianaOptions;
var schemaDir = (_this$lianaOptions = this.lianaOptions) === null || _this$lianaOptions === void 0 ? void 0 : _this$lianaOptions.schemaDir;
if (schemaDir) {
return this.path.resolve('.', "".concat(schemaDir));
}
return this.path.resolve('.', this.projectDirectoryFinder.getAbsolutePath());
}
}, {
key: "doesConfigDirExist",
value: function doesConfigDirExist() {
return this.fs.existsSync(this.configDir);
}
}, {
key: "doesSchemaDirExist",
value: function doesSchemaDirExist() {
return this.fs.existsSync(this.schemaDir);
}
}, {
key: "doesConnectionsHaveModels",
value: function doesConnectionsHaveModels() {
return Object.values(this.lianaOptions.connections).some(function (_ref2) {
var models = _ref2.models;
return Object.keys(models).length;
});
}
}, {
key: "validateOptions",
value: function validateOptions() {
var options = this.lianaOptions;
if (!options) {
throw new Error('Liana options cannot be null.');
}
if (options.secretKey && !options.envSecret || options.authKey && !options.authSecret) {
throw new Error('secretKey and authKey options are not supported anymore. Please use envSecret and authSecret instead.');
}
if (!options.authSecret) {
throw new Error('Your authSecret appears to be missing. Please check it is correctly set in your .env file.');
}
if (!options.envSecret) {
throw new Error('Your envSecret appears to be missing. Please check it is correctly set in your .env file.');
}
if (options.envSecret.length !== 64) {
throw new Error('Your envSecret seems incorrect (64 characters required). Please check it is correctly set in your .env file.');
}
if (!options.connections || !options.connections.constructor.toString().match('Object')) {
throw new Error('The connections option seems incorrectly set. Please check it is an object of named connections.');
}
if (!this.doesConnectionsHaveModels()) {
this.logger.warn('Your connections do not seem to have any models. Please check if your connections import your models.');
}
if (options.includedModels && !Array.isArray(options.includedModels)) {
throw new Error('The includedModels option seems incorrectly set. Please check it is an array of model names.');
}
if (options.excludedModels && !Array.isArray(options.excludedModels)) {
throw new Error('The excludedModels option seems incorrectly set. Please check it is an array of model names.');
}
if (!this.doesConfigDirExist()) {
this.logger.warn("Your configDir (\"".concat(this.configDir, "\") does not exist. Please make sure it is set correctly."));
}
if (!this.doesSchemaDirExist()) {
throw new Error("Your schemaDir (\"".concat(this.schemaDir, "\") does not exist. Please make sure it is set correctly."));
}
if (options.onlyCrudModule) {
this.logger.warn('onlyCrudModule is not supported anymore. Please remove this option.');
}
if (options.modelsDir) {
this.logger.warn('modelsDir is not supported anymore. Please remove this option.');
}
if (options.includedModels && options.excludedModels) {
this.logger.warn('includedModels and excludedModels options cannot be used simultaneously. Only the includedModels option will be taken into account.');
}
}
}]);
return ConfigStore;
}();
module.exports = ConfigStore;