aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact/versioning.lux
blob: 377e33a670b6c544dc57d028573037e223e22154 (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
(.using
 [library
  [lux "*"
   [abstract
    [equivalence {"+" Equivalence}]
    [monad {"+" do}]]
   [control
    ["[0]" exception {"+" exception:}]
    ["<>" parser
     ["<[0]>" xml {"+" Parser}]
     ["<[0]>" text]]]
   [data
    ["[0]" product]
    ["[0]" text
     ["%" format]]
    [format
     ["[0]" xml {"+" XML}]]
    [collection
     ["[0]" list ("[1]#[0]" functor)]]]
   [math
    [number
     ["n" nat]]]
   ["[0]" time {"+" Time}
    ["[0]" date {"+" Date}]
    ["[0]" year]
    ["[0]" month]]]]
 ["[0]" // "_"
  ["[1][0]" time]
  ["[1][0]" snapshot {"+" Snapshot}
   ["[1]/[0]" version {"+" Version}]]])

(type: .public Versioning
  (Record
   [#snapshot Snapshot
    #last_updated //time.Time
    #versions (List Version)]))

(def: .public init
  [#snapshot {//snapshot.#Local}
   #last_updated //time.epoch
   #versions (list)])

(def: .public equivalence
  (Equivalence Versioning)
  ($_ product.equivalence
      //snapshot.equivalence
      //time.equivalence
      (list.equivalence //snapshot/version.equivalence)
      ))

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

  [<last_updated> "lastUpdated"]
  [<snapshot_versions> "snapshotVersions"]

  [<versioning> "versioning"]
  )

(def: last_updated_format
  (-> //time.Time XML)
  (|>> //time.format {xml.#Text} list {xml.#Node ..<last_updated> xml.attributes}))

(def: .public (format (open "_[0]"))
  (-> Versioning XML)
  (<| {xml.#Node ..<versioning> xml.attributes}
      (list (//snapshot.format _#snapshot)
            (..last_updated_format _#last_updated)
            (|> _#versions
                (list#each //snapshot/version.format)
                {xml.#Node ..<snapshot_versions> xml.attributes}))))

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

(def: last_updated_parser
  (Parser //time.Time)
  (<| (<text>.then //time.parser)
      (..text ..<last_updated>)))

(def: .public parser
  (Parser Versioning)
  (<| (<xml>.node ..<versioning>)
      ($_ <>.and
          (<>.else {//snapshot.#Local} (<xml>.somewhere //snapshot.parser))
          (<>.else //time.epoch (<xml>.somewhere ..last_updated_parser))
          (<| (<>.else (list))
              <xml>.somewhere
              (<xml>.node ..<snapshot_versions>)
              (<>.some //snapshot/version.parser))
          )))