             [konserve.core :as k]
             [hasch.core :refer [uuid]]
             [konserve.serializers :as ser]
-            [konserve.protocols :refer [PEDNAsyncKeyValueStore -exists?
--get-in -update-in
-                                        PJSONAsyncKeyValueStore
--jget-in -jassoc-in -jupdate-in
-                                        PBinaryAsyncKeyValueStore -bget
--bassoc
+            [konserve.protocols :refer [PEDNAsyncKeyValueStore -exists? -get-in -update-in -assoc-in -dissoc
+                                        PJSONAsyncKeyValueStore -jget-in -jassoc-in -jupdate-in
+                                        PBinaryAsyncKeyValueStore -bget -bassoc
                                         -serialize -deserialize]]
-            [cljs.core.async :as async :refer (take! <! >! put! close!
-chan poll!)])
+            [cljs.core.async :as async :refer (take! <! >! put! close! chan poll!)])
   (:require-macros [cljs.core.async.macros :refer [go go-loop]]))
 
 (defonce fs (node/require "fs"))

(defn delete-store
  "Permanently deletes the folder of the store with all files."
  [folder]
  (if (fs.existsSync folder)
    (try
      (doseq [path [(str folder "/meta") (str folder "/data") folder]]
        (when (fs.existsSync path)
          (doseq [file (fs.readdirSync path)]
            (let [file-path (str path "/" file)]
              (when (fs.existsSync file-path)
                (if (.isDirectory (fs.statSync file-path))
                  (fs.rmdirSync file-path)
                  (fs.unlinkSync file-path)))))))
      (catch js/Object err
        (println err))
      (finally
        (fs.rmdirSync folder)))
    "folder not exists"))

(defn check-and-create-folder
  "Creates Folder with given path."
  [path]
  (let [test-file (str path "/" (random-uuid))]
    (try
      (when-not (fs.existsSync path)
        (fs.mkdirSync path))
      (fs.writeFileSync test-file "test-data")
      (fs.unlinkSync test-file)
      (catch js/Object err
        (println err)))))

(defrecord FileSystemNodejsStore
    [folder serializer read-handlers write-handlers locks config]
  PEDNAsyncKeyValueStore
  (-exists? [this key]
    (let [fn  (uuid key)
          f   (str folder "/data/" key)
          res (chan)]
      (put! res (fs.existsSync f))
      (close! res)
      res)))

(defn new-fs-store
  "Filestore contains a Key and a Data Folder"

                   write-handlers (atom {})
                   serializer     (ser/string-serializer)
                   config {:fsync true}}}]
  (println "creating store")
  (let [_         (check-and-create-folder path)
        _         (check-and-create-folder (str path "/meta"))
        _         (check-and-create-folder (str path "/data"))]
    (println "creating system")
    (go (map->FileSystemNodejsStore {:folder         path
                                     :serializer     serializer
                                     :read-handlers  read-handlers
