Skip to content

Commit

Permalink
Refactor specs so that we can include fonda.core.specs only
Browse files Browse the repository at this point in the history
  • Loading branch information
arichiardi committed Apr 13, 2020
1 parent c8d7c91 commit 2555004
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
23 changes: 5 additions & 18 deletions src/fonda/core/specs.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns fonda.core.specs
(:require [clojure.spec.alpha :as s]
[fonda.execute.specs :as execute]
[fonda.step.specs :as step]))

(def name-s (s/or :string string?
Expand All @@ -17,20 +18,6 @@
(s/def ::exception-handlers ::handlers-map)
(s/def ::callbacks-wrapper-fn (s/nilable fn?))

(s/def ::on-success some?)
(s/def ::on-exception some?)
(s/def ::on-anomaly (s/nilable any?))

(s/def ::step-name-map
(s/keys :opt-un [::name]))

(s/def ::step
(s/or :tap (s/merge ::step/tap-step ::step-name-map)
:processor (s/merge ::step/processor-step ::step-name-map)
:injector (s/merge ::step/injector-step ::step-name-map)))

(s/def ::steps (s/coll-of ::step))

(s/def ::config
(s/keys :opt-un [::anomaly?
::mock-fns
Expand All @@ -41,7 +28,7 @@

(s/fdef fonda.core/execute
:args (s/cat :config ::config
:steps ::steps
:on-exception ::on-exception
:on-success ::on-success
:on-anomaly (s/? ::on-anomaly)))
:steps ::step/steps
:on-exception :execute/on-exception
:on-success :execute/on-success
:on-anomaly (s/? :execute/on-anomaly)))
34 changes: 26 additions & 8 deletions src/fonda/execute/specs.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns fonda.execute.specs
(:require [clojure.spec.alpha :as s]
[fonda.step.specs :as step]
[fonda.core.specs :as core]))
[fonda.step.specs :as step]))

(s/def ::js-error #(instance? js/Error %))

Expand Down Expand Up @@ -32,24 +31,43 @@
(s/def ::exception (s/nilable ::js-error))
(s/def ::anomaly (s/nilable any?))

(s/def ::on-success some?)
(s/def ::on-exception some?)
(s/def ::on-anomaly (s/nilable any?))

(s/def ::fonda-context-async some?)

(s/def ::fonda-context-sync
(s/keys :req-un [::core/ctx
::core/on-success
::core/on-exception
(s/keys :req-un [::ctx
::on-success
::on-exception
::queue
::stack]
:opt-un [::anomaly-handlers
::exception-handlers
::core/on-anomaly
::on-anomaly
::anomaly-fn
::exception
::anomaly]))

(s/def ::fonda-context (s/or :async ::fonda-context-async
:sync ::fonda-context-sync))

(s/def ::config
(s/keys :req-un [::step/steps
::on-success
::on-exception
::on-anomaly]
:opt-un [::anomaly?
::mock-fns
::ctx
::anomaly-handlers
::exception-handlers
::callbacks-wrapper-fn]))

(s/fdef fonda.execute/fonda-context
:args (s/cat :config ::config))

(s/fdef fonda.execute/execute-steps
:args (s/cat :fonda-ctx ::fonda-context))

Expand All @@ -61,7 +79,7 @@

(s/fdef fonda.execute/try-step
:args (s/cat :fonda-ctx ::fonda-context
:step ::step))
:step ::step/step))

(s/fdef fonda.execute/assoc-processor-result
:args (s/cat :fonda-ctx ::fonda-context
Expand All @@ -74,4 +92,4 @@

(s/fdef fonda.execute/assoc-injector-result
:args (s/cat :fonda-ctx ::fonda-context
:res (s/nilable (s/or :step ::core/step :steps ::core/steps))))
:res (s/nilable (s/or :step ::step/step :steps ::step/steps))))
10 changes: 10 additions & 0 deletions src/fonda/step/specs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@
(s/def ::inject (s/or :function fn? :qualified-keyword qualified-keyword?))
(s/def ::injector-step
(s/keys :req-un [::inject]))

(s/def ::step-name-map
(s/keys :opt-un [::name]))

(s/def ::step
(s/or :tap (s/merge ::tap-step ::step-name-map)
:processor (s/merge ::processor-step ::step-name-map)
:injector (s/merge ::injector-step ::step-name-map)))

(s/def ::steps (s/coll-of ::step))
3 changes: 1 addition & 2 deletions test/fonda/core_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require [cljs.test :refer-macros [deftest is testing async use-fixtures]]
[fonda.core :as fonda]
[fonda.core.specs]
[fonda.execute.specs]
[orchestra-cljs.spec.test :as orchestra]))

(orchestra/instrument)
Expand Down Expand Up @@ -819,4 +818,4 @@
(done))}
[processor]
on-exception-event
success-cb-throw)))))
success-cb-throw)))))

0 comments on commit 2555004

Please sign in to comment.