diff --git a/.gitignore b/.gitignore index fac1c5f..e84b3bc 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ neo4j/* resources/public/js/out .rebel_readline_history /elm-stuff +*.*~ diff --git a/src/wanijo/instance/domain.clj b/src/wanijo/instance/domain.clj index d8bf6a6..74da9a1 100644 --- a/src/wanijo/instance/domain.clj +++ b/src/wanijo/instance/domain.clj @@ -1,35 +1,24 @@ (ns wanijo.instance.domain (:require [clojure.spec.alpha :as spec] + [wanijo.specs :as specs] [wanijo.framework.neo4j :as neo4j] [wanijo.schema.domain :as domain-schema] [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/keys :req-un [::neo4j/uuid - ::created_at - ::updated_at - ::name])) + ::specs/created_at + ::specs/updated_at + ::specs/name])) (spec/def ::properties (spec/coll-of (spec/keys :req-un [::neo4j/uuid - ::created_at - ::updated_at + ::specs/created_at + ::specs/updated_at ::domain-attr/attribute]))) (spec/def ::link (spec/keys :req-un [::neo4j/uuid - ::created_at + ::specs/created_at ::name])) (spec/def ::target ::instance) (spec/def ::source ::instance) @@ -46,15 +35,14 @@ (spec/def ::tags (spec/coll-of (spec/keys :req-un [::neo4j/uuid - ::name - ::created-at]))) + ::specs/name + ::specs/created_at]))) (neo4j/defquery findy-by-schema "MATCH (i:instance)-[:of]->(s:schema) WHERE s.uuid = {uuid} RETURN i ORDER BY i.name") - (defn find-by-schema! [schema-uuid] (map :i (neo4j/exec-query! @@ -69,7 +57,6 @@ SET i.name = {name}, i.created_at = {created_at}, i.updated_at = {created_at}") - (neo4j/defquery create-property "MATCH (i:instance {uuid:{uuid}}), (a:attribute {uuid:{attr_uuid}}) @@ -78,7 +65,6 @@ SET p.value = {value}, p.created_at = {created_at}, p.updated_at = {updated_at}") - (defn create! [user-uuid schema-uuid instance] (let [instance-uuid (neo4j/uuid) now (neo4j/now-str) @@ -100,16 +86,14 @@ (concat [instance-tuple] prop-tuples)))) -(neo4j/defquery find-by-uuid - "MATCH (i:instance {uuid:{uuid}}) - -[:of]->(s:schema) - RETURN i, s") - (spec/def ::instance-with-schema (spec/and ::instance (spec/keys :req-un [::domain-schema/schema]))) - +(neo4j/defquery find-by-uuid + "MATCH (i:instance {uuid:{uuid}}) + -[:of]->(s:schema) + RETURN i, s") (defn find-by-uuid! [uuid] {:post [(spec/assert ::instance-with-schema %)]} (->> (neo4j/exec-query! find-by-uuid @@ -125,7 +109,6 @@ (p)-[:of]->(a:attribute) RETURN p, a ORDER BY a.name") - (defn find-properties! [uuid] (map #(assoc (:p %) :attribute @@ -133,6 +116,15 @@ (neo4j/exec-query! find-properties {: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 "MATCH (i:instance {uuid:{uuid}}) SET i.name = {name}, @@ -147,16 +139,6 @@ p.value = {value} ON MATCH SET p.updated_at = {now}, 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] {:post [(spec/assert ::prop-tuple %)]} (map (fn [prop] @@ -263,9 +245,9 @@ (spec/def ::full-instance (spec/and ::instance-with-schema (spec/keys ::req-un [::neo4j/uuid - ::created-at - ::updated-at - ::name + ::specs/created-at + ::specs/updated-at + ::specs/name ::properties ::links-out ::links-in diff --git a/src/wanijo/specs.clj b/src/wanijo/specs.clj new file mode 100644 index 0000000..ee39408 --- /dev/null +++ b/src/wanijo/specs.clj @@ -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)