From 3ce236f395a0acc45da93048f715e828ac4716f8 Mon Sep 17 00:00:00 2001 From: vhqr0 Date: Fri, 10 Oct 2025 08:26:41 +0800 Subject: [PATCH] fix check pattern import --- src/sg/flybot/pullable.cljc | 15 +++++++++------ src/sg/flybot/pullable/util.cljc | 20 -------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/sg/flybot/pullable.cljc b/src/sg/flybot/pullable.cljc index 38ab93d..6adc4d1 100644 --- a/src/sg/flybot/pullable.cljc +++ b/src/sg/flybot/pullable.cljc @@ -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, @@ -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 @@ -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? - ) \ No newline at end of file + ) diff --git a/src/sg/flybot/pullable/util.cljc b/src/sg/flybot/pullable/util.cljc index 306991c..5399301 100644 --- a/src/sg/flybot/pullable/util.cljc +++ b/src/sg/flybot/pullable/util.cljc @@ -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)))