-
Notifications
You must be signed in to change notification settings - Fork 7
/
spec.cljs
109 lines (81 loc) · 3.16 KB
/
spec.cljs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(ns keechma.next.spec
(:require
[cljs.spec.alpha :as s]
[com.fulcrologic.guardrails.core :refer [>def]]))
(defn dynamic-config? [{:keys [:keechma.controller/params]}]
(= :dynamic (first params)))
(defn static-config? [{:keys [:keechma.controller/params]}]
(= :static (first params)))
(defn dep? [val]
(or (keyword? val)
(and (vector? val) (= 1 (count val)))
(and (vector? val) (= 2 (count val)))))
(defn inline-app-variant [[variant app]]
(assoc app :keechma.app/variant variant))
(>def :keechma.controller.factory/produce
fn?)
(>def :keechma.controller/deps
(s/coll-of dep? :kind vector? :min-count 1))
(>def :keechma.controller.name/singleton
keyword?)
(>def :keechma.controller.name/identity
(s/tuple keyword? (complement nil?)))
(>def :keechma.controller.name/factory
(s/tuple keyword?))
(>def :keechma.controller/type
(s/and keyword? #(isa? % :keechma/controller)))
(>def :keechma.controller.params/dynamic
fn?)
(>def :keechma.controller.params/static
(s/and (complement fn?) boolean))
(>def :keechma.controller/params
(s/or :dynamic :keechma.controller.params/dynamic
:static :keechma.controller.params/static))
(>def :keechma.controller.config/dynamic
(s/and (s/keys :req [:keechma.controller/deps
:keechma.controller/params
:keechma.controller/type])
dynamic-config?))
(>def :keechma.controller.config/static
(s/and (s/keys :req [:keechma.controller/params
:keechma.controller/type])
static-config?))
(>def :keechma.controller.config/factory
(s/keys :req [:keechma.controller/deps
:keechma.controller/type
:keechma.controller.factory/produce]))
(>def :keechma.controller/config
(s/or :static :keechma.controller.config/static
:dynamic :keechma.controller.config/dynamic))
(>def :keechma.controller.variant/singleton
(s/tuple :keechma.controller.name/singleton :keechma.controller/config))
(>def :keechma.controller.variant/identity
(s/tuple :keechma.controller.name/identity :keechma.controller/config))
(>def :keechma.controller.variant/factory
(s/tuple :keechma.controller.name/factory :keechma.controller.config/factory))
(>def :keechma/controller
(s/or
:singleton :keechma.controller.variant/singleton
:identity :keechma.controller.variant/identity
:factory :keechma.controller.variant/factory))
(>def :keechma.controller.factory/produced
(s/keys
:req [:keechma.controller/params]
:opt [:keechma.controller/deps]))
(>def :keechma/controllers
(s/and (s/map-of #(or (keyword? %) (vector? %)) map?)
(s/coll-of :keechma/controller :into {})))
(>def :keechma/app
(s/keys
:req [:keechma/controllers]
:opt [:keechma/apps]))
(>def :keechma/nested-app
(s/or
:dynamic (s/keys :req [:keechma.app/load :keechma.app/should-run? :keechma.app/deps])
:static (s/merge :keechma/app (s/keys :req [:keechma.app/should-run? :keechma.app/deps]))))
(>def :keechma.app/should-run? fn?)
(>def :keechma.app/load fn?)
(>def :keechma.app/deps (s/merge :keechma.controller/deps))
(>def :keechma/apps
(s/map-of keyword? :keechma/nested-app))
(>def :keechma/app-instance map?)