feat(xugu): expose object type members in schema tree

This commit is contained in:
Elias authored and GitHub committed 2026-08-11 02:12:22 +08:00
1 parent d7e93453c7
commit 1b37e97486
30 files changed
+1364 -63

No files matched your search

@@ -34,6 +34,12 @@ describe("sidebar tree item layout", () => {
expect(canTreeNodeShowExpander({ type: "procedure", childCount: 0, explicitContainer: true })).toBe(false);
});
it("allows only an explicitly marked Xugu type specification to expand", () => {
expect(canTreeNodeShowExpander({ type: "type", childCount: 0, explicitContainer: true })).toBe(true);
expect(canTreeNodeShowExpander({ type: "type", childCount: 0 })).toBe(false);
expect(canTreeNodeShowExpander({ type: "type-body", childCount: 0, explicitContainer: true })).toBe(false);
});
it("aligns comments to the longest sibling name without crossing parent groups", () => {
const widths = alignedSidebarCommentLabelWidths([
{ id: "tables", depth: 1, alignable: false, hasComment: false, labelWidth: 0 },
@@ -23,6 +23,11 @@ describe("treeNodeClick", () => {
expect(treeNodeRowAction("package", false)).toBe("open-source");
});
it("toggles an expandable type node before opening its source", () => {
expect(treeNodeRowAction("type", true)).toBe("toggle");
expect(treeNodeRowAction("type", false)).toBe("open-source");
});
it("routes package members to their owning package body", () => {
expect(
objectSourceTargetForTreeNode({
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";
import { buildXuguTypeMemberNodes, isXuguTypeMemberContainer } from "@/lib/sidebar/xuguTypeMembers";
import type { TreeNode } from "@/types/database";
const typeNode: TreeNode = {
id: "connection:database:schema:type:OrderType",
label: "OrderType",
objectName: "OrderType",
type: "type",
connectionId: "connection",
database: "database",
schema: "AppSchema",
isExpanded: false,
xuguTypeMembersExpandable: true,
};
describe("Xugu object type members", () => {
it("keeps the member loader exclusive to Xugu type specifications", () => {
expect(isXuguTypeMemberContainer(typeNode, "xugu")).toBe(true);
expect(isXuguTypeMemberContainer(typeNode, "oracle")).toBe(false);
expect(isXuguTypeMemberContainer({ ...typeNode, type: "type-body" }, "xugu")).toBe(false);
expect(isXuguTypeMemberContainer({ ...typeNode, xuguTypeMembersExpandable: false }, "xugu")).toBe(false);
expect(isXuguTypeMemberContainer({ ...typeNode, database: undefined }, "xugu")).toBe(false);
});
it("renders attributes and callable members without treating them as top-level routines", () => {
const nodes = buildXuguTypeMemberNodes(typeNode, [
{ name: "itemId", kind: "column", data_type: "INTEGER" },
{ name: "total", kind: "function", signature: "quantity INTEGER, price NUMERIC(12,2)", data_type: "NUMERIC(18,2)" },
{ name: "rename", kind: "procedure", signature: "OUT result VARCHAR(40)" },
{ name: "itemId", kind: "column", data_type: "INTEGER" },
]);
expect(nodes.map((node) => ({ type: node.type, label: node.label }))).toEqual([
{ type: "type-attribute", label: "itemId (INTEGER)" },
{ type: "type-method", label: "FUNCTION total(quantity INTEGER, price NUMERIC(12,2)) → NUMERIC(18,2)" },
{ type: "type-method", label: "PROCEDURE rename(OUT result VARCHAR(40))" },
]);
expect(nodes.every((node) => node.parentType === "type" && node.parentName === "OrderType" && node.children === undefined)).toBe(true);
});
});
+8 -2
View File
@@ -99,14 +99,20 @@ describe("programmable database objects", () => {
it("keeps Xugu trigger/type nodes distinct and preserves an invalid status", () => {
const objects: ObjectInfo[] = [
{ name: "TRG_AUDIT", object_type: "TRIGGER", schema: "APP", valid: false },
{ name: "ADDRESS_T", object_type: "TYPE", schema: "APP", valid: true },
{ name: "ADDRESS_T", object_type: "TYPE", schema: "APP", valid: true, xugu_type_members_expandable: true },
{ name: "ADDRESS_LIST", object_type: "TYPE", schema: "APP", valid: true, xugu_type_members_expandable: false },
{ name: "ADDRESS_T", object_type: "TYPE_BODY", schema: "APP", valid: true },
];
const nodes = buildSimpleObjectTreeNodes({ ...context, schema: "APP", objects });
expect(nodes).toEqual(
expect.arrayContaining([expect.objectContaining({ type: "trigger", objectName: "TRG_AUDIT", valid: false }), expect.objectContaining({ type: "type", objectName: "ADDRESS_T", valid: true }), expect.objectContaining({ type: "type-body", objectName: "ADDRESS_T", valid: true })]),
expect.arrayContaining([
expect.objectContaining({ type: "trigger", objectName: "TRG_AUDIT", valid: false }),
expect.objectContaining({ type: "type", objectName: "ADDRESS_T", valid: true, xuguTypeMembersExpandable: true }),
expect.objectContaining({ type: "type", objectName: "ADDRESS_LIST", valid: true, xuguTypeMembersExpandable: false }),
expect.objectContaining({ type: "type-body", objectName: "ADDRESS_T", valid: true }),
]),
);
});