feat(cli): migrate CLI to native Rust binary

This commit is contained in:
t8y2 committed 2026-07-18 22:29:29 +08:00
1 parent fa5579a3f1
commit 4bcf618162
47 files changed
+2369 -1255

No files matched your search

+1
View File
@@ -446,6 +446,7 @@ export const mongoDropDatabase = forward("mongoDropDatabase");
export const mongoDropCollection = forward("mongoDropCollection");
export const documentFindDocuments = forward("documentFindDocuments");
export const mongoFindDocuments = forward("mongoFindDocuments");
export const mongoParseShellCommand = forward("mongoParseShellCommand");
export const mongoFindOne = forward("mongoFindOne");
export const mongoCountDocuments = forward("mongoCountDocuments");
export const mongoServerVersion = forward("mongoServerVersion");
+6
View File
@@ -37,6 +37,7 @@ import type {
SshConfigHostEntry,
TunnelProfile,
} from "@/types/database";
import { normalizeRustMongoCommand, type MongoCommand } from "@/lib/mongo/mongoShellCommand";
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";
@@ -2071,6 +2072,11 @@ export async function mongoFindDocuments(connectionId: string, database: string,
return documentFindDocuments(connectionId, database, collection, skip, limit, filter, projection, sort, executionId);
}
export async function mongoParseShellCommand(source: string): Promise<MongoCommand> {
const raw = await post<Record<string, unknown>>("/api/mongo/parse-shell-command", { source });
return normalizeRustMongoCommand(raw);
}
export async function mongoFindOne(connectionId: string, database: string, collection: string, filter?: string, projection?: string, options?: string, executionId?: string): Promise<MongoDocumentResult> {
return post("/api/mongo/find-one", { connectionId, database, collection, filter, projection, options, executionId });
}
+6
View File
@@ -1,5 +1,6 @@
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
import { normalizeRustMongoCommand, type MongoCommand } from "@/lib/mongo/mongoShellCommand";
import type {
ConnectionConfig,
ConnectionTestResult,
@@ -1858,6 +1859,11 @@ export async function mongoFindOne(connectionId: string, database: string, colle
return invoke("mongo_find_one", { connectionId, database, collection, filter, projection, options, executionId });
}
export async function mongoParseShellCommand(source: string): Promise<MongoCommand> {
const raw = await invoke<Record<string, unknown>>("mongo_parse_shell_command", { source });
return normalizeRustMongoCommand(raw);
}
export async function documentFindDocuments(connectionId: string, database: string, collection: string, skip: number, limit: number, filter?: string, projection?: string, sort?: string, executionId?: string): Promise<MongoDocumentResult> {
return invoke("document_find_documents", { connectionId, database, collection, skip, limit, filter, projection, sort, executionId });
}
@@ -90,6 +90,20 @@ export type MongoCommand =
export type MongoWriteCommand = Extract<MongoCommand, { kind: MongoWriteKind }>;
export function normalizeRustMongoCommand(raw: Record<string, unknown>): MongoCommand {
const command = Object.fromEntries(Object.entries(raw).filter(([, value]) => value !== null)) as Record<string, any>;
if (command.kind === "countDocuments") {
const { accurate, ...rest } = command;
return { ...rest, kind: "countDocuments", mode: accurate ? "accurate" : "legacy" } as MongoCommand;
}
if (command.kind === "dropIndexes") {
const { single, indexes, ...rest } = command;
if (single) return { ...rest, kind: "dropIndex", index: indexes } as MongoCommand;
return { ...rest, kind: "dropIndexes", ...(indexes ? { indexes } : {}) } as MongoCommand;
}
return command as MongoCommand;
}
export interface ParsedMongoCommand {
text: string;
command: MongoCommand;