Răsfoiți Sursa

enhance: get_tag_objects support either block/uuid or db ident

Tienson Qin 2 săptămâni în urmă
părinte
comite
20f8f0fa80
3 a modificat fișierele cu 11 adăugiri și 7 ștergeri
  1. 2 2
      src/main/logseq/api.cljs
  2. 8 4
      src/main/logseq/api/db.cljs
  3. 1 1
      src/main/logseq/sdk/utils.cljs

+ 2 - 2
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)

+ 8 - 4
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/<invoke-db-worker :thread-api/get-class-objects
                                               (state/get-current-repo)
                                               (:db/id class))]

+ 1 - 1
src/main/logseq/sdk/utils.cljs

@@ -19,7 +19,7 @@
   [m]
   (->> (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