Added normalize

main
Clemens 10 months ago
parent 69d93a99ff
commit 7ae7c9b070

@ -54,7 +54,7 @@ Maps to
(s/def ::id
(s/and
...
::xsd/anyURI))
(sh/seq-spec ::xsd/anyURI)))
```
## **rdfs:domain**

@ -24,12 +24,21 @@
{k (first (normalize-value v))}
:else {k (normalize-value v)})))
(defn-spec serialize string?
(defn-spec normalize string?
[spec s/spec?
as-map map?]
(let [speced-map (assert (s/valid? spec as-map))]
(let [normalized-map (walk/walk normalize-functional-property identity as-map)]
(do
(assert (s/valid? spec normalized-map))
normalized-map)))
(defn-spec serialize string?
[spec s/spec?
normalized-map map?]
(do
(assert (s/valid? spec normalized-map))
(json/write-str
(merge
{(keyword "@context") "https://www.w3.org/ns/activitystreams"}
(walk/walk normalize-functional-property identity speced-map))
normalized-map)
:escape-slash false)))

@ -6,22 +6,42 @@
[org.domaindrivenarchitecture.activity-pub-poc.activitystreams2 :as as]
[org.domaindrivenarchitecture.activity-pub-poc.core :as sut]))
(def tmp )
(deftest should-normalize
(is (= {::as/id "http://example.org/likes/1"
::as/summary "Sally liked a note",
::as/type ["Like"],
::as/actor {::as/id "http://example.org/persons/1"
::as/type "Person",
::as/name "Sally"},
::as/object "http://example.org/notes/1"}
(sut/normalize
::as/Like
{::as/id ["http://example.org/likes/1"]
::as/summary "Sally liked a note",
::as/type ["Like"],
::as/actor {::as/id ["http://example.org/persons/1"]
::as/type "Person",
::as/name "Sally"},
::as/object "http://example.org/notes/1"}))))
(deftest should-serialize
(is (= (str "{\"@context\":\"https://www.w3.org/ns/activitystreams\","
"\"id\":\"http://example.org/likes/1\","
"\"summary\":\"Sally liked a note\","
"\"type\":\"Like\","
"\"actor\":{"
"\"id\":\"http://example.org/persons/1\","
"\"type\":\"Person\","
"\"name\":\"Sally\"},"
"\"object\":\"http://example.org/notes/1\"}")
(sut/serialize
::as/Like
{::as/id ["http://example.org/likes/1"]
::as/summary "Sally liked a note",
::as/type "Like",
::as/actor {::as/id ["http://example.org/persons/1"]
::as/type "Person",
::as/name "Sally"},
::as/object "http://example.org/notes/1"}))))
(is (= (str "{\"@context\":\"https://www.w3.org/ns/activitystreams\","
"\"id\":\"http://example.org/likes/1\","
"\"summary\":\"Sally liked a note\","
"\"type\":[\"Like\"],"
"\"actor\":{"
"\"id\":\"http://example.org/persons/1\","
"\"type\":\"Person\","
"\"name\":\"Sally\"},"
"\"object\":\"http://example.org/notes/1\"}")
(sut/serialize
::as/Like
{::as/id "http://example.org/likes/1"
::as/summary "Sally liked a note",
::as/type ["Like"],
::as/actor {::as/id "http://example.org/persons/1"
::as/type "Person",
::as/name "Sally"},
::as/object "http://example.org/notes/1"}))))
Loading…
Cancel
Save