all files / handlers/ BaseHandler.js

100% Statements 18/18
100% Branches 6/6
100% Functions 4/4
100% Lines 18/18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                            38×   19×     18×                                          
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MysqlSchemaPreprocessor_1 = require("../preprocesors/MysqlSchemaPreprocessor");
var RamlSchemaPreprocessor_1 = require("../preprocesors/RamlSchemaPreprocessor");
/**
 * Base Handler.
 *
 * @export
 * @class BaseHandler
 */
var BaseHandler = (function () {
    function BaseHandler(driver) {
        this.driver = driver;
    }
    /**
     * Normalize column schema.
     *
     * @param {*} columnSchema sql column schema
     * @returns {*} normalized column schema
     */
    BaseHandler.prototype.normalizeColumnSchema = function (columnSchema) {
        switch (this.driver) {
            case 'mysql': {
                return (new MysqlSchemaPreprocessor_1.default()).convertToStandardSchema(columnSchema);
            }
            case 'raml': {
                return (new RamlSchemaPreprocessor_1.default()).convertToStandardSchema(columnSchema);
            }
            default: {
                throw new Error('Input source not not supported.');
            }
        }
    };
    /**
     * Normalize relations between tables inside the schema.
     *
     * @param {*} schema database schema
     * @returns {*} normalized database schema
     */
    BaseHandler.prototype.normalizeRelations = function (schema) {
        switch (this.driver) {
            case 'mysql': {
                return (new MysqlSchemaPreprocessor_1.default()).normalizeSchemaRelations(schema);
            }
            case 'raml': {
                return (new RamlSchemaPreprocessor_1.default()).normalizeSchemaRelations(schema);
            }
            default: {
                throw new Error('Input source not not supported.');
            }
        }
    };
    return BaseHandler;
}());
exports.default = BaseHandler;