diff --git a/deps/db/src/logseq/db/sqlite/util.cljs b/deps/db/src/logseq/db/sqlite/util.cljs index c676cddb5d..14877036e7 100644 --- a/deps/db/src/logseq/db/sqlite/util.cljs +++ b/deps/db/src/logseq/db/sqlite/util.cljs @@ -2,8 +2,11 @@ "Utils fns for backend sqlite db" (:require [cljs-time.coerce :as tc] [cljs-time.core :as t] + [clojure.string :as string] [cognitect.transit :as transit] - [logseq.db.schema :as db-schema])) + [datascript.core :as d] + [logseq.db.schema :as db-schema] + [logseq.db.property :as db-property])) (defn- type-of-block " @@ -66,4 +69,34 @@ (assoc block :block/updated-at updated-at) (nil? (:block/created-at block)) (assoc :block/created-at updated-at))] - block)) \ No newline at end of file + block)) + +(defn sanitize-page-name + "Prepares a string for insertion to :block/name. Not using + gp-util/page-name-sanity-lc yet because it's unclear if db graphs have all the + same naming constraints" + [s] + (string/lower-case s)) + +(defn build-db-initial-data + [config-content] + (let [initial-files [{:block/uuid (d/squuid) + :file/path (str "logseq/" "config.edn") + :file/content config-content} + {:block/uuid (d/squuid) + :file/path (str "logseq/" "custom.css") + :file/content ""} + {:block/uuid (d/squuid) + :file/path (str "logseq/" "custom.js") + :file/content ""}] + default-properties (map + (fn [[k-keyword {:keys [schema original-name]}]] + (let [k-name (name k-keyword)] + (block-with-timestamps + {:block/schema schema + :block/original-name (or original-name k-name) + :block/name (sanitize-page-name k-name) + :block/uuid (d/squuid) + :block/type "property"}))) + db-property/built-in-properties)] + (concat initial-files default-properties))) \ No newline at end of file diff --git a/scripts/nbb.edn b/scripts/nbb.edn index 179e5837f7..f5afe220c9 100644 --- a/scripts/nbb.edn +++ b/scripts/nbb.edn @@ -5,7 +5,4 @@ logseq/outliner {:local/root "../deps/outliner"} logseq/publishing - {:local/root "../deps/publishing"} - logseq/frontend - {:local/root ".." - :deps/root "src/main"}}} + {:local/root "../deps/publishing"}}} diff --git a/scripts/src/logseq/tasks/db_graph/create_graph.cljs b/scripts/src/logseq/tasks/db_graph/create_graph.cljs index ebaa53f19c..bc0515fdd0 100644 --- a/scripts/src/logseq/tasks/db_graph/create_graph.cljs +++ b/scripts/src/logseq/tasks/db_graph/create_graph.cljs @@ -11,9 +11,7 @@ [datascript.core :as d] ["fs" :as fs] ["path" :as node-path] - [nbb.classpath :as cp] - ;; TODO: Move this namespace to more stable deps/ namespaces - [frontend.handler.common.repo :as repo-common-handler])) + [nbb.classpath :as cp])) (defn- find-on-classpath [rel-path] (some (fn [dir] @@ -29,7 +27,7 @@ (let [config-content (or (some-> (find-on-classpath "templates/config.edn") fs/readFileSync str) (do (println "Setting graph's config to empty since no templates/config.edn was found.") "{}"))] - (d/transact! conn (repo-common-handler/build-db-initial-data config-content)))) + (d/transact! conn (sqlite-util/build-db-initial-data config-content)))) (defn init-conn "Create sqlite DB, initialize datascript connection and sync listener and then @@ -86,7 +84,7 @@ (into {})) page-uuids (->> pages-and-blocks (map :page) - (map (juxt #(or (:block/name %) (string/lower-case (:block/original-name %))) + (map (juxt #(or (:block/name %) (sqlite-util/sanitize-page-name (:block/original-name %))) :block/uuid)) (into {})) block-uuids (->> pages-and-blocks @@ -173,7 +171,7 @@ :block/schema (merge {:type :default} (get-in properties [prop-name :block/schema])) :block/original-name (name prop-name) - :block/name (string/lower-case (name prop-name)) + :block/name (sqlite-util/sanitize-page-name (name prop-name)) :block/type "property" :block/created-at created-at :block/updated-at created-at} @@ -191,7 +189,7 @@ [(merge (dissoc page :properties) {:db/id page-id :block/original-name (or (:block/original-name page) (string/capitalize (:block/name page))) - :block/name (or (:block/name page) (string/lower-case (:block/original-name page))) + :block/name (or (:block/name page) (sqlite-util/sanitize-page-name (:block/original-name page))) :block/created-at created-at :block/updated-at created-at} (when (seq (:properties page)) diff --git a/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs b/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs index b297787771..6167d1d163 100644 --- a/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs +++ b/scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs @@ -2,6 +2,7 @@ "Script that generates all the permutations of property types and cardinality. Also creates a page of queries that exercises most properties" (:require [logseq.tasks.db-graph.create-graph :as create-graph] + [logseq.db.sqlite.util :as sqlite-util] [clojure.string :as string] [datascript.core :as d] ["path" :as node-path] @@ -11,7 +12,7 @@ (defn- date-journal-title [date] (let [title (.toLocaleString date "en-US" #js {:month "short" :day "numeric" :year "numeric"}) suffixes {1 "st" 21 "st" 31 "st" 2 "nd" 22 "nd" 3 "rd" 23 "rd" 33 "rd"}] - (string/lower-case + (sqlite-util/sanitize-page-name (string/replace-first title #"(\d+)" (str "$1" (suffixes (.getDate date) "th")))))) (defn- date-journal-day [date] @@ -78,7 +79,7 @@ (println "Generating" (count (filter :block/name blocks-tx)) "pages and" (count (filter :block/content blocks-tx)) "blocks ...") (d/transact! conn blocks-tx) - (println "Created graph" (str db-name "!")))) + (println "Created graph" (str db-name " with " (count (d/datoms @conn :eavt)) " datoms!")))) (when (= nbb/*file* (:file (meta #'-main))) (-main *command-line-args*)) \ No newline at end of file diff --git a/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs b/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs index d5c782063b..b0a751cd4a 100644 --- a/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs +++ b/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs @@ -9,6 +9,7 @@ type logseq doesnt' support yet * schema.org assumes no cardinality. For now, only :object properties are given a :cardinality :many" (:require [logseq.tasks.db-graph.create-graph :as create-graph] + [logseq.db.sqlite.util :as sqlite-util] [clojure.string :as string] [datascript.core :as d] ["path" :as node-path] @@ -133,7 +134,7 @@ [property-ids class-ids {:keys [verbose]}] (let [conflicts (->> (concat property-ids class-ids) - (group-by (comp string/lower-case first)) + (group-by (comp sqlite-util/sanitize-page-name first)) (filter #(> (count (val %)) 1)) vals) ;; If this assertion fails then renamed-classes approach to resolving diff --git a/src/main/frontend/handler/common/repo.cljs b/src/main/frontend/handler/common/repo.cljs deleted file mode 100644 index 040764845c..0000000000 --- a/src/main/frontend/handler/common/repo.cljs +++ /dev/null @@ -1,28 +0,0 @@ -(ns ^:nbb-compatible frontend.handler.common.repo - (:require [datascript.core :as d] - [logseq.db.property :as db-property] - [logseq.graph-parser.util :as gp-util] - [logseq.db.sqlite.util :as sqlite-util])) - -(defn build-db-initial-data - [config-content] - (let [initial-files [{:block/uuid (d/squuid) - :file/path (str "logseq/" "config.edn") - :file/content config-content} - {:block/uuid (d/squuid) - :file/path (str "logseq/" "custom.css") - :file/content ""} - {:block/uuid (d/squuid) - :file/path (str "logseq/" "custom.js") - :file/content ""}] - default-properties (map - (fn [[k-keyword {:keys [schema original-name]}]] - (let [k-name (name k-keyword)] - (sqlite-util/block-with-timestamps - {:block/schema schema - :block/original-name (or original-name k-name) - :block/name (gp-util/page-name-sanity-lc k-name) - :block/uuid (d/squuid) - :block/type "property"}))) - db-property/built-in-properties)] - (concat initial-files default-properties))) \ No newline at end of file diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index 9f0c01fd2e..0bf05cfa91 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -12,7 +12,6 @@ [frontend.handler.file :as file-handler] [frontend.handler.repo-config :as repo-config-handler] [frontend.handler.common.file :as file-common-handler] - [frontend.handler.common.repo :as repo-common-handler] [frontend.handler.route :as route-handler] [frontend.handler.ui :as ui-handler] [frontend.handler.global-config :as global-config-handler] @@ -28,6 +27,7 @@ [frontend.db.persist :as db-persist] [logseq.graph-parser :as graph-parser] [logseq.graph-parser.config :as gp-config] + [logseq.db.sqlite.util :as sqlite-util] [electron.ipc :as ipc] [cljs-bean.core :as bean] [clojure.core.async :as async] @@ -547,7 +547,7 @@ _ (route-handler/redirect-to-home!) _ (db/transact! full-graph-name [(react/kv :db/type "db")] {:skip-persist? true}) - initial-data (repo-common-handler/build-db-initial-data config/config-default-content) + initial-data (sqlite-util/build-db-initial-data config/config-default-content) _ (db/transact! full-graph-name initial-data) _ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content) ;; TODO: handle global graph