Offline-first key-value store with atom interface (swap!, deref, add-watch) that syncs to a SQLite-backed server over Transit. Server (CLJ): - SQLite storage with Nippy serialization preserving all Clojure types - GET /sync?group=G&since=T pull endpoint with prefix-based groups - POST /sync push endpoint with per-document version checking - Conflict detection (stale write rejection) - Token-based auth with per-user group access - CORS support, soft deletes, purge compaction Client (CLJS): - IndexedDB wrapper with Transit serialization - SyncedAtom implementing IAtom (IDeref, ISwap, IReset, IWatchable) - Write-through to IndexedDB on every swap! - Background sync loop (pull + push) with configurable interval - Online/offline detection with reconnect sync - Conflict resolution (accept server value) - ready? channel for initial load - Custom cache atom support (Reagent ratom compatible) 25 tests, 77 assertions across db, transit, server, and auth.
38 lines
1.1 KiB
Clojure
38 lines
1.1 KiB
Clojure
(ns pocketbook.transit-test
|
|
(:require [clojure.test :refer [deftest is testing]]
|
|
[pocketbook.transit :as t]))
|
|
|
|
(deftest roundtrip-basic-types
|
|
(doseq [v [42
|
|
"hello"
|
|
:keyword
|
|
true
|
|
nil
|
|
[1 2 3]
|
|
{:a 1 :b {:c 2}}
|
|
#{1 2 3}]]
|
|
(is (= v (t/decode (t/encode v)))
|
|
(str "Roundtrip failed for: " (pr-str v)))))
|
|
|
|
(deftest roundtrip-clojure-types
|
|
(let [uuid (java.util.UUID/randomUUID)
|
|
inst #inst "2026-04-04T10:00:00Z"]
|
|
(is (= uuid (t/decode (t/encode uuid))))
|
|
(is (= inst (t/decode (t/encode inst))))))
|
|
|
|
(deftest roundtrip-complex-structure
|
|
(let [data [{:id "todo:1"
|
|
:value {:text "Buy milk" :tags #{:groceries :urgent}}
|
|
:version 3
|
|
:updated 1743760800000}
|
|
{:id "todo:2"
|
|
:deleted true
|
|
:version 5}]]
|
|
(is (= data (t/decode (t/encode data))))))
|
|
|
|
(deftest encode-str-roundtrip
|
|
(let [v {:hello "world" :nums [1 2 3]}
|
|
s (t/encode-str v)]
|
|
(is (string? s))
|
|
(is (= v (t/decode s)))))
|