-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.cljc
56 lines (46 loc) · 1.64 KB
/
schema.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(ns slip.schema
(:require
[malli.util :as mu]
[slip.data.ref-path :as ref-path]))
(def DataSpec
"a recursive schema specifying a template for building data parameters
for factory methods, allowing references to already created objects
with `#slip/ref` tagged literals
- `::ref-path-spec` - a `RefPath` e.g. from a #slip/ref tagged literal
- `::map-data-spec` - a `{<keyword> <DataSpec>}` map
- `::vector-data-spec` - a `[<DataSpec>]`
- `<anything-else>` - a literal value"
[:schema
{:registry
{::data-spec [:or
[:ref ::ref-path-spec]
[:ref ::map-data-spec]
[:ref ::vector-data-spec]
[:not [:or map? vector? [:ref ::ref-path-spec]]]]
::ref-path-spec [:fn ref-path/ref-path?]
::map-data-spec [:map-of :keyword [:ref ::data-spec]]
::vector-data-spec [:vector [:ref ::data-spec]]}}
::data-spec])
(def KeylessObjectSpec
"an ObjectSpec with no key - to be used where keys
are implicit, in a [[MapSystemSpec]]"
[:map
[:slip/factory {:optional true} :keyword]
[:slip/data DataSpec]])
(def KeyedObjectSpec
"an ObjectSpec with a key - to be used where keys must
be explicit, in a [[VectorSystemSpec]]"
(mu/merge
KeylessObjectSpec
[:map
[:slip/key :keyword]]))
(def VectorSystemSpec
"a [[SystemSpec]] with explicit order"
[:vector KeyedObjectSpec])
(def MapSystemSpec
"a [[SystemSpec]] with no explicit order"
[:map-of :keyword KeylessObjectSpec])
(def SystemSpec
"a SystemSpec which may be presented as a map of
[[KeylessObjectSpec]] or a vector of [[KeyedObjectSpec]]"
[:or VectorSystemSpec MapSystemSpec])