feat(plugins): expose read-only estimated plan host api

This commit is contained in:
jearhe authored and GitHub committed 2026-09-20 17:15:52 +08:00
1 parent ea16af7f28
commit f909f85075
23 files changed
+2059 -17

No files matched your search

+6
View File
@@ -23,6 +23,10 @@ async function getBackend(): Promise<Backend> {
// ---------------------------------------------------------------------------
function forward<K extends keyof Backend>(name: K): Backend[K] {
// SAFETY: the resolved module is one of exactly two implementations of the same
// surface — `http.ts` imports its request/response types from `tauri.ts` on
// purpose, so both transports are kept signature-compatible by construction.
// TypeScript cannot express that cross-module equivalence, hence the cast.
return (async (...args: unknown[]) => {
const startedAt = performance.now();
const operation = String(name);
@@ -262,6 +266,8 @@ export const prepareQueryPaginationExecutionPlan = forward("prepareQueryPaginati
export const buildSortedQuerySql = forward("buildSortedQuerySql");
export const buildExplainSql = forward("buildExplainSql");
export const getExplainInfo = forward("getExplainInfo");
export const getPluginPlanCapabilities = forward("getPluginPlanCapabilities");
export const getPluginEstimatedPlan = forward("getPluginEstimatedPlan");
export const buildCreateUserSql = forward("buildCreateUserSql");
export const buildDroppedFilePreviewSql = forward("buildDroppedFilePreviewSql");
export const buildTableSelectSql = forward("buildTableSelectSql");
+17 -1
View File
@@ -160,6 +160,9 @@ import type {
QuerySqlBuildResult,
BuildExplainSqlOptions,
ExplainSqlBuildResult,
PluginPlanCapabilities,
PluginPlanRequest,
PluginPlanResult,
DroppedFilePreviewSqlOptions,
MongoGridFsFileInfo,
AppSupportInfo,
@@ -1567,6 +1570,19 @@ export async function getExplainInfo(connectionId: string, database: string | un
});
}
/** Plugin Host API: what the host and this connection can plan. Never connects. */
export async function getPluginPlanCapabilities(connectionId: string): Promise<PluginPlanCapabilities> {
return post<PluginPlanCapabilities>("/api/query/plugin-plan-capabilities", { connectionId });
}
/**
* Plugin Host API: acquires the estimated plan for caller-supplied SQL. The
* backend generates and owns the EXPLAIN statement; the request cannot carry one.
*/
export async function getPluginEstimatedPlan(request: PluginPlanRequest): Promise<PluginPlanResult> {
return post<PluginPlanResult>("/api/query/plugin-estimated-plan", request);
}
export async function buildDroppedFilePreviewSql(options: DroppedFilePreviewSqlOptions): Promise<string | undefined> {
const result = await post<string | null>("/api/query/build-dropped-file-preview-sql", { options });
return result ?? undefined;
@@ -4493,7 +4509,7 @@ export async function elasticsearchCountDocuments(connectionId: string, index: s
});
}
export async function elasticsearchGetIndexMetadata(connectionId: string, index: string, kind: ElasticsearchIndexMetadataKind): Promise<Record<string, any>> {
export async function elasticsearchGetIndexMetadata(connectionId: string, index: string, kind: ElasticsearchIndexMetadataKind): Promise<Record<string, unknown>> {
return post("/api/document-store/elasticsearch/index-metadata", {
connectionId,
index,
+19 -1
View File
@@ -3,6 +3,9 @@ import type { MongoDumpFormat, MongoDumpSourceInput, MongoDumpCatalog, MongoRest
import type { MongoRestoreUpload, MongoSourceReadOptions } from "./mongodbDumpTypes";
import { assertUpdateAllowsCommand } from "@/lib/app/updatePreparation";
import { collectBrowserSupportInfo } from "@/lib/app/supportInfo";
// Re-exported below so the HTTP transport shares one definition; imported here
// for this module's own signatures (a re-export does not bind local names).
import type { PluginPlanCapabilities, PluginPlanRequest, PluginPlanResult } from "@/types/pluginPlan";
function invoke<T>(command: string, args?: Record<string, unknown>): Promise<T> {
assertUpdateAllowsCommand(command);
@@ -791,6 +794,8 @@ export async function saveMaxRetries(maxRetries: number): Promise<void> {
}
export type { OpenTabsStatePayload, PersistedEditorGroup } from "@/lib/app/openTabsPersistence";
/** Shared with `@/lib/plugins/pluginHostBridge`; re-exported so the HTTP transport reuses one definition. */
export type { PluginPlanCapabilities, PluginPlanRequest, PluginPlanResult } from "@/types/pluginPlan";
import type { OpenTabsStatePayload } from "@/lib/app/openTabsPersistence";
import { uuid } from "@/lib/common/utils";
@@ -1807,6 +1812,19 @@ export async function getExplainInfo(connectionId: string, database: string | un
});
}
/** Plugin Host API: what the host and this connection can plan. Never connects. */
export async function getPluginPlanCapabilities(connectionId: string): Promise<PluginPlanCapabilities> {
return invoke<PluginPlanCapabilities>("get_plugin_plan_capabilities", { connectionId });
}
/**
* Plugin Host API: acquires the estimated plan for caller-supplied SQL. The
* backend generates and owns the EXPLAIN statement; the request cannot carry one.
*/
export async function getPluginEstimatedPlan(request: PluginPlanRequest): Promise<PluginPlanResult> {
return invoke<PluginPlanResult>("get_plugin_estimated_plan", { request });
}
export async function buildDroppedFilePreviewSql(options: DroppedFilePreviewSqlOptions): Promise<string | undefined> {
const result = await invoke<string | null>("build_dropped_file_preview_sql", {
options,
@@ -4291,7 +4309,7 @@ export interface ElasticsearchDeleteByQueryResult {
failures: string[];
}
export async function elasticsearchGetIndexMetadata(connectionId: string, index: string, kind: ElasticsearchIndexMetadataKind): Promise<Record<string, any>> {
export async function elasticsearchGetIndexMetadata(connectionId: string, index: string, kind: ElasticsearchIndexMetadataKind): Promise<Record<string, unknown>> {
return invoke("elasticsearch_get_index_metadata", {
connectionId,
index,