-
Notifications
You must be signed in to change notification settings - Fork 13
/
schema.cljc
131 lines (97 loc) · 4.25 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
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
110
111
112
113
114
115
116
117
118
119
(ns tupelo.schema
"Prismatic Schema type definitions"
(:refer-clojure :exclude [Fn List Single MapEntry])
(:require [schema.core :as s])
#?(:clj
(:import [java.util HashSet])))
(def Map {s/Any s/Any} )
(def KeyMap {s/Keyword s/Any} )
(def MapEntry #?(:clj clojure.lang.MapEntry
:cljs cljs.core.MapEntry))
(def Set
"Either a Clojure hash-set or a java.util.HashSet"
#?(:clj (s/if set? #{s/Any} java.util.HashSet)
:cljs #{s/Any}))
(def Vec
"An ordered sequence of items of indeterminate length (synonymous for List)."
[s/Any])
(def List
"An ordered sequence of items of indeterminate length (synonymous for Vec)."
[s/Any])
#?(:clj ; #todo cljs?
(def CharVec
"An ordered sequence of characters of indeterminate length."
[Character]))
(def Single [(s/one s/Any "x1")]) ; length-1 vector
(def Pair [(s/one s/Any "x1") (s/one s/Any "x2")]) ; length-2 vector
(def Triple [(s/one s/Any "x1") (s/one s/Any "x2") (s/one s/Any "x3")]) ; length-3 vector
(def Quad [(s/one s/Any "x1") (s/one s/Any "x2") (s/one s/Any "x3") (s/one s/Any "x4")]) ; length-4 vector
(def EnliveNode
"An Enlive tree node"
{:tag s/Any :attrs KeyMap :content [s/Any]})
(def Tuple
"A specific type of sequential collection, typically a vector of constant length where each
element has a pre-defined interpretation."
[s/Any])
(def TupleList
"A sequence of tuples (typically a vector of vectors)"
[Tuple])
(def TupleSet
"The result of any Datomic using the Entity API is logically a hash-set of tuples (vectors).
The contents and order of each tuple is determined by the find clause:
----- query ----- ----- tuples -----
(d/q '{:find [?e ?name ?age] ...) -> [?e ?name ?age]
"
#{Tuple})
(def MapList [Map]) ; a list of Maps
(def TupleMap [Map]) ; a single result returned by Datomic pull api ; #todo needs (s/one ...) ??? or MapList?
(def TupleMaps [TupleMap]) ; a list of results returned by Datomic pull api
(def Fn (s/make-fn-schema s/Any s/Any))
#?(:clj
(do
;-----------------------------------------------------------------------------
; Datomic-related stuff
(def Eid
"Each entity in the DB is uniquely specified its Entity ID (EID). Indeed, allocation of a unique
EID is what 'creates' an entity in the DB."
Long)
; #todo - clarify in all doc-strings that entity-spec = [EID or lookup-ref]
(def LookupRef
"If an entity has an attribute with either :db.unique/value or :db.unique/identity, that entity
can be uniquely specified using a lookup-ref (LookupRef). A lookup-ref is an attribute-value pair
expressed as a tuple: [ <attribute> <value> ]"
[(s/one s/Keyword "attr")
(s/one s/Any "val")])
(def EntitySpec
"An EntitySpec is used to uniquely specify an entity in the DB. It consists of
either an EID or a LookupRef."
(s/if int? Eid LookupRef))
(def DatomMap
"The Clojure map representation of a Datom."
{:e Eid :a Eid :v s/Any :tx Eid :added s/Bool})
;-----------------------------------------------------------------------------
; HTTP related stuff
(def HttpRequest
{s/Any s/Any
:body s/Any
:content-length s/Any
:headers {s/Str s/Str}
:params s/Any
:protocol s/Str
:remote-addr s/Str
:scheme s/Keyword
:server-name s/Str
:server-port s/Int
:uri s/Str
(s/optional-key :content-type) nil
(s/optional-key :cookies) s/Any
(s/optional-key :flash) nil
(s/optional-key :form-params) s/Any
(s/optional-key :query-params) {}
(s/optional-key :query-string) s/Any
(s/optional-key :request-method) s/Keyword
(s/optional-key :route-handler) s/Any
(s/optional-key :route-params) s/Any
(s/optional-key :session) s/Any
(s/optional-key :ssl-client-cert) s/Any})
))