-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.cljc
26 lines (21 loc) · 890 Bytes
/
registry.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(ns main.registry
(:require [com.fulcrologic.guardrails.malli.registry :as gr.reg]
[malli.core :as m]
[malli.registry :as mr]
[malli.util :as mu]))
;; To share the registry between regular Malli validations and Guardrails
;; we use a mutable Malli registry.
(def !registry
(atom (merge (-> m/default-registry (mr/schemas))
(mu/schemas) ; To get the declarative versions of Malli's
; schema transforming utilities
)))
(mr/set-default-registry!
(mr/mutable-registry !registry))
;; Guardrails' registry already contains the malli core schemas
;; But we need it to use our registry so we merge it here, and
;; whenever a new schema is registered.
(gr.reg/merge-schemas! @!registry)
(defn register! [type ?schema]
(swap! !registry assoc type ?schema)
(gr.reg/merge-schemas! @!registry))