Files
logseq/scripts/src/logseq/tasks/spec.clj
Gabriel Horner 0ccbe4d046 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>
2022-04-01 15:46:52 +08:00

20 lines
804 B
Clojure

(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!")))