Source file s.ml

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
(*
 * Copyright (c) 2013-2022 Thomas Gazagnaire <thomas@gazagnaire.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *)

open! Import
module T = Irmin.Type

module type Helper = sig
  type ctx

  val err_bad_version : string option -> 'a Lwt.t
  val check_version : Cohttp.Response.t -> unit Lwt.t
  val is_success : Cohttp.Response.t -> bool

  val map_string_response :
    (string -> ('a, [< `Msg of string ]) result) ->
    Cohttp.Response.t * Cohttp_lwt.Body.t ->
    'a Lwt.t

  val map_stream_response :
    'a T.t -> Cohttp.Response.t * Cohttp_lwt.Body.t -> 'a Lwt_stream.t Lwt.t

  val headers : keep_alive:bool -> unit -> Cohttp.Header.t

  val map_call :
    Cohttp.Code.meth ->
    Uri.t ->
    ctx option ->
    keep_alive:bool ->
    ?body:string ->
    string list ->
    (Cohttp.Response.t * Cohttp_lwt.Body.t -> 'a Lwt.t) ->
    'a Lwt.t

  val call :
    Cohttp.Code.meth ->
    Uri.t ->
    ctx option ->
    ?body:string ->
    string list ->
    (string -> ('a, [< `Msg of string ]) result) ->
    'a Lwt.t

  val call_stream :
    Cohttp.Code.meth ->
    Uri.t ->
    ctx option ->
    ?body:string ->
    string list ->
    'a T.t ->
    'a Lwt_stream.t Lwt.t
end

module Read_only = struct
  module type S = sig
    type ctx

    type -'a t = {
      uri : Uri.t;
      item : string;
      items : string;
      ctx : ctx option;
    }

    include Irmin.Read_only.S with type 'a t := 'a t
    module HTTP : Helper with type ctx = ctx

    val uri : 'a t -> Uri.t
    val item : 'a t -> string
    val items : 'a t -> string
    val key_str : key -> string
    val val_of_str : value T.of_string
    val v : ?ctx:ctx -> Uri.t -> string -> string -> 'a t Lwt.t
  end
end

module Content_addressable = struct
  module type S = sig
    include Irmin.Content_addressable.S

    type ctx

    val v : ?ctx:ctx -> Uri.t -> string -> string -> 'a t Lwt.t
  end

  module type Maker = functor
    (Client : Cohttp_lwt.S.Client)
    (H : Irmin.Hash.S)
    (V : Irmin.Type.S)
    -> S with type key = H.t and type value = V.t and type ctx = Client.ctx
end

module Atomic_write = struct
  module type S = sig
    include Irmin.Atomic_write.S

    type ctx

    val v : ?ctx:ctx -> Uri.t -> string -> string -> t Lwt.t
  end

  module type Maker = functor
    (Client : Cohttp_lwt.S.Client)
    (B : Irmin.Branch.S)
    (H : Irmin.Hash.S)
    -> sig
    module W : Irmin.Backend.Watch.S with type key = B.t and type value = H.t
    module RO : Read_only.S
    module HTTP = RO.HTTP
    include S with type key = B.t and type value = H.t and type ctx = Client.ctx
  end
end