2020-11-24 19:15:07 +00:00
|
|
|
import { EngineDriver, ExtensionsDirectory } from 'dbgate-types';
|
2020-11-24 18:06:05 +00:00
|
|
|
import _camelCase from 'lodash/camelCase';
|
2020-11-24 19:15:07 +00:00
|
|
|
import _isString from 'lodash/isString';
|
|
|
|
import _isPlainObject from 'lodash/isPlainObject';
|
2020-11-22 08:03:16 +00:00
|
|
|
|
|
|
|
export function extractShellApiPlugins(functionName, props): string[] {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-12-08 17:51:00 +00:00
|
|
|
export function extractPackageName(name): string {
|
|
|
|
if (!name) return null;
|
|
|
|
const nsMatch = name.match(/^([^@]+)@([^@]+)/);
|
|
|
|
if (nsMatch) {
|
|
|
|
return nsMatch[2];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-11-22 08:03:16 +00:00
|
|
|
export function extractShellApiFunctionName(functionName) {
|
|
|
|
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
|
|
|
|
if (nsMatch) {
|
2020-11-24 18:06:05 +00:00
|
|
|
return `${_camelCase(nsMatch[2])}.shellApi.${nsMatch[1]}`;
|
2020-11-22 08:03:16 +00:00
|
|
|
}
|
|
|
|
return `dbgateApi.${functionName}`;
|
|
|
|
}
|
2020-11-24 19:15:07 +00:00
|
|
|
|
|
|
|
export function findEngineDriver(connection, extensions: ExtensionsDirectory): EngineDriver {
|
|
|
|
if (_isString(connection)) {
|
|
|
|
return extensions.drivers.find((x) => x.engine == connection);
|
|
|
|
}
|
|
|
|
if (_isPlainObject(connection)) {
|
|
|
|
const { engine } = connection;
|
|
|
|
if (engine) {
|
|
|
|
return extensions.drivers.find((x) => x.engine == engine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|