dbgate-tools
Version:
Auxiliary tools for other DbGate packages.
67 lines (66 loc) • 2.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findEngineDriver = exports.evalShellApiFunctionName = exports.compileShellApiFunctionName = exports.extractPackageName = exports.extractShellApiPlugins = void 0;
const camelCase_1 = __importDefault(require("lodash/camelCase"));
const isString_1 = __importDefault(require("lodash/isString"));
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
function extractShellApiPlugins(functionName, props) {
const res = [];
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
if (nsMatch) {
res.push(nsMatch[2]);
}
if (props && props.connection && props.connection.engine) {
const nsMatchEngine = props.connection.engine.match(/^([^@]+)@([^@]+)/);
if (nsMatchEngine) {
res.push(nsMatchEngine[2]);
}
}
return res;
}
exports.extractShellApiPlugins = extractShellApiPlugins;
function extractPackageName(name) {
if (!name)
return null;
const nsMatch = name.match(/^([^@]+)@([^@]+)/);
if (nsMatch) {
return nsMatch[2];
}
return null;
}
exports.extractPackageName = extractPackageName;
function compileShellApiFunctionName(functionName) {
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
if (nsMatch) {
return `${(0, camelCase_1.default)(nsMatch[2])}.shellApi.${nsMatch[1]}`;
}
return `dbgateApi.${functionName}`;
}
exports.compileShellApiFunctionName = compileShellApiFunctionName;
function evalShellApiFunctionName(functionName, dbgateApi, requirePlugin) {
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
if (nsMatch) {
return requirePlugin(nsMatch[2]).shellApi[nsMatch[1]];
}
return dbgateApi[functionName];
}
exports.evalShellApiFunctionName = evalShellApiFunctionName;
function findEngineDriver(connection, extensions) {
if (!extensions) {
return null;
}
if ((0, isString_1.default)(connection)) {
return extensions.drivers.find(x => x.engine == connection);
}
if ((0, isPlainObject_1.default)(connection)) {
const { engine } = connection;
if (engine) {
return extensions.drivers.find(x => x.engine == engine);
}
}
return null;
}
exports.findEngineDriver = findEngineDriver;