Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

13.9 KB
Raw Blame
use std::path::Path;
use std::sync::Arc;

use tauri::ipc::Channel;
use tauri::State;

use crate::commands::connection::AppState;

#[tauri::command]
pub async fn nacos_test_connection(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    force_refresh: Option<bool>,
) -> Result<dbx_core::nacos::NacosConnectionInfo, String> {
    dbx_core::nacos::service::nacos_test_connection_core(&state, &connection_id, force_refresh.unwrap_or(false)).await
}

#[tauri::command]
pub async fn nacos_list_namespaces(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
) -> Result<Vec<dbx_core::nacos::NacosNamespaceInfo>, String> {
    dbx_core::nacos::service::nacos_list_namespaces_core(&state, &connection_id).await
}

#[tauri::command]
pub async fn nacos_sidebar_snapshot(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
) -> Result<dbx_core::nacos::NacosNamespaceSidebarSnapshot, String> {
    dbx_core::nacos::service::nacos_sidebar_snapshot_core(&state, &connection_id).await
}

#[tauri::command]
pub async fn nacos_create_namespace(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosNamespaceCreate,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_create_namespace_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_update_namespace(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosNamespaceUpdate,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_update_namespace_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_delete_namespace(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    namespace_id: String,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_delete_namespace_core(&state, &connection_id, namespace_id).await
}

#[tauri::command]
pub async fn nacos_list_configs(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosConfigQuery,
) -> Result<dbx_core::nacos::NacosConfigList, String> {
    dbx_core::nacos::service::nacos_list_configs_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_get_config(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    key: dbx_core::nacos::NacosConfigKey,
) -> Result<dbx_core::nacos::NacosConfigItem, String> {
    dbx_core::nacos::service::nacos_get_config_core(&state, &connection_id, key).await
}

#[tauri::command]
pub async fn nacos_publish_config(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosConfigUpsert,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_publish_config_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_delete_config(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    key: dbx_core::nacos::NacosConfigKey,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_delete_config_core(&state, &connection_id, key).await
}

#[tauri::command]
pub async fn nacos_list_config_history(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosConfigHistoryQuery,
) -> Result<dbx_core::nacos::NacosConfigHistoryList, String> {
    dbx_core::nacos::service::nacos_list_config_history_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_get_config_history(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    key: dbx_core::nacos::NacosConfigHistoryKey,
) -> Result<dbx_core::nacos::NacosConfigItem, String> {
    dbx_core::nacos::service::nacos_get_config_history_core(&state, &connection_id, key).await
}

#[tauri::command]
pub async fn nacos_rollback_config(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosConfigRollbackRequest,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_rollback_config_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_get_rnacos_console_captcha(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
) -> Result<dbx_core::nacos::NacosRNacosConsoleCaptcha, String> {
    dbx_core::nacos::service::nacos_get_rnacos_console_captcha_core(&state, &connection_id).await
}

#[tauri::command]
pub async fn nacos_login_rnacos_console(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    captcha: Option<String>,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_login_rnacos_console_core(&state, &connection_id, captcha).await
}

#[tauri::command]
pub async fn nacos_list_users(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosUserQuery,
) -> Result<dbx_core::nacos::NacosUserList, String> {
    dbx_core::nacos::service::nacos_list_users_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_create_user(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosUserCreate,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_create_user_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_update_user(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosUserUpdate,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_update_user_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_delete_user(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    username: String,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_delete_user_core(&state, &connection_id, username).await
}

#[tauri::command]
pub async fn nacos_list_role_bindings(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosRoleQuery,
) -> Result<dbx_core::nacos::NacosRoleList, String> {
    dbx_core::nacos::service::nacos_list_role_bindings_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_assign_role(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    binding: dbx_core::nacos::NacosRoleBinding,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_assign_role_core(&state, &connection_id, binding).await
}

#[tauri::command]
pub async fn nacos_remove_role(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    binding: dbx_core::nacos::NacosRoleBinding,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_remove_role_core(&state, &connection_id, binding).await
}

#[tauri::command]
pub async fn nacos_access_snapshot(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
) -> Result<dbx_core::nacos::NacosAccessControlSnapshot, String> {
    dbx_core::nacos::service::nacos_access_snapshot_core(&state, &connection_id).await
}

#[tauri::command]
pub async fn nacos_start_access_operation(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosAccessOperationRequest,
) -> Result<dbx_core::nacos::NacosAccessOperationResult, String> {
    dbx_core::nacos::service::nacos_start_access_operation_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_get_access_operation(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    operation_id: String,
) -> Result<dbx_core::nacos::NacosAccessOperationResult, String> {
    dbx_core::nacos::service::nacos_get_access_operation_core(&state, &connection_id, &operation_id).await
}

#[tauri::command]
pub async fn nacos_retry_access_operation(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    retry: dbx_core::nacos::NacosAccessOperationRetry,
) -> Result<dbx_core::nacos::NacosAccessOperationResult, String> {
    dbx_core::nacos::service::nacos_retry_access_operation_core(&state, &connection_id, retry).await
}

#[tauri::command]
pub async fn nacos_undo_access_operation(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    operation_id: String,
) -> Result<dbx_core::nacos::NacosAccessOperationResult, String> {
    dbx_core::nacos::service::nacos_undo_access_operation_core(&state, &connection_id, &operation_id).await
}

#[tauri::command]
pub async fn nacos_list_services(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosServiceQuery,
) -> Result<dbx_core::nacos::NacosServiceList, String> {
    dbx_core::nacos::service::nacos_list_services_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_get_service(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosServiceQuery,
) -> Result<dbx_core::nacos::NacosServiceDetail, String> {
    dbx_core::nacos::service::nacos_get_service_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_create_service(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosServiceUpsert,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_create_service_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_update_service(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosServiceUpsert,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_update_service_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_delete_service(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosServiceQuery,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_delete_service_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_list_instances(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosInstanceQuery,
) -> Result<Vec<dbx_core::nacos::NacosInstanceInfo>, String> {
    dbx_core::nacos::service::nacos_list_instances_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_update_instance(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosInstanceUpdateRequest,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_update_instance_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_register_instance(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosInstanceRegistration,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_register_instance_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_deregister_instance(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosInstanceRef,
) -> Result<(), String> {
    dbx_core::nacos::service::nacos_deregister_instance_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_get_dashboard(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    query: dbx_core::nacos::NacosDashboardQuery,
) -> Result<dbx_core::nacos::NacosDashboardSnapshot, String> {
    dbx_core::nacos::service::nacos_get_dashboard_core(&state, &connection_id, query).await
}

#[tauri::command]
pub async fn nacos_raw_request(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosRawRequest,
) -> Result<dbx_core::nacos::NacosRawResponse, String> {
    dbx_core::nacos::service::nacos_raw_request_core(&state, &connection_id, req).await
}

#[tauri::command]
pub async fn nacos_search_config_content(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    req: dbx_core::nacos::NacosContentSearchRequest,
    on_progress: Channel<dbx_core::nacos::NacosSearchProgress>,
) -> Result<dbx_core::nacos::NacosContentSearchResult, String> {
    dbx_core::nacos::service::nacos_search_config_content_core(&state, &connection_id, req, move |progress| {
        let _ = on_progress.send(progress);
        std::future::ready(())
    })
    .await
}

#[tauri::command]
pub async fn nacos_cancel_operation(operation_id: String) -> Result<bool, String> {
    Ok(dbx_core::nacos::service::nacos_cancel_operation_core(&operation_id))
}

#[tauri::command]
pub async fn nacos_export_configs(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    selector: dbx_core::nacos::NacosConfigSelector,
    destination: String,
) -> Result<(), String> {
    dbx_core::nacos::batch::nacos_export_config_archive_core(&state, &connection_id, selector, Path::new(&destination))
        .await
        .map(|_| ())
}

#[tauri::command]
pub async fn nacos_preview_config_import(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    target_namespace: String,
    archive_path: String,
) -> Result<dbx_core::nacos::NacosBatchPreview, String> {
    dbx_core::nacos::batch::nacos_preview_config_import_core(
        &state,
        &connection_id,
        &target_namespace,
        Path::new(&archive_path),
    )
    .await
}

#[tauri::command]
pub async fn nacos_apply_config_import(
    state: State<'_, Arc<AppState>>,
    connection_id: String,
    operation_id: String,
    target_namespace: String,
    archive_path: String,
    plan_hash: String,
    conflict_policy: dbx_core::nacos::NacosConflictPolicy,
) -> Result<dbx_core::nacos::NacosBatchReport, String> {
    dbx_core::nacos::batch::nacos_apply_config_import_core(
        &state,
        &connection_id,
        &target_namespace,
        Path::new(&archive_path),
        &operation_id,
        &plan_hash,
        &conflict_policy,
    )
    .await
}

#[tauri::command]
pub async fn nacos_preview_config_transfer(
    state: State<'_, Arc<AppState>>,
    req: dbx_core::nacos::NacosConfigTransferRequest,
) -> Result<dbx_core::nacos::NacosBatchPreview, String> {
    dbx_core::nacos::batch::nacos_preview_config_transfer_core(&state, &req).await
}

#[tauri::command]
pub async fn nacos_apply_config_transfer(
    state: State<'_, Arc<AppState>>,
    req: dbx_core::nacos::NacosConfigTransferRequest,
    plan_hash: String,
) -> Result<dbx_core::nacos::NacosBatchReport, String> {
    dbx_core::nacos::batch::nacos_apply_config_transfer_core(&state, &req, &plan_hash).await
}