diff --git a/src/main/cljs/dda/c4k_common/yaml.cljs b/src/main/cljs/dda/c4k_common/yaml.cljs index c8ec13b..11a39e8 100644 --- a/src/main/cljs/dda/c4k_common/yaml.cljs +++ b/src/main/cljs/dda/c4k_common/yaml.cljs @@ -3,6 +3,7 @@ ["js-yaml" :as yaml] [clojure.string :as st] [orchestra.core :refer-macros [defn-spec]] + [shadow.resource :as rc] [dda.c4k-common.predicate :as cp])) (defn-spec from-string cp/map-or-seq? @@ -10,14 +11,24 @@ (js->clj (yaml/load input) :keywordize-keys true)) -(defn-spec to-string string? +(defn-spec to-string string? [edn cp/map-or-seq?] (yaml/dump (clj->js edn))) (defn-spec dispatch-by-resource-name keyword? [resource string?] - (keyword (first (st/split resource #"/")))) + :cljs) (defmulti load-resource dispatch-by-resource-name) -(defmulti load-as-edn dispatch-by-resource-name) \ No newline at end of file +(defmethod load-resource :cljs [allowed-resources resource-name] + (if (some #(= % resource-name) allowed-resources) + (rc/inline resource-name) + (throw (js/Error. "Undefined Resource!")))) + +(defmulti load-as-edn dispatch-by-resource-name) + +(defmethod load-as-edn :cljs [resource-name] + (yaml/from-string (yaml/load-resource resource-name))) + +(defmulti allowed-resources dispatch-by-resource-name) \ No newline at end of file