blob: e9ecee8cdc6ff1ef80c9bd771ae7a6f72e15e7fc (
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
86
87
88
89
|
(.module:
[lux (#- Module)
[control
["ex" exception (#+ exception:)]
["." equivalence (#+ Equivalence)]
["." monad (#+ do)]]
[data
["." error (#+ Error)]
["." name]
["." text
format]
[collection
["." dictionary (#+ Dictionary)]]]
[type
abstract]
[world
[file (#+ File)]]]
[///
[default (#+ Version)]]
[/
["." signature (#+ Signature)]
["." key (#+ Key)]
["." descriptor (#+ Module Descriptor)]
["." document (#+ Document)]])
## Archive
(exception: #export (unknown-document {module Module})
(ex.report ["Module" module]))
(exception: #export (cannot-replace-document {module Module}
{old (Document Any)}
{new (Document Any)})
(ex.report ["Module" module]
["Old key" (signature.description (document.signature old))]
["New key" (signature.description (document.signature new))]))
(abstract: #export Archive
{}
(Dictionary Module [Descriptor (Document Any)])
(def: #export empty
Archive
(:abstraction (dictionary.new text.hash)))
(def: #export (add module [descriptor document] archive)
(-> Module [Descriptor (Document Any)] Archive (Error Archive))
(case (dictionary.get module (:representation archive))
(#.Some [existing-descriptor existing-document])
(if (is? document existing-document)
(#error.Success archive)
(ex.throw cannot-replace-document [module existing-document document]))
#.None
(#error.Success (|> archive
:representation
(dictionary.put module [descriptor document])
:abstraction))))
(def: #export (find module archive)
(-> Module Archive (Error [Descriptor (Document Any)]))
(case (dictionary.get module (:representation archive))
(#.Some document)
(#error.Success document)
#.None
(ex.throw unknown-document [module])))
(def: #export (archived? archive module)
(-> Archive Module Bit)
(case (find module archive)
(#error.Success _)
yes
(#error.Failure _)
no))
(def: #export archived
(-> Archive (List Module))
(|>> :representation dictionary.keys))
(def: #export (merge additions archive)
(-> Archive Archive (Error Archive))
(monad.fold error.monad
(function (_ [module' descriptor+document'] archive')
(..add module' descriptor+document' archive'))
archive
(dictionary.entries (:representation additions))))
)
|