Kaynağa Gözat

enhance: all default db idents are namespaced under logseq

Having consistent namespacing of core idents increases the
number of features they can be used for later
Gabriel Horner 1 yıl önce
ebeveyn
işleme
4ba9fea065

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

@@ -593,4 +593,4 @@
   (defn db-based-graph?
     "Whether the current graph is db-only"
     [db]
-    (= "db" (:db/type (d/entity db :db/type)))))
+    (= "db" (:db/type (d/entity db :logseq.kv.db/type)))))

+ 14 - 14
deps/db/src/logseq/db/frontend/property.cljs

@@ -59,7 +59,7 @@
    :logseq.tldraw.shape {:schema {:type :map}}
 
    ;; Task props
-   :status {:db-ident :task/status
+   :status {:db-ident :logseq.task/status
             :original-name "Status"
             :schema
             {:type :default}
@@ -69,14 +69,14 @@
                      :value value
                      :uuid (random-uuid)
                      :icon {:type :tabler-icon :id icon :name icon}})
-                  [[:task/status.backlog "Backlog" "Backlog"]
-                   [:task/status.todo "Todo" "Todo"]
-                   [:task/status.doing "Doing" "InProgress50"]
-                   [:task/status.in-review "In Review" "InReview"]
-                   [:task/status.done "Done" "Done"]
-                   [:task/status.canceled "Canceled" "Cancelled"]])
+                  [[:logseq.task/status.backlog "Backlog" "Backlog"]
+                   [:logseq.task/status.todo "Todo" "Todo"]
+                   [:logseq.task/status.doing "Doing" "InProgress50"]
+                   [:logseq.task/status.in-review "In Review" "InReview"]
+                   [:logseq.task/status.done "Done" "Done"]
+                   [:logseq.task/status.canceled "Canceled" "Cancelled"]])
             :visible true}
-   :priority {:db-ident :task/priority
+   :priority {:db-ident :logseq.task/priority
               :original-name "Priority"
               :schema
               {:type :default}
@@ -85,16 +85,16 @@
                       {:db-ident db-ident
                        :value value
                        :uuid (random-uuid)})
-                    [[:task/priority.urgent "Urgent"]
-                     [:task/priority.high "High"]
-                     [:task/priority.medium "Medium"]
-                     [:task/priority.low "Low"]])
+                    [[:logseq.task/priority.urgent "Urgent"]
+                     [:logseq.task/priority.high "High"]
+                     [:logseq.task/priority.medium "Medium"]
+                     [:logseq.task/priority.low "Low"]])
               :visible true}
-   :scheduled {:db-ident :task/scheduled
+   :scheduled {:db-ident :logseq.task/scheduled
                :original-name "Scheduled"
                :schema {:type :date}
                :visible true}
-   :deadline {:db-ident :task/deadline
+   :deadline {:db-ident :logseq.task/deadline
               :original-name "Deadline"
               :schema {:type :date}
               :visible true}

+ 10 - 3
deps/db/src/logseq/db/sqlite/create_graph.cljs

@@ -45,15 +45,22 @@
          (update blocks 0 #(default-db/mark-block-as-built-in db %))))
      built-in-properties)))
 
+(defn kv
+  "Creates a key-value pair tx with the key under the :db/ident namespace :logseq.kv.
+   For example, the :db/type key is stored under an entity with ident :logseq.kv.db/type"
+  [key value]
+  {:db/ident (keyword (str "logseq.kv." (namespace key)) (name key))
+   key value})
+
 (defn build-db-initial-data
   [db* config-content]
   (let [db (d/db-with db*
                       (map (fn [p]
-                             {:db/ident (keyword "logseq.property" (name p))
+                             {:db/ident (db-property/name->db-ident p)
                               :block/name (name p)
                               :block/uuid (random-uuid)}) db-property/first-stage-properties))
-        initial-data [{:db/ident :db/type :db/type "db"}
-                      {:db/ident :schema/version :schema/version db-schema/version}]
+        initial-data [(kv :db/type "db")
+                      (kv :schema/version db-schema/version)]
         initial-files [{:block/uuid (d/squuid)
                         :file/path (str "logseq/" "config.edn")
                         :file/content config-content

+ 11 - 6
deps/db/test/logseq/db/sqlite/create_graph_test.cljs

@@ -18,12 +18,17 @@
      (testing "namespaces"
        (is (= '() (remove namespace default-idents))
            "All default :db/ident's have namespaces")
-       (is (= #{"logseq.property" "logseq.property.table" "logseq.property.tldraw"
-                "logseq.class"
-                ;; TODO: These should start with logseq
-                "task" "schema" "db"}
-              (set (distinct (keep namespace default-idents))))
-           "All default :db/ident's have known namespaces"))
+       (is (= []
+              (->> (keep namespace default-idents)
+                   (remove #(string/starts-with? % "logseq."))))
+           "All default :db/ident namespaces start with logseq.")
+       (is (= #{"logseq.property" "logseq.class" "logseq.task" "logseq.kv"}
+              (->> (keep namespace default-idents)
+                   ;; only pull 1st and 2nd level namespaces e.g. logseq and logseq.property
+                   (keep #(re-find #"^([^.]+\.?([^.]+)?)" %))
+                   (map first)
+                   set))
+           "All default :db/ident's top-level namespaces are known"))
 
       (testing "closed values"
         (let [closed-value-ents (filter #(string/includes? (name (:db/ident %)) ".") ident-ents)

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

@@ -294,7 +294,7 @@
   [conn m]
   (or
    (let [marker (:block/marker m)
-         property (d/entity @conn :task/status)
+         property (d/entity @conn :logseq.task/status)
          matched-status-id (when marker
                              (->> (get-in property [:block/schema :values])
                                  (some (fn [id]

+ 4 - 4
src/main/frontend/commands.cljs

@@ -125,7 +125,7 @@
 (defn db-based-statuses
   []
   (map (fn [id] (get-in (db/entity [:block/uuid id]) [:block/schema :value]))
-    (pu/get-closed-property-values :task/status)))
+    (pu/get-closed-property-values :logseq.task/status)))
 
 (defn db-based-embed-page
   []
@@ -161,7 +161,7 @@
 (defn db-based-priorities
   []
   (map (fn [id] (get-in (db/entity [:block/uuid id]) [:block/schema :value]))
-    (pu/get-closed-property-values :task/priority)))
+    (pu/get-closed-property-values :logseq.task/priority)))
 
 (defn get-priorities
   []
@@ -659,7 +659,7 @@
 (defn- db-based-set-status
   [status]
   (when-let [block (state/get-edit-block)]
-    (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :task/status status)))
+    (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :logseq.task/status status)))
 
 (defmethod handle-step :editor/set-status [[_ status] format]
   (if (config/db-based-graph? (state/get-current-repo))
@@ -679,7 +679,7 @@
 (defn- db-based-set-priority
   [priority]
   (when-let [block (state/get-edit-block)]
-    (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :task/priority priority)))
+    (db-property-handler/batch-set-property-closed-value! [(:block/uuid block)] :logseq.task/priority priority)))
 
 (defmethod handle-step :editor/set-priority [[_ priority] _format]
   (if (config/db-based-graph? (state/get-current-repo))

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

@@ -234,7 +234,7 @@
                   (do
                     (upsert-property! repo k-name (assoc property-schema :type property-type)
                                       {:property-uuid property-uuid})
-                    (let [status? (= :task/status (:db/ident property))
+                    (let [status? (= :logseq.task/status (:db/ident property))
                           new-value (cond
                                       (and multiple-values? old-value
                                            (not= old-value :frontend.components.property/new-value-placeholder))
@@ -386,7 +386,7 @@
             (upsert-property! repo (name k-name) (assoc (:block/schema property) :type property-type)
                               {:property-uuid property-uuid}))
         {:keys [cardinality]} (:block/schema property)
-        status? (= :task/status (:db/ident property))
+        status? (= :logseq.task/status (:db/ident property))
         txs (mapcat
              (fn [id]
                (when-let [block (db/entity [:block/uuid id])]
@@ -674,7 +674,7 @@
 (defn re-init-commands!
   "Update commands after task status and priority's closed values has been changed"
   [property]
-  (when (contains? #{:task/status :task/priority} (:db/ident property))
+  (when (contains? #{:logseq.task/status :logseq.task/priority} (:db/ident property))
     (state/pub-event! [:init/commands])))
 
 (defn replace-closed-value

+ 7 - 7
src/main/frontend/handler/editor.cljs

@@ -643,17 +643,17 @@
 (defn db-based-cycle-todo!
   [block]
   (let [task (db/entity :logseq.class/task)
-        status-id (:block/uuid (db/entity :task/status))
+        status-id (:block/uuid (db/entity :logseq.task/status))
         status-value-id (get-in block [:block/properties status-id])
         status-value (when status-value-id (db/entity [:block/uuid status-value-id]))
         next-status (case (:db/ident status-value)
-                      :task/status.todo
-                      :task/status.doing
-                      :task/status.doing
-                      :task/status.done
-                      :task/status.done
+                      :logseq.task/status.todo
+                      :logseq.task/status.doing
+                      :logseq.task/status.doing
+                      :logseq.task/status.done
+                      :logseq.task/status.done
                       nil
-                      :task/status.todo)
+                      :logseq.task/status.todo)
         next-status-id (when next-status (:block/uuid (db/entity next-status)))
         properties (if next-status-id
                      (assoc (:block/properties block) status-id next-status-id)