From 23b4441b82b1355ca433292b8a093a4b66ed44cc Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sun, 27 Aug 2023 11:33:24 +0200 Subject: [PATCH] [nop] [ctx-filter] Drop obsolete `ns-pattern` concept --- src/taoensso/encore/ctx_filter.cljc | 54 +++++++++++++++-------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/taoensso/encore/ctx_filter.cljc b/src/taoensso/encore/ctx_filter.cljc index 79b10632..d6b48571 100644 --- a/src/taoensso/encore/ctx_filter.cljc +++ b/src/taoensso/encore/ctx_filter.cljc @@ -74,33 +74,36 @@ ;;;; Filter -(let [ns-compile (fn [nsp] (enc/compile-str-filter (or nsp :any))) - ns-conform? (fn [nsp ns] ((ns-compile nsp) ns)) +(let [ns-compile (fn [nsf] (enc/compile-str-filter (or nsf :any))) + ns-conform? (fn [nsf ns] ((ns-compile nsf) ns)) ns->min-level (fn [spec ns] - ;; Spec: [[ ] ... [\"*\" ]] + ;; Spec: [[ ] ... [\"*\" ]] (enc/rsome - (fn [[ns-pattern level]] - (when (ns-conform? ns-pattern ns) + (fn [[nsf level]] + (when (ns-conform? nsf ns) (valid-level-int level))) spec))] - (defn valid-ns-pattern - "Returns valid ns-pattern, or throws." + (defn valid-ns-filter + "Returns valid ns-filter, or throws." [x] (if-let [t (enc/catching (do (ns-compile x) nil) t t)] (throw - (ex-info "[encore/ctx-filter] Invalid namespace pattern" - {:ns-pattern {:value x, :type (type x)}} + (ex-info + (if (fn? x) + "[encore/ctx-filter] Invalid namespace filter (fn filters no longer supported)" + "[encore/ctx-filter] Invalid namespace filter") + {:ns-filter {:value x, :type (type x)}} t)) x)) (defn ^:no-doc #?(:clj -filtered? :cljs ^boolean -filtered?) "Low-level uncached util. Prefer `filtered?`." - [ns-pattern min-level ns level] + [ns-filter min-level ns level] (or ;; Check ns - (if (nil? ns-pattern) false (if ^boolean (ns-conform? ns-pattern ns) false true)) + (if (nil? ns-filter) false (if ^boolean (ns-conform? ns-filter ns) false true)) ;; Check level (if (nil? min-level) @@ -128,9 +131,9 @@ (if (vector? x) (do (enc/run! - (fn [[ns-pattern level]] - (valid-ns-pattern ns-pattern) - (valid-level level)) + (fn [[ns-filter level]] + (valid-ns-filter ns-filter) + (valid-level level)) x) x) (valid-level x))) @@ -138,38 +141,37 @@ (defn update-min-level "TODO Docstring ns, old, new may be nil" - ([old-level new-level] (update-min-level old-level nil new-level)) - ([old-level ns-pattern new-level] - (if-not ns-pattern + ([old-level new-level] (update-min-level old-level nil new-level)) + ([old-level ns-filter new-level] + (if (nil? ns-filter) (when new-level (valid-min-level new-level)) ;; Update namespace-specific level - (let [new-level (when new-level (valid-level new-level)) - ns-pattern (valid-ns-pattern ns-pattern) + (let [new-level (when new-level (valid-level new-level)) + ns-filter (valid-ns-filter ns-filter) old-vec (if (vector? old-level) old-level (if old-level [["*" (valid-level old-level)]] [])) new-vec (reduce ; Remove any pre-existing [ _] or [#{} _] entries - (fn [acc [ns-pattern* _level :as entry]] + (fn [acc [ns-filter* _level :as entry]] (if-let [exact-match? (or - (= ns-pattern* ns-pattern) - (= ns-pattern* #{ns-pattern}))] - + (= ns-filter* ns-filter) + (= ns-filter* #{ns-filter}))] (do acc) ; Remove entry (conj acc entry) ; Retain entry )) (if new-level - [[ns-pattern new-level]] ; Insert new-level entry at head + [[ns-filter new-level]] ; Insert new-level entry at head []) old-vec)] (if-let [simplified ; [["*" :info]] -> :info (when (= (count new-vec) 1) - (let [[[ns-pattern level]] new-vec] - (when (contains? #{"*" :any} ns-pattern) + (let [[[ns-filter level]] new-vec] + (when (contains? #{"*" :any} ns-filter) level)))] simplified (not-empty new-vec))))))