mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 22:25:01 +00:00
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:
19
scripts/src/logseq/tasks/spec.clj
Normal file
19
scripts/src/logseq/tasks/spec.clj
Normal 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!")))
|
||||
Reference in New Issue
Block a user