about summary refs log tree commit diff
path: root/users/Profpatsch/parked/sync-abfall-ics-aichach-friedberg/ics-to-caldav.dhall
blob: 2a7ac84979d2876899eb4381086e3071620f8734 (plain) (blame)
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
let Ini = ../ini/ini.dhall

let Lib = ../dhall/lib.dhall

in  \(Ini/externs : Ini.Externs) ->
      let Vdirsyncer =
            let StorageType =
                  < FileSystem : { path : Text, fileext : < ICS > }
                  | Http : { url : Text }
                  >

            let Collection = < FromA | FromB | Collection : Text >

            let Collections =
                  < Unspecified | TheseCollections : List Collection >

            let Storage = { storageName : Text, storage : StorageType }

            in  { Storage
                , StorageType
                , Collection
                , Collections
                , Pair =
                    { pairName : Text
                    , a : Storage
                    , b : Storage
                    , collections : Collections
                    }
                }

      let toIniSections
          : Vdirsyncer.Pair -> Ini.Sections
          = \(pair : Vdirsyncer.Pair) ->
              let
                  -- we assume the names are [a-zA-Z_]
                  renderList =
                    \(l : List Text) ->
                          "["
                      ++  Lib.Text/concatMapSep
                            ", "
                            Text
                            (\(t : Text) -> "\"${t}\"")
                            l
                      ++  "]"

              in  let nv = \(name : Text) -> \(value : Text) -> { name, value }

                  let mkStorage =
                        \(storage : Vdirsyncer.Storage) ->
                          { name = "storage ${storage.storageName}"
                          , value =
                              merge
                                { FileSystem =
                                    \ ( fs
                                      : { path : Text, fileext : < ICS > }
                                      ) ->
                                      [ nv "type" "filesystem"
                                      , nv
                                          "fileext"
                                          (merge { ICS = ".ics" } fs.fileext)
                                      , nv "path" fs.path
                                      ]
                                , Http =
                                    \(http : { url : Text }) ->
                                      [ nv "type" "http", nv "url" http.url ]
                                }
                                storage.storage
                          }

                  in  [ { name = "pair ${pair.pairName}"
                        , value =
                          [ nv "a" pair.a.storageName
                          , nv "b" pair.b.storageName
                          , nv
                              "collections"
                              ( merge
                                  { Unspecified = "none"
                                  , TheseCollections =
                                      \(colls : List Vdirsyncer.Collection) ->
                                        renderList
                                          ( Lib.List/map
                                              Vdirsyncer.Collection
                                              Text
                                              ( \ ( coll
                                                  : Vdirsyncer.Collection
                                                  ) ->
                                                  merge
                                                    { FromA = "from a"
                                                    , FromB = "from b"
                                                    , Collection =
                                                        \(t : Text) -> t
                                                    }
                                                    coll
                                              )
                                              colls
                                          )
                                  }
                                  pair.collections
                              )
                          ]
                        }
                      , mkStorage pair.a
                      , mkStorage pair.b
                      ]

      in  { example =
              Ini/externs.renderIni
                ( Ini.appendInis
                    ( Lib.List/map
                        Vdirsyncer.Pair
                        Ini.Ini
                        ( \(pair : Vdirsyncer.Pair) ->
                            { globalSection = [] : Ini.Section
                            , sections = toIniSections pair
                            }
                        )
                        (   [ { pairName = "testPair"
                              , a =
                                { storageName = "mystor"
                                , storage =
                                    Vdirsyncer.StorageType.FileSystem
                                      { path = "./test-ics"
                                      , fileext = < ICS >.ICS
                                      }
                                }
                              , b =
                                { storageName = "mystor"
                                , storage =
                                    Vdirsyncer.StorageType.Http
                                      { url = "https://profpatsch.de" }
                                }
                              , collections = Vdirsyncer.Collections.Unspecified
                              }
                            ]
                          : List Vdirsyncer.Pair
                        )
                    )
                )
          }