feat(xugu): expose public synonyms in an isolated scope
This commit is contained in:
1 parent
ab46f3fc72
commit
ea9a27ce11
11 files changed
+678
-39
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isXuguPublicSynonymScope, isXuguPublicSynonymTreeNode, XUGU_PUBLIC_SYNONYM_SCOPE, xuguSchemaDisplayName } from "@/lib/sidebar/xuguPublicSynonyms";
|
||||
|
||||
describe("Xugu public synonym scope", () => {
|
||||
it("uses an independent protocol identity", () => {
|
||||
expect(XUGU_PUBLIC_SYNONYM_SCOPE).not.toBe("GUEST");
|
||||
expect(XUGU_PUBLIC_SYNONYM_SCOPE.startsWith("\u0000")).toBe(true);
|
||||
expect(isXuguPublicSynonymScope(XUGU_PUBLIC_SYNONYM_SCOPE)).toBe(true);
|
||||
expect(isXuguPublicSynonymScope("GUEST")).toBe(false);
|
||||
expect(isXuguPublicSynonymScope("__DBX_XUGU_PUBLIC_SYNONYMS__")).toBe(false);
|
||||
});
|
||||
|
||||
it("only replaces the reserved key for display", () => {
|
||||
expect(xuguSchemaDisplayName(XUGU_PUBLIC_SYNONYM_SCOPE)).toBe("Public synonyms");
|
||||
expect(xuguSchemaDisplayName("GUEST")).toBe("GUEST");
|
||||
expect(xuguSchemaDisplayName("AppSchema")).toBe("AppSchema");
|
||||
});
|
||||
|
||||
it("identifies only the synthetic Xugu schema tree node", () => {
|
||||
expect(isXuguPublicSynonymTreeNode("xugu", "schema", XUGU_PUBLIC_SYNONYM_SCOPE)).toBe(true);
|
||||
expect(isXuguPublicSynonymTreeNode("xugu", "schema", "__DBX_XUGU_PUBLIC_SYNONYMS__")).toBe(false);
|
||||
expect(isXuguPublicSynonymTreeNode("postgres", "schema", XUGU_PUBLIC_SYNONYM_SCOPE)).toBe(false);
|
||||
expect(isXuguPublicSynonymTreeNode("xugu", "database", XUGU_PUBLIC_SYNONYM_SCOPE)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Xugu public synonyms do not belong to a user schema. The agent exposes
|
||||
* them through this reserved protocol scope so the schema tree can keep a
|
||||
* real schema named GUEST independent from database-global aliases.
|
||||
*/
|
||||
export const XUGU_PUBLIC_SYNONYM_SCOPE = "\u0000DBX_XUGU_PUBLIC_SYNONYMS";
|
||||
export const XUGU_PUBLIC_SYNONYM_SCOPE_LABEL = "Public synonyms";
|
||||
|
||||
export function isXuguPublicSynonymScope(schema: string | null | undefined): boolean {
|
||||
return schema === XUGU_PUBLIC_SYNONYM_SCOPE;
|
||||
}
|
||||
|
||||
export function xuguSchemaDisplayName(schema: string): string {
|
||||
return isXuguPublicSynonymScope(schema) ? XUGU_PUBLIC_SYNONYM_SCOPE_LABEL : schema;
|
||||
}
|
||||
|
||||
export function isXuguPublicSynonymTreeNode(databaseType: string | null | undefined, nodeType: string, schema: string | null | undefined): boolean {
|
||||
return databaseType === "xugu" && nodeType === "schema" && isXuguPublicSynonymScope(schema);
|
||||
}
|
||||
Reference in new issue
Block a user