feat(objects): show functions and procedures in sidebar tree

Add list_objects support for agent-driven databases (Dameng, Oracle, etc.)
and ExternalDriver plugin connections. SQL Server dbo schema now uses
listObjects to display grouped object nodes including routines.

- Add list_objects RPC to JDBC agent plugin
- Add extract_agent and ExternalDriver branches in list_objects_core
- Add get_object_source support for agent connections
- Click function/procedure nodes to view source via object browser
- Fix duplicate tree node IDs when same name exists as view and function
This commit is contained in:
t8y2
2026-05-15 13:02:19 +08:00
parent c8ba3dad69
commit c2da1f866c
7 changed files with 151 additions and 36 deletions
+43 -18
View File
@@ -1,38 +1,63 @@
import test from "node:test";
import assert from "node:assert/strict";
import { buildSqlServerDatabaseTreeNodes } from "../src/lib/sqlServerTree.ts";
import type { TableInfo } from "../src/types/database.ts";
import type { ObjectInfo } from "../src/types/database.ts";
function table(name: string, tableType = "BASE TABLE"): TableInfo {
function obj(name: string, objectType = "TABLE"): ObjectInfo {
return {
name,
table_type: tableType,
object_type: objectType,
};
}
test("SQL Server database tree flattens dbo tables and keeps non-default schemas", () => {
const nodes = buildSqlServerDatabaseTreeNodes(
"conn",
"app",
["dbo", "sales"],
[table("customers"), table("customer_view", "VIEW")],
test("SQL Server database tree groups dbo objects and keeps non-default schemas", () => {
const nodes = buildSqlServerDatabaseTreeNodes("conn", "app", ["dbo", "sales"], [
obj("customers"),
obj("customer_view", "VIEW"),
obj("get_total", "FUNCTION"),
]);
const topLevel = nodes.map((n) => ({ id: n.id, label: n.label, type: n.type }));
assert.deepEqual(topLevel, [
{ id: "conn:app:__tables", label: "tree.tables", type: "group-tables" },
{ id: "conn:app:__views", label: "tree.views", type: "group-views" },
{ id: "conn:app:__functions", label: "tree.functions", type: "group-functions" },
{ id: "conn:app:sales", label: "sales", type: "schema" },
]);
const tableGroup = nodes.find((n) => n.type === "group-tables");
assert.deepEqual(
tableGroup?.children?.map((c) => c.label),
["customers"],
);
const functionGroup = nodes.find((n) => n.type === "group-functions");
assert.deepEqual(
nodes.map((node) => ({ id: node.id, label: node.label, type: node.type, schema: node.schema })),
[
{ id: "conn:app:dbo:customers", label: "customers", type: "table", schema: "dbo" },
{ id: "conn:app:dbo:customer_view", label: "customer_view", type: "view", schema: "dbo" },
{ id: "conn:app:sales", label: "sales", type: "schema", schema: "sales" },
],
functionGroup?.children?.map((c) => c.label),
["get_total"],
);
});
test("SQL Server database tree hides default schema node when dbo has no tables", () => {
test("SQL Server database tree shows only schemas when dbo has no objects", () => {
const nodes = buildSqlServerDatabaseTreeNodes("conn", "app", ["dbo", "archive"], []);
assert.deepEqual(
nodes.map((node) => ({ id: node.id, label: node.label, type: node.type, schema: node.schema })),
[{ id: "conn:app:archive", label: "archive", type: "schema", schema: "archive" }],
nodes.map((node) => ({ id: node.id, label: node.label, type: node.type })),
[{ id: "conn:app:archive", label: "archive", type: "schema" }],
);
});
test("SQL Server database tree groups procedures alongside tables", () => {
const nodes = buildSqlServerDatabaseTreeNodes("conn", "app", ["dbo"], [
obj("orders"),
obj("sp_refresh", "PROCEDURE"),
]);
assert.deepEqual(
nodes.map((n) => ({ label: n.label, type: n.type })),
[
{ label: "tree.tables", type: "group-tables" },
{ label: "tree.procedures", type: "group-procedures" },
],
);
});