Ver Fonte

chore: clean up repeated uses of db attribute properties

Gabriel Horner há 1 ano atrás
pai
commit
e7bd84850d

+ 2 - 6
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -10,12 +10,8 @@
 ;; :db/ident malli schemas
 ;; =======================
 
-(def db-attribute-properties
-  "Internal properties that are also db attributes"
-  #{:block/alias :block/tags})
-
 (def db-attribute-ident
-  (into [:enum] db-attribute-properties))
+  (into [:enum] db-property/db-attribute-properties))
 
 (def logseq-property-ident
   [:and :keyword [:fn
@@ -243,7 +239,7 @@
 (def property-page
   [:multi {:dispatch (fn [m]
                        (or (db-property/logseq-property? (m :db/ident))
-                           (contains? db-attribute-properties (m :db/ident))))}
+                           (contains? db-property/db-attribute-properties (m :db/ident))))}
    [true internal-property]
    [:malli.core/default user-property]])
 

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

@@ -177,6 +177,15 @@
                  (assoc v :name (keyword (string/lower-case (name k)))))]))
        (into {})))
 
+(def db-attribute-properties
+  "Internal properties that are also db schema attributes"
+  #{:block/alias :block/tags})
+
+(assert (= db-attribute-properties
+           (set (keep (fn [[k {:keys [attribute]}]] (when attribute k))
+                        built-in-properties)))
+        "All db attribute properties are configured in built-in-properties")
+
 (defn valid-property-name?
   [s]
   {:pre [(string? s)]}

+ 1 - 1
deps/db/src/logseq/db/sqlite/util.cljs

@@ -72,7 +72,7 @@
   [db-ident prop-name prop-schema]
   (assert (keyword? db-ident))
   (let [db-ident' (if (or (db-property/property? db-ident)
-                          (contains? #{:block/tags :block/alias} db-ident))
+                          (db-property/db-attribute-properties db-ident))
                     db-ident
                     (keyword "user.property" (name db-ident)))]
     (block-with-timestamps

+ 2 - 2
deps/db/test/logseq/db/sqlite/create_graph_test.cljs

@@ -6,7 +6,7 @@
             [logseq.db.frontend.schema :as db-schema]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
             [logseq.db.frontend.validate :as db-validate]
-            [logseq.db.frontend.malli-schema :as malli-schema]
+            [logseq.db.frontend.property :as db-property]
             [logseq.db :as ldb]))
 
 (deftest new-graph-db-idents
@@ -25,7 +25,7 @@
         (is (= '() (remove namespace default-idents))
             "All default :db/ident's have namespaces")
         (is (= []
-               (->> (remove malli-schema/db-attribute-properties default-idents)
+               (->> (remove db-property/db-attribute-properties default-idents)
                     (keep namespace)
                     (remove #(string/starts-with? % "logseq."))))
             "All default :db/ident namespaces start with logseq."))

+ 1 - 1
src/main/frontend/components/property.cljs

@@ -446,7 +446,7 @@
                                (map #(:block/original-name (db/entity %)))
                                (remove nil?)
                                (set))
-        existing-tag-alias (->> [:block/tags :block/alias]
+        existing-tag-alias (->> db-property/db-attribute-properties
                                 (map db-property/built-in-properties)
                                 (keep #(when (get entity (:attribute %)) (:original-name %)))
                                 set)

+ 3 - 3
src/main/frontend/handler/db_based/property.cljs

@@ -153,7 +153,7 @@
                       (catch :default e
                         (notification/show! (str e) :error false)
                         nil))
-            tags-or-alias? (contains? #{:block/tags :block/alias} property-id)
+            tags-or-alias? (contains? db-property/db-attribute-properties property-id)
             old-values (if tags-or-alias?
                          (->> (get block property-id)
                               (map (fn [e] (:db/id e))))
@@ -226,7 +226,7 @@
                          (js/console.error e)
                          (notification/show! (str e) :error false)
                          nil)))
-                tags-or-alias? (and (contains? #{:block/tags :block/alias} property-id) (uuid? v*))]
+                tags-or-alias? (and (contains? db-property/db-attribute-properties property-id) (uuid? v*))]
             (if tags-or-alias?
               (let [property-value-id v*]
                 (db/transact! repo
@@ -360,7 +360,7 @@
 (defn remove-block-property!
   [repo eid property-id]
   (let [eid (->eid eid)]
-    (if (contains? #{:block/alias :block/tags} property-id)
+    (if (contains? db-property/db-attribute-properties property-id)
      (when-let [block (db/entity eid)]
        (db/transact! repo
                      [[:db/retract (:db/id block) property-id]]