Browse Source

fix: built-in? helper and most deps tests

Also fix validate script's count
Gabriel Horner 1 năm trước cách đây
mục cha
commit
354c0c1e42

+ 1 - 1
deps/db/script/validate_client_db.cljs

@@ -71,7 +71,7 @@
                                (count (filter #(contains? (:block/type %) "class") ent-maps)) " classes, "
                                (count (filter #(seq (:block/tags %)) ent-maps)) " objects, "
                                (count (filter #(contains? (:block/type %) "property") ent-maps)) " properties and "
-                               (count (mapcat db-property/properties ent-maps)) " property values"))
+                               (count (filter :property/pair-property ent-maps)) " property pairs"))
     (validate-client-db @conn ent-maps options)))
 
 (defn -main [argv]

+ 4 - 3
deps/db/src/logseq/db.cljs

@@ -6,6 +6,7 @@
             [logseq.common.util :as common-util]
             [logseq.common.config :as common-config]
             [logseq.db.frontend.content :as db-content]
+            [logseq.db.frontend.property :as db-property]
             [clojure.set :as set]
             [logseq.db.frontend.rules :as rules]
             [logseq.db.frontend.entity-plus :as entity-plus]
@@ -116,7 +117,7 @@
   "Return blocks of the designated page, without using cache.
    page-id - eid"
   [db page-id {:keys [pull-keys]
-            :or {pull-keys '[*]}}]
+               :or {pull-keys '[*]}}]
   (when page-id
     (let [datoms (d/datoms db :avet :block/page page-id)
           block-eids (mapv :e datoms)]
@@ -160,7 +161,7 @@
           :where
           [?page :block/name ?page-name]
           [(get-else $ ?page :block/original-name ?page-name) ?page-original-name]]
-         db)
+        db)
        (map first)
        (remove hidden-page?)))
 
@@ -455,7 +456,7 @@
 (defn built-in?
   "Built-in page or block"
   [entity]
-  (:logseq.property/built-in? entity))
+  (db-property/get-property-value entity :logseq.property/built-in?))
 
 (defn built-in-class-property?
   "Whether property a built-in property for the specific class"

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

@@ -214,13 +214,29 @@
 ;; ==========
 
 (defn properties
-  "Fetch all properties of entity like :block/properties used to do.
+  "Returns a block's properties as a map indexed by property's db-ident.
    Use this in deps because nbb can't use :block/properties from entity-plus"
   [e]
-  (->> (into {} e)
-       (filter (fn [[k _]] (property? k)))
+  (->> (:block/properties e)
+       (map (fn [pair-e]
+              (let [pid (:db/ident (:property/pair-property pair-e))]
+                {pid (pair-e pid)})))
        (into {})))
 
+(defn get-property-value
+  "Fetches a block's property value given a property's db-ident. Iterates over a
+  block's property pairs until it finds the given ident. This is nbb compatible"
+  [e ident]
+  (some (fn [pair-e]
+          ;; This assumes the property/pair-property's entity has been loaded
+          ;; which query results don't do by default.
+          ;; Should we have another helper that just fetches by the pair-e key
+          ;; that satisfies property?
+          (let [pid (get-in pair-e [:property/pair-property :db/ident])]
+            (when-some [val (and (= ident pid) (pair-e pid))]
+              val)))
+        (:block/properties e)))
+
 (defn valid-property-name?
   [s]
   {:pre [(string? s)]}

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

@@ -46,7 +46,7 @@
 (deftest new-graph-marks-built-ins
   (let [conn (d/create-conn db-schema/schema-for-db-based-graph)
         _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}"))
-        idents (->> (d/q '[:find [(pull ?b [:db/ident :logseq.property/built-in?]) ...]
+        idents (->> (d/q '[:find [(pull ?b [:db/ident {:block/properties [* {:property/pair-property [:db/ident]}]}]) ...]
                            :where [?b :db/ident]]
                          @conn)
                     ;; only kv's and empty property value aren't marked because

+ 2 - 3
deps/publishing/test/logseq/publishing/db_test.cljs

@@ -4,8 +4,7 @@
             [logseq.publishing.db :as publish-db]
             [logseq.graph-parser :as graph-parser]
             [datascript.core :as d]
-            [logseq.graph-parser.db :as gp-db]
-            [logseq.db :as ldb]))
+            [logseq.graph-parser.db :as gp-db]))
 
 (deftest clean-export!
   (let [conn (gp-db/start-conn)
@@ -57,7 +56,7 @@
         "Contains all pages that have been marked public")
     (is (not (contains? exported-pages "page1"))
         "Doesn't contain private page")
-    (is (seq (ldb/get-pages-by-name filtered-db "page2-alias"))
+    (is (seq (d/entity filtered-db [:block/original-name "page2-alias"]))
         "Alias of public page is exported")
     (is (= #{"page2" "page3"} exported-block-pages)
         "Only exports blocks from public pages")