diff --git a/src/main/clj/dda/c4k_common/yaml.clj b/src/main/clj/dda/c4k_common/yaml.clj index d47d631..e5ba27c 100644 --- a/src/main/clj/dda/c4k_common/yaml.clj +++ b/src/main/clj/dda/c4k_common/yaml.clj @@ -4,20 +4,22 @@ [clj-yaml.core :as yaml] [clojure.walk] [orchestra.core :refer [defn-spec]] - [orchestra.spec.test :as st])) + [dda.c4k-common.predicate :as cp])) -(defn-spec cast-lazy-seq-to-vec vector? - [lazy-seq map?] +(defn-spec resolve-lazy-sequences cp/map-or-seq? + [lazy-seq cp/map-or-seq?] (clojure.walk/postwalk #(if (instance? clojure.lang.LazySeq %) (into [] %) %) lazy-seq)) -(defn-spec from-string map? [input string?] - (cast-lazy-seq-to-vec (yaml/parse-string input))) +(defn-spec from-string cp/map-or-seq? + [input string?] + (resolve-lazy-sequences (yaml/parse-string input))) -(defn-spec to-string string? [edn map?] +(defn-spec to-string string? + [edn cp/map-or-seq?] (yaml/generate-string edn :dumper-options {:flow-style :block})) (defn dispatch-by-resource-name @@ -27,6 +29,4 @@ (defmulti load-resource dispatch-by-resource-name) (defmethod load-resource :clj [resource-name] - (slurp (io/resource resource-name))) - -(st/instrument) \ No newline at end of file + (slurp (io/resource resource-name))) \ No newline at end of file diff --git a/src/main/cljc/dda/c4k_common/common.cljc b/src/main/cljc/dda/c4k_common/common.cljc index ee61e12..da9fc4d 100644 --- a/src/main/cljc/dda/c4k_common/common.cljc +++ b/src/main/cljc/dda/c4k_common/common.cljc @@ -2,7 +2,7 @@ (:require [clojure.walk])) -;; deprecated functions were moved to dda.c4k-common.prefixes +;; deprecated functions were moved to dda.c4k-common.predicate (defn ^{:deprecated "0.1"} bash-env-string? [input] (and (string? input) diff --git a/src/main/cljc/dda/c4k_common/postgres.cljc b/src/main/cljc/dda/c4k_common/postgres.cljc index 9adbcd4..88491fa 100644 --- a/src/main/cljc/dda/c4k_common/postgres.cljc +++ b/src/main/cljc/dda/c4k_common/postgres.cljc @@ -4,7 +4,7 @@ #?(:cljs [shadow.resource :as rc]) [dda.c4k-common.yaml :as yaml] [dda.c4k-common.base64 :as b64] - [dda.c4k-common.prefixes :as cp] + [dda.c4k-common.predicate :as cp] [dda.c4k-common.common :as cm])) (defn postgres-size? diff --git a/src/main/cljc/dda/c4k_common/prefixes.cljc b/src/main/cljc/dda/c4k_common/predicate.cljc similarity index 70% rename from src/main/cljc/dda/c4k_common/prefixes.cljc rename to src/main/cljc/dda/c4k_common/predicate.cljc index 1dd4b17..a5ffa2c 100644 --- a/src/main/cljc/dda/c4k_common/prefixes.cljc +++ b/src/main/cljc/dda/c4k_common/predicate.cljc @@ -1,4 +1,4 @@ -(ns dda.c4k-common.prefixes) +(ns dda.c4k-common.predicate) (defn bash-env-string? [input] @@ -12,4 +12,8 @@ (defn letsencrypt-issuer? [input] - (contains? #{:prod :staging} input)) \ No newline at end of file + (contains? #{:prod :staging} input)) + +(defn map-or-seq? + [input] + (or (map? input) (seq? input))) \ No newline at end of file diff --git a/src/main/cljs/dda/c4k_common/yaml.cljs b/src/main/cljs/dda/c4k_common/yaml.cljs index e768dc3..b3f467a 100644 --- a/src/main/cljs/dda/c4k_common/yaml.cljs +++ b/src/main/cljs/dda/c4k_common/yaml.cljs @@ -1,17 +1,21 @@ (ns dda.c4k-common.yaml (:require ["js-yaml" :as yaml] - [clojure.string :as st])) + [clojure.string :as st] + [orchestra.core :refer-macros [defn-spec]] + [dda.c4k-common.predicate :as cp])) -(defn from-string [input] +(defn-spec from-string cp/map-or-seq? + [input string?] (js->clj (yaml/load input) :keywordize-keys true)) -(defn to-string [edn] +(defn-spec to-string string? + [edn cp/map-or-seq?] (yaml/dump (clj->js edn))) -(defn dispatch-by-resource-name - [resource] +(defn-spec dispatch-by-resource-name keyword? + [resource string?] (keyword (first (st/split resource #"/")))) (defmulti load-resource dispatch-by-resource-name) diff --git a/src/test/clj/dda/c4k_common/yaml_test.clj b/src/test/clj/dda/c4k_common/yaml_test.clj index 6a16d50..87be0ac 100644 --- a/src/test/clj/dda/c4k_common/yaml_test.clj +++ b/src/test/clj/dda/c4k_common/yaml_test.clj @@ -1,7 +1,8 @@ (ns dda.c4k-common.yaml-test (:require [clojure.test :refer [deftest is are testing run-tests]] - [dda.c4k-common.yaml :as cut])) + [dda.c4k-common.yaml :as cut] + [orchestra.spec.test :as st])) (deftest should-dispatch-by-resource-name (is (= :clj @@ -46,3 +47,5 @@ {:serviceName "another_keycloak" :servicePort 8081}}]}}]}} (cut/from-string (cut/load-resource "test/ingress_test.yaml"))))) + +(st/instrument)