Skip to content

Instantly share code, notes, and snippets.

@Jannis
Last active June 22, 2016 12:15
Show Gist options
  • Select an option

  • Save Jannis/fe48c6fd87ba9daa04e058c5a6bfbb60 to your computer and use it in GitHub Desktop.

Select an option

Save Jannis/fe48c6fd87ba9daa04e058c5a6bfbb60 to your computer and use it in GitHub Desktop.
From the `workflo/macros` properties destructuring syntax to Om Next queries with clojure.spec
boot.user=> (require 'workflo.macros.props :reload)
boot.user=> (in-ns 'workflo.macros.props)
;; Validate and parse the properties destructuring syntax using
;; `clojure.spec/conform`:
workflo.macros.props=> (s/conform ::properties-spec '[db [id] {users [user [name email]]} [current-user _]])
[[:properties {:base db, :children [[:name id]]}]
[:property [:join [:properties-join {users [user [name email]]}]]]
[:property [:link {:name current-user, :link-id _}]]]
;; The "heavy lifting" is transforming the above output of `clojure.spec/conform`
;; to something that is a little easier to work with:
workflo.macros.props=> (->> *1 (map parse-prop) (apply concat) (into []))
[{:name db/id, :type :property}
{:name users, :type :join, :join-target [{:name user/name, :type :property}
{:name user/email, :type :property}]}
{:name current-user, :type :link, :link-id _}]
;; Translate the resulting data to an Om Next query:
workflo.macros.props=> (into [] (map property-query) *1)
[:db/id {:users [:user/name :user/email]} [:current-user (quote _)]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment