"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Connection configuration.
 */
var Connection = /** @class */ (function () {
    function Connection(conn) {
        this.loadFromObject(conn);
    }
    /**
     * Parse connection string into object.
     *
     * @param name Connection name.
     * @param connString Connection string to parse.
     */
    Connection.prototype.loadFromString = function (name, connString) {
        var parts = connString.split(';');
        // match connection parts
        var server = parts.find(function (x) { return /^(server)/ig.test(x); });
        var database = parts.find(function (x) { return /^(database)/ig.test(x); });
        var user = parts.find(function (x) { return /^(uid)/ig.test(x); });
        var password = parts.find(function (x) { return /^(password|pwd)/ig.test(x); });
        var port;
        // get values
        server = (server && server.split('=')[1]);
        database = (database && database.split('=')[1]);
        user = (user && user.split('=')[1]);
        password = (password && password.split('=')[1]);
        // separate server and port
        if (server) {
            // format: `dev.example.com\instance,1435`
            var sub = server.split(',');
            server = sub[0];
            port = parseInt(sub[1], 10) || undefined;
        }
        Object.assign(this, {
            name: name,
            server: server,
            database: database,
            port: port,
            user: user,
            password: password
        });
    };
    /**
     * Load connection object.
     *
     * @param conn Connection object to load.
     */
    Connection.prototype.loadFromObject = function (conn) {
        if (!conn) {
            return;
        }
        Object.assign(this, conn);
    };
    return Connection;
}());
exports.default = Connection;
//# sourceMappingURL=connection.js.map