@megaorm/cli
Version:
This package allows you to communicate with MegaORM via commands directly from the command line interface (CLI).
96 lines • 3.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MegaConfig = void 0;
const config_1 = require("@megaorm/config");
const test_1 = require("@megaorm/test");
const cluster_1 = require("@megaorm/cluster");
/**
* MegaConfig is a specialized configuration manager for the MegaORM system.
* It handles validation and defaulting for various configuration properties,
* including paths, TypeScript settings, and cluster details.
*
* The configuration includes:
* - Paths to project folders such as models, seeders, and commands.
* - Support for TypeScript projects with optional source and distribution folder configuration.
* - Integration with a `MegaCluster` instance for managing database connections.
*
* Default configurations are applied where necessary, and detailed error messages
* are provided for invalid or missing configurations.
*/
class MegaConfig extends config_1.Config {
}
exports.MegaConfig = MegaConfig;
/**
* The default name of the configuration file.
*/
MegaConfig.file = 'mega.config.js';
/**
* Ensures the configuration is an object before proceeding.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isObj)(config)) {
throw new config_1.ConfigError(`Invalid config: Expected an object but received ${typeof config}.`);
}
return config;
});
/**
* Ensures that `config.cluster` is an instance of `MegaCluster`.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isChildOf)(config.cluster, cluster_1.MegaCluster)) {
throw new config_1.ConfigError(`Invalid config.cluster: Expected an instance of MegaCluster but received ${typeof config.cluster}.`);
}
return config;
});
/**
* Ensures that `config.default` is a string.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isStr)(config.default)) {
throw new config_1.ConfigError(`Invalid config.default: Expected a valid default pool name but received ${typeof config.default}.`);
}
return config;
});
/**
* Ensures `config.paths` is an object.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isObj)(config.paths))
config.paths = {};
return config;
});
/**
* Set default values for the `paths` property in the configuration.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isStr)(config.paths.models))
config.paths.models = 'models';
if (!(0, test_1.isStr)(config.paths.seeders))
config.paths.seeders = 'seeders';
if (!(0, test_1.isStr)(config.paths.commands))
config.paths.commands = 'commands';
if (!(0, test_1.isStr)(config.paths.generators))
config.paths.generators = 'generators';
return config;
});
/**
* Ensures `config.typescript` is an object.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isObj)(config.typescript))
config.typescript = {};
return config;
});
/**
* Set default values for the `typescript` property in the configuration.
*/
MegaConfig.register((config) => {
if (!(0, test_1.isBool)(config.typescript.enabled))
config.typescript.enabled = false;
if (!(0, test_1.isStr)(config.typescript.src))
config.typescript.src = 'src';
if (!(0, test_1.isStr)(config.typescript.dist))
config.typescript.dist = 'dist';
return config;
});
//# sourceMappingURL=MegaConfig.js.map