aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/metadata/snapshot.lux
blob: 6a32effef2e097b25a00561dd0c9489802aa6497 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
(.module:
  [library
   [lux (#- Name Type)
    [abstract
     [monad (#+ do)]
     [equivalence (#+ Equivalence)]]
    [control
     [pipe (#+ do> case>)]
     ["." try (#+ Try)]
     ["." exception (#+ exception:)]
     ["<>" parser
      ["<.>" xml (#+ Parser)]
      ["<.>" text]]
     [concurrency
      ["." async (#+ Async)]]]
    [data
     ["." product]
     ["." text
      ["%" format]
      [encoding
       ["." utf8]]]
     [format
      ["." xml (#+ XML)]]
     [collection
      ["." list ("#\." functor)]]]
    [math
     [number
      ["n" nat]]]
    ["." time (#+ Time)
     ["." instant (#+ Instant)]
     ["." date (#+ Date)]
     ["." year]
     ["." month]]
    [world
     [net
      ["." uri (#+ URI)]]]]]
  ["." //
   ["/#" // #_
    [repository (#+ Repository)]
    ["#." artifact (#+ Group Name Version Artifact)
     ["#/." time]
     ["#/." type (#+ Type)]
     ["#/." versioning (#+ Versioning)]
     ["#/." snapshot
      ["#/." version]
      ["#/." stamp]]]]])

(type: .public Metadata
  {#artifact Artifact
   #versioning Versioning})

(template [<definition> <tag>]
  [(def: <definition> xml.Tag ["" <tag>])]

  [<group> "groupId"]
  [<name> "artifactId"]
  [<version> "version"]
  [<metadata> "metadata"]
  )

(template [<name> <type> <tag> <pre>]
  [(def: <name>
     (-> <type> XML)
     (|>> <pre> #xml.Text list (#xml.Node <tag> xml.attributes)))]

  [group_format Group ..<group> (|>)]
  [name_format Name ..<name> (|>)]
  [version_format Version ..<version> (|>)]
  )

(def: .public (format (^slots [#artifact #versioning]))
  (-> Metadata XML)
  (let [(^slots [#///artifact.group #///artifact.name #///artifact.version]) artifact]
    (#xml.Node ..<metadata>
               xml.attributes
               (list (..group_format group)
                     (..name_format name)
                     (..version_format version)
                     (///artifact/versioning.format versioning)))))

(def: (text tag)
  (-> xml.Tag (Parser Text))
  (<| (<xml>.node tag)
      <xml>.text))

(def: .public parser
  (Parser Metadata)
  (<| (<xml>.node ..<metadata>)
      (do {! <>.monad}
        [group (<xml>.somewhere (..text ..<group>))
         name (<xml>.somewhere (..text ..<name>))
         version (<xml>.somewhere (..text ..<version>))
         versioning (with_expansions [<default_version> {#///artifact/snapshot/version.extension ///artifact/type.jvm_library
                                                         #///artifact/snapshot/version.value version
                                                         #///artifact/snapshot/version.updated ///artifact/time.epoch}]
                      (|> (<xml>.somewhere ///artifact/versioning.parser)
                          (\ ! map
                             (revised@ #///artifact/versioning.versions
                                       (: (-> (List ///artifact/snapshot/version.Version)
                                              (List ///artifact/snapshot/version.Version))
                                          (|>> (case> (^ (list))
                                                      (list <default_version>)

                                                      versions
                                                      versions)))))
                          (<>.else {#///artifact/versioning.snapshot #///artifact/snapshot.Local
                                    #///artifact/versioning.last_updated ///artifact/time.epoch
                                    #///artifact/versioning.versions (list <default_version>)})))]
        (in {#artifact {#///artifact.group group
                        #///artifact.name name
                        #///artifact.version version}
             #versioning versioning}))))

(def: .public equivalence
  (Equivalence Metadata)
  ($_ product.equivalence
      ///artifact.equivalence
      ///artifact/versioning.equivalence
      ))

(def: .public uri
  (-> Artifact URI)
  //.remote_artifact_uri)

(def: .public (read repository artifact)
  (-> (Repository Async) Artifact (Async (Try Metadata)))
  (do async.monad
    [project (\ repository download (..uri artifact))]
    (case project
      (#try.Success project)
      (in (|> project
              (do> try.monad
                   [(\ utf8.codec decode)]
                   [(\ xml.codec decode)]
                   [list (<xml>.result ..parser)])))
      
      (#try.Failure error)
      (in (#try.Success
           {#artifact artifact
            #versioning ///artifact/versioning.init})))))

(def: .public (write repository artifact metadata)
  (-> (Repository Async) Artifact Metadata (Async (Try Any)))
  (|> metadata
      ..format
      (\ xml.codec encode)
      (\ utf8.codec encode)
      (\ repository upload (..uri artifact))))