Schema options - moxaj/mikron GitHub Wiki

Schema options

This page describes the optional keyword arguments you can pass to mikron.runtime.core/schema and mikron.runtime.core/defschema. In the scope of this document, consider mikron.runtime.core implicitly loaded and aliased to mikron.

:processor-types

Syntax

:processor-types processor-types where

  • processor-types is a set of keywords, each from the set #{:pack :unpack :gen :valid? :diff :undiff :pack-diffed :unpack-diffed}
Semantics

restricts the set of generated processors (useful if code size is a concern)

Examples
(mikron/defschema ::schema <...>
  :processor-types #{:pack :unpack :valid?})
;;

(mikron/gen ::schema)
;; => Exception: No such processor <...>

(mikron/pack ::schema <...>)
;; => <binary value>

:diff-paths

Syntax

A tree like datastructure of nested maps; keys are arbitrary values (specific to the schema) and values are either booleans or maps.

Semantics

The keys are either navigators through the diffed value (for example record keys in the case of :record), selectors of the correct interpretation (in the case of :multi). For each schema specific diff path specification, see Schema DSL.

Examples
(mikron/defschema ::schema [:record {:a :int
                                     :b [:vector [:tuple [:byte :string]]]}]
  :diff-paths {:b true})
;; => :user/schema

;; Equivalent to:
(mikron/defschema ::schema [:record {:a :int
                                     :b [:vector [:tuple [:byte :string]]]}]
  :diff-paths {:a false
               :b {:all {:0 true :1 true}}})

(mikron/diff* ::schema {:a 0 :b [[1 "a"] [2 "b"]]}
                       {:a 0 :b [[1 "a"] [2 "b"]]})
;; => {:a 0 :b :mikron/nil}

(mikron/diff* ::schema {:a 0 :b [[1 "a"] [2 "b"]]}
                       {:a 0 :b [[1 "a"] [2 "c"]]})
;; => {:a 0 :b [:mikron/nil [:mikron/nil "c"]]]}
⚠️ **GitHub.com Fallback** ⚠️