Explorar el Código

remove file based handlers

Tienson Qin hace 3 días
padre
commit
9f927137a3
Se han modificado 41 ficheros con 183 adiciones y 2810 borrados
  1. 0 12
      src/main/electron/listener.cljs
  2. 0 93
      src/main/frontend/components/diff.cljs
  3. 0 23
      src/main/frontend/components/diff.css
  4. 2 58
      src/main/frontend/components/imports.cljs
  5. 1 6
      src/main/frontend/db/async.cljs
  6. 0 206
      src/main/frontend/fs/watcher_handler.cljs
  7. 2 7
      src/main/frontend/handler.cljs
  8. 2 26
      src/main/frontend/handler/code.cljs
  9. 2 6
      src/main/frontend/handler/config.cljs
  10. 8 89
      src/main/frontend/handler/editor.cljs
  11. 3 18
      src/main/frontend/handler/events.cljs
  12. 0 289
      src/main/frontend/handler/file_based/file.cljs
  13. 0 70
      src/main/frontend/handler/file_based/import.cljs
  14. 0 55
      src/main/frontend/handler/file_based/page.cljs
  15. 0 87
      src/main/frontend/handler/file_based/page_property.cljs
  16. 0 84
      src/main/frontend/handler/file_based/property.cljs
  17. 0 236
      src/main/frontend/handler/file_based/property/util.cljs
  18. 0 138
      src/main/frontend/handler/file_based/repeated.cljs
  19. 0 301
      src/main/frontend/handler/file_based/repo.cljs
  20. 0 71
      src/main/frontend/handler/file_based/status.cljs
  21. 2 8
      src/main/frontend/handler/page.cljs
  22. 15 33
      src/main/frontend/handler/property.cljs
  23. 0 54
      src/main/frontend/handler/property/file.cljs
  24. 0 6
      src/main/frontend/handler/property/util.cljs
  25. 1 16
      src/main/frontend/handler/worker.cljs
  26. 0 77
      src/main/frontend/pubsub.cljc
  27. 2 12
      src/main/frontend/search/browser.cljs
  28. 0 20
      src/main/frontend/util.cljc
  29. 0 42
      src/main/frontend/worker/db_worker.cljs
  30. 20 36
      src/main/frontend/worker/pipeline.cljs
  31. 0 161
      src/test/frontend/components/file_based/query_table_test.cljs
  32. 0 85
      src/test/frontend/extensions/zotero/extractor_test.cljs
  33. 0 40
      src/test/frontend/handler/editor_test.cljs
  34. 0 104
      src/test/frontend/handler/file_based/page_property_test.cljs
  35. 0 76
      src/test/frontend/handler/repo_test.cljs
  36. 70 0
      src/test/frontend/test/file.cljs
  37. 1 1
      src/test/frontend/test/file/reset.cljs
  38. 6 6
      src/test/frontend/test/helper.cljs
  39. 46 0
      src/test/frontend/test/repo.cljs
  40. 0 28
      src/test/frontend/util/marker_test.cljs
  41. 0 130
      src/test/frontend/util/property_test.cljs

+ 0 - 12
src/main/electron/listener.cljs

@@ -7,7 +7,6 @@
             [electron.ipc :as ipc]
             [frontend.db :as db]
             [frontend.db.async :as db-async]
-            [frontend.fs.watcher-handler :as watcher-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.property.util :as pu]
             [frontend.handler.route :as route-handler]
@@ -16,8 +15,6 @@
             [frontend.handler.user :as user]
             [frontend.state :as state]
             [frontend.ui :as ui]
-            [logseq.common.path :as path]
-            [logseq.common.util :as common-util]
             [promesa.core :as p]))
 
 (defn- safe-api-call
@@ -28,15 +25,6 @@
 
 (defn ^:large-vars/cleanup-todo listen-to-electron!
   []
-  ;; TODO: move "file-watcher" to electron.ipc.channels
-  (safe-api-call "file-watcher"
-                 (fn [data]
-                   (let [{:keys [type payload]} (bean/->clj data)
-                         path (common-util/path-normalize (:path payload))
-                         dir (:dir payload)
-                         payload (assoc payload :path (path/relative-path dir path))]
-                     (watcher-handler/handle-changed! type payload))))
-
   (safe-api-call "notification"
                  (fn [data]
                    (let [{:keys [type payload]} (bean/->clj data)

+ 0 - 93
src/main/frontend/components/diff.cljs

@@ -1,93 +0,0 @@
-(ns frontend.components.diff
-  (:require [clojure.string :as string]
-            [frontend.diff :as diff]
-            [frontend.handler.file-based.file :as file-handler]
-            [frontend.ui :as ui]
-            [frontend.util :as util]
-            [logseq.shui.ui :as shui]
-            [medley.core :as medley]
-            [rum.core :as rum]))
-
-(defonce disk-value (atom nil))
-(defonce db-value (atom nil))
-
-(rum/defc diff-cp
-  [diff]
-  [:div
-   (for [[idx {:keys [added removed value]}] diff]
-     (let [bg-color (cond
-                      added "#057a55"
-                      removed "#d61f69"
-                      :else
-                      "initial")]
-       [:span.diff {:key idx
-                    :style {:background-color bg-color}}
-        value]))])
-
-(rum/defcs local-file < rum/reactive
-  {:will-unmount (fn [state]
-                   (reset! disk-value nil)
-                   (reset! db-value nil)
-                   state)}
-  [state repo path disk-content db-content]
-  (when (nil? @disk-value)
-    (reset! disk-value disk-content)
-    (reset! db-value db-content))
-  [:div.cp__diff-file
-   [:div.cp__diff-file-header
-    [:span.cp__diff-file-header-content.pl-1
-     (shui/tabler-icon "info-triangle")
-     [:span (str "File " path "has been modified on the disk.")]]]
-   [:div.p-4
-    (when (not= (string/trim disk-content) (string/trim db-content))
-      (ui/foldable
-       (shui/button {:variant :link :class "!px-0"} "Check diff")
-       (fn []
-         (let [local-content (or db-content "")
-               content (or disk-content "")
-               diff (medley/indexed (diff/diff local-content content))
-               diff? (some (fn [[_idx {:keys [added removed]}]]
-                             (or added removed))
-                           diff)]
-           (when diff?
-             [:div.overflow-y-scroll.flex.flex-col
-              [:div {:style {:max-height "65vh"}}
-               (diff-cp diff)]])))
-       {:default-collapsed? true
-        :title-trigger? true}))
-
-    [:hr]
-
-    [:div.flex.flex-col.mt-4.sm:flex-row
-     [:div.flex-1
-      [:div.mb-2 "On disk:"]
-      [:textarea.overflow-auto
-       {:value (rum/react disk-value)
-        :on-change (fn [e]
-                     (reset! disk-value (util/evalue e)))}
-       disk-content]
-      (ui/button "Select this"
-                 :on-click
-                 (fn []
-                   (when-let [value @disk-value]
-                     (file-handler/alter-file repo path value
-                                      {:re-render-root? true
-                                       :skip-compare? true}))
-                   (shui/dialog-close!)))]
-
-     [:div.flex-1.mt-8.sm:ml-4.sm:mt-0
-      [:div.mb-2 "In Logseq:"]
-      [:textarea.overflow-auto
-       {:value (rum/react db-value)
-        :on-change (fn [e]
-                     (prn "new-value: " (util/evalue e))
-                     (reset! db-value (util/evalue e)))}
-       db-content]
-      (ui/button "Select this"
-                 :on-click
-                 (fn []
-                   (when-let [value @db-value]
-                     (file-handler/alter-file repo path value
-                                      {:re-render-root? true
-                                       :skip-compare? true}))
-                   (shui/dialog-close!)))]]]])

+ 0 - 23
src/main/frontend/components/diff.css

@@ -1,23 +0,0 @@
-.cp__diff-file {
-  @apply mb-3;
-
-  textarea {
-    @apply min-h-[20vh];
-
-    @screen sm {
-      @apply min-h-[40vh];
-    }
-  }
-}
-
-.cp__diff-file-header {
-  @apply px-1 py-2 bg-yellow-rx-04 rounded mt-4 font-medium;
-}
-
-.cp__diff-file-header-content {
-  @apply truncate break-all flex items-center space-x-1 opacity-70;
-}
-
-.cp__diff-file-header-type {
-  @apply text-sm font-medium ml-2 border rounded px-1;
-}

+ 2 - 58
src/main/frontend/components/imports.cljs

@@ -15,7 +15,6 @@
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.handler.db-based.import :as db-import-handler]
-            [frontend.handler.file-based.import :as file-import-handler]
             [frontend.handler.import :as import-handler]
             [frontend.handler.notification :as notification]
             [frontend.handler.repo :as repo-handler]
@@ -55,26 +54,6 @@
     (js/window.location.reload)
     (js/setTimeout ui-handler/re-render-root! 500)))
 
-(defn- roam-import-handler
-  [e]
-  (let [file      (first (array-seq (.-files (.-target e))))
-        file-name (gobj/get file "name")]
-    (if (string/ends-with? file-name ".json")
-      (do
-        (state/set-state! :graph/importing :roam-json)
-        (let [reader (js/FileReader.)]
-          (set! (.-onload reader)
-                (fn [e]
-                  (let [text (.. e -target -result)]
-                    (file-import-handler/import-from-roam-json!
-                     text
-                     #(do
-                        (state/set-state! :graph/importing nil)
-                        (finished-cb))))))
-          (.readAsText reader file)))
-      (notification/show! "Please choose a JSON file."
-                          :error))))
-
 (defn- lsq-import-handler
   [e & {:keys [sqlite? debug-transit? graph-name db-edn?]}]
   (let [file      (first (array-seq (.-files (.-target e))))
@@ -489,8 +468,7 @@
 
 (rum/defc ^:large-vars/cleanup-todo importer < rum/reactive
   [{:keys [query-params]}]
-  (let [support-file-based? (config/local-file-based-graph? (state/get-current-repo))
-        importing? (state/sub :graph/importing)]
+  (let [importing? (state/sub :graph/importing)]
     [:<>
      (import-indicator importing?)
      (when-not importing?
@@ -552,41 +530,7 @@
              :type "file"
              :on-change (fn [e]
                           (shui/dialog-open!
-                           #(set-graph-name-dialog e {:db-edn? true})))}]]
-
-          (when (and (util/electron?) support-file-based?)
-            [:label.action-input.flex.items-center.mx-2.my-2
-             [:span.as-flex-center [:i (svg/logo 28)]]
-             [:span.flex.flex-col
-              [[:strong "EDN / JSON to plain text graph"]
-               [:small (t :on-boarding/importing-lsq-desc)]]]
-             [:input.absolute.hidden
-              {:id "import-lsq"
-               :type "file"
-               :on-change lsq-import-handler}]])
-
-          (when (and (util/electron?) support-file-based?)
-            [:label.action-input.flex.items-center.mx-2.my-2
-             [:span.as-flex-center [:i (svg/roam-research 28)]]
-             [:div.flex.flex-col
-              [[:strong "RoamResearch"]
-               [:small (t :on-boarding/importing-roam-desc)]]]
-             [:input.absolute.hidden
-              {:id "import-roam"
-               :type "file"
-               :on-change roam-import-handler}]])
-
-          (when (and (util/electron?) support-file-based?)
-            [:label.action-input.flex.items-center.mx-2.my-2
-             [:span.as-flex-center.ml-1 (ui/icon "sitemap" {:size 26})]
-             [:span.flex.flex-col
-              [[:strong "OPML"]
-               [:small (t :on-boarding/importing-opml-desc)]]]
-
-             [:input.absolute.hidden
-              {:id "import-opml"
-               :type "file"
-               :on-change opml-import-handler}]])]
+                           #(set-graph-name-dialog e {:db-edn? true})))}]]]
 
          (when (= "picker" (:from query-params))
            [:section.e

+ 1 - 6
src/main/frontend/db/async.cljs

@@ -13,7 +13,6 @@
             [frontend.db.model :as db-model]
             [frontend.db.react :as react]
             [frontend.db.utils :as db-utils]
-            [frontend.handler.file-based.property.util :as property-util]
             [frontend.state :as state]
             [frontend.util :as util]
             [logseq.common.util :as common-util]
@@ -61,11 +60,7 @@
   :block/title"
   [& {:as opts}]
   (when-let [graph (state/get-current-repo)]
-    (if (config/db-based-graph? graph)
-      (db-model/get-all-properties graph opts)
-      (p/let [properties (file-async/<file-based-get-all-properties graph)
-              hidden-properties (set (map name (property-util/hidden-properties)))]
-        (remove #(hidden-properties (:block/title %)) properties)))))
+    (db-model/get-all-properties graph opts)))
 
 (defn <file-get-property-values
   "For file graphs, returns property value names for given property name"

+ 0 - 206
src/main/frontend/fs/watcher_handler.cljs

@@ -1,206 +0,0 @@
-(ns frontend.fs.watcher-handler
-  "Main ns that handles file watching events from electron's main process"
-  (:require [clojure.set :as set]
-            [clojure.string :as string]
-            [frontend.config :as config]
-            [frontend.db :as db]
-            [frontend.db.async :as db-async]
-            [frontend.db.file-based.model :as file-model]
-            [frontend.db.model :as model]
-            [frontend.fs :as fs]
-            [frontend.handler.file-based.file :as file-handler]
-            [frontend.handler.file-based.property :as file-property-handler]
-            [frontend.handler.global-config :as global-config-handler]
-            [frontend.handler.notification :as notification]
-            [frontend.handler.page :as page-handler]
-            [frontend.handler.ui :as ui-handler]
-            [frontend.state :as state]
-            [frontend.util.fs :as fs-util]
-            [lambdaisland.glogi :as log]
-            [logseq.common.config :as common-config]
-            [logseq.common.path :as path]
-            [logseq.common.util.block-ref :as block-ref]
-            [promesa.core :as p]))
-
-;; all IPC paths must be normalized! (via common-util/path-normalize)
-
-(defn- set-missing-block-ids!
-  "For every referred block in the content, fix their block ids in files if missing."
-  [content]
-  (when (string? content)
-    (let [missing-blocks (->> (block-ref/get-all-block-ref-ids content)
-                              (distinct)
-                              (keep model/get-block-by-uuid)
-                              (filter (fn [block]
-                                        (not= (str (:id (:block/properties block)))
-                                              (str (:block/uuid block))))))]
-      (when (seq missing-blocks)
-        (file-property-handler/batch-set-block-property-aux!
-         (mapv
-          (fn [b] [(:block/uuid b) :id (str (:block/uuid b))])
-          missing-blocks))))))
-
-(defn- handle-add-and-change!
-  [repo path content db-content ctime mtime backup?]
-  (let [config (state/get-config repo)
-        path-hidden-patterns (:hidden config)]
-    (when-not (or (and (seq path-hidden-patterns)
-                       (common-config/hidden? path path-hidden-patterns))
-                  ;; File not changed
-                  (= content db-content))
-      (p/let [;; save the previous content in a versioned bak file to avoid data overwritten.
-              _ (when backup?
-                  (-> (when-let [repo-dir (config/get-local-dir repo)]
-                        (file-handler/backup-file! repo-dir path db-content content))
-                      (p/catch #(js/console.error "❌ Bak Error: " path %))))
-
-              _ (file-handler/alter-file repo path content {:re-render-root? true
-                                                            :from-disk? true
-                                                            :fs/event :fs/local-file-change
-                                                            :ctime ctime
-                                                            :mtime mtime})]
-        (set-missing-block-ids! content)))))
-
-(defn handle-changed!
-  [type {:keys [dir path content stat global-dir] :as payload}]
-  (let [repo (state/get-current-repo)]
-    (when dir
-      (let [;; Global directory events don't know their originating repo so we rely
-          ;; on the client to correctly identify it
-            repo (cond
-                   global-dir repo
-                   :else (config/get-local-repo dir))
-            repo-dir (config/get-local-dir repo)
-            {:keys [mtime ctime]} stat
-            ext (keyword (path/file-ext path))]
-        (when (contains? #{:org :md :markdown :css :js :edn} ext)
-          (p/let [db-content (db-async/<get-file repo path)
-                  exists-in-db? (not (nil? db-content))
-                  db-content (or db-content "")]
-            (when (or content (contains? #{"unlink" "unlinkDir" "addDir"} type))
-              (cond
-                (and (= "unlinkDir" type) dir)
-                (state/pub-event! [:graph/dir-gone dir])
-
-                (and (= "addDir" type) dir)
-                (state/pub-event! [:graph/dir-back repo dir])
-
-                (contains? (:file/unlinked-dirs @state/state) dir)
-                nil
-
-                (and (= "add" type)
-                     (not= (string/trim content) (string/trim db-content)))
-                (let [backup? (not (string/blank? db-content))]
-                  (handle-add-and-change! repo path content db-content ctime mtime backup?))
-
-                (and (= "change" type)
-                     (= dir repo-dir)
-                     (not (common-config/local-relative-asset? path)))
-                (handle-add-and-change! repo path content db-content ctime mtime (not global-dir)) ;; no backup for global dir
-
-                (and (= "unlink" type)
-                     exists-in-db?)
-                (p/let [dir-exists? (fs/file-exists? dir "")]
-                  (when dir-exists?
-                    (when-let [page-name (file-model/get-file-page path)]
-                      (println "Delete page: " page-name ", file path: " path ".")
-                      (page-handler/<delete! page-name #()))))
-
-          ;; global config handling
-                (and (= "change" type)
-                     (= dir (global-config-handler/global-config-dir)))
-                (when (= path "config.edn")
-                  (file-handler/alter-global-file
-                   (global-config-handler/global-config-path) content {:from-disk? true}))
-
-                (and (= "change" type)
-                     (not exists-in-db?))
-                (js/console.error "Can't get file in the db: " path)
-
-                (and (contains? #{"add" "change" "unlink"} type)
-                     (string/ends-with? path "logseq/custom.css"))
-                (do
-                  (println "reloading custom.css")
-                  (ui-handler/add-style-if-exists!))
-
-                (contains? #{"add" "change" "unlink"} type)
-                nil
-
-                :else
-                (log/error :fs/watcher-no-handler {:type type
-                                                   :payload payload})))))
-
-      ;; return nil, otherwise the entire db will be transferred by ipc
-        nil))))
-
-(defn load-graph-files!
-  "This fn replaces the former initial fs watcher"
-  [graph]
-  (when graph
-    (let [repo-dir (config/get-repo-dir graph)]
-      ;; read all files in the repo dir, notify if readdir error
-      (p/let [db-files' (db-async/<get-files graph)
-              db-files (map first db-files')
-              [files deleted-files]
-              (-> (fs/readdir repo-dir :path-only? true)
-                  (p/chain (fn [files]
-                             (->> files
-                                  (map #(path/relative-path repo-dir %))
-                                  (remove #(fs-util/ignored-path? repo-dir %))
-                                  (sort-by (fn [f] [(not (string/starts-with? f "logseq/"))
-                                                    (not (string/starts-with? f "journals/"))
-                                                    (not (string/starts-with? f "pages/"))
-                                                    (string/lower-case f)]))))
-                           (fn [files]
-                             (let [deleted-files (set/difference (set db-files) (set files))]
-                               [files
-                                deleted-files])))
-                  (p/catch (fn [error]
-                             (when-not (config/demo-graph? graph)
-                               (js/console.error "reading" graph)
-                               (state/pub-event! [:notification/show
-                                                  {:content (str "The graph " graph " can not be read:" error)
-                                                   :status :error
-                                                   :clear? false}]))
-                             [nil nil])))
-              ;; notifies user when large initial change set is detected
-              ;; NOTE: this is an estimation, not accurate
-              notification-uid (when (or (> (abs (- (count db-files) (count files)))
-                                            100)
-                                         (> (count deleted-files)
-                                            100))
-                                 (prn ::init-watcher-large-change-set)
-                                 (notification/show! "Loading changes from disk..."
-                                                     :info
-                                                     false))]
-        (prn ::initial-watcher repo-dir {:deleted (count deleted-files)
-                                         :total (count files)})
-        (p/do!
-         (when (seq deleted-files)
-           (p/all (map (fn [path]
-                         (when-let [page-name (file-model/get-file-page path)]
-                           (println "Delete page: " page-name ", file path: " path ".")
-                           (page-handler/<delete! page-name #())))
-                       deleted-files)))
-         (-> (p/delay 500) ;; workaround for notification ui not showing
-             (p/then #(p/all (map (fn [file-rpath]
-                                    (p/let [stat (fs/stat repo-dir file-rpath)
-                                            content (fs/read-file repo-dir file-rpath)
-                                            type (if (db/file-exists? graph file-rpath)
-                                                   "change"
-                                                   "add")]
-                                      (handle-changed! type
-                                                       {:dir repo-dir
-                                                        :path file-rpath
-                                                        :content content
-                                                        :stat stat})))
-                                  files)))
-             (p/then (fn []
-                       (when notification-uid
-                         (prn ::init-notify)
-                         (notification/clear! notification-uid)
-                         (state/pub-event! [:notification/show {:content (str "The graph " graph " is loaded.")
-                                                                :status :success
-                                                                :clear? true}]))))
-             (p/catch (fn [error]
-                        (js/console.dir error)))))))))

+ 2 - 7
src/main/frontend/handler.cljs

@@ -21,7 +21,6 @@
             [frontend.handler.events :as events]
             [frontend.handler.events.rtc]
             [frontend.handler.events.ui]
-            [frontend.handler.file-based.file :as file-handler]
             [frontend.handler.global-config :as global-config-handler]
             [frontend.handler.page :as page-handler]
             [frontend.handler.plugin :as plugin-handler]
@@ -91,9 +90,7 @@
 
            (page-handler/init-commands!)
 
-           (watch-for-date!)
-           (when (and (not (config/db-based-graph? repo)) (util/electron?))
-             (file-handler/watch-for-current-graph-dir!))))
+           (watch-for-date!)))
         (p/catch (fn [error]
                    (log/error :exception error))))))
 
@@ -190,9 +187,7 @@
                             (p/do! (db-browser/start-inference-worker!)
                                    (db-browser/<connect-db-worker-and-infer-worker!)
                                    (reset! vector-search-flows/*infer-worker-ready true))))
-                        nil))))
-
-     (util/<app-wake-up-from-sleep-loop (atom false)))))
+                        nil)))))))
 
 (defn stop! []
   (prn "stop!"))

+ 2 - 26
src/main/frontend/handler/code.cljs

@@ -3,13 +3,11 @@
   (:require [clojure.string :as string]
             [frontend.config :as config]
             [frontend.db :as db]
+            [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.file-based.file :as file-handler]
             [frontend.state :as state]
             [goog.object :as gobj]
-            [logseq.graph-parser.utf8 :as utf8]
-            [logseq.common.path :as path]
-            [frontend.handler.db-based.editor :as db-editor-handler]))
+            [logseq.graph-parser.utf8 :as utf8]))
 
 (defn save-code-editor!
   []
@@ -49,27 +47,5 @@
                  (config/db-based-graph? repo))
             (db-editor-handler/save-file! (:file-path config) value)
 
-            (and (not-empty (:file-path config))
-                 (not (config/db-based-graph? repo)))
-            (let [path (:file-path config)
-                  repo-dir (config/get-repo-dir repo)
-                  rpath (when (string/starts-with? path repo-dir)
-                          (path/trim-dir-prefix repo-dir path))]
-              (if rpath
-                ;; in-db file
-                (let [db-content (db/get-file rpath)
-                      not-in-db? (nil? db-content)
-                      old-content (or db-content "")
-                      contents-matched? (= (string/trim value) (string/trim old-content))]
-                  (when (or
-                         (and not-in-db? (not-empty value))
-                         (not contents-matched?))
-                    (file-handler/alter-file (state/get-current-repo)
-                                             rpath
-                                             (str (string/trim value) "\n")
-                                             {:re-render-root? true})))
-                ;; global file
-                (file-handler/alter-global-file path (str (string/trim value) "\n") {})))
-
             :else
             nil))))))

+ 2 - 6
src/main/frontend/handler/config.cljs

@@ -2,10 +2,8 @@
   "Fns for setting repo config"
   (:require [borkdude.rewrite-edn :as rewrite]
             [clojure.string :as string]
-            [frontend.config :as config]
             [frontend.db :as db]
             [frontend.handler.db-based.editor :as db-editor-handler]
-            [frontend.handler.file-based.file :as file-handler]
             [frontend.handler.repo-config :as repo-config-handler]
             [frontend.state :as state]))
 
@@ -16,7 +14,7 @@
 
 (defn- repo-config-set-key-value
   [path k v]
-  (when-let [repo (state/get-current-repo)]
+  (when (state/get-current-repo)
     (when-let [content (db/get-file path)]
       (repo-config-handler/read-repo-config content)
       (let [result (parse-repo-config (if (string/blank? content) "{}" content))
@@ -26,9 +24,7 @@
                 (reduce-kv (fn [a k v] (rewrite/assoc a k v)) (rewrite/parse-string "{}")))
             new-result (rewrite/assoc-in result ks v)
             new-content (str new-result)]
-        (if (config/db-based-graph? repo)
-          (db-editor-handler/save-file! path new-content)
-          (file-handler/set-file-content! repo path new-content)) nil))))
+        (db-editor-handler/save-file! path new-content) nil))))
 
 (defn set-config!
   [k v]

+ 8 - 89
src/main/frontend/handler/editor.cljs

@@ -25,10 +25,8 @@
             [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.handler.export.html :as export-html]
             [frontend.handler.export.text :as export-text]
-            [frontend.handler.file-based.status :as status]
             [frontend.handler.notification :as notification]
             [frontend.handler.property :as property-handler]
-            [frontend.handler.property.file :as property-file]
             [frontend.handler.property.util :as pu]
             [frontend.handler.route :as route-handler]
             [frontend.handler.user :as user-handler]
@@ -577,9 +575,6 @@
                       (get block :block/format :markdown)
                       (db/get-page-format (:block/name block))
                       (state/get-preferred-format))
-              content (if (and (not db-based?) (seq properties))
-                        (property-file/insert-properties-when-file-based repo format content properties)
-                        content)
               new-block (cond->
                          (-> (select-keys block [:block/page])
                              (assoc :block/title content))
@@ -647,20 +642,6 @@
   []
   (distinct (seq (state/get-selection-blocks))))
 
-(defn set-marker
-  "The set-marker will set a new marker on the selected block.
-  if the `new-marker` is nil, it will generate it automatically."
-  ([block]
-   (set-marker block nil))
-  ([{:block/keys [marker title format] :as block} new-marker]
-   (let [[new-content _] (status/cycle-marker title marker new-marker format (state/get-preferred-workflow))]
-     (save-block-if-changed! block new-content))))
-
-(defn file-based-cycle-todo!
-  [block]
-  (when (not-empty (:block/title block))
-    (set-marker block)))
-
 (defn db-based-cycle-todo!
   [block]
   (let [status-value (if (ldb/class-instance? (db/entity :logseq.class/Task) block)
@@ -682,17 +663,14 @@
 (defn cycle-todos!
   []
   (when-let [blocks (seq (get-selected-blocks))]
-    (let [db-based? (config/db-based-graph? (state/get-current-repo))
-          ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
+    (let [ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
                                      (uuid id)) blocks))
                    (remove nil?))]
       (ui-outliner-tx/transact!
        {:outliner-op :cycle-todos}
        (doseq [id ids]
          (when-let [block (db/entity [:block/uuid id])]
-           (if db-based?
-             (db-based-cycle-todo! block)
-             (file-based-cycle-todo! block))))))))
+           (db-based-cycle-todo! block)))))))
 
 (defn cycle-todo!
   []
@@ -1349,15 +1327,13 @@
 (defn save-block!
   ([repo block-or-uuid content]
    (save-block! repo block-or-uuid content {}))
-  ([repo block-or-uuid content {:keys [properties] :as opts}]
+  ([repo block-or-uuid content opts]
    (let [block (if (or (uuid? block-or-uuid)
                        (string? block-or-uuid))
                  (db-model/query-block-by-uuid block-or-uuid) block-or-uuid)]
      (save-block!
-      {:block block :repo repo :opts (dissoc opts :properties)}
-      (if (seq properties)
-        (property-file/insert-properties-when-file-based repo (get block :block/format :markdown) content properties)
-        content))))
+      {:block block :repo repo :opts opts}
+      content)))
   ([{:keys [block repo opts] :as _state} value]
    (let [repo (or repo (state/get-current-repo))]
      (when (db/entity repo [:block/uuid (:block/uuid block)])
@@ -2000,11 +1976,7 @@
         new-content
         (if content-update-fn
           (content-update-fn (:block/title block))
-          (:block/title block))
-        new-content
-        (cond->> new-content
-          (not keep-uuid?) (property-file/remove-property-when-file-based repo format "id")
-          true             (property-file/remove-property-when-file-based repo format "custom_id"))]
+          (:block/title block))]
     (merge (apply dissoc block (conj (if-not keep-uuid? [:block/_refs] []) :block/pre-block? :block/meta))
            (cond->
             {:block/page {:db/id (:db/id page)}
@@ -2113,9 +2085,7 @@
   (->> (outliner-core/tree-vec-flatten tree-vec)
        (map (fn [block]
               (let [content (:content block)
-                    props (into [] (:properties block))
-                    content* (str (if (= :markdown format) "- " "* ")
-                                  (property-file/insert-properties-when-file-based repo format content props))
+                    content* (str (if (= :markdown format) "- " "* ") content)
                     ast (mldoc/->edn content* format)
                     blocks (->> (block/extract-blocks ast content* format {:page-name page-name})
                                 (map wrap-parse-block))
@@ -2195,8 +2165,6 @@
            (let [exclude-properties [:id :template :template-including-parent]
                  content-update-fn (fn [content]
                                      (->> content
-                                          (property-file/remove-property-when-file-based repo format "template")
-                                          (property-file/remove-property-when-file-based repo format "template-including-parent")
                                           template/resolve-dynamic-template!))
                  page (if (:block/name block) block
                           (when target (:block/page (db/entity (:db/id target)))))
@@ -2318,54 +2286,6 @@
 
 (declare delete-and-update)
 
-(defn- dwim-in-properties
-  [state]
-  (when-not (auto-complete?)
-    (let [{:keys [block]} (get-state)]
-      (when block
-        (let [input (state/get-input)
-              content (gobj/get input "value")
-              format (get (:block (get-state)) :block/format :markdown)
-              property-key (:raw-content (thingatpt/property-key-at-point input))
-              org? (= format :org)
-              move-to-pos (if org? 2 3)]
-          (if org?
-            (cond
-              (and property-key (not= property-key ""))
-              (case property-key
-                ;; When cursor in "PROPERTIES", add :|: in a new line and move cursor to |
-                "PROPERTIES"
-                (do (cursor/move-cursor-to-line-end input)
-                    (insert "\n:: ")
-                    (cursor/move-cursor-backward input move-to-pos))
-                ;; When cursor in "END", new block (respect the previous enter behavior)
-                "END"
-                (do
-                  (cursor/move-cursor-to-end input)
-                  (save-current-block!)
-                  (insert-new-block! state))
-                ;; cursor in other positions of :ke|y: or ke|y::, move to line end for inserting value.
-                (if (property-file/property-key-exist?-when-file-based format content property-key)
-                  (notification/show!
-                   (util/format "Property key \"%s\" already exists!" property-key)
-                   :error)
-                  (cursor/move-cursor-to-line-end input)))
-
-              ;; when cursor in empty property key
-              (and property-key (= property-key ""))
-              (do (delete-and-update
-                   input
-                   (cursor/line-beginning-pos input)
-                   (inc (cursor/line-end-pos input)))
-                  (property-file/goto-properties-end-when-file-based format input)
-                  (cursor/move-cursor-to-line-end input))
-              :else
-              ;;When cursor in other place of PROPERTIES drawer, add :|: in a new line and move cursor to |
-              (do
-                (insert "\n:: ")
-                (cursor/move-cursor-backward input move-to-pos)))
-            (insert "\n")))))))
-
 (defn toggle-list-checkbox
   [{:block/keys [title] :as block} item-content]
   (let [toggle-fn (fn [m x-mark]
@@ -2465,8 +2385,7 @@
                              (p/do!
                               (save-current-block!)
                               (route-handler/redirect-to-page! page-name))))
-              "list-item" (dwim-in-list)
-              "properties-drawer" (dwim-in-properties state))
+              "list-item" (dwim-in-list))
 
             (and (string/blank? content)
                  (own-order-number-list? block)

+ 3 - 18
src/main/frontend/handler/events.cljs

@@ -17,7 +17,6 @@
             [frontend.db.react :as react]
             [frontend.extensions.fsrs :as fsrs]
             [frontend.fs :as fs]
-            [frontend.fs.watcher-handler :as fs-watcher]
             [frontend.handler.assets :as assets-handler]
             [frontend.handler.code :as code-handler]
             [frontend.handler.common.page :as page-common-handler]
@@ -98,16 +97,7 @@
          (persist-db/export-current-graph!)
          (state/set-state! :db/async-queries {})
          (st/refresh!)
-         (if (config/db-based-graph?)
-           (graph-switch-on-persisted graph opts)
-           (p/let [writes-finished? (state/<invoke-db-worker :thread-api/file-writes-finished? (state/get-current-repo))]
-             (if (not writes-finished?) ; TODO: test (:sync-graph/init? @state/state)
-               (do
-                 (log/info :graph/switch {:file-writes-finished? writes-finished?})
-                 (notification/show!
-                  "Please wait seconds until all changes are saved for the current graph."
-                  :warning))
-               (graph-switch-on-persisted graph opts)))))]
+         (graph-switch-on-persisted graph opts))]
     (p/then switch-promise
             (fn [_]
               (export/backup-db-graph (state/get-current-repo))))))
@@ -161,13 +151,8 @@
       (when (and (not dir-exists?)
                  (not util/nfs?))
         (state/pub-event! [:graph/dir-gone dir]))))
-  (let [db-based? (config/db-based-graph? repo)]
-    ;; FIXME: an ugly implementation for redirecting to page on new window is restored
-    (repo-handler/graph-ready! repo)
-
-    (when-not config/publishing?
-      (when-not db-based?
-        (fs-watcher/load-graph-files! repo)))))
+  ;; FIXME: an ugly implementation for redirecting to page on new window is restored
+  (repo-handler/graph-ready! repo))
 
 (defmethod handle :instrument [[_ {:keys [type payload] :as opts}]]
   (when-not (empty? (dissoc opts :type :payload))

+ 0 - 289
src/main/frontend/handler/file_based/file.cljs

@@ -1,289 +0,0 @@
-(ns frontend.handler.file-based.file
-  "Provides util handler fns for file graph files"
-  (:refer-clojure :exclude [load-file])
-  (:require [electron.ipc :as ipc]
-            [frontend.config :as config]
-            [frontend.db :as db]
-            [frontend.db.file-based.model :as file-model]
-            [frontend.fs :as fs]
-            [frontend.handler.common.config-edn :as config-edn-common-handler]
-            [frontend.handler.global-config :as global-config-handler]
-            [frontend.handler.repo-config :as repo-config-handler]
-            [frontend.handler.ui :as ui-handler]
-            [frontend.schema.handler.global-config :as global-config-schema]
-            [frontend.schema.handler.repo-config :as repo-config-schema]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [frontend.worker.file.reset :as file-reset]
-            [lambdaisland.glogi :as log]
-            [logseq.common.config :as common-config]
-            [logseq.common.path :as path]
-            [logseq.common.util :as common-util]
-            [promesa.core :as p]))
-
-;; TODO: extract all git ops using a channel
-
-(defn load-file
-  [repo-url path]
-  (->
-   (p/let [content (fs/read-file (config/get-repo-dir repo-url) path)]
-     content)
-   (p/catch
-    (fn [e]
-      (println "Load file failed: " path)
-      (js/console.error e)))))
-
-(defn reset-file!
-  [repo file-path content opts]
-  (if util/node-test?
-    (file-reset/reset-file! repo (db/get-db repo false) file-path content opts)
-    (state/<invoke-db-worker :thread-api/reset-file repo file-path content opts)))
-
-(defn- load-multiple-files
-  [repo-url paths]
-  (doall
-   (mapv #(load-file repo-url %) paths)))
-
-(defn- keep-formats
-  [files formats]
-  (filter
-   (fn [file]
-     (let [format (common-util/get-format file)]
-       (contains? formats format)))
-   files))
-
-(defn- only-text-formats
-  [files]
-  (keep-formats files (common-config/text-formats)))
-
-(defn- only-image-formats
-  [files]
-  (keep-formats files (common-config/img-formats)))
-
-(defn load-files-contents!
-  [repo-url files ok-handler]
-  (let [images (only-image-formats files)
-        files (only-text-formats files)]
-    (-> (p/all (load-multiple-files repo-url files))
-        (p/then (fn [contents]
-                  (let [file-contents (cond->
-                                       (zipmap files contents)
-
-                                        (seq images)
-                                        (merge (zipmap images (repeat (count images) ""))))
-                        file-contents (for [[file content] file-contents]
-                                        {:file/path (common-util/path-normalize file)
-                                         :file/content content})]
-                    (ok-handler file-contents))))
-        (p/catch (fn [error]
-                   (log/error :fs/load-files-error repo-url)
-                   (log/error :exception error))))))
-
-(defn backup-file!
-  "Backup db content to bak directory"
-  [repo-url path db-content content]
-  (when (util/electron?)
-    (ipc/ipc "backupDbFile" repo-url path db-content content)))
-
-(defn- detect-deprecations
-  [path content]
-  (when (or (= path "logseq/config.edn")
-            (= (path/dirname path) (global-config-handler/safe-global-config-dir)))
-    (config-edn-common-handler/detect-deprecations path content {:db-graph? false})))
-
-(defn- validate-file
-  "Returns true if valid and if false validator displays error message. Files
-  that are not validated just return true"
-  [path content]
-  (cond
-    (= path "logseq/config.edn")
-    (config-edn-common-handler/validate-config-edn path content repo-config-schema/Config-edn)
-
-    (= (path/dirname path) (global-config-handler/safe-global-config-dir))
-    (config-edn-common-handler/validate-config-edn path content global-config-schema/Config-edn)
-
-    :else
-    true))
-
-(defn- write-file-aux!
-  [repo path content write-file-options]
-  (let [original-content (db/get-file repo path)
-        path-dir (config/get-repo-dir repo)
-        write-file-options' (merge write-file-options
-                                   (when original-content {:old-content original-content}))]
-    (fs/write-plain-text-file! repo path-dir path content write-file-options')))
-
-(defn alter-global-file
-  "Does pre-checks on a global file, writes if it's not already written
-  (:from-disk? is not set) and then does post-checks. Currently only handles
-  global config.edn but can be extended as needed"
-  [path content {:keys [from-disk?]}]
-  (if (and path (= path (global-config-handler/safe-global-config-path)))
-    (do
-      (detect-deprecations path content)
-      (when (validate-file path content)
-        (-> (p/let [_ (when-not from-disk?
-                        (fs/write-plain-text-file! "" nil path content {:skip-compare? true}))]
-              (p/do! (global-config-handler/restore-global-config!)
-                     (state/pub-event! [:shortcut/refresh])))
-            (p/catch (fn [error]
-                       (state/pub-event! [:notification/show
-                                          {:content (str "Failed to write to file " path ", error: " error)
-                                           :status :error}])
-                       (log/error :write/failed error)
-                       (state/pub-event! [:capture-error
-                                          {:error error
-                                           :payload {:type :write-file/failed-for-alter-file}}]))))))
-    (log/error :msg "alter-global-file does not support this file" :file path)))
-
-(defn alter-file
-  "Write any in-DB file, e.g. repo config, page, whiteboard, etc."
-  [repo path content {:keys [reset? re-render-root? from-disk? skip-compare? new-graph? verbose
-                             ctime mtime]
-                      :fs/keys [event]
-                      :or {reset? true
-                           re-render-root? false
-                           from-disk? false
-                           skip-compare? false}}]
-  (let [path (common-util/path-normalize path)
-        config-file? (= path "logseq/config.edn")
-        _ (when config-file?
-            (detect-deprecations path content))
-        config-valid? (and config-file? (validate-file path content))]
-    (when (or config-valid? (not config-file?)) ; non-config file or valid config
-      (let [opts {:new-graph? new-graph?
-                  :from-disk? from-disk?
-                  :fs/event event
-                  :ctime ctime
-                  :mtime mtime}]
-        (-> (p/let [result (if reset?
-                             (p/do!
-                              (when-let [page-id (file-model/get-file-page-id path)]
-                                (db/transact! repo
-                                              [[:db/retract page-id :block/alias]
-                                               [:db/retract page-id :block/tags]]
-                                              opts))
-                              (reset-file!
-                               repo path content (merge opts
-                                                         ;; To avoid skipping the `:or` bounds for keyword destructuring
-                                                        (when (some? verbose) {:verbose verbose}))))
-                             (db/set-file-content! repo path content opts))
-                    _ (when-not from-disk?
-                        (write-file-aux! repo path content {:skip-compare? skip-compare?}))]
-              (when re-render-root? (ui-handler/re-render-root!))
-
-              (cond
-                (= path "logseq/custom.css")
-                (do
-                  ;; ui-handler will load css from db and config
-                  (db/set-file-content! repo path content)
-                  (ui-handler/add-style-if-exists!))
-
-                (= path "logseq/config.edn")
-                (p/let [_ (repo-config-handler/restore-repo-config! repo content)]
-                  (state/pub-event! [:shortcut/refresh])))
-
-              result)
-            (p/catch
-             (fn [error]
-               (println "Write file failed, path: " path ", content: " content)
-               (log/error :write/failed error)
-               (state/pub-event! [:capture-error
-                                  {:error error
-                                   :payload {:type :write-file/failed-for-alter-file}}]))))))))
-
-(defn alter-file-test-version
-  "Test version of alter-file that is synchronous"
-  [repo path content {:keys [reset? from-disk? new-graph? verbose
-                             ctime mtime]
-                      :fs/keys [event]
-                      :or {reset? true
-                           from-disk? false}}]
-  (let [path (common-util/path-normalize path)
-        config-file? (= path "logseq/config.edn")
-        _ (when config-file?
-            (detect-deprecations path content))
-        config-valid? (and config-file? (validate-file path content))]
-    (when (or config-valid? (not config-file?)) ; non-config file or valid config
-      (let [opts {:new-graph? new-graph?
-                  :from-disk? from-disk?
-                  :fs/event event
-                  :ctime ctime
-                  :mtime mtime}
-            result (if reset?
-                     (do
-                       (when-let [page-id (file-model/get-file-page-id path)]
-                         (db/transact! repo
-                                       [[:db/retract page-id :block/alias]
-                                        [:db/retract page-id :block/tags]]
-                                       opts))
-                       (reset-file!
-                        repo path content (merge opts
-                                                         ;; To avoid skipping the `:or` bounds for keyword destructuring
-                                                 (when (some? verbose) {:verbose verbose}))))
-                     (db/set-file-content! repo path content opts))]
-        result))))
-
-(defn set-file-content!
-  [repo path new-content]
-  (alter-file repo path new-content {:reset? false
-                                     :re-render-root? false}))
-
-(defn- alter-files-handler!
-  [repo files {:keys [finish-handler]} file->content]
-  (let [write-file-f (fn [[path content]]
-                       (when path
-                         (let [path (common-util/path-normalize path)
-                               original-content (get file->content path)]
-                           (-> (fs/write-plain-text-file! repo (config/get-repo-dir repo) path content
-                                                          {:old-content original-content})
-                               (p/catch (fn [error]
-                                          (state/pub-event! [:notification/show
-                                                             {:content (str "Failed to save the file " path ". Error: "
-                                                                            (str error))
-                                                              :status :error
-                                                              :clear? false}])
-                                          (state/pub-event! [:capture-error
-                                                             {:error error
-                                                              :payload {:type :write-file/failed}}])
-                                          (log/error :write-file/failed {:path path
-                                                                         :content content
-                                                                         :error error})))))))
-        finish-handler (fn []
-                         (when finish-handler
-                           (finish-handler)))]
-    (-> (p/all (map write-file-f files))
-        (p/then (fn []
-                  (finish-handler)))
-        (p/catch (fn [error]
-                   (println "Alter files failed:")
-                   (js/console.error error))))))
-
-(defn alter-files
-  [repo files {:keys [reset? update-db?]
-               :or {reset? false
-                    update-db? true}
-               :as opts}]
-  ;; old file content
-  (let [file->content (let [paths (map first files)]
-                        (zipmap paths
-                                (map (fn [path] (db/get-file repo path)) paths)))]
-    ;; update db
-    (when update-db?
-      (p/all
-       (map
-        (fn [[path content]]
-          (if reset?
-            (reset-file! repo path content {})
-            (db/set-file-content! repo path content)))
-        files)))
-    (alter-files-handler! repo files opts file->content)))
-
-(defn watch-for-current-graph-dir!
-  []
-  (when-let [repo (state/get-current-repo)]
-    (when-let [dir (config/get-repo-dir repo)]
-      ;; An unwatch shouldn't be needed on startup. However not having this
-      ;; after an app refresh can cause stale page data to load
-      (fs/unwatch-dir! dir)
-      (fs/watch-dir! dir))))

+ 0 - 70
src/main/frontend/handler/file_based/import.cljs

@@ -1,70 +0,0 @@
-(ns frontend.handler.file-based.import
-  "Handles file-graph specific imports"
-  (:require [clojure.string :as string]
-            [frontend.config :as config]
-            [frontend.db :as db]
-            [frontend.date :as date]
-            [frontend.external :as external]
-            [frontend.handler.file-based.file :as file-handler]
-            [frontend.handler.file-based.repo :as file-repo-handler]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [logseq.common.util :as common-util]
-            [logseq.common.util.date-time :as date-time-util]))
-
-
-(defn index-files!
-  "Create file structure, then parse into DB (client only)"
-  [repo files finish-handler]
-  (let [titles (->> files
-                    (map :title)
-                    (remove nil?))
-        files (map (fn [file]
-                     (let [title (:title file)
-                           journal? (date/valid-journal-title? title)]
-                       (when-let [text (:text file)]
-                         (let [title (or
-                                      (when journal?
-                                        (date/journal-title->default title))
-                                      (string/replace title "/" "-"))
-                               title (-> (common-util/page-name-sanity title)
-                                         (string/replace "\n" " "))
-                               path (str (if journal?
-                                           (config/get-journals-directory)
-                                           (config/get-pages-directory))
-                                         "/"
-                                         title
-                                         ".md")]
-                           {:file/path path
-                            :file/content text}))))
-                   files)
-        files (remove nil? files)]
-    (file-repo-handler/parse-files-and-load-to-db! repo files nil)
-    (let [files (->> (map (fn [{:file/keys [path content]}] (when path [path content])) files)
-                     (remove nil?))]
-      (file-handler/alter-files repo files {:add-history? false
-                                            :update-db? false
-                                            :update-status? false
-                                            :finish-handler finish-handler}))
-    (let [journal-pages-tx (let [titles (filter date/normalize-journal-title titles)]
-                             (map
-                              (fn [title]
-                                (let [day (date/journal-title->int title)
-                                      journal-title (date-time-util/int->journal-title day (state/get-date-formatter))]
-                                  (when journal-title
-                                    (let [page-name (util/page-name-sanity-lc journal-title)]
-                                      {:block/name page-name
-                                       :block/type "journal"
-                                       :block/journal-day day}))))
-                              titles))]
-      (when (seq journal-pages-tx)
-        (db/transact! repo journal-pages-tx)))))
-
-;; TODO: replace files with page blocks transaction
-(defn import-from-roam-json!
-  [data finished-ok-handler]
-  (when-let [repo (state/get-current-repo)]
-    (let [files (external/to-markdown-files :roam data {})]
-      (index-files! repo files
-                    (fn []
-                      (finished-ok-handler))))))

+ 0 - 55
src/main/frontend/handler/file_based/page.cljs

@@ -1,55 +0,0 @@
-(ns ^:no-doc frontend.handler.file-based.page
-  (:require [clojure.string :as string]
-            [frontend.config :as config]
-            [frontend.date :as date]
-            [frontend.db.file-based.model :as file-model]
-            [frontend.handler.common.page :as page-common-handler]
-            [frontend.mobile.util :as mobile-util]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [logseq.common.util :as common-util]
-            [logseq.common.util.page-ref :as page-ref]))
-
-;; FIXME: add whiteboard
-(defn- get-directory
-  [journal?]
-  (if journal?
-    (config/get-journals-directory)
-    (config/get-pages-directory)))
-
-(defn- get-file-name
-  [journal? title]
-  (when-let [s (if journal?
-                 (date/journal-title->default title)
-                 ;; legacy in org-mode format, don't escape slashes except bug reported
-                 (common-util/page-name-sanity (string/lower-case title)))]
-    ;; Win10 file path has a length limit of 260 chars
-    (common-util/safe-subs s 0 200)))
-
-(defn get-page-ref-text
-  [page]
-  (let [edit-block-file-path (file-model/get-block-file-path (state/get-edit-block))
-        page-name (string/lower-case page)]
-    (if (and edit-block-file-path
-             (state/org-mode-file-link? (state/get-current-repo)))
-      (if-let [ref-file-path (:file/path (file-model/get-page-file page-name))]
-        (util/format "[[file:%s][%s]]"
-                     (util/get-relative-path edit-block-file-path ref-file-path)
-                     page)
-        (let [journal? (date/valid-journal-title? page)
-              ref-file-path (str
-                             (if (or (util/electron?) (mobile-util/native-platform?))
-                               (-> (config/get-repo-dir (state/get-current-repo))
-                                   js/decodeURI
-                                   (string/replace #"/+$" "")
-                                   (str "/"))
-                               "")
-                             (get-directory journal?)
-                             "/"
-                             (get-file-name journal? page)
-                             ".org")]
-          (page-common-handler/<create! page {:redirect? false})
-          (util/format "[[file:%s][%s]]"
-                       (util/get-relative-path edit-block-file-path ref-file-path)
-                       page)))
-      (page-ref/->page-ref page))))

+ 0 - 87
src/main/frontend/handler/file_based/page_property.cljs

@@ -1,87 +0,0 @@
-(ns frontend.handler.file-based.page-property
-  "Page property fns for file graphs"
-  (:require [clojure.string :as string]
-            [frontend.db :as db]
-            [frontend.db.file-based.model :as file-model]
-            [frontend.modules.outliner.op :as outliner-op]
-            [frontend.modules.outliner.ui :as ui-outliner-tx]
-            [frontend.state :as state]
-            [frontend.util :as util]))
-
-(defn insert-property
-  [format content key value]
-  (when (and (string? content) (not (string/blank? (name key))))
-    (let [key (if (string? key) (keyword key) key)
-          key-part (util/format (case format
-                                  :org "#+%s: "
-                                  "%s:: ") (string/lower-case (name key)))
-          new-property-line (str key-part value)
-          lines (string/split-lines content)
-          key-exists? (atom false)
-          lines (doall
-                 (map (fn [line]
-                        (if (and (string/starts-with?
-                                  (string/lower-case line)
-                                  (string/lower-case key-part))
-                                 (not @key-exists?)) ; only replace the first match
-                          (do
-                            (reset! key-exists? true)
-                            new-property-line)
-                          line)) lines))
-          lines (if (= lines [""]) nil lines)
-          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 key value]
-  (let [repo (state/get-current-repo)
-        key (keyword key)
-        pre-block (file-model/get-pre-block repo (:db/id page))
-        format (state/get-preferred-format)
-        page-id {:db/id (:db/id page)}
-        org? (= format :org)
-        value (if (contains? #{:filters} key) (pr-str value) value)]
-    (if pre-block
-      (let [properties (:block/properties pre-block)
-            new-properties (assoc properties key value)
-            content (:block/title pre-block)
-            new-content (insert-property format content key value)
-            block {:db/id (:db/id pre-block)
-                   :block/properties new-properties
-                   :block/title new-content
-                   :block/page page-id}
-            tx [(assoc page-id :block/properties new-properties)
-                block]]
-        (db/transact! tx))
-      (let [block {:block/uuid (db/new-block-id)
-                   :block/parent page-id
-                   :block/page page-id
-                   :block/title (if org?
-                                  (str "#+" (string/upper-case (name key)) ": " value)
-                                  (str (name key) ":: " value))
-                   :block/format format
-                   :block/properties {key value}
-                   :block/pre-block? true}
-            page-properties-tx [(assoc page-id :block/properties {key value})]]
-        (ui-outliner-tx/transact!
-         {:outliner-op :insert-blocks
-          :additional-tx page-properties-tx}
-         (outliner-op/insert-blocks! [block] page {:sibling? false}))))))

+ 0 - 84
src/main/frontend/handler/file_based/property.cljs

@@ -1,84 +0,0 @@
-(ns frontend.handler.file-based.property
-  "Property handlers for file based graphs"
-  (:require [frontend.db :as db]
-            [frontend.handler.block :as block-handler]
-            [frontend.handler.file-based.property.util :as property-util]
-            [frontend.modules.outliner.op :as outliner-op]
-            [frontend.modules.outliner.ui :as ui-outliner-tx]
-            [frontend.state :as state]
-            [logseq.common.util :as common-util]
-            [promesa.core :as p]))
-
-(defn insert-property
-  [format content key value & args]
-  (apply property-util/insert-property format content key value args))
-
-(defn remove-id-property
-  [format content]
-  (property-util/remove-id-property format content))
-
-(def hidden-properties property-util/hidden-properties)
-(def built-in-properties property-util/built-in-properties)
-
-(defn batch-set-block-property-aux!
-  "col: a collection of [block-id property-key property-value]."
-  [col]
-  (let [col' (group-by first col)]
-    (p/do!
-     (ui-outliner-tx/transact!
-      {:outliner-op :save-block}
-      (doseq [[block-id items] col']
-        (let [block-id (if (string? block-id) (uuid block-id) block-id)
-              new-properties (zipmap (map second items)
-                                     (map last items))]
-          (when-let [block (db/entity [:block/uuid block-id])]
-            (let [format (get block :block/format :markdown)
-                  content (:block/title block)
-                  ;; FIXME: Remove not-empty if :block/properties stops returning '()
-                  properties* (not-empty (:block/properties block))
-                  properties-text-values (:block/properties-text-values block)
-                  properties (-> (merge properties* new-properties)
-                                 common-util/remove-nils-non-nested)
-                  properties-text-values (-> (merge properties-text-values new-properties)
-                                             common-util/remove-nils-non-nested)
-                  property-ks (->> (concat (:block/properties-order block)
-                                           (map second items))
-                                   (filter (set (keys properties)))
-                                   distinct
-                                   vec)
-                  content (property-util/remove-properties format content)
-                  kvs (for [key property-ks] [key (or (get properties-text-values key)
-                                                      (get properties key))])
-                  content (property-util/insert-properties format content kvs)
-                  content (property-util/remove-empty-properties content)
-                  block {:block/uuid block-id
-                         :block/properties properties
-                         :block/properties-order property-ks
-                         :block/properties-text-values properties-text-values
-                         :block/title content}]
-              (outliner-op/save-block! block {:retract-attributes? false}))))))
-     (let [block-id (ffirst col)
-           block-id (if (string? block-id) (uuid block-id) block-id)
-           input-pos (or (state/get-edit-pos) :max)]
-    ;; update editing input content
-       (when-let [editing-block (state/get-edit-block)]
-         (when (= (:block/uuid editing-block) block-id)
-           (block-handler/edit-block! editing-block input-pos)))))))
-
-(defn batch-set-block-property!
-  [block-ids property-key property-value]
-  (batch-set-block-property-aux! (map #(vector % property-key property-value) block-ids)))
-
-(defn batch-remove-block-property!
-  [block-ids property-key]
-  (batch-set-block-property! block-ids property-key nil))
-
-(defn remove-block-property!
-  [block-id key]
-  (let [key (keyword key)]
-    (batch-set-block-property-aux! [[block-id key nil]])))
-
-(defn set-block-property!
-  [block-id key value]
-  (let [key (keyword key)]
-    (batch-set-block-property-aux! [[block-id key value]])))

+ 0 - 236
src/main/frontend/handler/file_based/property/util.cljs

@@ -1,236 +0,0 @@
-(ns frontend.handler.file-based.property.util
-  "Property fns needed by the rest of the app and not graph-parser"
-  (:require [clojure.string :as string]
-            [frontend.util :as util]
-            [clojure.set :as set]
-            [frontend.config :as config]
-            [logseq.graph-parser.property :as gp-property :refer [properties-start properties-end]]
-            [frontend.format.mldoc :as mldoc]
-            [frontend.db :as db]
-            [frontend.state :as state]
-            [frontend.util.cursor :as cursor]))
-
-(defn hidden-properties
-  "These are properties hidden from user including built-in ones and ones
-  configured by user"
-  []
-  (set/union
-   (gp-property/hidden-built-in-properties)
-   (set (config/get-block-hidden-properties))))
-
-;; TODO: Investigate if this behavior is correct for configured hidden
-;; properties and for editable built in properties
-(def built-in-properties
-  "Alias to hidden-properties to keep existing behavior"
-  hidden-properties)
-
-(defn remove-empty-properties
-  [content]
-  (if (gp-property/contains-properties? content)
-    (string/replace content
-                    (re-pattern ":PROPERTIES:\n+:END:\n*")
-                    "")
-    content))
-
-(def simplified-property? gp-property/simplified-property?)
-
-(defn- get-property-key
-  [line format]
-  (and (string? line)
-       (when-let [key (last
-                       (if (= format :org)
-                         (util/safe-re-find #"^\s*:([^: ]+): " line)
-                         (util/safe-re-find #"^\s*([^ ]+):: " line)))]
-         (keyword key))))
-
-(defn- org-property?
-  [line]
-  (boolean
-   (and (string? line)
-        (util/safe-re-find #"^\s*:[^: ]+: " line)
-        (when-let [key (get-property-key line :org)]
-          (not (contains? #{:PROPERTIES :END} key))))))
-
-(defn- get-org-property-keys
-  [content]
-  (let [content-lines (string/split-lines content)
-        [_ properties&body] (split-with #(-> (string/triml %)
-                                             string/upper-case
-                                             (string/starts-with? properties-start)
-                                             not)
-                                        content-lines)
-        properties (rest (take-while #(-> (string/trim %)
-                                          string/upper-case
-                                          (string/starts-with? properties-end)
-                                          not
-                                          (or (string/blank? %)))
-                                     properties&body))]
-    (when (seq properties)
-      (map #(->> (string/split % ":")
-                 (remove string/blank?)
-                 first
-                 string/upper-case)
-           properties))))
-
-(defn- get-markdown-property-keys
-  [content]
-  (let [content-lines (string/split-lines content)
-        properties (filter #(re-matches (re-pattern (str "^.+" gp-property/colons "\\s*.+")) %)
-                           content-lines)]
-    (when (seq properties)
-      (map #(->> (string/split % gp-property/colons)
-                 (remove string/blank?)
-                 first
-                 string/upper-case)
-           properties))))
-
-(defn- get-property-keys
-  [format content]
-  (cond
-    (gp-property/contains-properties? content)
-    (get-org-property-keys content)
-
-    (= :markdown format)
-    (get-markdown-property-keys content)))
-
-(defn property-key-exist?
-  [format content key]
-  (let [key (string/upper-case key)]
-    (contains? (set (util/remove-first #{key} (get-property-keys format content))) key)))
-
-(defn goto-properties-end
-  [_format input]
-  (cursor/move-cursor-to-thing input properties-start 0)
-  (let [from (cursor/pos input)]
-    (cursor/move-cursor-to-thing input properties-end from)))
-
-(def remove-properties gp-property/remove-properties)
-
-;; title properties body
-(defn with-built-in-properties
-  [properties content format]
-  (let [org? (= format :org)
-        properties (filter (fn [[k _v]] ((built-in-properties) k)) properties)]
-    (if (seq properties)
-      (let [lines (string/split-lines content)
-            ast (mldoc/->edn content format)
-            [title body] (if (mldoc/block-with-title? (first (ffirst ast)))
-                           [(first lines) (rest lines)]
-                           [nil lines])
-            properties-in-content? (and title (= (string/upper-case title) properties-start))
-            no-title? (or (simplified-property? title) properties-in-content?)
-            properties&body (concat
-                                 (when (and no-title? (not org?)) [title])
-                                 (if (and org? properties-in-content?)
-                                   (rest body)
-                                   body))
-            {properties-lines true body false} (group-by (fn [s]
-                                                           (or (simplified-property? s)
-                                                               (and org? (org-property? s)))) properties&body)
-            body (if org?
-                   (remove (fn [s] (contains? #{properties-start properties-end} (string/trim s))) body)
-                   body)
-            properties-in-content (->> (map #(get-property-key % format) properties-lines)
-                                       (remove nil?)
-                                       (set))
-            properties (remove (comp properties-in-content first) properties)
-            built-in-properties-area (map (fn [[k v]]
-                                            (if org?
-                                              (str ":" (name k) ": " v)
-                                              (str (name k) gp-property/colons " " v))) properties)
-            body (concat (if no-title? nil [title])
-                         (when org? [properties-start])
-                         built-in-properties-area
-                         properties-lines
-                         (when org?
-                           [properties-end])
-                         body)]
-        (string/triml (string/join "\n" body)))
-      content)))
-
-(defn insert-property
-  "Only accept nake content (without any indentation)"
-  ([format content key value]
-   (insert-property format content key value false))
-  ([format content key value front-matter?]
-   (let [repo (state/get-current-repo)]
-     (gp-property/insert-property repo format content key value front-matter?))))
-
-(defn insert-properties
-  [format content kvs]
-  (let [repo (state/get-current-repo)]
-    (gp-property/insert-properties repo format content kvs)))
-
-(def remove-property gp-property/remove-property)
-
-(defn remove-id-property
-  [format content]
-  (remove-property format "id" content false))
-
-;; FIXME: remove only from the properties area, not other blocks such as
-;; code blocks, quotes, etc.
-;; Currently, this function will do nothing if the content is a code block.
-;; The future plan is to separate those properties from the block' content.
-(defn remove-built-in-properties
-  [format content]
-  (when content
-    (let [trim-content (string/trim content)]
-      (if (or
-           (and (= format :markdown)
-                (string/starts-with? trim-content "```")
-                (string/ends-with? trim-content "```"))
-           (and (= format :org)
-                (string/starts-with? trim-content "#+BEGIN_SRC")
-                (string/ends-with? trim-content "#+END_SRC")))
-        content
-        (let [built-in-properties* (built-in-properties)
-              content (reduce (fn [content key]
-                                (remove-property format key content)) content built-in-properties*)]
-          (if (= format :org)
-            (string/replace-first content (re-pattern ":PROPERTIES:\n:END:\n*") "")
-            content))))))
-
-(def hidden-editable-page-properties
-  "Properties that are hidden in the pre-block (page property)"
-  #{:title :filters :icon})
-
-(assert (set/subset? hidden-editable-page-properties (gp-property/editable-built-in-properties))
-        "Hidden editable page properties must be valid editable properties")
-
-(def hidden-editable-block-properties
-  "Properties that are hidden in a block (block property)"
-  #{:logseq.query/nlp-date})
-
-(assert (set/subset? hidden-editable-block-properties (gp-property/editable-built-in-properties))
-        "Hidden editable page properties must be valid editable properties")
-
-(defn- add-aliases-to-properties
-  "Adds aliases to a page when a page has aliases and is also an alias of other pages"
-  [properties page-id]
-  (let [repo (state/get-current-repo)
-        aliases (db/get-page-alias-names repo page-id)]
-    (if (seq aliases)
-      (if (:alias properties)
-        (update properties :alias (fn [c]
-                                    (util/distinct-by string/lower-case (concat c aliases))))
-        (assoc properties :alias aliases))
-      properties)))
-
-(defn get-visible-ordered-properties
-  "Given a block's properties, order of properties and any display context,
-  returns a tuple of property pairs that are visible when not being edited"
-  [properties* properties-order {:keys [pre-block? page-id]}]
-  (let [dissoc-keys (fn [m keys] (apply dissoc m keys))
-        properties (cond-> (update-keys properties* keyword)
-                     true
-                     (dissoc-keys (hidden-properties))
-                     pre-block?
-                     (dissoc-keys hidden-editable-page-properties)
-                     (not pre-block?)
-                     (dissoc-keys hidden-editable-block-properties)
-                     pre-block?
-                     (add-aliases-to-properties page-id))]
-    (if (seq properties-order)
-      (keep (fn [k] (when (contains? properties k) [k (get properties k)]))
-            (distinct properties-order))
-      properties*)))

+ 0 - 138
src/main/frontend/handler/file_based/repeated.cljs

@@ -1,138 +0,0 @@
-(ns frontend.handler.file-based.repeated
-  "Provides fns related to schedule and deadline"
-  (:require [cljs-time.core :as t]
-            [cljs-time.local :as tl]
-            [cljs-time.format :as tf]
-            [clojure.string :as string]
-            [frontend.util :as util]))
-
-(def custom-formatter (tf/formatter "yyyy-MM-dd EEE"))
-
-(defn repeated?
-  [timestamp]
-  (some? (:repetition timestamp)))
-
-(defn- get-duration-f-and-text
-  [duration]
-  (case duration
-    "Hour"
-    [t/hours "h"]
-    "Day"
-    [t/days "d"]
-    "Week"
-    [t/weeks "w"]
-    "Month"
-    [t/months "m"]
-    "Year"
-    [t/years "y"]
-    nil))
-
-(defn get-repeater-symbol
-  [kind]
-  (case kind
-    "Plus"
-    "+"
-    "Dotted"
-    ".+"
-    "++"))
-
-(defn timestamp->text
-  ([timestamp]
-   (timestamp->text timestamp nil))
-  ([{:keys [date repetition time]} start-time]
-   (let [{:keys [year month day]} date
-         {:keys [hour min]
-          :or {hour 0 min 0}} time
-         [hour min] (if start-time
-                      [(t/hour start-time)
-                       (t/minute start-time)]
-                      [hour min])
-         [[kind] [duration] num] repetition
-         start-time (or start-time (t/local-date-time year month day hour min))
-         [_duration-f d] (get-duration-f-and-text duration)
-         kind (get-repeater-symbol kind)
-         repeater (when (and kind num d)
-                    (str kind num d))
-         time-repeater (if time
-                         (str (util/zero-pad hour) ":" (util/zero-pad min)
-                              (if (string/blank? repeater)
-                                ""
-                                (str " " repeater)))
-                         repeater)]
-     (util/format "%s%s"
-                  (tf/unparse custom-formatter start-time)
-                  (if (string/blank? time-repeater)
-                    ""
-                    (str " " time-repeater))))))
-
-(defn- repeat-until-future-timestamp
-  [datetime now delta keep-week?]
-  (let [datetime (t/plus datetime delta)
-        result (loop [result datetime]
-                 (if (t/after? result now)
-                   result
-                   (recur (t/plus result delta))))
-        w1 (t/day-of-week datetime)
-        w2 (t/day-of-week result)]
-    (if (and keep-week? (not= w1 w2))
-      ;; next week
-      (if (> w2 w1)
-        (t/plus result (t/days (- 7 (- w2 w1))))
-        (t/plus result (t/days (- w1 w2))))
-      result)))
-
-(defn next-timestamp-text
-  [{:keys [date repetition time] :as timestamp}]
-  (let [{:keys [year month day]} date
-        {:keys [hour min]
-         :or {hour 0 min 0}} time
-        [[kind] [duration] num] repetition
-        week? (or (= duration "Week")
-                  (= duration "w"))
-        [duration-f _] (get-duration-f-and-text duration)
-        delta (duration-f num)
-        start-time (t/local-date-time year month day hour min)
-        now (tl/local-now)
-        start-time' (case kind
-                      "Dotted"
-                      (repeat-until-future-timestamp start-time now delta week?)
-
-                      "DoublePlus"
-                      (if (t/after? start-time now)
-                        start-time
-                        (t/plus start-time delta))
-
-
-                      ;; "Plus"
-                      (t/plus start-time delta))]
-    (timestamp->text timestamp start-time')))
-
-(defn timestamp-map->text
-  [{:keys [date time repeater]}]
-  (let [{:keys [kind duration num]} repeater
-        repeater (when (and kind num duration)
-                   (str kind num duration))
-        time-repeater (if-not (string/blank? time)
-                        (str time
-                             (if (string/blank? repeater)
-                               ""
-                               (str " " repeater)))
-                        repeater)]
-    (util/format "<%s%s>"
-                 (tf/unparse custom-formatter date)
-                 (if (string/blank? time-repeater)
-                   ""
-                   (str " " time-repeater)))))
-
-(defn timestamp->map
-  [{:keys [date repetition time]}]
-  (let [{:keys [year month day]} date
-        {:keys [hour min]} time
-        [[kind] [duration] num] repetition]
-    {:date (t/local-date year month day)
-     :time (when (and hour min)
-             (str (util/zero-pad hour) ":" (util/zero-pad min)))
-     :repeater (when (and kind duration num)
-                 {:kind (get-repeater-symbol kind)
-                  :duration (last (get-duration-f-and-text duration))
-                  :num num})}))

+ 0 - 301
src/main/frontend/handler/file_based/repo.cljs

@@ -1,301 +0,0 @@
-(ns frontend.handler.file-based.repo
-  "Repo fns for creating, loading and parsing file graphs"
-  (:require [clojure.core.async :as async]
-            [clojure.core.async.interop :refer [p->c]]
-            [frontend.config :as config]
-            [frontend.db :as db]
-            [frontend.db.file-based.model :as file-model]
-            [frontend.fs :as fs]
-            [frontend.handler.file-based.file :as file-handler]
-            [frontend.handler.repo-config :as repo-config-handler]
-            [frontend.handler.route :as route-handler]
-            [frontend.handler.ui :as ui-handler]
-            [frontend.spec :as spec]
-            [frontend.state :as state]
-            [frontend.util :as util]
-            [logseq.common.config :as common-config]
-            [logseq.common.path :as path]
-            [logseq.graph-parser :as graph-parser]
-            [medley.core :as medley]
-            [promesa.core :as p]
-            [shadow.resource :as rc]))
-
-(defn- create-contents-file
-  [repo-url]
-  (spec/validate :repos/url repo-url)
-  (p/let [repo-dir (config/get-repo-dir repo-url)
-          pages-dir (state/get-pages-directory)
-          [org-path md-path] (map #(str pages-dir "/contents." %) ["org" "md"])
-          contents-file-exist? (some #(fs/file-exists? repo-dir %) [org-path md-path])]
-    (when-not contents-file-exist?
-      (let [format (state/get-preferred-format)
-            file-rpath (str "pages/" "contents." (config/get-file-extension format))
-            default-content (case (name format)
-                              "org" (rc/inline "templates/contents.org")
-                              "markdown" (rc/inline "templates/contents.md")
-                              "")]
-        (p/let [_ (fs/mkdir-if-not-exists (path/path-join repo-dir pages-dir))
-                file-exists? (fs/create-if-not-exists repo-url repo-dir file-rpath default-content)]
-          (when-not file-exists?
-            (file-handler/reset-file! repo-url file-rpath default-content {})))))))
-
-(defn- create-custom-theme
-  [repo-url]
-  (spec/validate :repos/url repo-url)
-  (let [repo-dir (config/get-repo-dir repo-url)
-        path (str config/app-name "/" config/custom-css-file)
-        file-rpath path
-        default-content ""]
-    (p/let [_ (fs/mkdir-if-not-exists (path/path-join repo-dir config/app-name))
-            file-exists? (fs/create-if-not-exists repo-url repo-dir file-rpath default-content)]
-      (when-not file-exists?
-        (file-handler/reset-file! repo-url path default-content {})))))
-
-(comment
-  (defn- create-dummy-notes-page
-    [repo-url content]
-    (spec/validate :repos/url repo-url)
-    (let [repo-dir (config/get-repo-dir repo-url)
-          file-rpath (str (config/get-pages-directory) "/how_to_make_dummy_notes.md")]
-      (p/let [_ (fs/mkdir-if-not-exists (path/path-join repo-dir (config/get-pages-directory)))
-              _file-exists? (fs/create-if-not-exists repo-url repo-dir file-rpath content)]
-        (file-handler/reset-file! repo-url file-rpath content {})))))
-
-(defn create-config-file-if-not-exists
-  "Creates a default logseq/config.edn if it doesn't exist"
-  [repo-url]
-  (spec/validate :repos/url repo-url)
-  (let [repo-dir (config/get-repo-dir repo-url)
-        app-dir config/app-name
-        dir (path/path-join repo-dir app-dir)]
-    (p/let [_ (fs/mkdir-if-not-exists dir)]
-      (let [default-content config/config-default-content
-            path (str app-dir "/" config/config-file)]
-        (p/let [file-exists? (fs/create-if-not-exists repo-url repo-dir "logseq/config.edn" default-content)]
-          (when-not file-exists?
-            (file-handler/reset-file! repo-url path default-content {})
-            (repo-config-handler/set-repo-config-state! repo-url default-content)))))))
-
-(defn- create-default-files!
-  [repo-url]
-  (spec/validate :repos/url repo-url)
-  (let [repo-dir (config/get-repo-dir repo-url)]
-    (p/do! (fs/mkdir-if-not-exists (path/path-join repo-dir config/app-name))
-           (fs/mkdir-if-not-exists (path/path-join repo-dir config/app-name config/recycle-dir))
-           (fs/mkdir-if-not-exists (path/path-join repo-dir (config/get-journals-directory)))
-           (create-config-file-if-not-exists repo-url)
-           (create-contents-file repo-url)
-           (create-custom-theme repo-url)
-           (state/pub-event! [:page/create-today-journal repo-url]))))
-
-(defn- parse-and-load-file!
-  "Accept: .md, .org, .edn, .css"
-  [repo-url file {:keys [new-graph? verbose]}]
-  (->
-   (p/let [result (file-handler/alter-file repo-url
-                                           (:file/path file)
-                                           (:file/content file)
-                                           (merge (:stat file)
-                                                  {:new-graph? new-graph?
-                                                   :re-render-root? false
-                                                   :from-disk? true}
-                                                  ;; To avoid skipping the `:or` bounds for keyword destructuring
-                                                  (when (some? verbose) {:verbose verbose})))]
-     (state/set-parsing-state! (fn [m]
-                                 (update m :finished inc)))
-     result)
-   (p/catch (fn [e]
-              (println "Parse and load file failed: " (str (:file/path file)))
-              (js/console.error e)
-              (state/set-parsing-state! (fn [m]
-                                          (update m :failed-parsing-files conj [(:file/path file) e])))
-              (state/set-parsing-state! (fn [m]
-                                          (update m :finished inc)))
-              nil))))
-
-(defn- parse-and-load-file-test-version!
-  "Accept: .md, .org, .edn, .css"
-  [repo-url file {:keys [new-graph? verbose]}]
-  (try
-    (let [result (file-handler/alter-file-test-version
-                  repo-url
-                  (:file/path file)
-                  (:file/content file)
-                  (merge (:stat file)
-                         {:new-graph? new-graph?
-                          :re-render-root? false
-                          :from-disk? true}
-                                                  ;; To avoid skipping the `:or` bounds for keyword destructuring
-                         (when (some? verbose) {:verbose verbose})))]
-      (state/set-parsing-state! (fn [m]
-                                  (update m :finished inc)))
-      result)
-    (catch :default e
-      (println "Parse and load file failed: " (str (:file/path file)))
-      (js/console.error e)
-      (state/set-parsing-state! (fn [m]
-                                  (update m :failed-parsing-files conj [(:file/path file) e])))
-      (state/set-parsing-state! (fn [m]
-                                  (update m :finished inc))))))
-
-(defn- after-parse
-  [repo-url re-render? re-render-opts opts graph-added-chan]
-  (when (or (:new-graph? opts) (not (:refresh? opts)))
-    (create-default-files! repo-url))
-  (when re-render?
-    (ui-handler/re-render-root! re-render-opts))
-  (state/pub-event! [:graph/added repo-url opts])
-  (let [parse-errors (get-in @state/state [:graph/parsing-state repo-url :failed-parsing-files])]
-    (when (seq parse-errors)
-      (state/pub-event! [:file/parse-and-load-error repo-url parse-errors])))
-  (state/reset-parsing-state!)
-  (state/set-loading-files! repo-url false)
-  (async/offer! graph-added-chan true))
-
-(defn- parse-files-and-create-default-files-inner!
-  [repo-url files delete-files delete-blocks re-render? re-render-opts opts]
-  (let [supported-files (graph-parser/filter-files files)
-        delete-data (->> (concat delete-files delete-blocks)
-                         (remove nil?))
-        indexed-files (medley/indexed supported-files)
-        chan (async/to-chan! indexed-files)
-        graph-added-chan (async/promise-chan)
-        total (count supported-files)
-        large-graph? (> total 1000)
-        *page-names (atom #{})
-        *page-name->path (atom {})]
-    (when (seq delete-data) (db/transact! repo-url delete-data {:delete-files? true}))
-    (state/set-current-repo! repo-url)
-    (state/set-parsing-state! {:total (count supported-files)})
-    ;; Synchronous for tests for not breaking anything
-    (if util/node-test?
-      (do
-        (doseq [file supported-files]
-          (state/set-parsing-state! (fn [m]
-                                      (assoc m
-                                             :current-parsing-file (:file/path file))))
-          (parse-and-load-file-test-version! repo-url file (select-keys opts [:new-graph? :verbose])))
-        (after-parse repo-url re-render? re-render-opts opts graph-added-chan))
-      (async/go-loop []
-        (if-let [item (async/<! chan)]
-          (let [[idx file] item
-                whiteboard? (common-config/whiteboard? (:file/path file))
-                yield-for-ui? (or (not large-graph?)
-                                  (zero? (rem idx 10))
-                                  (<= (- total idx) 10)
-                                  whiteboard?)]
-            (state/set-parsing-state! (fn [m]
-                                        (assoc m :current-parsing-file (:file/path file))))
-
-            (when yield-for-ui? (async/<! (async/timeout 1)))
-
-            (let [opts' (select-keys opts [:new-graph? :verbose])
-                  ;; whiteboards might have conflicting block IDs so that db transaction could be failed
-                  result (async/<! (p->c (parse-and-load-file! repo-url file opts')))
-                  page-name (when (coll? result) ; result could be a promise
-                              (some (fn [x] (when (and (map? x)
-                                                       (:block/title x)
-                                                       (= (:file/path file) (:file/path (:block/file x))))
-                                              (:block/name x)))
-                                    result))
-                  page-exists? (and page-name (get @*page-names page-name))
-                  _ (when page-exists?
-                      (state/pub-event! [:notification/show
-                                         {:content [:div
-                                                    (util/format "The file \"%s\" will be skipped because another file \"%s\" has the same page title."
-                                                                 (:file/path file)
-                                                                 (get @*page-name->path page-name))]
-                                          :status :warning
-                                          :clear? false}]))
-                  _ (when (and page-name (not page-exists?))
-                      (swap! *page-names conj page-name)
-                      (swap! *page-name->path assoc page-name (:file/path file)))]
-              (recur)))
-          (after-parse repo-url re-render? re-render-opts opts graph-added-chan))))
-    graph-added-chan))
-
-(defn- parse-files-and-create-default-files!
-  [repo-url files delete-files delete-blocks re-render? re-render-opts opts]
-  (parse-files-and-create-default-files-inner! repo-url files delete-files delete-blocks re-render? re-render-opts opts))
-
-(defn parse-files-and-load-to-db!
-  [repo-url files {:keys [delete-files delete-blocks re-render? re-render-opts _refresh?] :as opts
-                   :or {re-render? true}}]
-  (parse-files-and-create-default-files! repo-url files delete-files delete-blocks re-render? re-render-opts opts))
-
-(defn load-new-repo-to-db!
-  "load graph files to db."
-  [repo-url {:keys [file-objs new-graph? empty-graph?]}]
-  (spec/validate :repos/url repo-url)
-  (route-handler/redirect-to-home!)
-  (prn ::load-new-repo repo-url :empty-graph? empty-graph? :new-graph? new-graph?)
-  (state/set-parsing-state! {:graph-loading? true})
-  (let [config (or (when-let [content (some-> (first (filter #(= "logseq/config.edn" (:file/path %)) file-objs))
-                                              :file/content)]
-                     (repo-config-handler/read-repo-config content))
-                   (state/get-config repo-url))
-        ;; NOTE: Use config while parsing. Make sure it's the current journal title format
-        ;; config should be loaded to state first
-        _ (state/set-config! repo-url config)
-        ;; remove :hidden files from file-objs, :hidden
-        file-objs (common-config/remove-hidden-files file-objs config :file/path)]
-
-    ;; Load to db even it's empty, (will create default files)
-    (parse-files-and-load-to-db! repo-url file-objs {:new-graph? new-graph?
-                                                     :empty-graph? empty-graph?})))
-
-(defn load-repo-to-db!
-  [repo-url {:keys [diffs file-objs refresh? new-graph? empty-graph?]}]
-  (spec/validate :repos/url repo-url)
-  (route-handler/redirect-to-home!)
-  (prn ::load-repo-to-db! repo-url)
-  (state/set-parsing-state! {:graph-loading? true})
-  (let [config (or (when-let [content (some-> (first (filter #(= (config/get-repo-config-path) (:file/path %)) file-objs))
-                                              :file/content)]
-                     (repo-config-handler/read-repo-config content))
-                   (state/get-config repo-url))
-        ;; NOTE: Use config while parsing. Make sure it's the current journal title format
-        _ (state/set-config! repo-url config)
-        nfs-files (common-config/remove-hidden-files file-objs config :file/node-node-path)
-        diffs (common-config/remove-hidden-files diffs config :path)
-        load-contents (fn [files option]
-                        (file-handler/load-files-contents!
-                         repo-url
-                         files
-                         (fn [files-contents]
-                           (parse-files-and-load-to-db! repo-url files-contents (assoc option :refresh? refresh?)))))]
-    (cond
-      (and (not (seq diffs)) nfs-files)
-      (parse-files-and-load-to-db! repo-url nfs-files {:new-graph? new-graph?
-                                                       :empty-graph? empty-graph?})
-
-      :else
-      (when (seq diffs)
-        (let [filter-diffs (fn [type] (->> (filter (fn [f] (= type (:type f))) diffs)
-                                           (map :path)))
-              remove-files (filter-diffs "remove")
-              modify-files (filter-diffs "modify")
-              add-files (filter-diffs "add")
-              delete-files (when (seq remove-files)
-                             (db/delete-files remove-files))
-              delete-blocks (file-model/delete-blocks repo-url remove-files true)
-              delete-blocks (->>
-                             (concat
-                              delete-blocks
-                              (file-model/delete-blocks repo-url modify-files false))
-                             (remove nil?))
-              delete-pages (if (seq remove-files)
-                             (file-model/delete-pages-by-files remove-files)
-                             [])
-              add-or-modify-files (some->>
-                                   (concat modify-files add-files)
-                                   (remove nil?))
-              options {:delete-files (concat delete-files delete-pages)
-                       :delete-blocks delete-blocks
-                       :re-render? true}]
-          (if (seq nfs-files)
-            (parse-files-and-load-to-db! repo-url nfs-files
-                                         (assoc options
-                                                :refresh? refresh?
-                                                :re-render-opts {:clear-all-query-state? true}))
-            (load-contents add-or-modify-files options)))))))

+ 0 - 71
src/main/frontend/handler/file_based/status.cljs

@@ -1,71 +0,0 @@
-(ns frontend.handler.file-based.status
-  "Task (formerly todo) related util fns"
-  (:require [clojure.string :as string]
-            [frontend.util :as util]
-            [logseq.common.marker :as common-marker]))
-
-(def marker-pattern common-marker/marker-pattern)
-
-(def bare-marker-pattern
-  #"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS){1}\s+")
-
-(defn add-or-update-marker
-  [content format marker]
-  (let [[re-pattern new-line-re-pattern]
-        (case format
-          :org
-          [#"^\*+\s" #"\n\*+\s"]
-
-          (:markdown :md)
-          [#"^#+\s" #"\n#+\s"]
-
-          ;; failback to markdown
-          [#"^#+\s" #"\n#+\s"])
-
-        pos
-        (if-let [matches (seq (util/re-pos new-line-re-pattern content))]
-          (let [[start-pos content] (last matches)]
-            (+ start-pos (count content)))
-          (count (util/safe-re-find re-pattern content)))
-
-        new-content
-        (str (subs content 0 pos)
-             (string/replace-first (subs content pos)
-                                   (marker-pattern format)
-                                   (str marker (if (empty? marker) "" " "))))]
-    new-content))
-
-(defn cycle-marker-state
-  [marker preferred-workflow]
-  (case marker
-    "TODO"
-    "DOING"
-
-    "DOING"
-    "DONE"
-
-    "LATER"
-    "NOW"
-
-    "NOW"
-    "DONE"
-
-    "DONE"
-    nil
-
-    (if (= :now preferred-workflow) "LATER" "TODO")))
-
-(defn cycle-marker
-  "The cycle-marker will cycle markers sequentially. You can find all its order in `cycle-marker-state`.
-
-  It also accepts the specified `marker` and `new-marker`.
-  If you don't specify it, it will automatically find it based on `content`.
-
-  Returns [new-content new-marker]."
-  [content marker new-marker format preferred-workflow]
-  (let [content    (string/triml content)
-        marker     (or (not-empty marker)
-                       (last (util/safe-re-find (marker-pattern format) content))) ; Returns the last matching group (last vec)
-        new-marker (or (not-empty new-marker)
-                       (cycle-marker-state marker preferred-workflow))]
-    [(add-or-update-marker content format new-marker) new-marker]))

+ 2 - 8
src/main/frontend/handler/page.cljs

@@ -16,8 +16,6 @@
             [frontend.handler.db-based.page :as db-page-handler]
             [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.file-based.page :as file-page-handler]
-            [frontend.handler.file-based.page-property :as file-page-property]
             [frontend.handler.notification :as notification]
             [frontend.handler.plugin :as plugin-handler]
             [frontend.handler.property :as property-handler]
@@ -135,15 +133,11 @@
 
 (defn update-public-attribute!
   [repo page value]
-  (if (config/db-based-graph? repo)
-    (db-property-handler/set-block-property! [:block/uuid (:block/uuid page)] :logseq.property/publishing-public? value)
-    (file-page-property/add-property! page :public value)))
+  (db-property-handler/set-block-property! [:block/uuid (:block/uuid page)] :logseq.property/publishing-public? value))
 
 (defn get-page-ref-text
   [page]
-  (if (config/db-based-graph?)
-    (ref/->page-ref page)
-    (file-page-handler/get-page-ref-text page)))
+  (ref/->page-ref page))
 
 (defn init-commands!
   []

+ 15 - 33
src/main/frontend/handler/property.cljs

@@ -1,29 +1,22 @@
 (ns frontend.handler.property
   "Property fns for both file and DB graphs"
-  (:require [frontend.config :as config]
-            [frontend.db.model :as db-model]
+  (:require [frontend.db.model :as db-model]
             [frontend.handler.db-based.property :as db-property-handler]
-            [frontend.handler.file-based.page-property :as file-page-property]
-            [frontend.handler.file-based.property :as file-property-handler]
             [frontend.state :as state]))
 
 (defn remove-block-property!
   [repo block-id property-id-or-key]
   (assert (some? property-id-or-key) "remove-block-property! remove-block-property! is nil")
-  (if (config/db-based-graph? repo)
-    (let [eid (if (uuid? block-id) [:block/uuid block-id] block-id)]
-      (db-property-handler/remove-block-property! eid property-id-or-key))
-    (file-property-handler/remove-block-property! block-id property-id-or-key)))
+  (let [eid (if (uuid? block-id) [:block/uuid block-id] block-id)]
+    (db-property-handler/remove-block-property! eid property-id-or-key)))
 
 (defn set-block-property!
   [repo block-id key v]
   (assert (some? key) "set-block-property! key is nil")
-  (if (config/db-based-graph? repo)
-    (let [eid (if (uuid? block-id) [:block/uuid block-id] block-id)]
-      (if (or (nil? v) (and (coll? v) (empty? v)))
-        (db-property-handler/remove-block-property! eid key)
-        (db-property-handler/set-block-property! eid key v)))
-    (file-property-handler/set-block-property! block-id key v)))
+  (let [eid (if (uuid? block-id) [:block/uuid block-id] block-id)]
+    (if (or (nil? v) (and (coll? v) (empty? v)))
+      (db-property-handler/remove-block-property! eid key)
+      (db-property-handler/set-block-property! eid key v))))
 
 (defn add-page-property!
   "Sanitized page-name, unsanitized key / value"
@@ -31,42 +24,31 @@
   (assert (some? key) "key is nil")
   (when page-entity
     (let [repo (state/get-current-repo)]
-      (if (config/db-based-graph? repo)
-        (set-block-property! repo (:block/uuid page-entity) key value)
-        (file-page-property/add-property! page-entity key value)))))
+      (set-block-property! repo (:block/uuid page-entity) key value))))
 
 (defn remove-id-property
   [repo format content]
-  (if (config/db-based-graph? repo)
-    content
-    (file-property-handler/remove-id-property format content)))
+  content)
 
 (defn file-persist-block-id!
-  [repo block-id]
-  (when-not (config/db-based-graph? repo)
-    (file-property-handler/set-block-property! block-id :id (str block-id))))
+  [repo block-id])
 
 (defn batch-remove-block-property!
   [repo block-ids key]
   (assert (some? key) "key is nil")
-  (if (config/db-based-graph? repo)
-    (db-property-handler/batch-remove-property! block-ids key)
-    (file-property-handler/batch-remove-block-property! block-ids key)))
+  (db-property-handler/batch-remove-property! block-ids key))
 
 (defn batch-set-block-property!
   [repo block-ids key value & {:as opts}]
   (assert (some? key) "key is nil")
-  (if (config/db-based-graph? repo)
-    (if (nil? value)
-      (db-property-handler/batch-remove-property! block-ids key)
-      (db-property-handler/batch-set-property! block-ids key value opts))
-    (file-property-handler/batch-set-block-property! block-ids key value)))
+  (if (nil? value)
+    (db-property-handler/batch-remove-property! block-ids key)
+    (db-property-handler/batch-set-property! block-ids key value opts)))
 
 (defn set-block-properties!
   [repo block-id properties]
   (assert (uuid? block-id))
-  (when (config/db-based-graph? repo)
-    (db-property-handler/set-block-properties! block-id properties)))
+  (db-property-handler/set-block-properties! block-id properties))
 
 (defonce class-property-excludes
   #{:logseq.property.class/properties :block/tags

+ 0 - 54
src/main/frontend/handler/property/file.cljs

@@ -1,54 +0,0 @@
-(ns frontend.handler.property.file
-  "Handler for older property features that originated with file graphs. Most of these
-   fns can be used with file or db graphs.
-   It's unclear what the difference is between this and frontend.handler.property. If no difference,
-   we should merge them"
-  (:require [frontend.config :as config]
-            [frontend.handler.file-based.property.util :as property-util]
-            [frontend.handler.file-based.property :as file-property-handler]
-            [clojure.string :as string]))
-
-;; Why need these XXX-when-file-based fns?
-;; there're a lot of usages of property-related fns(e.g. property-util/insert-property) in the whole codebase.
-;; I want to minimize extensive modifications as much as possible when we add db-based graph support.
-
-(defn insert-properties-when-file-based
-  [repo format content kvs]
-  (if (config/db-based-graph? repo)
-    content
-    (property-util/insert-properties format content kvs)))
-
-(defn remove-property-when-file-based
-  [repo format key content & args]
-  (if (config/db-based-graph? repo)
-    content
-    (apply property-util/remove-property format key content args)))
-
-(defn remove-properties-when-file-based
-  [repo format content]
-  (if (config/db-based-graph? repo)
-    content
-    (property-util/remove-properties format content)))
-
-(defn remove-built-in-properties-when-file-based
-  [repo format content]
-  (if (config/db-based-graph? repo)
-    content
-    (property-util/remove-built-in-properties format content)))
-
-(defn with-built-in-properties-when-file-based
-  [repo properties content format]
-  (if (config/db-based-graph? repo)
-    content
-    (property-util/with-built-in-properties properties content format)))
-
-(def property-key-exist?-when-file-based property-util/property-key-exist?)
-(def goto-properties-end-when-file-based property-util/goto-properties-end)
-
-(defn properties-hidden?
-  [properties]
-  (and (seq properties)
-       (let [ks (map (comp keyword string/lower-case name)
-                     (keys properties))
-             hidden-properties-set (file-property-handler/hidden-properties)]
-         (every? hidden-properties-set ks))))

+ 0 - 6
src/main/frontend/handler/property/util.cljs

@@ -25,12 +25,6 @@
   (let [repo (state/get-current-repo)]
     (db-property-util/get-pid repo db-ident)))
 
-(defn block->shape [block]
-  (get-block-property-value block :logseq.property.tldraw/shape))
-
-(defn page-block->tldr-page [block]
-  (get-block-property-value block :logseq.property.tldraw/page))
-
 (defn shape-block?
   [block]
   (let [repo (state/get-current-repo)

+ 1 - 16
src/main/frontend/handler/worker.cljs

@@ -2,29 +2,14 @@
   "Handle messages received from the webworkers"
   (:require [cljs-bean.core :as bean]
             [clojure.string :as string]
-            [frontend.handler.file-based.file :as file-handler]
             [frontend.handler.notification :as notification]
             [frontend.state :as state]
             [frontend.undo-redo :as undo-redo]
             [lambdaisland.glogi :as log]
-            [logseq.db :as ldb]
-            [promesa.core :as p]))
+            [logseq.db :as ldb]))
 
 (defmulti handle identity)
 
-(defmethod handle :write-files [_ _worker data]
-  (let [{:keys [request-id page-id repo files]} data]
-    (->
-     (p/let [_ (file-handler/alter-files repo files {})]
-       (state/<invoke-db-worker :thread-api/page-file-saved request-id page-id))
-     (p/catch (fn [error]
-                (notification/show!
-                 [:div
-                  [:p "Write file failed, please copy the changes to other editors in case of losing data."]
-                  "Error: " (str (.-stack error))]
-                 :error)
-                (state/<invoke-db-worker :thread-api/page-file-saved request-id page-id))))))
-
 (defmethod handle :notification [_ _worker data]
   (apply notification/show! data))
 

+ 0 - 77
src/main/frontend/pubsub.cljc

@@ -1,77 +0,0 @@
-(ns frontend.pubsub
-  "All mults and pubs are collected to this ns.
-  vars with suffix '-mult' is a/Mult, use a/tap and a/untap on them. used by event subscribers
-  vars with suffix '-pub' is a/Pub, use a/sub and a/unsub on them. used by event subscribers
-  vars with suffix '-ch' is chan used by event publishers."
-  {:clj-kondo/config {:linters {:unresolved-symbol {:level :off}}}}
-  #?(:cljs (:require-macros [frontend.pubsub :refer [def-mult-or-pub chan-of]]))
-  (:require [clojure.core.async :as a :refer [chan mult pub]]
-            [clojure.core.async.impl.protocols :as ap]
-            [malli.core :as m]
-            [malli.dev.pretty :as mdp]
-            [clojure.pprint :as pp]))
-
-;;; helper macro
-(defmacro chan-of [malli-schema malli-schema-validator & chan-args]
-  `(let [ch# (chan ~@chan-args)]
-     (reify
-       ap/ReadPort
-       (~'take! [~'_ fn1-handler#]
-        (ap/take! ch# fn1-handler#))
-       ap/WritePort
-       (~'put! [~'_ val# fn1-handler#]
-        (if (~malli-schema-validator val#)
-          (ap/put! ch# val# fn1-handler#)
-          (do (mdp/explain ~malli-schema val#)
-              (throw (ex-info "validate chan value failed" {:val val#}))))))))
-
-(defmacro def-mult-or-pub
-  "define following vars:
-  - `symbol-name`-ch for event publisher.
-  - `symbol-name`-mult or `symbol-name`-pub for event subscribers.
-  - `symbol-name`-validator is malli schema validator
-  def -pub var when `:topic-fn` exists otherwise -mult var"
-  [symbol-name doc-string malli-schema & {:keys [ch-buffer topic-fn]
-                                          :or   {ch-buffer 1}}]
-  (let [schema-validator-name (symbol (str symbol-name "-validator"))
-        schema-name           (symbol (str symbol-name "-schema"))
-        ch-name               (symbol (str symbol-name "-ch"))
-        mult-or-pub-name      (if topic-fn
-                                (symbol (str symbol-name "-pub"))
-                                (symbol (str symbol-name "-mult")))
-        doc-string*           (str doc-string "\nMalli-schema:\n" (with-out-str (pp/pprint malli-schema)))]
-    `(do
-       (def ~schema-name ~malli-schema)
-       (def ~schema-validator-name (m/validator ~malli-schema))
-       (def ~ch-name ~doc-string* (chan-of ~malli-schema ~schema-validator-name ~ch-buffer))
-       ~(if topic-fn
-          `(def ~mult-or-pub-name ~doc-string* (pub ~ch-name ~topic-fn))
-          `(def ~mult-or-pub-name ~doc-string* (mult ~ch-name))))))
-
-;;; all chan, mult, pub defined here...
-
-(def-mult-or-pub app-wake-up-from-sleep
-  "app wake up from sleep event"
-  [:map
-   [:last-activated-at :int]
-   [:now :int]])
-
-(def-mult-or-pub sync-events
-  "file-sync events"
-  [:map
-   [:event [:enum
-            :created-local-version-file
-            :finished-local->remote
-            :finished-remote->local
-            :start
-            :pause
-            :resume
-            :exception-decrypt-failed
-            :remote->local-full-sync-failed
-            :local->remote-full-sync-failed
-            :get-remote-graph-failed
-            :get-deletion-logs-failed
-            :get-remote-all-files-failed]]
-   [:data :map]]
-  :topic-fn :event
-  :ch-buffer (a/sliding-buffer 10))

+ 2 - 12
src/main/frontend/search/browser.cljs

@@ -1,8 +1,6 @@
 (ns frontend.search.browser
   "Browser implementation of search protocol"
-  (:require [frontend.config :as config]
-            [frontend.handler.file-based.property.util :as property-util]
-            [frontend.search.protocol :as protocol]
+  (:require [frontend.search.protocol :as protocol]
             [frontend.state :as state]
             [promesa.core :as p]))
 
@@ -14,17 +12,9 @@
     (state/<invoke-db-worker :thread-api/search-build-pages-indice repo))
   (rebuild-blocks-indice! [this]
     (p/let [repo (state/get-current-repo)
-            file-based? (config/local-file-based-graph? repo)
             _ (protocol/truncate-blocks! this)
             result (state/<invoke-db-worker :thread-api/search-build-blocks-indice repo)
-            blocks (if file-based?
-                     (->> result
-                          ;; remove built-in properties from content
-                          (map
-                           #(update % :content
-                                    (fn [content]
-                                      (property-util/remove-built-in-properties (get % :format :markdown) content)))))
-                     result)
+            blocks result
             _ (when (seq blocks)
                 (state/<invoke-db-worker :thread-api/search-upsert-blocks repo blocks))]))
   (transact-blocks! [_this {:keys [blocks-to-remove-set

+ 0 - 20
src/main/frontend/util.cljc

@@ -15,7 +15,6 @@
             ["semver" :as semver]
             [frontend.loader :refer [load]]
             [cljs-bean.core :as bean]
-            [cljs-time.coerce :as tc]
             [cljs-time.core :as t]
             [clojure.pprint]
             [dommy.core :as d]
@@ -29,7 +28,6 @@
             [promesa.core :as p]
             [rum.core :as rum]
             [clojure.core.async :as async]
-            [frontend.pubsub :as pubsub]
             [datascript.impl.entity :as de]
             [logseq.common.config :as common-config]))
   #?(:cljs (:import [goog.async Debouncer]))
@@ -1432,24 +1430,6 @@
           ret)
         @last-mem))))
 
-#?(:cljs
-   (do
-     (defn <app-wake-up-from-sleep-loop
-       "start a async/go-loop to check the app awake from sleep.
-Use (async/tap `pubsub/app-wake-up-from-sleep-mult`) to receive messages.
-Arg *stop: atom, reset to true to stop the loop"
-       [*stop]
-       (let [*last-activated-at (volatile! (tc/to-epoch (t/now)))]
-         (async/go-loop []
-           (if @*stop
-             (println :<app-wake-up-from-sleep-loop :stop)
-             (let [now-epoch (tc/to-epoch (t/now))]
-               (when (< @*last-activated-at (- now-epoch 10))
-                 (async/>! pubsub/app-wake-up-from-sleep-ch {:last-activated-at @*last-activated-at :now now-epoch}))
-               (vreset! *last-activated-at now-epoch)
-               (async/<! (async/timeout 5000))
-               (recur))))))))
-
 ;; from rum
 #?(:cljs
    (def schedule

+ 0 - 42
src/main/frontend/worker/db_worker.cljs

@@ -21,8 +21,6 @@
             [frontend.worker.db.validate :as worker-db-validate]
             [frontend.worker.embedding :as embedding]
             [frontend.worker.export :as worker-export]
-            [frontend.worker.file :as file]
-            [frontend.worker.file.reset :as file-reset]
             [frontend.worker.handler.page :as worker-page]
             [frontend.worker.pipeline :as worker-pipeline]
             [frontend.worker.rtc.asset-db-listener]
@@ -619,27 +617,6 @@
               (shared-service/broadcast-to-clients! :notification [(:message payload) (:type payload) (:clear? payload) (:uid payload) (:timeout payload)]))
             (throw e)))))))
 
-(def-thread-api :thread-api/file-writes-finished?
-  [repo]
-  (let [conn (worker-state/get-datascript-conn repo)
-        writes @file/*writes]
-    ;; Clean pages that have been deleted
-    (when conn
-      (swap! file/*writes (fn [writes]
-                            (->> writes
-                                 (remove (fn [[_ pid]] (d/entity @conn pid)))
-                                 (into {})))))
-    (if (empty? writes)
-      true
-      (do
-        (prn "Unfinished file writes:" @file/*writes)
-        false))))
-
-(def-thread-api :thread-api/page-file-saved
-  [request-id _page-id]
-  (file/dissoc-request! request-id)
-  nil)
-
 (def-thread-api :thread-api/sync-app-state
   [new-state]
   (when (and (contains? new-state :git/current-repo)
@@ -724,12 +701,6 @@
   [repo]
   (get-all-page-titles-with-cache repo))
 
-(def-thread-api :thread-api/reset-file
-  [repo file-path content opts]
-  ;; (prn :debug :reset-file :file-path file-path :opts opts)
-  (when-let [conn (worker-state/get-datascript-conn repo)]
-    (file-reset/reset-file! repo conn file-path content opts)))
-
 (def-thread-api :thread-api/gc-graph
   [repo]
   (let [{:keys [db client-ops]} (get @*sqlite-conns repo)
@@ -837,18 +808,6 @@
     :delete-page (fn [repo conn [page-uuid]]
                    (delete-page! repo conn page-uuid))}))
 
-(defn- <ratelimit-file-writes!
-  []
-  (file/<ratelimit-file-writes!
-   (fn [col]
-     (when (seq col)
-       (let [repo (ffirst col)
-             conn (worker-state/get-datascript-conn repo)]
-         (if conn
-           (when-not (ldb/db-based-graph? @conn)
-             (file/write-files! conn col (worker-state/get-context)))
-           (js/console.error (str "DB is not found for " repo))))))))
-
 (defn- on-become-master
   [repo start-opts]
   (js/Promise.
@@ -943,7 +902,6 @@
     (log/add-handler worker-state/log-append!)
     (check-worker-scope!)
     (outliner-register-op-handlers!)
-    (<ratelimit-file-writes!)
     (js/setInterval #(.postMessage js/self "keepAliveResponse") (* 1000 25))
     (Comlink/expose proxy-object)
     (let [^js wrapped-main-thread* (Comlink/wrap js/self)

+ 20 - 36
src/main/frontend/worker/pipeline.cljs

@@ -5,7 +5,6 @@
             [datascript.core :as d]
             [frontend.worker-common.util :as worker-util]
             [frontend.worker.commands :as commands]
-            [frontend.worker.file :as file]
             [frontend.worker.react :as worker-react]
             [frontend.worker.state :as worker-state]
             [logseq.common.util :as common-util]
@@ -14,7 +13,6 @@
             [logseq.db :as ldb]
             [logseq.db.common.entity-plus :as entity-plus]
             [logseq.db.common.order :as db-order]
-            [logseq.db.common.sqlite :as common-sqlite]
             [logseq.db.frontend.class :as db-class]
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
             [logseq.db.sqlite.export :as sqlite-export]
@@ -40,32 +38,25 @@
   (when (or (and (:outliner-op tx-meta) (refs-need-recalculated? tx-meta))
             (:rtc-tx? tx-meta)
             (:rtc-op? tx-meta))
-    (let [db-based? (entity-plus/db-based-graph? db-after)]
-      (mapcat (fn [block]
-                (when (d/entity db-after (:db/id block))
-                  (let [date-formatter (worker-state/get-date-formatter repo)
-                        refs (->> (outliner-core/rebuild-block-refs repo db-after date-formatter block) set)]
-                    (if db-based?
-                      (let [old-refs (->> (:block/refs (d/entity db-before (:db/id block)))
-                                          (map :db/id)
-                                          set)
-                            added-refs (when (and (seq refs) (not= refs old-refs))
-                                         (set/difference refs old-refs))
-                            retracted-refs (when (and (seq old-refs) (not= refs old-refs))
-                                             (set/difference old-refs refs))]
-                        (concat
-                         (map (fn [id]
-                                [:db/retract (:db/id block) :block/refs id])
-                              retracted-refs)
-                         (map (fn [id]
-                                [:db/add (:db/id block) :block/refs id])
-                              added-refs)))
-                      ;; retract all refs for file graphs because we can't ensure `refs` are all db ids
-                      (cond-> [[:db/retract (:db/id block) :block/refs]]
-                        (seq refs)
-                        (conj {:db/id (:db/id block)
-                               :block/refs refs}))))))
-              blocks))))
+    (mapcat (fn [block]
+              (when (d/entity db-after (:db/id block))
+                (let [date-formatter (worker-state/get-date-formatter repo)
+                      refs (->> (outliner-core/rebuild-block-refs repo db-after date-formatter block) set)
+                      old-refs (->> (:block/refs (d/entity db-before (:db/id block)))
+                                    (map :db/id)
+                                    set)
+                      added-refs (when (and (seq refs) (not= refs old-refs))
+                                   (set/difference refs old-refs))
+                      retracted-refs (when (and (seq old-refs) (not= refs old-refs))
+                                       (set/difference old-refs refs))]
+                  (concat
+                   (map (fn [id]
+                          [:db/retract (:db/id block) :block/refs id])
+                        retracted-refs)
+                   (map (fn [id]
+                          [:db/add (:db/id block) :block/refs id])
+                        added-refs)))))
+            blocks)))
 
 (defn- insert-tag-templates
   [repo tx-report]
@@ -439,9 +430,7 @@
   "Compute extra tx-data and block/refs, should ensure it's a pure function and
   doesn't call `d/transact!` or `ldb/transact!`."
   [repo {:keys [db-after tx-meta] :as tx-report}]
-  (let [db-based? (entity-plus/db-based-graph? db-after)
-        extra-tx-data (when db-based?
-                        (compute-extra-tx-data repo tx-report))
+  (let [extra-tx-data (compute-extra-tx-data repo tx-report)
         tx-report* (if (seq extra-tx-data)
                      (let [result (d/with db-after extra-tx-data)]
                        (assoc tx-report
@@ -482,11 +471,6 @@
   (try
     (let [{:keys [pages blocks]} (ds-report/get-blocks-and-pages tx-report)
           deleted-blocks (outliner-pipeline/filter-deleted-blocks (:tx-data tx-report))
-          _ (when (common-sqlite/local-file-based-graph? repo)
-              (let [page-ids (distinct (map :db/id pages))]
-                (doseq [page-id page-ids]
-                  (when (d/entity @conn page-id)
-                    (file/sync-to-file repo page-id tx-meta)))))
           deleted-block-uuids (set (map :block/uuid deleted-blocks))
           deleted-block-ids (set (map :db/id deleted-blocks))
           _ (when (seq deleted-block-uuids)

+ 0 - 161
src/test/frontend/components/file_based/query_table_test.cljs

@@ -1,161 +0,0 @@
-(ns frontend.components.file-based.query-table-test
-  (:require [clojure.test :refer [deftest testing are use-fixtures is]]
-            [frontend.test.helper :as test-helper :refer [load-test-files]]
-            [frontend.state :as state]
-            [frontend.components.file-based.query-table :as query-table]
-            [frontend.db.query-dsl :as query-dsl]
-            [frontend.db.react :as react]
-            [frontend.util :as util]))
-
-(use-fixtures :each {:before test-helper/start-test-db!
-                     :after test-helper/destroy-test-db!})
-
-(defn- dsl-query
-  [s]
-  (react/clear-query-state!)
-  (when-let [result (query-dsl/query test-helper/test-db s)]
-    (map first (deref result))))
-
-(deftest sort-result-for-standard-columns
-  ;; Define since it's not defined
-  (state/set-preferred-language! "en")
-
-  (testing "sort by block column"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/title %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/title %) result) sort-state))
-         {:sort-desc? true :sort-by-column :block}
-         ["abc" "cde"] ["cde" "abc"]
-
-         {:sort-desc? false :sort-by-column :block}
-         ["abc" "cde"] ["abc" "cde"]))
-
-  (testing "sort by page column"
-    (are [sort-options result sorted-result]
-         (= sorted-result
-            (#'query-table/sort-result result sort-options))
-         ;; on page queries
-         {:sort-desc? true :sort-by-column :page :page? true}
-         (map #(hash-map :block/name %) ["abc" "cde"])
-         (map #(hash-map :block/name %) ["cde" "abc"])
-
-         ;; on block queries
-         {:sort-desc? true :sort-by-column :page :page? false}
-         (map #(hash-map :block/page {:block/name %}) ["abc" "cde"])
-         (map #(hash-map :block/page {:block/name %}) ["cde" "abc"]))))
-
-(deftest sort-result-for-property-columns
-  ;; Define since it's not defined
-  (state/set-preferred-language! "en")
-
-  (testing "sort by integer block property"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :integer}
-         [{:integer 8} {:integer 7} {:integer 77} {:integer 0} {:integer -8}]
-         [{:integer 77} {:integer 8} {:integer 7} {:integer 0} {:integer -8}]
-
-         {:sort-desc? false :sort-by-column :integer}
-         [{:integer 8} {:integer 7} {:integer 77} {:integer 0} {:integer -8}]
-         [{:integer -8} {:integer 0} {:integer 7} {:integer 8} {:integer 77}]))
-
-  (testing "sort by boolean block property"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :funny?}
-         [{:funny? true} {:funny? false}] [{:funny? true} {:funny? false}]
-
-         {:sort-desc? false :sort-by-column :funny?}
-         [{:funny? true} {:funny? false}] [{:funny? false} {:funny? true}]))
-
-  (testing "sort by string block property"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :title}
-         [{:title "abc"} {:title "cde"}] [{:title "cde"} {:title "abc"}]
-
-         {:sort-desc? false :sort-by-column :title}
-         [{:title "abc"} {:title "cde"}] [{:title "abc"} {:title "cde"}]))
-
-  (testing "sort by mixed type block property"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :title}
-         [{:title 1} {:title "A"} {:title 2} {:title "B"} {:title 11} {:title "C"}]
-         [{:title "C"} {:title "B"} {:title "A"} {:title 11} {:title 2} {:title 1}]
-
-         {:sort-desc? false :sort-by-column :title}
-         [{:title 1} {:title "A"} {:title 2} {:title "B"} {:title 11} {:title "C"}]
-         [{:title 1} {:title 2} {:title 11} {:title "A"} {:title "B"} {:title "C"}]))
-
-  (testing "sort by decimal number block property"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :title}
-         [{:title 1.1} {:title 1.2} {:title 1.11}]
-         [{:title 1.2} {:title 1.11} {:title 1.1}]
-
-         {:sort-desc? false :sort-by-column :title}
-         [{:title 1.1} {:title 1.2} {:title 1.11}]
-         [{:title 1.1} {:title 1.11} {:title 1.2}]))
-
-  (testing "sort by semver-style string block property"
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :title}
-         [{:title "1.1.0"} {:title "1.2.0"} {:title "1.11.0"} {:title "1.1.1"} {:title "1.11.1"} {:title "1.2.1"}]
-         [{:title "1.11.1"} {:title "1.11.0"} {:title "1.2.1"} {:title "1.2.0"} {:title "1.1.1"} {:title "1.1.0"}]
-
-         {:sort-desc? false :sort-by-column :title}
-         [{:title "1.1.0"} {:title "1.2.0"} {:title "1.11.0"} {:title "1.1.1"} {:title "1.11.1"} {:title "1.2.1"}]
-         [{:title "1.1.0"} {:title "1.1.1"} {:title "1.2.0"} {:title "1.2.1"} {:title "1.11.0"} {:title "1.11.1"}]))
-
-  (testing "sort by string block property for specific locale"
-    (state/set-preferred-language! "zh-CN")
-    (are [sort-state result sorted-result]
-         (= (mapv #(hash-map :block/properties %) sorted-result)
-            (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))
-         {:sort-desc? true :sort-by-column :title}
-         [{:title "意志"} {:title "圆圈"}] [{:title "圆圈"} {:title "意志"}]
-
-         {:sort-desc? false :sort-by-column :title}
-         [{:title "圆圈"} {:title "意志"}] [{:title "意志"} {:title "圆圈"}])
-    (state/set-preferred-language! "en")))
-
-(deftest sort-result-performance
-  (testing "monitor time of sort by integer block property"
-    (are [sort-state result _sorted-result timeout]
-         (>= timeout (:time (util/with-time (#'query-table/sort-result (mapv #(hash-map :block/properties %) result) sort-state))))
-      {:sort-desc? true :sort-by-column :rating}
-      [{:rating 8} {:rating 7}] [{:rating 8} {:rating 7}]
-         2.0 ;; actual: ~0.05
-
-      {:sort-desc? false :sort-by-column :rating}
-      [{:rating 8} {:rating 7}] [{:rating 7} {:rating 8}]
-      2.0 ;; actual: ~0.05
-      )))
-
-(deftest build-column-value
-  (load-test-files [{:file/path "pages/page1.md"
-                     :file/content "prop:: a
-- b1
-- b2
-prop:: b"}])
-  (testing "for :page"
-    (is (= ["page1" "page1"]
-           (->> (dsl-query "(property prop)")
-                (map #(#'query-table/build-column-value % :page {:page? false}))
-                (map second)))
-        "Page columns have valid value for blocks")
-
-    (is (= ["page1"]
-           (->> (dsl-query "(page-property prop)")
-                (map #(#'query-table/build-column-value % :page {:page? true}))
-                (map second)))
-        "Page columns have valid value for pages")))

+ 0 - 85
src/test/frontend/extensions/zotero/extractor_test.cljs

@@ -1,85 +0,0 @@
-(ns frontend.extensions.zotero.extractor-test
-  (:require [clojure.edn :as edn]
-            [clojure.test :as test :refer [deftest is testing are]]
-            [shadow.resource :as rc]
-            [frontend.extensions.zotero.extractor :as extractor]))
-
-(def data
-  (-> (rc/inline "fixtures/zotero.edn")
-      (edn/read-string)))
-
-(deftest extract-test
-  (testing "journal article"
-    (let [{:keys [page-name properties]}
-          (extractor/extract (:journal-article-sample-1 data))]
-
-      (testing "page name prefer citation key"
-        (is (= "@efroniHowCombineTreeSearch2019" page-name)))
-
-      (testing "convert date"
-        (is (= "[[Feb 17th, 2019]]" (-> properties :date))))
-
-      (testing "convert date"
-        (is (= "[[Feb 17th, 2019]]" (-> properties :date))))
-
-      (testing "original title"
-        (is (= "How to Combine Tree-Search Methods in Reinforcement Learning" (-> properties :original-title))))
-
-      (testing "double quote when containing comma"
-        (is (= "\"arXiv:1809.01843 [cs, stat]\"" (-> properties :publication-title))))
-
-      (testing "skip when containing newline"
-        (is (nil? (-> properties :extra))))))
-
-  (testing "another journal article"
-    (let [{:keys [_page-name properties]}
-          (extractor/extract (:journal-article-sample-2 data))
-          authors (count (-> properties :authors))
-          tags    (count (-> properties :tags))]
-
-      (testing "authors"
-        (is (= 8 authors)))
-
-      (testing "tags"
-        ;; tags split by `,` are counted into different tags
-        ;; https://github.com/logseq/logseq/commit/435c2110bcc2d30ed743ba31375450f1a705b00b
-        (is (= 20 tags)))))
-
-  (testing "book"
-    (let [{:keys [page-name properties]}
-          (extractor/extract (:book-sample-1 data))]
-
-      (testing "page name"
-        (is (= "@1984" page-name)))
-
-      (testing "author"
-        (is (= '("George Orwell") (-> properties :authors))))
-
-      (testing "preserve unparsable date"
-        (is (= "1984" (-> properties :date))))))
-
-  (testing "newpaper article"
-    (let [{:keys [_page-name properties]}
-          (extractor/extract (:newspaper-article-sample-1 data))]
-      (is (= "A Letter to Our Readers About Digital Subscriptions" (-> properties :original-title)))
-
-      (testing "use parsed date when possible"
-        (is (= "[[Mar 28th, 2011]]" (-> properties :date))))))
-  
-  (testing "zotero imported file path"
-    (are [item-key filename open] (= (extractor/zotero-imported-file-macro item-key filename) open)
-      "9AUD8MNT" "a.pdf" "{{zotero-imported-file 9AUD8MNT, \"a.pdf\"}}"))
-
-  (testing "zotero linked file path"
-    (are [path open] (= (extractor/zotero-linked-file-macro path) open)
-      ;; TODO provide some real samples on multiple platforms
-      "attachments:abc/def/ghi.pdf" "{{zotero-linked-file \"abc/def/ghi.pdf\"}}"
-      ;; Chinese and blank
-      "attachments:书籍/人民邮电出版社/NSCA-CPT美国国家体能协会私人教练认证指南 第2版.pdf" "{{zotero-linked-file \"书籍/人民邮电出版社/NSCA-CPT美国国家体能协会私人教练认证指南 第2版.pdf\"}}"))
-
-;; 2022.10.18. Should be deprecated since Hickory is invalid in Node test
-;; Skip until we find an alternative
-;;   (testing "note"
-;;     (let [result (extractor/extract (:note-sample-1 data))]
-;;       (is (str/starts-with? result "This study shows"))))
-)

+ 0 - 40
src/test/frontend/handler/editor_test.cljs

@@ -50,28 +50,6 @@
           "[[https://github.com/logseq/logseq][logseq]] is #awesome :)" 0 editor/url-regex))
       "Finds url in org link correctly"))
 
-(defn- set-marker
-  "Spied version of editor/set-marker"
-  [marker content format]
-  (let [actual-content (atom nil)]
-    (with-redefs [editor/save-block-if-changed! (fn [_ content]
-                                                  (reset! actual-content content))]
-      (editor/set-marker {:block/marker marker :block/title content :block/format format})
-      @actual-content)))
-
-(deftest set-marker-org
-  (are [marker content expect] (= expect (set-marker marker content :org))
-    "TODO" "TODO content" "DOING content"
-    "TODO" "** TODO content" "** DOING content"
-    "TODO" "## TODO content" "DOING ## TODO content"
-    "DONE" "DONE content" "content"))
-
-(deftest set-marker-markdown
-  (are [marker content expect] (= expect (set-marker marker content :markdown))
-    "TODO" "TODO content" "DOING content"
-    "TODO" "## TODO content" "## DOING content"
-    "DONE" "DONE content" "content"))
-
 (defn- keyup-handler
   "Spied version of editor/keyup-handler"
   [{:keys [value cursor-pos action commands]
@@ -235,21 +213,6 @@
   ;; Reset state
   (state/set-editor-action! nil))
 
-(deftest save-block-aux!
-  (load-test-files [{:file/path "pages/page1.md"
-                     :file/content "\n
-- b1 #foo"}])
-  (testing "updating block's content changes content"
-    (let [conn (db/get-db test-helper/test-db false)
-          block (->> (d/q '[:find (pull ?b [*])
-                            :where [?b :block/title "b1 #foo"]]
-                          @conn)
-                     ffirst)
-         ;; Use same options as edit-box-on-change!
-          _ (editor/save-block-aux! block "b12 #foo" {:skip-properties? true})
-          updated-block (d/pull @conn '[*] [:block/uuid (:block/uuid block)])]
-      (is (= "b12 #foo" (:block/title updated-block)) "Content updated correctly"))))
-
 (deftest save-block!
   (testing "Saving blocks with and without properties"
     (test-helper/load-test-files [{:file/path "foo.md"
@@ -260,8 +223,5 @@
       (editor/save-block! repo block-uuid "# bar")
       (is (= "# bar" (:block/title (model/query-block-by-uuid block-uuid))))
 
-      (editor/save-block! repo block-uuid "# foo" {:properties {:foo "bar"}})
-      (is (= "# foo\nfoo:: bar" (:block/title (model/query-block-by-uuid block-uuid))))
-
       (editor/save-block! repo block-uuid "# bar")
       (is (= "# bar" (:block/title (model/query-block-by-uuid block-uuid)))))))

+ 0 - 104
src/test/frontend/handler/file_based/page_property_test.cljs

@@ -1,104 +0,0 @@
-(ns frontend.handler.file-based.page-property-test
-  (:require [cljs.test :refer [are deftest testing]]
-            [frontend.handler.file-based.page-property :as file-page-property]))
-
-(deftest test-insert-property
-  (testing "add org page property"
-    (are [x y] (= x y)
-      (file-page-property/insert-property :org "" :title "title")
-      "#+title: title"
-
-      (file-page-property/insert-property :org "hello" :title "title")
-      "#+title: title\nhello"
-
-      (file-page-property/insert-property :org "#+title: title\nhello" :title "new title")
-      "#+title: new title\nhello"
-
-      (file-page-property/insert-property :org "#+title: title\nhello" :alias "alias1")
-      "#+alias: alias1\n#+title: title\nhello"
-
-      (file-page-property/insert-property :org "#+title: title\n#+alias: alias1\nhello" :alias "alias2")
-      "#+title: title\n#+alias: alias2\nhello"
-
-      (file-page-property/insert-property :org "#+title: title\n#+alias: alias1, alias2\nhello" :alias "alias3")
-      "#+title: title\n#+alias: alias3\nhello"))
-
-  (testing "add markdown page property"
-    (are [x y] (= x y)
-      (file-page-property/insert-property :markdown "" :title "title")
-      "title:: title"
-
-      (file-page-property/insert-property :markdown "hello" :title "title")
-      "title:: title\nhello"
-
-      (file-page-property/insert-property :markdown "title:: title\nhello" :title "new title")
-      "title:: new title\nhello"
-
-      (file-page-property/insert-property :markdown "title:: title\nhello" :alias "alias1")
-      "alias:: alias1\ntitle:: title\nhello"
-
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1\nhello" :alias "alias2")
-      "title:: title\nalias:: alias2\nhello"
-
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1, alias2\nhello" :alias "alias3")
-      "title:: title\nalias:: alias3\nhello"
-
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1, alias2\nhello" :aliases "aliases1")
-      "aliases:: aliases1\ntitle:: title\nalias:: alias1, alias2\nhello"
-
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1, alias2\naliases:: aliases1\nhello" :aliases "aliases2")
-      "title:: title\nalias:: alias1, alias2\naliases:: aliases2\nhello")))
-
-(deftest test-insert-properties
-  (testing "add org page properties"
-    (are [x y] (= x y)
-
-      (file-page-property/insert-properties :org "" {:title "title"})
-      "#+title: title"
-
-      (file-page-property/insert-properties :org "hello" {:title "title"})
-      "#+title: title\nhello"
-
-      (file-page-property/insert-properties :org "#+title: title\nhello"
-                                  {:title "new title"
-                                   :alias "alias1"})
-      "#+alias: alias1\n#+title: new title\nhello"
-
-      (file-page-property/insert-properties :org "#+title: title\n#+alias: alias1\nhello"
-                                  {:title "new title"
-                                   :alias "alias2"
-                                   :aliases "aliases1"})
-      "#+aliases: aliases1\n#+title: new title\n#+alias: alias2\nhello"
-
-      (file-page-property/insert-properties :org "#+title: title\n#+alias: alias1, alias2\n#+aliases: aliases1\nhello"
-                                  {:title "new title"
-                                   :alias "alias2"
-                                   :aliases "aliases1"})
-      "#+title: new title\n#+alias: alias2\n#+aliases: aliases1\nhello"))
-
-  (testing "add markdown page properties"
-    (are [x y] (= x y)
-      (file-page-property/insert-properties :markdown "" {:title "title"})
-      "title:: title"
-
-      (file-page-property/insert-properties :markdown "hello" {:title "title"})
-      "title:: title\nhello"
-
-      (file-page-property/insert-properties :markdown "title:: title\nhello"
-                                  {:title "new title"
-                                   :alias "alias1"})
-      "alias:: alias1\ntitle:: new title\nhello"
-
-      (file-page-property/insert-properties :markdown "title:: title\nalias:: alias1\nhello"
-                                  {:title "new title"
-                                   :alias "alias2"
-                                   :aliases "aliases1"})
-      "aliases:: aliases1\ntitle:: new title\nalias:: alias2\nhello"
-
-      (file-page-property/insert-properties :markdown "title:: title\nalias:: alias1, alias2\naliases:: aliases1\nhello"
-                                  {:title "new title"
-                                   :alias "alias2"
-                                   :aliases "aliases1"})
-      "title:: new title\nalias:: alias2\naliases:: aliases1\nhello")))
-
-#_(cljs.test/run-tests)

+ 0 - 76
src/test/frontend/handler/repo_test.cljs

@@ -1,76 +0,0 @@
-(ns frontend.handler.repo-test
-  (:require ["fs" :as fs]
-            ["path" :as node-path]
-            [cljs.test :refer [deftest use-fixtures testing is]]
-            [clojure.edn :as edn]
-            [datascript.core :as d]
-            [frontend.db.conn :as conn]
-            [frontend.db.model :as model]
-            [frontend.handler.file-based.repo :as file-repo-handler]
-            [frontend.test.helper :as test-helper :refer [load-test-files]]
-            [frontend.worker.state :as worker-state]
-            [logseq.common.util.block-ref :as block-ref]
-            [logseq.graph-parser.cli :as gp-cli]
-            [logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper]))
-
-(use-fixtures :each test-helper/start-and-destroy-db)
-
-(deftest ^:integration parse-and-load-files-to-db
-  (let [graph-dir "src/test/docs-0.10.12"
-        _ (docs-graph-helper/clone-docs-repo-if-not-exists graph-dir "v0.10.12")
-        repo-config (edn/read-string (str (fs/readFileSync (node-path/join graph-dir "logseq/config.edn"))))
-        files (#'gp-cli/build-graph-files graph-dir repo-config)
-        _ (with-redefs [worker-state/get-config (constantly repo-config)]
-            (file-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)]
-
-    (docs-graph-helper/docs-graph-assertions db graph-dir (map :file/path files))
-    (testing "Additional Counts"
-      (is (= 58149 (count (d/datoms db :eavt))) "Correct datoms count")
-
-      (is (= 2065
-             (ffirst
-              (d/q '[:find (count ?b)
-                     :where [?b :block/refs ?bp] [?bp :block/name]] db)))
-          "Correct referenced blocks count"))))
-
-(deftest parse-files-and-load-to-db-with-block-refs-on-reload
-  (testing "Refs to blocks on a page are retained if that page is reloaded"
-    (let [test-uuid "16c90195-6a03-4b3f-839d-095a496d9acd"
-          target-page-content (str "- target block\n  id:: " test-uuid)
-          referring-page-content (str "- " (block-ref/->block-ref test-uuid))]
-      (load-test-files [{:file/path "pages/target.md"
-                         :file/content target-page-content}
-                        {:file/path "pages/referrer.md"
-                         :file/content referring-page-content}])
-      (is (= [(parse-uuid test-uuid)] (model/get-all-referenced-blocks-uuid)))
-
-      (load-test-files [{:file/path "pages/target.md"
-                         :file/content target-page-content}])
-      (is (= [(parse-uuid test-uuid)] (model/get-all-referenced-blocks-uuid))))))
-
-(deftest parse-files-and-load-to-db-with-page-rename
-  (testing
-   "Reload a file when the disk contents result in the file having a new page name"
-    (let [test-uuid "16c90195-6a03-4b3f-839d-095a496d9efc"
-          target-page-content (str "- target block\n  id:: " test-uuid)
-          referring-page-content (str "- " (block-ref/->block-ref test-uuid))
-          update-referring-page-content (str "title:: updatedPage\n- " (block-ref/->block-ref test-uuid))
-          get-page-block-count (fn [page-name]
-                                 (let [page-id (:db/id (model/get-page page-name))]
-                                   (if (some? page-id)
-                                     (model/get-page-blocks-count test-helper/test-db page-id)
-                                     0)))]
-      (load-test-files [{:file/path "pages/target.md"
-                         :file/content target-page-content}
-                        {:file/path "pages/referrer.md"
-                         :file/content referring-page-content}])
-      (is (= [(parse-uuid test-uuid)] (model/get-all-referenced-blocks-uuid)))
-      (is (= 1 (get-page-block-count "referrer")))
-      (is (= 0 (get-page-block-count "updatedPage")))
-
-      (load-test-files [{:file/path "pages/referrer.md"
-                         :file/content update-referring-page-content}])
-      (is (= [(parse-uuid test-uuid)] (model/get-all-referenced-blocks-uuid)))
-      (is (= 0 (get-page-block-count "referrer")))
-      (is (= 2 (get-page-block-count "updatedPage"))))))

+ 70 - 0
src/test/frontend/test/file.cljs

@@ -0,0 +1,70 @@
+(ns frontend.test.file
+  "Provides util handler fns for file graph files"
+  (:refer-clojure :exclude [load-file])
+  (:require [frontend.db :as db]
+            [frontend.db.file-based.model :as file-model]
+            [frontend.handler.common.config-edn :as config-edn-common-handler]
+            [frontend.handler.global-config :as global-config-handler]
+            [frontend.schema.handler.global-config :as global-config-schema]
+            [frontend.schema.handler.repo-config :as repo-config-schema]
+            [frontend.test.file.reset :as file-reset]
+            [frontend.util :as util]
+            [logseq.common.path :as path]
+            [logseq.common.util :as common-util]))
+
+(defn reset-file!
+  [repo file-path content opts]
+  (when util/node-test?
+    (file-reset/reset-file! repo (db/get-db repo false) file-path content opts)))
+
+(defn- detect-deprecations
+  [path content]
+  (when (or (= path "logseq/config.edn")
+            (= (path/dirname path) (global-config-handler/safe-global-config-dir)))
+    (config-edn-common-handler/detect-deprecations path content {:db-graph? false})))
+
+(defn- validate-file
+  "Returns true if valid and if false validator displays error message. Files
+  that are not validated just return true"
+  [path content]
+  (cond
+    (= path "logseq/config.edn")
+    (config-edn-common-handler/validate-config-edn path content repo-config-schema/Config-edn)
+
+    (= (path/dirname path) (global-config-handler/safe-global-config-dir))
+    (config-edn-common-handler/validate-config-edn path content global-config-schema/Config-edn)
+
+    :else
+    true))
+
+(defn alter-file-test-version
+  "Test version of alter-file that is synchronous"
+  [repo path content {:keys [reset? from-disk? new-graph? verbose
+                             ctime mtime]
+                      :fs/keys [event]
+                      :or {reset? true
+                           from-disk? false}}]
+  (let [path (common-util/path-normalize path)
+        config-file? (= path "logseq/config.edn")
+        _ (when config-file?
+            (detect-deprecations path content))
+        config-valid? (and config-file? (validate-file path content))]
+    (when (or config-valid? (not config-file?)) ; non-config file or valid config
+      (let [opts {:new-graph? new-graph?
+                  :from-disk? from-disk?
+                  :fs/event event
+                  :ctime ctime
+                  :mtime mtime}
+            result (if reset?
+                     (do
+                       (when-let [page-id (file-model/get-file-page-id path)]
+                         (db/transact! repo
+                                       [[:db/retract page-id :block/alias]
+                                        [:db/retract page-id :block/tags]]
+                                       opts))
+                       (reset-file!
+                        repo path content (merge opts
+                                                         ;; To avoid skipping the `:or` bounds for keyword destructuring
+                                                 (when (some? verbose) {:verbose verbose}))))
+                     (db/set-file-content! repo path content opts))]
+        result))))

+ 1 - 1
src/main/frontend/worker/file/reset.cljs → src/test/frontend/test/file/reset.cljs

@@ -1,4 +1,4 @@
-(ns frontend.worker.file.reset
+(ns frontend.test.file.reset
   "Fns for resetting a db file with parsed file content"
   (:require [clojure.string :as string]
             [datascript.core :as d]

+ 6 - 6
src/test/frontend/test/helper.cljs

@@ -8,9 +8,8 @@
             [frontend.db.conn :as conn]
             [frontend.handler.db-based.property :as db-property-handler]
             [frontend.handler.editor :as editor-handler]
-            [frontend.handler.file-based.repo :as file-repo-handler]
-            [frontend.handler.file-based.status :as status]
             [frontend.state :as state]
+            [frontend.test.repo :as file-repo-handler]
             [frontend.worker.handler.page :as worker-page]
             [frontend.worker.pipeline :as worker-pipeline]
             [logseq.db :as ldb]
@@ -20,6 +19,9 @@
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.graph-parser.text :as text]))
 
+(def bare-marker-pattern
+  #"(NOW|LATER|TODO|DOING|DONE|WAITING|WAIT|CANCELED|CANCELLED|IN-PROGRESS){1}\s+")
+
 (def node? (exists? js/process))
 
 (def test-db-name "test-db")
@@ -115,7 +117,7 @@
            (rest blocks**)]
           [nil blocks**])
         blocks
-        (mapv #(if-let [status (some-> (second (re-find status/bare-marker-pattern (:block/title %)))
+        (mapv #(if-let [status (some-> (second (re-find bare-marker-pattern (:block/title %)))
                                        file-to-db-statuses)]
                  (-> %
                      (assoc :block/tags [{:db/ident :logseq.class/Task}])
@@ -175,9 +177,7 @@ This can be called in synchronous contexts as no async fns should be invoked"
     (load-test-files-for-db-graph files)
     (file-repo-handler/parse-files-and-load-to-db!
      test-db
-     files
-   ;; Set :refresh? to avoid creating default files in after-parse
-     {:re-render? false :verbose false :refresh? true})))
+     files)))
 
 (defn initial-test-page-and-blocks
   [& {:keys [page-uuid]}]

+ 46 - 0
src/test/frontend/test/repo.cljs

@@ -0,0 +1,46 @@
+(ns frontend.test.repo
+  "Repo fns for creating, loading and parsing file graphs"
+  (:require [frontend.state :as state]
+            [frontend.test.file :as file-handler]
+            [logseq.graph-parser :as graph-parser]))
+
+(defn- parse-and-load-file-test-version!
+  "Accept: .md, .org, .edn, .css"
+  [repo-url file {:keys [new-graph? verbose]}]
+  (try
+    (let [result (file-handler/alter-file-test-version
+                  repo-url
+                  (:file/path file)
+                  (:file/content file)
+                  (merge (:stat file)
+                         {:new-graph? new-graph?
+                          :re-render-root? false
+                          :from-disk? true}
+                         ;; To avoid skipping the `:or` bounds for keyword destructuring
+                         (when (some? verbose) {:verbose verbose})))]
+      (state/set-parsing-state! (fn [m]
+                                  (update m :finished inc)))
+      result)
+    (catch :default e
+      (println "Parse and load file failed: " (str (:file/path file)))
+      (js/console.error e)
+      (state/set-parsing-state! (fn [m]
+                                  (update m :failed-parsing-files conj [(:file/path file) e])))
+      (state/set-parsing-state! (fn [m]
+                                  (update m :finished inc))))))
+
+(defn- parse-files-and-create-default-files-inner!
+  [repo-url files]
+  (let [supported-files (graph-parser/filter-files files)]
+    (state/set-current-repo! repo-url)
+    (state/set-parsing-state! {:total (count supported-files)})
+    ;; Synchronous for tests for not breaking anything
+    (doseq [file supported-files]
+      (state/set-parsing-state! (fn [m]
+                                  (assoc m
+                                         :current-parsing-file (:file/path file))))
+      (parse-and-load-file-test-version! repo-url file {}))))
+
+(defn parse-files-and-load-to-db!
+  [repo-url files]
+  (parse-files-and-create-default-files-inner! repo-url files))

+ 0 - 28
src/test/frontend/util/marker_test.cljs

@@ -1,28 +0,0 @@
-(ns frontend.util.marker-test
-  (:require [cljs.test :refer [are deftest]]
-            [frontend.handler.file-based.status :as status]))
-
-(deftest add-or-update-marker-markdown
-  (are [content marker expect] (= expect (status/add-or-update-marker content :markdown marker))
-    "test content" "TODO" "TODO test content"
-    "\nxxx\n" "TODO" "TODO xxx\n"
-    "## xxx" "TODO" "## TODO xxx"
-    "## [#A] xxx" "TODO" "## TODO [#A] xxx"
-    "" "TODO" "TODO "
-    "todo" "TODO" "TODO todo"
-    "TODO xxx" "DONE" "DONE xxx"
-    "TODO" "DONE" "DONE "
-    "## TODO [#A] xxx" "DONE" "## DONE [#A] xxx"
-    "#test content" "TODO" "TODO #test content"
-    "TODO #test content" "DONE" "DONE #test content"))
-
-(deftest add-or-update-marker-org
-  (are [content marker expect] (= expect (status/add-or-update-marker content :org marker))
-    "test content" "TODO" "TODO test content"
-    "\nxxx\n" "TODO" "TODO xxx\n"
-    "" "TODO" "TODO "
-    "todo" "TODO" "TODO todo"
-    "TODO xxx" "DONE" "DONE xxx"
-    "TODO" "DONE" "DONE "))
-
-#_(cljs.test/run-tests)

+ 0 - 130
src/test/frontend/util/property_test.cljs

@@ -1,130 +0,0 @@
-(ns frontend.util.property-test
-  (:require [cljs.test :refer [are deftest testing]]
-            [frontend.handler.file-based.property.util :as property-util]
-            [logseq.graph-parser.property :as gp-property]))
-
-(deftest remove-id-property
-  (testing "org"
-    (are [x y] (= (property-util/remove-id-property :org x) y)
-      "hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\n:END:\n"
-      "hello\n:PROPERTIES:\n:END:"
-
-      "hello\n:PROPERTIES:\n:id: f9873a81-07b9-4246-b910-53a6f5ec7e04\na: b\n:END:\n"
-      "hello\n:PROPERTIES:\na: b\n:END:"))
-  (testing "markdown"
-    (are [x y] (= (property-util/remove-id-property :markdown x) y)
-      "hello\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04"
-      "hello"
-
-      "hello\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04\n\nworld"
-      "hello\n\nworld"
-
-      "hello\naa:: bb\nid:: f9873a81-07b9-4246-b910-53a6f5ec7e04\n\nworld"
-      "hello\naa:: bb\n\nworld")))
-
-(deftest test-remove-empty-properties
-  (testing "remove properties if it is empty. Available in orgmode"
-    (are [x y] (= (property-util/remove-empty-properties x) y)
-      "* TODO properties demo\nabcd"
-      "* TODO properties demo\nabcd"
-
-      "* TODO properties demo\n:PROPERTIES:\n:END:\nabcd"
-      "* TODO properties demo\nabcd"
-
-      "* TODO properties demo\n:PROPERTIES:\n:END:\n\n\nabcd"
-      "* TODO properties demo\nabcd"
-
-      "* TODO properties demo\n:PROPERTIES:\n\n:END:\n\n\nabcd"
-      "* TODO properties demo\nabcd")))
-
-(deftest test-get-property-keys
-  (testing "org mode"
-    (are [x y] (= x y)
-        (#'property-util/get-property-keys :org "hello\n:PROPERTIES:\n:x1: y1\n:x2: y2\n:END:\n")
-        ["X1" "X2"]
-
-        (#'property-util/get-property-keys :org "hello\n:PROPERTIES:\n:END:\n")
-        nil))
-  (testing "markdown mode"
-    (are [x y] (= x y)
-        (#'property-util/get-property-keys :markdown "hello\nx1:: y1\nx2:: y2\n")
-        ["X1" "X2"]
-
-        (#'property-util/get-property-keys :markdown "hello\n")
-        nil)))
-
-(deftest test-build-properties-str
-  (are [x y] (= (#'gp-property/build-properties-str :mardown x) y)
-    {:title "a"}
-    "title:: a\n"
-    {:title "a/b/c"}
-    "title:: a/b/c\n"
-    {:title "a/b/c" :tags "d,e"}
-    "title:: a/b/c\ntags:: d,e\n")
-  (are [x y] (= (#'gp-property/build-properties-str :org x) y)
-    {:title "a"}
-    ":PROPERTIES:\n:title: a\n:END:"
-    {:title "a/b/c"}
-    ":PROPERTIES:\n:title: a/b/c\n:END:"
-    {:title "a/b/c" :tags "d,e"}
-    ":PROPERTIES:\n:title: a/b/c\n:tags: d,e\n:END:"))
-
-(deftest test-with-built-in-properties
-  (let [content "#+BEGIN_QUERY\n{:title      \"cool NEXT\"\n    :query      [:find (pull ?h [*])\n                 :in $ ?start ?next\n                 :where\n                 [?h :block/marker ?marker]\n                 [(contains? #{\"NOW\" \"LATER\" \"TODO\"} ?marker)]\n                 [?h :block/ref-pages ?p]\n                [?p :block/journal-day ?d]\n                 [(> ?d ?start)]\n                 [(< ?d ?next)]]\n    :inputs     [:today :7d-after]\n    :collapsed? false}\n#+END_QUERY"]
-    (let [md-property "query-table:: true"]
-      (are [x y] (= (property-util/with-built-in-properties {:query-table true} x :markdown) y)
-       content
-       (str md-property "\n" content)
-
-       "title"
-       (str "title\n" md-property)
-
-       "title\nbody"
-       (str "title\n" md-property "\nbody")
-
-       "1. list"
-       (str md-property "\n1. list")))
-
-    (let [org-property ":PROPERTIES:\n:query-table: true\n:END:"]
-      (are [x y] (= (property-util/with-built-in-properties {:query-table true} x :org) y)
-        content
-        (str org-property "\n" content)
-
-        "title"
-        (str "title\n" org-property)
-
-        "title\nbody"
-        (str "title\n" org-property "\nbody")
-
-        "1. list"
-        (str org-property "\n1. list")))))
-
-(deftest get-visible-ordered-properties
-  (testing "basic cases"
-    (are [x y expected] (= expected (property-util/get-visible-ordered-properties x y {}))
-      ;; returns in property order
-      {:prop "val" :prop2 "val2"} [:prop2 :prop]
-      [[:prop2 "val2"] [:prop "val"]]
-      ;; returns empty non-nil value if properties is non-nil
-      {} [:prop]
-      '()
-      ;; returns nil if properties is nil
-      nil []
-      nil))
-
-  (testing "hidden properties"
-    (are [x y z expected] (= expected (property-util/get-visible-ordered-properties x y z))
-      ;; page block
-      {:logseq.order-list-type "number" :foo "bar"}  [:logseq.order-list-type :foo] {:pre-block false}
-      [[:foo "bar"]]
-      ;; normal block
-      {:logseq.order-list-type "number" :foo "bar"}  [:logseq.order-list-type :foo] {:pre-block false}
-      [[:foo "bar"]]))
-
-  (testing "hidden editable properties"
-    (are [x y z expected] (= expected (property-util/get-visible-ordered-properties x y z))
-      ;; page block
-      {:title "foo"} [:title] {:pre-block? true :page-id 1}
-      '()
-      {:title "foo" :foo "bar"} [:title :foo] {:pre-block? true :page-id 1}
-      [[:foo "bar"]])))