claro.middleware.transform
Generic middlewares to transform resolution results.
wrap-transform
(wrap-transform engine transform-fn)
(wrap-transform engine predicate transform-fn)
Middleware that will pass any Resolvable
that matches Predicate
– as well as the resolved result – to transform-fn
and use its return value in place of the actual result.
For example, to inject the current timestamp into each Person
record:
(def run-engine
(-> (engine/engine)
(wrap-transform
#(instance? Person %)
#(assoc %2 :__timestamp (System/currentTimeMillis)))))
If no predicate
is given, all Resolvable
values will be transformed.
wrap-transform-by-class
(wrap-transform-by-class engine classes-to-transform transformer-fn)
Middleware that will pass any Resolvable
of one of the given classes-to-transform
– as well as the resolved result – to transform-fn
and use its return value in place of the actual result.
For example, to inject the current timestamp into each Person
record:
(def run-engine
(-> (engine/engine)
(wrap-transform-classes
[Person]
#(assoc %2 :__timestamp (System/currentTimeMillis)))))