Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.2 KB
Raw Blame
const JAVA_SYSTEM_PROPERTY_PREFIX = "-D";
const SHELL_QUOTE_PATTERN = /["']/;

export class DamengJvmSystemPropertyError extends Error {
  constructor(readonly lineNumber: number) {
    super(`Invalid Dameng JVM system property on line ${lineNumber}`);
    this.name = "DamengJvmSystemPropertyError";
  }
}

export function damengJvmSystemPropertiesText(options?: string[]): string {
  return (options ?? [])
    .map((option) => option.trim())
    .filter(Boolean)
    .join("\n");
}

export function parseDamengJvmSystemProperties(value: string): string[] {
  const options: string[] = [];

  for (const [index, line] of value.split(/\r?\n/).entries()) {
    const option = line.trim();
    if (!option) continue;
    if (!isJavaSystemProperty(option)) {
      throw new DamengJvmSystemPropertyError(index + 1);
    }
    options.push(option);
  }

  return options;
}

function isJavaSystemProperty(option: string): boolean {
  if (!option.startsWith(JAVA_SYSTEM_PROPERTY_PREFIX) || SHELL_QUOTE_PATTERN.test(option)) return false;
  const property = option.slice(JAVA_SYSTEM_PROPERTY_PREFIX.length);
  const separator = property.indexOf("=");
  const key = separator >= 0 ? property.slice(0, separator) : property;
  return key.length > 0 && !/\s/.test(key);
}