aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact.lux
blob: 92c8629bc024a9efe190ff78d1159ab727fff6f8 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
(.require
 [library
  [lux (.except local)
   [abstract
    [equivalence (.only Equivalence)]
    [order (.only Order)]
    [hash (.only Hash)]]
   [data
    ["[0]" product]
    ["[0]" text (.use "[1]#[0]" order)
     ["%" \\format (.only Format)]]
    [collection
     ["[0]" list (.use "[1]#[0]" monoid)]]]
   [world
    ["[0]" file (.only Path)]
    [net
     ["[0]" uri (.only URI)]]]]])

(type .public Group
  Text)

(type .public Name
  Text)

(type .public Version
  Text)

(type .public Artifact
  (Record
   [#group Group
    #name Name
    #version Version]))

(def .public hash
  (Hash Artifact)
  (all product.hash
       text.hash
       text.hash
       text.hash
       ))

(def .public equivalence
  (Equivalence Artifact)
  (at ..hash equivalence))

(def .public order
  (Order Artifact)
  (implementation
   (def equivalence
     ..equivalence)

   (def (< reference subject)
     (<| (or (text#< (the #group reference)
                     (the #group subject)))

         (and (text#= (the #group reference)
                      (the #group subject)))
         (or (text#< (the #name reference)
                     (the #name subject)))
         
         (and (text#= (the #name reference)
                      (the #name subject)))
         (text#< (the #version reference)
                 (the #version subject))))))

(with_template [<separator> <definition>]
  [(def <definition>
     Text
     <separator>)]

  ["." group_separator]
  ["-" version_separator]
  [":" identity_separator]
  )

(def .public (identity artifact)
  (-> Artifact Text)
  (%.format (the #name artifact)
            ..version_separator
            (the #version artifact)))

(def .public (format value)
  (Format Artifact)
  (%.format (the #group value)
            ..identity_separator
            (..identity value)))

(def .public (directory separator group)
  (-> Text Group Text)
  (|> group
      (text.all_split_by ..group_separator)
      (text.interposed separator)))

(def .public (bundle version artifact)
  (-> Version Artifact URI)
  (let [/ uri.separator
        group (..directory / (the #group artifact))
        name (the #name artifact)]
    (%.format group / name / version)))

(def .public (uri version artifact)
  (-> Version Artifact URI)
  (let [/ uri.separator]
    (%.format (..bundle version artifact) / (..identity artifact))))

(def .public (local artifact)
  (-> Artifact (List Text))
  (list#composite (|> artifact
                      (the #group)
                      (text.all_split_by ..group_separator))
                  (list (the #name artifact)
                        (the #version artifact))))