aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact/versioning.lux
blob: 9ccfd46ba35710eec7df4d254a7cecbd19934f8c (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
(.require
 [library
  [lux (.except)
   [abstract
    [equivalence (.only Equivalence)]
    [monad (.only do)]]
   [control
    ["<>" parser]]
   [data
    ["[0]" product]
    ["[0]" text (.only)
     ["%" \\format]
     ["<[1]>" \\parser]]
    [format
     ["[0]" xml (.only XML)
      ["<[1]>" \\parser (.only Parser)]]]
    [collection
     ["[0]" list (.use "[1]#[0]" functor)]]]
   [math
    [number
     ["n" nat]]]
   [world
    ["[0]" time (.only Time)
     ["[0]" date (.only Date)]
     ["[0]" year]
     ["[0]" month]]]]]
 ["[0]" //
  ["[1][0]" time]
  ["[1][0]" snapshot (.only Snapshot)
   ["[1]/[0]" version (.only 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)
  (all product.equivalence
       //snapshot.equivalence
       //time.equivalence
       (list.equivalence //snapshot/version.equivalence)
       ))

(with_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>)
      (all <>.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))
           )))