"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PlatformTools_1 = require("../../platform/PlatformTools");
var OrmUtils_1 = require("../../util/OrmUtils");
/**
 * Reads connection options from environment variables.
 * Environment variables can have only a single connection.
 * Its strongly required to define TYPEORM_CONNECTION env variable.
 */
var ConnectionOptionsEnvReader = (function () {
    function ConnectionOptionsEnvReader() {
    }
    // -------------------------------------------------------------------------
    // Public Methods
    // -------------------------------------------------------------------------
    /**
     * Reads connection options from environment variables.
     */
    ConnectionOptionsEnvReader.prototype.read = function () {
        return {
            type: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_CONNECTION"),
            url: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_URL"),
            host: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_HOST"),
            port: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_PORT"),
            username: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_USERNAME"),
            password: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_PASSWORD"),
            database: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_DATABASE"),
            sid: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_SID"),
            extra: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA") ? JSON.parse(PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA")) : undefined,
            autoSchemaSync: OrmUtils_1.OrmUtils.toBoolean(PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_AUTO_SCHEMA_SYNC")),
            entities: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_ENTITIES") ? PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_ENTITIES").split(",") : [],
            subscribers: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS") ? PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS").split(",") : [],
            entitySchemas: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_ENTITY_SCHEMAS") ? PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_ENTITY_SCHEMAS").split(",") : [],
            logging: {
                logQueries: OrmUtils_1.OrmUtils.toBoolean(PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_LOGGING_QUERIES")),
                logFailedQueryError: OrmUtils_1.OrmUtils.toBoolean(PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_LOGGING_FAILED_QUERIES")),
                logOnlyFailedQueries: OrmUtils_1.OrmUtils.toBoolean(PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_LOGGING_ONLY_FAILED_QUERIES")),
            },
            cli: {
                entitiesDir: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_ENTITIES_DIR"),
                migrationsDir: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_DIR"),
                subscribersDir: PlatformTools_1.PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS_DIR"),
            }
        };
    };
    return ConnectionOptionsEnvReader;
}());
exports.ConnectionOptionsEnvReader = ConnectionOptionsEnvReader;

//# sourceMappingURL=ConnectionOptionsEnvReader.js.map
