feat(xugu): expose package members in schema tree
This commit is contained in:
1 parent
37f13018d3
commit
ad9075e18f
15 files changed
+922
-28
No files matched your search
@@ -60,6 +60,19 @@ function oracleConnection(): ConnectionConfig {
|
||||
} as ConnectionConfig;
|
||||
}
|
||||
|
||||
function xuguConnection(): ConnectionConfig {
|
||||
return {
|
||||
id: "xugu-1",
|
||||
name: "XuguDB",
|
||||
db_type: "xugu",
|
||||
host: "127.0.0.1",
|
||||
port: 5138,
|
||||
username: "app_user",
|
||||
password: "",
|
||||
database: "app_db",
|
||||
} as ConnectionConfig;
|
||||
}
|
||||
|
||||
function genericJdbcConnection(): ConnectionConfig {
|
||||
return {
|
||||
id: "jdbc-1",
|
||||
@@ -132,6 +145,61 @@ describe("connectionStore metadata loading", () => {
|
||||
setActivePinia(createPinia());
|
||||
});
|
||||
|
||||
// Dynamic import of the merged connectionStore plus the scoped metadata
|
||||
// load can exceed Vitest's 5s default on slower CI runners; the assertion
|
||||
// is deterministic, so allow a wider timeout.
|
||||
it("loads Xugu package members through the scoped completion endpoint", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [
|
||||
{ name: "process_item", kind: "procedure", signature: "p_id IN INT" },
|
||||
{ name: "process_item", kind: "procedure", signature: "p_code IN VARCHAR" },
|
||||
{ name: "item_count", kind: "function", data_type: "INT" },
|
||||
],
|
||||
incomplete: false,
|
||||
fallback_used: false,
|
||||
});
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({ checkConnectionHealth: vi.fn().mockResolvedValue(undefined), completionAssistantSearch }));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
const connection = xuguConnection();
|
||||
const packageNode: TreeNode = {
|
||||
id: "xugu-1:app_db:app_schema:package:business_api",
|
||||
label: "business_api",
|
||||
type: "package",
|
||||
connectionId: connection.id,
|
||||
database: "app_db",
|
||||
schema: "app_schema",
|
||||
children: [],
|
||||
isExpanded: false,
|
||||
};
|
||||
store.connections = [connection];
|
||||
store.connectedIds = new Set([connection.id]);
|
||||
store.treeNodes = [packageNode];
|
||||
|
||||
await store.loadXuguPackageMembers(packageNode);
|
||||
|
||||
expect(completionAssistantSearch).toHaveBeenCalledWith({
|
||||
connection_id: connection.id,
|
||||
database: "app_db",
|
||||
schema: "app_schema",
|
||||
object_kinds: ["routine"],
|
||||
mask: "",
|
||||
case_sensitive: true,
|
||||
global_search: false,
|
||||
max_results: 1000,
|
||||
search_in_comments: false,
|
||||
search_in_definitions: false,
|
||||
parent_schema: "app_schema",
|
||||
parent_name: "business_api",
|
||||
match_mode: "prefix",
|
||||
});
|
||||
expect(packageNode.isExpanded).toBe(true);
|
||||
expect(packageNode.children?.map((child) => child.label)).toEqual(["process_item(p_id IN INT)", "process_item(p_code IN VARCHAR)", "item_count"]);
|
||||
expect(packageNode.children?.every((child) => child.parentName === "business_api")).toBe(true);
|
||||
}, 15000);
|
||||
|
||||
it("loads missing database roots only for connected sidebar search targets", async () => {
|
||||
const checkConnectionHealth = vi.fn().mockResolvedValue(undefined);
|
||||
const listDatabases = vi.fn().mockResolvedValue([{ name: "dajia", comment: null }]);
|
||||
|
||||
@@ -111,6 +111,7 @@ import { appendAgentDriverUpdateHint, hasAgentDriverUpdate, hasInstalledAgentVer
|
||||
import { appendConnectionErrorHints } from "@/lib/connection/connectionErrorHints";
|
||||
import { appendVisibleDatabaseSelection } from "@/lib/connection/connectionVisibleDatabases";
|
||||
import { filterNacosNamespacesForSidebar, normalizeNacosNamespacesForDisplay } from "@/lib/nacos/nacosNamespaceVisibility";
|
||||
import { buildXuguPackageMemberNodes, markXuguPackageNodesExpandable } from "@/lib/sidebar/xuguPackageMembers";
|
||||
import { configuredDatabaseProductName, connectionConfigFingerprint, normalizeDatabaseConnectionInfo } from "@/lib/connection/connectionDatabaseInfo";
|
||||
import { createMetadataLoadTrace, logMetadataLoadTrace, MetadataLoadCoordinator, type MetadataLoadTraceLogger } from "@/lib/metadata/metadataLoadCoordinator";
|
||||
import type { MetadataScopeInput } from "@/lib/metadata/metadataLoadScope";
|
||||
@@ -1604,7 +1605,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
objects: options.objects.filter((object) => options.objectTypes.includes(normalizedObjectTreeKind(object.object_type))),
|
||||
});
|
||||
const refreshedGroup = grouped.find((group) => group.type === options.node.type);
|
||||
return refreshedGroup?.children ?? [];
|
||||
const children = refreshedGroup?.children ?? [];
|
||||
return options.node.connectionId && getConfig(options.node.connectionId)?.db_type === "xugu" ? markXuguPackageNodesExpandable(children) : children;
|
||||
}
|
||||
|
||||
function tableInfosToCompletionTables(tables: readonly TableInfo[], schema?: string): SqlCompletionTable[] {
|
||||
@@ -1861,13 +1863,16 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
);
|
||||
const supplementalObjects = filterSimpleSidebarSupplementalObjects(objects);
|
||||
if (supplementalObjects.length === 0) return;
|
||||
const supplementalChildren = buildSimpleObjectTreeNodes({
|
||||
let supplementalChildren = buildSimpleObjectTreeNodes({
|
||||
nodeId: options.nodeId,
|
||||
connectionId: options.connectionId,
|
||||
database: options.database,
|
||||
schema: options.effectiveSchema,
|
||||
objects: supplementalObjects,
|
||||
});
|
||||
if (getConfig(options.connectionId)?.db_type === "xugu") {
|
||||
supplementalChildren = markXuguPackageNodesExpandable(supplementalChildren);
|
||||
}
|
||||
if (supplementalChildren.length === 0) return;
|
||||
if (isTreeLoadSearchChanged(searchFilter, options.loadOptions)) return;
|
||||
const targetNode = treeNodeLoadTarget(options.load);
|
||||
@@ -5613,6 +5618,57 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
});
|
||||
}
|
||||
|
||||
async function loadXuguPackageMembers(node: TreeNode, options?: LoadTreeOptions): Promise<void> {
|
||||
if (node.type !== "package" || !node.connectionId || !node.database || getConfig(node.connectionId)?.db_type !== "xugu") return;
|
||||
const connectionId = node.connectionId;
|
||||
const database = node.database;
|
||||
const schema = node.schema;
|
||||
const packageName = node.objectName || node.label;
|
||||
let load = beginTreeNodeLoad(node);
|
||||
|
||||
try {
|
||||
await runTreeMetadataLoad(
|
||||
{
|
||||
kind: "xugu-package-members",
|
||||
connectionId,
|
||||
database,
|
||||
schema,
|
||||
nodeKind: node.type,
|
||||
extra: { packageName },
|
||||
},
|
||||
async () => {
|
||||
await ensureConnected(connectionId);
|
||||
load = reclaimTreeNodeLoad(load, node);
|
||||
const response = await completionAssistantSearch({
|
||||
connection_id: connectionId,
|
||||
database,
|
||||
schema: schema ?? null,
|
||||
object_kinds: ["routine"],
|
||||
mask: "",
|
||||
case_sensitive: true,
|
||||
global_search: false,
|
||||
max_results: 1000,
|
||||
search_in_comments: false,
|
||||
search_in_definitions: false,
|
||||
parent_schema: schema ?? null,
|
||||
parent_name: packageName,
|
||||
match_mode: "prefix",
|
||||
});
|
||||
const targetNode = treeNodeLoadTarget(load);
|
||||
if (!targetNode) return;
|
||||
setChildren(targetNode, buildXuguPackageMemberNodes(targetNode, response.candidates));
|
||||
targetNode.isExpanded = true;
|
||||
},
|
||||
options,
|
||||
);
|
||||
} catch (error) {
|
||||
recordMetadataLoadError(connectionId, error, load);
|
||||
throw error;
|
||||
} finally {
|
||||
finishTreeNodeLoad(load);
|
||||
}
|
||||
}
|
||||
|
||||
const ORACLE_SYSTEM_COMPLETION_SCHEMAS = new Set(["SYS", "SYSTEM", "SYSMAN", "DBSNMP", "OUTLN", "XDB", "MDSYS", "CTXSYS", "WMSYS"]);
|
||||
const FILTERED_ROUTINE_COMPLETION_DATABASES = new Set<DatabaseType>(["mysql", "postgres", "sqlserver", "oracle"]);
|
||||
|
||||
@@ -7224,6 +7280,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
loadTables,
|
||||
loadTableForLocate,
|
||||
loadObjectGroupChildren,
|
||||
loadXuguPackageMembers,
|
||||
loadMoreObjectGroupChildren,
|
||||
loadAllObjectGroupChildren,
|
||||
loadTableGroups,
|
||||
|
||||
Reference in new issue
Block a user