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.6 KB
Raw Blame
import type { PluginFilesystemEntry, PluginFilesystemProviderContribution } from "@/types/database";

export function pluginFilesystemRootUri(provider: Pick<PluginFilesystemProviderContribution, "root_uri" | "schemes">): string {
  return provider.root_uri || `${provider.schemes[0]}:/`;
}

export function pluginFilesystemParentUri(uri: string, root: string): string | undefined {
  if (!uri || uri === root) return undefined;
  const schemeEnd = uri.indexOf(":");
  if (schemeEnd < 1) return root;
  const minimumEnd = uri.startsWith("//", schemeEnd + 1)
    ? (() => {
        const authorityEnd = uri.indexOf("/", schemeEnd + 3);
        return authorityEnd < 0 ? uri.length : authorityEnd + 1;
      })()
    : schemeEnd + 2;
  const normalized = uri.endsWith("/") && uri.length > minimumEnd ? uri.slice(0, -1) : uri;
  const separator = normalized.lastIndexOf("/");
  const parent = separator < minimumEnd ? uri.slice(0, minimumEnd) : uri.slice(0, separator + 1);
  return parent.length < root.length ? root : parent;
}

export function sortPluginFilesystemEntries(entries: readonly PluginFilesystemEntry[]): PluginFilesystemEntry[] {
  return [...entries].sort((left, right) => {
    const leftDirectory = left.kind === "directory";
    const rightDirectory = right.kind === "directory";
    if (leftDirectory !== rightDirectory) return leftDirectory ? -1 : 1;
    return left.name.localeCompare(right.name, undefined, { numeric: true, sensitivity: "base" });
  });
}

export function uniquePluginFilesystemEntries(entries: readonly PluginFilesystemEntry[]): PluginFilesystemEntry[] {
  return [...new Map(entries.map((entry) => [entry.uri, entry])).values()];
}