registry.clj

Branches > refactor/use-spec-1 > 2bdfa58 > 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]))

(s/def ::table
  (s/* (s/cat :field keyword?
              :doc (s/? string?)
              :type #(or (keyword? %) (vector? %)))))

(s/def ::packet-registry
  (s/map-of ::pk/id ::table))

(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)))