fix: remove remaining uses of file graph specific attributes

Removed all file graph uses of :block/namespace, :block/file, :block/type and
:block/properties except for graph-parser which still uses them for db
importer.
Removed all uses of :block/format except for graph-parser and
src/main/frontend
This commit is contained in:
Gabriel Horner
2026-01-12 12:20:51 -05:00
parent 4bb7430682
commit 37af8f690e
23 changed files with 90 additions and 207 deletions

View File

@@ -61,14 +61,14 @@
;;; internal utils ;;; internal utils
(defn ^:api get-blocks-contents (defn ^:api get-blocks-contents
[repo root-block-uuid & {:keys [init-level] [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]) (let [block (d/entity *current-db* [:block/uuid root-block-uuid])
link (:block/link block) link (:block/link block)
block' (or link block) block' (or link block)
root-id (:block/uuid block') root-id (:block/uuid block')
blocks (ldb/get-block-and-children *current-db* root-id) blocks (ldb/get-block-and-children *current-db* root-id)
tree (otree/blocks->vec-tree repo *current-db* blocks root-id {:link link})] 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-repo* *current-db* tree
{:init-level init-level :link link} {:init-level init-level :link link}
*content-config*))) *content-config*)))
@@ -87,7 +87,7 @@
(defn- block-uuid->ast-with-children (defn- block-uuid->ast-with-children
[block-uuid] [block-uuid]
(let [content (get-blocks-contents *current-repo* block-uuid) (let [content (get-blocks-contents block-uuid)
format :markdown] format :markdown]
(when content (when content
(removev Properties-block-ast? (removev Properties-block-ast?

View File

@@ -89,7 +89,7 @@
1)) 1))
blocks (->> (d/pull-many db '[*] (keep :db/id (ldb/get-block-and-children db root-block-uuid))) 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 #(update-block-content db % (:db/id %))))
tree (otree/blocks->vec-tree repo db blocks (str root-block-uuid))] tree (otree/blocks->vec-tree db blocks (str root-block-uuid))]
(tree->file-content repo db tree (tree->file-content repo db tree
(assoc tree->file-opts :init-level init-level) (assoc tree->file-opts :init-level init-level)
context))) context)))

View File

@@ -74,8 +74,7 @@
block-eids (mapv :e datoms) block-eids (mapv :e datoms)
block-ents (map #(d/entity db %) block-eids) block-ents (map #(d/entity db %) block-eids)
blocks (map #(assoc % :block/title (db-content/recur-replace-uuid-in-block-title %)) block-ents)] blocks (map #(assoc % :block/title (db-content/recur-replace-uuid-in-block-title %)) block-ents)]
;; Use repo stub since this is a DB only tool (->> (otree/blocks->vec-tree db blocks page-id)
(->> (otree/blocks->vec-tree "logseq_db_repo_stub" db blocks page-id)
(map #(update % :block/uuid str))))) (map #(update % :block/uuid str)))))
(defn ^:api remove-hidden-properties (defn ^:api remove-hidden-properties

1
deps/db/README.md vendored
View File

@@ -15,7 +15,6 @@ This library is under the parent namespace `logseq.db`. It provides the followin
* `logseq.db` - main entry point serving both file and DB graphs * `logseq.db` - main entry point serving both file and DB graphs
* `logseq.db.frontend.*` - frontend namespaces for DB graphs * `logseq.db.frontend.*` - frontend namespaces for DB graphs
* `logseq.db.sqlite.*` - backend/sqlite namespaces for DB graphs * `logseq.db.sqlite.*` - backend/sqlite namespaces for DB graphs
* `logseq.db.file-based.*` - namespaces for file graphs, mostly old namespaces
* `logseq.db.common.*` - namespaces for both file and DB graphs * `logseq.db.common.*` - namespaces for both file and DB graphs
## Usage ## Usage

View File

@@ -39,9 +39,7 @@
results (if (:entity options) results (if (:entity options)
(map #(when-let [ent (d/entity @conn (map #(when-let [ent (d/entity @conn
(if (string? %) (edn/read-string %) %))] (if (string? %) (edn/read-string %) %))]
(cond-> (into {:db/id (:db/id ent)} ent) (into {:db/id (:db/id ent)} ent))
(seq (:block/properties ent))
(update :block/properties (fn [props] (map (fn [m] (into {} m)) props)))))
(:entity options)) (:entity options))
;; assumes no :in are in queries ;; assumes no :in are in queries
(let [query (into (edn/read-string (first args'')) [:in '$ '%]) (let [query (into (edn/read-string (first args'')) [:in '$ '%])

View File

@@ -421,7 +421,6 @@
(contains? #{"" "-" "*"} (string/trim (:block/title first-child)))))) (contains? #{"" "-" "*"} (string/trim (:block/title first-child))))))
(not (contains? built-in-pages name')) (not (contains? built-in-pages name'))
(not (whiteboard? page)) (not (whiteboard? page))
(not (:block/_namespace page))
(not (property? page)) (not (property? page))
;; a/b/c might be deleted but a/b/c/d still exists (for backward compatibility) ;; a/b/c might be deleted but a/b/c/d still exists (for backward compatibility)
(not (and (string/includes? name' "/") (not (and (string/includes? name' "/")
@@ -620,30 +619,18 @@
(defn get-pages-relation (defn get-pages-relation
[db with-journal?] [db with-journal?]
(if (entity-plus/db-based-graph? db) (let [q (if with-journal?
(let [q (if with-journal? '[:find ?p ?ref-page
'[:find ?p ?ref-page :where
:where [?block :block/page ?p]
[?block :block/page ?p] [?block :block/refs ?ref-page]]
[?block :block/refs ?ref-page]] '[:find ?p ?ref-page
'[:find ?p ?ref-page :where
:where [?block :block/page ?p]
[?block :block/page ?p] [?p :block/tags]
[?p :block/tags] (not [?p :block/tags :logseq.class/Journal])
(not [?p :block/tags :logseq.class/Journal]) [?block :block/refs ?ref-page]])]
[?block :block/refs ?ref-page]])] (d/q q db)))
(d/q q db))
(let [q (if with-journal?
'[:find ?p ?ref-page
:where
[?block :block/page ?p]
[?block :block/refs ?ref-page]]
'[:find ?p ?ref-page
:where
[?block :block/page ?p]
(not [?p :block/type "journal"])
[?block :block/refs ?ref-page]])]
(d/q q db))))
(defn get-all-tagged-pages (defn get-all-tagged-pages
[db] [db]

View File

@@ -25,20 +25,18 @@
(get-file-pid db-ident))) (get-file-pid db-ident)))
(defn lookup (defn lookup
"Get the property value by a built-in property's db-ident from coll. For file and db graphs" "Get the property value by a built-in property's db-ident from coll"
[repo block db-ident] [block db-ident]
(if (sqlite-util/db-based-graph? repo) (let [val (get 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)))
(if (db-property/built-in-has-ref-value? db-ident) (db-property/property-value-content val) val))
(get (:block/properties block) (get-pid repo db-ident))))
(defn get-block-property-value (defn get-block-property-value
"Get the value of built-in block's property by its db-ident" "Get the value of built-in block's property by its db-ident"
[repo db block db-ident] [db block db-ident]
(when db (when db
(let [block (or (d/entity db (:db/id block)) block)] (let [block (or (d/entity db (:db/id block)) block)]
(lookup repo block db-ident)))) (lookup block db-ident))))
(defn shape-block? (defn shape-block?
[repo db block] [db block]
(= :whiteboard-shape (get-block-property-value repo db block :logseq.property/ls-type))) (= :whiteboard-shape (get-block-property-value db block :logseq.property/ls-type)))

View File

@@ -111,8 +111,7 @@
:logseq.class/Asset}) :logseq.class/Asset})
(def private-tags (def private-tags
"Built-in classes that are private and should not be used by a user directly. "Built-in classes that are private and should not be used by a user directly."
These used to be in block/type"
(set/union (disj internal-tags :logseq.class/Root) (set/union (disj internal-tags :logseq.class/Root)
#{:logseq.class/Journal :logseq.class/Whiteboard #{:logseq.class/Journal :logseq.class/Whiteboard
:logseq.class/Pdf-annotation})) :logseq.class/Pdf-annotation}))

View File

@@ -243,8 +243,7 @@
(let [data (if (de/entity? this) (let [data (if (de/entity? this)
(assoc (.-kv ^js this) :db/id (:db/id this)) (assoc (.-kv ^js this) :db/id (:db/id this))
this) this)
data' (->> (dissoc data :block/properties) data' (remove-disallowed-inline-classes db data)
(remove-disallowed-inline-classes db))
collapse-or-expand? (= outliner-op :collapse-expand-blocks) collapse-or-expand? (= outliner-op :collapse-expand-blocks)
m* (cond-> m* (cond->
(-> data' (-> data'
@@ -268,19 +267,16 @@
(not= block-title (:block/title block-entity))) (not= block-title (:block/title block-entity)))
_ (when (and page? block-title) _ (when (and page? block-title)
(outliner-validate/validate-page-title-characters block-title {:node m*})) (outliner-validate/validate-page-title-characters block-title {:node m*}))
m* (if page-title-changed? m (if page-title-changed?
(let [_ (outliner-validate/validate-page-title (:block/title m*) {:node m*}) (let [_ (outliner-validate/validate-page-title (:block/title m*) {:node m*})
page-name (common-util/page-name-sanity-lc (:block/title m*))] page-name (common-util/page-name-sanity-lc (:block/title m*))]
(assoc m* :block/name page-name)) (assoc m* :block/name page-name))
m*) m*)
_ (when (and ;; page or object changed? _ (when (and ;; page or object changed?
(or (ldb/page? block-entity) (ldb/object? block-entity)) (or (ldb/page? block-entity) (ldb/object? block-entity))
(:block/title m*) (:block/title m)
(not= (:block/title m*) (:block/title block-entity))) (not= (:block/title m) (:block/title block-entity)))
(outliner-validate/validate-block-title db (:block/title m*) block-entity)) (outliner-validate/validate-block-title db (:block/title m) block-entity))]
m (cond-> m*
true
(dissoc :block/format))]
;; Ensure block UUID never changes ;; Ensure block UUID never changes
(let [e (d/entity db db-id)] (let [e (d/entity db db-id)]
(when (and e block-uuid) (when (and e block-uuid)
@@ -747,9 +743,7 @@
update-timestamps? update-timestamps?
(mapv #(dissoc % :block/created-at :block/updated-at)) (mapv #(dissoc % :block/created-at :block/updated-at))
true true
(mapv block-with-timestamps) (mapv block-with-timestamps)))
true
(mapv #(-> % (dissoc :block/properties)))))
insert-opts {:sibling? sibling? insert-opts {:sibling? sibling?
:replace-empty-target? replace-empty-target? :replace-empty-target? replace-empty-target?
:keep-uuid? keep-uuid? :keep-uuid? keep-uuid?

View File

@@ -699,7 +699,7 @@
(let [block (d/entity db eid)] (let [block (d/entity db eid)]
(->> (->>
(concat (concat
(map (fn [ident] (d/entity db ident)) (keys (:block/properties block))) (map (fn [ident] (d/entity db ident)) (keys (entity-plus/lookup-kv-then-entity block :block/properties)))
(:classes-properties (get-block-classes-properties db eid))) (:classes-properties (get-block-classes-properties db eid)))
(common-util/distinct-by :db/id)))) (common-util/distinct-by :db/id))))

View File

@@ -10,9 +10,9 @@
(-del [this *txs-state db])) (-del [this *txs-state db]))
(defn- blocks->vec-tree-aux (defn- blocks->vec-tree-aux
[repo db blocks root] [db blocks root]
(let [root-id (:db/id root) (let [root-id (:db/id root)
blocks (remove #(db-property-util/shape-block? repo db %) blocks) blocks (remove #(db-property-util/shape-block? db %) blocks)
parent-blocks (group-by #(get-in % [:block/parent :db/id]) blocks) ;; exclude whiteboard shapes parent-blocks (group-by #(get-in % [:block/parent :db/id]) blocks) ;; exclude whiteboard shapes
sort-fn (fn [parent] sort-fn (fn [parent]
(when-let [children (get parent-blocks parent)] (when-let [children (get parent-blocks parent)]
@@ -53,14 +53,14 @@
;; TODO: entity can already be used as a tree ;; TODO: entity can already be used as a tree
(defn blocks->vec-tree (defn blocks->vec-tree
"`blocks` need to be in the same page." "`blocks` need to be in the same page."
[repo db blocks root-id & {:as option}] [db blocks root-id & {:as option}]
(let [blocks (map (fn [b] (if (de/entity? b) (let [blocks (map (fn [b] (if (de/entity? b)
(assoc (into {} b) :db/id (:db/id b)) (assoc (into {} b) :db/id (:db/id b))
b)) blocks) b)) blocks)
[page? root] (get-root-and-page db root-id)] [page? root] (get-root-and-page db root-id)]
(if-not root ; custom query (if-not root ; custom query
blocks blocks
(let [result (blocks->vec-tree-aux repo db blocks root)] (let [result (blocks->vec-tree-aux db blocks root)]
(if (and page? (not (:link option))) (if (and page? (not (:link option)))
result result
;; include root block ;; include root block

View File

@@ -2,6 +2,7 @@
"Provides db fns and associated util fns for publishing" "Provides db fns and associated util fns for publishing"
(:require [clojure.set :as set] (:require [clojure.set :as set]
[datascript.core :as d] [datascript.core :as d]
[logseq.db.common.entity-plus :as entity-plus]
[logseq.db.frontend.malli-schema :as db-malli-schema] [logseq.db.frontend.malli-schema :as db-malli-schema]
[logseq.db.frontend.rules :as rules])) [logseq.db.frontend.rules :as rules]))
@@ -25,7 +26,7 @@
(when (seq tag-pages*) (when (seq tag-pages*)
(some-> (d/entity db :block/tags) :db/id vector))) (some-> (d/entity db :block/tags) :db/id vector)))
property-pages (mapcat (fn [ent] property-pages (mapcat (fn [ent]
(->> (keys (:block/properties ent)) (->> (keys (entity-plus/lookup-kv-then-entity ent :block/properties))
(map #(:db/id (d/entity db %))))) (map #(:db/id (d/entity db %)))))
page-ents)] page-ents)]
(concat pages tag-pages property-pages))) (concat pages tag-pages property-pages)))

View File

@@ -342,7 +342,7 @@ These tasks are specific to database graphs. For these tasks there is a one time
```sh ```sh
$ bb dev:db-query woot '[:find (pull ?b [*]) :where (block-content ?b "Dogma")]' $ bb dev:db-query woot '[:find (pull ?b [*]) :where (block-content ?b "Dogma")]'
DB contains 833 datoms DB contains 833 datoms
[{:block/tx-id 536870923, :block/link #:db{:id 100065}, :block/uuid #uuid "65565c26-f972-4400-bce4-a15df488784d", :block/updated-at 1700158508564, :block/order "a0", :block/refs [#:db{:id 100064}], :block/created-at 1700158502056, :block/format :markdown, :block/tags [#:db{:id 100064}], :block/title "Dogma #[[65565c2a-b1c5-4dc8-a0f0-81b786bc5c6d]]", :db/id 100090, :block/parent #:db{:id 100051}, :block/page #:db{:id 100051}}] [{:block/tx-id 536870923, :block/link #:db{:id 100065}, :block/uuid #uuid "65565c26-f972-4400-bce4-a15df488784d", :block/updated-at 1700158508564, :block/order "a0", :block/refs [#:db{:id 100064}], :block/created-at 1700158502056, :block/tags [#:db{:id 100064}], :block/title "Dogma #[[65565c2a-b1c5-4dc8-a0f0-81b786bc5c6d]]", :db/id 100090, :block/parent #:db{:id 100051}, :block/page #:db{:id 100051}}]
``` ```
* `dev:db-transact` - Run a `d/transact!` against the queried results of a DB graph * `dev:db-transact` - Run a `d/transact!` against the queried results of a DB graph
@@ -353,17 +353,19 @@ These tasks are specific to database graphs. For these tasks there is a one time
Usage: $0 GRAPH-DIR QUERY TRANSACT-FN Usage: $0 GRAPH-DIR QUERY TRANSACT-FN
# First use the -n flag to see a dry-run of what would happen # First use the -n flag to see a dry-run of what would happen
$ bb dev:db-transact test-db '[:find ?b :where [?b :block/type "object"]]' '(fn [id] (vector :db/retract id :block/type "object"))' -n $ bb dev:db-transact test-db '[:find ?b :where [?b :block/title "say wut"]]' '(fn [id] (vector :db/add id :block/title "say woot!"))' -n
Would update 16 blocks with the following tx: Would update 1 blocks with the following tx:
[[:db/retract 100137 :block/type "object"] [:db/retract 100035 :block/type "object"] [:db/retract 100128 :block/type "object"] [:db/retract 100049 :block/type "object"] [:db/retract 100028 :block/type "object"] [:db/retract 100146 :block/type "object"] [:db/retract 100144 :block/type "object"] [:db/retract 100047 :block/type "object"] [:db/retract 100145 :block/type "object"] [:db/retract 100046 :block/type "object"] [:db/retract 100045 :block/type "object"] [:db/retract 100063 :block/type "object"] [:db/retract 100036 :block/type "object"] [:db/retract 100044 :block/type "object"] [:db/retract 100129 :block/type "object"] [:db/retract 100030 :block/type "object"]] [[:db/add 169 :block/title "say woot!"]]
With the following blocks updated: With the following blocks updated:
... (#:block{:title "say wut"})
# When the transact looks good, run it without the flag # When the transact looks good, run it without the flag
$ bb dev:db-transact test-db '[:find ?b :where [?b :block/type "object"]]' '(fn [id] (vector :db/retract id :block/type "object"))' $ bb dev:db-transact test-db '[:find ?b :where [?b :block/title "say wut"]]' '(fn [id] (vector :db/add id :block/title "say woot!"))'
Updated 16 block(s) for graph test-db! Updated 1 block(s) for graph test-db!
``` ```
Run the dev command `Replace graph with its db.sqlite file` to use the updated graph in the desktop app.
* `dev:db-create` - Create a DB graph given a `sqlite.build` EDN file * `dev:db-create` - Create a DB graph given a `sqlite.build` EDN file
First in Electron, create the name of the graph you want create e.g. `inferred`. First in Electron, create the name of the graph you want create e.g. `inferred`.
@@ -410,15 +412,8 @@ These tasks are specific to database graphs. For these tasks there is a one time
[[] [[]
[[162 :block/title "b7" 536871039 true] [[162 :block/title "b7" 536871039 true]
[162 :block/created-at 1703004379103 536871037 true] [162 :block/created-at 1703004379103 536871037 true]
[162 :block/format :markdown 536871037 true]
[162 :block/page 149 536871037 true] [162 :block/page 149 536871037 true]
[162 :block/parent 149 536871037 true] [162 :block/parent 149 536871037 true]
[162
:block/properties
{#uuid "21be4275-bba9-48b8-9351-c9ca27883159"
#uuid "6581b09e-8b9c-4dca-a938-c900aedc8275"}
536871043
true]
[162 :block/refs 108 536871043 true] [162 :block/refs 108 536871043 true]
[162 :block/refs 160 536871043 true] [162 :block/refs 160 536871043 true]
[162 [162
@@ -444,16 +439,9 @@ These tasks are specific to database graphs. For these tasks there is a one time
[nil nil 536871037 536871038] [nil nil 536871037 536871038]
[162 :block/title "b7" 536871039 true] [162 :block/title "b7" 536871039 true]
[162 :block/created-at 1703004379103 536871037 true] [162 :block/created-at 1703004379103 536871037 true]
[162 :block/format :markdown 536871037 true]
[162 :block/order "a0" 536871037 true] [162 :block/order "a0" 536871037 true]
[162 :block/page 149 536871037 true] [162 :block/page 149 536871037 true]
[162 :block/parent 149 536871037 true] [162 :block/parent 149 536871037 true]
[162
:block/properties
{#uuid "21be4275-bba9-48b8-9351-c9ca27883159"
#uuid "6581b09e-8b9c-4dca-a938-c900aedc8275"}
536871043
true]
[162 :block/refs 108 536871043 true] [162 :block/refs 108 536871043 true]
[162 :block/refs 160 536871043 true] [162 :block/refs 160 536871043 true]
[162 :block/tx-id 536871043 536871044 true] [162 :block/tx-id 536871043 536871044 true]

View File

@@ -5,7 +5,6 @@
(defkeywords (defkeywords
:block/uuid {:doc "block's uuid"} :block/uuid {:doc "block's uuid"}
:block/name {:doc "block name, lowercase, only page-blocks have this attr"} :block/name {:doc "block name, lowercase, only page-blocks have this attr"}
:block/type {:doc "block type, *deprecated* in db-version"}
:block/raw-title {:doc "like `:block/title`, :block/raw-title {:doc "like `:block/title`,
but when eval `(:block/raw-title block-entity)`, return raw title of this block"} but when eval `(:block/raw-title block-entity)`, return raw title of this block"}
:kv/value {:doc "Used to store key-value, the value could be anything, :kv/value {:doc "Used to store key-value, the value could be anything,

View File

@@ -1930,8 +1930,7 @@
(or (pu/lookup block :logseq.property.pdf/hl-page) (or (pu/lookup block :logseq.property.pdf/hl-page)
"?"))]] "?"))]]
(when (and area? (or (get-in block [:block/properties :hl-stamp]) (when (and area? (:logseq.property.pdf/hl-image block))
(:logseq.property.pdf/hl-image block)))
(pdf-assets/area-display block))])] (pdf-assets/area-display block))])]
(remove-nils (remove-nils
(concat (concat

View File

@@ -4,7 +4,6 @@
[clojure.walk :as walk] [clojure.walk :as walk]
[datascript.core :as d] [datascript.core :as d]
[frontend.common.graph-view :as graph-view] [frontend.common.graph-view :as graph-view]
[frontend.config :as config]
[frontend.db.conn :as conn] [frontend.db.conn :as conn]
[frontend.db.react :as react] [frontend.db.react :as react]
[frontend.db.utils :as db-utils] [frontend.db.utils :as db-utils]
@@ -80,44 +79,26 @@ independent of format as format specific heading characters are stripped"
name must match the content of a page's block header" name must match the content of a page's block header"
[repo page-uuid-str route-name] [repo page-uuid-str route-name]
(let [db (conn/get-db repo)] (let [db (conn/get-db repo)]
(if (config/db-based-graph? repo) (->> (d/q '[:find (pull ?b [:block/uuid])
(->> (d/q '[:find (pull ?b [:block/uuid]) :in $ ?page-uuid ?route-name ?content-matches %
:in $ ?page-uuid ?route-name ?content-matches % :where
:where [?page :block/uuid ?page-uuid]
[?page :block/uuid ?page-uuid] [?b :block/page ?page]
[?b :block/page ?page] (has-property ?b :logseq.property/heading)
(has-property ?b :logseq.property/heading) [?b :block/title ?content]
[?b :block/title ?content] [(?content-matches ?content ?route-name ?b)]]
[(?content-matches ?content ?route-name ?b)]] db
db (uuid page-uuid-str)
(uuid page-uuid-str) route-name
route-name (fn content-matches? [block-content external-content block-id]
(fn content-matches? [block-content external-content block-id] (let [block (db-utils/entity repo block-id)
(let [block (db-utils/entity repo block-id) ref-tags (distinct (concat (:block/tags block) (:block/refs block)))]
ref-tags (distinct (concat (:block/tags block) (:block/refs block)))] (= (-> (db-content/id-ref->title-ref block-content ref-tags)
(= (-> (db-content/id-ref->title-ref block-content ref-tags) (db-content/content-id-ref->page ref-tags)
(db-content/content-id-ref->page ref-tags) heading-content->route-name)
heading-content->route-name)
(string/lower-case external-content))))
(rules/extract-rules rules/db-query-dsl-rules [:has-property]))
ffirst)
(->> (d/q '[:find (pull ?b [:block/uuid])
:in $ ?page-uuid ?route-name ?content-matches
:where
[?page :block/uuid ?page-uuid]
[?b :block/page ?page]
[?b :block/properties ?prop]
[(get ?prop :heading) _]
[?b :block/title ?content]
[(?content-matches ?content ?route-name)]]
db
(uuid page-uuid-str)
route-name
(fn content-matches? [block-content external-content]
(= (heading-content->route-name block-content)
(string/lower-case external-content)))) (string/lower-case external-content))))
ffirst)))) (rules/extract-rules rules/db-query-dsl-rules [:has-property]))
ffirst)))
(defn get-page-format (defn get-page-format
[_page-name] [_page-name]

View File

@@ -1,5 +1,7 @@
(ns frontend.format.block (ns frontend.format.block
"Block code needed by app but not graph-parser" "Block code needed by app but not graph-parser. This should be the only frontend
namespace that has references to legacy file attributes like :block/pre-block?
as they are being removed from graph-parser output"
(:require [cljs-time.format :as tf] (:require [cljs-time.format :as tf]
[cljs.cache :as cache] [cljs.cache :as cache]
[clojure.string :as string] [clojure.string :as string]

View File

@@ -19,7 +19,7 @@
cli-export-common/*current-db* (conn/get-db repo) cli-export-common/*current-db* (conn/get-db repo)
cli-export-common/*content-config* (get-content-config)] cli-export-common/*content-config* (get-content-config)]
(let [contents (mapv (fn [id] (let [contents (mapv (fn [id]
(cli-export-common/get-blocks-contents repo id)) root-block-uuids)] (cli-export-common/get-blocks-contents id)) root-block-uuids)]
(string/join "\n" (mapv string/trim-newline contents))))) (string/join "\n" (mapv string/trim-newline contents)))))
(defn get-page-content (defn get-page-content
@@ -30,12 +30,6 @@
cli-export-common/*content-config* (get-content-config)] cli-export-common/*content-config* (get-content-config)]
(cli-export-common/get-page-content page-uuid))) (cli-export-common/get-page-content page-uuid)))
;; Utils
(comment
(defn <get-all-pages
[repo]
(state/<invoke-db-worker :thread-api/export-get-all-pages repo)))
(defn <get-debug-datoms (defn <get-debug-datoms
[repo] [repo]
(state/<invoke-db-worker :thread-api/export-get-debug-datoms repo)) (state/<invoke-db-worker :thread-api/export-get-debug-datoms repo))

View File

@@ -6,18 +6,15 @@
[frontend.state :as state] [frontend.state :as state]
[logseq.db.common.property-util :as db-property-util])) [logseq.db.common.property-util :as db-property-util]))
(defn lookup (def lookup
"Get the property value by a built-in property's db-ident from block. For file and db graphs" "Get the property value by a built-in property's db-ident from block."
[block key] db-property-util/lookup)
(let [repo (state/get-current-repo)]
(db-property-util/lookup repo block key)))
(defn get-block-property-value (defn get-block-property-value
"Get the value of a built-in block's property by its db-ident" "Get the value of a built-in block's property by its db-ident"
[block db-ident] [block db-ident]
(let [repo (state/get-current-repo) (let [db (conn/get-db (state/get-current-repo))]
db (conn/get-db repo)] (db-property-util/get-block-property-value db block db-ident)))
(db-property-util/get-block-property-value repo db block db-ident)))
(defn get-pid (defn get-pid
"Get a built-in property's id (db-ident or name) given its db-ident. For file and db graphs" "Get a built-in property's id (db-ident or name) given its db-ident. For file and db graphs"
@@ -29,4 +26,4 @@
[block] [block]
(let [repo (state/get-current-repo) (let [repo (state/get-current-repo)
db (conn/get-db repo)] db (conn/get-db repo)]
(db-property-util/shape-block? repo db block))) (db-property-util/shape-block? db block)))

View File

@@ -9,7 +9,7 @@
(blocks->vec-tree (state/get-current-repo) blocks root-id)) (blocks->vec-tree (state/get-current-repo) blocks root-id))
([repo blocks root-id & {:as option}] ([repo blocks root-id & {:as option}]
(let [db (db/get-db repo)] (let [db (db/get-db repo)]
(otree/blocks->vec-tree repo db blocks root-id option)))) (otree/blocks->vec-tree db blocks root-id option))))
(def filter-top-level-blocks otree/filter-top-level-blocks) (def filter-top-level-blocks otree/filter-top-level-blocks)

View File

@@ -656,11 +656,6 @@
(when-let [conn (worker-state/get-datascript-conn repo)] (when-let [conn (worker-state/get-datascript-conn repo)]
(worker-export/get-debug-datoms conn))) (worker-export/get-debug-datoms conn)))
(def-thread-api :thread-api/export-get-all-pages
[repo]
(when-let [conn (worker-state/get-datascript-conn repo)]
(worker-export/get-all-pages repo @conn)))
(def-thread-api :thread-api/export-get-all-page->content (def-thread-api :thread-api/export-get-all-page->content
[repo options] [repo options]
(when-let [conn (worker-state/get-datascript-conn repo)] (when-let [conn (worker-state/get-datascript-conn repo)]

View File

@@ -3,45 +3,7 @@
(:require [datascript.core :as d] (:require [datascript.core :as d]
[logseq.cli.common.file :as common-file] [logseq.cli.common.file :as common-file]
[logseq.common.util :as common-util] [logseq.common.util :as common-util]
[logseq.db :as ldb] [logseq.db :as ldb]))
[logseq.graph-parser.property :as gp-property]
[logseq.outliner.tree :as otree]))
(defn- safe-keywordize
[block]
(update block :block/properties
(fn [properties]
(when (seq properties)
(->> (filter (fn [[k _v]]
(gp-property/valid-property-name? (str k))) properties)
(into {}))))))
(defn get-all-pages
"Get all pages and their children blocks."
[repo db]
(->> (d/q '[:find (pull ?b [*])
:in $
:where
[?b :block/title]
[?b :block/name]] db)
(map (fn [[page]]
(let [whiteboard? (ldb/whiteboard? page)
blocks (ldb/get-page-blocks db (:db/id page))
blocks' (if whiteboard?
blocks
(map (fn [b]
(let [b' (if (seq (:block/properties b))
(update b :block/title
(fn [content]
(gp-property/remove-properties (get b :block/format :markdown) content)))
b)]
(safe-keywordize b'))) blocks))
children (if whiteboard?
blocks'
(otree/blocks->vec-tree repo db blocks' (:db/id page)))
page' (safe-keywordize page)]
(assoc page' :block/children children))))))
(def get-all-page->content common-file/get-all-page->content) (def get-all-page->content common-file/get-all-page->content)

View File

@@ -15,7 +15,6 @@
:block/updated-at 1720017595873, :block/updated-at 1720017595873,
:block/created-at 1720017595872, :block/created-at 1720017595872,
:db/ident :user.class/yyy, :db/ident :user.class/yyy,
:block/type "class",
:block/name "yyy", :block/name "yyy",
:block/title "yyy"}])] :block/title "yyy"}])]
(is (= {:move (is (= {:move
@@ -27,8 +26,7 @@
:pos [nil nil], :pos [nil nil],
:av-coll :av-coll
[[:block/name "[\"~#'\",\"yyy\"]" 1 true] [[:block/name "[\"~#'\",\"yyy\"]" 1 true]
[:block/title "[\"~#'\",\"yyy\"]" 1 true] [:block/title "[\"~#'\",\"yyy\"]" 1 true]]}}
[:block/type "[\"~#'\",\"class\"]" 1 true]]}}
(:remote-ops (:remote-ops
(#'subject/local-block-ops->remote-ops (#'subject/local-block-ops->remote-ops
db db
@@ -37,8 +35,7 @@
[:update 1 {:block-uuid block-uuid [:update 1 {:block-uuid block-uuid
:av-coll :av-coll
[[:block/name (ldb/write-transit-str "yyy") 1 true] [[:block/name (ldb/write-transit-str "yyy") 1 true]
[:block/title (ldb/write-transit-str "yyy") 1 true] [:block/title (ldb/write-transit-str "yyy") 1 true]]}]}))))))
[:block/type (ldb/write-transit-str "class") 1 true]]}]}))))))
(testing "user.property/xxx creation" (testing "user.property/xxx creation"
(let [block-uuid (random-uuid) (let [block-uuid (random-uuid)
@@ -70,7 +67,6 @@
:db/cardinality :db.cardinality/one :db/cardinality :db.cardinality/one
:db/ident :user.property/xxx, :db/ident :user.property/xxx,
:block/tags [3] :block/tags [3]
:block/type "property",
:block/order block-order, :block/order block-order,
:block/name "xxx", :block/name "xxx",
:block/title "xxx"}])] :block/title "xxx"}])]
@@ -84,8 +80,7 @@
:pos [nil block-order], :pos [nil block-order],
:av-coll :av-coll
[[:block/name "[\"~#'\",\"xxx\"]" 1 true] [[:block/name "[\"~#'\",\"xxx\"]" 1 true]
[:block/title "[\"~#'\",\"xxx\"]" 1 true] [:block/title "[\"~#'\",\"xxx\"]" 1 true]]}
[:block/type "[\"~#'\",\"property\"]" 1 true]]}
:update-schema :update-schema
{:block-uuid block-uuid {:block-uuid block-uuid
:db/ident :user.property/xxx, :db/ident :user.property/xxx,
@@ -102,7 +97,6 @@
[[:db/valueType (ldb/write-transit-str :db.type/ref) 1 true] [[:db/valueType (ldb/write-transit-str :db.type/ref) 1 true]
[:block/name (ldb/write-transit-str "xxx") 1 true] [:block/name (ldb/write-transit-str "xxx") 1 true]
[:block/title (ldb/write-transit-str "xxx") 1 true] [:block/title (ldb/write-transit-str "xxx") 1 true]
[:block/type (ldb/write-transit-str "property") 1 true]
[:db/cardinality (ldb/write-transit-str :db.cardinality/one) 1 true] [:db/cardinality (ldb/write-transit-str :db.cardinality/one) 1 true]
[:db/index (ldb/write-transit-str true) 1 true]]}]})))))) [:db/index (ldb/write-transit-str true) 1 true]]}]}))))))
@@ -112,7 +106,6 @@
:block/updated-at 1720017595873, :block/updated-at 1720017595873,
:block/created-at 1720017595872, :block/created-at 1720017595872,
:db/ident :user.class/zzz, :db/ident :user.class/zzz,
:block/type "class",
:block/name "zzz", :block/name "zzz",
:block/title "zzz"}])] :block/title "zzz"}])]
(is (= {:add (is (= {:add
@@ -121,13 +114,11 @@
:pos [nil nil] :pos [nil nil]
:av-coll :av-coll
[[:block/name "[\"~#'\",\"zzz\"]" 1 true] [[:block/name "[\"~#'\",\"zzz\"]" 1 true]
[:block/title "[\"~#'\",\"zzz\"]" 1 true] [:block/title "[\"~#'\",\"zzz\"]" 1 true]]}}
[:block/type "[\"~#'\",\"class\"]" 1 true]]}}
(:remote-ops (:remote-ops
(#'subject/local-block-ops->remote-ops (#'subject/local-block-ops->remote-ops
db db
{:add [:add 1 {:block-uuid block-uuid {:add [:add 1 {:block-uuid block-uuid
:av-coll :av-coll
[[:block/name (ldb/write-transit-str "zzz") 1 true] [[:block/name (ldb/write-transit-str "zzz") 1 true]
[:block/title (ldb/write-transit-str "zzz") 1 true] [:block/title (ldb/write-transit-str "zzz") 1 true]]}]})))))))
[:block/type (ldb/write-transit-str "class") 1 true]]}]})))))))