瀏覽代碼

enhance: property db ident doesn't allow #

Tienson Qin 1 年之前
父節點
當前提交
d48e45eaa7

+ 9 - 19
deps/db/src/logseq/db/frontend/property.cljs

@@ -190,15 +190,15 @@
   "Get a built-in property's id (keyword name for file graph and uuid for db graph)
   given its db-ident. Use this fn on a file or db graph. Use
   db-pu/get-built-in-property-uuid if only in a db graph context"
-  [repo db db-ident]
+  [repo db-ident]
   (if (sqlite-util/db-based-graph? repo)
     db-ident
     (get-in built-in-properties [db-ident :name])))
 
 (defn lookup
   "Get the value of coll by db-ident. For file and db graphs"
-  [repo db coll db-ident]
-  (get coll (get-pid repo db db-ident)))
+  [repo coll db-ident]
+  (get coll (get-pid repo db-ident)))
 
 (defn get-block-property-value
   "Get the value of built-in block's property by its db-ident"
@@ -206,17 +206,7 @@
   (when db
     (let [block (or (d/entity db (:db/id block)) block)]
       (when-let [properties (:block/properties block)]
-        (lookup repo db properties db-ident)))))
-
-(defn name->db-ident
-  "Converts a built-in property's keyword name to its :db/ident equivalent.
-  Legacy property names that had pseudo-namespacing are converted to their new
-  format e.g. :logseq.table.headers -> :logseq.property.table/headers"
-  [legacy-name]
-  ;; Migrate legacy names that have logseq.* style names but no namespace
-  (if-let [[_ additional-ns prop-name] (re-matches  #"logseq(.*)\.([^.]+)" (name legacy-name))]
-    (keyword (str "logseq.property" additional-ns) prop-name)
-    (keyword "logseq.property" (name legacy-name))))
+        (lookup repo properties db-ident)))))
 
 (defn shape-block?
   [repo db block]
@@ -261,13 +251,13 @@
 (defn get-db-ident-from-name
   [property-name]
   (let [n (-> (string/lower-case property-name)
-              (string/replace #"^:" "")
-              (string/replace " " "_")
+              (string/replace #"^:\s*" "")
+              (string/replace #"\s*:\s*$" "")
+              (string/replace " " "-")
+              (string/replace "#" "")
               (string/trim))]
     (when-not (string/blank? n)
-      (->
-       (str "user.property/" n)
-       keyword))))
+      (keyword "user.property" n))))
 
 (defn get-class-ordered-properties
   [class-entity]

+ 3 - 3
deps/graph-parser/src/logseq/graph_parser/whiteboard.cljs

@@ -87,9 +87,9 @@
            (when (nil? (:block/format block)) {:block/format :markdown}) ;; TODO: read from config
            {:block/page default-page-ref})))
 
-(defn shape->block [repo db shape page-name]
-  (let [properties {(db-property/get-pid repo db :logseq.property/ls-type) :whiteboard-shape
-                    (db-property/get-pid repo db :logseq.property.tldraw/shape) shape}
+(defn shape->block [repo shape page-name]
+  (let [properties {(db-property/get-pid repo :logseq.property/ls-type) :whiteboard-shape
+                    (db-property/get-pid repo :logseq.property.tldraw/shape) shape}
         page-name (common-util/page-name-sanity-lc page-name)
         block {:block/uuid (if (uuid? (:id shape)) (:id shape) (uuid (:id shape)))
                :block/page {:block/name page-name}

+ 1 - 1
deps/outliner/src/logseq/outliner/core.cljs

@@ -636,7 +636,7 @@
         tb (when target-block (block db target-block))
         target-block (if sibling? target-block (when tb (:block (otree/-get-down tb conn))))
         list-type-fn (fn [block] (db-property/get-block-property-value repo db block :logseq.property/order-list-type))
-        k (db-property/get-pid repo db :logseq.property/order-list-type)
+        k (db-property/get-pid repo :logseq.property/order-list-type)
         db-based? (sqlite-util/db-based-graph? repo)]
     (if-let [list-type (and target-block (list-type-fn target-block))]
       (mapv

+ 2 - 1
src/main/frontend/handler/editor.cljs

@@ -3409,7 +3409,8 @@
 (defn- valid-dsl-query-block?
   "Whether block has a valid dsl query."
   [block]
-  (string/includes? block "{{query "))
+  (some-> (:block/content block)
+          (string/includes? "{{query ")))
 
 (defn- valid-custom-query-block?
   "Whether block has a valid custom query."

+ 4 - 6
src/main/frontend/handler/property/util.cljs

@@ -11,9 +11,8 @@
 (defn lookup
   "Get the value of coll's (a map) by db-ident. For file and db graphs"
   [coll key]
-  (let [repo (state/get-current-repo)
-        db (db/get-db repo)]
-    (db-property/lookup repo db coll key)))
+  (let [repo (state/get-current-repo)]
+    (db-property/lookup repo coll key)))
 
 (defn lookup-by-name
   "Get the value of coll's (a map) by name. Only use this
@@ -39,9 +38,8 @@
 (defn get-pid
   "Get a built-in property's id (db-ident or name) given its db-ident. For file and db graphs"
   [db-ident]
-  (let [repo (state/get-current-repo)
-        db (db/get-db repo)]
-    (db-property/get-pid repo db db-ident)))
+  (let [repo (state/get-current-repo)]
+    (db-property/get-pid repo db-ident)))
 
 (defn block->shape [block]
   (get-block-property-value block :logseq.property.tldraw/shape))

+ 2 - 3
src/main/frontend/handler/whiteboard.cljs

@@ -25,9 +25,8 @@
   (js->clj obj :keywordize-keys true))
 
 (defn shape->block [shape page-name]
-  (let [repo (state/get-current-repo)
-        db (db/get-db repo)]
-    (gp-whiteboard/shape->block repo db shape page-name)))
+  (let [repo (state/get-current-repo)]
+    (gp-whiteboard/shape->block repo shape page-name)))
 
 (defn- build-shapes
   [page-block blocks]

+ 2 - 3
src/main/frontend/worker/rtc/core.cljs

@@ -24,7 +24,6 @@
             [logseq.common.util :as common-util]
             [logseq.db :as ldb]
             [logseq.db.frontend.content :as db-content]
-            [logseq.db.frontend.property :as db-property]
             [logseq.graph-parser.whiteboard :as gp-whiteboard]
             [logseq.outliner.core :as outliner-core]
             [logseq.outliner.transaction :as outliner-tx]
@@ -345,12 +344,12 @@
     (when-let [local-parent (d/entity db [:block/uuid first-remote-parent])]
       (let [page-name (:block/name local-parent)
             properties* (transit/read transit-r properties)
-            shape-property-id (db-property/get-pid repo db :logseq.property.tldraw/shape)
+            shape-property-id :logseq.property.tldraw/shape
             shape (and (map? properties*)
                        (get properties* shape-property-id))]
         (assert (some? page-name) local-parent)
         (assert (some? shape) properties*)
-        (transact-db! :upsert-whiteboard-block conn [(gp-whiteboard/shape->block repo db shape page-name)])))))
+        (transact-db! :upsert-whiteboard-block conn [(gp-whiteboard/shape->block repo shape page-name)])))))
 
 (defn- need-update-block?
   [conn block-uuid op-value]