Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/sg/flybot/pullable.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

(def ^:dynamic *data-schema* nil)

#?(:clj
(try
(require 'sg.flybot.pullable.schema)
(def check-pattern! (ns-resolve 'sg.flybot.pullable.schema 'check-pattern!))
(catch Exception e
(defn check-pattern! [data-schema pattern]))))

(defn query
"Returns a query function from `pattern`. A query function can be used to extract information
from data. Query function takes `data` as its single argument, if data matches the pattern,
Expand Down Expand Up @@ -51,11 +58,7 @@
(query pattern nil))
([pattern context]
#?(:clj
#_{:clj-kondo/ignore [:unresolved-namespace]}
(util/optional-require
sg.flybot.pullable.schema/check-pattern!
(sg.flybot.pullable.schema/check-pattern! *data-schema* pattern)
nil))
(check-pattern! *data-schema* pattern))
(fn [data]
(-> context
core/query-maker
Expand Down Expand Up @@ -133,4 +136,4 @@
(macroexpand-1 '(with-schema nil nil))
(with-data-schema [:map [:a :int]] (qfn '{:a 3})) ;=>> fn?
(with-data-schema [:map [:a :int]] (qfn '{:a "3"})) ;throws=>> some?
)
)
20 changes: 0 additions & 20 deletions src/sg/flybot/pullable/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,3 @@
(comment
(named-lvar? 3) ;=> false
(named-lvar? '?a)) ;=>> some?


;; To avoid hard dependency of malli.
;; But this not work with ClojureScript.
;; For Cljs developers, if want to use schema,
;; has to require sg.flybot.pullable.schema manually.

#?(:clj
(defmacro optional-require
"optionally try requre `require-clause`, if success, run `if-body`,
else `else-body`"
[require-clause if-body else-body]
(if
(try
(requiring-resolve require-clause)
true
(catch Exception _
false))
if-body
else-body)))