 (ns konserve.indexeddb
-  #_(:require [incognito.edn :refer [read-string-safe]]
+  (:require [incognito.edn :refer [read-string-safe]]
             [konserve.core :as k]
             [konserve.serializers :as ser]
-            [konserve.protocols :refer [PEDNAsyncKeyValueStore -exists? -get-in -update-in
-                                        PJSONAsyncKeyValueStore -jget-in -jassoc-in -jupdate-in
+            [konserve.protocols :refer [PEDNAsyncKeyValueStore -exists? -get -update-in -assoc-in -get-meta
                                         PBinaryAsyncKeyValueStore -bget -bassoc
-                                        -serialize -deserialize]]
+                                        PStoreSerializer -serialize -deserialize]]
             [cljs.core.async :as async :refer (take! <! >! put! close! chan poll!)])
-  #_(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
-
-#_(comment 
-  (defrecord IndexedDBKeyValueStore [db store-name serializer read-handlers write-handlers locks]
+  (:require-macros [cljs.core.async.macros :refer [go go-loop]]))
+
+
+  (defrecord IndexedDBKeyValueStore [db store-name serializer read-handlers write-handlers locks version]
     PEDNAsyncKeyValueStore
     (-exists? [this key]
-      (let [res (chan)
-            tx (.transaction db #js [store-name])
-            obj-store (.objectStore tx store-name)
-            req (.openCursor obj-store (pr-str key))]
+      (let [res       (chan)
+            tx        (.transaction db #js [store-name])
+            obj-store (.objectStore tx store-name)
+            req       (.openCursor obj-store (pr-str key))]
         (set! (.-onerror req)
               (fn [e]
                 (put! res (ex-info "Cannot check for existence."
-                                   {:type :access-error
-                                    :key key
+                                   {:type  :access-error
+                                    :key   key
                                     :error (.-target e)}))
                 (close! res)))
         (set! (.-onsuccess req)

                                               :read-handlers
                                               (atom {'konserve.indexeddb.Test
                                                      map->Test})))))
    ;; or
    (-jassoc-in my-store ["test" "bar"] #js {:a 3})
    (go (println (<! (-jget-in my-store ["test"]))))

           (<! (-update-in my-store [i] (fn [_] (inc i)))))
         #_(doseq [i (range 10)]
             (println (<! (-get-in my-store [i]))))))
    (go (println (<! (-get my-store 999))))

    (go (prn (<! (-update-in my-store ["foo"] (fn [_] {:meta "META"}) (fn [_] 0) []))))

    (go (prn (<! (-update-in my-store ["foo"] (fn [_] {:meta "META"}) inc []))))

    (go (println (<! (-get-meta my-store "foo"))))

    (go (println (<! (-get my-store "foo"))))


    (go (println (<! (-assoc-in my-store ["rec-test"] (Test. 5)))))
    (go (println (<! (-get my-store "rec-test"))))

    (go (println (<! (-assoc-in my-store ["test2"] {:a 1 :b 4.2}))))

    (go (println (<! (-assoc-in my-store ["test"] {:a 43}))))

    (go (println (<! (-update-in my-store ["test" :a] inc))))
    (go (println (<! (-get my-store "test2"))))


    (go (println (<! (-bassoc my-store
                              "blob-fun"
                              (fn [_] "my meta")
                              (new js/Blob #js ["hello worlds"], #js {"type" "text/plain"})))))

    (go (println (<! (-get-meta my-store "blob-fun"))))

    (go (.log js/console (<! (-bget my-store "blob-fun" identity))))


    )
