From 847599a83e5d69341eb0114a366769db8eb9f65a Mon Sep 17 00:00:00 2001 From: Mike Sperber Date: Wed, 20 Mar 2024 14:57:43 +0100 Subject: [PATCH] Implement and use re-export macro. --- src/active/data/realm/inspection.cljc | 122 +++++++++++++++----------- test/active/data/internal/export.cljc | 17 ++++ 2 files changed, 87 insertions(+), 52 deletions(-) create mode 100644 test/active/data/internal/export.cljc diff --git a/src/active/data/realm/inspection.cljc b/src/active/data/realm/inspection.cljc index 893adc5..79a26d5 100644 --- a/src/active/data/realm/inspection.cljc +++ b/src/active/data/realm/inspection.cljc @@ -3,146 +3,164 @@ (:require [active.data.realm.internal.records :as realm-records] [active.data.realm :as realm] #?(:clj [active.data.record :refer [def-record is-a?]] - :cljs [active.data.record :refer [is-a?] :refer-macros [def-record]]))) + :cljs [active.data.record :refer [is-a?] :refer-macros [def-record]]) + #?(:clj [active.data.internal.export :refer [re-export]] + :cljs [active.data.internal.export :refer-macros [re-export]]))) (defn realm? [thing] (is-a? realm-records/realm thing)) -(def description realm-records/description) -(def predicate realm-records/predicate) -(def metadata realm-records/metadata) +(re-export + realm-records/description + realm-records/predicate + realm-records/metadata) -(def builtin-scalar-realm realm-records/builtin-scalar-realm) - -(def builtin-scalar-realm-id realm-records/builtin-scalar-realm-id) +(re-export + realm-records/builtin-scalar-realm + realm-records/builtin-scalar-realm-id) (defn builtin-scalar? [thing] (is-a? builtin-scalar-realm thing)) -(def from-predicate-realm realm-records/from-predicate-realm) +(re-export realm-records/from-predicate-realm) (defn from-predicate? [thing] (is-a? from-predicate-realm thing)) -(def optional-realm realm-records/optional-realm) -(def optional-realm-realm realm-records/optional-realm-realm) +(re-export + realm-records/optional-realm + realm-records/optional-realm-realm) (defn optional? [thing] (is-a? optional-realm thing)) -(def integer-from-to-realm realm-records/integer-from-to-realm) -(def integer-from-to-realm-from realm-records/integer-from-to-realm-from) -(def integer-from-to-realm-to realm-records/integer-from-to-realm-to) +(re-export + realm-records/integer-from-to-realm + realm-records/integer-from-to-realm-from + realm-records/integer-from-to-realm-to) (defn real-range? [thing] (is-a? real-range? thing)) -(def union-realm realm-records/union-realm) -(def union-realm-realms realm-records/union-realm-realms) +(re-export + realm-records/union-realm + realm-records/union-realm-realms) (defn union? [thing] (is-a? union-realm thing)) -(def enum-realm realm-records/enum-realm) -(def enum-realm-values realm-records/enum-realm-values) +(re-export + realm-records/enum-realm + realm-records/enum-realm-values) (defn enum? [thing] (is-a? enum-realm thing)) -(def intersection-realm realm-records/intersection-realm) -(def intersection-realm-realms realm-records/intersection-realm-realms) +(re-export + realm-records/intersection-realm + realm-records/intersection-realm-realms) (defn intersection? [thing] (is-a? intersection-realm thing)) -(def sequence-of-realm realm-records/sequence-of-realm) -(def sequence-of-realm-realm realm-records/sequence-of-realm-realm) +(re-export + realm-records/sequence-of-realm + realm-records/sequence-of-realm-realm) (defn sequence-of? [thing] (is-a? sequence-of-realm thing)) -(def set-of-realm realm-records/set-of-realm) -(def set-of-realm-realm realm-records/set-of-realm-realm) +(re-export + realm-records/set-of-realm + realm-records/set-of-realm-realm) (defn set-of? [thing] (is-a? set-of-realm thing)) -(def map-with-keys-realm realm-records/map-with-keys-realm) -(def map-with-keys-realm-map realm-records/map-with-keys-realm-map) +(re-export + realm-records/map-with-keys-realm + realm-records/map-with-keys-realm-map) (defn map-with-keys? [thing] (is-a? map-with-keys-realm thing)) -(def map-of-realm realm-records/map-of-realm) -(def map-of-realm-key-realm realm-records/map-of-realm-key-realm) -(def map-of-realm-value-realm realm-records/map-of-realm-value-realm) +(re-export + realm-records/map-of-realm + realm-records/map-of-realm-key-realm + realm-records/map-of-realm-value-realm) (defn map-of? [thing] (is-a? map-of-realm thing)) -(def map-with-tag-realm realm-records/map-with-tag-realm) -(def map-with-tag-realm-key realm-records/map-with-tag-realm-key) -(def map-with-tag-realm-value realm-records/map-with-tag-realm-value) +(re-export + realm-records/map-with-tag-realm + realm-records/map-with-tag-realm-key + realm-records/map-with-tag-realm-value) (defn map-with-tag? [thing] (is-a? map-with-tag-realm thing)) -(def tuple-realm realm-records/tuple-realm) -(def tuple-realm-realms realm-records/tuple-realm-realms) +(re-export + realm-records/tuple-realm + realm-records/tuple-realm-realms) (defn tuple? [thing] (is-a? tuple-realm thing)) -(def record-realm-field realm-records/record-realm-field) -(def record-realm-field-name realm-records/record-realm-field-name) -(def record-realm-field-realm realm-records/record-realm-field-realm) -(def record-realm-field-getter realm-records/record-realm-field-getter) +(re-export + realm-records/record-realm-field + realm-records/record-realm-field-name + realm-records/record-realm-field-realm + realm-records/record-realm-field-getter -(def record-realm realm-records/record-realm) -(def record-realm-name realm-records/record-realm-name) -(def record-realm-constructor realm-records/record-realm-constructor) -(def record-realm-fields realm-records/record-realm-fields) + realm-records/record-realm + realm-records/record-realm-name + realm-records/record-realm-constructor + realm-records/record-realm-fields) (defn record? [thing] (is-a? record-realm thing)) -(def function-case realm-records/function-case) -(def function-case-positional-argument-realms realm-records/function-case-positional-argument-realms) -(def function-case-optional-arguments-realm realm-records/function-case-optional-arguments-realm) -(def function-case-return-realm realm-records/function-case-return-realm) +(re-export + realm-records/function-case + realm-records/function-case-positional-argument-realms + realm-records/function-case-optional-arguments-realm + realm-records/function-case-return-realm -(def function-realm realm-records/function-realm) -(def function-realm-cases realm-records/function-realm-cases) + realm-records/function-realm + realm-records/function-realm-cases) (defn function? [thing] (is-a? function-realm thing)) -(def delayed-realm realm-records/delayed-realm) -(def delayed-realm-delay realm-records/delayed-realm-delay) +(re-export + realm-records/delayed-realm + realm-records/delayed-realm-delay) (defn delayed? [thing] (is-a? delayed-realm thing)) -(def named-realm realm-records/named-realm) -(def named-realm-name realm-records/named-realm-name) -(def named-realm-realm realm-records/named-realm-realm) +(re-export + realm-records/named-realm + realm-records/named-realm-name + realm-records/named-realm-realm) (defn named? [thing] diff --git a/test/active/data/internal/export.cljc b/test/active/data/internal/export.cljc new file mode 100644 index 0000000..a8bd25b --- /dev/null +++ b/test/active/data/internal/export.cljc @@ -0,0 +1,17 @@ +(ns active.data.internal.export) + +(defn- re-export-1 + [var-name] + (let [local-name (symbol (name var-name))] + `(do + (def ~local-name ~var-name) + (alter-meta! (var ~local-name) + (constantly (assoc (meta (var ~var-name)) + :re-exporting (var ~var-name))))))) + +(defmacro re-export + "Re-exports a bunch of names, copying metadata" + [& names] + `(do ~@(map re-export-1 names))) + +