blob: f92b1e5b91ef2dce202ed4aaa94e1b48f8ea8b0c (
plain)
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
|
(.module:
[lux #*
[abstract
[monad (#+ do)]]
[control
["." io (#+ IO)]
["." try (#+ Try)]
[concurrency
["." promise (#+ Promise)]
["." stm]]]
[data
[binary (#+ Binary)]]
[world
[net (#+ URL)]]]
["." // #_
["#." artifact (#+ Artifact)
["#/." extension (#+ Extension)]]])
(type: #export Address
URL)
(type: #export User
Text)
(type: #export Password
Text)
(type: #export Identity
{#user User
#password Password})
(signature: #export (Repository !)
(: (-> Artifact Extension (! (Try Binary)))
download)
(: (-> Identity Artifact Extension Binary (! (Try Any)))
upload))
(def: #export (async repository)
(-> (Repository IO) (Repository Promise))
(structure
(def: (download artifact extension)
(promise.future (:: repository download artifact extension)))
(def: (upload identity artifact extension content)
(promise.future (:: repository upload identity artifact extension content)))
))
(signature: #export (Simulation s)
(: (-> Artifact Extension s
(Try [s Binary]))
on-download)
(: (-> Identity Artifact Extension Binary s
(Try s))
on-upload))
(def: #export (mock simulation init)
(All [s] (-> (Simulation s) s (Repository Promise)))
(let [state (stm.var init)]
(structure
(def: (download artifact extension)
(stm.commit
(do {! stm.monad}
[|state| (stm.read state)]
(case (:: simulation on-download artifact extension |state|)
(#try.Success [|state| output])
(do !
[_ (stm.write |state| state)]
(wrap (#try.Success output)))
(#try.Failure error)
(wrap (#try.Failure error))))))
(def: (upload identity artifact extension content)
(stm.commit
(do {! stm.monad}
[|state| (stm.read state)]
(case (:: simulation on-upload identity artifact extension content |state|)
(#try.Success |state|)
(do !
[_ (stm.write |state| state)]
(wrap (#try.Success [])))
(#try.Failure error)
(wrap (#try.Failure error))))))
)))
|