@megaorm/utils
Version:
This package provides utility functions to validate whether a value is a MegaORM driver or a connection.
107 lines • 3.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isDriver = isDriver;
exports.isMySQL = isMySQL;
exports.isSQLite = isSQLite;
exports.isPostgreSQL = isPostgreSQL;
exports.isCon = isCon;
exports.isPendingCon = isPendingCon;
exports.isPoolCon = isPoolCon;
const test_1 = require("@megaorm/test");
/**
* Checks if the given object is a valid `MegaDriver`.
* @param driver - The object to validate as a `MegaDriver`.
* @returns `true` if the object is a `MegaDriver`, `false` otherwise.
*/
function isDriver(driver) {
if (!(0, test_1.isObj)(driver))
return false;
if (!(0, test_1.isSymbol)(driver.id))
return false;
return ['MySQL', 'SQLite', 'PostgreSQL'].some((name) => name === driver.id.description);
}
/**
* Checks if the given object is a valid `MySQL` instance.
* @param driver The object to validate.
* @returns `true` if the object is a `MySQL` instance, `false` otherwise.
*/
function isMySQL(driver) {
if (!(0, test_1.isObj)(driver))
return false;
if (!(0, test_1.isSymbol)(driver.id))
return false;
if (driver.id.description !== 'MySQL')
return false;
return true;
}
/**
* Checks if the given object is a valid `SQLite` instance.
* @param driver The object to validate.
* @returns `true` if the object is a `SQLite` instance, `false` otherwise.
*/
function isSQLite(driver) {
if (!(0, test_1.isObj)(driver))
return false;
if (!(0, test_1.isSymbol)(driver.id))
return false;
if (driver.id.description !== 'SQLite')
return false;
return true;
}
/**
* Checks if the given object is a valid `PostgreSQL` instance.
* @param driver The object to validate.
* @returns `true` if the object is a `PostgreSQL` instance, `false` otherwise.
*/
function isPostgreSQL(driver) {
if (!(0, test_1.isObj)(driver))
return false;
if (!(0, test_1.isSymbol)(driver.id))
return false;
if (driver.id.description !== 'PostgreSQL')
return false;
return true;
}
/**
* Checks if the given object is a valid `MegaConnection`.
* @param connection - The object to validate as a `MegaConnection`.
* @returns `true` if the object is a `MegaConnection`, `false` otherwise.
*/
function isCon(connection) {
if (!(0, test_1.isObj)(connection))
return false;
if (!(0, test_1.isSymbol)(connection.id))
return false;
if (connection.id.description !== 'MegaConnection')
return false;
return true;
}
/**
* Checks if the given object is a valid `MegaPendingConnection`.
* @param connection - The object to validate as a `MegaPendingConnection`.
* @returns `true` if the object is a `MegaPendingConnection`, `false` otherwise.
*/
function isPendingCon(connection) {
if (!(0, test_1.isObj)(connection))
return false;
if (!(0, test_1.isSymbol)(connection.id))
return false;
if (connection.id.description !== 'MegaPendingConnection')
return false;
return true;
}
/**
* Checks if the given object is a valid `MegaPoolConnection`.
* @param connection - The object to validate as a `MegaPoolConnection`.
* @returns `true` if the object is a `MegaPoolConnection`, `false` otherwise.
*/
function isPoolCon(connection) {
if (!(0, test_1.isObj)(connection))
return false;
if (!(0, test_1.isSymbol)(connection.id))
return false;
if (connection.id.description !== 'MegaPoolConnection')
return false;
return true;
}
//# sourceMappingURL=index.js.map