дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 01:57:13 +02:00
feat(plugins): expose database table menus and read-only schema (#7372)
Plugin API 1.20 adds wit/database.wit with describe-table behind the database.schema capability: a read-only view of a connected source's table (columns, keys, indexes) through DbManager::connected_table_details. Plugins can contribute database.table.context menu entries (needs_api 20) that receive the non-secret table identity and the when keys databaseDriver, databaseObjectKind, databaseSchema, databaseTable and databaseSelectionCount. Co-authored-by: gejun123456 <[email protected]>
Цей коміт міститься в:
1 джерело
abc5b2b2c6
коміт
b7c2d4eacb
201 files changed
+1180
-176
No files matched your search
@@ -0,0 +1,99 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
||||
import type { PluginInfo } from "@/bindings";
|
||||
import { registerAction } from "@/platform/actions";
|
||||
import { nodeMenu } from "@/features/database/treeMenu";
|
||||
import { useDatabase } from "@/features/database/store";
|
||||
import type { DbNode } from "@/features/database/nodes";
|
||||
import { defineBuiltinUiPoints } from "../points";
|
||||
import { clearUiContributions, syncUiContributions } from "../projection";
|
||||
import { pluginDatabaseTableMenuItems, type DatabaseTableContext } from "../uiPoints";
|
||||
|
||||
const initialDatabase = useDatabase.getState();
|
||||
let stop: () => void;
|
||||
let offs: (() => void)[];
|
||||
beforeEach(() => {
|
||||
stop = defineBuiltinUiPoints();
|
||||
offs = [];
|
||||
});
|
||||
afterEach(() => {
|
||||
useDatabase.setState(initialDatabase, true);
|
||||
clearUiContributions();
|
||||
stop();
|
||||
offs.forEach((off) => off());
|
||||
});
|
||||
const plugin = { id: "mapper", name: "Mapper generator", enabled: true, status: "active", icon: null } as PluginInfo;
|
||||
const table: DatabaseTableContext = {
|
||||
sourceId: "pg:inventory",
|
||||
catalog: null,
|
||||
schema: "public",
|
||||
table: "users",
|
||||
kind: "table",
|
||||
driver: "postgres",
|
||||
};
|
||||
function contribute(when?: string) {
|
||||
offs.push(registerAction({ id: "plugin.mapper.generate", title: "Generate mapper", run: () => {} }));
|
||||
syncUiContributions(
|
||||
[
|
||||
{
|
||||
pluginId: "mapper",
|
||||
point: "menus",
|
||||
key: "database.table.context/generate",
|
||||
decl: {
|
||||
menu: "database.table.context",
|
||||
command: "generate",
|
||||
submenu: "Generate",
|
||||
when,
|
||||
},
|
||||
},
|
||||
],
|
||||
[plugin],
|
||||
);
|
||||
}
|
||||
describe("database table plugin menu", () => {
|
||||
it("passes only non-secret table identities and checks when for every selected table", () => {
|
||||
contribute("databaseDriver == postgres && databaseObjectKind == table && databaseSelectionCount == 1");
|
||||
const [entry] = pluginDatabaseTableMenuItems([table]);
|
||||
expect(entry).toEqual({
|
||||
kind: "action",
|
||||
action: "plugin.mapper.generate",
|
||||
arg: JSON.stringify({ tables: [table] }),
|
||||
});
|
||||
expect(pluginDatabaseTableMenuItems([])).toEqual([]);
|
||||
expect(pluginDatabaseTableMenuItems([table, { ...table, table: "orders" }])).toEqual([]);
|
||||
expect(pluginDatabaseTableMenuItems([{ ...table, kind: "view" }])).toEqual([]);
|
||||
expect(pluginDatabaseTableMenuItems([{ ...table, driver: "mysql" }])).toEqual([]);
|
||||
});
|
||||
it("strips extra fields instead of serializing connection settings", () => {
|
||||
contribute();
|
||||
const injected = { ...table, password: "do-not-send", host: "private-host", url: "private-url" };
|
||||
const [entry] = pluginDatabaseTableMenuItems([injected]);
|
||||
expect(entry).toMatchObject({ arg: JSON.stringify({ tables: [table] }) });
|
||||
});
|
||||
it("appends commands to built-in table menus and retains a multi-catalog selection", () => {
|
||||
contribute();
|
||||
useDatabase.setState({ sources: [{ id: "duck", name: "Local", driver: "jdbc", vendor: "duckdb" }] });
|
||||
const a: DbNode = {
|
||||
kind: "table",
|
||||
key: "duck/a/main/users",
|
||||
id: "duck",
|
||||
catalog: "a",
|
||||
schema: "main",
|
||||
table: { name: "users", kind: "table" },
|
||||
};
|
||||
const b: DbNode = { ...a, key: "duck/b/main/users", catalog: "b" };
|
||||
const items = nodeMenu(a, [a, b]);
|
||||
expect(items.length).toBeGreaterThan(1);
|
||||
const entry = items.at(-1)!;
|
||||
expect(entry).toMatchObject({ action: "plugin.mapper.generate" });
|
||||
if (entry.kind !== "action") throw new Error("expected command");
|
||||
expect(JSON.parse(entry.arg as string).tables).toEqual([
|
||||
{ sourceId: "duck", catalog: "a", schema: "main", table: "users", kind: "table", driver: "jdbc" },
|
||||
{ sourceId: "duck", catalog: "b", schema: "main", table: "users", kind: "table", driver: "jdbc" },
|
||||
]);
|
||||
expect(
|
||||
nodeMenu(a, [{ kind: "schema", key: "duck/main", id: "duck", schema: "main" }, a]).some(
|
||||
(item) => item.kind === "action" && item.action === "plugin.mapper.generate",
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Заблокувати користувача