specs restructuring

integration-tests
Josha von Gizycki 5 years ago
parent 2086fc9757
commit 874af1eecf

1
.gitignore vendored

@ -16,3 +16,4 @@ neo4j/*
resources/public/js/out resources/public/js/out
.rebel_readline_history .rebel_readline_history
/elm-stuff /elm-stuff
*.*~

@ -1,35 +1,24 @@
(ns wanijo.instance.domain (ns wanijo.instance.domain
(:require [clojure.spec.alpha :as spec] (:require [clojure.spec.alpha :as spec]
[wanijo.specs :as specs]
[wanijo.framework.neo4j :as neo4j] [wanijo.framework.neo4j :as neo4j]
[wanijo.schema.domain :as domain-schema] [wanijo.schema.domain :as domain-schema]
[wanijo.attribute.domain :as domain-attr])) [wanijo.attribute.domain :as domain-attr]))
(spec/def ::created-at ::neo4j/date-str)
(spec/def ::created_at ::neo4j/date-str)
(spec/def ::updated-at ::neo4j/date-str)
(spec/def ::updated_at ::neo4j/date-str)
(spec/def ::name string?)
(spec/def ::value
(spec/or :string string?
:bool boolean?
:nil nil?
:number number?))
(spec/def ::instance_uuid ::neo4j/uuid)
(spec/def ::attribute_uuid ::neo4j/uuid)
(spec/def ::instance (spec/def ::instance
(spec/keys :req-un [::neo4j/uuid (spec/keys :req-un [::neo4j/uuid
::created_at ::specs/created_at
::updated_at ::specs/updated_at
::name])) ::specs/name]))
(spec/def ::properties (spec/def ::properties
(spec/coll-of (spec/coll-of
(spec/keys :req-un [::neo4j/uuid (spec/keys :req-un [::neo4j/uuid
::created_at ::specs/created_at
::updated_at ::specs/updated_at
::domain-attr/attribute]))) ::domain-attr/attribute])))
(spec/def ::link (spec/def ::link
(spec/keys :req-un [::neo4j/uuid (spec/keys :req-un [::neo4j/uuid
::created_at ::specs/created_at
::name])) ::name]))
(spec/def ::target ::instance) (spec/def ::target ::instance)
(spec/def ::source ::instance) (spec/def ::source ::instance)
@ -46,15 +35,14 @@
(spec/def ::tags (spec/def ::tags
(spec/coll-of (spec/coll-of
(spec/keys :req-un [::neo4j/uuid (spec/keys :req-un [::neo4j/uuid
::name ::specs/name
::created-at]))) ::specs/created_at])))
(neo4j/defquery findy-by-schema (neo4j/defquery findy-by-schema
"MATCH (i:instance)-[:of]->(s:schema) "MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid} WHERE s.uuid = {uuid}
RETURN i RETURN i
ORDER BY i.name") ORDER BY i.name")
(defn find-by-schema! [schema-uuid] (defn find-by-schema! [schema-uuid]
(map :i (map :i
(neo4j/exec-query! (neo4j/exec-query!
@ -69,7 +57,6 @@
SET i.name = {name}, SET i.name = {name},
i.created_at = {created_at}, i.created_at = {created_at},
i.updated_at = {created_at}") i.updated_at = {created_at}")
(neo4j/defquery create-property (neo4j/defquery create-property
"MATCH (i:instance {uuid:{uuid}}), "MATCH (i:instance {uuid:{uuid}}),
(a:attribute {uuid:{attr_uuid}}) (a:attribute {uuid:{attr_uuid}})
@ -78,7 +65,6 @@
SET p.value = {value}, SET p.value = {value},
p.created_at = {created_at}, p.created_at = {created_at},
p.updated_at = {updated_at}") p.updated_at = {updated_at}")
(defn create! [user-uuid schema-uuid instance] (defn create! [user-uuid schema-uuid instance]
(let [instance-uuid (neo4j/uuid) (let [instance-uuid (neo4j/uuid)
now (neo4j/now-str) now (neo4j/now-str)
@ -100,16 +86,14 @@
(concat [instance-tuple] (concat [instance-tuple]
prop-tuples)))) prop-tuples))))
(neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}})
-[:of]->(s:schema)
RETURN i, s")
(spec/def ::instance-with-schema (spec/def ::instance-with-schema
(spec/and ::instance (spec/and ::instance
(spec/keys :req-un (spec/keys :req-un
[::domain-schema/schema]))) [::domain-schema/schema])))
(neo4j/defquery find-by-uuid
"MATCH (i:instance {uuid:{uuid}})
-[:of]->(s:schema)
RETURN i, s")
(defn find-by-uuid! [uuid] (defn find-by-uuid! [uuid]
{:post [(spec/assert ::instance-with-schema %)]} {:post [(spec/assert ::instance-with-schema %)]}
(->> (neo4j/exec-query! find-by-uuid (->> (neo4j/exec-query! find-by-uuid
@ -125,7 +109,6 @@
(p)-[:of]->(a:attribute) (p)-[:of]->(a:attribute)
RETURN p, a RETURN p, a
ORDER BY a.name") ORDER BY a.name")
(defn find-properties! [uuid] (defn find-properties! [uuid]
(map #(assoc (:p %) (map #(assoc (:p %)
:attribute :attribute
@ -133,6 +116,15 @@
(neo4j/exec-query! find-properties (neo4j/exec-query! find-properties
{:uuid uuid}))) {:uuid uuid})))
(spec/def ::prop-tuple-values
(spec/keys :req-un [::neo4j/uuid
::specs/now
::value
::specs/instance_uuid
::specs/attribute_uuid]))
(spec/def ::prop-tuple
(spec/coll-of
(spec/tuple fn? ::prop-tuple-values)))
(neo4j/defquery edit-instance (neo4j/defquery edit-instance
"MATCH (i:instance {uuid:{uuid}}) "MATCH (i:instance {uuid:{uuid}})
SET i.name = {name}, SET i.name = {name},
@ -147,16 +139,6 @@
p.value = {value} p.value = {value}
ON MATCH SET p.updated_at = {now}, ON MATCH SET p.updated_at = {now},
p.value = {value}") p.value = {value}")
(spec/def ::now ::neo4j/date-str)
(spec/def ::prop-tuple-values
(spec/keys :req-un [::neo4j/uuid
::now
::value
::instance_uuid
::attribute_uuid]))
(spec/def ::prop-tuple
(spec/coll-of
(spec/tuple fn? ::prop-tuple-values)))
(defn instance->prop-tuples [instance] (defn instance->prop-tuples [instance]
{:post [(spec/assert ::prop-tuple %)]} {:post [(spec/assert ::prop-tuple %)]}
(map (fn [prop] (map (fn [prop]
@ -263,9 +245,9 @@
(spec/def ::full-instance (spec/def ::full-instance
(spec/and ::instance-with-schema (spec/and ::instance-with-schema
(spec/keys ::req-un [::neo4j/uuid (spec/keys ::req-un [::neo4j/uuid
::created-at ::specs/created-at
::updated-at ::specs/updated-at
::name ::specs/name
::properties ::properties
::links-out ::links-out
::links-in ::links-in

@ -0,0 +1,10 @@
(ns wanijo.specs
(:require [clojure.spec.alpha :as spec]
[wanijo.framework.neo4j :as neo4j]))
(spec/def ::created_at ::neo4j/date-str)
(spec/def ::updated_at ::neo4j/date-str)
(spec/def ::name string?)
(spec/def ::instance_uuid ::neo4j/uuid)
(spec/def ::attribute_uuid ::neo4j/uuid)
(spec/def ::now ::neo4j/date-str)
Loading…
Cancel
Save