diff --git a/.carve/ignore b/.carve/ignore index b0e3526b1..c2003954a 100644 --- a/.carve/ignore +++ b/.carve/ignore @@ -88,12 +88,10 @@ frontend.fs.sync/stop-debug-print-sync-events-loop frontend.state/get-current-edit-block-and-position ;; For debugging frontend.db.model/get-all-classes -;; Repl fn -frontend.db.sync/export-as-blocks ;; Initial loaded frontend.ui/_emoji-init-data ;; placeholder var for defonce -frontend.db.rtc.op-mem-layer/_sync-loop +frontend.worker.rtc.op-mem-layer/_sync-loop ;; Used by shadow.cljs frontend.db-worker/init ;; For defonce diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index 81d0b2ce9..78af3ec82 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -23,7 +23,7 @@ object]} :unused-namespace {:level :warning - :exclude [frontend.db.datascript.entity-plus]} + :exclude [logseq.db.frontend.entity-plus]} ;; TODO:lint: Remove node-path excludes once we have a cleaner api :unresolved-var {:exclude [frontend.util/node-path.basename @@ -168,7 +168,7 @@ ;; src/test frontend.test.helper/deftest-async clojure.test/deftest frontend.test.helper/with-reset cljs.test/async - frontend.db.rtc.idb-keyval-mock/with-reset-idb-keyval-mock cljs.test/async + frontend.worker.rtc.idb-keyval-mock/with-reset-idb-keyval-mock cljs.test/async frontend.react/defc clojure.core/defn} :skip-comments true :output {:progress true}} diff --git a/deps/common/src/logseq/common/util.cljs b/deps/common/src/logseq/common/util.cljs index 951960bfd..6037ef328 100644 --- a/deps/common/src/logseq/common/util.cljs +++ b/deps/common/src/logseq/common/util.cljs @@ -259,7 +259,6 @@ ;; Register sanitization / parsing fns in: ;; logseq.common.util (parsing only) ;; frontend.util.fs (sanitization only) -;; frontend.handler.conversion (both) (defn title-parsing "Convert file name in the given file name format to page title" [file-name-body filename-format] diff --git a/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj b/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj index 011786c29..2c664d767 100644 --- a/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj +++ b/scripts/src/logseq/tasks/dev/db_and_file_graphs.clj @@ -21,7 +21,7 @@ (def file-graph-ns "Namespaces or parent namespaces _only_ for file graphs" (mapv escape-shell-regex - ["frontend.handler.file-based" "frontend.handler.conversion" "frontend.handler.file-sync" + ["frontend.handler.file-based" "frontend.handler.file-sync" "frontend.db.file-based" "frontend.fs" "frontend.components.conversion" "frontend.components.file-sync" @@ -40,9 +40,9 @@ (def file-graph-paths "Paths _only_ for file graphs" - ["src/main/frontend/handler/file_based" "src/main/frontend/handler/conversion.cljs" "src/main/frontend/handler/file_sync.cljs" + ["src/main/frontend/handler/file_based" "src/main/frontend/handler/file_sync.cljs" "src/main/frontend/fs" - "src/main/frontend/components/conversion.cljs" "src/main/frontend/components/file_sync.cljs" + "src/main/frontend/components/file_sync.cljs" "src/main/frontend/util/fs.cljs"]) (defn- validate-db-ns-not-in-file diff --git a/src/main/frontend/components/settings.cljs b/src/main/frontend/components/settings.cljs index 66d419e0f..af6fcccaa 100644 --- a/src/main/frontend/components/settings.cljs +++ b/src/main/frontend/components/settings.cljs @@ -624,15 +624,6 @@ (ipc/ipc :userAppCfgs :feature/enable-automatic-chmod? (not enabled?))) [:span.text-sm.opacity-50 (t :settings-page/auto-chmod-desc)]))) -(defn filename-format-row [] - (row-with-button-action - {:left-label (t :settings-page/filename-format) - :button-label (t :settings-page/edit-setting) - ;; :on-click #(state/set-sub-modal! - ;; (fn [_] (conversion-component/files-breaking-changed)) - ;; {:id :filename-format-panel :center? true}) - })) - (rum/defcs native-titlebar-row < rum/reactive [state t] (let [enabled? (state/sub [:electron/user-cfgs :window/native-titlebar?])] diff --git a/src/main/frontend/db/react.cljs b/src/main/frontend/db/react.cljs index 70a13302b..31615272f 100644 --- a/src/main/frontend/db/react.cljs +++ b/src/main/frontend/db/react.cljs @@ -218,15 +218,6 @@ (when (and (not (:skip-refresh? tx-meta)) (seq tx-data)) (refresh-affected-queries! repo-url affected-keys))))) -(defn batch-refresh! - [repo-url _txs] - ;; (when (and repo-url (seq txs)) - ;; (let [affected-keys (apply set/union (map get-affected-queries-keys txs))] - ;; (refresh-affected-queries! repo-url affected-keys))) - (state/set-state! [:rtc/remote-batch-tx-state repo-url] - {:in-transaction? false - :txs []})) - (defn set-key-value [repo-url key value] (if value diff --git a/src/main/frontend/handler/common.cljs b/src/main/frontend/handler/common.cljs index 8449e3098..03d9a9a41 100644 --- a/src/main/frontend/handler/common.cljs +++ b/src/main/frontend/handler/common.cljs @@ -40,12 +40,6 @@ (println error-message-or-handler)) {}))) -(defn get-page-default-properties - [page-name] - {:title page-name - ;; :date (date/get-date-time-string) - }) - (defn fix-pages-timestamps [pages] (map (fn [{:block/keys [created-at updated-at journal-day] :as p}] diff --git a/src/main/frontend/handler/conversion.cljs b/src/main/frontend/handler/conversion.cljs deleted file mode 100644 index 240392be8..000000000 --- a/src/main/frontend/handler/conversion.cljs +++ /dev/null @@ -1,120 +0,0 @@ -;; Convert data on updating from earlier version of Logseq on demand - -(ns frontend.handler.conversion - "For conversion logic between old version and new version" - (:require [logseq.common.util :as common-util] - [frontend.util.fs :as fs-util] - [frontend.handler.config :refer [set-config!]] - [frontend.util :as util])) - -(defn write-filename-format! - "Return: - Promise " - [repo format] - (js/console.log (str "Writing character escaping format " format " of repo " repo)) - (set-config! :file/name-format format)) - -(defn- calc-current-name - "If the file body is parsed as the same page name, but the page name has a - different file sanitization result under the current sanitization form, return - the new file name. - Return: - the file name for the page name under the current file naming rules, or `nil` - if no change of path happens" - [format file-body prop-title] - (let [page-title (or prop-title - (common-util/title-parsing file-body format)) - cur-file-body (fs-util/file-name-sanity page-title format)] - (when-not (= file-body cur-file-body) - {:status :informal - :target cur-file-body - :old-title page-title - :changed-title page-title}))) - -(defn- calc-previous-name - "We want to recover user's title back under new file name sanity rules. - Return: - the file name for that page name under the current file naming rules, - and the new title if no action applied, or `nil` if no break change happens" - [old-format new-format file-body] - (let [new-title (common-util/title-parsing file-body new-format) ;; Rename even the prop-title is provided. - old-title (common-util/title-parsing file-body old-format) - target (fs-util/file-name-sanity old-title new-format)] - (when (not= new-title old-title) - (if (not= target file-body) - {:status :breaking - :target target - :old-title old-title - :changed-title new-title} - ;; Even the same file body are producing mismatched titles - it's unreachable! - {:status :unreachable - :target target - :old-title old-title - :changed-title new-title})))) - -;; Register sanitization / parsing fns in: -;; logseq.common.util (parsing only) -;; frontend.util.fs (sanitization only) -;; frontend.handler.conversion (both) -;; - the special rule in `is-manual-title-prop?` -(defonce supported-filename-formats [:triple-lowbar :legacy]) - -(defn- is-manual-title-prop? - "If it's an user defined title property instead of the generated one" - [format file-body prop-title] - (if prop-title - (not (or (= file-body (fs-util/file-name-sanity prop-title format)) - (when (= format :legacy) - (= file-body (fs-util/file-name-sanity prop-title :legacy-dot))))) - false)) - -(defn- calc-rename-target-impl - [old-format new-format file-body prop-title] - ;; dont rename journal page. officially it's stored as `yyyy_mm_dd` - ;; If it's a journal file imported with custom :journal/page-title-format, - ;; and it includes reserved characters, format config change / file renaming is required. - ;; It's about user's own data management decision and should be handled - ;; by user manually. - ;; the 'expected' title of the user when updating from the previous format, or title will be broken in new format - (let [ret (or (when (and (nil? prop-title) - (not= old-format new-format)) - (calc-previous-name old-format new-format file-body)) - ;; if no break-change conversion triggered, check if file name is in an informal / outdated style. - (calc-current-name new-format file-body prop-title))] - (when (and ret - ;; Return only when the target is different from the original file body, not only capitalization difference - (not= (util/page-name-sanity-lc (:target ret)) - (util/page-name-sanity-lc file-body))) - ret))) - -(defn calc-rename-target - "Return the renaming status and new file body to recover the original title of the file in previous version. - The return title should be the same as the title in the index file in the previous version. - return nil if no rename is needed. - page: the page entity - path: the path of the file of the page - old-format, new-format: the filename formats - Return: - {:status :informal | :breaking | :unreachable - :file-name original file name - :target the new file name - :old-title the old title - :changed-title the new title} | nil" - [page path old-format new-format] - (let [prop-title (get-in page [:block/properties :title]) - file-body (common-util/path->file-body path) - journal? (:block/journal? page) - manual-prop-title? (is-manual-title-prop? old-format file-body prop-title)] - (cond - (and (not journal?) - (not manual-prop-title?)) - (calc-rename-target-impl old-format new-format file-body prop-title) - - (and (not journal?) - manual-prop-title? - (fs-util/include-reserved-chars? file-body)) - {:status :informal - :file-name file-body - :target (fs-util/file-name-sanity file-body new-format) - :old-title prop-title - :changed-title prop-title}))) diff --git a/src/main/frontend/handler/file_based/editor.cljs b/src/main/frontend/handler/file_based/editor.cljs index 8547756c4..c6f53087b 100644 --- a/src/main/frontend/handler/file_based/editor.cljs +++ b/src/main/frontend/handler/file_based/editor.cljs @@ -17,7 +17,6 @@ [frontend.handler.file-based.property :as file-property-handler] [frontend.handler.file-based.property.util :as property-util] [logseq.db.frontend.schema :as db-schema] - [logseq.graph-parser.block :as gp-block] [logseq.common.util.block-ref :as block-ref])) (defn- remove-non-existed-refs! @@ -129,24 +128,6 @@ :block/properties new-properties) (merge (if level {:block/level level} {}))))) -(defn properties-block - [repo properties format page] - (let [content (property-file/insert-properties-when-file-based repo format "" properties) - refs (gp-block/get-page-refs-from-properties properties - (db/get-db (state/get-current-repo)) - (state/get-date-formatter) - (state/get-config))] - {:block/pre-block? true - :block/uuid (db/new-block-id) - :block/properties properties - :block/properties-order (keys properties) - :block/refs refs - :block/left page - :block/format format - :block/content content - :block/parent page - :block/page page})) - (defn- set-block-property-aux! [block-or-id key value] (when-let [block (cond (string? block-or-id) (db/entity [:block/uuid (uuid block-or-id)]) diff --git a/src/main/frontend/handler/file_based/page_property.cljs b/src/main/frontend/handler/file_based/page_property.cljs index 6d42544d8..14cdf5efe 100644 --- a/src/main/frontend/handler/file_based/page_property.cljs +++ b/src/main/frontend/handler/file_based/page_property.cljs @@ -31,24 +31,6 @@ lines (if @key-exists? lines (cons new-property-line lines))] (string/join "\n" lines)))) -(defn insert-properties - "Updates multiple page properties. Mainly just used in legacy title context" - [format content kvs] - (reduce - (fn [content [k v]] - (let [k (if (string? k) - (keyword (-> (string/lower-case k) - (string/replace " " "-"))) - k) - v (if (coll? v) - (some->> - (seq v) - (distinct) - (string/join ", ")) - v)] - (insert-property format content k v))) - content kvs)) - (defn add-property! [page-name key value] (let [repo (state/get-current-repo)] diff --git a/src/main/frontend/handler/file_based/property/util.cljs b/src/main/frontend/handler/file_based/property/util.cljs index a1700c21a..9a2ba5e14 100644 --- a/src/main/frontend/handler/file_based/property/util.cljs +++ b/src/main/frontend/handler/file_based/property/util.cljs @@ -148,11 +148,6 @@ (string/triml (string/join "\n" body))) content))) -;; FIXME: -(defn front-matter? - [s] - (string/starts-with? s "---\n")) - (defn insert-property "Only accept nake content (without any indentation)" ([format content key value] diff --git a/src/main/frontend/handler/property/file.cljs b/src/main/frontend/handler/property/file.cljs index 300ec015e..00ec06d2b 100644 --- a/src/main/frontend/handler/property/file.cljs +++ b/src/main/frontend/handler/property/file.cljs @@ -46,7 +46,6 @@ (def property-key-exist?-when-file-based property-util/property-key-exist?) (def goto-properties-end-when-file-based property-util/goto-properties-end) -(def front-matter?-when-file-based property-util/front-matter?) (defn properties-hidden? [properties] diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 74e68b353..2de67a3c7 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -254,14 +254,6 @@ (reduce-kv #(if (pred %3) (reduced %2) %1) -1 (cond-> coll (list? coll) (vec))))) -;; (defn format -;; [fmt & args] -;; (apply gstring/format fmt args)) - -(defn remove-nils-non-nested - [nm] - (into {} (remove (comp nil? second)) nm)) - ;; ".lg:absolute.lg:inset-y-0.lg:right-0.lg:w-1/2" (defn hiccup->class [class] diff --git a/src/main/frontend/util/fs.cljs b/src/main/frontend/util/fs.cljs index cfceda43b..713ea2c81 100644 --- a/src/main/frontend/util/fs.cljs +++ b/src/main/frontend/util/fs.cljs @@ -3,9 +3,7 @@ (ns frontend.util.fs "Misc util fns built on top of frontend.fs" (:require ["path" :as node-path] - [logseq.common.util :as common-util] [clojure.string :as string] - [frontend.state :as state] [frontend.fs :as fs] [frontend.config :as config] [promesa.core :as p] @@ -78,13 +76,3 @@ (defn file-name-sanity [name _format] (wfu/file-name-sanity name)) - -(defn create-title-property? - [page-name] - (and (string? page-name) - (let [filename-format (state/get-filename-format) - file-name (file-name-sanity page-name filename-format) - page-name' (common-util/title-parsing file-name filename-format) - result (or (not= page-name page-name') - (include-reserved-chars? file-name))] - result))) diff --git a/src/main/frontend/worker/file/util.cljs b/src/main/frontend/worker/file/util.cljs index babe1d43f..8d5cc7a48 100644 --- a/src/main/frontend/worker/file/util.cljs +++ b/src/main/frontend/worker/file/util.cljs @@ -62,7 +62,6 @@ ;; Register sanitization / parsing fns in: ;; logseq.common.util (parsing only) ;; frontend.util.fs (sanitization only) -;; frontend.handler.conversion (both) (defn file-name-sanity [title] (when (string? title) diff --git a/src/main/frontend/worker/handler/page.cljs b/src/main/frontend/worker/handler/page.cljs index a490ba391..6a4d247a5 100644 --- a/src/main/frontend/worker/handler/page.cljs +++ b/src/main/frontend/worker/handler/page.cljs @@ -1,4 +1,5 @@ (ns frontend.worker.handler.page + "Page operations" (:require [logseq.db :as ldb] [logseq.graph-parser.block :as gp-block] [logseq.graph-parser.property :as gp-property] diff --git a/src/main/frontend/worker/rtc/op_mem_layer.cljs b/src/main/frontend/worker/rtc/op_mem_layer.cljs index 89cc4d914..d27cc02ad 100644 --- a/src/main/frontend/worker/rtc/op_mem_layer.cljs +++ b/src/main/frontend/worker/rtc/op_mem_layer.cljs @@ -393,15 +393,18 @@ ops* (ops-encoder ops)] (op-idb-layer/ \"%3F\")" - :file-rn/filename-desc-4 "命名空間分隔符 \"/\" 也會更改為 \"___\" (三個底線) 以便分辨" - :file-rn/instruct-1 "需要兩個以更新文件名稱:" - :file-rn/instruct-2 "1. 點擊" - :file-rn/instruct-3 "2. 按照以下說明將文件重命名為新格式:" :page/created-at "創建於" :page/updated-at "更新於" :page/backlinks "反向連結" @@ -144,7 +120,6 @@ :settings-page/edit-global-config-edn "編輯 global config.edn" :settings-page/edit-custom-css "編輯 custom.css" :settings-page/edit-export-css "編輯 export.css" - :settings-page/edit-setting "編輯" :settings-page/custom-configuration "個人化設定" :settings-page/custom-global-configuration "個人化全域設定" :settings-page/custom-theme "個人化主題" @@ -180,7 +155,6 @@ :settings-page/plugin-system "外掛系統" :settings-page/enable-flashcards "啟用卡片" :settings-page/network-proxy "網路代理" - :settings-page/filename-format "文件名稱格式" :settings-page/alpha-features "Alpha 功能" :settings-page/beta-features "Beta 功能" :settings-page/login-prompt "你必須是 Logseq 的 Open Collective Sponsor 或 Backer 以使用新功能。(需要登入)" diff --git a/src/test/frontend/db/name_sanity_test.cljs b/src/test/frontend/db/name_sanity_test.cljs index 71bb1bd77..d2a2d982f 100644 --- a/src/test/frontend/db/name_sanity_test.cljs +++ b/src/test/frontend/db/name_sanity_test.cljs @@ -1,9 +1,8 @@ (ns frontend.db.name-sanity-test - (:require [cljs.test :refer [deftest testing is are]] + (:require [cljs.test :refer [deftest testing is]] [clojure.string :as string] [logseq.common.util :as common-util] [frontend.worker.handler.page.rename :as worker-page-rename] - [frontend.handler.conversion :as conversion-handler] [frontend.util.fs :as fs-util] [frontend.worker.file.util :as wfu])) @@ -49,112 +48,3 @@ (deftest new-path-computation-tests (is (= (#'worker-page-rename/compute-new-file-path "/data/app/dsal dsalfjk aldsaf.jkl" "ddd") "/data/app/ddd.jkl")) (is (= (#'worker-page-rename/compute-new-file-path "c://data/a sdfpp/dsal dsalf% * _ dsaf.mnk" "c d / f") "c://data/a sdfpp/c d / f.mnk"))) - -(deftest break-change-conversion-tests - (let [conv-legacy #(:target (#'conversion-handler/calc-previous-name :legacy :triple-lowbar %))] - (is (= "dsal dsalfjk aldsaf___jkl" (conv-legacy "dsal dsalfjk aldsaf.jkl"))) - (is (= nil (conv-legacy "dsal dsalfjk jkl"))) - (is (= nil (conv-legacy "dsa&l dsalfjk jkl"))) - (is (= nil (conv-legacy "dsa<l dsalfjk jkl"))) - (is (= nil (conv-legacy "dsal dsal%2Ffjk jkl"))) - (is (= nil (conv-legacy "dsal dsal%2Cfjk jkl")))) ;; %2C already parsed as `,` in the previous ver. - ) - -(deftest formalize-conversion-tests - (let [conv-informal #(:target (#'conversion-handler/calc-current-name :triple-lowbar % nil))] - (is (= "Hello.js, navigator___userAgent" (conv-informal "Hello.js, navigator/userAgent"))) - (is (= "sdaf ___dsakl" (conv-informal "sdaf %2Fdsakl"))) - (is (= "sdaf ___dsakl" (conv-informal "sdaf /dsakl"))) - (is (= nil (conv-informal "sdaf .dsakl"))))) - -(deftest rename-previous-tests - (are [x y] (= y (#'conversion-handler/calc-previous-name :legacy :triple-lowbar x)) - "aa?#.bbb.ccc" {:status :breaking, - :target "aa%3F%23___bbb___ccc", - :old-title "aa?#/bbb/ccc", - :changed-title "aa?#.bbb.ccc"} - "aaa__bbb__ccc" nil - "aaa__bbb__cccon" nil - "aaa.bbb.ccc" {:status :breaking, - :target "aaa___bbb___ccc", - :old-title "aaa/bbb/ccc", - :changed-title "aaa.bbb.ccc"} - "a__.bbb.ccc" {:status :breaking, - :target "a_%5F___bbb___ccc", - :old-title "a__/bbb/ccc", - :changed-title "a__.bbb.ccc"}) - ;; is not a common used case - (are [x y] (= y (#'conversion-handler/calc-previous-name :triple-lowbar :legacy x)) - "aa%3F%23.bbb.ccc" {:status :unreachable, - :target "aa%3F%23.bbb.ccc", - :old-title "aa?#.bbb.ccc", - :changed-title "aa?#/bbb/ccc"})) - -(deftest rename-tests-l2t - ;; Test cases for rename from legacy to triple-lowbar - ;; The title property matters - removing it will change the result. Ask users not to remove it. - ;; z: new title structure; x: old ver title; y: title property (if available) - (are [x y z] (= z (#'conversion-handler/calc-rename-target-impl :legacy :triple-lowbar x y)) - "报错 SyntaxError: Unexpected token '.'" "报错 SyntaxError: Unexpected token '.'" {:status :informal, - :target "报错 SyntaxError%3A Unexpected token '.'", - :old-title "报错 SyntaxError: Unexpected token '.'", - :changed-title "报错 SyntaxError: Unexpected token '.'"} - "报错 SyntaxError: Unexpected token '.'" nil {:status :breaking, - :target "报错 SyntaxError%3A Unexpected token '___'", - :old-title "报错 SyntaxError: Unexpected token '/'", - :changed-title "报错 SyntaxError: Unexpected token '.'"} - "aaBBcc" "aabbcc" nil - "aaa.bbb.ccc" "aaa/bbb/ccc" {:status :informal, - :target "aaa___bbb___ccc", - :old-title "aaa/bbb/ccc", - :changed-title "aaa/bbb/ccc"} - "aaa.bbb.ccc" nil {:status :breaking, - :target "aaa___bbb___ccc", - :old-title "aaa/bbb/ccc", - :changed-title "aaa.bbb.ccc"} - "aa__.bbb.ccc" "aa?#/bbb/ccc" {:status :informal, - :target "aa%3F%23___bbb___ccc", - :old-title "aa?#/bbb/ccc", - :changed-title "aa?#/bbb/ccc"} - "aa?#.bbb.ccc" "aa__/bbb/ccc" {:status :informal, - :target "aa_%5F___bbb___ccc", - :old-title "aa__/bbb/ccc", - :changed-title "aa__/bbb/ccc"} - "aaa__bbb__ccc" "aaa/bbb/ccc" {:status :informal, - :target "aaa___bbb___ccc", - :old-title "aaa/bbb/ccc", - :changed-title "aaa/bbb/ccc"} - "aaa__bbb__cccon" "aaa/bbb/cccon" {:status :informal, - :target "aaa___bbb___cccon", - :old-title "aaa/bbb/cccon", - :changed-title "aaa/bbb/cccon"} - "aaa__bbb__ccc" nil nil - "aaa_bbb_ccc" nil nil - "aaa.bbb.ccc" "adbcde/aks/sdf" {:status :informal, - :target "adbcde___aks___sdf", - :old-title "adbcde/aks/sdf", - :changed-title "adbcde/aks/sdf"} - "a__.bbb.ccc" "adbcde/aks/sdf" {:status :informal, - :target "adbcde___aks___sdf", - :old-title "adbcde/aks/sdf", - :changed-title "adbcde/aks/sdf"} - "aaa%2Fbbb%2Fccc" "aaa/bbb/ccc" {:status :informal, - :target "aaa___bbb___ccc", - :old-title "aaa/bbb/ccc", - :changed-title "aaa/bbb/ccc"} - "CON" "CON" {:status :informal, - :target "CON___", - :old-title "CON", - :changed-title "CON"} - "CON" nil {:status :informal, - :target "CON___", - :old-title "CON", - :changed-title "CON"} - "abc." "abc." {:status :informal, - :target "abc.___", - :old-title "abc.", - :changed-title "abc."} - "abc." nil {:status :breaking, - :target "abc", ;; abc/ is an invalid file name - :old-title "abc/", - :changed-title "abc."})) diff --git a/src/test/frontend/handler/repo_conversion_test.cljs b/src/test/frontend/handler/repo_conversion_test.cljs deleted file mode 100644 index 6551979d6..000000000 --- a/src/test/frontend/handler/repo_conversion_test.cljs +++ /dev/null @@ -1,147 +0,0 @@ -(ns frontend.handler.repo-conversion-test - "Repo tests of directory conversion" - (:require [cljs.test :refer [deftest use-fixtures is testing]] - [clojure.string :as string] - [logseq.graph-parser.cli :as gp-cli] - [logseq.common.util :as common-util] - [logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper] - [logseq.common.config :as common-config] - [frontend.test.helper :as test-helper] - [frontend.worker.handler.page.rename :as worker-page-rename] - [frontend.handler.conversion :as conversion-handler] - [frontend.handler.repo :as repo-handler] - [frontend.db.conn :as conn] - [datascript.core :as d])) - -(use-fixtures :each {:before test-helper/start-test-db! - :after test-helper/destroy-test-db!}) - -(defn- query-assertions-v067 - [db graph-dir files] - (testing "Query based stats" - (is (= (->> files - ;; logseq files aren't saved under :block/file - (remove #(string/includes? % (str graph-dir "/" common-config/app-name "/"))) - set) - (->> (d/q '[:find (pull ?b [* {:block/file [:file/path]}]) - :where [?b :block/name] [?b :block/file]] - db) - (map (comp #(get-in % [:block/file :file/path]) first)) - set)) - "Files on disk should equal ones in db") - - (is (= (count (filter #(re-find #"journals/" %) files)) - (->> (d/q '[:find (count ?b) - :where - [?b :block/journal? true] - [?b :block/name] - [?b :block/file]] - db) - ffirst)) - "Journal page count on disk equals count in db") - - (is (= {"CANCELED" 2 "DONE" 6 "LATER" 4 "NOW" 5} - (->> (d/q '[:find (pull ?b [*]) :where [?b :block/marker]] - db) - (map first) - (group-by :block/marker) - (map (fn [[k v]] [k (count v)])) - (into {}))) - "Task marker counts") - - (is (= {:markdown 3552 :org 519} - (docs-graph-helper/get-block-format-counts db)) - "Block format counts") - - (is (= {:title 98 :id 98 - :updated-at 47 :created-at 47 - :card-last-score 6 :card-repeats 6 :card-next-schedule 6 - :card-last-interval 6 :card-ease-factor 6 :card-last-reviewed 6 - :alias 6 :logseq.macro-arguments 94 :logseq.macro-name 94 :heading 64} - (docs-graph-helper/get-top-block-properties db)) - "Counts for top block properties") - - (is (= {:title 98 - :alias 6 - :tags 3 :permalink 2 - :name 1 :type 1 :related 1 :sample 1 :click 1 :id 1 :example 1} - (docs-graph-helper/get-all-page-properties db)) - "Counts for all page properties") - - (is (= {:block/scheduled 2 - :block/priority 4 - :block/deadline 1 - :block/collapsed? 22 - :block/repeated? 1} - (->> [:block/scheduled :block/priority :block/deadline :block/collapsed? - :block/repeated?] - (map (fn [attr] - [attr - (ffirst (d/q [:find (list 'count '?b) :where ['?b attr]] - db))])) - (into {}))) - "Counts for blocks with common block attributes") - - (is (= #{"term" "setting" "book" "templates" "Query" "Query/table" "page"} - (->> (d/q '[:find (pull ?n [*]) :where [?b :block/namespace ?n]] db) - (map (comp :block/original-name first)) - set)) - "Has correct namespaces"))) - -(defn docs-graph-assertions-v067 - "These are common assertions that should pass in both graph-parser and main - logseq app. It is important to run these in both contexts to ensure that the - functionality in frontend.handler.repo and logseq.graph-parser remain the - same" - [db graph-dir files] - ;; Counts assertions help check for no major regressions. These counts should - ;; only increase over time as the docs graph rarely has deletions - (testing "Counts" - (is (= 211 (count files)) "Correct file count") - (is (= 39261 (count (d/datoms db :eavt))) "Correct datoms count") - - (is (= 3600 - (ffirst - (d/q '[:find (count ?b) - :where [?b :block/path-refs ?bp] [?bp :block/name]] db))) - "Correct referenced blocks count") - (is (= 21 - (ffirst - (d/q '[:find (count ?b) - :where [?b :block/content ?content] - [(clojure.string/includes? ?content "+BEGIN_QUERY")]] - db))) - "Advanced query count")) - - (query-assertions-v067 db graph-dir files)) - -(defn- convert-to-triple-lowbar - [path] - (let [original-body (common-util/path->file-body path) - ;; only test file name parsing, don't consider title prop overriding - rename-target (:target (#'conversion-handler/calc-rename-target-impl :legacy :triple-lowbar original-body nil))] - (if rename-target - #_:clj-kondo/ignore - (do #_(prn "conversion triple-lowbar: " original-body " -> " rename-target) - (#'worker-page-rename/compute-new-file-path path rename-target)) - path))) - -(defn- convert-graph-files-path - "Given a list of files, converts them according to the given conversion function" - [files conversion-fn] - (map (fn [file] - (assoc file :file/path (conversion-fn (:file/path file)))) files)) - -;; Integration test that test parsing a large graph like docs -;; Check if file name conversion from old version of docs is working -(deftest ^:integration convert-v067-filenames-parse-and-load-files-to-db - (let [graph-dir "src/test/docs" - _ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir "v0.6.7") - files (#'gp-cli/build-graph-files graph-dir {}) - ;; Converting the v0.6.7 ver docs graph under the old namespace naming rule to the new one (:repo/dir-version 0->3) - files (convert-graph-files-path files convert-to-triple-lowbar) - _ (repo-handler/parse-files-and-load-to-db! test-helper/test-db files {:re-render? false :verbose false}) - db (conn/get-db test-helper/test-db)] - - ;; Result under new naming rule after conversion should be the same as the old one - (docs-graph-assertions-v067 db graph-dir (map :file/path files))))