registry.clj

Branches > main > 5683776 > files / src / net / bowmap / packets / registry.clj

(ns net.bowmap.packets.registry
  (:require
   [clojure.alpha.spec :as s]
   [dev.grahp.error :refer [raise]]
   [net.bowmap.packet :as pk]))

;; TODO could have :type actually check that it's a valid type!
(s/def ::packet-registry
  (s/map-of ::pk/id
            (s/* (s/cat :field keyword?
                        :doc (s/? string?)
                        :type #(or (keyword? %) (vector? %))))))

(defn conform-registry
  "Returns a registry conformed to '::packet-registry', or throws if it is invalid"
  [registry]
  (let [registry (s/conform ::packet-registry registry)]
    (if (= ::s/invalid registry)
      (raise "Invalid packet registry!" {:explanation (s/explain-data ::packet-registry registry)})
      registry)))