From 5c225a51ceb118fe15f436bfa9d5b7496ef3e8fd Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 28 May 2025 14:40:34 +0200 Subject: [PATCH] :sparkles: Add the ability to retrieve a set of keys from map schemas --- common/src/app/common/schema.cljc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index b218ea14d0..0c91aa6de3 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -5,7 +5,7 @@ ;; Copyright (c) KALEIDOS INC (ns app.common.schema - (:refer-clojure :exclude [deref merge parse-uuid parse-long parse-double parse-boolean type]) + (:refer-clojure :exclude [deref merge parse-uuid parse-long parse-double parse-boolean type keys]) #?(:cljs (:require-macros [app.common.schema :refer [ignoring]])) (:require [app.common.data :as d] @@ -118,6 +118,21 @@ [& transformers] (apply mt/transformer transformers)) +(defn entries + "Get map entires of a map schema" + [schema] + (m/entries schema default-options)) + +(def ^:private xf:map-key + (map key)) + +(defn keys + "Given a map schema, return all keys as set" + [schema] + (->> (entries schema) + (into #{} xf:map-key))) + + ;; (defn key-transformer ;; [& {:as opts}] ;; (mt/key-transformer opts))