Просмотр исходного кода

fix: remove most file graph uses in deps

except for graph-parser and publish deps

- Removed most mentions of 'repo' in deps, which cleaned up a lot related
  to export cli and worker
- Removed db-based-graph? checks in deps except for unknown use
  in entity-plus?
- Removing db-based-graph? checks resulted in deleting unused file graph
  code paths e.g. get-pid
- Removed file graph handling in cli list command
- Remove file-based-graph? checks from deps
Gabriel Horner 6 дней назад
Родитель
Сommit
b523416b4f
51 измененных файлов с 227 добавлено и 382 удалено
  1. 0 1
      .clj-kondo/config.edn
  2. 0 5
      deps/cli/README.md
  3. 9 13
      deps/cli/src/logseq/cli/commands/export.cljs
  4. 0 1
      deps/cli/src/logseq/cli/commands/export_edn.cljs
  5. 3 14
      deps/cli/src/logseq/cli/commands/graph.cljs
  6. 0 1
      deps/cli/src/logseq/cli/commands/import_edn.cljs
  7. 0 1
      deps/cli/src/logseq/cli/commands/query.cljs
  8. 0 1
      deps/cli/src/logseq/cli/commands/search.cljs
  9. 1 2
      deps/cli/src/logseq/cli/commands/validate.cljs
  10. 7 8
      deps/cli/src/logseq/cli/common/export/common.cljs
  11. 2 2
      deps/cli/src/logseq/cli/common/export/text.cljs
  12. 33 53
      deps/cli/src/logseq/cli/common/file.cljs
  13. 0 10
      deps/cli/src/logseq/cli/common/mcp/tools.cljs
  14. 0 6
      deps/cli/src/logseq/cli/util.cljs
  15. 0 1
      deps/db/.carve/config.edn
  16. 0 1
      deps/db/.clj-kondo/config.edn
  17. 7 5
      deps/db/README.md
  18. 27 35
      deps/db/src/logseq/db.cljs
  19. 2 3
      deps/db/src/logseq/db/common/delete_blocks.cljs
  20. 4 1
      deps/db/src/logseq/db/common/entity_plus.cljc
  21. 21 35
      deps/db/src/logseq/db/common/initial_data.cljs
  22. 0 42
      deps/db/src/logseq/db/common/property_util.cljs
  23. 8 28
      deps/db/src/logseq/db/common/reference.cljs
  24. 6 17
      deps/db/src/logseq/db/common/sqlite.cljs
  25. 1 9
      deps/db/src/logseq/db/common/sqlite_cli.cljs
  26. 17 0
      deps/db/src/logseq/db/frontend/property.cljs
  27. 1 1
      deps/db/src/logseq/db/frontend/rules.cljc
  28. 2 8
      deps/db/src/logseq/db/frontend/schema.cljs
  29. 3 1
      deps/db/test/logseq/db/common/initial_data_test.cljs
  30. 2 0
      deps/graph-parser/.carve/ignore
  31. 13 5
      deps/graph-parser/src/logseq/graph_parser/block.cljs
  32. 12 2
      deps/graph-parser/src/logseq/graph_parser/exporter.cljs
  33. 5 0
      deps/graph-parser/src/logseq/graph_parser/mldoc.cljc
  34. 2 18
      deps/graph-parser/src/logseq/graph_parser/whiteboard.cljs
  35. 1 2
      deps/outliner/src/logseq/outliner/transaction.cljc
  36. 2 2
      deps/outliner/src/logseq/outliner/tree.cljs
  37. 4 4
      src/main/frontend/components/block.cljs
  38. 4 4
      src/main/frontend/components/content.cljs
  39. 1 2
      src/main/frontend/components/icon.cljs
  40. 1 1
      src/main/frontend/components/reference.cljs
  41. 1 1
      src/main/frontend/components/reference_filters.cljs
  42. 8 2
      src/main/frontend/db/persist.cljs
  43. 1 5
      src/main/frontend/db/query_react.cljs
  44. 1 2
      src/main/frontend/extensions/pdf/assets.cljs
  45. 3 3
      src/main/frontend/handler/editor.cljs
  46. 3 5
      src/main/frontend/handler/export/common.cljs
  47. 1 2
      src/main/frontend/handler/export/html.cljs
  48. 1 2
      src/main/frontend/handler/export/opml.cljs
  49. 2 4
      src/main/frontend/handler/export/text.cljs
  50. 4 10
      src/main/frontend/handler/property/util.cljs
  51. 1 1
      src/main/frontend/worker/db_worker.cljs

+ 0 - 1
.clj-kondo/config.edn

@@ -171,7 +171,6 @@
              logseq.db.common.entity-plus entity-plus
              logseq.db.common.initial-data common-initial-data
              logseq.db.common.order db-order
-             logseq.db.common.property-util db-property-util
              logseq.db.common.sqlite common-sqlite
              logseq.db.common.view db-view
              logseq.db.frontend.class db-class

+ 0 - 5
deps/cli/README.md

@@ -37,16 +37,11 @@ validate [options]   Validate DB graph
 help                 Print a command's help
 
 $ logseq list
-DB Graphs:
 db-test
 docs
 woot
 ...
 
-File Graphs:
-docs
-...
-
 $ logseq show db-test
 
 |                         Name |                                              Value |

+ 9 - 13
deps/cli/src/logseq/cli/commands/export.cljs

@@ -9,7 +9,6 @@
             [logseq.cli.common.file :as common-file]
             [logseq.cli.common.util :as cli-common-util]
             [logseq.cli.util :as cli-util]
-            [logseq.common.config :as common-config]
             [logseq.common.util :as common-util]
             [logseq.db.common.sqlite-cli :as sqlite-cli]))
 
@@ -34,8 +33,8 @@
 
 (defn- get-file-contents
   "Modified version of export.common/<get-file-contents which doesn't have to deal with worker threads"
-  [repo db content-config suffix]
-  (let [page->content (common-file/get-all-page->content repo db content-config)]
+  [db content-config suffix]
+  (let [page->content (common-file/get-all-page->content db content-config)]
     (map (fn [[page-title content]]
            {:path (str page-title "." suffix)
             :content content
@@ -45,26 +44,24 @@
 
 (defn- export-files-as-markdown
   "Modified version of handler.export.text/export-files-as-markdown for the CLI"
-  [repo files options]
+  [files options]
   (mapv
    (fn [{:keys [path title content]}]
-     [(or path title) (cli-export-text/export-helper repo content :markdown options)])
+     [(or path title) (cli-export-text/export-helper content :markdown options)])
    files))
 
 (defn- export-repo-as-markdown!
   "Modified version of handler.export.text/export-repo-as-markdown for the CLI"
-  [repo db {:keys [file]}]
+  [graph db {:keys [file]}]
   (let [content-config (get-content-config db)
-        files* (get-file-contents repo db content-config "md")]
+        files* (get-file-contents db content-config "md")]
     (when (seq files*)
       (let [files (binding [cli-export-common/*current-db* db
-                            cli-export-common/*current-repo* repo
                             cli-export-common/*content-config* content-config]
-                    (export-files-as-markdown repo files* nil))
-            repo' (string/replace repo common-config/db-version-prefix "")
+                    (export-files-as-markdown files* nil))
             zip-file-name (if file
                             (string/replace-first file #"(?i)\.zip$" "")
-                            (str repo' "_markdown_" (quot (common-util/time-ms) 1000)))
+                            (str graph "_markdown_" (quot (common-util/time-ms) 1000)))
             file-name (or file (str zip-file-name ".zip"))
             zip (cli-common-util/make-export-zip zip-file-name files)
             ;; matches behavior in make-export-zip
@@ -78,6 +75,5 @@
     (cli-util/error "Command missing required option 'graph'"))
   (if (fs/existsSync (cli-util/get-graph-path graph))
     (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))]
-      (cli-util/ensure-db-graph-for-command @conn)
-      (export-repo-as-markdown! (str common-config/db-version-prefix graph) @conn opts))
+      (export-repo-as-markdown! graph @conn opts))
     (cli-util/error "Graph" (pr-str graph) "does not exist")))

+ 0 - 1
deps/cli/src/logseq/cli/commands/export_edn.cljs

@@ -33,7 +33,6 @@
     (cli-util/error "Command missing required option 'graph'"))
   (if (fs/existsSync (cli-util/get-graph-path graph))
     (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
-          _ (cli-util/ensure-db-graph-for-command @conn)
           export-map (sqlite-export/build-export @conn (build-export-options options))]
       (when validate
         (validate-export export-map options))

+ 3 - 14
deps/cli/src/logseq/cli/commands/graph.cljs

@@ -1,7 +1,6 @@
 (ns logseq.cli.commands.graph
   "Graph related commands"
   (:require ["fs" :as fs]
-            ["path" :as node-path]
             [cljs-time.coerce :as tc]
             [clojure.pprint :as pprint]
             [clojure.string :as string]
@@ -22,7 +21,6 @@
     (let [graph-dir (cli-util/get-graph-path graph)]
       (if (fs/existsSync graph-dir)
         (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
-              _ (cli-util/ensure-db-graph-for-command @conn)
               kv-value #(:kv/value (d/entity @conn %))]
           (pprint/print-table
            (map #(array-map "Name" (first %) "Value" (second %))
@@ -39,16 +37,7 @@
 
 (defn list-graphs
   []
-  (let [[db-graphs* file-graphs*] ((juxt filter remove) #(string/starts-with? % common-config/db-version-prefix)
-                                                        (cli-common-graph/get-db-based-graphs))
-        db-graphs (->> db-graphs*
+  (let [db-graphs (->> (cli-common-graph/get-db-based-graphs)
                        (map #(string/replace-first % common-config/db-version-prefix ""))
-                       sort)
-        file-graphs (->> file-graphs*
-                         (map #(string/replace-first % common-config/file-version-prefix ""))
-                         (map node-path/basename)
-                         sort)]
-    (println "DB Graphs:")
-    (println (string/join "\n" db-graphs))
-    (println "\nFile Graphs:")
-    (println (string/join "\n" file-graphs))))
+                       sort)]
+    (println (string/join "\n" db-graphs))))

+ 0 - 1
deps/cli/src/logseq/cli/commands/import_edn.cljs

@@ -26,7 +26,6 @@
   (if (fs/existsSync (cli-util/get-graph-path graph))
     (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
           _ (db-pipeline/add-listener conn)
-          _ (cli-util/ensure-db-graph-for-command @conn)
           {:keys [init-tx block-props-tx misc-tx]}
           (sqlite-export/build-import import-map @conn {})
           txs (vec (concat init-tx block-props-tx misc-tx))]

+ 0 - 1
deps/cli/src/logseq/cli/commands/query.cljs

@@ -77,7 +77,6 @@
   (doseq [graph graphs]
     (if (fs/existsSync (cli-util/get-graph-path graph))
       (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
-            _ (cli-util/ensure-db-graph-for-command @conn)
             query* (when (string? (first args)) (common-util/safe-read-string {:log-error? false} (first args)))
             results (cond
                       ;; Run datalog query if detected

+ 0 - 1
deps/cli/src/logseq/cli/commands/search.cljs

@@ -55,7 +55,6 @@
     (cli-util/error "Command missing required option 'graph'"))
   (if (fs/existsSync (cli-util/get-graph-path graph))
     (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
-          _ (cli-util/ensure-db-graph-for-command @conn)
           nodes (->> (d/datoms @conn :aevt :block/title)
                      (filter (fn [datom]
                                (string/includes? (:v datom) search-term)))

+ 1 - 2
deps/cli/src/logseq/cli/commands/validate.cljs

@@ -21,8 +21,7 @@
 
 (defn- validate-graph [graph options]
   (if (fs/existsSync (cli-util/get-graph-path graph))
-    (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))
-          _ (cli-util/ensure-db-graph-for-command @conn)]
+    (let [conn (apply sqlite-cli/open-db! (cli-util/->open-db-args graph))]
       (validate-db @conn graph options))
     (cli-util/error "Graph" (pr-str graph) "does not exist")))
 

+ 7 - 8
deps/cli/src/logseq/cli/common/export/common.cljs

@@ -55,21 +55,20 @@
 ;; Global vars that are not explicitly passed in all fns
 ;; These vars must be bound in order to use most fns in this namespace
 (def ^:dynamic *current-db* nil)
-(def ^:dynamic *current-repo* nil)
 ;; Config used by logseq.cli.common.file fns
 (def ^:dynamic *content-config* nil)
 
 ;;; internal utils
 (defn ^:api get-blocks-contents
   [root-block-uuid & {:keys [init-level]
-                           :or {init-level 1}}]
+                      :or {init-level 1}}]
   (let [block (d/entity *current-db* [:block/uuid root-block-uuid])
         link (:block/link block)
         block' (or link block)
         root-id (:block/uuid block')
         blocks (ldb/get-block-and-children *current-db* root-id)
         tree (otree/blocks->vec-tree *current-db* blocks root-id {:link link})]
-    (common-file/tree->file-content *current-repo* *current-db* tree
+    (common-file/tree->file-content *current-db* tree
                                     {:init-level init-level :link link}
                                     *content-config*)))
 
@@ -78,12 +77,12 @@
 (defn- block-uuid->ast
   [block-uuid]
   (let [block (into {} (d/entity *current-db* [:block/uuid block-uuid]))
-        content (common-file/tree->file-content *current-repo* *current-db* [block] {:init-level 1} *content-config*)
+        content (common-file/tree->file-content *current-db* [block] {:init-level 1} *content-config*)
         format :markdown]
     (when content
       (removev Properties-block-ast?
                (mapv remove-block-ast-pos
-                     (gp-mldoc/->edn *current-repo* content format))))))
+                     (gp-mldoc/->db-edn content format))))))
 
 (defn- block-uuid->ast-with-children
   [block-uuid]
@@ -92,11 +91,11 @@
     (when content
       (removev Properties-block-ast?
                (mapv remove-block-ast-pos
-                     (gp-mldoc/->edn *current-repo* content format))))))
+                     (gp-mldoc/->db-edn content format))))))
 
 (defn ^:api get-page-content
   [page-uuid]
-  (common-file/block->content *current-repo* *current-db* page-uuid nil *content-config*))
+  (common-file/block->content *current-db* page-uuid nil *content-config*))
 
 (defn- page-name->ast
   [page-name]
@@ -106,7 +105,7 @@
         (let [format :markdown]
           (removev Properties-block-ast?
                    (mapv remove-block-ast-pos
-                         (gp-mldoc/->edn *current-repo* content format))))))))
+                         (gp-mldoc/->db-edn content format))))))))
 
 (defn- update-level-in-block-ast-coll
   [block-ast-coll origin-level]

+ 2 - 2
deps/cli/src/logseq/cli/common/export/text.cljs

@@ -451,7 +451,7 @@
 ;;; block-ast, inline-ast -> simple-ast (ends)
 
 (defn ^:large-vars/cleanup-todo export-helper
-  [repo content format options]
+  [content format options]
   (let [remove-options (set (:remove-options options))
         other-options (:other-options options)]
     (binding [*state* (merge *state*
@@ -463,7 +463,7 @@
                                :remove-properties? (contains? remove-options :property)
                                :keep-only-level<=N (:keep-only-level<=N other-options)
                                :newline-after-block (:newline-after-block other-options)}})]
-      (let [ast (gp-mldoc/->edn repo content format)
+      (let [ast (gp-mldoc/->db-edn content format)
             ast (mapv cli-export-common/remove-block-ast-pos ast)
             ast (removev cli-export-common/Properties-block-ast? ast)
             ast* (cli-export-common/replace-block&page-reference&embed ast)

+ 33 - 53
deps/cli/src/logseq/cli/common/file.cljs

@@ -1,6 +1,5 @@
 (ns logseq.cli.common.file
-  "Convert blocks to file content for file and DB graphs. Used for exports and
-  saving file to disk. Shared by CLI, worker and frontend namespaces"
+  "Convert blocks to file content. Used for frontend exports and CLI"
   (:require [clojure.string :as string]
             [datascript.core :as d]
             [logseq.db :as ldb]
@@ -13,48 +12,35 @@
   (let [lines (string/split-lines content)]
     (string/join (str "\n" spaces-tabs) lines)))
 
-(defn- ^:large-vars/cleanup-todo transform-content
-  [db {:block/keys [format pre-block? properties] :as b} level {:keys [heading-to-list?]} context]
-  (let [heading (:heading properties)
-                ;; replace [[uuid]] with block's content
+(defn- transform-content
+  [db b level {:keys [heading-to-list?]} context]
+  (let [heading (:logseq.property/heading b)
+        ;; replace [[uuid]] with block's content
         title (db-content/recur-replace-uuid-in-block-title (d/entity db (:db/id b)))
         content (or title "")
-        content (cond
-                  pre-block?
-                  (let [content (string/trim content)]
-                    (str content "\n"))
-
-                  :else
-                  (let [[prefix spaces-tabs]
-                        (cond
-                          (= format :org)
-                          [(->>
-                            (repeat level "*")
-                            (apply str)) ""]
-
-                          :else
-                          (let [level (if (and heading-to-list? heading)
-                                        (if (> heading 1)
-                                          (dec heading)
-                                          heading)
-                                        level)
-                                spaces-tabs (->>
-                                             (repeat (dec level) (:export-bullet-indentation context))
-                                             (apply str))]
-                            [(str spaces-tabs "-") (str spaces-tabs "  ")]))
-                        content (if heading-to-list?
-                                  (-> (string/replace content #"^\s?#+\s+" "")
-                                      (string/replace #"^\s?#+\s?$" ""))
-                                  content)
-                        new-content (indented-block-content (string/trim content) spaces-tabs)
-                        sep (if (string/blank? new-content)
-                              ""
-                              " ")]
-                    (str prefix sep new-content)))]
+        content (let [[prefix spaces-tabs]
+                      (let [level (if (and heading-to-list? heading)
+                                    (if (> heading 1)
+                                      (dec heading)
+                                      heading)
+                                    level)
+                            spaces-tabs (->>
+                                         (repeat (dec level) (:export-bullet-indentation context))
+                                         (apply str))]
+                        [(str spaces-tabs "-") (str spaces-tabs "  ")])
+                      content (if heading-to-list?
+                                (-> (string/replace content #"^\s?#+\s+" "")
+                                    (string/replace #"^\s?#+\s?$" ""))
+                                content)
+                      new-content (indented-block-content (string/trim content) spaces-tabs)
+                      sep (if (string/blank? new-content)
+                            ""
+                            " ")]
+                  (str prefix sep new-content))]
     content))
 
 (defn- tree->file-content-aux
-  [repo db tree {:keys [init-level link] :as opts} context]
+  [db tree {:keys [init-level link] :as opts} context]
   (let [block-contents (transient [])]
     (loop [[f & r] tree level init-level]
       (if (nil? f)
@@ -63,40 +49,34 @@
               content (if (and page? (not link)) nil (transform-content db f level opts context))
               new-content
               (if-let [children (seq (:block/children f))]
-                (cons content (tree->file-content-aux repo db children {:init-level (inc level)} context))
+                (cons content (tree->file-content-aux db children {:init-level (inc level)} context))
                 [content])]
           #_:clj-kondo/ignore
           (conj! block-contents new-content)
           (recur r level))))))
 
 (defn tree->file-content
-  "Used by both file and DB graphs for export and for file-graph specific features"
-  [repo db tree opts context]
-  (->> (tree->file-content-aux repo db tree opts context) (string/join "\n")))
-
-(defn- update-block-content
-  [db item eid]
-  ;; This may not be needed if this becomes a file-graph only context
-  (db-content/update-block-content db item eid))
+  [db tree opts context]
+  (->> (tree->file-content-aux db tree opts context) (string/join "\n")))
 
 (defn block->content
   "Converts a block including its children (recursively) to plain-text."
-  [repo db root-block-uuid tree->file-opts context]
+  [db root-block-uuid tree->file-opts context]
   (assert (uuid? root-block-uuid))
   (let [init-level (or (:init-level tree->file-opts)
                        (if (ldb/page? (d/entity db [:block/uuid root-block-uuid]))
                          0
                          1))
         blocks (->> (d/pull-many db '[*] (keep :db/id (ldb/get-block-and-children db root-block-uuid)))
-                    (map #(update-block-content db % (:db/id %))))
+                    (map #(db-content/update-block-content db % (:db/id %))))
         tree (otree/blocks->vec-tree db blocks (str root-block-uuid))]
-    (tree->file-content repo db tree
+    (tree->file-content db tree
                         (assoc tree->file-opts :init-level init-level)
                         context)))
 
 (defn get-all-page->content
   "Exports a graph's pages as tuples of page name and page content"
-  [repo db options]
+  [db options]
   (let [filter-fn (fn [ent]
                     (or (not (:logseq.property/built-in? ent))
                         (contains? sqlite-create-graph/built-in-pages-names (:block/title ent))))]
@@ -105,4 +85,4 @@
          (filter filter-fn)
          (map (fn [e]
                 [(:block/title e)
-                 (block->content repo db (:block/uuid e) {} options)])))))
+                 (block->content db (:block/uuid e) {} options)])))))

+ 0 - 10
deps/cli/src/logseq/cli/common/mcp/tools.cljs

@@ -16,15 +16,9 @@
             [malli.core :as m]
             [malli.error :as me]))
 
-(defn- ensure-db-graph
-  [db]
-  (when-not (ldb/db-based-graph? db)
-    (throw (ex-info "This tool must be called on a DB graph" {}))))
-
 (defn list-properties
   "Main fn for ListProperties tool"
   [db {:keys [expand]}]
-  (ensure-db-graph db)
   (->> (d/datoms db :avet :block/tags :logseq.class/Property)
        (map #(d/entity db (:e %)))
        #_((fn [x] (prn :prop-keys (distinct (mapcat keys x))) x))
@@ -46,7 +40,6 @@
 (defn list-tags
   "Main fn for ListTags tool"
   [db {:keys [expand]}]
-  (ensure-db-graph db)
   (->> (d/datoms db :avet :block/tags :logseq.class/Tag)
        (map #(d/entity db (:e %)))
        (map (fn [e]
@@ -88,7 +81,6 @@
 (defn get-page-data
   "Get page data for GetPage tool including the page's entity and its blocks"
   [db page-name-or-uuid]
-  (ensure-db-graph db)
   (when-let [page (ldb/get-page db page-name-or-uuid)]
     {:entity (-> (remove-hidden-properties page)
                  (dissoc :block/tags :block/refs)
@@ -102,7 +94,6 @@
 (defn list-pages
   "Main fn for ListPages tool"
   [db {:keys [expand]}]
-  (ensure-db-graph db)
   (->> (d/datoms db :avet :block/name)
        (map #(d/entity db (:e %)))
        (remove entity-util/hidden?)
@@ -368,7 +359,6 @@
   "Given llm generated operations, builds the import EDN, validates it and returns it. It fails
    fast on anything invalid"
   [db operations*]
-  (ensure-db-graph db)
   ;; Only support these operations with appropriate outliner validations
   (when (seq (filter #(and (#{"page" "tag" "property"} (:entityType %)) (= "edit" (:operation %))) operations*))
     (throw (ex-info "Editing a page, tag or property isn't supported yet" {})))

+ 0 - 6
deps/cli/src/logseq/cli/util.cljs

@@ -4,7 +4,6 @@
             ["path" :as node-path]
             [clojure.string :as string]
             [logseq.cli.common.graph :as cli-common-graph]
-            [logseq.db.common.entity-plus :as entity-plus]
             [logseq.db.common.sqlite :as common-sqlite]
             [nbb.error]
             [promesa.core :as p]))
@@ -82,11 +81,6 @@
          (count (:classes edn-map)) " " (pluralize "class" (count (:classes edn-map))) " and "
          (count (:pages-and-blocks edn-map)) " " (pluralize "page" (count (:pages-and-blocks edn-map))))))
 
-(defn ensure-db-graph-for-command
-  [db]
-  (when-not (entity-plus/db-based-graph? db)
-    (error "This command must be called on a DB graph")))
-
 (defn api-command?
   "Given user options and $LOGSEQ_API_SERVER_TOKEN, determines if
    given command is an api (true) or local (false) command"

+ 0 - 1
deps/db/.carve/config.edn

@@ -4,7 +4,6 @@
                   logseq.db.common.sqlite-cli
                   logseq.db.frontend.property
                   logseq.db.frontend.property.build
-                  logseq.db.common.property-util
                   logseq.db.frontend.content
                   logseq.db.common.order
                   logseq.db.sqlite.create-graph

+ 0 - 1
deps/db/.clj-kondo/config.edn

@@ -11,7 +11,6 @@
              logseq.db ldb
              logseq.db.common.entity-plus entity-plus
              logseq.db.common.order db-order
-             logseq.db.common.property-util db-property-util
              logseq.db.common.sqlite common-sqlite
              logseq.db.common.view db-view
              logseq.db.frontend.content db-content

+ 7 - 5
deps/db/README.md

@@ -3,19 +3,21 @@
 This library provides an API to the
 frontend([datascript](https://github.com/tonsky/datascript)) and
 backend([SQLite](https://www.sqlite.org/index.html)) databases from the Logseq
-app and the CLI. The majority of this library is focused on supporting DB graphs
-but there are a few namespaces that support file graphs. This library is
-compatible with ClojureScript and with
+app and the CLI. This library defines the core schema and fns for DB graphs.
+There are a few namespaces that also support file graphs for the graph-parser.
+This library is compatible with ClojureScript and with
 [nbb-logseq](https://github.com/logseq/nbb-logseq) to respectively provide
 frontend and commandline functionality.
 
 ## API
 
 This library is under the parent namespace `logseq.db`. It provides the following namespaces:
-* `logseq.db` - main entry point serving both file and DB graphs
+* `logseq.db` - main public ns. Most often used by frontend
 * `logseq.db.frontend.*` - frontend namespaces for DB graphs
 * `logseq.db.sqlite.*` - backend/sqlite namespaces for DB graphs
-* `logseq.db.common.*` - namespaces for both file and DB graphs
+* `logseq.db.common.*` - frontend and backend namespaces for DB graphs
+
+The following namespaces are used with file graphs via the graph-parser: `logseq.db.common.order, logseq.db.frontend.entity-util and logseq.db.common.entity-plus`.
 
 ## Usage
 

+ 27 - 35
deps/db/src/logseq/db.cljs

@@ -1,6 +1,5 @@
 (ns logseq.db
-  "Main namespace for db fns that handles DB and file graphs. For db graph only
-  fns, you can also use logseq.db.frontend.db."
+  "Main namespace for db fns. All fns are only for DB graphs"
   (:require [clojure.set :as set]
             [clojure.string :as string]
             [clojure.walk :as walk]
@@ -308,44 +307,37 @@
 
 (def get-first-page-by-name common-initial-data/get-first-page-by-name)
 
-(def db-based-graph? entity-plus/db-based-graph?)
-
 (defn page-exists?
-  "Returns truthy value if page exists.
-   For db graphs, returns all page db ids that given title and one of the given `tags`.
-   For file graphs, returns page db/id vector if it exists"
+  "Returns all page db ids that given title and one of the given `tags`."
   [db page-name tags]
   (when page-name
-    (if (db-based-graph? db)
-      (let [tags' (if (coll? tags) (set tags) #{tags})]
+    (let [tags' (if (coll? tags) (set tags) #{tags})]
         ;; Classes and properties are case sensitive and can be looked up
         ;; as such in case-sensitive contexts e.g. no Page
-        (if (and (seq tags') (every? #{:logseq.class/Tag :logseq.class/Property} tags'))
-          (seq
-           (d/q
-            '[:find [?p ...]
-              :in $ ?name [?tag-ident ...]
-              :where
-              [?p :block/title ?name]
-              [?p :block/tags ?tag]
-              [?tag :db/ident ?tag-ident]]
-            db
-            page-name
-            tags'))
-          ;; TODO: Decouple db graphs from file specific :block/name
-          (seq
-           (d/q
-            '[:find [?p ...]
-              :in $ ?name [?tag-ident ...]
-              :where
-              [?p :block/name ?name]
-              [?p :block/tags ?tag]
-              [?tag :db/ident ?tag-ident]]
-            db
-            (common-util/page-name-sanity-lc page-name)
-            tags'))))
-      (when-let [id (:db/id (d/entity db [:block/name (common-util/page-name-sanity-lc page-name)]))]
-        [id]))))
+      (if (and (seq tags') (every? #{:logseq.class/Tag :logseq.class/Property} tags'))
+        (seq
+         (d/q
+          '[:find [?p ...]
+            :in $ ?name [?tag-ident ...]
+            :where
+            [?p :block/title ?name]
+            [?p :block/tags ?tag]
+            [?tag :db/ident ?tag-ident]]
+          db
+          page-name
+          tags'))
+        ;; TODO: Decouple db graphs from file specific :block/name
+        (seq
+         (d/q
+          '[:find [?p ...]
+            :in $ ?name [?tag-ident ...]
+            :where
+            [?p :block/name ?name]
+            [?p :block/tags ?tag]
+            [?tag :db/ident ?tag-ident]]
+          db
+          (common-util/page-name-sanity-lc page-name)
+          tags'))))))
 
 (defn get-page
   "Get a page given its unsanitized name or uuid"

+ 2 - 3
deps/db/src/logseq/db/common/delete_blocks.cljs

@@ -1,5 +1,5 @@
 (ns logseq.db.common.delete-blocks
-  "For file and DB graphs, provides fn to handle any deletion to occur per ldb/transact!"
+  "Provides fn to handle any deletion to occur per ldb/transact!"
   (:require [clojure.string :as string]
             [datascript.core :as d]
             [logseq.common.util :as common-util]
@@ -46,8 +46,7 @@
      refs)))
 
 (defn update-refs-history-and-macros
-  "When a block is deleted, refs are updated, property history are deleted. For file graphs, macros associated
-  with the block are also deleted"
+  "When a block is deleted, refs are updated, property history are deleted"
   [db txs _opts]
   (let [retracted-block-ids (->> (keep (fn [tx]
                                          (when (and (vector? tx)

+ 4 - 1
deps/db/src/logseq/db/common/entity_plus.cljc

@@ -1,5 +1,7 @@
 (ns logseq.db.common.entity-plus
   "Add map ops such as assoc/dissoc to datascript Entity.
+   The db-based-graph? checks are still in this ns because it's unclear which of these
+   lower level fns are still used by the graph-parser.
 
    NOTE: This doesn't work for nbb/sci yet because of https://github.com/babashka/sci/issues/639"
   ;; Disable clj linters since we don't support clj
@@ -75,7 +77,8 @@
   (Entity. db e (volatile! false) (volatile! {})))
 
 (defn db-based-graph?
-  "Whether the current graph is db-only"
+  "Whether the current graph is db-only. This should only be used in contexts
+   where both DB and file graph databases are possible e.g. graph-parser"
   [db]
   (when db
     (identical? "db" (:kv/value (entity-memoized db :logseq.kv/db-type)))))

+ 21 - 35
deps/db/src/logseq/db/common/initial_data.cljs

@@ -6,7 +6,6 @@
             [logseq.common.config :as common-config]
             [logseq.common.util :as common-util]
             [logseq.common.util.date-time :as date-time-util]
-            [logseq.db.common.entity-plus :as entity-plus]
             [logseq.db.common.order :as db-order]
             [logseq.db.frontend.class :as db-class]
             [logseq.db.frontend.db :as db-db]
@@ -164,23 +163,18 @@
 (defn hidden-ref?
   "Whether ref-block (for block with the `id`) should be hidden."
   [db ref-block id]
-  (let [db-based? (entity-plus/db-based-graph? db)]
-    (if db-based?
-      (let [entity (d/entity db id)]
-        (or
-         (= (:db/id ref-block) id)
-         (= id (:db/id (:block/page ref-block)))
-         (= id (:db/id (:logseq.property/view-for ref-block)))
-         (entity-util/hidden? (:block/page ref-block))
-         (entity-util/hidden? ref-block)
-         (and (entity-util/class? entity)
-              (let [children (db-class/get-structured-children db id)
-                    class-ids (set (conj children id))]
-                (some class-ids (map :db/id (:block/tags ref-block)))))
-         (some? (get ref-block (:db/ident entity)))))
-      (or
-       (= (:db/id ref-block) id)
-       (= id (:db/id (:block/page ref-block)))))))
+  (let [entity (d/entity db id)]
+    (or
+     (= (:db/id ref-block) id)
+     (= id (:db/id (:block/page ref-block)))
+     (= id (:db/id (:logseq.property/view-for ref-block)))
+     (entity-util/hidden? (:block/page ref-block))
+     (entity-util/hidden? ref-block)
+     (and (entity-util/class? entity)
+          (let [children (db-class/get-structured-children db id)
+                class-ids (set (conj children id))]
+            (some class-ids (map :db/id (:block/tags ref-block)))))
+     (some? (get ref-block (:db/ident entity))))))
 
 (defn get-block-refs
   [db id]
@@ -324,12 +318,9 @@
      (d/datoms db :avet :logseq.property.user/email))))
 
 (defn get-initial-data
-  "Returns current database schema and initial data.
-   NOTE: This fn is called by DB and file graphs"
+  "Returns current database schema and initial data"
   [db]
-  (let [db-graph? (entity-plus/db-based-graph? db)
-        _ (when db-graph?
-            (reset! db-order/*max-key (db-order/get-max-order db)))
+  (let [_ (reset! db-order/*max-key (db-order/get-max-order db))
         schema (:schema db)
         idents (mapcat (fn [id]
                          (when-let [e (d/entity db id)]
@@ -342,22 +333,17 @@
                         :logseq.kv/graph-backup-folder
                         :logseq.kv/graph-text-embedding-model-name
                         :logseq.property/empty-placeholder])
-        favorites (when db-graph? (get-favorites db))
+        favorites (get-favorites db)
         recent-updated-pages (let [pages (get-recent-updated-pages db)]
                                (mapcat (fn [p] (d/datoms db :eavt (:db/id p))) pages))
         all-files (get-all-files db)
-        structured-datoms (when db-graph?
-                            (get-structured-datoms db))
+        structured-datoms (get-structured-datoms db)
         user-datoms (get-all-user-datoms db)
-        pages-datoms (if db-graph?
-                       (let [contents-id (get-first-page-by-title db "Contents")
-                             capture-page-id (:db/id (db-db/get-built-in-page db common-config/quick-add-page-name))
-                             views-id (get-first-page-by-title db common-config/views-page-name)]
-                         (mapcat #(d/datoms db :eavt %)
-                                 (remove nil? [contents-id capture-page-id views-id])))
-                       ;; load all pages for file graphs
-                       (->> (d/datoms db :avet :block/name)
-                            (mapcat (fn [d] (d/datoms db :eavt (:e d))))))
+        pages-datoms (let [contents-id (get-first-page-by-title db "Contents")
+                           capture-page-id (:db/id (db-db/get-built-in-page db common-config/quick-add-page-name))
+                           views-id (get-first-page-by-title db common-config/views-page-name)]
+                       (mapcat #(d/datoms db :eavt %)
+                               (remove nil? [contents-id capture-page-id views-id])))
         data (->> (concat idents
                           structured-datoms
                           user-datoms

+ 0 - 42
deps/db/src/logseq/db/common/property_util.cljs

@@ -1,42 +0,0 @@
-(ns logseq.db.common.property-util
-  "Property related util fns. Fns used in both DB and file graphs should go here"
-  (:require [datascript.core :as d]
-            [logseq.db.frontend.property :as db-property]
-            [logseq.db.sqlite.util :as sqlite-util]))
-
-(defn get-file-pid
-  "Gets file graph property id given the db graph ident"
-  [db-ident]
-  ;; Map of unique cases where the db graph keyword name is different than the file graph id
-  (let [unique-file-ids {:logseq.property/order-list-type :logseq.order-list-type
-                         :logseq.property.tldraw/page :logseq.tldraw.page
-                         :logseq.property.tldraw/shape :logseq.tldraw.shape
-                         :logseq.property/publishing-public? :public}]
-    (or (get unique-file-ids db-ident)
-        (keyword (name db-ident)))))
-
-;; TODO: replace repo with db later to remove this fn
-(defn get-pid
-  "Get a built-in property's id (keyword name for file graph and db-ident for db
-  graph) given its db-ident. No need to use this fn in a db graph only context"
-  [repo db-ident]
-  (if (sqlite-util/db-based-graph? repo)
-    db-ident
-    (get-file-pid db-ident)))
-
-(defn lookup
-  "Get the property value by a built-in property's db-ident from coll"
-  [block db-ident]
-  (let [val (get block db-ident)]
-    (if (db-property/built-in-has-ref-value? db-ident) (db-property/property-value-content val) val)))
-
-(defn get-block-property-value
-  "Get the value of built-in block's property by its db-ident"
-  [db block db-ident]
-  (when db
-    (let [block (or (d/entity db (:db/id block)) block)]
-      (lookup block db-ident))))
-
-(defn shape-block?
-  [db block]
-  (= :whiteboard-shape (get-block-property-value db block :logseq.property/ls-type)))

+ 8 - 28
deps/db/src/logseq/db/common/reference.cljs

@@ -1,12 +1,9 @@
 (ns logseq.db.common.reference
   "References"
-  (:require [cljs.reader :as reader]
-            [clojure.set :as set]
+  (:require [clojure.set :as set]
             [clojure.string :as string]
             [datascript.core :as d]
-            [logseq.common.log :as log]
             [logseq.db :as ldb]
-            [logseq.db.common.entity-plus :as entity-plus]
             [logseq.db.common.initial-data :as common-initial-data]
             [logseq.db.frontend.class :as db-class]
             [logseq.db.frontend.entity-util :as entity-util]))
@@ -240,34 +237,17 @@
 ;; -----------------------------------------------------------------------------
 
 (defn get-filters
-  [db page]
-  (let [db-based? (entity-plus/db-based-graph? db)]
-    (if db-based?
-      (let [included-pages (:logseq.property.linked-references/includes page)
-            excluded-pages (:logseq.property.linked-references/excludes page)]
-        (when (or (seq included-pages) (seq excluded-pages))
-          {:included included-pages
-           :excluded excluded-pages}))
-      (let [k :filters
-            properties (:block/properties page)
-            properties-str (or (get properties k) "{}")]
-        (try (let [result (reader/read-string properties-str)]
-               (when (seq result)
-                 (let [excluded-pages (->> (filter #(false? (second %)) result)
-                                           (keep first)
-                                           (keep #(ldb/get-page db %)))
-                       included-pages (->> (filter #(true? (second %)) result)
-                                           (keep first)
-                                           (keep #(ldb/get-page db %)))]
-                   {:included included-pages
-                    :excluded excluded-pages})))
-             (catch :default e
-               (log/error :syntax/filters e)))))))
+  [page]
+  (let [included-pages (:logseq.property.linked-references/includes page)
+        excluded-pages (:logseq.property.linked-references/excludes page)]
+    (when (or (seq included-pages) (seq excluded-pages))
+      {:included included-pages
+       :excluded excluded-pages})))
 
 (defn get-linked-references [db id]
   (let [entity       (d/entity db id)
         ids          (set (cons id (ldb/get-block-alias db id)))
-        page-filters (get-filters db entity)
+        page-filters (get-filters entity)
         excludes     (map :db/id (:excluded page-filters))
         includes     (map :db/id (:included page-filters))
         has-filters? (or (seq excludes) (seq includes))

+ 6 - 17
deps/db/src/logseq/db/common/sqlite.cljs

@@ -1,10 +1,8 @@
 (ns logseq.db.common.sqlite
-  "Provides common sqlite util fns for file and DB graphs. These fns work on
-  browser and node"
+  "Provides common sqlite util fns that work on browser and node"
   (:require ["path" :as node-path]
             [clojure.string :as string]
             [datascript.core :as d]
-            [logseq.common.config :as common-config]
             [logseq.db.sqlite.util :as sqlite-util]))
 
 (defn create-kvs-table!
@@ -18,22 +16,13 @@
   (or (d/restore-conn storage)
       (d/create-conn schema {:storage storage})))
 
-(defn local-file-based-graph?
-  [s]
-  (and (string? s)
-       (string/starts-with? s common-config/file-version-prefix)))
-
 (defn sanitize-db-name
   [db-name]
-  (if (string/starts-with? db-name common-config/file-version-prefix)
-    (-> db-name
-        (string/replace ":" "+3A+")
-        (string/replace "/" "++"))
-    (-> db-name
-        (string/replace sqlite-util/db-version-prefix "")
-        (string/replace "/" "_")
-        (string/replace "\\" "_")
-        (string/replace ":" "_"))));; windows
+  (-> db-name
+      (string/replace sqlite-util/db-version-prefix "")
+      (string/replace "/" "_")
+      (string/replace "\\" "_")
+      (string/replace ":" "_")));; windows
 
 (defn get-db-full-path
   [graphs-dir db-name]

+ 1 - 9
deps/db/src/logseq/db/common/sqlite_cli.cljs

@@ -1,7 +1,6 @@
 (ns ^:node-only logseq.db.common.sqlite-cli
-  "Primary ns to interact with DB files for DB and file graphs with node.js based CLIs"
+  "Primary ns to interact with DB files with node.js based CLIs"
   (:require ["better-sqlite3" :as sqlite3]
-            ["fs" :as fs]
             ["os" :as os]
             ["path" :as node-path]
             [cljs-bean.core :as bean]
@@ -11,13 +10,6 @@
             [logseq.db.frontend.schema :as db-schema]
             [logseq.db.sqlite.util :as sqlite-util]))
 
-;; Should this check directory name instead if file graphs also
-;; have this file?
-(defn db-graph-directory?
-  "Returns boolean indicating if the given directory is a DB graph"
-  [graph-dir]
-  (fs/existsSync (node-path/join graph-dir "db.sqlite")))
-
 ;; Reference same sqlite default class in cljs + nbb without needing .cljc
 (def sqlite (if (find-ns 'nbb.core) (aget sqlite3 "default") sqlite3))
 

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

@@ -870,3 +870,20 @@
                   :else
                   false)))
             values)))
+
+(defn lookup
+  "Get the property value by a built-in property's db-ident from coll"
+  [block db-ident]
+  (let [val (get block db-ident)]
+    (if (built-in-has-ref-value? db-ident) (property-value-content val) val)))
+
+(defn get-block-property-value
+  "Get the value of built-in block's property by its db-ident"
+  [db block db-ident]
+  (when db
+    (let [block (or (d/entity db (:db/id block)) block)]
+      (lookup block db-ident))))
+
+(defn shape-block?
+  [db block]
+  (= :whiteboard-shape (get-block-property-value db block :logseq.property/ls-type)))

+ 1 - 1
deps/db/src/logseq/db/frontend/rules.cljc

@@ -2,7 +2,7 @@
   "Datalog rules for DB graphs")
 
 (def ^:large-vars/data-var rules
-  "Rules used mainly in frontend.db.model for both DB and file graphs"
+  "Rules used mainly in frontend.db.model"
   ;; rule "parent" is optimized for parent node -> child node nesting queries
   {:parent
    '[[(parent ?p ?c)

+ 2 - 8
deps/db/src/logseq/db/frontend/schema.cljs

@@ -1,16 +1,10 @@
 (ns logseq.db.frontend.schema
-  "Schema related fns for DB and file graphs"
+  "Schema related fns"
   (:require [clojure.set :as set]
             [clojure.string :as string]))
 
 (def schema-version? (every-pred map? :major))
 
-(def major-schema-version-string-schema
-  [:and :string
-   [:fn
-    {:error/message "should be a major schema-version"}
-    (fn [s] (some? (parse-long s)))]])
-
 (defn parse-schema-version
   "Return schema-version({:major <num> :minor <num>}).
   supported input: 10, \"10.1\", [10 1]"
@@ -60,7 +54,7 @@
     :else (throw (ex-info "Not a schema-version" {:data schema-version}))))
 
 (def ^:large-vars/data-var schema
-  "Schema for file graphs"
+  "Schema for DB graphs"
   {:db/ident        {:db/unique :db.unique/identity}
    :kv/value       {}
 

+ 3 - 1
deps/db/test/logseq/db/common/initial_data_test.cljs

@@ -31,6 +31,7 @@
     (create-graph-dir "tmp/graphs" "test-db")
 
     (let [conn* (sqlite-cli/open-db! "tmp/graphs" "test-db")
+          _ (d/transact! conn* (sqlite-create-graph/build-db-initial-data "{}"))
           blocks [{:file/path "logseq/config.edn"
                    :file/content "{:foo :bar}"}]
           _ (d/transact! conn* blocks)
@@ -39,7 +40,8 @@
           conn (d/conn-from-datoms initial-data schema)]
       (is (= blocks
              (->> @conn
-                  (d/q '[:find (pull ?b [:block/uuid :file/path :file/content]) :where [?b :file/content]])
+                  (d/q '[:find (pull ?b [:file/path :file/content])
+                         :where [?b :file/content] [?b :file/path "logseq/config.edn"]])
                   (map first)))
           "Correct file with content is found"))))
 

+ 2 - 0
deps/graph-parser/.carve/ignore

@@ -5,6 +5,8 @@ logseq.graph-parser.mldoc/block-with-title?
 ;; API
 logseq.graph-parser.mldoc/link?
 ;; API
+logseq.graph-parser.mldoc/->db-edn
+;; API
 logseq.graph-parser.text/get-file-basename
 ;; API
 logseq.graph-parser.mldoc/mldoc-link?

+ 13 - 5
deps/graph-parser/src/logseq/graph_parser/block.cljs

@@ -16,6 +16,7 @@
             [logseq.db.common.order :as db-order]
             [logseq.db.frontend.class :as db-class]
             [logseq.db.frontend.entity-util :as entity-util]
+            [logseq.db.common.entity-plus :as entity-plus]
             [logseq.graph-parser.mldoc :as gp-mldoc]
             [logseq.graph-parser.property :as gp-property]
             [logseq.graph-parser.text :as text]
@@ -305,21 +306,28 @@
 ;; Hack to detect export as some fns are too deeply nested to be refactored to get explicit option
 (def *export-to-db-graph? (atom false))
 
+(defn- get-page
+  "Similar to get-page but only for file graphs"
+  [db page-name]
+  (when (and db (string? page-name))
+    (d/entity db
+              (first (sort (map :e (entity-util/get-pages-by-name db page-name)))))))
+
 (defn- page-name-string->map
   [original-page-name db date-formatter
    {:keys [with-timestamp? page-uuid from-page class? skip-existing-page-check?]}]
-  (let [db-based? (ldb/db-based-graph? db)
+  (let [db-based? (entity-plus/db-based-graph? db)
         original-page-name (common-util/remove-boundary-slashes original-page-name)
         [original-page-name' page-name journal-day] (convert-page-if-journal original-page-name date-formatter {:export-to-db-graph? @*export-to-db-graph?})
         namespace? (and (or (not db-based?) @*export-to-db-graph?)
                         (not (boolean (text/get-nested-page-name original-page-name')))
                         (text/namespace-page? original-page-name'))
         page-entity (when (and db (not skip-existing-page-check?))
-                      (if class?
+                      (if (and class? db-based?)
                         (some->> (ldb/page-exists? db original-page-name' #{:logseq.class/Tag})
                                  first
                                  (d/entity db))
-                        (ldb/get-page db original-page-name')))
+                        (get-page db original-page-name')))
         original-page-name' (or from-page (:block/title page-entity) original-page-name')
         page (merge
               {:block/name page-name
@@ -384,7 +392,7 @@
    & {:keys [page-uuid class?] :as options}]
   (when-not (and db (common-util/uuid-string? original-page-name)
                  (not (page-entity? (d/entity db [:block/uuid (uuid original-page-name)]))))
-    (let [db-based? (ldb/db-based-graph? db)
+    (let [db-based? (entity-plus/db-based-graph? db)
           original-page-name (cond-> (string/trim original-page-name)
                                db-based?
                                sanitize-hashtag-name)
@@ -463,7 +471,7 @@
 (defn- with-page-refs-and-tags
   [{:keys [title body tags refs marker priority] :as block} db date-formatter {:keys [structured-tags]
                                                                                :or {structured-tags #{}}}]
-  (let [db-based? (and (ldb/db-based-graph? db) (not @*export-to-db-graph?))
+  (let [db-based? (and (entity-plus/db-based-graph? db) (not @*export-to-db-graph?))
         refs (->> (concat tags refs (when-not db-based? [marker priority]))
                   (remove string/blank?)
                   (distinct))

+ 12 - 2
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -22,7 +22,6 @@
             [logseq.common.uuid :as common-uuid]
             [logseq.db :as ldb]
             [logseq.db.common.order :as db-order]
-            [logseq.db.common.property-util :as db-property-util]
             [logseq.db.frontend.asset :as db-asset]
             [logseq.db.frontend.class :as db-class]
             [logseq.db.frontend.content :as db-content]
@@ -452,11 +451,22 @@
     (when (and prev-type (not= prev-type prop-type))
       {:type {:from prev-type :to prop-type}})))
 
+(defn- get-file-pid
+  "Gets file graph property id given the db graph ident"
+  [db-ident]
+  ;; Map of unique cases where the db graph keyword name is different than the file graph id
+  (let [unique-file-ids {:logseq.property/order-list-type :logseq.order-list-type
+                         :logseq.property.tldraw/page :logseq.tldraw.page
+                         :logseq.property.tldraw/shape :logseq.tldraw.shape
+                         :logseq.property/publishing-public? :public}]
+    (or (get unique-file-ids db-ident)
+        (keyword (name db-ident)))))
+
 (def built-in-property-file-to-db-idents
   "Map of built-in property file ids to their db graph idents"
   (->> (keys db-property/built-in-properties)
        (map (fn [k]
-              [(db-property-util/get-file-pid k) k]))
+              [(get-file-pid k) k]))
        (into {})))
 
 (def all-built-in-property-file-ids

+ 5 - 0
deps/graph-parser/src/logseq/graph_parser/mldoc.cljc

@@ -169,6 +169,11 @@
   ([repo content format]
    (->edn content (get-default-config repo format))))
 
+(defn ->db-edn
+  "Wrapper around ->edn for DB graphs"
+  [content format]
+  (->edn "logseq_db_repo_stub" content format))
+
 (defn inline->edn
   [text config]
   (try

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

@@ -1,7 +1,5 @@
 (ns logseq.graph-parser.whiteboard
-  "Whiteboard related parser utilities"
-  (:require [logseq.db.common.property-util :as db-property-util]
-            [logseq.db.sqlite.util :as sqlite-util]))
+  "Whiteboard related parser utilities")
 
 (defn block->shape [block]
   (get-in block [:block/properties :logseq.tldraw.shape]))
@@ -73,18 +71,4 @@
               (with-whiteboard-content shape)))
            (when (nil? (:block/parent block)) {:block/parent page-id})
            (when (nil? (:block/format block)) {:block/format :markdown}) ;; TODO: read from config
-           {:block/page page-id})))
-
-(defn shape->block [repo shape page-id]
-  (let [block-uuid (if (uuid? (:id shape)) (:id shape) (uuid (:id shape)))
-        properties {(db-property-util/get-pid repo :logseq.property/ls-type) :whiteboard-shape
-                    (db-property-util/get-pid repo :logseq.property.tldraw/shape) shape}
-        block {:block/uuid block-uuid
-               :block/title ""
-               :block/page page-id
-               :block/parent page-id}
-        block' (if (sqlite-util/db-based-graph? repo)
-                 (merge block properties)
-                 (assoc block :block/properties properties))
-        additional-props (with-whiteboard-block-props block' page-id)]
-    (merge block' additional-props)))
+           {:block/page page-id})))

+ 1 - 2
deps/outliner/src/logseq/outliner/transaction.cljc

@@ -12,8 +12,7 @@
             {:transact-opts {:conn conn} \"Datascript conn\"
              :additional-tx \"Additional tx data that can be bundled together
                               with the body in this macro.\"
-             :persist-op? \"Boolean, store ops into db (sqlite), by default,
-                            its value depends on (config/db-based-graph? repo)\"}
+             :persist-op? \"Boolean, store ops into db (sqlite)\"}
   `Example`:
   (transact! {:conn db-conn}
     (insert-blocks! ...)

+ 2 - 2
deps/outliner/src/logseq/outliner/tree.cljs

@@ -3,7 +3,7 @@
   (:require [datascript.core :as d]
             [datascript.impl.entity :as de]
             [logseq.db :as ldb]
-            [logseq.db.common.property-util :as db-property-util]))
+            [logseq.db.frontend.property :as db-property]))
 
 (defprotocol INode
   (-save [this *txs-state conn opts])
@@ -12,7 +12,7 @@
 (defn- blocks->vec-tree-aux
   [db blocks root]
   (let [root-id (:db/id root)
-        blocks (remove #(db-property-util/shape-block? db %) blocks)
+        blocks (remove #(db-property/shape-block? db %) blocks)
         parent-blocks (group-by #(get-in % [:block/parent :db/id]) blocks) ;; exclude whiteboard shapes
         sort-fn (fn [parent]
                   (when-let [children (get parent-blocks parent)]

+ 4 - 4
src/main/frontend/components/block.cljs

@@ -651,7 +651,7 @@
        on-context-menu
        (assoc :on-context-menu on-context-menu))
      (when (and show-icon? (not tag?))
-       (let [own-icon (get page-entity (pu/get-pid :logseq.property/icon))
+       (let [own-icon (get page-entity :logseq.property/icon)
              emoji? (and (map? own-icon) (= (:type own-icon) :emoji))]
          (when-let [icon (icon-component/get-node-icon-cp page-entity {:color? true
                                                                        :not-text-or-page? true})]
@@ -2994,7 +2994,7 @@
         order-list? (boolean own-number-list?)
         children (ldb/get-children block)
         page-icon (when (:page-title? config)
-                    (let [icon' (get block (pu/get-pid :logseq.property/icon))]
+                    (let [icon' (get block :logseq.property/icon)]
                       (when-let [icon (and (ldb/page? block)
                                            (or icon'
                                                (some :logseq.property/icon (:block/tags block))
@@ -3010,12 +3010,12 @@
                                                                    (if icon
                                                                      (db-property-handler/set-block-property!
                                                                       (:db/id block)
-                                                                      (pu/get-pid :logseq.property/icon)
+                                                                      :logseq.property/icon
                                                                       (select-keys icon [:id :type :color]))
                                                                      ;; del
                                                                      (db-property-handler/remove-block-property!
                                                                       (:db/id block)
-                                                                      (pu/get-pid :logseq.property/icon))))
+                                                                      :logseq.property/icon)))
                                                       :del-btn? (boolean icon')
                                                       :icon-props {:style {:width "1lh"
                                                                            :height "1lh"

+ 4 - 4
src/main/frontend/components/content.cljs

@@ -34,10 +34,10 @@
   []
   [:<>
    (ui/menu-background-color #(property-handler/batch-set-block-property! (state/get-selection-block-ids)
-                                                                          (pu/get-pid :logseq.property/background-color)
+                                                                          :logseq.property/background-color
                                                                           %)
                              #(property-handler/batch-remove-block-property! (state/get-selection-block-ids)
-                                                                             (pu/get-pid :logseq.property/background-color)))
+                                                                             :logseq.property/background-color))
    (ui/menu-heading #(editor-handler/batch-set-heading! (state/get-selection-block-ids) %)
                     #(editor-handler/batch-set-heading! (state/get-selection-block-ids) true)
                     #(editor-handler/batch-remove-heading! (state/get-selection-block-ids)))
@@ -126,10 +126,10 @@
                       false)]
       [:<>
        (ui/menu-background-color #(property-handler/set-block-property! block-id
-                                                                        (pu/get-pid :logseq.property/background-color)
+                                                                        :logseq.property/background-color
                                                                         %)
                                  #(property-handler/remove-block-property! block-id
-                                                                           (pu/get-pid :logseq.property/background-color)))
+                                                                           :logseq.property/background-color))
 
        (ui/menu-heading heading
                         #(editor-handler/set-heading! block-id %)

+ 1 - 2
src/main/frontend/components/icon.cljs

@@ -5,7 +5,6 @@
             [cljs-bean.core :as bean]
             [clojure.string :as string]
             [frontend.config :as config]
-            [frontend.handler.property.util :as pu]
             [frontend.search :as search]
             [frontend.storage :as storage]
             [frontend.ui :as ui]
@@ -54,7 +53,7 @@
   [node-entity {:keys [ignore-current-icon?]
                 :or {ignore-current-icon? false}}]
   (or (when-not ignore-current-icon?
-        (get node-entity (pu/get-pid :logseq.property/icon)))
+        (get node-entity :logseq.property/icon))
       (let [asset-type (:logseq.property.asset/type node-entity)
             first-tag-icon (some :logseq.property/icon (sort-by :db/id (:block/tags node-entity)))]
         (cond

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

@@ -15,7 +15,7 @@
 
 (rum/defc references-aux
   [page-entity config]
-  (let [filters (db-reference/get-filters (db/get-db) page-entity)
+  (let [filters (db-reference/get-filters page-entity)
         reference-filter (fn [{:keys [ref-pages-count]}]
                            (shui/button
                             {:title "Page filter"

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

@@ -65,7 +65,7 @@
   [page-entity references]
   (let [[filter-search set-filter-search!] (hooks/use-state "")
         [filtered-references set-filtered-references!] (hooks/use-state references)
-        filters (db-reference/get-filters (db/get-db) page-entity)
+        filters (db-reference/get-filters page-entity)
         {:keys [included excluded]} filters]
     (hooks/use-effect!
      (fn []

+ 8 - 2
src/main/frontend/db/persist.cljs

@@ -1,20 +1,26 @@
 (ns frontend.db.persist
   "Handles operations to persisting db to disk or indexedDB"
   (:require [cljs-bean.core :as bean]
+            [clojure.string :as string]
             [electron.ipc :as ipc]
             [frontend.config :as config]
             [frontend.db.conn :as db-conn]
             [frontend.persist-db :as persist-db]
             [frontend.util :as util]
-            [logseq.db.common.sqlite :as common-sqlite]
+            [logseq.common.config :as common-config]
             [promesa.core :as p]))
 
+(defn local-file-based-graph?
+  [s]
+  (and (string? s)
+       (string/starts-with? s common-config/file-version-prefix)))
+
 (defn get-all-graphs
   []
   (p/let [repos (persist-db/<list-db)
           repos' (->> repos
                       (remove (fn [{:keys [name]}]
-                                (common-sqlite/local-file-based-graph? name)))
+                                (local-file-based-graph? name)))
                       (map
                        (fn [{:keys [name] :as repo}]
                          (assoc repo :name

+ 1 - 5
src/main/frontend/db/query_react.cljs

@@ -11,7 +11,6 @@
             [frontend.state :as state]
             [lambdaisland.glogi :as log]
             [logseq.common.util.page-ref :as page-ref]
-            [logseq.db :as ldb]
             [logseq.db.frontend.inputs :as db-inputs]))
 
 (defn resolve-input
@@ -23,10 +22,7 @@
                             input
                             (merge {:current-page-fn (fn []
                                                        (or (when-let [name-or-uuid (state/get-current-page)]
-                                                             ;; `ldb/db-based-graph?` left here for testing
-                                                             (if (ldb/db-based-graph? db)
-                                                               (:block/title (model/get-block-by-uuid name-or-uuid))
-                                                               name-or-uuid))
+                                                             (:block/title (model/get-block-by-uuid name-or-uuid)))
                                                            (:page (state/get-default-home))
                                                            (date/today)))}
                                    opts))))

+ 1 - 2
src/main/frontend/extensions/pdf/assets.cljs

@@ -12,7 +12,6 @@
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.property :as property-handler]
-            [frontend.handler.property.util :as pu]
             [frontend.handler.route :as route-handler]
             [frontend.state :as state]
             [frontend.ui :as ui]
@@ -168,7 +167,7 @@
   [highlight]
   (when-let [block (db-model/get-block-by-uuid (:id highlight))]
     (when-let [color (get-in highlight [:properties :color])]
-      (let [k (pu/get-pid :logseq.property.pdf/hl-color)
+      (let [k :logseq.property.pdf/hl-color
             color' (let [colors (:property/closed-values (db/entity :logseq.property.pdf/hl-color))]
                      (some (fn [color-block] (when (= (:block/title color-block) color)
                                                (:db/id color-block))) colors))]

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

@@ -85,12 +85,12 @@
 (defn set-block-own-order-list-type!
   [block type]
   (when-let [uuid (:block/uuid block)]
-    (property-handler/set-block-property! uuid (pu/get-pid :logseq.property/order-list-type) (name type))))
+    (property-handler/set-block-property! uuid :logseq.property/order-list-type (name type))))
 
 (defn remove-block-own-order-list-type!
   [block]
   (when-let [uuid (:block/uuid block)]
-    (property-handler/remove-block-property! uuid (pu/get-pid :logseq.property/order-list-type))))
+    (property-handler/remove-block-property! uuid :logseq.property/order-list-type)))
 
 (defn own-order-number-list?
   [block]
@@ -106,7 +106,7 @@
   (when (seq blocks)
     (let [has-ordered?    (some own-order-number-list? blocks)
           blocks-uuids    (some->> blocks (map :block/uuid) (remove nil?))
-          order-list-prop (pu/get-pid :logseq.property/order-list-type)]
+          order-list-prop :logseq.property/order-list-type]
       (if has-ordered?
         (property-handler/batch-remove-block-property! blocks-uuids order-list-prop)
         (property-handler/batch-set-block-property! blocks-uuids order-list-prop "number")))))

+ 3 - 5
src/main/frontend/handler/export/common.cljs

@@ -15,8 +15,7 @@
 (defn root-block-uuids->content
   "Converts given block uuids to content for given repo"
   [repo root-block-uuids]
-  (binding [cli-export-common/*current-repo* repo
-            cli-export-common/*current-db* (conn/get-db repo)
+  (binding [cli-export-common/*current-db* (conn/get-db repo)
             cli-export-common/*content-config* (get-content-config)]
     (let [contents (mapv (fn [id]
                            (cli-export-common/get-blocks-contents id)) root-block-uuids)]
@@ -25,8 +24,7 @@
 (defn get-page-content
   "Gets page content for current repo, db and state"
   [page-uuid]
-  (binding [cli-export-common/*current-repo* (state/get-current-repo)
-            cli-export-common/*current-db* (conn/get-db (state/get-current-repo))
+  (binding [cli-export-common/*current-db* (conn/get-db (state/get-current-repo))
             cli-export-common/*content-config* (get-content-config)]
     (cli-export-common/get-page-content page-uuid)))
 
@@ -49,7 +47,7 @@
                          :format :markdown})
                       page->content)))
 
-;; Aliased fns requiring cli-export-common dynamic bindings e.g. cli-export-common/*current-repo*
+;; Aliased fns requiring cli-export-common dynamic bindings e.g. cli-export-common/*current-db*
 (def replace-block&page-reference&embed cli-export-common/replace-block&page-reference&embed)
 (def replace-Heading-with-Paragraph cli-export-common/replace-Heading-with-Paragraph)
 

+ 1 - 2
src/main/frontend/handler/export/html.cljs

@@ -429,8 +429,7 @@
         first-block (and (coll? root-block-uuids-or-page-uuid)
                          (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)]))
         format (get first-block :block/format :markdown)]
-    (binding [cli-export-common/*current-repo* repo
-              cli-export-common/*current-db* (conn/get-db repo)
+    (binding [cli-export-common/*current-db* (conn/get-db repo)
               cli-export-common/*content-config* (common/get-content-config)]
       (export-helper content format options))))
 

+ 1 - 2
src/main/frontend/handler/export/opml.cljs

@@ -445,8 +445,7 @@
           first-block (and (coll? root-block-uuids-or-page-uuid)
                            (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)]))
           format (get first-block :block/format :markdown)]
-      (binding [cli-export-common/*current-repo* repo
-                cli-export-common/*current-db* (conn/get-db repo)
+      (binding [cli-export-common/*current-db* (conn/get-db repo)
                 cli-export-common/*content-config* (common/get-content-config)]
         (export-helper content format options :title title)))))
 

+ 2 - 4
src/main/frontend/handler/export/text.cljs

@@ -42,9 +42,8 @@
                              (db/entity [:block/uuid (first root-block-uuids-or-page-uuid)]))
             format (get first-block :block/format :markdown)]
         (binding [cli-export-common/*current-db* (conn/get-db repo)
-                  cli-export-common/*current-repo* repo
                   cli-export-common/*content-config* (common/get-content-config)]
-          (cli-export-text/export-helper repo content format options)))
+          (cli-export-text/export-helper content format options)))
       (catch :default e
         (js/console.error e)))))
 
@@ -59,9 +58,8 @@
        (util/profile (print-str :export-files-as-markdown title)
          [(or path title)
           (binding [cli-export-common/*current-db* db
-                    cli-export-common/*current-repo* repo
                     cli-export-common/*content-config* content-config]
-            (cli-export-text/export-helper repo content :markdown options))]))
+            (cli-export-text/export-helper content :markdown options))]))
      files)))
 
 (defn export-repo-as-markdown!

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

@@ -4,26 +4,20 @@
   compatible with file graphs"
   (:require [frontend.db.conn :as conn]
             [frontend.state :as state]
-            [logseq.db.common.property-util :as db-property-util]))
+            [logseq.db.frontend.property :as db-property]))
 
 (def lookup
   "Get the property value by a built-in property's db-ident from block."
-  db-property-util/lookup)
+  db-property/lookup)
 
 (defn get-block-property-value
   "Get the value of a built-in block's property by its db-ident"
   [block db-ident]
   (let [db (conn/get-db (state/get-current-repo))]
-    (db-property-util/get-block-property-value db block db-ident)))
-
-(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-property-util/get-pid repo db-ident)))
+    (db-property/get-block-property-value db block db-ident)))
 
 (defn shape-block?
   [block]
   (let [repo (state/get-current-repo)
         db (conn/get-db repo)]
-    (db-property-util/shape-block? db block)))
+    (db-property/shape-block? db block)))

+ 1 - 1
src/main/frontend/worker/db_worker.cljs

@@ -659,7 +659,7 @@
 (def-thread-api :thread-api/export-get-all-page->content
   [repo options]
   (when-let [conn (worker-state/get-datascript-conn repo)]
-    (worker-export/get-all-page->content repo @conn options)))
+    (worker-export/get-all-page->content @conn options)))
 
 (def-thread-api :thread-api/validate-db
   [repo]