Added normalize
This commit is contained in:
parent
69d93a99ff
commit
7ae7c9b070
3 changed files with 51 additions and 22 deletions
|
@ -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,11 +6,31 @@
|
|||
[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\","
|
||||
"\"type\":[\"Like\"],"
|
||||
"\"actor\":{"
|
||||
"\"id\":\"http://example.org/persons/1\","
|
||||
"\"type\":\"Person\","
|
||||
|
@ -18,10 +38,10 @@
|
|||
"\"object\":\"http://example.org/notes/1\"}")
|
||||
(sut/serialize
|
||||
::as/Like
|
||||
{::as/id ["http://example.org/likes/1"]
|
||||
{::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 ["Like"],
|
||||
::as/actor {::as/id "http://example.org/persons/1"
|
||||
::as/type "Person",
|
||||
::as/name "Sally"},
|
||||
::as/object "http://example.org/notes/1"}))))
|
Loading…
Reference in a new issue