mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
chore: mv api cli fns to their own ns
Move to keep inline with recent api refactor. Also more lint config for api
This commit is contained in:
@@ -164,6 +164,7 @@
|
|||||||
frontend.worker.state worker-state
|
frontend.worker.state worker-state
|
||||||
frontend.worker.util worker-util
|
frontend.worker.util worker-util
|
||||||
lambdaisland.glogi log
|
lambdaisland.glogi log
|
||||||
|
logseq.api.db-based db-based-api
|
||||||
logseq.cli.common.graph cli-common-graph
|
logseq.cli.common.graph cli-common-graph
|
||||||
logseq.cli.common.export.common cli-export-common
|
logseq.cli.common.export.common cli-export-common
|
||||||
logseq.cli.common.export.text cli-export-text
|
logseq.cli.common.export.text cli-export-text
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
"Namespaces or parent namespaces _only_ for file graphs"
|
"Namespaces or parent namespaces _only_ for file graphs"
|
||||||
(mapv escape-shell-regex
|
(mapv escape-shell-regex
|
||||||
["logseq.graph-parser.db" "logseq.graph-parser.property" "logseq.graph-parser.extract"
|
["logseq.graph-parser.db" "logseq.graph-parser.property" "logseq.graph-parser.extract"
|
||||||
|
"logseq.api.file-based"
|
||||||
"frontend.handler.file-based" "frontend.handler.file-sync"
|
"frontend.handler.file-based" "frontend.handler.file-sync"
|
||||||
"frontend.db.file-based"
|
"frontend.db.file-based"
|
||||||
"frontend.util.file-based"
|
"frontend.util.file-based"
|
||||||
@@ -65,6 +66,7 @@
|
|||||||
"src/main/frontend/components/query/view.cljs"
|
"src/main/frontend/components/query/view.cljs"
|
||||||
"src/main/frontend/inference_worker"
|
"src/main/frontend/inference_worker"
|
||||||
"src/main/logseq/api/db_based.cljs"
|
"src/main/logseq/api/db_based.cljs"
|
||||||
|
"src/main/logseq/api/db_based"
|
||||||
"src/electron/electron/db.cljs"
|
"src/electron/electron/db.cljs"
|
||||||
"src/main/mobile"]))
|
"src/main/mobile"]))
|
||||||
|
|
||||||
|
|||||||
@@ -7,16 +7,12 @@
|
|||||||
[frontend.handler.plugin :as plugin-handler]
|
[frontend.handler.plugin :as plugin-handler]
|
||||||
[frontend.handler.search :as search-handler]
|
[frontend.handler.search :as search-handler]
|
||||||
[frontend.loader :as loader]
|
[frontend.loader :as loader]
|
||||||
[frontend.handler.ui :as ui-handler]
|
|
||||||
[logseq.sdk.utils :as sdk-utils]
|
|
||||||
[logseq.cli.common.mcp.tools :as cli-common-mcp-tools]
|
|
||||||
[frontend.modules.outliner.op :as outliner-op]
|
|
||||||
[frontend.modules.outliner.ui :as ui-outliner-tx]
|
|
||||||
[frontend.modules.layout.core]
|
[frontend.modules.layout.core]
|
||||||
[frontend.state :as state]
|
[frontend.state :as state]
|
||||||
[logseq.api.app :as api-app]
|
[logseq.api.app :as api-app]
|
||||||
[logseq.api.db :as api-db]
|
[logseq.api.db :as api-db]
|
||||||
[logseq.api.db-based :as db-based-api]
|
[logseq.api.db-based :as db-based-api]
|
||||||
|
[logseq.api.db-based.cli :as cli-based-api]
|
||||||
[logseq.api.editor :as api-editor]
|
[logseq.api.editor :as api-editor]
|
||||||
[logseq.api.file-based :as file-based-api]
|
[logseq.api.file-based :as file-based-api]
|
||||||
[logseq.api.plugin :as api-plugin]
|
[logseq.api.plugin :as api-plugin]
|
||||||
@@ -25,6 +21,7 @@
|
|||||||
[logseq.sdk.experiments]
|
[logseq.sdk.experiments]
|
||||||
[logseq.sdk.git]
|
[logseq.sdk.git]
|
||||||
[logseq.sdk.ui :as sdk-ui]
|
[logseq.sdk.ui :as sdk-ui]
|
||||||
|
[logseq.sdk.utils :as sdk-utils]
|
||||||
[promesa.core :as p]))
|
[promesa.core :as p]))
|
||||||
|
|
||||||
;; Alert: All apis shouldn't invoke any reactive queries
|
;; Alert: All apis shouldn't invoke any reactive queries
|
||||||
@@ -138,51 +135,6 @@
|
|||||||
(def ^:export update_block api-editor/update_block)
|
(def ^:export update_block api-editor/update_block)
|
||||||
(def ^:export upsert_block_property api-editor/upsert_block_property)
|
(def ^:export upsert_block_property api-editor/upsert_block_property)
|
||||||
|
|
||||||
;; Internal CLI API
|
|
||||||
;; TODO: Use transit for internal APIs
|
|
||||||
(defn ^:export list_tags
|
|
||||||
[options]
|
|
||||||
(p/let [resp (state/<invoke-db-worker :thread-api/api-list-tags
|
|
||||||
(state/get-current-repo)
|
|
||||||
(js->clj options :keywordize-keys true))]
|
|
||||||
(clj->js resp)))
|
|
||||||
|
|
||||||
(defn ^:export list_properties
|
|
||||||
[options]
|
|
||||||
(p/let [resp (state/<invoke-db-worker :thread-api/api-list-properties
|
|
||||||
(state/get-current-repo)
|
|
||||||
(js->clj options :keywordize-keys true))]
|
|
||||||
(clj->js resp)))
|
|
||||||
|
|
||||||
(defn ^:export list_pages
|
|
||||||
[options]
|
|
||||||
(p/let [resp (state/<invoke-db-worker :thread-api/api-list-pages
|
|
||||||
(state/get-current-repo)
|
|
||||||
(js->clj options :keywordize-keys true))]
|
|
||||||
(clj->js resp)))
|
|
||||||
|
|
||||||
(defn ^:export get_page_data
|
|
||||||
"Like get_page_blocks_tree but for MCP tools"
|
|
||||||
[page-title]
|
|
||||||
(p/let [resp (state/<invoke-db-worker :thread-api/api-get-page-data (state/get-current-repo) page-title)]
|
|
||||||
(if resp
|
|
||||||
(clj->js resp)
|
|
||||||
#js {:error (str "Page " (pr-str page-title) " not found")})))
|
|
||||||
|
|
||||||
(defn ^:export upsert_nodes
|
|
||||||
"Given a list of MCP operations, batch imports with resulting EDN data"
|
|
||||||
[operations options*]
|
|
||||||
(p/let [ops (js->clj operations :keywordize-keys true)
|
|
||||||
{:keys [dry-run] :as options} (js->clj options* :keywordize-keys true)
|
|
||||||
edn-data (state/<invoke-db-worker :thread-api/api-build-upsert-nodes-edn (state/get-current-repo) ops)
|
|
||||||
{:keys [error]} (when-not dry-run
|
|
||||||
(ui-outliner-tx/transact!
|
|
||||||
{:outliner-op :batch-import-edn}
|
|
||||||
(outliner-op/batch-import-edn! edn-data {})))]
|
|
||||||
(when error (throw (ex-info error {})))
|
|
||||||
(ui-handler/re-render-root!)
|
|
||||||
(cli-common-mcp-tools/summarize-upsert-operations ops options)))
|
|
||||||
|
|
||||||
;; ui
|
;; ui
|
||||||
(def ^:export show_msg sdk-ui/-show_msg)
|
(def ^:export show_msg sdk-ui/-show_msg)
|
||||||
(def ^:export query_element_rect sdk-ui/query_element_rect)
|
(def ^:export query_element_rect sdk-ui/query_element_rect)
|
||||||
@@ -249,6 +201,13 @@
|
|||||||
(def ^:export get_all_properties db-based-api/get-all-properties)
|
(def ^:export get_all_properties db-based-api/get-all-properties)
|
||||||
(def ^:export get_tag_objects db-based-api/get-tag-objects)
|
(def ^:export get_tag_objects db-based-api/get-tag-objects)
|
||||||
|
|
||||||
|
;; Internal db-based CLI APIs
|
||||||
|
(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)
|
||||||
|
|
||||||
;; file based graph APIs
|
;; file based graph APIs
|
||||||
(def ^:export get_current_graph_templates file-based-api/get_current_graph_templates)
|
(def ^:export get_current_graph_templates file-based-api/get_current_graph_templates)
|
||||||
(def ^:export get_template file-based-api/get_template)
|
(def ^:export get_template file-based-api/get_template)
|
||||||
|
|||||||
51
src/main/logseq/api/db_based/cli.cljs
Normal file
51
src/main/logseq/api/db_based/cli.cljs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
(ns logseq.api.db-based.cli
|
||||||
|
"API fns for CLI"
|
||||||
|
(:require [frontend.handler.ui :as ui-handler]
|
||||||
|
[frontend.modules.outliner.op :as outliner-op]
|
||||||
|
[frontend.modules.outliner.ui :as ui-outliner-tx]
|
||||||
|
[frontend.state :as state]
|
||||||
|
[logseq.cli.common.mcp.tools :as cli-common-mcp-tools]
|
||||||
|
[promesa.core :as p]))
|
||||||
|
|
||||||
|
(defn list-tags
|
||||||
|
[options]
|
||||||
|
(p/let [resp (state/<invoke-db-worker :thread-api/api-list-tags
|
||||||
|
(state/get-current-repo)
|
||||||
|
(js->clj options :keywordize-keys true))]
|
||||||
|
(clj->js resp)))
|
||||||
|
|
||||||
|
(defn list-properties
|
||||||
|
[options]
|
||||||
|
(p/let [resp (state/<invoke-db-worker :thread-api/api-list-properties
|
||||||
|
(state/get-current-repo)
|
||||||
|
(js->clj options :keywordize-keys true))]
|
||||||
|
(clj->js resp)))
|
||||||
|
|
||||||
|
(defn list-pages
|
||||||
|
[options]
|
||||||
|
(p/let [resp (state/<invoke-db-worker :thread-api/api-list-pages
|
||||||
|
(state/get-current-repo)
|
||||||
|
(js->clj options :keywordize-keys true))]
|
||||||
|
(clj->js resp)))
|
||||||
|
|
||||||
|
(defn get-page-data
|
||||||
|
"Like get_page_blocks_tree but for MCP tools"
|
||||||
|
[page-title]
|
||||||
|
(p/let [resp (state/<invoke-db-worker :thread-api/api-get-page-data (state/get-current-repo) page-title)]
|
||||||
|
(if resp
|
||||||
|
(clj->js resp)
|
||||||
|
#js {:error (str "Page " (pr-str page-title) " not found")})))
|
||||||
|
|
||||||
|
(defn upsert-nodes
|
||||||
|
"Given a list of MCP operations, batch imports with resulting EDN data"
|
||||||
|
[operations options*]
|
||||||
|
(p/let [ops (js->clj operations :keywordize-keys true)
|
||||||
|
{:keys [dry-run] :as options} (js->clj options* :keywordize-keys true)
|
||||||
|
edn-data (state/<invoke-db-worker :thread-api/api-build-upsert-nodes-edn (state/get-current-repo) ops)
|
||||||
|
{:keys [error]} (when-not dry-run
|
||||||
|
(ui-outliner-tx/transact!
|
||||||
|
{:outliner-op :batch-import-edn}
|
||||||
|
(outliner-op/batch-import-edn! edn-data {})))]
|
||||||
|
(when error (throw (ex-info error {})))
|
||||||
|
(ui-handler/re-render-root!)
|
||||||
|
(cli-common-mcp-tools/summarize-upsert-operations ops options)))
|
||||||
Reference in New Issue
Block a user