Browse Source

First pass at schema for global config

Gabriel Horner 3 years ago
parent
commit
8f5f4fc5b1

+ 3 - 0
bb.edn

@@ -66,6 +66,9 @@
   dev:validate-plugins-edn
   logseq.tasks.malli/validate-plugins-edn
 
+  dev:validate-global-config-edn
+  logseq.tasks.malli/validate-global-config-edn
+
   dev:lint
   logseq.tasks.dev/lint
 

+ 14 - 0
scripts/src/logseq/tasks/malli.clj

@@ -3,6 +3,7 @@
   (:require [malli.core :as m]
             [malli.error :as me]
             [frontend.schema.handler.plugin-config :as plugin-config-schema]
+            [frontend.schema.handler.global-config :as global-config-schema]
             [clojure.pprint :as pprint]
             [clojure.edn :as edn]))
 
@@ -18,3 +19,16 @@
       (println "Found errors:")
       (pprint/pprint errors))
     (println "Valid!")))
+
+(defn validate-global-config-edn
+  "Validate a global config.edn file"
+  [file]
+  (if-let [errors (->> file
+                       slurp
+                       edn/read-string
+                       (m/explain global-config-schema/Config-edn)
+                       me/humanize)]
+    (do
+      (println "Found errors:")
+      (pprint/pprint errors))
+    (println "Valid!")))

+ 78 - 0
src/main/frontend/schema/handler/common_config.cljc

@@ -0,0 +1,78 @@
+(ns frontend.schema.handler.common-config
+  "Schema that is common for global-config and repo-config"
+  (:require [malli.util :as mu]))
+
+(def Config-edn
+  (mu/optional-keys
+   [:map
+    [:meta/version :int]
+    ;; Loose since it looks like capitalization and string are possible
+    [:preferred-format [:or :keyword :string]]
+    [:preferred-workflow [:enum :now :todo]]
+    [:hidden [:vector :string]]
+    [:default-templates [:map-of
+                         [:enum :journals]
+                         :string]]
+    [:ui/enable-tooltip? :boolean]
+    [:feature/enable-block-timestamps? :boolean]
+    [:feature/enable-search-remove-accents? :boolean]
+    [:feature/disable-scheduled-and-deadline-query? :boolean]
+    [:start-of-week [:enum 0 1 2 3 4 5 6]]
+    [:custom-css-url :string]
+    [:export/bullet-indentation
+     [:enum :eight-spaces :four-spaces :two-spaces :tab]]
+    [:publishing/all-pages-public? :boolean]
+    [:default-home [:map
+                    [:page {:optional true} :string]
+                    [:sidebar {:optional true} [:or :string [:vector :string]]]]]
+    [:pages-directory :string]
+    [:journal-directory :string]
+    [:org-mode/insert-file-link? :boolean]
+    [:shortcuts [:map-of
+                 :keyword
+                 [:or :string [:vector :string]]]]
+    [:shortcut/doc-mode-enter-for-new-block? :boolean]
+    [:block/content-max-length :int]
+    [:ui/show-command-doc? :boolean]
+    [:ui/show-empty-bullets? :boolean]
+    [:query/views [:map-of
+                   :keyword
+                   [:sequential any?]]]
+    [:query/result-transforms [:map-of
+                               :keyword
+                               [:sequential any?]]]
+    [:default-queries [:map
+                       ;; Maybe validate these query maps later
+                       [:journals [:vector :map]]]]
+    [:commands [:vector [:tuple :string :string]]]
+    [:outliner/block-title-collapse-enabled? :boolean]
+    [:macros [:map-of
+              :string
+              :string]]
+    [:ref/default-open-blocks-level :int]
+    [:ref/linked-references-collapsed-threshold :int]
+    [:favorites [:vector :string]]
+    ;; There isn't a :float yet
+    [:srs/learning-fraction float?]
+    [:srs/initial-interval :int]
+    [:block-hidden-properties [:set :keyword]]
+    [:property-pages/enabled? :boolean]
+    [:property-pages/excludelist [:set :keyword]]
+    [:property/separated-by-commas [:set :keyword]]
+    [:logbook/settings :map]
+    [:mobile/photo [:map
+                    [:allow-editing? {:optional true} :boolean]
+                    [:quality {:optional true} :int]]]
+    [:mobile [:map
+              [:gestures/disabled-in-block-with-tags {:optional true} [:vector :string]]]]
+    [:editor/extra-codemirror-options :map]
+    [:ignored-page-references-keywords [:set :keyword]]
+    [:quick-capture-templates [:map
+                               [:text {:optional true} :string]
+                               [:media {:optional true} :string]]]
+    [:quick-capture-options [:map
+                             [:insert-today? {:optional true} :boolean]
+                             [:redirect-page? {:optional true} :boolean]]]
+    [:file-sync/ignore-files [:vector :string]]
+    [:dwim/settings [:map-of :keyword :boolean]]
+    [:file/name-format [:enum :legacy :triple-lowbar]]]))

+ 9 - 0
src/main/frontend/schema/handler/global_config.cljc

@@ -0,0 +1,9 @@
+(ns frontend.schema.handler.global-config
+  "Malli schemas for global-config"
+  (:require [frontend.schema.handler.common-config :as common-config]))
+
+;; For now this just references a common schema but repo-config and
+;; global-config could diverge
+(def Config-edn
+  "Schema for global config.edn"
+  common-config/Config-edn)