From 20f8f0fa80cb1e873a1b605ac7812f94e95f7157 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Thu, 9 Oct 2025 14:26:43 +0800 Subject: [PATCH] enhance: get_tag_objects support either block/uuid or db ident --- src/main/logseq/api.cljs | 4 ++-- src/main/logseq/api/db.cljs | 12 ++++++++---- src/main/logseq/sdk/utils.cljs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/logseq/api.cljs b/src/main/logseq/api.cljs index 65c03f62f3..07f1cef32f 100644 --- a/src/main/logseq/api.cljs +++ b/src/main/logseq/api.cljs @@ -1187,8 +1187,8 @@ (db-api/remove-property property)))) (def ^:export get_all_tags db-api/get-all-tags) -(def ^:export get-all-properties db-api/get-all-properties) -(def ^:export get-tag-objects db-api/get-tag-objects) +(def ^:export get_all_properties db-api/get-all-properties) +(def ^:export get_tag_objects db-api/get-tag-objects) ;; file based graph APIs (def ^:export get_current_graph_templates file-api/get_current_graph_templates) diff --git a/src/main/logseq/api/db.cljs b/src/main/logseq/api/db.cljs index e93b07c177..8c0a41079c 100644 --- a/src/main/logseq/api/db.cljs +++ b/src/main/logseq/api/db.cljs @@ -11,6 +11,7 @@ [frontend.handler.page :as page-handler] [frontend.modules.layout.core] [frontend.state :as state] + [frontend.util :as util] [logseq.api.block :as api-block] [logseq.db :as ldb] [logseq.outliner.core :as outliner-core] @@ -109,11 +110,14 @@ result->js)) (defn get-tag-objects - [class-uuid] - (let [id (sdk-utils/uuid-or-throw-error class-uuid) - class (db/entity [:block/uuid id])] + [class-uuid-or-ident] + (let [eid (if (util/uuid-string? class-uuid-or-ident) + (when-let [id (sdk-utils/uuid-or-throw-error class-uuid-or-ident)] + [:block/uuid id]) + (keyword (api-block/sanitize-user-property-name class-uuid-or-ident))) + class (db/entity eid)] (if-not class - (throw (ex-info (str "Tag not exists with id: " class-uuid) {})) + (throw (ex-info (str "Tag not exists with id: " eid) {})) (p/let [result (state/> (remove (fn [[k _v]] (or (= "block.temp" (namespace k)) - (contains? #{:logseq.property.embedding/hnsw-label-updated-at} k))) m) + (contains? #{:logseq.property.embedding/hnsw-label-updated-at :block/tx-id} k))) m) (into {}))) (defn normalize-keyword-for-json