diff --git a/bb.edn b/bb.edn index fc8bb3080..33f7fd3ef 100644 --- a/bb.edn +++ b/bb.edn @@ -116,6 +116,9 @@ lint:ns-docstrings logseq.bb-tasks.lint.ns-docstrings/-main + lint:db-and-file-graphs-separate + logseq.tasks.dev.db-and-file-graphs/-main + nbb:watch logseq.bb-tasks.nbb.watch/watch diff --git a/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj b/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj new file mode 100644 index 000000000..fe7b8f4a0 --- /dev/null +++ b/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj @@ -0,0 +1,87 @@ +(ns logseq.tasks.dev.db-and-file-graphs + (:require [babashka.process :refer [shell]] + [clojure.string :as string])) + +(defn- escape-shell-regex + [s] + (reduce (fn [acc escape-char] + (string/replace acc escape-char (str "\\" escape-char))) + s + ["." "?"])) + +(def db-graph-ns + "Namespaces or parent namespaces _only_ for DB graphs" + (mapv escape-shell-regex + ["frontend.handler.db-based." "logseq.db.sqlite." "logseq.db.frontend.property" + "frontend.components.property" "frontend.components.class"])) + +(def file-graph-ns + "Namespaces or parent namespaces _only_ for file graphs" + (mapv escape-shell-regex + ["frontend.handler.file-based" "frontend.fs"])) + +(def db-graph-paths + "Paths _only_ for DB graphs" + ["src/main/frontend/handler/db_based" + "src/main/frontend/components/class.cljs" + "src/main/frontend/components/property.cljs"]) + +(def file-graph-paths + "Paths _only_ for file graphs" + ["src/main/frontend/handler/file_based" "src/main/frontend/fs"]) + +(defn- validate-db-ns-not-in-file + [] + (let [res (apply shell {:out :string :continue true} + "git grep -E" (str "(" (string/join "|" db-graph-ns) ")") + file-graph-paths)] + (when-not (and (= 1 (:exit res)) (= "" (:out res))) + (println "The following db graph namespaces should not be in file graph files:") + (println (:out res)) + (System/exit 1)))) + +(defn- validate-file-ns-not-in-db + [] + (let [res (apply shell {:out :string :continue true} + "git grep -E" (str "(" (string/join "|" file-graph-ns) ")") + db-graph-paths)] + (when-not (and (= 1 (:exit res)) (= "" (:out res))) + (println "The following file graph namespaces should not be in db graph files:") + (println (:out res)) + (System/exit 1)))) + +(defn- validate-multi-graph-fns-not-in-file-or-db + [] + (let [multi-graph-fns ["config/db-based-graph\\?"] + res (apply shell {:out :string :continue true} + "git grep -E" (str "(" (string/join "|" multi-graph-fns) ")") + (into file-graph-paths db-graph-paths))] + (when-not (and (= 1 (:exit res)) (= "" (:out res))) + (println "The following files should not have contained config/db-based-graph:") + (println (:out res)) + (System/exit 1)))) + +(defn- validate-file-attributes-not-in-db + [] + (let [file-attrs-str (str "(" + ;; from logseq.db.frontend.schema + (->> [:block/properties-text-values :block/pre-block :recent/pages :file/handle :block/file :block/properties-order] + (map #(subs (str %) 1)) + (string/join "|")) + ")") + res (apply shell {:out :string :continue true} + "git grep -E" file-attrs-str + db-graph-paths)] + (when-not (and (= 1 (:exit res)) (= "" (:out res))) + (println "The following files should not have contained file specific attributes:") + (println (:out res)) + (System/exit 1)))) + +(defn -main + "Check that file and db graph specific namespaces and concepts are separate" + [] + (validate-db-ns-not-in-file) + (validate-file-ns-not-in-db) + (validate-file-attributes-not-in-db) + (validate-multi-graph-fns-not-in-file-or-db) + (println "✅ All checks passed!")) \ No newline at end of file diff --git a/src/main/frontend/handler/db_based/editor.cljs b/src/main/frontend/handler/db_based/editor.cljs index 417faabe9..a2e4b36d7 100644 --- a/src/main/frontend/handler/db_based/editor.cljs +++ b/src/main/frontend/handler/db_based/editor.cljs @@ -86,8 +86,6 @@ (dissoc :block.temp/top? :block.temp/bottom? - :block/properties-text-values - :block/pre-block? :block/unordered) (assoc :block/content content) (merge (if level {:block/level level} {}))