feat(easysearch): add first-class database support

This commit is contained in:
t8y2 committed 2026-07-30 19:03:09 +08:00
1 parent daf6bce72b
commit 350096b4f7
80 files changed
+875 -107

No files matched your search

@@ -0,0 +1,19 @@
import { describe, expect, it } from "vitest";
import { documentStoreProviderFor } from "@/lib/app/documentStoreProvider";
describe("Easysearch document store provider", () => {
it("uses the Elasticsearch-compatible document provider", () => {
const provider = documentStoreProviderFor("easysearch");
expect(provider.kind).toBe("elasticsearch");
expect(
provider.queryPreview({
collection: "orders",
filterJson: '{"status":"paid"}',
sortJson: '{"created_at":-1}',
skip: 0,
limit: 100,
}),
).toContain("POST /orders/_search");
});
});
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import { connectionProfileForScheme, parseConnectionUrl } from "@/lib/connection/connectionUrl";
describe("Easysearch connection URLs", () => {
it("parses the dedicated Easysearch scheme", () => {
expect(parseConnectionUrl("easysearch://dbx_test:secret@easysearch.example.com:9200")).toMatchObject({
dbType: "easysearch",
driverProfile: "easysearch",
driverLabel: "Easysearch",
host: "easysearch.example.com",
port: 9200,
username: "dbx_test",
password: "secret",
ssl: false,
});
});
it("keeps Easysearch selected for HTTPS URLs", () => {
expect(parseConnectionUrl("https://easysearch.example.com:9443", "easysearch")).toMatchObject({
dbType: "easysearch",
driverProfile: "easysearch",
port: 9443,
ssl: true,
});
});
it("exposes the Easysearch scheme profile", () => {
expect(connectionProfileForScheme("easysearch")).toEqual({
type: "easysearch",
profile: "easysearch",
label: "Easysearch",
defaultPort: 9200,
});
});
});
@@ -40,6 +40,7 @@ describe("dataGridColumnNameCopy", () => {
expect(supportsColumnNameQuoting("mongodb")).toBe(false);
expect(supportsColumnNameQuoting("redis")).toBe(false);
expect(supportsColumnNameQuoting("elasticsearch")).toBe(false);
expect(supportsColumnNameQuoting("easysearch")).toBe(false);
expect(supportsColumnNameQuoting("qdrant")).toBe(false);
expect(supportsColumnNameQuoting("jdbc")).toBe(false);
expect(supportsColumnNameQuoting("iotdb")).toBe(false);
@@ -5,6 +5,7 @@ describe("dataGridPreviewLabelKey", () => {
it("offers a query preview for document databases that never emit SQL", () => {
expect(dataGridPreviewLabelKey("mongodb")).toBe("toolbar.previewQuery");
expect(dataGridPreviewLabelKey("elasticsearch")).toBe("toolbar.previewQuery");
expect(dataGridPreviewLabelKey("easysearch")).toBe("toolbar.previewQuery");
});
it("keeps the SQL wording for SQL databases", () => {
@@ -73,6 +73,7 @@ describe("supportsSqlInListPaste", () => {
expect(supportsSqlInListPaste("redis")).toBe(false);
expect(supportsSqlInListPaste("mongodb")).toBe(false);
expect(supportsSqlInListPaste("elasticsearch")).toBe(false);
expect(supportsSqlInListPaste("easysearch")).toBe(false);
expect(supportsSqlInListPaste("qdrant")).toBe(false);
expect(supportsSqlInListPaste("milvus")).toBe(false);
expect(supportsSqlInListPaste("weaviate")).toBe(false);
@@ -16,4 +16,11 @@ describe("Elasticsearch JSON response detection", () => {
body: '[{"index":"data_pack_and_box_index_v1","docs.count":"42"}]',
});
});
it("routes Easysearch REST responses through the same JSON renderer", () => {
expect(elasticsearchJsonResponseForResult("easysearch", "GET /_cat/indices", catJsonResult)).toEqual({
status: 200,
body: '[{"index":"data_pack_and_box_index_v1","docs.count":"42"}]',
});
});
});
@@ -428,8 +428,10 @@ POST /orders/_search
HEAD /orders`;
expect(rangeSqlTexts(splitSqlStatementRanges(sql, "elasticsearch"))).toEqual(["GET /_nodes/stats/jvm?pretty", 'POST /orders/_search\n{\n "query": { "match_all": {} }\n}', "HEAD /orders"]);
expect(hasMultipleExecutionTargets(sql, "elasticsearch")).toBe(true);
for (const databaseType of ["elasticsearch", "easysearch"] as const) {
expect(rangeSqlTexts(splitSqlStatementRanges(sql, databaseType))).toEqual(["GET /_nodes/stats/jvm?pretty", 'POST /orders/_search\n{\n "query": { "match_all": {} }\n}', "HEAD /orders"]);
expect(hasMultipleExecutionTargets(sql, databaseType)).toBe(true);
}
});
it("targets the Elasticsearch request following a comment", () => {
@@ -1178,6 +1180,7 @@ describe("supportsExecutionTargetPicker", () => {
expect(supportsExecutionTargetPicker("redis")).toBe(true);
expect(supportsExecutionTargetPicker("mongodb")).toBe(false);
expect(supportsExecutionTargetPicker("elasticsearch")).toBe(true);
expect(supportsExecutionTargetPicker("easysearch")).toBe(true);
expect(supportsExecutionTargetPicker("qdrant")).toBe(false);
expect(supportsExecutionTargetPicker("milvus")).toBe(false);
expect(supportsExecutionTargetPicker("weaviate")).toBe(false);
@@ -1,6 +1,6 @@
import type { ComposerTranslation } from "vue-i18n";
import { normalizeJsonArgument } from "@dbx-app/mongo-shell";
import type { DatabaseType } from "@/types/database";
import { isElasticsearchCompatibleDatabaseType, type DatabaseType } from "@/types/database";
import { quoteUnquotedObjectKeys } from "@/lib/mongo/mongoShellCommand";
import { formatMongoShellLiteral } from "@/lib/mongo/mongoDocumentValues";
@@ -114,7 +114,7 @@ const elasticsearchDocumentProvider: DocumentStoreProvider = {
};
export function documentStoreProviderFor(databaseType?: DatabaseType): DocumentStoreProvider {
return databaseType === "elasticsearch" ? elasticsearchDocumentProvider : mongoDocumentProvider;
return isElasticsearchCompatibleDatabaseType(databaseType) ? elasticsearchDocumentProvider : mongoDocumentProvider;
}
export function defaultDocumentFilterRule(id: string, fieldName = ""): DocumentFilterRule {
@@ -135,6 +135,7 @@ export function connectionUrlPlaceholder(dbType: DatabaseType): string {
return "oracle://user:password@host:port/service_name";
case "elasticsearch":
case "easysearch":
case "qdrant":
case "milvus":
case "weaviate":
@@ -45,6 +45,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
mssql: { type: "sqlserver", profile: "sqlserver", label: "SQL Server", defaultPort: 1433 },
oracle: { type: "oracle", profile: "oracle", label: "Oracle", defaultPort: 1521 },
elasticsearch: { type: "elasticsearch", profile: "elasticsearch", label: "Elasticsearch", defaultPort: 9200 },
easysearch: { type: "easysearch", profile: "easysearch", label: "Easysearch", defaultPort: 9200 },
qdrant: { type: "qdrant", profile: "qdrant", label: "Qdrant", defaultPort: 6333 },
milvus: { type: "milvus", profile: "milvus", label: "Milvus", defaultPort: 19530 },
weaviate: { type: "weaviate", profile: "weaviate", label: "Weaviate", defaultPort: 8080 },
@@ -72,6 +73,7 @@ const SCHEME_PROFILES: Record<string, ConnectionProfile> = {
const HTTP_SELECTED_PROFILES: Record<string, ConnectionProfile> = {
clickhouse: SCHEME_PROFILES.clickhouse,
elasticsearch: SCHEME_PROFILES.elasticsearch,
easysearch: SCHEME_PROFILES.easysearch,
qdrant: SCHEME_PROFILES.qdrant,
milvus: SCHEME_PROFILES.milvus,
weaviate: SCHEME_PROFILES.weaviate,
@@ -5,7 +5,7 @@ const DRAFT_VISIBLE_DATABASES_PREFIX = "__visible_draft_";
// Turso and Cloudflare D1 connections target one fixed SQLite-compatible `main` namespace;
// listing account-level databases requires separate platform credentials, not the database connection.
const UNSUPPORTED_VISIBLE_DATABASE_TYPES = new Set<DatabaseType>(["turso", "cloudflare-d1", "elasticsearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper"]);
const UNSUPPORTED_VISIBLE_DATABASE_TYPES = new Set<DatabaseType>(["turso", "cloudflare-d1", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper"]);
type VisibleDatabaseConnectionFields = Pick<
ConnectionConfig,
@@ -25,7 +25,7 @@ export function isColumnNameCopySeparator(value: unknown): value is ColumnNameCo
}
// SQL 执行能力是产品能力,不代表数据库支持 SQL 标识符引用。
const NON_SQL_DATABASE_TYPES = new Set<DatabaseType>(["redis", "mongodb", "elasticsearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos"]);
const NON_SQL_DATABASE_TYPES = new Set<DatabaseType>(["redis", "mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "nacos"]);
// quoteTableIdentifier 对 jdbc/iotdb 原样返回(无引用字符可用)。
const UNQUOTABLE_DATABASE_TYPES = new Set<DatabaseType>(["jdbc", "iotdb"]);
@@ -1,6 +1,6 @@
import type { DatabaseType } from "@/types/database";
const NON_SQL_PREVIEW_DATABASE_TYPES: ReadonlySet<DatabaseType> = new Set<DatabaseType>(["mongodb", "elasticsearch"]);
const NON_SQL_PREVIEW_DATABASE_TYPES: ReadonlySet<DatabaseType> = new Set<DatabaseType>(["mongodb", "elasticsearch", "easysearch"]);
export function dataGridPreviewLabelKey(databaseType?: DatabaseType): "toolbar.previewQuery" | "toolbar.previewSql" {
return databaseType && NON_SQL_PREVIEW_DATABASE_TYPES.has(databaseType) ? "toolbar.previewQuery" : "toolbar.previewSql";
@@ -28,6 +28,7 @@ export const DATABASE_NAMESPACE_CREATION_MATRIX = {
mongodb: { connection: "special" },
oracle: { deferred: "Oracle schemas are users; database creation is not a normal connected DDL action" },
elasticsearch: { deferred: "index creation is not modeled as database creation" },
easysearch: { deferred: "index creation is not modeled as database creation" },
hbase: { deferred: "namespace creation needs dedicated HBase namespace options" },
qdrant: { deferred: "collection creation is separate from database creation" },
milvus: { deferred: "collection/database lifecycle needs a dedicated vector workflow" },
@@ -29,6 +29,7 @@ export const DATABASE_PROPERTY_EDITING_MATRIX = {
mongodb: { deferred: "database options are not modeled as SQL database properties" },
oracle: { deferred: "Oracle database properties are instance/user/tablespace administration" },
elasticsearch: { deferred: "index settings are not database properties" },
easysearch: { deferred: "index settings are not database properties" },
hbase: { deferred: "namespace and table properties need a dedicated HBase workflow" },
qdrant: { deferred: "collection settings are not database properties" },
milvus: { deferred: "collection/database settings need a dedicated vector workflow" },
@@ -1,4 +1,4 @@
import type { DatabaseType, QueryResult } from "@/types/database";
import { isElasticsearchCompatibleDatabaseType, type DatabaseType, type QueryResult } from "@/types/database";
import { stripLeadingElasticsearchComments } from "@/lib/sql/sqlStatementRanges";
export interface ElasticsearchJsonResponse {
@@ -13,7 +13,7 @@ const ELASTICSEARCH_REST_STATEMENT = /^(?:GET|POST|PUT|DELETE|HEAD)\s+\S+/i;
* DBX asks unformatted CAT requests for JSON so they use this response panel.
*/
export function elasticsearchJsonResponseForResult(databaseType: DatabaseType | undefined, sourceStatement: string | undefined, result: QueryResult | undefined): ElasticsearchJsonResponse | undefined {
if (databaseType !== "elasticsearch" || !result || typeof sourceStatement !== "string") return undefined;
if (!isElasticsearchCompatibleDatabaseType(databaseType) || !result || typeof sourceStatement !== "string") return undefined;
if (!ELASTICSEARCH_REST_STATEMENT.test(stripLeadingElasticsearchComments(sourceStatement))) return undefined;
if (result.columns.length !== 2 || result.columns[0] !== "status" || result.columns[1] !== "response" || result.rows.length !== 1) return undefined;
@@ -59,6 +59,7 @@ const driverRefMap: Record<string, DriverProfile> = {
cockroachdb: { dbType: "postgres", profile: "cockroachdb", label: "CockroachDB", port: 26257, user: "root" },
redshift: { dbType: "redshift", profile: "redshift", label: "Redshift", port: 5439, user: "awsuser" },
elasticsearch: { dbType: "elasticsearch", profile: "elasticsearch", label: "Elasticsearch", port: 9200, user: "" },
easysearch: { dbType: "easysearch", profile: "easysearch", label: "Easysearch", port: 9200, user: "" },
h2: { dbType: "h2", profile: "h2", label: "H2", port: 9092, user: "sa" },
snowflake: { dbType: "snowflake", profile: "snowflake", label: "Snowflake", port: 443, user: "" },
kingbase: { dbType: "kingbase", profile: "kingbase", label: "KingbaseES", port: 54321, user: "SYSTEM" },
@@ -82,6 +83,7 @@ const productMap: Record<string, DriverProfile> = {
bigquery: { dbType: "bigquery", profile: "bigquery", label: "BigQuery", port: 443, user: "" },
redshift: { dbType: "redshift", profile: "redshift", label: "Redshift", port: 5439, user: "awsuser" },
elasticsearch: { dbType: "elasticsearch", profile: "elasticsearch", label: "Elasticsearch", port: 9200, user: "" },
easysearch: { dbType: "easysearch", profile: "easysearch", label: "Easysearch", port: 9200, user: "" },
snowflake: { dbType: "snowflake", profile: "snowflake", label: "Snowflake", port: 443, user: "" },
kingbase: { dbType: "kingbase", profile: "kingbase", label: "KingbaseES", port: 54321, user: "SYSTEM" },
};
@@ -52,6 +52,7 @@ const profileMap: Record<string, ConnectionProfile> = {
mongo: { dbType: "mongodb", profile: "mongodb", label: "MongoDB", port: 27017, user: "" },
redshift: { dbType: "redshift", profile: "redshift", label: "Redshift", port: 5439, user: "awsuser" },
elasticsearch: { dbType: "elasticsearch", profile: "elasticsearch", label: "Elasticsearch", port: 9200, user: "" },
easysearch: { dbType: "easysearch", profile: "easysearch", label: "Easysearch", port: 9200, user: "" },
doris: { dbType: "doris", profile: "doris", label: "Doris", port: 9030, user: "root" },
starrocks: { dbType: "starrocks", profile: "starrocks", label: "StarRocks", port: 9030, user: "root" },
dameng: { dbType: "dameng", profile: "dm", label: "达梦 Dameng", port: 5236, user: "SYSDBA" },
@@ -40,7 +40,7 @@ export function sortSidebarTreeChildrenForParent(parent: Pick<TreeNode, "type">,
const regularChildren = normalized.filter((child) => child.type !== "user-admin" && child.type !== "saved-sql-root");
const withConnectionUtilityOrder = (children: TreeNode[]) => [...savedSqlNodes, ...children, ...userAdminNodes];
if (databaseType === "mongodb" || databaseType === "elasticsearch" || databaseType === "qdrant" || databaseType === "milvus" || databaseType === "weaviate" || databaseType === "chromadb") {
if (databaseType === "mongodb" || databaseType === "elasticsearch" || databaseType === "easysearch" || databaseType === "qdrant" || databaseType === "milvus" || databaseType === "weaviate" || databaseType === "chromadb") {
return withConnectionUtilityOrder(sortByLabel(regularChildren));
}
@@ -198,7 +198,17 @@ export function areSqlSemanticDiagnosticsEqual(left: readonly SqlSemanticDiagnos
}
export function shouldRunSqlSemanticDiagnostics(sql: string, cursor: number, options: { databaseType?: DatabaseType } = {}): boolean {
if (options.databaseType === "mongodb" || options.databaseType === "elasticsearch" || options.databaseType === "qdrant" || options.databaseType === "milvus" || options.databaseType === "weaviate" || options.databaseType === "chromadb" || options.databaseType === "redis") return false;
if (
options.databaseType === "mongodb" ||
options.databaseType === "elasticsearch" ||
options.databaseType === "easysearch" ||
options.databaseType === "qdrant" ||
options.databaseType === "milvus" ||
options.databaseType === "weaviate" ||
options.databaseType === "chromadb" ||
options.databaseType === "redis"
)
return false;
const context = getSqlCompletionContext(sql, cursor, options);
if (context.exclusiveColumnSuggestions) return false;
if (context.qualifier) return false;
@@ -207,7 +217,17 @@ export function shouldRunSqlSemanticDiagnostics(sql: string, cursor: number, opt
}
export function isSqlSemanticDiagnosticInputContext(sql: string, cursor: number, options: { databaseType?: DatabaseType } = {}): boolean {
if (options.databaseType === "mongodb" || options.databaseType === "elasticsearch" || options.databaseType === "qdrant" || options.databaseType === "milvus" || options.databaseType === "weaviate" || options.databaseType === "chromadb" || options.databaseType === "redis") return false;
if (
options.databaseType === "mongodb" ||
options.databaseType === "elasticsearch" ||
options.databaseType === "easysearch" ||
options.databaseType === "qdrant" ||
options.databaseType === "milvus" ||
options.databaseType === "weaviate" ||
options.databaseType === "chromadb" ||
options.databaseType === "redis"
)
return false;
const context = getSqlCompletionContext(sql, cursor, options);
return context.exclusiveColumnSuggestions || !!context.qualifier || ((context.suggestTables || context.exclusiveTableSuggestions) && isCursorAfterTableTrigger(sql, cursor));
}
+14 -5
View File
@@ -1,7 +1,7 @@
import type { SqlExecutionCandidate } from "@/lib/sql/sqlExecutionTarget";
import { splitMongoCommandRanges } from "@/lib/mongo/mongoShellCommand";
import { readSqlBracedParameterAt, type SqlParameterOptions } from "@/lib/sql/sqlParameters";
import type { DatabaseType } from "@/types/database";
import { isElasticsearchCompatibleDatabaseType, type DatabaseType } from "@/types/database";
/**
* A contiguous range of SQL text expressed as document offsets plus the
@@ -13,10 +13,18 @@ export interface SqlTextRange {
sql: string;
}
const NON_SQL_EXECUTION_TARGET_TYPES: ReadonlySet<DatabaseType> = new Set(["mongodb", "elasticsearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "neo4j"]);
const ELASTICSEARCH_REST_REQUEST = /^(?:GET|POST|PUT|DELETE|HEAD)\s+\S+/i;
export function elasticsearchRestRequestRanges(sql: string, databaseType?: DatabaseType): SqlTextRange[] {
if (!isElasticsearchCompatibleDatabaseType(databaseType)) return [];
const requests = splitSqlStatementRanges(sql, databaseType);
return requests.length > 0 && requests.every((request) => ELASTICSEARCH_REST_REQUEST.test(request.sql)) ? requests : [];
}
const NON_SQL_EXECUTION_TARGET_TYPES: ReadonlySet<DatabaseType> = new Set(["mongodb", "elasticsearch", "easysearch", "qdrant", "milvus", "weaviate", "chromadb", "etcd", "zookeeper", "mq", "neo4j"]);
export function supportsExecutionTargetPicker(databaseType?: DatabaseType): boolean {
return !!databaseType && (databaseType === "redis" || databaseType === "elasticsearch" || !NON_SQL_EXECUTION_TARGET_TYPES.has(databaseType));
return !!databaseType && (databaseType === "redis" || isElasticsearchCompatibleDatabaseType(databaseType) || !NON_SQL_EXECUTION_TARGET_TYPES.has(databaseType));
}
export function hasMultipleExecutionTargets(sql: string, databaseType?: DatabaseType, parameterOptions?: SqlParameterOptions): boolean {
@@ -233,6 +241,7 @@ const DATABASE_SOFT_STATEMENT_KEYWORDS: Partial<Record<DatabaseType, readonly st
redis: [],
mongodb: [],
elasticsearch: [],
easysearch: [],
qdrant: [],
milvus: [],
weaviate: [],
@@ -274,7 +283,7 @@ const SAP_HANA_SCRIPT_BLOCK_TERMINATORS = new Set(["IF", "FOR", "WHILE"]);
* whitespace are excluded so editor highlights stay tight).
*/
export function splitSqlStatementRanges(sql: string, databaseType?: DatabaseType, parameterOptions?: SqlParameterOptions): RawStatement[] {
if (databaseType === "elasticsearch") {
if (isElasticsearchCompatibleDatabaseType(databaseType)) {
const requests = splitElasticsearchRestRequestRanges(sql);
if (requests) return requests;
}
@@ -567,7 +576,7 @@ export function statementRangeAtCursor(sql: string, cursorPos: number, databaseT
// Cursor in indentation or inter-statement whitespace immediately before
// the statement should still target that statement, while the returned
// execution range remains tight around the SQL text itself.
if (pos >= statement.hitFrom && pos < statement.from && (sql.slice(pos, statement.from).trim() === "" || (databaseType === "elasticsearch" && isElasticsearchRequestPreamble(sql.slice(statement.hitFrom, statement.from))))) {
if (pos >= statement.hitFrom && pos < statement.from && (sql.slice(pos, statement.from).trim() === "" || (isElasticsearchCompatibleDatabaseType(databaseType) && isElasticsearchRequestPreamble(sql.slice(statement.hitFrom, statement.from))))) {
const previous = statements[index - 1];
if (previous && isCursorInSameLineDelimiterGap(sql, previous.to, pos)) {
const previousSoftRanges = splitStatementRangeAtSoftStarts(sql, previous, databaseType, parameterOptions);
@@ -31,6 +31,12 @@ const capabilityByType: Partial<Record<DatabaseType, Partial<TableMetadataCapabi
triggers: false,
ddl: false,
},
easysearch: {
indexes: false,
foreignKeys: false,
triggers: false,
ddl: false,
},
hbase: {
indexes: false,
foreignKeys: false,