import registry from "../connection-types/connection-types.json"; /** * 驱动目录 §3.11:单一事实来源是 connection-types/connection-types.json(运行时 import), * 本文件只做类型收敛与查询辅助。新增驱动请先改 JSON(Go 侧 open.go 分发表仍需手工同步)。 */ export type DriverId = | "mysql" | "mariadb" | "tidb" | "postgresql" | "sqlserver" | "oracle" | "sqlite" | "mongodb" | "redis" | "elasticsearch" | "zookeeper" | "influxdb" | "dameng" | "oceanbase" | "gaussdb" | "opengauss" // 服务端族接受此 id(老数据/URL 粘贴兼容),选择器与 gaussdb 合并展示 | "polardb" | "tdsql" | "kingbase"; export type DriverCategory = "关系型" | "NoSQL" | "国产库" | "时序/搜索" | "全部"; export type FormKind = "standard" | "file" | "redis" | "oracle"; export type DriverDef = { id: DriverId; name: string; category: Exclude; defaultPort: number; color: string; icon?: string; mysqlCompat?: boolean; ready?: boolean; /** 是否已在 docker 验收矩阵验收;false 时引擎列表显示「未验收」徽标 */ verified?: boolean; /** 未验收/未就绪说明 */ notes?: string; formKind?: FormKind; hints?: { host?: string; port?: string; user?: string; database?: string }; }; type RegistryEntry = { id: string; label: string; category: Exclude; form?: FormKind; ready?: boolean; verified?: boolean; notes?: string; defaultPort?: number; mysqlCompat?: boolean; color?: string; icon?: string; hints?: { host?: string; port?: string; user?: string; database?: string }; }; export const DRIVERS: DriverDef[] = (registry.types as RegistryEntry[]).map((t) => ({ id: t.id as DriverId, name: t.label, category: t.category, defaultPort: t.defaultPort ?? 0, color: t.color ?? "#64748b", icon: t.icon, mysqlCompat: t.mysqlCompat, ready: t.ready, verified: t.verified, notes: t.notes, formKind: t.form, hints: t.hints, })); export const CATEGORIES: DriverCategory[] = ["全部", "关系型", "NoSQL", "国产库", "时序/搜索"]; export function driverById(id: string) { return DRIVERS.find((d) => d.id === id); } export function isDriverReady(id: string) { const d = driverById(id); return !!(d?.ready || d?.mysqlCompat); } export function formKindOf(id: string): FormKind { return driverById(id)?.formKind ?? "standard"; } // ---------- 驱动能力模型 ---------- // 对象树分组 / 右键菜单 / 行编辑等按驱动开关,禁止名不副实的功能展示 // (如 ES 挂「存储过程」、ZK 节点提供「删除表」)。 export type TreeGroupKind = "tables" | "views" | "procedures" | "functions"; export type DriverCaps = { /** 库节点下展示哪些分组;空数组 = 该驱动无分组概念(走特殊树) */ treeGroups: TreeGroupKind[]; /** 分组显示别名(如 ES 的 tables →「索引」) */ groupLabel: Partial>; /** 对象节点可展开查看字段(列) */ columns: boolean; /** 右键「查看 DDL」 */ ddl: boolean; /** 右键「清空/截断」 */ truncate: boolean; /** 右键「删除对象」(表/集合/索引…) */ dropObject: boolean; /** 库节点「设为默认库」 */ setDefaultDb: boolean; }; const ALL_GROUPS: TreeGroupKind[] = ["tables", "views", "procedures", "functions"]; /** 全能力 SQL 库(含达梦:JDBC 元数据全支持) */ const SQL_CAPS: DriverCaps = { treeGroups: ALL_GROUPS, groupLabel: {}, columns: true, ddl: true, truncate: true, dropObject: true, setDefaultDb: true, }; /** 只读 flat 对象树(无分组包装,对象直挂库节点)的 NoSQL 驱动 */ function readonlyCaps(columns: boolean): DriverCaps { return { treeGroups: [], // flat:ES 索引/Mongo 集合/Influx measurement/ZK 子节点 直挂库节点 groupLabel: {}, columns, ddl: false, truncate: false, dropObject: false, setDefaultDb: false, }; } export function driverCaps(driver: string): DriverCaps { const d = (driver || "").toLowerCase(); switch (d) { case "mysql": case "mariadb": case "tidb": case "oceanbase": case "polardb": case "tdsql": case "postgresql": case "postgres": case "gaussdb": case "opengauss": case "kingbase": case "sqlserver": case "mssql": case "oracle": case "dameng": return SQL_CAPS; case "sqlite": // SQLite 无存储过程/函数/TRUNCATE;有视图与 DROP TABLE return { ...SQL_CAPS, treeGroups: ["tables", "views"], truncate: false }; case "elasticsearch": // ES SQL 只读:索引≈表;无 DDL/写操作/默认库 return readonlyCaps(true); case "influxdb": // bucket→measurement;字段可探(Flux fieldKeys),只读 return readonlyCaps(true); case "mongodb": // 库→集合;抽样字段;写操作走 DSL 编辑器而非树右键 return readonlyCaps(true); case "zookeeper": // 路径→子节点;节点数据靠双击 GET;无列概念 return readonlyCaps(false); case "redis": // Redis 走专属键树(buildRedisKeyTree),这里全关兜底 return { treeGroups: [], groupLabel: {}, columns: false, ddl: false, truncate: false, dropObject: false, setDefaultDb: false }; default: return readonlyCaps(false); } }