feat(meilisearch): add document and settings views
This commit is contained in:
1 parent
39ce50b681
commit
884744df4c
32 files changed
+3673
-57
No files matched your search
@@ -728,6 +728,15 @@ export const mongoUpdateDocument = forward("mongoUpdateDocument");
|
||||
export const mongoUpdateDocuments = forward("mongoUpdateDocuments");
|
||||
export const documentDeleteDocument = forward("documentDeleteDocument");
|
||||
export const documentSaveMeilisearchBatch = forward("documentSaveMeilisearchBatch");
|
||||
export const meilisearchSearchDocuments = forward("meilisearchSearchDocuments");
|
||||
export const meilisearchFetchDocuments = forward("meilisearchFetchDocuments");
|
||||
export const meilisearchGetDocument = forward("meilisearchGetDocument");
|
||||
export const meilisearchGetIndexSettings = forward("meilisearchGetIndexSettings");
|
||||
export const meilisearchUpdateIndexSettings = forward("meilisearchUpdateIndexSettings");
|
||||
export const meilisearchGetIndexStats = forward("meilisearchGetIndexStats");
|
||||
export const meilisearchGetIndexOverview = forward("meilisearchGetIndexOverview");
|
||||
export const meilisearchDeleteIndex = forward("meilisearchDeleteIndex");
|
||||
export const meilisearchDeleteAllDocuments = forward("meilisearchDeleteAllDocuments");
|
||||
export const mongoDeleteDocument = forward("mongoDeleteDocument");
|
||||
export const mongoDeleteDocuments = forward("mongoDeleteDocuments");
|
||||
export const mongoFindOneAndUpdate = forward("mongoFindOneAndUpdate");
|
||||
|
||||
@@ -47,6 +47,7 @@ import type {
|
||||
} from "@/types/database";
|
||||
import { normalizeRustMongoCommand, type MongoCommand } from "@/lib/mongo/mongoShellCommand";
|
||||
import { BackendErrorException, type BackendError } from "@/lib/backend/errorUtils";
|
||||
import { decodeMeilisearchDocumentPage, decodeMeilisearchSearchResult, type MeilisearchDocumentPage, type MeilisearchDocumentPageWire, type MeilisearchSearchResult, type MeilisearchSearchWireResult } from "@/lib/backend/meilisearchTransport";
|
||||
import type { CollectionInfo } from "@/types/database";
|
||||
import type { SchemaDiffPreparation, SchemaDiffPreparationOptions, TableDiff, FunctionDiff, SequenceDiff, RuleDiff, OwnerDiff } from "@/lib/schema/schemaDiff";
|
||||
import type { SidebarObjectKind } from "@/lib/database/databaseObjectCapabilities";
|
||||
@@ -139,6 +140,7 @@ import type {
|
||||
AppSupportInfo,
|
||||
PromptTemplate,
|
||||
SshPromptResolution,
|
||||
MeilisearchIndexOverview,
|
||||
} from "@/lib/backend/tauri";
|
||||
import type { QueryEditability } from "@/lib/sql/sqlAnalysis";
|
||||
import { isTerminalTransferProgress } from "@/lib/backend/transferProgress";
|
||||
@@ -3878,6 +3880,90 @@ export async function documentSaveMeilisearchBatch(connectionId: string, collect
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchSearchDocuments(
|
||||
connectionId: string,
|
||||
index: string,
|
||||
params: { q?: string | null; filter?: string | null; sort?: string | null; limit: number; offset: number; hybridEmbedder?: string | null; hybridSemanticRatio?: number | null; showRankingScore?: boolean; rankingScoreThreshold?: number | null },
|
||||
): Promise<MeilisearchSearchResult> {
|
||||
const result = await post<MeilisearchSearchWireResult>("/api/document-store/meilisearch/search", {
|
||||
connectionId,
|
||||
index,
|
||||
q: params.q ?? null,
|
||||
filter: params.filter ?? null,
|
||||
sort: params.sort ?? null,
|
||||
limit: params.limit,
|
||||
offset: params.offset,
|
||||
hybridEmbedder: params.hybridEmbedder ?? null,
|
||||
hybridSemanticRatio: params.hybridSemanticRatio ?? null,
|
||||
showRankingScore: params.showRankingScore ?? false,
|
||||
rankingScoreThreshold: params.rankingScoreThreshold ?? null,
|
||||
});
|
||||
return decodeMeilisearchSearchResult(result);
|
||||
}
|
||||
|
||||
export async function meilisearchFetchDocuments(connectionId: string, index: string, params: { filter?: string | null; sort?: string | null; limit: number; offset: number }): Promise<MeilisearchDocumentPage> {
|
||||
const page = await post<MeilisearchDocumentPageWire>("/api/document-store/meilisearch/documents/fetch", {
|
||||
connectionId,
|
||||
index,
|
||||
filter: params.filter ?? null,
|
||||
sort: params.sort ?? null,
|
||||
limit: params.limit,
|
||||
offset: params.offset,
|
||||
});
|
||||
return decodeMeilisearchDocumentPage(page);
|
||||
}
|
||||
|
||||
export async function meilisearchGetDocument(connectionId: string, index: string, id: string): Promise<string> {
|
||||
return post("/api/document-store/meilisearch/documents/get", {
|
||||
connectionId,
|
||||
index,
|
||||
id,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchGetIndexSettings(connectionId: string, index: string): Promise<Record<string, any>> {
|
||||
return post("/api/document-store/meilisearch/settings/get", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchUpdateIndexSettings(connectionId: string, index: string, settings: Record<string, any>): Promise<void> {
|
||||
return post("/api/document-store/meilisearch/settings/update", {
|
||||
connectionId,
|
||||
index,
|
||||
settings,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchGetIndexStats(connectionId: string, index: string): Promise<{ numberOfDocuments: number; isIndexing: boolean; fieldDistribution: Record<string, number> } & Record<string, any>> {
|
||||
return post("/api/document-store/meilisearch/stats", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchGetIndexOverview(connectionId: string, index: string): Promise<MeilisearchIndexOverview> {
|
||||
return post("/api/document-store/meilisearch/overview", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchDeleteIndex(connectionId: string, index: string): Promise<void> {
|
||||
return post("/api/document-store/meilisearch/index/delete", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchDeleteAllDocuments(connectionId: string, index: string): Promise<void> {
|
||||
return post("/api/document-store/meilisearch/documents/delete-all", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function mongoDeleteDocuments(connectionId: string, database: string, collection: string, filterJson: string, many: boolean): Promise<{ affected_rows: number }> {
|
||||
return post("/api/mongo/delete-documents", {
|
||||
connectionId,
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { serializeDocumentStoreId, stringifyDocumentStoreValue } from "@/lib/app/documentJsonValues";
|
||||
import { decodeMeilisearchDocumentPage, decodeMeilisearchSearchResult } from "./meilisearchTransport";
|
||||
|
||||
describe("Meilisearch transport", () => {
|
||||
it("keeps large integer identities and document JSON exact", () => {
|
||||
const result = decodeMeilisearchSearchResult({
|
||||
hits: [
|
||||
{
|
||||
idJson: "9007199254740993",
|
||||
documentJson: '{"movie_id":9007199254740993,"title":"Alien"}',
|
||||
},
|
||||
],
|
||||
totalHits: 1,
|
||||
processingTimeMs: 1,
|
||||
});
|
||||
|
||||
expect(serializeDocumentStoreId(result.hits[0].id, "meilisearch")).toBe("9007199254740993");
|
||||
expect(stringifyDocumentStoreValue(result.hits[0].document, "meilisearch")).toBe('{"movie_id":9007199254740993,"title":"Alien"}');
|
||||
});
|
||||
|
||||
it("decodes full-document export pages without rounding integers", () => {
|
||||
const page = decodeMeilisearchDocumentPage({
|
||||
documentsJson: ['{"movie_id":9007199254740993,"internal_notes":"secret"}'],
|
||||
total: 1,
|
||||
});
|
||||
|
||||
expect(stringifyDocumentStoreValue(page.documents, "meilisearch")).toBe('[{"movie_id":9007199254740993,"internal_notes":"secret"}]');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import { parseJsonPreservingLargeNumbers } from "@/lib/common/safeJsonFormat";
|
||||
|
||||
export type MeilisearchSearchHit = {
|
||||
id?: unknown;
|
||||
document: Record<string, unknown>;
|
||||
formatted?: Record<string, unknown>;
|
||||
rankingScore?: unknown;
|
||||
};
|
||||
|
||||
export type MeilisearchSearchResult = {
|
||||
hits: MeilisearchSearchHit[];
|
||||
totalHits: number;
|
||||
processingTimeMs: number;
|
||||
};
|
||||
|
||||
export type MeilisearchSearchWireResult = {
|
||||
hits: Array<{
|
||||
idJson?: string;
|
||||
documentJson: string;
|
||||
formattedJson?: string;
|
||||
rankingScoreJson?: string;
|
||||
}>;
|
||||
totalHits: number;
|
||||
processingTimeMs: number;
|
||||
};
|
||||
|
||||
export type MeilisearchDocumentPage = {
|
||||
documents: Record<string, unknown>[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
export type MeilisearchDocumentPageWire = {
|
||||
documentsJson: string[];
|
||||
total: number;
|
||||
};
|
||||
|
||||
function parseJsonObject(json: string, context: string): Record<string, unknown> {
|
||||
const value = parseJsonPreservingLargeNumbers(json);
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Invalid Meilisearch ${context} payload`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
export function decodeMeilisearchSearchResult(result: MeilisearchSearchWireResult): MeilisearchSearchResult {
|
||||
return {
|
||||
hits: result.hits.map((hit) => ({
|
||||
id: hit.idJson === undefined ? undefined : parseJsonPreservingLargeNumbers(hit.idJson),
|
||||
document: parseJsonObject(hit.documentJson, "document"),
|
||||
formatted: hit.formattedJson === undefined ? undefined : parseJsonObject(hit.formattedJson, "formatted document"),
|
||||
rankingScore: hit.rankingScoreJson === undefined ? undefined : parseJsonPreservingLargeNumbers(hit.rankingScoreJson),
|
||||
})),
|
||||
totalHits: result.totalHits,
|
||||
processingTimeMs: result.processingTimeMs,
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeMeilisearchDocumentPage(page: MeilisearchDocumentPageWire): MeilisearchDocumentPage {
|
||||
return {
|
||||
documents: page.documentsJson.map((document) => parseJsonObject(document, "document")),
|
||||
total: page.total,
|
||||
};
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { normalizeRustMongoCommand, type MongoCommand } from "@/lib/mongo/mongoShellCommand";
|
||||
import { ExternalSqlFileTooLargeError } from "@/lib/sql/sqlFileOpen";
|
||||
import { appendDebugLog, isDebugLoggingEnabled } from "@/lib/backend/debugLog";
|
||||
import { decodeMeilisearchDocumentPage, decodeMeilisearchSearchResult, type MeilisearchDocumentPage, type MeilisearchDocumentPageWire, type MeilisearchSearchResult, type MeilisearchSearchWireResult } from "@/lib/backend/meilisearchTransport";
|
||||
|
||||
/** Normalize Tauri rejections once at the public backend boundary. */
|
||||
async function invokeBackend<T>(command: string, args?: Record<string, unknown>): Promise<T> {
|
||||
@@ -3797,6 +3798,100 @@ export async function documentSaveMeilisearchBatch(connectionId: string, collect
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchSearchDocuments(
|
||||
connectionId: string,
|
||||
index: string,
|
||||
params: { q?: string | null; filter?: string | null; sort?: string | null; limit: number; offset: number; hybridEmbedder?: string | null; hybridSemanticRatio?: number | null; showRankingScore?: boolean; rankingScoreThreshold?: number | null },
|
||||
): Promise<MeilisearchSearchResult> {
|
||||
const result = await invoke<MeilisearchSearchWireResult>("meilisearch_search_documents", {
|
||||
connectionId,
|
||||
index,
|
||||
q: params.q ?? null,
|
||||
filter: params.filter ?? null,
|
||||
sort: params.sort ?? null,
|
||||
limit: params.limit,
|
||||
offset: params.offset,
|
||||
hybridEmbedder: params.hybridEmbedder ?? null,
|
||||
hybridSemanticRatio: params.hybridSemanticRatio ?? null,
|
||||
showRankingScore: params.showRankingScore ?? false,
|
||||
rankingScoreThreshold: params.rankingScoreThreshold ?? null,
|
||||
});
|
||||
return decodeMeilisearchSearchResult(result);
|
||||
}
|
||||
|
||||
export async function meilisearchFetchDocuments(connectionId: string, index: string, params: { filter?: string | null; sort?: string | null; limit: number; offset: number }): Promise<MeilisearchDocumentPage> {
|
||||
const page = await invoke<MeilisearchDocumentPageWire>("meilisearch_fetch_documents", {
|
||||
connectionId,
|
||||
index,
|
||||
filter: params.filter ?? null,
|
||||
sort: params.sort ?? null,
|
||||
limit: params.limit,
|
||||
offset: params.offset,
|
||||
});
|
||||
return decodeMeilisearchDocumentPage(page);
|
||||
}
|
||||
|
||||
export async function meilisearchGetDocument(connectionId: string, index: string, id: string): Promise<string> {
|
||||
return invoke("meilisearch_get_document", {
|
||||
connectionId,
|
||||
index,
|
||||
id,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchGetIndexSettings(connectionId: string, index: string): Promise<Record<string, any>> {
|
||||
return invoke("meilisearch_get_index_settings", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchUpdateIndexSettings(connectionId: string, index: string, settings: Record<string, any>): Promise<void> {
|
||||
return invoke("meilisearch_update_index_settings", {
|
||||
connectionId,
|
||||
index,
|
||||
settings,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchGetIndexStats(connectionId: string, index: string): Promise<{ numberOfDocuments: number; isIndexing: boolean; fieldDistribution: Record<string, number> } & Record<string, any>> {
|
||||
return invoke("meilisearch_get_index_stats", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export interface MeilisearchIndexOverview {
|
||||
uid: string;
|
||||
primaryKey: string | null;
|
||||
createdAt: string | null;
|
||||
updatedAt: string | null;
|
||||
numberOfDocuments: number;
|
||||
isIndexing: boolean;
|
||||
databaseSize: number | null;
|
||||
}
|
||||
|
||||
export async function meilisearchGetIndexOverview(connectionId: string, index: string): Promise<MeilisearchIndexOverview> {
|
||||
return invoke("meilisearch_get_index_overview", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchDeleteIndex(connectionId: string, index: string): Promise<void> {
|
||||
return invoke("meilisearch_delete_index", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function meilisearchDeleteAllDocuments(connectionId: string, index: string): Promise<void> {
|
||||
return invoke("meilisearch_delete_all_documents", {
|
||||
connectionId,
|
||||
index,
|
||||
});
|
||||
}
|
||||
|
||||
export async function mongoDeleteDocuments(connectionId: string, database: string, collection: string, filterJson: string, many: boolean): Promise<{ affected_rows: number }> {
|
||||
const affectedRows = await invoke<number>("mongo_delete_documents", {
|
||||
connectionId,
|
||||
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { appendJsonPointer, createJsonTreeRoot, getJsonTreeChildren, getVisibleJsonTreeNodes, isJsonTreeContainer, isJsonTreeInitiallyExpanded } from "../jsonTree";
|
||||
import { appendJsonPointer, createJsonTreeRoot, getJsonTreeChildren, getVisibleJsonTreeNodes, isJsonTreeClosingNode, isJsonTreeContainer, isJsonTreeInitiallyExpanded } from "../jsonTree";
|
||||
import { parseJsonPreservingLargeNumbers } from "../safeJsonFormat";
|
||||
|
||||
describe("jsonTree", () => {
|
||||
@@ -35,6 +35,15 @@ describe("jsonTree", () => {
|
||||
expect(nodes.map((node) => node.path)).toEqual(["", "/first", "/second", "/second/0"]);
|
||||
});
|
||||
|
||||
it("adds closing-bracket rows after expanded containers when requested", () => {
|
||||
const root = createJsonTreeRoot({ first: { nested: true }, second: ["kept"] });
|
||||
const nodes = getVisibleJsonTreeNodes(root, () => true, true);
|
||||
|
||||
expect(nodes.map((node) => node.path)).toEqual(["", "/first", "/first/nested", "/first/$close\0", "/second", "/second/0", "/second/$close\0", "/$close\0"]);
|
||||
expect(isJsonTreeClosingNode(nodes[3])).toBe(true);
|
||||
expect(isJsonTreeClosingNode(nodes[0])).toBe(false);
|
||||
});
|
||||
|
||||
it("handles deeply nested expanded JSON without recursive traversal", () => {
|
||||
let value: unknown = true;
|
||||
for (let depth = 0; depth < 2_000; depth += 1) value = { child: value };
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface JsonTreeNode {
|
||||
/** Zero-based structural depth; the root value is at depth zero. */
|
||||
depth: number;
|
||||
parentKind: JsonTreeParentKind;
|
||||
/** True only for the synthetic closing-bracket row of an expanded container. */
|
||||
closing?: boolean;
|
||||
}
|
||||
|
||||
export type JsonTreeContainer = Record<string, unknown> | unknown[];
|
||||
@@ -36,9 +38,14 @@ export function jsonTreeContainerKind(value: JsonTreeContainer): JsonTreeContain
|
||||
return Array.isArray(value) ? "array" : "object";
|
||||
}
|
||||
|
||||
export function jsonTreeContainerSummary(value: JsonTreeContainer, includeObjectLength = true): string {
|
||||
/** Compact summary shown between the brackets of a collapsed container. */
|
||||
export function jsonTreeContainerSummary(value: JsonTreeContainer): string {
|
||||
if (Array.isArray(value)) return `Array(${value.length})`;
|
||||
return includeObjectLength ? `Object(${Object.keys(value).length})` : "Object";
|
||||
return `Object(${Object.keys(value).length})`;
|
||||
}
|
||||
|
||||
export function isJsonTreeClosingNode(node: JsonTreeNode): boolean {
|
||||
return node.closing === true;
|
||||
}
|
||||
|
||||
/** Escape a reference token according to RFC 6901. */
|
||||
@@ -81,9 +88,10 @@ export function getJsonTreeChildren(node: JsonTreeNode): JsonTreeNode[] {
|
||||
/**
|
||||
* Flatten the currently expanded tree with an iterative traversal. This lets
|
||||
* virtual renderers keep every node logically expanded without recursive DOM
|
||||
* creation or deep-call-stack failures.
|
||||
* creation or deep-call-stack failures. When `includeClosingRows` is set, each
|
||||
* expanded container is followed by a synthetic closing-bracket row.
|
||||
*/
|
||||
export function getVisibleJsonTreeNodes(root: JsonTreeNode, isExpanded: (node: JsonTreeNode) => boolean): JsonTreeNode[] {
|
||||
export function getVisibleJsonTreeNodes(root: JsonTreeNode, isExpanded: (node: JsonTreeNode) => boolean, includeClosingRows = false): JsonTreeNode[] {
|
||||
const nodes: JsonTreeNode[] = [];
|
||||
const pending = [root];
|
||||
|
||||
@@ -92,7 +100,20 @@ export function getVisibleJsonTreeNodes(root: JsonTreeNode, isExpanded: (node: J
|
||||
if (!node) continue;
|
||||
nodes.push(node);
|
||||
|
||||
if (!isJsonTreeContainer(node.value) || !isExpanded(node)) continue;
|
||||
if (isJsonTreeClosingNode(node) || !isJsonTreeContainer(node.value) || !isExpanded(node)) continue;
|
||||
if (includeClosingRows) {
|
||||
pending.push({
|
||||
// NUL suffix keeps synthetic closing rows from colliding with a real
|
||||
// `$close` key that a document may legitimately contain.
|
||||
key: `${node.key}$close\0`,
|
||||
label: "",
|
||||
value: node.value,
|
||||
path: `${node.path}/$close\0`,
|
||||
depth: node.depth,
|
||||
parentKind: node.parentKind,
|
||||
closing: true,
|
||||
});
|
||||
}
|
||||
const children = getJsonTreeChildren(node);
|
||||
for (let index = children.length - 1; index >= 0; index -= 1) pending.push(children[index]);
|
||||
}
|
||||
|
||||
@@ -116,6 +116,17 @@ export function activeTabSidebarTarget(tab: QueryTab | undefined | null): Active
|
||||
};
|
||||
}
|
||||
|
||||
if (tab.mode === "meilisearch") {
|
||||
const collectionName = tab.sql || tab.title;
|
||||
if (!collectionName) return null;
|
||||
return {
|
||||
type: "mongo-collection",
|
||||
connectionId: tab.connectionId,
|
||||
database: tab.database,
|
||||
collectionName,
|
||||
};
|
||||
}
|
||||
|
||||
if (tab.mode === "mongo-bucket") {
|
||||
return {
|
||||
type: "mongo-gridfs",
|
||||
|
||||
Reference in new issue
Block a user