feat(postgres): list user-defined types with details and DDL for PG-family databases
This commit is contained in:
1 parent
0c6c1fada2
commit
154c460657
59 files changed
+6538
-150
No files matched your search
+38
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { normalizeSidebarObjectKind, sidebarObjectKindsForDatabase, supportsPackageMemberExpansion } from "@/lib/database/databaseObjectCapabilities";
|
||||
import { customTypeCapabilities, databaseObjectCapabilities, normalizeSidebarObjectKind, sidebarObjectKindsForDatabase, supportsPackageMemberExpansion, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
|
||||
describe("databaseObjectCapabilities", () => {
|
||||
it("exposes supported programmable objects for Dameng", () => {
|
||||
@@ -39,4 +39,41 @@ describe("databaseObjectCapabilities", () => {
|
||||
it("normalizes space separated materialized view types", () => {
|
||||
expect(normalizeSidebarObjectKind("MATERIALIZED VIEW")).toBe("MATERIALIZED_VIEW");
|
||||
});
|
||||
|
||||
it("exposes TYPE for verified PostgreSQL-family databases only", () => {
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"] as const) {
|
||||
expect(sidebarObjectKindsForDatabase(dbType), dbType).toContain("TYPE");
|
||||
}
|
||||
// Unverified PG-like databases must not advertise TYPE this cycle.
|
||||
for (const dbType of ["highgo", "uxdb", "redshift", "kwdb"] as const) {
|
||||
expect(sidebarObjectKindsForDatabase(dbType), dbType).not.toContain("TYPE");
|
||||
}
|
||||
});
|
||||
|
||||
it("only Xugu TYPE nodes can open object source", () => {
|
||||
expect(supportsTypeObjectSource("xugu")).toBe(true);
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase", undefined] as const) {
|
||||
expect(supportsTypeObjectSource(dbType), String(dbType)).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps sourceReadable in sync with supportsTypeObjectSource", () => {
|
||||
expect(databaseObjectCapabilities("xugu").sourceReadable).toContain("TYPE");
|
||||
expect(databaseObjectCapabilities("xugu").sourceReadable).toContain("TYPE_BODY");
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"] as const) {
|
||||
expect(databaseObjectCapabilities(dbType).sourceReadable, dbType).not.toContain("TYPE");
|
||||
expect(databaseObjectCapabilities(dbType).sourceReadable, dbType).not.toContain("TYPE_BODY");
|
||||
// Non-type programmable objects stay source-readable on PG-family.
|
||||
expect(databaseObjectCapabilities(dbType).sourceReadable, dbType).toContain("FUNCTION");
|
||||
}
|
||||
});
|
||||
|
||||
it("enables custom type details only for verified PG-family databases", () => {
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"] as const) {
|
||||
expect(customTypeCapabilities(dbType), dbType).toEqual({ details: true, members: true, ddl: true });
|
||||
}
|
||||
for (const dbType of ["xugu", "highgo", "uxdb", "redshift", "mysql", undefined] as const) {
|
||||
expect(customTypeCapabilities(dbType), String(dbType)).toEqual({ details: false, members: false, ddl: false });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,92 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildCustomTypeTreeChildren } from "@/lib/sidebar/customTypeTree";
|
||||
import type { CustomTypeDetails, TreeNode } from "@/types/database";
|
||||
|
||||
const parent: TreeNode = {
|
||||
id: "c:db:app:types:status",
|
||||
label: "status",
|
||||
type: "type",
|
||||
connectionId: "c",
|
||||
database: "db",
|
||||
schema: "app",
|
||||
};
|
||||
|
||||
function details(overrides: Partial<CustomTypeDetails>): CustomTypeDetails {
|
||||
return {
|
||||
name: "status",
|
||||
schema: "app",
|
||||
kind: "enum",
|
||||
members: [],
|
||||
properties: { domainConstraints: [] },
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("custom type sidebar tree", () => {
|
||||
it("builds composite fields with their data types", () => {
|
||||
const children = buildCustomTypeTreeChildren(parent, details({ kind: "composite", members: [{ name: "city", dataType: "text", ordinal: 1 }] }));
|
||||
|
||||
expect(children).toHaveLength(1);
|
||||
expect(children[0]).toMatchObject({ id: "c:db:app:types:status:type-member:field:city", label: "city", type: "type-member", meta: { kind: "field", displayValue: "text", ordinal: 1 } });
|
||||
});
|
||||
|
||||
it("builds enum values in backend order", () => {
|
||||
const children = buildCustomTypeTreeChildren(
|
||||
parent,
|
||||
details({
|
||||
members: [
|
||||
{ name: "", dataType: "", ordinal: 1, enumValue: "draft" },
|
||||
{ name: "", dataType: "", ordinal: 2, enumValue: "published" },
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(children.map((child) => child.label)).toEqual(["draft", "published"]);
|
||||
expect(children.map((child) => child.id)).toEqual(["c:db:app:types:status:type-member:enum-value:draft", "c:db:app:types:status:type-member:enum-value:published"]);
|
||||
});
|
||||
|
||||
it("keeps existing member IDs stable when a new member is inserted", () => {
|
||||
const before = buildCustomTypeTreeChildren(
|
||||
parent,
|
||||
details({
|
||||
members: [
|
||||
{ name: "", dataType: "", ordinal: 1, enumValue: "draft" },
|
||||
{ name: "", dataType: "", ordinal: 2, enumValue: "published" },
|
||||
],
|
||||
}),
|
||||
);
|
||||
const after = buildCustomTypeTreeChildren(
|
||||
parent,
|
||||
details({
|
||||
members: [
|
||||
{ name: "", dataType: "", ordinal: 1, enumValue: "new" },
|
||||
{ name: "", dataType: "", ordinal: 2, enumValue: "draft" },
|
||||
{ name: "", dataType: "", ordinal: 3, enumValue: "published" },
|
||||
],
|
||||
}),
|
||||
);
|
||||
expect(after.find((child) => child.label === "draft")?.id).toBe(before.find((child) => child.label === "draft")?.id);
|
||||
expect(after.find((child) => child.label === "published")?.id).toBe(before.find((child) => child.label === "published")?.id);
|
||||
});
|
||||
|
||||
it("encodes member identity characters in IDs", () => {
|
||||
const children = buildCustomTypeTreeChildren(parent, details({ members: [{ name: "", dataType: "text", ordinal: 1, enumValue: "a:b/c" }] }));
|
||||
expect(children[0].id).toContain("a%3Ab%2Fc");
|
||||
});
|
||||
|
||||
it.each(["domain", "range", "multirange", "base"] as const)("does not add property children for %s types", (kind) => {
|
||||
expect(
|
||||
buildCustomTypeTreeChildren(
|
||||
parent,
|
||||
details({
|
||||
kind,
|
||||
properties: {
|
||||
baseType: "text",
|
||||
rangeSubtype: "numeric",
|
||||
domainConstraints: [{ name: "value_check", definition: "CHECK (VALUE IS NOT NULL)" }],
|
||||
},
|
||||
}),
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -40,6 +40,13 @@ describe("sidebar tree item layout", () => {
|
||||
expect(canTreeNodeShowExpander({ type: "type-body", childCount: 0, explicitContainer: true })).toBe(false);
|
||||
});
|
||||
|
||||
it("shows an expander only while a custom type may still load children", () => {
|
||||
expect(canTreeNodeShowExpander({ type: "type", childCount: undefined })).toBe(true);
|
||||
expect(canTreeNodeShowExpander({ type: "type", childCount: 2 })).toBe(true);
|
||||
expect(canTreeNodeShowExpander({ type: "type", childCount: 0 })).toBe(false);
|
||||
expect(canTreeNodeShowExpander({ type: "type-member", childCount: undefined })).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 },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isDirectNavigationTreeNode, objectSourceKindForTreeNode, objectSourceTargetForTreeNode, shouldActivateTreeNodeOnSingleClick, treeNodeRowAction } from "@/lib/sidebar/treeNodeClick";
|
||||
import { isDirectNavigationTreeNode, objectSourceKindForTreeNode, objectSourceTargetForTreeNode, shouldActivateTreeNodeOnSingleClick, treeNodeRowAction, treeNodeRowDoubleClickAction } from "@/lib/sidebar/treeNodeClick";
|
||||
|
||||
describe("treeNodeClick", () => {
|
||||
it("opens synonym nodes as synonym source", () => {
|
||||
@@ -7,6 +7,32 @@ describe("treeNodeClick", () => {
|
||||
expect(treeNodeRowAction("synonym", false)).toBe("open-source");
|
||||
});
|
||||
|
||||
it("only Xugu type nodes open source on single click", () => {
|
||||
expect(treeNodeRowAction("type", false, "single", "xugu")).toBe("open-source");
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"] as const) {
|
||||
expect(treeNodeRowAction("type", true, "single", dbType), String(dbType)).toBe("toggle");
|
||||
expect(treeNodeRowAction("type", false, "single", dbType), String(dbType)).toBe("none");
|
||||
}
|
||||
// Unknown connection type keeps the conservative no-action behavior.
|
||||
expect(treeNodeRowAction("type", false, "single", undefined)).toBe("none");
|
||||
});
|
||||
|
||||
it("only Xugu type nodes open source on double click", () => {
|
||||
expect(treeNodeRowDoubleClickAction("type", false, "double", false, "xugu")).toBe("open-source");
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"] as const) {
|
||||
expect(treeNodeRowDoubleClickAction("type", false, "double", true, dbType), String(dbType)).toBe("toggle");
|
||||
expect(treeNodeRowDoubleClickAction("type", false, "double", false, dbType), String(dbType)).toBe("none");
|
||||
}
|
||||
expect(treeNodeRowDoubleClickAction("type", false, "double", false, undefined)).toBe("none");
|
||||
});
|
||||
|
||||
it("keeps source actions for non-type source nodes on PG-family databases", () => {
|
||||
for (const type of ["procedure", "function", "trigger", "sequence", "package", "package-body"] as const) {
|
||||
expect(treeNodeRowAction(type, false, "single", "postgres"), type).toBe("open-source");
|
||||
}
|
||||
expect(treeNodeRowAction("type-body", false, "single", "xugu")).toBe("open-source");
|
||||
});
|
||||
|
||||
it("opens Consul navigation entries on one click regardless of object activation preference", () => {
|
||||
expect(isDirectNavigationTreeNode("consul-root")).toBe(true);
|
||||
expect(isDirectNavigationTreeNode("consul-overview")).toBe(true);
|
||||
@@ -23,9 +49,9 @@ 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("toggles an expandable Xugu type node before opening its source", () => {
|
||||
expect(treeNodeRowAction("type", true, "single", "xugu")).toBe("toggle");
|
||||
expect(treeNodeRowAction("type", false, "single", "xugu")).toBe("open-source");
|
||||
});
|
||||
|
||||
it("routes package members to their owning package body", () => {
|
||||
|
||||
@@ -39,8 +39,30 @@ describe("singleClickRowAction", () => {
|
||||
expect(singleClickRowAction(row("PACKAGE_BODY", "pkg_body_test"))).toBe("open-source");
|
||||
});
|
||||
|
||||
it.each(["TRIGGER", "TYPE", "TYPE_BODY"] as const)("returns open-source for %s", (type) => {
|
||||
expect(singleClickRowAction(row(type, "programmable_test"))).toBe("open-source");
|
||||
it.each(["TRIGGER", "TYPE", "TYPE_BODY"] as const)("returns open-source for %s on Xugu", (type) => {
|
||||
expect(singleClickRowAction(row(type, "programmable_test"), "xugu")).toBe("open-source");
|
||||
});
|
||||
|
||||
it("only Xugu TYPE rows open source", () => {
|
||||
expect(singleClickRowAction(row("TYPE", "app_status"), "xugu")).toBe("open-source");
|
||||
expect(doubleClickRowAction(row("TYPE", "app_status"), "xugu")).toBe("open-source");
|
||||
expect(singleClickRowAction(row("TYPE_BODY", "app_status"), "xugu")).toBe("open-source");
|
||||
for (const dbType of ["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"] as const) {
|
||||
// Verified PG-family TYPE rows open the read-only details panel.
|
||||
expect(singleClickRowAction(row("TYPE", "app_status"), dbType), String(dbType)).toBe("type-info");
|
||||
expect(doubleClickRowAction(row("TYPE", "app_status"), dbType), String(dbType)).toBe("type-info");
|
||||
// TYPE_BODY has no backend getter on these databases.
|
||||
expect(singleClickRowAction(row("TYPE_BODY", "app_status"), dbType), String(dbType)).toBe("none");
|
||||
}
|
||||
// Unknown connection type keeps the conservative no-action behavior.
|
||||
expect(singleClickRowAction(row("TYPE", "app_status"), undefined)).toBe("none");
|
||||
expect(doubleClickRowAction(row("TYPE", "app_status"), undefined)).toBe("none");
|
||||
});
|
||||
|
||||
it("keeps source actions for non-type rows on PG-family databases", () => {
|
||||
for (const type of ["VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "TRIGGER", "SEQUENCE", "PACKAGE", "PACKAGE_BODY"] as const) {
|
||||
expect(singleClickRowAction(row(type), "postgres"), type).toBe("open-source");
|
||||
}
|
||||
});
|
||||
|
||||
it("returns none for null/undefined", () => {
|
||||
|
||||
@@ -95,6 +95,27 @@ describe("PostgreSQL overloaded routines", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("PostgreSQL custom type metadata", () => {
|
||||
it("preserves type kind and member capability in simple and grouped trees", () => {
|
||||
const objects: ObjectInfo[] = [
|
||||
{ name: "address", object_type: "TYPE", schema: "public", custom_type_kind: "composite", has_members: true },
|
||||
{ name: "email", object_type: "TYPE", schema: "public", custom_type_kind: "domain", has_members: false },
|
||||
];
|
||||
|
||||
const simple = buildSimpleObjectTreeNodes({ ...context, schema: "public", objects });
|
||||
expect(simple.map((node) => ({ name: node.label, kind: node.customTypeKind, hasMembers: node.hasMembers }))).toEqual([
|
||||
{ name: "address", kind: "composite", hasMembers: true },
|
||||
{ name: "email", kind: "domain", hasMembers: false },
|
||||
]);
|
||||
|
||||
const grouped = buildGroupedObjectTreeNodes({ ...context, schema: "public", objects });
|
||||
expect(grouped.find((node) => node.type === "group-types")?.children?.map((node) => ({ name: node.label, kind: node.customTypeKind, hasMembers: node.hasMembers }))).toEqual([
|
||||
{ name: "address", kind: "composite", hasMembers: true },
|
||||
{ name: "email", kind: "domain", hasMembers: false },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("programmable database objects", () => {
|
||||
it("keeps Xugu trigger/type nodes distinct and preserves an invalid status", () => {
|
||||
const objects: ObjectInfo[] = [
|
||||
@@ -156,6 +177,22 @@ describe("programmable database objects", () => {
|
||||
expect(synonymGroup).toEqual(expect.objectContaining({ objectCount: 1, label: "tree.synonyms" }));
|
||||
expect(synonymGroup?.children).toEqual([expect.objectContaining({ type: "synonym", objectName: "SYN_SHOP_USERS", valid: true })]);
|
||||
});
|
||||
|
||||
it("groups user-defined types with an object count", () => {
|
||||
const objects: ObjectInfo[] = [
|
||||
{ name: "status", object_type: "TYPE", schema: "app", comment: "order status" },
|
||||
{ name: "email", object_type: "TYPE", schema: "app" },
|
||||
];
|
||||
|
||||
const groups = buildGroupedObjectTreeNodes({ ...context, schema: "app", objects });
|
||||
const typeGroup = groups.find((node) => node.type === "group-types");
|
||||
|
||||
expect(typeGroup).toEqual(expect.objectContaining({ objectCount: 2, label: "tree.types" }));
|
||||
expect(typeGroup?.children?.map((node) => node.type)).toEqual(["type", "type"]);
|
||||
expect(typeGroup?.children?.map((node) => node.objectName)).toEqual(["email", "status"]);
|
||||
expect(typeGroup?.children?.[0]?.comment).toBeUndefined();
|
||||
expect(typeGroup?.children?.[1]?.comment).toBe("order status");
|
||||
});
|
||||
});
|
||||
|
||||
describe("PostgreSQL table hierarchy", () => {
|
||||
|
||||
@@ -157,6 +157,7 @@ export const listObjectStatistics = forward("listObjectStatistics");
|
||||
export const listCompletionObjects = forward("listCompletionObjects");
|
||||
export const completionAssistantSearch = forward("completionAssistantSearch");
|
||||
export const getObjectSource = forward("getObjectSource");
|
||||
export const getCustomTypeDetails = forward("getCustomTypeDetails");
|
||||
export const getColumns = forward("getColumns");
|
||||
export const getAllColumns = forward("getAllColumns");
|
||||
export const getSqlServerColumnMetadata = forward("getSqlServerColumnMetadata");
|
||||
|
||||
@@ -14,6 +14,7 @@ import type {
|
||||
CompletionAssistantRequest,
|
||||
CompletionAssistantResponse,
|
||||
ObjectStatistics,
|
||||
CustomTypeDetails,
|
||||
ObjectSource,
|
||||
ObjectSourceKind,
|
||||
ColumnInfo,
|
||||
@@ -742,6 +743,10 @@ export async function getObjectSource(connectionId: string, database: string, sc
|
||||
return get(`/api/schema/object-source?${qs({ connection_id: connectionId, database, schema, table: name, object_type: objectType, signature, relation_name: relationName })}`);
|
||||
}
|
||||
|
||||
export async function getCustomTypeDetails(connectionId: string, database: string, schema: string, name: string): Promise<CustomTypeDetails> {
|
||||
return get(`/api/schema/custom-type-details?${qs({ connection_id: connectionId, database, schema, table: name })}`);
|
||||
}
|
||||
|
||||
export async function getColumns(connectionId: string, database: string, schema: string, table: string, catalog?: string, clientSessionId?: string): Promise<ColumnInfo[]> {
|
||||
return get(`/api/schema/columns?${qs({ connection_id: connectionId, database, schema, table, catalog, client_session_id: clientSessionId })}`);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import type {
|
||||
CompletionAssistantRequest,
|
||||
CompletionAssistantResponse,
|
||||
ObjectStatistics,
|
||||
CustomTypeDetails,
|
||||
ObjectSource,
|
||||
ObjectSourceKind,
|
||||
ColumnInfo,
|
||||
@@ -1055,6 +1056,9 @@ export async function listSchemaInfos(connectionId: string, database: string): P
|
||||
return invoke("list_schema_infos", { connectionId, database });
|
||||
}
|
||||
|
||||
export async function getCustomTypeDetails(connectionId: string, database: string, schema: string, name: string): Promise<CustomTypeDetails> {
|
||||
return invoke("get_custom_type_details", { connectionId, database, schema, name });
|
||||
}
|
||||
export async function getColumns(connectionId: string, database: string, schema: string, table: string, catalog?: string, clientSessionId?: string): Promise<ColumnInfo[]> {
|
||||
return invoke("get_columns", {
|
||||
connectionId,
|
||||
|
||||
@@ -13,7 +13,21 @@ const TABLE_VIEW_MV_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZ
|
||||
|
||||
const ROUTINE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "PROCEDURE", "FUNCTION"];
|
||||
|
||||
const POSTGRES_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE"];
|
||||
// PostgreSQL-family databases with a verified pg_type listing path. TYPE only
|
||||
// covers user-created types (enum/domain/composite/range/multirange/base);
|
||||
// relation auto-generated row types stay hidden.
|
||||
const POSTGRES_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE", "TYPE"];
|
||||
|
||||
// KWDB is routed through the PostgreSQL pool but its pg_type catalog
|
||||
// compatibility is not verified yet, so it stays on the pre-TYPE object set.
|
||||
const POSTGRES_NO_TYPE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE"];
|
||||
|
||||
// Kingbase and Vastbase agents support the same user-defined type listing via
|
||||
// their own metadata query, but do not expose sequences. Kept separate from
|
||||
// POSTGRES_OBJECTS and POSTGRES_LIKE_OBJECTS so unverified PG-like databases
|
||||
// (highgo/uxdb/redshift) never advertise TYPE.
|
||||
const KINGBASE_VASTBASE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "TYPE"];
|
||||
|
||||
const POSTGRES_LIKE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION"];
|
||||
const ORACLE_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "PACKAGE", "PACKAGE_BODY"];
|
||||
const DAMENG_OBJECTS: SidebarObjectKind[] = ["TABLE", "VIEW", "MATERIALIZED_VIEW", "PROCEDURE", "FUNCTION", "SEQUENCE", "PACKAGE", "PACKAGE_BODY"];
|
||||
@@ -24,13 +38,13 @@ const DATABASE_TYPE_OBJECTS = new Map<DatabaseType, SidebarObjectKind[]>([
|
||||
// postgres
|
||||
["postgres", POSTGRES_OBJECTS],
|
||||
["gaussdb", POSTGRES_OBJECTS],
|
||||
["kwdb", POSTGRES_OBJECTS],
|
||||
["kwdb", POSTGRES_NO_TYPE_OBJECTS],
|
||||
["opengauss", POSTGRES_OBJECTS],
|
||||
// postgres like
|
||||
["kingbase", POSTGRES_LIKE_OBJECTS],
|
||||
["kingbase", KINGBASE_VASTBASE_OBJECTS],
|
||||
["highgo", POSTGRES_LIKE_OBJECTS],
|
||||
["uxdb", POSTGRES_LIKE_OBJECTS],
|
||||
["vastbase", POSTGRES_LIKE_OBJECTS],
|
||||
["vastbase", KINGBASE_VASTBASE_OBJECTS],
|
||||
["redshift", POSTGRES_LIKE_OBJECTS],
|
||||
// oracle
|
||||
["oracle", ORACLE_OBJECTS],
|
||||
@@ -69,11 +83,22 @@ const DATABASE_TYPE_OBJECTS = new Map<DatabaseType, SidebarObjectKind[]>([
|
||||
["manticoresearch", ["TABLE", "FUNCTION"]],
|
||||
["databend", ["TABLE", "VIEW", "PROCEDURE"]],
|
||||
]);
|
||||
/**
|
||||
* Whether a kind is readable as object source for the given connection type.
|
||||
* TYPE/TYPE_BODY only have a real source implementation on Xugu; PostgreSQL-
|
||||
* family databases list types without a CREATE TYPE getter this cycle.
|
||||
*/
|
||||
function isSourceReadableObjectKind(kind: SidebarObjectKind, dbType?: DatabaseType): boolean {
|
||||
if (kind === "TABLE") return false;
|
||||
if (kind === "TYPE" || kind === "TYPE_BODY") return supportsTypeObjectSource(dbType);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function databaseObjectCapabilities(dbType?: DatabaseType): DatabaseObjectCapabilities {
|
||||
const sidebarObjects = sidebarObjectKindsForDatabase(dbType);
|
||||
return {
|
||||
sidebarObjects,
|
||||
sourceReadable: sidebarObjects.filter((kind) => kind !== "TABLE"),
|
||||
sourceReadable: sidebarObjects.filter((kind) => isSourceReadableObjectKind(kind, dbType)),
|
||||
executable: sidebarObjects.filter((kind) => kind === "PROCEDURE"),
|
||||
};
|
||||
}
|
||||
@@ -83,6 +108,37 @@ export function sidebarObjectKindsForDatabase(dbType?: DatabaseType): SidebarObj
|
||||
return DATABASE_TYPE_OBJECTS.get(dbType) ?? [...ROUTINE_OBJECTS];
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a connection's TYPE tree nodes may be opened as object source.
|
||||
*
|
||||
* Xugu has a real TYPE/TYPE_BODY source implementation. PostgreSQL-family
|
||||
* databases only list user-defined types this cycle; their CREATE TYPE DDL has
|
||||
* no unified catalog getter, so opening source would error. Callers must gate
|
||||
* the source action (single/double click, context menu, shortcuts) on this
|
||||
* before dispatching getObjectSource.
|
||||
*/
|
||||
export function supportsTypeObjectSource(dbType?: DatabaseType): boolean {
|
||||
return dbType === "xugu";
|
||||
}
|
||||
|
||||
export type CustomTypeCapabilities = {
|
||||
details: boolean;
|
||||
members: boolean;
|
||||
ddl: boolean;
|
||||
};
|
||||
|
||||
const VERIFIED_CUSTOM_TYPE_DATABASES = new Set<DatabaseType>(["postgres", "opengauss", "gaussdb", "kingbase", "vastbase"]);
|
||||
|
||||
/**
|
||||
* Whether a connection may open read-only custom type details (phase 2).
|
||||
* Kept separate from the listing capability so a future per-kind DDL toggle
|
||||
* can be introduced without touching the object-list sets.
|
||||
*/
|
||||
export function customTypeCapabilities(dbType?: DatabaseType): CustomTypeCapabilities {
|
||||
const supported = !!dbType && VERIFIED_CUSTOM_TYPE_DATABASES.has(dbType);
|
||||
return { details: supported, members: supported, ddl: supported };
|
||||
}
|
||||
|
||||
export function supportsPackageMemberExpansion(dbType?: DatabaseType): boolean {
|
||||
return !!dbType && PACKAGE_MEMBER_EXPANSION_DATABASES.has(dbType);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import type { CustomTypeDetails, CustomTypeTreeMemberMeta, TreeNode } from "@/types/database";
|
||||
|
||||
function encodeMemberIdentity(value: string): string {
|
||||
return encodeURIComponent(value);
|
||||
}
|
||||
|
||||
function typeMemberNode(parent: TreeNode, identity: string, label: string, meta: CustomTypeTreeMemberMeta): TreeNode {
|
||||
return {
|
||||
id: `${parent.id}:type-member:${meta.kind}:${encodeMemberIdentity(identity)}`,
|
||||
label,
|
||||
type: "type-member",
|
||||
connectionId: parent.connectionId,
|
||||
database: parent.database,
|
||||
schema: parent.schema,
|
||||
catalog: parent.catalog,
|
||||
objectName: parent.objectName || parent.label,
|
||||
meta,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildCustomTypeTreeChildren(parent: TreeNode, details: CustomTypeDetails): TreeNode[] {
|
||||
if (details.kind === "composite") {
|
||||
return details.members.map((member) =>
|
||||
typeMemberNode(parent, member.name, member.name, {
|
||||
kind: "field",
|
||||
displayValue: member.dataType,
|
||||
ordinal: member.ordinal,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (details.kind === "enum") {
|
||||
return details.members.map((member) =>
|
||||
typeMemberNode(parent, member.enumValue || member.name, member.enumValue || member.name, {
|
||||
kind: "enum-value",
|
||||
ordinal: member.ordinal,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
@@ -10,8 +10,8 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
||||
"synonym",
|
||||
"package",
|
||||
"package-body",
|
||||
"type",
|
||||
"type-body",
|
||||
"type-member",
|
||||
"object-browser",
|
||||
"redis-db",
|
||||
"mq-tenant",
|
||||
@@ -34,7 +34,7 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
||||
|
||||
const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "mongo-collection", "mongo-bucket", "vector-collection", "elasticsearch-index"]);
|
||||
|
||||
const emptyContainerTypes: Set<TreeNodeType> = new Set(["saved-sql-root", "saved-sql-folder"]);
|
||||
const emptyContainerTypes: Set<TreeNodeType> = new Set(["saved-sql-root", "saved-sql-folder", "type"]);
|
||||
|
||||
const pinnableTypes: Set<TreeNodeType> = new Set([
|
||||
"connection-group",
|
||||
@@ -157,7 +157,11 @@ export function canTreeNodeExpand(type: TreeNodeType): boolean {
|
||||
|
||||
export function canTreeNodeShowExpander({ type, childCount, explicitContainer = false }: { type: TreeNodeType; childCount?: number; explicitContainer?: boolean }): boolean {
|
||||
if (!canTreeNodeExpand(type) && !((type === "package" || type === "type") && explicitContainer)) return false;
|
||||
if (childCount === 0 && emptyContainerTypes.has(type)) return false;
|
||||
// An empty type node only hides its expander when it is not an explicitly
|
||||
// marked container. Xugu TYPE specifications use explicitContainer to lazy
|
||||
// load members even when childCount is currently 0; PostgreSQL-family types
|
||||
// without members rely on the caller's hasMembers gate instead.
|
||||
if (childCount === 0 && emptyContainerTypes.has(type) && !explicitContainer) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ObjectSourceKind, TreeNode, TreeNodeType } from "@/types/database";
|
||||
import type { DatabaseType, ObjectSourceKind, TreeNode, TreeNodeType } from "@/types/database";
|
||||
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
import { matchesShortcut, type ShortcutLikeEvent } from "@/lib/editor/keyboardShortcuts";
|
||||
|
||||
export type TreeNodeRowAction = "open-data" | "open-source" | "open-extension-details" | "toggle" | "none";
|
||||
@@ -88,12 +89,25 @@ export function isDocumentBrowserTreeNode(type: TreeNodeType): boolean {
|
||||
return documentBrowserNodeTypes.has(type);
|
||||
}
|
||||
|
||||
export function treeNodeRowAction(type: TreeNodeType, canExpand: boolean, activation: SidebarActivation = "single"): TreeNodeRowAction {
|
||||
/**
|
||||
* Whether a tree node type may open an object source dialog for the given
|
||||
* connection type. TYPE/TYPE_BODY only have a real source implementation on
|
||||
* Xugu; other databases list types without a DDL getter this cycle.
|
||||
*/
|
||||
function canOpenTreeNodeSource(type: TreeNodeType, dbType?: DatabaseType): boolean {
|
||||
if (type === "type" || type === "type-body") return supportsTypeObjectSource(dbType);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function treeNodeRowAction(type: TreeNodeType, canExpand: boolean, activation: SidebarActivation = "single", dbType?: DatabaseType): TreeNodeRowAction {
|
||||
if (!shouldActivateTreeNodeOnSingleClick(type, activation)) return "none";
|
||||
if (type === "extension") return "open-extension-details";
|
||||
if (dataNodeTypes.has(type)) return "open-data";
|
||||
// PostgreSQL-family custom types: open read-only details (toggle when expandable).
|
||||
if (type === "type" && customTypeCapabilities(dbType).details) return canExpand ? "toggle" : "none";
|
||||
// Xugu and other databases: expandable package/type nodes toggle their members.
|
||||
if ((type === "package" || type === "type") && canExpand) return "toggle";
|
||||
if (sourceNodeTypes.has(type)) return "open-source";
|
||||
if (sourceNodeTypes.has(type) && canOpenTreeNodeSource(type, dbType)) return "open-source";
|
||||
if (toggleLeafNodeTypes.has(type)) return "toggle";
|
||||
if (canExpand) return "toggle";
|
||||
return "none";
|
||||
@@ -106,14 +120,15 @@ export function shouldRunTreeNodeRowAction(action: TreeNodeRowAction, clickDetai
|
||||
return action !== "none" && clickDetail <= 1;
|
||||
}
|
||||
|
||||
export function treeNodeRowDoubleClickAction(type: TreeNodeType, canOpenObjectBrowser: boolean, activation: SidebarActivation = "single", canExpand = false): TreeNodeRowDoubleClickAction {
|
||||
export function treeNodeRowDoubleClickAction(type: TreeNodeType, canOpenObjectBrowser: boolean, activation: SidebarActivation = "single", canExpand = false, dbType?: DatabaseType): TreeNodeRowDoubleClickAction {
|
||||
// Single-click activation already handles the first click in a dblclick
|
||||
// sequence. Only double-click activation needs a second-stage table action.
|
||||
if (type === "table") return activation === "double" ? "activate-data" : "none";
|
||||
if (activation === "double") {
|
||||
if (type === "extension") return "open-extension-details";
|
||||
if (dataNodeTypes.has(type)) return "open-data";
|
||||
if (sourceNodeTypes.has(type)) return "open-source";
|
||||
if (type === "type" && customTypeCapabilities(dbType).details) return canExpand ? "toggle" : "none";
|
||||
if (sourceNodeTypes.has(type) && canOpenTreeNodeSource(type, dbType)) return "open-source";
|
||||
if (savedSqlNodeTypes.has(type)) return "open-saved-sql";
|
||||
if (toggleLeafNodeTypes.has(type)) return "toggle";
|
||||
if (canOpenObjectBrowser && objectBrowserNodeTypes.has(type) && canExpand) return "open-object-browser-and-expand";
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||
import type { ObjectBrowserRow } from "@/lib/table/objectBrowserRows";
|
||||
|
||||
export type ObjectBrowserRowAction = "table-info" | "open-table" | "open-source" | "none";
|
||||
export type ObjectBrowserRowAction = "table-info" | "type-info" | "open-table" | "open-source" | "none";
|
||||
|
||||
/**
|
||||
* Determine the action for a single click on an object browser row.
|
||||
* - TABLE → table-info (show table properties panel)
|
||||
* - VIEW/MATERIALIZED_VIEW/PROCEDURE/FUNCTION/TRIGGER/SEQUENCE/PACKAGE/PACKAGE_BODY/TYPE/TYPE_BODY → open-source
|
||||
* - TYPE → type-info (read-only type details) on verified PG-family databases
|
||||
* - VIEW/MATERIALIZED_VIEW/PROCEDURE/FUNCTION/TRIGGER/SEQUENCE/PACKAGE/PACKAGE_BODY/TYPE_BODY → open-source
|
||||
* - otherwise → none
|
||||
*
|
||||
* TYPE/TYPE_BODY only open source for connections with a real type source
|
||||
* implementation (Xugu); other databases list types without a DDL getter.
|
||||
*/
|
||||
export function singleClickRowAction(row: ObjectBrowserRow | null | undefined): ObjectBrowserRowAction {
|
||||
export function singleClickRowAction(row: ObjectBrowserRow | null | undefined, dbType?: DatabaseType): ObjectBrowserRowAction {
|
||||
if (!row) return "none";
|
||||
if (row.type === "TABLE") return "table-info";
|
||||
if (canOpenSource(row)) return "open-source";
|
||||
if (row.type === "TYPE" && customTypeCapabilities(dbType).details) return "type-info";
|
||||
if (canOpenSource(row, dbType)) return "open-source";
|
||||
return "none";
|
||||
}
|
||||
|
||||
@@ -21,10 +28,11 @@ export function singleClickRowAction(row: ObjectBrowserRow | null | undefined):
|
||||
* - VIEW/MATERIALIZED_VIEW/PROCEDURE/FUNCTION/TRIGGER/SEQUENCE/PACKAGE/PACKAGE_BODY/TYPE/TYPE_BODY → open-source
|
||||
* - otherwise → none
|
||||
*/
|
||||
export function doubleClickRowAction(row: ObjectBrowserRow | null | undefined): ObjectBrowserRowAction {
|
||||
export function doubleClickRowAction(row: ObjectBrowserRow | null | undefined, dbType?: DatabaseType): ObjectBrowserRowAction {
|
||||
if (!row) return "none";
|
||||
if (row.type === "TABLE") return "open-table";
|
||||
if (canOpenSource(row)) return "open-source";
|
||||
if (row.type === "TYPE" && customTypeCapabilities(dbType).details) return "type-info";
|
||||
if (canOpenSource(row, dbType)) return "open-source";
|
||||
return "none";
|
||||
}
|
||||
|
||||
@@ -38,14 +46,14 @@ export function doubleClickRowAction(row: ObjectBrowserRow | null | undefined):
|
||||
* the caller defers the single-click via shouldDeferSingleClick so the second
|
||||
* click can cancel it.
|
||||
*/
|
||||
export function resolveRowClickAction(row: ObjectBrowserRow | null | undefined, detail: number, activation: "single" | "double"): { action: ObjectBrowserRowAction; isDouble: boolean } {
|
||||
export function resolveRowClickAction(row: ObjectBrowserRow | null | undefined, detail: number, activation: "single" | "double", dbType?: DatabaseType): { action: ObjectBrowserRowAction; isDouble: boolean } {
|
||||
if (activation === "double") {
|
||||
if (detail === 2) return { action: doubleClickRowAction(row), isDouble: true };
|
||||
return { action: singleClickRowAction(row), isDouble: false };
|
||||
if (detail === 2) return { action: doubleClickRowAction(row, dbType), isDouble: true };
|
||||
return { action: singleClickRowAction(row, dbType), isDouble: false };
|
||||
}
|
||||
// single-click activation
|
||||
if (detail > 1) return { action: doubleClickRowAction(row), isDouble: true };
|
||||
return { action: singleClickRowAction(row), isDouble: false };
|
||||
if (detail > 1) return { action: doubleClickRowAction(row, dbType), isDouble: true };
|
||||
return { action: singleClickRowAction(row, dbType), isDouble: false };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,6 +78,10 @@ export function isSourceOnlyObjectBrowserRow(row: ObjectBrowserRow): boolean {
|
||||
return row.type === "TRIGGER" || row.type === "SEQUENCE" || row.type === "PACKAGE" || row.type === "PACKAGE_BODY" || row.type === "TYPE" || row.type === "TYPE_BODY";
|
||||
}
|
||||
|
||||
function canOpenSource(row: ObjectBrowserRow): boolean {
|
||||
function canOpenSource(row: ObjectBrowserRow, dbType?: DatabaseType): boolean {
|
||||
// Verified PG-family TYPE rows open the read-only details panel instead;
|
||||
// Xugu keeps its source editor entry through supportsTypeObjectSource below.
|
||||
if (row.type === "TYPE" && customTypeCapabilities(dbType).details) return false;
|
||||
if ((row.type === "TYPE" || row.type === "TYPE_BODY") && !supportsTypeObjectSource(dbType)) return false;
|
||||
return row.type === "VIEW" || row.type === "MATERIALIZED_VIEW" || row.type === "PROCEDURE" || row.type === "FUNCTION" || row.type === "TRIGGER" || row.type === "SEQUENCE" || row.type === "PACKAGE" || row.type === "PACKAGE_BODY" || row.type === "TYPE" || row.type === "TYPE_BODY";
|
||||
}
|
||||
@@ -585,6 +585,8 @@ export function buildSimpleObjectTreeNodes({ nodeId, connectionId, database, sch
|
||||
type: simpleNodeType,
|
||||
objectName: name,
|
||||
signature: signature || undefined,
|
||||
customTypeKind: obj.custom_type_kind ?? undefined,
|
||||
hasMembers: obj.has_members ?? undefined,
|
||||
comment: obj.comment,
|
||||
valid: obj.valid ?? undefined,
|
||||
meta: objectType === "TRIGGER" ? (obj.trigger ?? undefined) : undefined,
|
||||
@@ -760,6 +762,8 @@ export function buildGroupedObjectTreeNodes({ nodeId, connectionId, database, sc
|
||||
type: childType,
|
||||
objectName: obj.name,
|
||||
signature: signature || undefined,
|
||||
customTypeKind: obj.custom_type_kind ?? undefined,
|
||||
hasMembers: obj.has_members ?? undefined,
|
||||
comment: obj.comment,
|
||||
valid: obj.valid ?? undefined,
|
||||
meta: objectType === "TRIGGER" ? (obj.trigger ?? undefined) : undefined,
|
||||
|
||||
Reference in new issue
Block a user