diff --git a/src/deft/core.clj b/src/deft/core.clj index ebaa22e7..8476260c 100644 --- a/src/deft/core.clj +++ b/src/deft/core.clj @@ -1,7 +1,7 @@ (ns deft.core (:require [cljs.analyzer.api :as api] - [deft.core-shared :refer :all] + [deft.core-shared :refer :all :exclude [always-instrument!]] [malli.core :as m] [malli.destructure :as md])) @@ -293,7 +293,22 @@ ~(when (contains? tagged-args :record-like) `(define-record-like-print-methods ~type-name)) - (m/=> ~(symbol (str ">" (name class-name))) + + (if @deft.core-shared/always-instrument + (def ~(symbol (str ">" (name class-name))) + (m/-instrument {:schema [:=> + ;; TODO deduplicate with above + ~(into [] + (cons :cat + (mapcat identity + (for [[field type] fields-to-types] + [(if (is-namespaced-key? field) + [:= field] + [:= (keyword (str field))]) + type])))) + ~class-name]} + ~(symbol (str ">" (name class-name))))) + (m/=> ~(symbol (str ">" (name class-name))) [:=> ;; TODO remove the order restriction once Malli improves ~(into [] @@ -304,7 +319,9 @@ [:= field] [:= (keyword (str field))]) type])))) - ~class-name])))) + ~class-name])) + + ))) @@ -340,4 +357,6 @@ (def get-deft-mutable-registry deft.core-shared/get-deft-mutable-registry-internal) (def use-deft-malli-registry! deft.core-shared/use-deft-malli-registry-internal!) +;; warning!! this may enforce more things in the future +(def always-instrument! deft.core-shared/always-instrument!) diff --git a/src/deft/core.cljs b/src/deft/core.cljs index 33b8377d..704adf57 100644 --- a/src/deft/core.cljs +++ b/src/deft/core.cljs @@ -4,3 +4,5 @@ (def get-deft-mutable-registry deft.core-shared/get-deft-mutable-registry-internal) (def use-deft-malli-registry! deft.core-shared/use-deft-malli-registry-internal!) +;; warning!! this may enforce more things in the future +(def always-instrument! deft.core-shared/always-instrument!) diff --git a/src/deft/core_shared.cljc b/src/deft/core_shared.cljc index c1e9c6ec..ad3358dc 100644 --- a/src/deft/core_shared.cljc +++ b/src/deft/core_shared.cljc @@ -9,6 +9,7 @@ [clojure.pprint :as pprint])) (def malli-registry-atom (atom {})) +(def always-instrument (atom false)) #?(:clj (def-map-type TypeMap [m mta] @@ -205,3 +206,6 @@ (mr/composite-registry (m/default-schemas) (mr/mutable-registry malli-registry-atom)))) + +(defn always-instrument! [] + (reset! always-instrument true))