Enhance: validate local storage (#4784)

* Validate localStorage with spec

This will help get at the source of errors like #4706 quicker

* Fix settings bugs

Close #4679 as shortcut tooltip setting is now visible.
No need to js/alert when a setting is changed. Probably leftover bugging

* Add docs and example of reusing specs in bb task

Co-authored-by: Andelf <andelf@gmail.com>
This commit is contained in:
Gabriel Horner
2022-04-01 03:46:52 -04:00
committed by GitHub
parent 28d3cb4658
commit 0ccbe4d046
8 changed files with 109 additions and 5 deletions

View File

@@ -0,0 +1,19 @@
(ns logseq.tasks.spec
"Clojure spec related tasks"
(:require [clojure.spec.alpha :as s]
[cheshire.core :as json]
[frontend.spec.storage :as storage-spec]
[clojure.edn :as edn]))
;; To create file for validation, `JSON.stringify(localStorage)` in the js
;; console and copy string to file
(defn validate-local-storage
"Validate a localStorage json file"
[file]
(let [local-storage
(update-vals (json/parse-string (slurp file) keyword)
;; Not all localStorage values are edn so gracefully return.
;; For example, logseq-plugin-tabs stores data as json
#(try (edn/read-string %) (catch Throwable _ %)))]
(s/assert ::storage-spec/local-storage local-storage)
(println "Success!")))