blob: 237b092da9dbe473a3531c9ef2bc6bb398be16b3 (
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
|
(.module:
[lux (#- Module)
[control
["ex" exception (#+ exception:)]]
[data
["." error (#+ Error)]
[collection
["." dictionary (#+ Dictionary)]]]
[type (#+ :share)
abstract]]
[//
["." signature (#+ Signature)]
["." key (#+ Key)]
["." descriptor (#+ Module Descriptor)]])
## Document
(exception: #export (invalid-key {module Module} {expected (Key Any)} {actual (Key Any)})
(ex.report ["Module" module]
["Expected" (signature.description (get@ #key.signature expected))]
["Actual" (signature.description (get@ #key.signature actual))]))
(abstract: #export (Document d)
{}
{#key (Key d)
#descriptor Descriptor
#content d}
(def: #export (read key document)
(All [d] (-> (Key d) (Document Any) (Error d)))
(let [[document//key document//descriptor document//content] (:representation document)]
(if (:: signature.Equivalence<Signature> =
(get@ #key.signature key)
(get@ #key.signature document//key))
(#error.Success (:share [e]
{(Key e)
key}
{e
document//content}))
(ex.throw invalid-key [(get@ #descriptor.name document//descriptor) key document//key]))))
(def: #export (write key descriptor content)
(All [d] (-> (Key d) Descriptor d (Document d)))
(:abstraction {#key key
#descriptor descriptor
#content content}))
(def: #export signature
(-> (Document Any) Signature)
(|>> :representation (get@ #key) (get@ #key.signature)))
)
|