|
9 | 9 | ::args args |
10 | 10 | ::optargs optargs}) |
11 | 11 |
|
12 | | -#?(:clj |
13 | | - (do |
14 | | - (declare parse-term) |
15 | | - |
16 | | - (defn snake-case-keys [m] |
17 | | - (into {} |
18 | | - (for [[k v] m] |
19 | | - [(snake-case k) v]))) |
20 | | - |
21 | | - (defmulti parse-arg |
22 | | - (fn [arg] |
23 | | - (cond |
24 | | - (::term arg) :query |
25 | | - (or (sequential? arg) (seq? arg)) :sequential |
26 | | - (map? arg) :map |
27 | | - (= (type arg) #?(:clj org.joda.time.DateTime :cljs js/Date)) :time |
28 | | - (= (type arg) #?(:clj java.util.UUID :cljs UUID)) :uuid))) |
29 | | - |
30 | | - (defmethod parse-arg :query [arg] |
31 | | - (parse-term arg)) |
32 | | - |
33 | | - (defmethod parse-arg :sequential [arg] |
34 | | - (parse-term (term :MAKE_ARRAY arg))) |
35 | | - |
36 | | - (defmethod parse-arg :map [arg] |
37 | | - (zipmap (keys arg) (map parse-arg (vals arg)))) |
38 | | - |
39 | | - (defmethod parse-arg :time [arg] |
40 | | - (parse-term (term :EPOCH_TIME [(c/to-epoch arg)]))) |
41 | | - |
42 | | - (defmethod parse-arg :uuid [arg] |
43 | | - (str arg)) |
44 | | - |
45 | | - (defmethod parse-arg :default [arg] |
46 | | - arg) |
47 | | - |
48 | | - (defn parse-term [{term ::term args ::args optargs ::optargs}] |
49 | | - (filter |
50 | | - identity |
51 | | - [(tt->int term) |
52 | | - (map parse-arg (seq args)) |
53 | | - (if optargs (snake-case-keys optargs))])) |
54 | | - |
55 | | - (defn parse-query |
56 | | - ([type] |
57 | | - [(qt->int type)]) |
58 | | - ([type term] |
59 | | - [(qt->int type) (parse-term term)])))) |
| 12 | +(declare parse-term) |
| 13 | + |
| 14 | +(defn snake-case-keys [m] |
| 15 | + (into {} |
| 16 | + (for [[k v] m] |
| 17 | + [(snake-case k) v]))) |
| 18 | + |
| 19 | +(defmulti parse-arg |
| 20 | + (fn [arg] |
| 21 | + (cond |
| 22 | + (::term arg) :query |
| 23 | + (or (sequential? arg) (seq? arg)) :sequential |
| 24 | + (map? arg) :map |
| 25 | + (= (type arg) #?(:clj org.joda.time.DateTime :cljs js/Date)) :time |
| 26 | + (= (type arg) #?(:clj java.util.UUID :cljs UUID)) :uuid))) |
| 27 | + |
| 28 | +(defmethod parse-arg :query [arg] |
| 29 | + (parse-term arg)) |
| 30 | + |
| 31 | +(defmethod parse-arg :sequential [arg] |
| 32 | + (parse-term (term :MAKE_ARRAY arg))) |
| 33 | + |
| 34 | +(defmethod parse-arg :map [arg] |
| 35 | + (zipmap (keys arg) (map parse-arg (vals arg)))) |
| 36 | + |
| 37 | +(defmethod parse-arg :time [arg] |
| 38 | + (parse-term (term :EPOCH_TIME [#?(:clj (c/to-epoch arg) |
| 39 | + :cljs (.getTime arg))]))) |
| 40 | + |
| 41 | +(defmethod parse-arg :uuid [arg] |
| 42 | + (str arg)) |
| 43 | + |
| 44 | +(defmethod parse-arg :default [arg] |
| 45 | + arg) |
| 46 | + |
| 47 | +(defn parse-term [{term ::term args ::args optargs ::optargs}] |
| 48 | + (filter |
| 49 | + identity |
| 50 | + [(tt->int term) |
| 51 | + (map parse-arg (seq args)) |
| 52 | + (if optargs (snake-case-keys optargs))])) |
| 53 | + |
| 54 | +(defn parse-query |
| 55 | + ([type] |
| 56 | + [(qt->int type)]) |
| 57 | + ([type term] |
| 58 | + [(qt->int type) (parse-term term)])) |
0 commit comments