Forráskód Böngészése

fix: frontend lint

Move ensure-db-graph check which provides clear and consistent
error messages instead of the inconsistent, confusing errors
we had before for file graphs
Gabriel Horner 2 hete
szülő
commit
4dce582d33
2 módosított fájl, 11 hozzáadás és 8 törlés
  1. 11 2
      src/main/logseq/api.cljs
  2. 0 6
      src/main/logseq/api/db_based/cli.cljs

+ 11 - 2
src/main/logseq/api.cljs

@@ -16,6 +16,7 @@
             [logseq.api.editor :as api-editor]
             [logseq.api.file-based :as file-based-api]
             [logseq.api.plugin :as api-plugin]
+            [logseq.db.sqlite.util :as sqlite-util]
             [logseq.sdk.assets :as sdk-assets]
             [logseq.sdk.core]
             [logseq.sdk.experiments]
@@ -208,13 +209,21 @@
 (def ^:export remove_tag_property db-based-api/tag-remove-property)
 
 ;; Internal db-based CLI APIs
+;; CLI APIs should use ensure-db-graph unless they have a nested check in cli-common-mcp-tools ns
+(defn- ensure-db-graph
+  [f]
+  (fn ensure-db-graph-wrapper [& args]
+    (when-not (sqlite-util/db-based-graph? (state/get-current-repo))
+      (throw (ex-info "This endpoint must be called on a DB graph" {})))
+    (apply f args)))
+
 (def ^:export list_tags cli-based-api/list-tags)
 (def ^:export list_properties cli-based-api/list-properties)
 (def ^:export list_pages cli-based-api/list-pages)
 (def ^:export get_page_data cli-based-api/get-page-data)
 (def ^:export upsert_nodes cli-based-api/upsert-nodes)
-(def ^:export import_edn cli-based-api/import-edn)
-(def ^:export export_edn cli-based-api/export-edn)
+(def ^:export import_edn (ensure-db-graph cli-based-api/import-edn))
+(def ^:export export_edn (ensure-db-graph cli-based-api/export-edn))
 
 ;; file based graph APIs
 (def ^:export get_current_graph_templates file-based-api/get_current_graph_templates)

+ 0 - 6
src/main/logseq/api/db_based/cli.cljs

@@ -53,15 +53,10 @@
     (ui-handler/re-render-root!)
     (cli-common-mcp-tools/summarize-upsert-operations ops options)))
 
-(defn- ensure-db-graph
-  [repo]
-  (when-not (sqlite-util/db-based-graph? repo)
-    (throw (ex-info "This endpoint must be called on a DB graph" {}))))
 
 (defn import-edn
   "Given EDN data as a transitized string, converts to EDN and imports it."
   [edn-data*]
-  (ensure-db-graph (state/get-current-repo))
   (p/let [edn-data (sqlite-util/transit-read edn-data*)
           {:keys [error]} (ui-outliner-tx/transact!
                            {:outliner-op :batch-import-edn}
@@ -73,7 +68,6 @@
   "Given sqlite.export options, exports the current graph as a json map with the
   :export-body key containing a transit string of the export EDN"
   [options*]
-  (ensure-db-graph (state/get-current-repo))
   (p/let [options (-> (js->clj options* :keywordize-keys true)
                       (update :export-type (fnil keyword :graph)))
           result (state/<invoke-db-worker :thread-api/export-edn (state/get-current-repo) options)]