Matrix protocol in OCaml, Eio specialised
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nox

+1742 -1748
+6 -6
dune-project
··· 17 17 matrix.client for the HTTP client, and matrix.eio for Eio-idiomatic usage.") 18 18 (depends 19 19 (ocaml (>= 5.1)) 20 - jsont 20 + nox-json 21 21 ptime 22 22 requests 23 23 tomlt 24 - xdge 24 + nox-xdge 25 25 uri 26 26 eio 27 27 logs 28 28 base64 29 - mirage-crypto 30 - mirage-crypto-ec 31 - mirage-crypto-rng 29 + nox-crypto 30 + nox-crypto-ec 31 + nox-crypto-rng 32 32 digestif 33 - kdf 33 + nox-kdf 34 34 fmt 35 35 cmdliner 36 36 (alcotest :with-test)
+6 -8
examples/dune
··· 1 - (executable 2 - (name simple_bot) 3 - (libraries matrix.eio matrix.proto jsont eio_main uri)) 4 - 5 - (executable 6 - (name send_dm) 7 - (libraries matrix.eio matrix.proto eio_main uri cmdliner logs logs.cli logs.fmt fmt.tty fmt.cli)) 1 + (executables 2 + (names simple_bot send_dm) 3 + (modules simple_bot send_dm) 4 + (libraries matrix.eio matrix.proto nox-json eio_main uri cmdliner logs logs.cli logs.fmt fmt.tty fmt.cli)) 8 5 9 6 (executable 10 7 (name omatrix) 11 8 (public_name omatrix) 12 9 (package matrix) 10 + (modules omatrix) 13 11 (libraries 14 12 matrix.eio 15 13 matrix.client 16 14 matrix.proto 17 15 eio_main 18 16 uri 19 - xdge 17 + nox-xdge 20 18 ptime.clock.os 21 19 cmdliner))
+1 -1
examples/omatrix.ml
··· 42 42 (** Get XDG directories for session storage *) 43 43 let with_xdg ~env f = 44 44 let fs = Eio.Stdenv.fs env in 45 - let xdg = Xdge.create fs "matrix" in 45 + let xdg = Xdge.v fs "matrix" in 46 46 f xdg 47 47 48 48 (** Load a stored session, returning the store and session data *)
+3 -3
examples/simple_bot.ml
··· 20 20 21 21 (** Helper to extract string from JSON. 22 22 Returns [Some value] if the key exists and is a string, [None] otherwise. *) 23 - let json_get_string key (json : Jsont.json) = 23 + let json_get_string key (json : Json.t) = 24 24 match json with 25 - | Jsont.Object (mems, _) -> 25 + | Json.Object (mems, _) -> 26 26 List.find_map (fun ((name, _), value) -> 27 27 if name = key then 28 28 match value with 29 - | Jsont.String (s, _) -> Some s 29 + | Json.String (s, _) -> Some s 30 30 | _ -> None 31 31 else None 32 32 ) mems
+53 -54
lib/matrix_client/account.ml
··· 12 12 in 13 13 match Client.get client ~path () with 14 14 | Error e -> Error e 15 - | Ok body -> Client.decode_response Jsont.json body 15 + | Ok body -> Client.decode_response Json.Codec.Value.t body 16 16 17 17 let set_account_data client ~event_type ~content = 18 18 match Client.user_id client with ··· 23 23 (Uri.pct_encode user_id_str) 24 24 (Uri.pct_encode event_type) 25 25 in 26 - match Client.encode_body Jsont.json content with 26 + match Client.encode_body Json.Codec.Value.t content with 27 27 | Error e -> Error e 28 28 | Ok body -> 29 29 match Client.put client ~path ~body () with ··· 43 43 in 44 44 match Client.get client ~path () with 45 45 | Error e -> Error e 46 - | Ok body -> Client.decode_response Jsont.json body 46 + | Ok body -> Client.decode_response Json.Codec.Value.t body 47 47 48 48 let set_room_account_data client ~room_id ~event_type ~content = 49 49 match Client.user_id client with ··· 56 56 (Uri.pct_encode room_id_str) 57 57 (Uri.pct_encode event_type) 58 58 in 59 - match Client.encode_body Jsont.json content with 59 + match Client.encode_body Json.Codec.Value.t content with 60 60 | Error e -> Error e 61 61 | Ok body -> 62 62 match Client.put client ~path ~body () with ··· 72 72 } 73 73 74 74 let threepid_jsont = 75 - Jsont.Object.( 75 + Json.Codec.Object.( 76 76 map (fun medium address validated_at added_at -> 77 77 { medium; address; validated_at; added_at }) 78 - |> mem "medium" Jsont.string 79 - |> mem "address" Jsont.string 80 - |> mem "validated_at" Jsont.int64 81 - |> mem "added_at" Jsont.int64 82 - |> finish) 78 + |> member "medium" Json.Codec.string 79 + |> member "address" Json.Codec.string 80 + |> member "validated_at" Json.Codec.int64 81 + |> member "added_at" Json.Codec.int64 82 + |> seal) 83 83 84 84 type threepids_response = { 85 85 threepids : threepid list; 86 86 } 87 87 88 88 let threepids_response_jsont = 89 - Jsont.Object.( 89 + Json.Codec.Object.( 90 90 map (fun threepids -> { threepids }) 91 - |> mem "threepids" (Jsont.list threepid_jsont) ~dec_absent:[] 92 - |> finish) 91 + |> member "threepids" (Json.Codec.list threepid_jsont) ~dec_absent:[] 92 + |> seal) 93 93 94 94 let get_3pids client = 95 95 match Client.get client ~path:"/account/3pid" () with ··· 107 107 } [@@warning "-69"] 108 108 109 109 let email_token_request_jsont = 110 - Jsont.Object.( 110 + Json.Codec.Object.( 111 111 map (fun email client_secret send_attempt -> 112 112 { email; client_secret; send_attempt }) 113 - |> mem "email" Jsont.string 114 - |> mem "client_secret" Jsont.string 115 - |> mem "send_attempt" Jsont.int 116 - |> finish) 113 + |> member "email" Json.Codec.string 114 + |> member "client_secret" Json.Codec.string 115 + |> member "send_attempt" Json.Codec.int 116 + |> seal) 117 117 118 118 type token_response = { 119 119 sid : string; 120 120 } 121 121 122 122 let token_response_jsont = 123 - Jsont.Object.( 123 + Json.Codec.Object.( 124 124 map (fun sid -> { sid }) 125 - |> mem "sid" Jsont.string 126 - |> finish) 125 + |> member "sid" Json.Codec.string 126 + |> seal) 127 127 128 128 let request_email_token client ~email ~client_secret ~send_attempt = 129 129 let request = { email; client_secret; send_attempt } in ··· 146 146 } [@@warning "-69"] 147 147 148 148 let msisdn_token_request_jsont = 149 - Jsont.Object.( 149 + Json.Codec.Object.( 150 150 map (fun country phone_number client_secret send_attempt -> 151 151 { country; phone_number; client_secret; send_attempt }) 152 - |> mem "country" Jsont.string 153 - |> mem "phone_number" Jsont.string 154 - |> mem "client_secret" Jsont.string 155 - |> mem "send_attempt" Jsont.int 156 - |> finish) 152 + |> member "country" Json.Codec.string 153 + |> member "phone_number" Json.Codec.string 154 + |> member "client_secret" Json.Codec.string 155 + |> member "send_attempt" Json.Codec.int 156 + |> seal) 157 157 158 158 let request_msisdn_token client ~country ~phone_number ~client_secret ~send_attempt = 159 159 let request = { country; phone_number; client_secret; send_attempt } in ··· 174 174 } [@@warning "-69"] 175 175 176 176 let add_3pid_request_jsont = 177 - Jsont.Object.( 177 + Json.Codec.Object.( 178 178 map (fun client_secret sid -> { client_secret; sid }) 179 - |> mem "client_secret" Jsont.string 180 - |> mem "sid" Jsont.string 181 - |> finish) 179 + |> member "client_secret" Json.Codec.string 180 + |> member "sid" Json.Codec.string 181 + |> seal) 182 182 183 183 let add_3pid client ~client_secret ~sid = 184 184 let request = { client_secret; sid } in ··· 196 196 } [@@warning "-69"] 197 197 198 198 let delete_3pid_request_jsont = 199 - Jsont.Object.( 199 + Json.Codec.Object.( 200 200 map (fun medium address -> { medium; address }) 201 - |> mem "medium" Jsont.string 202 - |> mem "address" Jsont.string 203 - |> finish) 201 + |> member "medium" Json.Codec.string 202 + |> member "address" Json.Codec.string 203 + |> seal) 204 204 205 205 let delete_3pid client ~medium ~address = 206 206 let request = { medium; address } in ··· 218 218 } [@@warning "-69"] 219 219 220 220 let change_password_request_jsont = 221 - Jsont.Object.( 221 + Json.Codec.Object.( 222 222 map (fun new_password logout_devices -> { new_password; logout_devices }) 223 - |> mem "new_password" Jsont.string 224 - |> mem "logout_devices" Jsont.bool ~dec_absent:false 225 - |> finish) 223 + |> member "new_password" Json.Codec.string 224 + |> member "logout_devices" Json.Codec.bool ~dec_absent:false 225 + |> seal) 226 226 227 227 let change_password client ~new_password ?(logout_devices = false) () = 228 228 let request = { new_password; logout_devices } in ··· 239 239 } [@@warning "-69"] 240 240 241 241 let deactivate_request_jsont = 242 - Jsont.Object.( 242 + Json.Codec.Object.( 243 243 map (fun erase -> { erase }) 244 - |> mem "erase" Jsont.bool ~dec_absent:false 245 - |> finish) 244 + |> member "erase" Json.Codec.bool ~dec_absent:false 245 + |> seal) 246 246 247 247 let deactivate client ?(erase = false) () = 248 248 let request = { erase } in ··· 255 255 256 256 (* Ignored users - stored in account data *) 257 257 type ignored_users_content = { 258 - ignored_users : (string * Jsont.json) list; 258 + ignored_users : (string * Json.t) list; 259 259 } 260 260 261 261 let ignored_users_content_jsont = 262 262 let module StringMap = Map.Make(String) in 263 263 let map_jsont = 264 - Jsont.Object.as_string_map Jsont.json 265 - |> Jsont.map 264 + Json.Codec.Object.as_string_map Json.Codec.Value.t 265 + |> Json.Codec.map 266 266 ~dec:(fun m -> StringMap.bindings m) 267 267 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 268 268 in 269 - Jsont.Object.( 269 + Json.Codec.Object.( 270 270 map (fun ignored_users -> { ignored_users }) 271 - |> mem "ignored_users" map_jsont ~dec_absent:[] 272 - |> finish) 271 + |> member "ignored_users" map_jsont ~dec_absent:[] 272 + |> seal) 273 273 274 274 let get_ignored_users client = 275 275 match get_account_data client ~event_type:"m.ignored_user_list" with 276 276 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok [] 277 277 | Error e -> Error e 278 278 | Ok json -> 279 - match Jsont_bytesrw.decode_string ignored_users_content_jsont 280 - (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with 279 + match (Json.of_string ignored_users_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with 281 280 | Error _ -> Ok [] 282 281 | Ok content -> 283 282 let user_ids = List.filter_map (fun (uid, _) -> ··· 297 296 else 298 297 let new_list = user_id :: current in 299 298 let ignored_map = List.map (fun u -> 300 - (Matrix_proto.Id.User_id.to_string u, Jsont.Json.object' []) 299 + (Matrix_proto.Id.User_id.to_string u, Json.Value.object' []) 301 300 ) new_list in 302 301 let content = { ignored_users = ignored_map } in 303 302 match Client.encode_body ignored_users_content_jsont content with 304 303 | Error e -> Error e 305 304 | Ok body -> 306 - match Client.decode_response Jsont.json body with 305 + match Client.decode_response Json.Codec.Value.t body with 307 306 | Error e -> Error e 308 307 | Ok json -> 309 308 set_account_data client ~event_type:"m.ignored_user_list" ~content:json ··· 317 316 Matrix_proto.Id.User_id.to_string u <> user_id_str 318 317 ) current in 319 318 let ignored_map = List.map (fun u -> 320 - (Matrix_proto.Id.User_id.to_string u, Jsont.Json.object' []) 319 + (Matrix_proto.Id.User_id.to_string u, Json.Value.object' []) 321 320 ) new_list in 322 321 let content = { ignored_users = ignored_map } in 323 322 match Client.encode_body ignored_users_content_jsont content with 324 323 | Error e -> Error e 325 324 | Ok body -> 326 - match Client.decode_response Jsont.json body with 325 + match Client.decode_response Json.Codec.Value.t body with 327 326 | Error e -> Error e 328 327 | Ok json -> 329 328 set_account_data client ~event_type:"m.ignored_user_list" ~content:json
+4 -4
lib/matrix_client/account.mli
··· 6 6 val get_account_data : 7 7 Client.t -> 8 8 event_type:string -> 9 - (Jsont.json, Error.t) result 9 + (Json.t, Error.t) result 10 10 11 11 (** Set global account data. *) 12 12 val set_account_data : 13 13 Client.t -> 14 14 event_type:string -> 15 - content:Jsont.json -> 15 + content:Json.t -> 16 16 (unit, Error.t) result 17 17 18 18 (** Get room-specific account data. *) ··· 20 20 Client.t -> 21 21 room_id:Matrix_proto.Id.Room_id.t -> 22 22 event_type:string -> 23 - (Jsont.json, Error.t) result 23 + (Json.t, Error.t) result 24 24 25 25 (** Set room-specific account data. *) 26 26 val set_room_account_data : 27 27 Client.t -> 28 28 room_id:Matrix_proto.Id.Room_id.t -> 29 29 event_type:string -> 30 - content:Jsont.json -> 30 + content:Json.t -> 31 31 (unit, Error.t) result 32 32 33 33 (** {1 Third-Party Identifiers} *)
+48 -48
lib/matrix_client/auth.ml
··· 24 24 25 25 (* JSON codecs for login flows response *) 26 26 let login_flow_jsont = 27 - Jsont.of_of_string ~kind:"login_flow" 27 + Json.Codec.of_of_string ~kind:"login_flow" 28 28 ~enc:login_flow_to_string 29 29 (fun s -> Ok (login_flow_of_string s)) 30 30 31 31 let login_flow_obj_jsont = 32 - Jsont.Object.map 32 + Json.Codec.Object.map 33 33 ~kind:"login_flow_object" 34 34 (fun flow_type -> flow_type) 35 - |> Jsont.Object.mem "type" login_flow_jsont 36 - |> Jsont.Object.finish 35 + |> Json.Codec.Object.member "type" login_flow_jsont 36 + |> Json.Codec.Object.seal 37 37 38 38 let login_flows_response_jsont = 39 - Jsont.Object.map 39 + Json.Codec.Object.map 40 40 ~kind:"login_flows_response" 41 41 (fun flows -> flows) 42 - |> Jsont.Object.mem "flows" (Jsont.list login_flow_obj_jsont) 43 - |> Jsont.Object.finish 42 + |> Json.Codec.Object.member "flows" (Json.Codec.list login_flow_obj_jsont) 43 + |> Json.Codec.Object.seal 44 44 45 45 let get_login_flows client = 46 46 match Client.get client ~path:"/login" () with ··· 74 74 } [@@warning "-69"] 75 75 76 76 let login_identifier_jsont = 77 - Jsont.Object.( 77 + Json.Codec.Object.( 78 78 map ~kind:"login_identifier" 79 79 (fun id_type user -> { id_type; user }) 80 - |> mem "type" Jsont.string ~enc:(fun t -> t.id_type) 81 - |> opt_mem "user" Jsont.string ~enc:(fun t -> t.user) 82 - |> finish) 80 + |> member "type" Json.Codec.string ~enc:(fun t -> t.id_type) 81 + |> opt_member "user" Json.Codec.string ~enc:(fun t -> t.user) 82 + |> seal) 83 83 84 84 let login_request_jsont = 85 - Jsont.Object.( 85 + Json.Codec.Object.( 86 86 map ~kind:"login_request" 87 87 (fun req_type identifier password token device_id initial_device_display_name -> 88 88 { req_type; identifier; password; token; device_id; initial_device_display_name }) 89 - |> mem "type" Jsont.string ~enc:(fun t -> t.req_type) 90 - |> mem "identifier" login_identifier_jsont ~enc:(fun t -> t.identifier) 91 - |> opt_mem "password" Jsont.string ~enc:(fun t -> t.password) 92 - |> opt_mem "token" Jsont.string ~enc:(fun t -> t.token) 93 - |> opt_mem "device_id" Jsont.string ~enc:(fun t -> t.device_id) 94 - |> opt_mem "initial_device_display_name" Jsont.string 89 + |> member "type" Json.Codec.string ~enc:(fun t -> t.req_type) 90 + |> member "identifier" login_identifier_jsont ~enc:(fun t -> t.identifier) 91 + |> opt_member "password" Json.Codec.string ~enc:(fun t -> t.password) 92 + |> opt_member "token" Json.Codec.string ~enc:(fun t -> t.token) 93 + |> opt_member "device_id" Json.Codec.string ~enc:(fun t -> t.device_id) 94 + |> opt_member "initial_device_display_name" Json.Codec.string 95 95 ~enc:(fun t -> t.initial_device_display_name) 96 - |> finish) 96 + |> seal) 97 97 98 98 (* Login response codec *) 99 99 type login_response = { ··· 104 104 } 105 105 106 106 let login_response_jsont = 107 - Jsont.Object.map 107 + Json.Codec.Object.map 108 108 ~kind:"login_response" 109 109 (fun user_id access_token device_id refresh_token -> 110 110 { user_id; access_token; device_id; refresh_token }) 111 - |> Jsont.Object.mem "user_id" Matrix_proto.Id.User_id.jsont 112 - |> Jsont.Object.mem "access_token" Jsont.string 113 - |> Jsont.Object.mem "device_id" Matrix_proto.Id.Device_id.jsont 114 - |> Jsont.Object.opt_mem "refresh_token" Jsont.string 115 - |> Jsont.Object.finish 111 + |> Json.Codec.Object.member "user_id" Matrix_proto.Id.User_id.jsont 112 + |> Json.Codec.Object.member "access_token" Json.Codec.string 113 + |> Json.Codec.Object.member "device_id" Matrix_proto.Id.Device_id.jsont 114 + |> Json.Codec.Object.opt_member "refresh_token" Json.Codec.string 115 + |> Json.Codec.Object.seal 116 116 117 117 let response_to_session resp : Client.session = 118 118 { user_id = resp.user_id; ··· 172 172 } [@@warning "-69"] 173 173 174 174 let refresh_request_jsont = 175 - Jsont.Object.( 175 + Json.Codec.Object.( 176 176 map ~kind:"refresh_request" 177 177 (fun refresh_token -> { refresh_token }) 178 - |> mem "refresh_token" Jsont.string ~enc:(fun t -> t.refresh_token) 179 - |> finish) 178 + |> member "refresh_token" Json.Codec.string ~enc:(fun t -> t.refresh_token) 179 + |> seal) 180 180 181 181 type refresh_response = { 182 182 access_token : string; ··· 184 184 } 185 185 186 186 let refresh_response_jsont = 187 - Jsont.Object.map 187 + Json.Codec.Object.map 188 188 ~kind:"refresh_response" 189 189 (fun access_token refresh_token -> { access_token; refresh_token }) 190 - |> Jsont.Object.mem "access_token" Jsont.string 191 - |> Jsont.Object.opt_mem "refresh_token" Jsont.string 192 - |> Jsont.Object.finish 190 + |> Json.Codec.Object.member "access_token" Json.Codec.string 191 + |> Json.Codec.Object.opt_member "refresh_token" Json.Codec.string 192 + |> Json.Codec.Object.seal 193 193 194 194 let refresh_token client ~refresh_token = 195 195 let request = { refresh_token } in ··· 229 229 } [@@warning "-69"] 230 230 231 231 let register_request_jsont = 232 - Jsont.Object.( 232 + Json.Codec.Object.( 233 233 map ~kind:"register_request" 234 234 (fun username password device_id initial_device_display_name inhibit_login -> 235 235 { kind = None; username; password; device_id; initial_device_display_name; inhibit_login }) 236 - |> opt_mem "username" Jsont.string ~enc:(fun t -> t.username) 237 - |> opt_mem "password" Jsont.string ~enc:(fun t -> t.password) 238 - |> opt_mem "device_id" Jsont.string ~enc:(fun t -> t.device_id) 239 - |> opt_mem "initial_device_display_name" Jsont.string 236 + |> opt_member "username" Json.Codec.string ~enc:(fun t -> t.username) 237 + |> opt_member "password" Json.Codec.string ~enc:(fun t -> t.password) 238 + |> opt_member "device_id" Json.Codec.string ~enc:(fun t -> t.device_id) 239 + |> opt_member "initial_device_display_name" Json.Codec.string 240 240 ~enc:(fun t -> t.initial_device_display_name) 241 - |> opt_mem "inhibit_login" Jsont.bool ~enc:(fun t -> t.inhibit_login) 242 - |> finish) 241 + |> opt_member "inhibit_login" Json.Codec.bool ~enc:(fun t -> t.inhibit_login) 242 + |> seal) 243 243 244 244 type register_response = { 245 245 user_id : Matrix_proto.Id.User_id.t; ··· 249 249 } 250 250 251 251 let register_response_jsont = 252 - Jsont.Object.map 252 + Json.Codec.Object.map 253 253 ~kind:"register_response" 254 254 (fun user_id access_token device_id refresh_token -> 255 255 { user_id; access_token; device_id; refresh_token }) 256 - |> Jsont.Object.mem "user_id" Matrix_proto.Id.User_id.jsont 257 - |> Jsont.Object.opt_mem "access_token" Jsont.string 258 - |> Jsont.Object.opt_mem "device_id" Jsont.string 259 - |> Jsont.Object.opt_mem "refresh_token" Jsont.string 260 - |> Jsont.Object.finish 256 + |> Json.Codec.Object.member "user_id" Matrix_proto.Id.User_id.jsont 257 + |> Json.Codec.Object.opt_member "access_token" Json.Codec.string 258 + |> Json.Codec.Object.opt_member "device_id" Json.Codec.string 259 + |> Json.Codec.Object.opt_member "refresh_token" Json.Codec.string 260 + |> Json.Codec.Object.seal 261 261 262 262 let register client ?kind ?username ?password ?device_id ?initial_device_display_name ?inhibit_login () = 263 263 let kind_str = match kind with ··· 301 301 } 302 302 303 303 let whoami_response_jsont = 304 - Jsont.Object.map 304 + Json.Codec.Object.map 305 305 ~kind:"whoami_response" 306 306 (fun user_id -> { user_id }) 307 - |> Jsont.Object.mem "user_id" Matrix_proto.Id.User_id.jsont 308 - |> Jsont.Object.finish 307 + |> Json.Codec.Object.member "user_id" Matrix_proto.Id.User_id.jsont 308 + |> Json.Codec.Object.seal 309 309 310 310 let whoami client = 311 311 match Client.get client ~path:"/account/whoami" () with
+10 -10
lib/matrix_client/backup.ml
··· 9 9 Note: Due to various known flaws in this algorithm, it is provided mainly 10 10 for backwards compatibility with existing backups. *) 11 11 12 - open Mirage_crypto_ec 12 + open Crypto_ec 13 13 14 14 (** {1 Backup Key Types} *) 15 15 ··· 67 67 (** Room key backup info - describes the backup algorithm and parameters *) 68 68 type backup_info = 69 69 | Megolm_v1_curve25519_aes_sha2 of megolm_v1_auth_data 70 - | Other of { algorithm : string; auth_data : Jsont.json } 70 + | Other of { algorithm : string; auth_data : Json.t } 71 71 72 72 (** Backup version info from server *) 73 73 type backup_version_info = { 74 74 version : string; 75 75 algorithm : string; 76 - auth_data : Jsont.json; 76 + auth_data : Json.t; 77 77 count : int; 78 78 etag : string; 79 79 } ··· 181 181 let padded = payload ^ String.make pad_len (Char.chr pad_len) in 182 182 183 183 (* Generate random IV *) 184 - let iv = Mirage_crypto_rng.generate 16 in 184 + let iv = Crypto_rng.generate 16 in 185 185 186 186 (* Encrypt with AES-256-CBC *) 187 - let key = Mirage_crypto.AES.CBC.of_secret aes_key in 188 - let ciphertext = Mirage_crypto.AES.CBC.encrypt ~key ~iv padded in 187 + let key = Crypto.AES.CBC.of_secret aes_key in 188 + let ciphertext = Crypto.AES.CBC.encrypt ~key ~iv padded in 189 189 190 190 (* Prepend IV to ciphertext for MAC calculation *) 191 191 let mac_input = iv ^ ciphertext in ··· 241 241 let ciphertext = String.sub ciphertext_with_iv 16 (String.length ciphertext_with_iv - 16) in 242 242 243 243 (* Decrypt with AES-256-CBC *) 244 - let key = Mirage_crypto.AES.CBC.of_secret aes_key in 245 - let plaintext = Mirage_crypto.AES.CBC.decrypt ~key ~iv ciphertext in 244 + let key = Crypto.AES.CBC.of_secret aes_key in 245 + let plaintext = Crypto.AES.CBC.decrypt ~key ~iv ciphertext in 246 246 247 247 (* Remove PKCS#7 padding *) 248 248 let pad_len = Char.code (String.get plaintext (String.length plaintext - 1)) in ··· 379 379 match String.split_on_char '"' str with 380 380 | _ -> None 381 381 in 382 - (* Simplified - would use Jsont in real implementation *) 383 - match Jsont_bytesrw.decode_string Jsont.json json_str with 382 + (* Simplified - would use Json in real implementation *) 383 + match (Json.of_string Json.Codec.Value.t json_str |> Result.map_error Json.Error.to_string) with 384 384 | Error _ -> None 385 385 | Ok _json -> None (* Would extract fields from JSON *) 386 386
+2 -2
lib/matrix_client/backup.mli
··· 55 55 (** Room key backup info - describes the backup algorithm and parameters. *) 56 56 type backup_info = 57 57 | Megolm_v1_curve25519_aes_sha2 of megolm_v1_auth_data 58 - | Other of { algorithm : string; auth_data : Jsont.json } 58 + | Other of { algorithm : string; auth_data : Json.t } 59 59 60 60 (** Backup version info from server. *) 61 61 type backup_version_info = { 62 62 version : string; 63 63 algorithm : string; 64 - auth_data : Jsont.json; 64 + auth_data : Json.t; 65 65 count : int; 66 66 etag : string; 67 67 }
+6 -6
lib/matrix_client/calls.ml
··· 177 177 } 178 178 179 179 let turn_server_jsont = 180 - Jsont.Object.( 180 + Json.Codec.Object.( 181 181 map (fun username password uris ttl -> 182 182 { username; password; uris; ttl }) 183 - |> mem "username" Jsont.string ~enc:(fun t -> t.username) 184 - |> mem "password" Jsont.string ~enc:(fun t -> t.password) 185 - |> mem "uris" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.uris) 186 - |> mem "ttl" Jsont.int ~enc:(fun t -> t.ttl) 187 - |> finish) 183 + |> member "username" Json.Codec.string ~enc:(fun t -> t.username) 184 + |> member "password" Json.Codec.string ~enc:(fun t -> t.password) 185 + |> member "uris" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.uris) 186 + |> member "ttl" Json.Codec.int ~enc:(fun t -> t.ttl) 187 + |> seal) 188 188 189 189 (** Get TURN server credentials from the homeserver. *) 190 190 let get_turn_server client =
+1 -1
lib/matrix_client/calls.mli
··· 112 112 ttl : int; 113 113 } 114 114 115 - val turn_server_jsont : turn_server Jsont.t 115 + val turn_server_jsont : turn_server Json.codec 116 116 (** JSON codec for TURN server. *) 117 117 118 118 val get_turn_server : Client.t -> (turn_server, Error.t) result
+4 -4
lib/matrix_client/client.ml
··· 20 20 } 21 21 22 22 let create ~sw ~config env = 23 - let http = Requests.create ~sw env in 23 + let http = Requests.v ~sw env in 24 24 { http; config; session = None } 25 25 26 26 let with_session t session = ··· 69 69 else begin 70 70 Log.warn (fun m -> m "HTTP error: status=%d body=%s" status body); 71 71 (* Try to parse as Matrix error *) 72 - match Jsont_bytesrw.decode_string Error.matrix_error_jsont body with 72 + match (Json.of_string Error.matrix_error_jsont body |> Result.map_error Json.Error.to_string) with 73 73 | Ok matrix_err -> Error (Error.Matrix_error matrix_err) 74 74 | Error _ -> Error (Error.Http_error { status; body }) 75 75 end ··· 153 153 Error (Error.Network_error (Printexc.to_string exn)) 154 154 155 155 let decode_response jsont body = 156 - match Jsont_bytesrw.decode_string jsont body with 156 + match (Json.of_string jsont body |> Result.map_error Json.Error.to_string) with 157 157 | Ok v -> Ok v 158 158 | Error e -> 159 159 Log.err (fun m -> m "JSON decode error: %s" e); 160 160 Error (Error.Json_error e) 161 161 162 162 let encode_body jsont value = 163 - match Jsont_bytesrw.encode_string jsont value with 163 + match (try Ok (Json.to_string jsont value) with Json.Error e -> Error (Json.Error.to_string e)) with 164 164 | Ok s -> Ok s 165 165 | Error e -> 166 166 Log.err (fun m -> m "JSON encode error: %s" e);
+2 -2
lib/matrix_client/client.mli
··· 103 103 (string, Error.t) result 104 104 105 105 (** Decode a JSON response using a jsont codec. *) 106 - val decode_response : 'a Jsont.t -> string -> ('a, Error.t) result 106 + val decode_response : 'a Json.codec -> string -> ('a, Error.t) result 107 107 108 108 (** Encode a value to JSON string using a jsont codec. 109 109 Returns Error if encoding fails. *) 110 - val encode_body : 'a Jsont.t -> 'a -> (string, Error.t) result 110 + val encode_body : 'a Json.codec -> 'a -> (string, Error.t) result
+15 -15
lib/matrix_client/devices.ml
··· 8 8 } 9 9 10 10 let device_jsont = 11 - Jsont.Object.( 11 + Json.Codec.Object.( 12 12 map (fun device_id display_name last_seen_ip last_seen_ts -> 13 13 { device_id; display_name; last_seen_ip; last_seen_ts }) 14 - |> mem "device_id" Jsont.string 15 - |> opt_mem "display_name" Jsont.string ~enc:(fun t -> t.display_name) 16 - |> opt_mem "last_seen_ip" Jsont.string ~enc:(fun t -> t.last_seen_ip) 17 - |> opt_mem "last_seen_ts" Jsont.int64 ~enc:(fun t -> t.last_seen_ts) 18 - |> finish) 14 + |> member "device_id" Json.Codec.string 15 + |> opt_member "display_name" Json.Codec.string ~enc:(fun t -> t.display_name) 16 + |> opt_member "last_seen_ip" Json.Codec.string ~enc:(fun t -> t.last_seen_ip) 17 + |> opt_member "last_seen_ts" Json.Codec.int64 ~enc:(fun t -> t.last_seen_ts) 18 + |> seal) 19 19 20 20 type devices_response = { 21 21 devices : device list; 22 22 } 23 23 24 24 let devices_response_jsont = 25 - Jsont.Object.( 25 + Json.Codec.Object.( 26 26 map (fun devices -> { devices }) 27 - |> mem "devices" (Jsont.list device_jsont) ~dec_absent:[] 28 - |> finish) 27 + |> member "devices" (Json.Codec.list device_jsont) ~dec_absent:[] 28 + |> seal) 29 29 30 30 let get_devices client = 31 31 match Client.get client ~path:"/devices" () with ··· 46 46 } [@@warning "-69"] 47 47 48 48 let update_device_request_jsont = 49 - Jsont.Object.( 49 + Json.Codec.Object.( 50 50 map (fun display_name -> { display_name }) 51 - |> mem "display_name" Jsont.string 52 - |> finish) 51 + |> member "display_name" Json.Codec.string 52 + |> seal) 53 53 54 54 let update_device client ~device_id ~display_name = 55 55 let path = Printf.sprintf "/devices/%s" (Uri.pct_encode device_id) in ··· 74 74 } [@@warning "-69"] 75 75 76 76 let delete_devices_request_jsont = 77 - Jsont.Object.( 77 + Json.Codec.Object.( 78 78 map (fun devices -> { devices }) 79 - |> mem "devices" (Jsont.list Jsont.string) 80 - |> finish) 79 + |> member "devices" (Json.Codec.list Json.Codec.string) 80 + |> seal) 81 81 82 82 let delete_devices client ~device_ids = 83 83 let request = { devices = device_ids } in
+39 -39
lib/matrix_client/directory.ml
··· 7 7 } 8 8 9 9 let alias_info_jsont = 10 - Jsont.Object.( 10 + Json.Codec.Object.( 11 11 map (fun room_id servers -> { room_id; servers }) 12 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 13 - |> mem "servers" (Jsont.list Jsont.string) ~dec_absent:[] 14 - |> finish) 12 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 13 + |> member "servers" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 14 + |> seal) 15 15 16 16 let resolve_alias client ~alias = 17 17 let alias_str = Matrix_proto.Id.Room_alias.to_string alias in ··· 26 26 } [@@warning "-69"] 27 27 28 28 let create_alias_request_jsont = 29 - Jsont.Object.( 29 + Json.Codec.Object.( 30 30 map (fun room_id -> { room_id }) 31 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 32 - |> finish) 31 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 32 + |> seal) 33 33 34 34 let create_alias client ~alias ~room_id = 35 35 let alias_str = Matrix_proto.Id.Room_alias.to_string alias in ··· 58 58 } 59 59 60 60 let visibility_response_jsont = 61 - Jsont.Object.( 61 + Json.Codec.Object.( 62 62 map (fun visibility -> { visibility }) 63 - |> mem "visibility" Jsont.string 64 - |> finish) 63 + |> member "visibility" Json.Codec.string 64 + |> seal) 65 65 66 66 let get_visibility client ~room_id = 67 67 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 81 81 } [@@warning "-69"] 82 82 83 83 let set_visibility_request_jsont = 84 - Jsont.Object.( 84 + Json.Codec.Object.( 85 85 map (fun visibility -> { visibility }) 86 - |> mem "visibility" Jsont.string 87 - |> finish) 86 + |> member "visibility" Json.Codec.string 87 + |> seal) 88 88 89 89 let set_visibility client ~room_id ~visibility = 90 90 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 123 123 } [@@warning "-69"] 124 124 125 125 let search_filter_request_jsont = 126 - Jsont.Object.( 126 + Json.Codec.Object.( 127 127 map (fun generic_search_term room_types -> 128 128 { generic_search_term; room_types }) 129 - |> opt_mem "generic_search_term" Jsont.string ~enc:(fun (t : search_filter_request) -> t.generic_search_term) 130 - |> opt_mem "room_types" (Jsont.list Jsont.string) ~enc:(fun (t : search_filter_request) -> t.room_types) 131 - |> finish) 129 + |> opt_member "generic_search_term" Json.Codec.string ~enc:(fun (t : search_filter_request) -> t.generic_search_term) 130 + |> opt_member "room_types" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : search_filter_request) -> t.room_types) 131 + |> seal) 132 132 133 133 let search_request_jsont = 134 - Jsont.Object.( 134 + Json.Codec.Object.( 135 135 map (fun filter limit since -> { filter; limit; since }) 136 - |> opt_mem "filter" search_filter_request_jsont ~enc:(fun (t : search_request) -> t.filter) 137 - |> opt_mem "limit" Jsont.int ~enc:(fun (t : search_request) -> t.limit) 138 - |> opt_mem "since" Jsont.string ~enc:(fun (t : search_request) -> t.since) 139 - |> finish) 136 + |> opt_member "filter" search_filter_request_jsont ~enc:(fun (t : search_request) -> t.filter) 137 + |> opt_member "limit" Json.Codec.int ~enc:(fun (t : search_request) -> t.limit) 138 + |> opt_member "since" Json.Codec.string ~enc:(fun (t : search_request) -> t.since) 139 + |> seal) 140 140 141 141 (* Reuse public_room_jsont from Rooms - need to duplicate here *) 142 - let public_room_jsont : Rooms.public_room Jsont.t = 143 - Jsont.Object.( 142 + let public_room_jsont : Rooms.public_room Json.codec = 143 + Json.Codec.Object.( 144 144 map (fun room_id name topic num_joined_members world_readable guest_can_join avatar_url canonical_alias -> 145 145 ({ room_id; name; topic; num_joined_members; world_readable; guest_can_join; avatar_url; canonical_alias } : Rooms.public_room)) 146 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 147 - |> opt_mem "name" Jsont.string ~enc:(fun (t : Rooms.public_room) -> t.name) 148 - |> opt_mem "topic" Jsont.string ~enc:(fun (t : Rooms.public_room) -> t.topic) 149 - |> mem "num_joined_members" Jsont.int ~dec_absent:0 ~enc:(fun (t : Rooms.public_room) -> t.num_joined_members) 150 - |> mem "world_readable" Jsont.bool ~dec_absent:false ~enc:(fun (t : Rooms.public_room) -> t.world_readable) 151 - |> mem "guest_can_join" Jsont.bool ~dec_absent:false ~enc:(fun (t : Rooms.public_room) -> t.guest_can_join) 152 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun (t : Rooms.public_room) -> t.avatar_url) 153 - |> opt_mem "canonical_alias" Jsont.string ~enc:(fun (t : Rooms.public_room) -> t.canonical_alias) 154 - |> finish) 146 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 147 + |> opt_member "name" Json.Codec.string ~enc:(fun (t : Rooms.public_room) -> t.name) 148 + |> opt_member "topic" Json.Codec.string ~enc:(fun (t : Rooms.public_room) -> t.topic) 149 + |> member "num_joined_members" Json.Codec.int ~dec_absent:0 ~enc:(fun (t : Rooms.public_room) -> t.num_joined_members) 150 + |> member "world_readable" Json.Codec.bool ~dec_absent:false ~enc:(fun (t : Rooms.public_room) -> t.world_readable) 151 + |> member "guest_can_join" Json.Codec.bool ~dec_absent:false ~enc:(fun (t : Rooms.public_room) -> t.guest_can_join) 152 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun (t : Rooms.public_room) -> t.avatar_url) 153 + |> opt_member "canonical_alias" Json.Codec.string ~enc:(fun (t : Rooms.public_room) -> t.canonical_alias) 154 + |> seal) 155 155 156 156 let search_result_jsont = 157 - Jsont.Object.( 157 + Json.Codec.Object.( 158 158 map (fun chunk next_batch prev_batch total_room_count_estimate -> 159 159 { chunk; next_batch; prev_batch; total_room_count_estimate }) 160 - |> mem "chunk" (Jsont.list public_room_jsont) ~dec_absent:[] 161 - |> opt_mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 162 - |> opt_mem "prev_batch" Jsont.string ~enc:(fun t -> t.prev_batch) 163 - |> opt_mem "total_room_count_estimate" Jsont.int ~enc:(fun t -> t.total_room_count_estimate) 164 - |> finish) 160 + |> member "chunk" (Json.Codec.list public_room_jsont) ~dec_absent:[] 161 + |> opt_member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 162 + |> opt_member "prev_batch" Json.Codec.string ~enc:(fun t -> t.prev_batch) 163 + |> opt_member "total_room_count_estimate" Json.Codec.int ~enc:(fun t -> t.total_room_count_estimate) 164 + |> seal) 165 165 166 166 let search client ?server ?limit ?since ?(filter : search_filter option) () = 167 167 let path = "/publicRooms" in
+7 -7
lib/matrix_client/dune
··· 4 4 (libraries 5 5 matrix.proto 6 6 requests 7 - jsont 8 - jsont.bytesrw 7 + nox-json 9 8 tomlt 10 9 tomlt.eio 11 - xdge 10 + nox-xdge 12 11 eio 13 12 ptime 14 13 base64 15 - mirage-crypto 16 - mirage-crypto-ec 17 - mirage-crypto-rng 14 + nox-crypto 15 + nox-crypto-ec 16 + nox-crypto-rng 17 + nox-crypto-rng.unix 18 18 digestif 19 - kdf.hkdf 19 + nox-kdf.hkdf 20 20 logs 21 21 logs.cli 22 22 logs.fmt
+7 -7
lib/matrix_client/error.ml
··· 107 107 | s -> M_UNKNOWN_CODE s 108 108 109 109 let errcode_jsont = 110 - Jsont.of_of_string ~kind:"errcode" 110 + Json.Codec.of_of_string ~kind:"errcode" 111 111 ~enc:errcode_to_string 112 112 (fun s -> Ok (errcode_of_string s)) 113 113 ··· 119 119 } 120 120 121 121 let matrix_error_jsont = 122 - Jsont.Object.( 122 + Json.Codec.Object.( 123 123 map (fun errcode error retry_after_ms soft_logout -> 124 124 { errcode; error; retry_after_ms; soft_logout }) 125 - |> mem "errcode" errcode_jsont ~enc:(fun e -> e.errcode) 126 - |> mem "error" Jsont.string ~dec_absent:"" ~enc:(fun e -> e.error) 127 - |> opt_mem "retry_after_ms" Jsont.int ~enc:(fun e -> e.retry_after_ms) 128 - |> opt_mem "soft_logout" Jsont.bool ~enc:(fun e -> e.soft_logout) 129 - |> finish) 125 + |> member "errcode" errcode_jsont ~enc:(fun e -> e.errcode) 126 + |> member "error" Json.Codec.string ~dec_absent:"" ~enc:(fun e -> e.error) 127 + |> opt_member "retry_after_ms" Json.Codec.int ~enc:(fun e -> e.retry_after_ms) 128 + |> opt_member "soft_logout" Json.Codec.bool ~enc:(fun e -> e.soft_logout) 129 + |> seal) 130 130 131 131 type t = 132 132 | Matrix_error of matrix_error
+1 -1
lib/matrix_client/error.mli
··· 52 52 } 53 53 54 54 (** jsont codec for matrix_error. *) 55 - val matrix_error_jsont : matrix_error Jsont.t 55 + val matrix_error_jsont : matrix_error Json.codec 56 56 57 57 (** SDK error type. *) 58 58 type t =
+83 -83
lib/matrix_client/keys.ml
··· 3 3 This module handles device keys, one-time keys, and key exchange 4 4 for end-to-end encryption using Olm/Megolm protocols. *) 5 5 6 - module Ed25519 = Mirage_crypto_ec.Ed25519 7 - module X25519 = Mirage_crypto_ec.X25519 6 + module Ed25519 = Crypto_ec.Ed25519 7 + module X25519 = Crypto_ec.X25519 8 8 9 9 (* Base64 encoding/decoding - Matrix uses unpadded base64 *) 10 10 let base64_encode s = ··· 153 153 154 154 module StringMap = Map.Make(String) 155 155 156 - let string_string_map_jsont : (string * string) list Jsont.t = 157 - let map_jsont = Jsont.Object.as_string_map Jsont.string in 158 - Jsont.map 156 + let string_string_map_jsont : (string * string) list Json.codec = 157 + let map_jsont = Json.Codec.Object.as_string_map Json.Codec.string in 158 + Json.Codec.map 159 159 ~dec:(fun m -> StringMap.bindings m) 160 160 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 161 161 map_jsont 162 162 163 - let signatures_jsont : (string * (string * string) list) list Jsont.t = 164 - let inner = Jsont.Object.as_string_map Jsont.string in 165 - let outer = Jsont.Object.as_string_map inner in 166 - Jsont.map 163 + let signatures_jsont : (string * (string * string) list) list Json.codec = 164 + let inner = Json.Codec.Object.as_string_map Json.Codec.string in 165 + let outer = Json.Codec.Object.as_string_map inner in 166 + Json.Codec.map 167 167 ~dec:(fun m -> 168 168 StringMap.bindings m 169 169 |> List.map (fun (k, v) -> (k, StringMap.bindings v))) ··· 172 172 |> List.to_seq |> StringMap.of_seq) 173 173 outer 174 174 175 - let device_keys_json_jsont : device_keys_json Jsont.t = 176 - Jsont.Object.( 175 + let device_keys_json_jsont : device_keys_json Json.codec = 176 + Json.Codec.Object.( 177 177 map (fun user_id device_id algorithms keys signatures -> 178 178 { user_id; device_id; algorithms; keys; signatures }) 179 - |> mem "user_id" Jsont.string 180 - |> mem "device_id" Jsont.string 181 - |> mem "algorithms" (Jsont.list Jsont.string) 182 - |> mem "keys" string_string_map_jsont 183 - |> mem "signatures" signatures_jsont 184 - |> finish) 179 + |> member "user_id" Json.Codec.string 180 + |> member "device_id" Json.Codec.string 181 + |> member "algorithms" (Json.Codec.list Json.Codec.string) 182 + |> member "keys" string_string_map_jsont 183 + |> member "signatures" signatures_jsont 184 + |> seal) 185 185 186 - let one_time_key_json_jsont : one_time_key_json Jsont.t = 187 - Jsont.Object.( 186 + let one_time_key_json_jsont : one_time_key_json Json.codec = 187 + Json.Codec.Object.( 188 188 map (fun key signatures -> { key; signatures }) 189 - |> mem "key" Jsont.string 190 - |> opt_mem "signatures" signatures_jsont ~enc:(fun (t : one_time_key_json) -> t.signatures) 191 - |> finish) 189 + |> member "key" Json.Codec.string 190 + |> opt_member "signatures" signatures_jsont ~enc:(fun (t : one_time_key_json) -> t.signatures) 191 + |> seal) 192 192 193 - let one_time_keys_map_jsont : (string * one_time_key_json) list Jsont.t = 194 - let map_jsont = Jsont.Object.as_string_map one_time_key_json_jsont in 195 - Jsont.map 193 + let one_time_keys_map_jsont : (string * one_time_key_json) list Json.codec = 194 + let map_jsont = Json.Codec.Object.as_string_map one_time_key_json_jsont in 195 + Json.Codec.map 196 196 ~dec:(fun m -> StringMap.bindings m) 197 197 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 198 198 map_jsont 199 199 200 - let upload_keys_request_jsont : upload_keys_request Jsont.t = 201 - Jsont.Object.( 200 + let upload_keys_request_jsont : upload_keys_request Json.codec = 201 + Json.Codec.Object.( 202 202 map (fun device_keys one_time_keys fallback_keys -> 203 203 { device_keys; one_time_keys; fallback_keys }) 204 - |> opt_mem "device_keys" device_keys_json_jsont ~enc:(fun t -> t.device_keys) 205 - |> mem "one_time_keys" one_time_keys_map_jsont ~dec_absent:[] 206 - |> mem "fallback_keys" one_time_keys_map_jsont ~dec_absent:[] 207 - |> finish) 204 + |> opt_member "device_keys" device_keys_json_jsont ~enc:(fun t -> t.device_keys) 205 + |> member "one_time_keys" one_time_keys_map_jsont ~dec_absent:[] 206 + |> member "fallback_keys" one_time_keys_map_jsont ~dec_absent:[] 207 + |> seal) 208 208 209 209 (* Upload keys response *) 210 210 type upload_keys_response = { 211 211 one_time_key_counts : (string * int) list; 212 212 } 213 213 214 - let one_time_key_counts_jsont : (string * int) list Jsont.t = 215 - let map_jsont = Jsont.Object.as_string_map Jsont.int in 216 - Jsont.map 214 + let one_time_key_counts_jsont : (string * int) list Json.codec = 215 + let map_jsont = Json.Codec.Object.as_string_map Json.Codec.int in 216 + Json.Codec.map 217 217 ~dec:(fun m -> StringMap.bindings m) 218 218 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 219 219 map_jsont 220 220 221 221 let upload_keys_response_jsont = 222 - Jsont.Object.( 222 + Json.Codec.Object.( 223 223 map (fun one_time_key_counts -> { one_time_key_counts }) 224 - |> mem "one_time_key_counts" one_time_key_counts_jsont ~dec_absent:[] 225 - |> finish) 224 + |> member "one_time_key_counts" one_time_key_counts_jsont ~dec_absent:[] 225 + |> seal) 226 226 227 227 (* Upload device keys *) 228 228 let upload_keys client ?device_keys ?(one_time_keys=[]) ?(fallback_keys=[]) () = ··· 240 240 device_keys : (string * string list) list; (* user_id -> device_ids *) 241 241 } [@@warning "-69"] 242 242 243 - let device_keys_query_jsont : (string * string list) list Jsont.t = 244 - let map_jsont = Jsont.Object.as_string_map (Jsont.list Jsont.string) in 245 - Jsont.map 243 + let device_keys_query_jsont : (string * string list) list Json.codec = 244 + let map_jsont = Json.Codec.Object.as_string_map (Json.Codec.list Json.Codec.string) in 245 + Json.Codec.map 246 246 ~dec:(fun m -> StringMap.bindings m) 247 247 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 248 248 map_jsont 249 249 250 250 let query_keys_request_jsont = 251 - Jsont.Object.( 251 + Json.Codec.Object.( 252 252 map (fun timeout device_keys -> { timeout; device_keys }) 253 - |> opt_mem "timeout" Jsont.int ~enc:(fun t -> t.timeout) 254 - |> mem "device_keys" device_keys_query_jsont 255 - |> finish) 253 + |> opt_member "timeout" Json.Codec.int ~enc:(fun t -> t.timeout) 254 + |> member "device_keys" device_keys_query_jsont 255 + |> seal) 256 256 257 257 type queried_device_keys = { 258 258 user_id : string; ··· 260 260 algorithms : string list; 261 261 keys : (string * string) list; 262 262 signatures : (string * (string * string) list) list; 263 - unsigned : Jsont.json option; 263 + unsigned : Json.t option; 264 264 } 265 265 266 266 let queried_device_keys_jsont = 267 - Jsont.Object.( 267 + Json.Codec.Object.( 268 268 map (fun user_id device_id algorithms keys signatures unsigned -> 269 269 { user_id; device_id; algorithms; keys; signatures; unsigned }) 270 - |> mem "user_id" Jsont.string 271 - |> mem "device_id" Jsont.string 272 - |> mem "algorithms" (Jsont.list Jsont.string) ~dec_absent:[] 273 - |> mem "keys" string_string_map_jsont ~dec_absent:[] 274 - |> mem "signatures" signatures_jsont ~dec_absent:[] 275 - |> opt_mem "unsigned" Jsont.json ~enc:(fun t -> t.unsigned) 276 - |> finish) 270 + |> member "user_id" Json.Codec.string 271 + |> member "device_id" Json.Codec.string 272 + |> member "algorithms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 273 + |> member "keys" string_string_map_jsont ~dec_absent:[] 274 + |> member "signatures" signatures_jsont ~dec_absent:[] 275 + |> opt_member "unsigned" Json.Codec.Value.t ~enc:(fun t -> t.unsigned) 276 + |> seal) 277 277 278 278 type query_keys_response = { 279 - failures : (string * Jsont.json) list; 279 + failures : (string * Json.t) list; 280 280 device_keys : (string * (string * queried_device_keys) list) list; 281 281 } 282 282 283 283 let device_keys_map_jsont = 284 - let inner = Jsont.Object.as_string_map queried_device_keys_jsont in 285 - let outer = Jsont.Object.as_string_map inner in 286 - Jsont.map 284 + let inner = Json.Codec.Object.as_string_map queried_device_keys_jsont in 285 + let outer = Json.Codec.Object.as_string_map inner in 286 + Json.Codec.map 287 287 ~dec:(fun m -> 288 288 StringMap.bindings m 289 289 |> List.map (fun (k, v) -> (k, StringMap.bindings v))) ··· 293 293 outer 294 294 295 295 let failures_jsont = 296 - let map_jsont = Jsont.Object.as_string_map Jsont.json in 297 - Jsont.map 296 + let map_jsont = Json.Codec.Object.as_string_map Json.Codec.Value.t in 297 + Json.Codec.map 298 298 ~dec:(fun m -> StringMap.bindings m) 299 299 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 300 300 map_jsont 301 301 302 302 let query_keys_response_jsont = 303 - Jsont.Object.( 303 + Json.Codec.Object.( 304 304 map (fun failures device_keys -> { failures; device_keys }) 305 - |> mem "failures" failures_jsont ~dec_absent:[] 306 - |> mem "device_keys" device_keys_map_jsont ~dec_absent:[] 307 - |> finish) 305 + |> member "failures" failures_jsont ~dec_absent:[] 306 + |> member "device_keys" device_keys_map_jsont ~dec_absent:[] 307 + |> seal) 308 308 309 309 (* Query device keys *) 310 310 let query_keys client ?timeout ~users () = ··· 326 326 } [@@warning "-69"] 327 327 328 328 let one_time_keys_claim_jsont = 329 - let inner = Jsont.Object.as_string_map Jsont.string in 330 - let outer = Jsont.Object.as_string_map inner in 331 - Jsont.map 329 + let inner = Json.Codec.Object.as_string_map Json.Codec.string in 330 + let outer = Json.Codec.Object.as_string_map inner in 331 + Json.Codec.map 332 332 ~dec:(fun m -> 333 333 StringMap.bindings m 334 334 |> List.map (fun (k, v) -> (k, StringMap.bindings v))) ··· 338 338 outer 339 339 340 340 let claim_keys_request_jsont = 341 - Jsont.Object.( 341 + Json.Codec.Object.( 342 342 map (fun timeout one_time_keys -> { timeout; one_time_keys }) 343 - |> opt_mem "timeout" Jsont.int ~enc:(fun t -> t.timeout) 344 - |> mem "one_time_keys" one_time_keys_claim_jsont 345 - |> finish) 343 + |> opt_member "timeout" Json.Codec.int ~enc:(fun t -> t.timeout) 344 + |> member "one_time_keys" one_time_keys_claim_jsont 345 + |> seal) 346 346 347 347 type claim_keys_response = { 348 - failures : (string * Jsont.json) list; 348 + failures : (string * Json.t) list; 349 349 one_time_keys : (string * (string * (string * one_time_key_json) list) list) list; 350 350 } 351 351 352 352 let claimed_keys_map_jsont = 353 - let key_map = Jsont.Object.as_string_map one_time_key_json_jsont in 354 - let device_map = Jsont.Object.as_string_map key_map in 355 - let user_map = Jsont.Object.as_string_map device_map in 356 - Jsont.map 353 + let key_map = Json.Codec.Object.as_string_map one_time_key_json_jsont in 354 + let device_map = Json.Codec.Object.as_string_map key_map in 355 + let user_map = Json.Codec.Object.as_string_map device_map in 356 + Json.Codec.map 357 357 ~dec:(fun m -> 358 358 StringMap.bindings m 359 359 |> List.map (fun (user, devices) -> ··· 368 368 user_map 369 369 370 370 let claim_keys_response_jsont = 371 - Jsont.Object.( 371 + Json.Codec.Object.( 372 372 map (fun failures one_time_keys -> { failures; one_time_keys }) 373 - |> mem "failures" failures_jsont ~dec_absent:[] 374 - |> mem "one_time_keys" claimed_keys_map_jsont ~dec_absent:[] 375 - |> finish) 373 + |> member "failures" failures_jsont ~dec_absent:[] 374 + |> member "one_time_keys" claimed_keys_map_jsont ~dec_absent:[] 375 + |> seal) 376 376 377 377 (* Claim one-time keys for Olm session establishment *) 378 378 let claim_keys client ?timeout ~keys () = ··· 398 398 } 399 399 400 400 let key_changes_response_jsont = 401 - Jsont.Object.( 401 + Json.Codec.Object.( 402 402 map (fun changed left -> { changed; left }) 403 - |> mem "changed" (Jsont.list Jsont.string) ~dec_absent:[] 404 - |> mem "left" (Jsont.list Jsont.string) ~dec_absent:[] 405 - |> finish) 403 + |> member "changed" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 404 + |> member "left" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 405 + |> seal) 406 406 407 407 let get_key_changes client ~from ~to_ = 408 408 let query = [("from", from); ("to", to_)] in
+16 -16
lib/matrix_client/keys.mli
··· 9 9 10 10 (** Ed25519 key pair for signing. *) 11 11 type ed25519_keypair = { 12 - priv : Mirage_crypto_ec.Ed25519.priv; 13 - pub : Mirage_crypto_ec.Ed25519.pub; 12 + priv : Crypto_ec.Ed25519.priv; 13 + pub : Crypto_ec.Ed25519.pub; 14 14 } 15 15 16 16 (** Curve25519 key pair for key exchange. *) 17 17 type curve25519_keypair = { 18 - secret : Mirage_crypto_ec.X25519.secret; 18 + secret : Crypto_ec.X25519.secret; 19 19 public : string; 20 20 } 21 21 ··· 58 58 @return List of (one_time_key, curve25519_keypair) tuples. *) 59 59 val generate_one_time_keys : 60 60 count:int -> 61 - ?sign_with:Mirage_crypto_ec.Ed25519.priv -> 61 + ?sign_with:Crypto_ec.Ed25519.priv -> 62 62 unit -> 63 63 (one_time_key * curve25519_keypair) list 64 64 65 65 (** {1 Key Serialization} *) 66 66 67 67 (** Encode Ed25519 public key to unpadded base64. *) 68 - val ed25519_pub_to_base64 : Mirage_crypto_ec.Ed25519.pub -> string 68 + val ed25519_pub_to_base64 : Crypto_ec.Ed25519.pub -> string 69 69 70 70 (** Encode Ed25519 private key to unpadded base64. *) 71 - val ed25519_priv_to_base64 : Mirage_crypto_ec.Ed25519.priv -> string 71 + val ed25519_priv_to_base64 : Crypto_ec.Ed25519.priv -> string 72 72 73 73 (** Encode Curve25519 public key to unpadded base64. *) 74 74 val curve25519_pub_to_base64 : string -> string 75 75 76 76 (** Encode Curve25519 secret key to unpadded base64. *) 77 - val curve25519_secret_to_base64 : Mirage_crypto_ec.X25519.secret -> string 77 + val curve25519_secret_to_base64 : Crypto_ec.X25519.secret -> string 78 78 79 79 (** Decode Ed25519 public key from base64. *) 80 - val ed25519_pub_of_base64 : string -> (Mirage_crypto_ec.Ed25519.pub, string) result 80 + val ed25519_pub_of_base64 : string -> (Crypto_ec.Ed25519.pub, string) result 81 81 82 82 (** Decode Ed25519 private key from base64. *) 83 - val ed25519_priv_of_base64 : string -> (Mirage_crypto_ec.Ed25519.priv, string) result 83 + val ed25519_priv_of_base64 : string -> (Crypto_ec.Ed25519.priv, string) result 84 84 85 85 (** Decode Curve25519 public key from base64. *) 86 86 val curve25519_pub_of_base64 : string -> (string, string) result 87 87 88 88 (** Decode Curve25519 secret key from base64. *) 89 - val curve25519_secret_of_base64 : string -> (Mirage_crypto_ec.X25519.secret, string) result 89 + val curve25519_secret_of_base64 : string -> (Crypto_ec.X25519.secret, string) result 90 90 91 91 (** {1 Signing and Verification} *) 92 92 93 93 (** Sign a JSON string with Ed25519. 94 94 95 95 @return Base64-encoded signature. *) 96 - val sign_json : Mirage_crypto_ec.Ed25519.priv -> string -> string 96 + val sign_json : Crypto_ec.Ed25519.priv -> string -> string 97 97 98 98 (** Verify an Ed25519 signature. 99 99 100 100 @param signature_b64 Base64-encoded signature. 101 101 @return true if signature is valid. *) 102 - val verify_signature : Mirage_crypto_ec.Ed25519.pub -> string -> string -> bool 102 + val verify_signature : Crypto_ec.Ed25519.pub -> string -> string -> bool 103 103 104 104 (** {1 Key Exchange} *) 105 105 ··· 109 109 @param their_public Their public key (raw bytes). 110 110 @return Shared secret or error. *) 111 111 val key_exchange : 112 - secret:Mirage_crypto_ec.X25519.secret -> 112 + secret:Crypto_ec.X25519.secret -> 113 113 their_public:string -> 114 114 (string, string) result 115 115 ··· 157 157 algorithms : string list; 158 158 keys : (string * string) list; 159 159 signatures : (string * (string * string) list) list; 160 - unsigned : Jsont.json option; 160 + unsigned : Json.t option; 161 161 } 162 162 163 163 (** Response from key query. *) 164 164 type query_keys_response = { 165 - failures : (string * Jsont.json) list; 165 + failures : (string * Json.t) list; 166 166 device_keys : (string * (string * queried_device_keys) list) list; 167 167 } 168 168 ··· 181 181 182 182 (** Response from key claim. *) 183 183 type claim_keys_response = { 184 - failures : (string * Jsont.json) list; 184 + failures : (string * Json.t) list; 185 185 one_time_keys : (string * (string * (string * one_time_key_json) list) list) list; 186 186 } 187 187
+6 -6
lib/matrix_client/media.ml
··· 9 9 } [@@warning "-69"] 10 10 11 11 let _upload_response_jsont = 12 - Jsont.Object.( 12 + Json.Codec.Object.( 13 13 map (fun content_uri -> { content_uri }) 14 - |> mem "content_uri" Jsont.string 15 - |> finish) 14 + |> member "content_uri" Json.Codec.string 15 + |> seal) 16 16 17 17 let upload client ~content_type:_ ~data:_ ?filename:_ () = 18 18 (* Note: This is a simplified version - actual implementation would need ··· 100 100 } 101 101 102 102 let config_jsont = 103 - Jsont.Object.( 103 + Json.Codec.Object.( 104 104 map (fun upload_size -> { upload_size }) 105 - |> opt_mem "m.upload.size" Jsont.int ~enc:(fun t -> t.upload_size) 106 - |> finish) 105 + |> opt_member "m.upload.size" Json.Codec.int ~enc:(fun t -> t.upload_size) 106 + |> seal) 107 107 108 108 let get_config client = 109 109 let homeserver = Client.homeserver client in
+39 -39
lib/matrix_client/messages.ml
··· 13 13 } 14 14 15 15 let send_response_jsont = 16 - Jsont.Object.( 16 + Json.Codec.Object.( 17 17 map (fun event_id -> { event_id }) 18 - |> mem "event_id" Matrix_proto.Id.Event_id.jsont 19 - |> finish) 18 + |> member "event_id" Matrix_proto.Id.Event_id.jsont 19 + |> seal) 20 20 21 21 (* Generic send event *) 22 22 let send_event client ~room_id ~event_type ~content = ··· 27 27 (Uri.pct_encode event_type) 28 28 (Uri.pct_encode txn_id) 29 29 in 30 - match Client.encode_body Jsont.json content with 30 + match Client.encode_body Json.Codec.Value.t content with 31 31 | Error e -> Error e 32 32 | Ok body -> 33 33 match Client.put client ~path ~body () with ··· 46 46 } [@@warning "-69"] 47 47 48 48 let text_content_jsont = 49 - Jsont.Object.( 49 + Json.Codec.Object.( 50 50 map (fun msgtype body format formatted_body -> 51 51 { msgtype; body; format; formatted_body }) 52 - |> mem "msgtype" Jsont.string ~enc:(fun t -> t.msgtype) 53 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 54 - |> opt_mem "format" Jsont.string ~enc:(fun t -> t.format) 55 - |> opt_mem "formatted_body" Jsont.string ~enc:(fun t -> t.formatted_body) 56 - |> finish) 52 + |> member "msgtype" Json.Codec.string ~enc:(fun t -> t.msgtype) 53 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 54 + |> opt_member "format" Json.Codec.string ~enc:(fun t -> t.format) 55 + |> opt_member "formatted_body" Json.Codec.string ~enc:(fun t -> t.formatted_body) 56 + |> seal) 57 57 58 58 let send_text client ~room_id ~body ?format ?formatted_body () = 59 59 let content = { msgtype = "m.text"; body; format; formatted_body } in 60 60 match Client.encode_body text_content_jsont content with 61 61 | Error e -> Error e 62 62 | Ok json_str -> 63 - match Client.decode_response Jsont.json json_str with 63 + match Client.decode_response Json.Codec.Value.t json_str with 64 64 | Error e -> Error e 65 65 | Ok json -> send_event client ~room_id ~event_type:"m.room.message" ~content:json 66 66 ··· 69 69 match Client.encode_body text_content_jsont content with 70 70 | Error e -> Error e 71 71 | Ok json_str -> 72 - match Client.decode_response Jsont.json json_str with 72 + match Client.decode_response Json.Codec.Value.t json_str with 73 73 | Error e -> Error e 74 74 | Ok json -> send_event client ~room_id ~event_type:"m.room.message" ~content:json 75 75 ··· 78 78 match Client.encode_body text_content_jsont content with 79 79 | Error e -> Error e 80 80 | Ok json_str -> 81 - match Client.decode_response Jsont.json json_str with 81 + match Client.decode_response Json.Codec.Value.t json_str with 82 82 | Error e -> Error e 83 83 | Ok json -> send_event client ~room_id ~event_type:"m.room.message" ~content:json 84 84 ··· 87 87 msgtype : string; 88 88 body : string; 89 89 url : string; 90 - info : Jsont.json option; 90 + info : Json.t option; 91 91 } [@@warning "-69"] 92 92 93 93 let media_content_jsont = 94 - Jsont.Object.( 94 + Json.Codec.Object.( 95 95 map (fun msgtype body url info -> 96 96 { msgtype; body; url; info }) 97 - |> mem "msgtype" Jsont.string ~enc:(fun t -> t.msgtype) 98 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 99 - |> mem "url" Jsont.string ~enc:(fun t -> t.url) 100 - |> opt_mem "info" Jsont.json ~enc:(fun t -> t.info) 101 - |> finish) 97 + |> member "msgtype" Json.Codec.string ~enc:(fun t -> t.msgtype) 98 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 99 + |> member "url" Json.Codec.string ~enc:(fun t -> t.url) 100 + |> opt_member "info" Json.Codec.Value.t ~enc:(fun t -> t.info) 101 + |> seal) 102 102 103 103 let send_image client ~room_id ~body ~url ?info () = 104 104 let content = { msgtype = "m.image"; body; url; info } in 105 105 match Client.encode_body media_content_jsont content with 106 106 | Error e -> Error e 107 107 | Ok json_str -> 108 - match Client.decode_response Jsont.json json_str with 108 + match Client.decode_response Json.Codec.Value.t json_str with 109 109 | Error e -> Error e 110 110 | Ok json -> send_event client ~room_id ~event_type:"m.room.message" ~content:json 111 111 ··· 114 114 match Client.encode_body media_content_jsont content with 115 115 | Error e -> Error e 116 116 | Ok json_str -> 117 - match Client.decode_response Jsont.json json_str with 117 + match Client.decode_response Json.Codec.Value.t json_str with 118 118 | Error e -> Error e 119 119 | Ok json -> send_event client ~room_id ~event_type:"m.room.message" ~content:json 120 120 ··· 124 124 } [@@warning "-69"] 125 125 126 126 let redact_request_jsont = 127 - Jsont.Object.( 127 + Json.Codec.Object.( 128 128 map (fun reason -> { reason }) 129 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 130 - |> finish) 129 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 130 + |> seal) 131 131 132 132 let redact client ~room_id ~event_id ?reason () = 133 133 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 160 160 } 161 161 162 162 let messages_response_jsont = 163 - Jsont.Object.( 163 + Json.Codec.Object.( 164 164 map (fun start end_ chunk state -> 165 165 { start; end_; chunk; state }) 166 - |> mem "start" Jsont.string 167 - |> opt_mem "end" Jsont.string ~enc:(fun t -> t.end_) 168 - |> mem "chunk" (Jsont.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 169 - |> mem "state" (Jsont.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 170 - |> finish) 166 + |> member "start" Json.Codec.string 167 + |> opt_member "end" Json.Codec.string ~enc:(fun t -> t.end_) 168 + |> member "chunk" (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 169 + |> member "state" (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 170 + |> seal) 171 171 172 172 let get_messages client ~room_id ~from ~dir ?limit ?filter () = 173 173 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 205 205 } 206 206 207 207 let context_jsont = 208 - Jsont.Object.( 208 + Json.Codec.Object.( 209 209 map (fun start end_ event events_before events_after state -> 210 210 { start; end_; event; events_before; events_after; state }) 211 - |> mem "start" Jsont.string 212 - |> mem "end" Jsont.string 213 - |> mem "event" Matrix_proto.Event.Raw_event.jsont 214 - |> mem "events_before" (Jsont.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 215 - |> mem "events_after" (Jsont.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 216 - |> mem "state" (Jsont.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 217 - |> finish) 211 + |> member "start" Json.Codec.string 212 + |> member "end" Json.Codec.string 213 + |> member "event" Matrix_proto.Event.Raw_event.jsont 214 + |> member "events_before" (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 215 + |> member "events_after" (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 216 + |> member "state" (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) ~dec_absent:[] 217 + |> seal) 218 218 219 219 let get_context client ~room_id ~event_id ?limit () = 220 220 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in
+4 -4
lib/matrix_client/messages.mli
··· 8 8 } 9 9 10 10 (** JSON codec for send_response. *) 11 - val send_response_jsont : send_response Jsont.t 11 + val send_response_jsont : send_response Json.codec 12 12 13 13 (** Send a text message. 14 14 ··· 48 48 room_id:Matrix_proto.Id.Room_id.t -> 49 49 body:string -> 50 50 url:string -> 51 - ?info:Jsont.json -> 51 + ?info:Json.t -> 52 52 unit -> 53 53 (Matrix_proto.Id.Event_id.t, Error.t) result 54 54 ··· 60 60 room_id:Matrix_proto.Id.Room_id.t -> 61 61 body:string -> 62 62 url:string -> 63 - ?info:Jsont.json -> 63 + ?info:Json.t -> 64 64 unit -> 65 65 (Matrix_proto.Id.Event_id.t, Error.t) result 66 66 ··· 72 72 Client.t -> 73 73 room_id:Matrix_proto.Id.Room_id.t -> 74 74 event_type:string -> 75 - content:Jsont.json -> 75 + content:Json.t -> 76 76 (Matrix_proto.Id.Event_id.t, Error.t) result 77 77 78 78 (** {1 Redaction} *)
+13 -13
lib/matrix_client/olm.ml
··· 3 3 This module implements the Olm double-ratchet algorithm for encrypted 4 4 to-device messages, and Megolm for encrypted room messages. *) 5 5 6 - module Ed25519 = Mirage_crypto_ec.Ed25519 7 - module X25519 = Mirage_crypto_ec.X25519 6 + module Ed25519 = Crypto_ec.Ed25519 7 + module X25519 = Crypto_ec.X25519 8 8 9 9 (* Base64 encoding/decoding - Matrix uses unpadded base64 *) 10 10 let base64_encode s = Base64.encode_string ~pad:false s ··· 359 359 let pad_len = block_size - (String.length plaintext mod block_size) in 360 360 let padded = plaintext ^ String.make pad_len (Char.chr pad_len) in 361 361 (* Encrypt using mirage-crypto AES.CBC *) 362 - let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in 363 - let encrypted = Mirage_crypto.AES.CBC.encrypt ~key:cipher ~iv padded in 362 + let cipher = Crypto.AES.CBC.of_secret aes_key in 363 + let encrypted = Crypto.AES.CBC.encrypt ~key:cipher ~iv padded in 364 364 iv ^ encrypted 365 365 366 366 (** Decrypt a message *) ··· 371 371 let iv = String.sub ciphertext 0 16 in 372 372 let data = String.sub ciphertext 16 (String.length ciphertext - 16) in 373 373 let aes_key = String.sub key 0 32 in 374 - let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in 375 - let decrypted = Mirage_crypto.AES.CBC.decrypt ~key:cipher ~iv data in 374 + let cipher = Crypto.AES.CBC.of_secret aes_key in 375 + let decrypted = Crypto.AES.CBC.decrypt ~key:cipher ~iv data in 376 376 (* Remove PKCS7 padding *) 377 377 if String.length decrypted = 0 then 378 378 Error "Empty plaintext" ··· 534 534 | _ -> 535 535 (* Generate random initial state if parsing fails *) 536 536 let random_part () = 537 - Mirage_crypto_rng.generate 32 537 + Crypto_rng.generate 32 538 538 in 539 539 [| random_part (); random_part (); random_part (); random_part () |] 540 540 in ··· 583 583 Error "MAC verification failed" 584 584 else begin 585 585 (* Decrypt using mirage-crypto AES.CBC *) 586 - let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in 587 - let decrypted = Mirage_crypto.AES.CBC.decrypt ~key:cipher ~iv ct_data in 586 + let cipher = Crypto.AES.CBC.of_secret aes_key in 587 + let decrypted = Crypto.AES.CBC.decrypt ~key:cipher ~iv ct_data in 588 588 (* Remove PKCS7 padding *) 589 589 let pad_len = Char.code decrypted.[String.length decrypted - 1] in 590 590 if pad_len > 16 then ··· 622 622 (** Create a new outbound session for a room *) 623 623 let create ~room_id = 624 624 let session_id = 625 - Mirage_crypto_rng.generate 16 625 + Crypto_rng.generate 16 626 626 |> base64_encode 627 627 in 628 628 let random_part () = 629 - Mirage_crypto_rng.generate 32 629 + Crypto_rng.generate 32 630 630 in 631 631 let ratchet = [| random_part (); random_part (); random_part (); random_part () |] in 632 632 let signing_priv, signing_pub = Ed25519.generate () in ··· 696 696 let pad_len = block_size - (String.length plaintext mod block_size) in 697 697 let padded = plaintext ^ String.make pad_len (Char.chr pad_len) in 698 698 (* Encrypt using mirage-crypto AES.CBC *) 699 - let cipher = Mirage_crypto.AES.CBC.of_secret aes_key in 700 - let ct_data = Mirage_crypto.AES.CBC.encrypt ~key:cipher ~iv padded in 699 + let cipher = Crypto.AES.CBC.of_secret aes_key in 700 + let ct_data = Crypto.AES.CBC.encrypt ~key:cipher ~iv padded in 701 701 (* Add HMAC (first 8 bytes) *) 702 702 let mac = 703 703 Digestif.SHA256.hmac_string ~key:hmac_key ct_data
+8 -8
lib/matrix_client/olm.mli
··· 16 16 module Account : sig 17 17 (** Account type. *) 18 18 type t = { 19 - ed25519_priv : Mirage_crypto_ec.Ed25519.priv; 20 - ed25519_pub : Mirage_crypto_ec.Ed25519.pub; 21 - curve25519_secret : Mirage_crypto_ec.X25519.secret; 19 + ed25519_priv : Crypto_ec.Ed25519.priv; 20 + ed25519_pub : Crypto_ec.Ed25519.pub; 21 + curve25519_secret : Crypto_ec.X25519.secret; 22 22 curve25519_public : string; 23 - mutable one_time_keys : (string * (Mirage_crypto_ec.X25519.secret * string)) list; 24 - mutable fallback_key : (string * (Mirage_crypto_ec.X25519.secret * string)) option; 23 + mutable one_time_keys : (string * (Crypto_ec.X25519.secret * string)) list; 24 + mutable fallback_key : (string * (Crypto_ec.X25519.secret * string)) option; 25 25 mutable next_key_id : int; 26 26 max_one_time_keys : int; 27 27 } ··· 82 82 session_id : string; 83 83 their_identity_key : string; 84 84 mutable their_ratchet_key : string option; 85 - mutable our_ratchet_secret : Mirage_crypto_ec.X25519.secret; 85 + mutable our_ratchet_secret : Crypto_ec.X25519.secret; 86 86 mutable our_ratchet_public : string; 87 87 mutable root_key : root_key; 88 88 mutable sending_chain : chain_key option; ··· 187 187 room_id : string; 188 188 mutable ratchet : string array; 189 189 mutable message_index : int; 190 - signing_priv : Mirage_crypto_ec.Ed25519.priv; 191 - signing_pub : Mirage_crypto_ec.Ed25519.pub; 190 + signing_priv : Crypto_ec.Ed25519.priv; 191 + signing_pub : Crypto_ec.Ed25519.pub; 192 192 creation_time : Ptime.t; 193 193 mutable message_count : int; 194 194 max_messages : int;
+11 -11
lib/matrix_client/presence.ml
··· 17 17 | s -> Error ("Unknown presence state: " ^ s) 18 18 19 19 let presence_state_jsont = 20 - Jsont.of_of_string ~kind:"presence_state" 20 + Json.Codec.of_of_string ~kind:"presence_state" 21 21 ~enc:presence_state_to_string 22 22 presence_state_of_string 23 23 ··· 29 29 } 30 30 31 31 let presence_jsont = 32 - Jsont.Object.( 32 + Json.Codec.Object.( 33 33 map (fun presence status_msg last_active_ago currently_active -> 34 34 { presence; status_msg; last_active_ago; currently_active }) 35 - |> mem "presence" presence_state_jsont 36 - |> opt_mem "status_msg" Jsont.string ~enc:(fun t -> t.status_msg) 37 - |> opt_mem "last_active_ago" Jsont.int ~enc:(fun t -> t.last_active_ago) 38 - |> opt_mem "currently_active" Jsont.bool ~enc:(fun t -> t.currently_active) 39 - |> finish) 35 + |> member "presence" presence_state_jsont 36 + |> opt_member "status_msg" Json.Codec.string ~enc:(fun t -> t.status_msg) 37 + |> opt_member "last_active_ago" Json.Codec.int ~enc:(fun t -> t.last_active_ago) 38 + |> opt_member "currently_active" Json.Codec.bool ~enc:(fun t -> t.currently_active) 39 + |> seal) 40 40 41 41 let get_presence client ~user_id = 42 42 let user_id_str = Matrix_proto.Id.User_id.to_string user_id in ··· 51 51 } [@@warning "-69"] 52 52 53 53 let set_presence_request_jsont = 54 - Jsont.Object.( 54 + Json.Codec.Object.( 55 55 map (fun presence status_msg -> { presence; status_msg }) 56 - |> mem "presence" presence_state_jsont 57 - |> opt_mem "status_msg" Jsont.string ~enc:(fun t -> t.status_msg) 58 - |> finish) 56 + |> member "presence" presence_state_jsont 57 + |> opt_member "status_msg" Json.Codec.string ~enc:(fun t -> t.status_msg) 58 + |> seal) 59 59 60 60 let set_presence client ~presence ?status_msg () = 61 61 match Client.user_id client with
+16 -16
lib/matrix_client/profile.ml
··· 6 6 } 7 7 8 8 let profile_jsont = 9 - Jsont.Object.( 9 + Json.Codec.Object.( 10 10 map (fun displayname avatar_url -> { displayname; avatar_url }) 11 - |> opt_mem "displayname" Jsont.string ~enc:(fun t -> t.displayname) 12 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 13 - |> finish) 11 + |> opt_member "displayname" Json.Codec.string ~enc:(fun t -> t.displayname) 12 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 13 + |> seal) 14 14 15 15 let get_profile client ~user_id = 16 16 let user_id_str = Matrix_proto.Id.User_id.to_string user_id in ··· 24 24 } 25 25 26 26 let displayname_response_jsont = 27 - Jsont.Object.( 27 + Json.Codec.Object.( 28 28 map (fun displayname -> { displayname }) 29 - |> opt_mem "displayname" Jsont.string 30 - |> finish) 29 + |> opt_member "displayname" Json.Codec.string 30 + |> seal) 31 31 32 32 let get_displayname client ~user_id = 33 33 let user_id_str = Matrix_proto.Id.User_id.to_string user_id in ··· 44 44 } 45 45 46 46 let avatar_url_response_jsont = 47 - Jsont.Object.( 47 + Json.Codec.Object.( 48 48 map (fun avatar_url -> { avatar_url }) 49 - |> opt_mem "avatar_url" Jsont.string 50 - |> finish) 49 + |> opt_member "avatar_url" Json.Codec.string 50 + |> seal) 51 51 52 52 let get_avatar_url client ~user_id = 53 53 let user_id_str = Matrix_proto.Id.User_id.to_string user_id in ··· 64 64 } [@@warning "-69"] 65 65 66 66 let set_displayname_request_jsont = 67 - Jsont.Object.( 67 + Json.Codec.Object.( 68 68 map (fun displayname -> { displayname }) 69 - |> mem "displayname" Jsont.string 70 - |> finish) 69 + |> member "displayname" Json.Codec.string 70 + |> seal) 71 71 72 72 let set_displayname client ~displayname = 73 73 match Client.user_id client with ··· 88 88 } [@@warning "-69"] 89 89 90 90 let set_avatar_url_request_jsont = 91 - Jsont.Object.( 91 + Json.Codec.Object.( 92 92 map (fun avatar_url -> { avatar_url }) 93 - |> mem "avatar_url" Jsont.string 94 - |> finish) 93 + |> member "avatar_url" Json.Codec.string 94 + |> seal) 95 95 96 96 let set_avatar_url client ~avatar_url = 97 97 match Client.user_id client with
+69 -69
lib/matrix_client/push.ml
··· 24 24 | s -> Error ("Unknown rule kind: " ^ s) 25 25 26 26 let rule_kind_jsont = 27 - Jsont.of_of_string ~kind:"rule_kind" 27 + Json.Codec.of_of_string ~kind:"rule_kind" 28 28 ~enc:rule_kind_to_string 29 29 rule_kind_of_string 30 30 ··· 33 33 | Notify 34 34 | Dont_notify 35 35 | Coalesce 36 - | Set_tweak of string * Jsont.json 36 + | Set_tweak of string * Json.t 37 37 38 38 (* For actions, we use a string codec as a simplification *) 39 - let action_jsont : action Jsont.t = 40 - Jsont.string 41 - |> Jsont.map 39 + let action_jsont : action Json.codec = 40 + Json.Codec.string 41 + |> Json.Codec.map 42 42 ~dec:(function 43 43 | "notify" -> Notify 44 44 | "dont_notify" -> Dont_notify ··· 59 59 } 60 60 61 61 let condition_jsont = 62 - Jsont.Object.( 62 + Json.Codec.Object.( 63 63 map (fun kind key pattern is_ -> { kind; key; pattern; is_ }) 64 - |> mem "kind" Jsont.string ~enc:(fun t -> t.kind) 65 - |> opt_mem "key" Jsont.string ~enc:(fun t -> t.key) 66 - |> opt_mem "pattern" Jsont.string ~enc:(fun t -> t.pattern) 67 - |> opt_mem "is" Jsont.string ~enc:(fun t -> t.is_) 68 - |> finish) 64 + |> member "kind" Json.Codec.string ~enc:(fun t -> t.kind) 65 + |> opt_member "key" Json.Codec.string ~enc:(fun t -> t.key) 66 + |> opt_member "pattern" Json.Codec.string ~enc:(fun t -> t.pattern) 67 + |> opt_member "is" Json.Codec.string ~enc:(fun t -> t.is_) 68 + |> seal) 69 69 70 70 (** Push rule *) 71 71 type rule = { ··· 78 78 } 79 79 80 80 let rule_jsont = 81 - Jsont.Object.( 81 + Json.Codec.Object.( 82 82 map (fun rule_id default enabled actions conditions pattern -> 83 83 { rule_id; default; enabled; actions; conditions; pattern }) 84 - |> mem "rule_id" Jsont.string ~enc:(fun t -> t.rule_id) 85 - |> mem "default" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.default) 86 - |> mem "enabled" Jsont.bool ~dec_absent:true ~enc:(fun t -> t.enabled) 87 - |> mem "actions" (Jsont.list action_jsont) ~dec_absent:[] ~enc:(fun t -> t.actions) 88 - |> opt_mem "conditions" (Jsont.list condition_jsont) ~enc:(fun t -> t.conditions) 89 - |> opt_mem "pattern" Jsont.string ~enc:(fun t -> t.pattern) 90 - |> finish) 84 + |> member "rule_id" Json.Codec.string ~enc:(fun t -> t.rule_id) 85 + |> member "default" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.default) 86 + |> member "enabled" Json.Codec.bool ~dec_absent:true ~enc:(fun t -> t.enabled) 87 + |> member "actions" (Json.Codec.list action_jsont) ~dec_absent:[] ~enc:(fun t -> t.actions) 88 + |> opt_member "conditions" (Json.Codec.list condition_jsont) ~enc:(fun t -> t.conditions) 89 + |> opt_member "pattern" Json.Codec.string ~enc:(fun t -> t.pattern) 90 + |> seal) 91 91 92 92 (** Push ruleset *) 93 93 type ruleset = { ··· 99 99 } 100 100 101 101 let ruleset_jsont = 102 - Jsont.Object.( 102 + Json.Codec.Object.( 103 103 map (fun override underride sender room content -> 104 104 { override; underride; sender; room; content }) 105 - |> mem "override" (Jsont.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.override) 106 - |> mem "underride" (Jsont.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.underride) 107 - |> mem "sender" (Jsont.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.sender) 108 - |> mem "room" (Jsont.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.room) 109 - |> mem "content" (Jsont.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.content) 110 - |> finish) 105 + |> member "override" (Json.Codec.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.override) 106 + |> member "underride" (Json.Codec.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.underride) 107 + |> member "sender" (Json.Codec.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.sender) 108 + |> member "room" (Json.Codec.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.room) 109 + |> member "content" (Json.Codec.list rule_jsont) ~dec_absent:[] ~enc:(fun t -> t.content) 110 + |> seal) 111 111 112 112 type push_rules_response = { 113 113 global : ruleset; 114 114 } 115 115 116 116 let push_rules_response_jsont = 117 - Jsont.Object.( 117 + Json.Codec.Object.( 118 118 map (fun global -> { global }) 119 - |> mem "global" ruleset_jsont ~enc:(fun t -> t.global) 120 - |> finish) 119 + |> member "global" ruleset_jsont ~enc:(fun t -> t.global) 120 + |> seal) 121 121 122 122 (** Get all push rules. *) 123 123 let get_push_rules client = ··· 157 157 } [@@warning "-69"] 158 158 159 159 let add_rule_request_jsont = 160 - Jsont.Object.( 160 + Json.Codec.Object.( 161 161 map (fun actions conditions pattern -> 162 162 { actions; conditions; pattern }) 163 - |> mem "actions" (Jsont.list action_jsont) ~enc:(fun t -> t.actions) 164 - |> opt_mem "conditions" (Jsont.list condition_jsont) ~enc:(fun t -> t.conditions) 165 - |> opt_mem "pattern" Jsont.string ~enc:(fun t -> t.pattern) 166 - |> finish) 163 + |> member "actions" (Json.Codec.list action_jsont) ~enc:(fun t -> t.actions) 164 + |> opt_member "conditions" (Json.Codec.list condition_jsont) ~enc:(fun t -> t.conditions) 165 + |> opt_member "pattern" Json.Codec.string ~enc:(fun t -> t.pattern) 166 + |> seal) 167 167 168 168 let set_push_rule client ~scope ~kind ~rule_id 169 169 ~actions ?conditions ?pattern ?before ?after () = ··· 193 193 } [@@warning "-69"] 194 194 195 195 let enabled_request_jsont = 196 - Jsont.Object.( 196 + Json.Codec.Object.( 197 197 map (fun enabled -> { enabled }) 198 - |> mem "enabled" Jsont.bool ~enc:(fun t -> t.enabled) 199 - |> finish) 198 + |> member "enabled" Json.Codec.bool ~enc:(fun t -> t.enabled) 199 + |> seal) 200 200 201 201 let set_push_rule_enabled client ~scope ~kind ~rule_id ~enabled = 202 202 let kind_str = rule_kind_to_string kind in ··· 219 219 } [@@warning "-69"] 220 220 221 221 let actions_request_jsont = 222 - Jsont.Object.( 222 + Json.Codec.Object.( 223 223 map (fun actions -> { actions }) 224 - |> mem "actions" (Jsont.list action_jsont) ~enc:(fun t -> t.actions) 225 - |> finish) 224 + |> member "actions" (Json.Codec.list action_jsont) ~enc:(fun t -> t.actions) 225 + |> seal) 226 226 227 227 let set_push_rule_actions client ~scope ~kind ~rule_id ~actions = 228 228 let kind_str = rule_kind_to_string kind in ··· 254 254 | s -> Error ("Unknown pusher kind: " ^ s) 255 255 256 256 let pusher_kind_jsont = 257 - Jsont.of_of_string ~kind:"pusher_kind" 257 + Json.Codec.of_of_string ~kind:"pusher_kind" 258 258 ~enc:pusher_kind_to_string 259 259 pusher_kind_of_string 260 260 ··· 264 264 } 265 265 266 266 let pusher_data_jsont = 267 - Jsont.Object.( 267 + Json.Codec.Object.( 268 268 map (fun url format -> { url; format }) 269 - |> opt_mem "url" Jsont.string ~enc:(fun t -> t.url) 270 - |> opt_mem "format" Jsont.string ~enc:(fun t -> t.format) 271 - |> finish) 269 + |> opt_member "url" Json.Codec.string ~enc:(fun t -> t.url) 270 + |> opt_member "format" Json.Codec.string ~enc:(fun t -> t.format) 271 + |> seal) 272 272 273 273 type pusher = { 274 274 pushkey : string; ··· 282 282 } 283 283 284 284 let pusher_jsont = 285 - Jsont.Object.( 285 + Json.Codec.Object.( 286 286 map (fun pushkey kind app_id app_display_name device_display_name 287 287 profile_tag lang data -> 288 288 { pushkey; kind; app_id; app_display_name; device_display_name; 289 289 profile_tag; lang; data }) 290 - |> mem "pushkey" Jsont.string ~enc:(fun t -> t.pushkey) 291 - |> mem "kind" pusher_kind_jsont ~enc:(fun t -> t.kind) 292 - |> mem "app_id" Jsont.string ~enc:(fun t -> t.app_id) 293 - |> mem "app_display_name" Jsont.string ~enc:(fun t -> t.app_display_name) 294 - |> mem "device_display_name" Jsont.string ~enc:(fun t -> t.device_display_name) 295 - |> opt_mem "profile_tag" Jsont.string ~enc:(fun t -> t.profile_tag) 296 - |> mem "lang" Jsont.string ~enc:(fun t -> t.lang) 297 - |> mem "data" pusher_data_jsont ~enc:(fun t -> t.data) 298 - |> finish) 290 + |> member "pushkey" Json.Codec.string ~enc:(fun t -> t.pushkey) 291 + |> member "kind" pusher_kind_jsont ~enc:(fun t -> t.kind) 292 + |> member "app_id" Json.Codec.string ~enc:(fun t -> t.app_id) 293 + |> member "app_display_name" Json.Codec.string ~enc:(fun t -> t.app_display_name) 294 + |> member "device_display_name" Json.Codec.string ~enc:(fun t -> t.device_display_name) 295 + |> opt_member "profile_tag" Json.Codec.string ~enc:(fun t -> t.profile_tag) 296 + |> member "lang" Json.Codec.string ~enc:(fun t -> t.lang) 297 + |> member "data" pusher_data_jsont ~enc:(fun t -> t.data) 298 + |> seal) 299 299 300 300 type pushers_response = { 301 301 pushers : pusher list; 302 302 } 303 303 304 304 let pushers_response_jsont = 305 - Jsont.Object.( 305 + Json.Codec.Object.( 306 306 map (fun pushers -> { pushers }) 307 - |> mem "pushers" (Jsont.list pusher_jsont) ~dec_absent:[] ~enc:(fun t -> t.pushers) 308 - |> finish) 307 + |> member "pushers" (Json.Codec.list pusher_jsont) ~dec_absent:[] ~enc:(fun t -> t.pushers) 308 + |> seal) 309 309 310 310 (** Get all pushers for the current user. *) 311 311 let get_pushers client = ··· 330 330 } [@@warning "-69"] 331 331 332 332 let set_pusher_request_jsont = 333 - Jsont.Object.( 333 + Json.Codec.Object.( 334 334 map (fun pushkey kind app_id app_display_name device_display_name 335 335 profile_tag lang data append -> 336 336 { pushkey; kind; app_id; app_display_name; device_display_name; 337 337 profile_tag; lang; data; append }) 338 - |> mem "pushkey" Jsont.string 339 - |> mem "kind" pusher_kind_jsont 340 - |> mem "app_id" Jsont.string 341 - |> mem "app_display_name" Jsont.string 342 - |> mem "device_display_name" Jsont.string 343 - |> opt_mem "profile_tag" Jsont.string ~enc:(fun t -> t.profile_tag) 344 - |> mem "lang" Jsont.string 345 - |> mem "data" pusher_data_jsont 346 - |> opt_mem "append" Jsont.bool ~enc:(fun t -> t.append) 347 - |> finish) 338 + |> member "pushkey" Json.Codec.string 339 + |> member "kind" pusher_kind_jsont 340 + |> member "app_id" Json.Codec.string 341 + |> member "app_display_name" Json.Codec.string 342 + |> member "device_display_name" Json.Codec.string 343 + |> opt_member "profile_tag" Json.Codec.string ~enc:(fun t -> t.profile_tag) 344 + |> member "lang" Json.Codec.string 345 + |> member "data" pusher_data_jsont 346 + |> opt_member "append" Json.Codec.bool ~enc:(fun t -> t.append) 347 + |> seal) 348 348 349 349 let set_pusher client ~pushkey ~kind ~app_id ~app_display_name 350 350 ~device_display_name ?profile_tag ~lang ~data ?append () =
+10 -10
lib/matrix_client/push.mli
··· 18 18 val rule_kind_of_string : string -> (rule_kind, string) result 19 19 (** Parse rule kind from string. *) 20 20 21 - val rule_kind_jsont : rule_kind Jsont.t 21 + val rule_kind_jsont : rule_kind Json.codec 22 22 (** JSON codec for rule kind. *) 23 23 24 24 (** {1 Push Rule Actions} *) ··· 28 28 | Notify 29 29 | Dont_notify 30 30 | Coalesce 31 - | Set_tweak of string * Jsont.json 31 + | Set_tweak of string * Json.t 32 32 33 - val action_jsont : action Jsont.t 33 + val action_jsont : action Json.codec 34 34 (** JSON codec for action. *) 35 35 36 36 (** {1 Push Rule Conditions} *) ··· 43 43 is_ : string option; 44 44 } 45 45 46 - val condition_jsont : condition Jsont.t 46 + val condition_jsont : condition Json.codec 47 47 (** JSON codec for condition. *) 48 48 49 49 (** {1 Push Rules} *) ··· 58 58 pattern : string option; 59 59 } 60 60 61 - val rule_jsont : rule Jsont.t 61 + val rule_jsont : rule Json.codec 62 62 (** JSON codec for rule. *) 63 63 64 64 (** {1 Push Ruleset} *) ··· 72 72 content : rule list; 73 73 } 74 74 75 - val ruleset_jsont : ruleset Jsont.t 75 + val ruleset_jsont : ruleset Json.codec 76 76 (** JSON codec for ruleset. *) 77 77 78 78 (** Push rules response. *) ··· 80 80 global : ruleset; 81 81 } 82 82 83 - val push_rules_response_jsont : push_rules_response Jsont.t 83 + val push_rules_response_jsont : push_rules_response Json.codec 84 84 (** JSON codec for push rules response. *) 85 85 86 86 (** {1 Push Rule Operations} *) ··· 149 149 val pusher_kind_of_string : string -> (pusher_kind, string) result 150 150 (** Parse pusher kind from string. *) 151 151 152 - val pusher_kind_jsont : pusher_kind Jsont.t 152 + val pusher_kind_jsont : pusher_kind Json.codec 153 153 (** JSON codec for pusher kind. *) 154 154 155 155 (** Pusher data. *) ··· 158 158 format : string option; 159 159 } 160 160 161 - val pusher_data_jsont : pusher_data Jsont.t 161 + val pusher_data_jsont : pusher_data Json.codec 162 162 (** JSON codec for pusher data. *) 163 163 164 164 (** Pusher. *) ··· 173 173 data : pusher_data; 174 174 } 175 175 176 - val pusher_jsont : pusher Jsont.t 176 + val pusher_jsont : pusher Json.codec 177 177 (** JSON codec for pusher. *) 178 178 179 179 (** {1 Pusher Operations} *)
+4 -4
lib/matrix_client/receipts.ml
··· 18 18 } [@@warning "-69"] 19 19 20 20 let read_marker_request_jsont = 21 - Jsont.Object.( 21 + Json.Codec.Object.( 22 22 map (fun fully_read read -> { fully_read; read }) 23 - |> mem "m.fully_read" Jsont.string 24 - |> opt_mem "m.read" Jsont.string ~enc:(fun t -> t.read) 25 - |> finish) 23 + |> member "m.fully_read" Json.Codec.string 24 + |> opt_member "m.read" Json.Codec.string ~enc:(fun t -> t.read) 25 + |> seal) 26 26 27 27 let set_read_marker client ~room_id ~fully_read ?read () = 28 28 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in
+55 -55
lib/matrix_client/relations.ml
··· 21 21 | s -> Error ("Unknown relation type: " ^ s) 22 22 23 23 let relation_type_jsont = 24 - Jsont.of_of_string ~kind:"relation_type" 24 + Json.Codec.of_of_string ~kind:"relation_type" 25 25 ~enc:relation_type_to_string 26 26 relation_type_of_string 27 27 [@@warning "-32"] ··· 44 44 } [@@warning "-69"] 45 45 46 46 let reaction_relates_to_jsont = 47 - Jsont.Object.( 47 + Json.Codec.Object.( 48 48 map (fun rel_type event_id key -> { rel_type; event_id; key }) 49 - |> mem "rel_type" Jsont.string 50 - |> mem "event_id" Jsont.string 51 - |> mem "key" Jsont.string 52 - |> finish) 49 + |> member "rel_type" Json.Codec.string 50 + |> member "event_id" Json.Codec.string 51 + |> member "key" Json.Codec.string 52 + |> seal) 53 53 54 54 let reaction_content_jsont = 55 - Jsont.Object.( 55 + Json.Codec.Object.( 56 56 map (fun relates_to -> { relates_to }) 57 - |> mem "m.relates_to" reaction_relates_to_jsont 58 - |> finish) 57 + |> member "m.relates_to" reaction_relates_to_jsont 58 + |> seal) 59 59 60 60 let send_reaction client ~room_id ~event_id ~key = 61 61 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 97 97 } [@@warning "-69"] 98 98 99 99 let edit_new_content_jsont = 100 - Jsont.Object.( 100 + Json.Codec.Object.( 101 101 map (fun msgtype body -> { msgtype; body }) 102 - |> mem "msgtype" Jsont.string 103 - |> mem "body" Jsont.string 104 - |> finish) 102 + |> member "msgtype" Json.Codec.string 103 + |> member "body" Json.Codec.string 104 + |> seal) 105 105 106 106 let edit_relates_to_jsont = 107 - Jsont.Object.( 107 + Json.Codec.Object.( 108 108 map (fun rel_type event_id -> { rel_type; event_id }) 109 - |> mem "rel_type" Jsont.string 110 - |> mem "event_id" Jsont.string 111 - |> finish) 109 + |> member "rel_type" Json.Codec.string 110 + |> member "event_id" Json.Codec.string 111 + |> seal) 112 112 113 113 let edit_content_jsont = 114 - Jsont.Object.( 114 + Json.Codec.Object.( 115 115 map (fun msgtype body new_content relates_to -> 116 116 { msgtype; body; new_content; relates_to }) 117 - |> mem "msgtype" Jsont.string 118 - |> mem "body" Jsont.string 119 - |> mem "m.new_content" edit_new_content_jsont 120 - |> mem "m.relates_to" edit_relates_to_jsont 121 - |> finish) 117 + |> member "msgtype" Json.Codec.string 118 + |> member "body" Json.Codec.string 119 + |> member "m.new_content" edit_new_content_jsont 120 + |> member "m.relates_to" edit_relates_to_jsont 121 + |> seal) 122 122 123 123 let edit_message client ~room_id ~event_id ~new_body = 124 124 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 162 162 } [@@warning "-69"] 163 163 164 164 let reply_in_reply_to_jsont = 165 - Jsont.Object.( 165 + Json.Codec.Object.( 166 166 map (fun event_id -> { event_id }) 167 - |> mem "event_id" Jsont.string 168 - |> finish) 167 + |> member "event_id" Json.Codec.string 168 + |> seal) 169 169 170 170 let reply_relates_to_jsont = 171 - Jsont.Object.( 171 + Json.Codec.Object.( 172 172 map (fun in_reply_to -> { in_reply_to }) 173 - |> mem "m.in_reply_to" reply_in_reply_to_jsont 174 - |> finish) 173 + |> member "m.in_reply_to" reply_in_reply_to_jsont 174 + |> seal) 175 175 176 176 let reply_content_jsont = 177 - Jsont.Object.( 177 + Json.Codec.Object.( 178 178 map (fun msgtype body relates_to -> { msgtype; body; relates_to }) 179 - |> mem "msgtype" Jsont.string 180 - |> mem "body" Jsont.string 181 - |> mem "m.relates_to" reply_relates_to_jsont 182 - |> finish) 179 + |> member "msgtype" Json.Codec.string 180 + |> member "body" Json.Codec.string 181 + |> member "m.relates_to" reply_relates_to_jsont 182 + |> seal) 183 183 184 184 let send_reply client ~room_id ~event_id ~body = 185 185 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 219 219 } [@@warning "-69"] 220 220 221 221 let thread_relates_to_jsont = 222 - Jsont.Object.( 222 + Json.Codec.Object.( 223 223 map (fun rel_type event_id is_falling_back in_reply_to -> 224 224 { rel_type; event_id; is_falling_back; in_reply_to }) 225 - |> mem "rel_type" Jsont.string 226 - |> mem "event_id" Jsont.string 227 - |> mem "is_falling_back" Jsont.bool ~dec_absent:true 228 - |> opt_mem "m.in_reply_to" reply_in_reply_to_jsont ~enc:(fun t -> t.in_reply_to) 229 - |> finish) 225 + |> member "rel_type" Json.Codec.string 226 + |> member "event_id" Json.Codec.string 227 + |> member "is_falling_back" Json.Codec.bool ~dec_absent:true 228 + |> opt_member "m.in_reply_to" reply_in_reply_to_jsont ~enc:(fun t -> t.in_reply_to) 229 + |> seal) 230 230 231 231 let thread_content_jsont = 232 - Jsont.Object.( 232 + Json.Codec.Object.( 233 233 map (fun msgtype body relates_to -> { msgtype; body; relates_to }) 234 - |> mem "msgtype" Jsont.string 235 - |> mem "body" Jsont.string 236 - |> mem "m.relates_to" thread_relates_to_jsont 237 - |> finish) 234 + |> member "msgtype" Json.Codec.string 235 + |> member "body" Json.Codec.string 236 + |> member "m.relates_to" thread_relates_to_jsont 237 + |> seal) 238 238 239 239 let send_in_thread client ~room_id ~thread_root_id ?reply_to_id ~body () = 240 240 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 272 272 } 273 273 274 274 let aggregation_jsont = 275 - Jsont.Object.( 275 + Json.Codec.Object.( 276 276 map (fun event_id origin_server_ts sender -> 277 277 { event_id; origin_server_ts; sender }) 278 - |> mem "event_id" Matrix_proto.Id.Event_id.jsont 279 - |> mem "origin_server_ts" Jsont.int64 280 - |> mem "sender" Matrix_proto.Id.User_id.jsont 281 - |> finish) 278 + |> member "event_id" Matrix_proto.Id.Event_id.jsont 279 + |> member "origin_server_ts" Json.Codec.int64 280 + |> member "sender" Matrix_proto.Id.User_id.jsont 281 + |> seal) 282 282 283 283 type relations_response = { 284 284 chunk : aggregation list; ··· 287 287 } 288 288 289 289 let relations_response_jsont = 290 - Jsont.Object.( 290 + Json.Codec.Object.( 291 291 map (fun chunk next_batch prev_batch -> 292 292 { chunk; next_batch; prev_batch }) 293 - |> mem "chunk" (Jsont.list aggregation_jsont) ~dec_absent:[] 294 - |> opt_mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 295 - |> opt_mem "prev_batch" Jsont.string ~enc:(fun t -> t.prev_batch) 296 - |> finish) 293 + |> member "chunk" (Json.Codec.list aggregation_jsont) ~dec_absent:[] 294 + |> opt_member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 295 + |> opt_member "prev_batch" Json.Codec.string ~enc:(fun t -> t.prev_batch) 296 + |> seal) 297 297 298 298 let get_relations client ~room_id ~event_id ?rel_type ?event_type ?limit ?from () = 299 299 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in
+55 -55
lib/matrix_client/room_preview.ml
··· 36 36 } 37 37 38 38 let room_summary_jsont = 39 - Jsont.Object.( 39 + Json.Codec.Object.( 40 40 map (fun room_id membership is_encrypted room_name topic avatar_url 41 41 canonical_alias joined_members_count invited_members_count 42 42 room_version room_type join_rule guest_can_join world_readable -> 43 43 { room_id; membership; is_encrypted; room_name; topic; avatar_url; 44 44 canonical_alias; joined_members_count; invited_members_count; 45 45 room_version; room_type; join_rule; guest_can_join; world_readable }) 46 - |> mem "room_id" Jsont.string ~enc:(fun t -> t.room_id) 47 - |> opt_mem "membership" Matrix_proto.Event.Membership.jsont ~enc:(fun t -> t.membership) 48 - |> opt_mem "is_encrypted" Jsont.bool ~enc:(fun t -> t.is_encrypted) 49 - |> opt_mem "room_name" Jsont.string ~enc:(fun t -> t.room_name) 50 - |> opt_mem "topic" Jsont.string ~enc:(fun t -> t.topic) 51 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 52 - |> opt_mem "canonical_alias" Jsont.string ~enc:(fun t -> t.canonical_alias) 53 - |> opt_mem "joined_members_count" Jsont.int ~enc:(fun t -> t.joined_members_count) 54 - |> opt_mem "invited_members_count" Jsont.int ~enc:(fun t -> t.invited_members_count) 55 - |> opt_mem "room_version" Jsont.string ~enc:(fun t -> t.room_version) 56 - |> opt_mem "room_type" Jsont.string ~enc:(fun t -> t.room_type) 57 - |> opt_mem "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule) 58 - |> opt_mem "guest_can_join" Jsont.bool ~enc:(fun t -> t.guest_can_join) 59 - |> opt_mem "world_readable" Jsont.bool ~enc:(fun t -> t.world_readable) 60 - |> finish) 46 + |> member "room_id" Json.Codec.string ~enc:(fun t -> t.room_id) 47 + |> opt_member "membership" Matrix_proto.Event.Membership.jsont ~enc:(fun t -> t.membership) 48 + |> opt_member "is_encrypted" Json.Codec.bool ~enc:(fun t -> t.is_encrypted) 49 + |> opt_member "room_name" Json.Codec.string ~enc:(fun t -> t.room_name) 50 + |> opt_member "topic" Json.Codec.string ~enc:(fun t -> t.topic) 51 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 52 + |> opt_member "canonical_alias" Json.Codec.string ~enc:(fun t -> t.canonical_alias) 53 + |> opt_member "joined_members_count" Json.Codec.int ~enc:(fun t -> t.joined_members_count) 54 + |> opt_member "invited_members_count" Json.Codec.int ~enc:(fun t -> t.invited_members_count) 55 + |> opt_member "room_version" Json.Codec.string ~enc:(fun t -> t.room_version) 56 + |> opt_member "room_type" Json.Codec.string ~enc:(fun t -> t.room_type) 57 + |> opt_member "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule) 58 + |> opt_member "guest_can_join" Json.Codec.bool ~enc:(fun t -> t.guest_can_join) 59 + |> opt_member "world_readable" Json.Codec.bool ~enc:(fun t -> t.world_readable) 60 + |> seal) 61 61 62 62 (** Get room summary (MSC3266). 63 63 ··· 91 91 } 92 92 93 93 let public_room_jsont = 94 - Jsont.Object.( 94 + Json.Codec.Object.( 95 95 map (fun room_id name topic avatar_url canonical_alias num_joined_members 96 96 world_readable guest_can_join join_rule room_type -> 97 97 { room_id; name; topic; avatar_url; canonical_alias; num_joined_members; 98 98 world_readable; guest_can_join; join_rule; room_type }) 99 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont ~enc:(fun t -> t.room_id) 100 - |> opt_mem "name" Jsont.string ~enc:(fun t -> t.name) 101 - |> opt_mem "topic" Jsont.string ~enc:(fun t -> t.topic) 102 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 103 - |> opt_mem "canonical_alias" Matrix_proto.Id.Room_alias.jsont ~enc:(fun t -> t.canonical_alias) 104 - |> mem "num_joined_members" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members) 105 - |> mem "world_readable" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.world_readable) 106 - |> mem "guest_can_join" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join) 107 - |> opt_mem "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule) 108 - |> opt_mem "room_type" Jsont.string ~enc:(fun t -> t.room_type) 109 - |> finish) 99 + |> member "room_id" Matrix_proto.Id.Room_id.jsont ~enc:(fun t -> t.room_id) 100 + |> opt_member "name" Json.Codec.string ~enc:(fun t -> t.name) 101 + |> opt_member "topic" Json.Codec.string ~enc:(fun t -> t.topic) 102 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 103 + |> opt_member "canonical_alias" Matrix_proto.Id.Room_alias.jsont ~enc:(fun t -> t.canonical_alias) 104 + |> member "num_joined_members" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members) 105 + |> member "world_readable" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.world_readable) 106 + |> member "guest_can_join" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join) 107 + |> opt_member "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule) 108 + |> opt_member "room_type" Json.Codec.string ~enc:(fun t -> t.room_type) 109 + |> seal) 110 110 111 111 type public_rooms_response = { 112 112 chunk : public_room list; ··· 116 116 } 117 117 118 118 let public_rooms_response_jsont = 119 - Jsont.Object.( 119 + Json.Codec.Object.( 120 120 map (fun chunk next_batch prev_batch total_room_count_estimate -> 121 121 { chunk; next_batch; prev_batch; total_room_count_estimate }) 122 - |> mem "chunk" (Jsont.list public_room_jsont) ~dec_absent:[] 122 + |> member "chunk" (Json.Codec.list public_room_jsont) ~dec_absent:[] 123 123 ~enc:(fun t -> t.chunk) 124 - |> opt_mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 125 - |> opt_mem "prev_batch" Jsont.string ~enc:(fun t -> t.prev_batch) 126 - |> opt_mem "total_room_count_estimate" Jsont.int 124 + |> opt_member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 125 + |> opt_member "prev_batch" Json.Codec.string ~enc:(fun t -> t.prev_batch) 126 + |> opt_member "total_room_count_estimate" Json.Codec.int 127 127 ~enc:(fun t -> t.total_room_count_estimate) 128 - |> finish) 128 + |> seal) 129 129 130 130 (** Get list of public rooms. 131 131 ··· 152 152 } 153 153 154 154 let public_rooms_filter_jsont = 155 - Jsont.Object.( 155 + Json.Codec.Object.( 156 156 map (fun generic_search_term room_types -> 157 157 { generic_search_term; room_types }) 158 - |> opt_mem "generic_search_term" Jsont.string ~enc:(fun t -> t.generic_search_term) 159 - |> opt_mem "room_types" (Jsont.list Jsont.string) ~enc:(fun t -> t.room_types) 160 - |> finish) 158 + |> opt_member "generic_search_term" Json.Codec.string ~enc:(fun t -> t.generic_search_term) 159 + |> opt_member "room_types" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.room_types) 160 + |> seal) 161 161 162 162 type search_public_rooms_request = { 163 163 limit : int option; ··· 168 168 } [@@warning "-69"] 169 169 170 170 let search_public_rooms_request_jsont = 171 - Jsont.Object.( 171 + Json.Codec.Object.( 172 172 map (fun limit since filter include_all_networks third_party_instance_id -> 173 173 { limit; since; filter; include_all_networks; third_party_instance_id }) 174 - |> opt_mem "limit" Jsont.int ~enc:(fun t -> t.limit) 175 - |> opt_mem "since" Jsont.string ~enc:(fun t -> t.since) 176 - |> opt_mem "filter" public_rooms_filter_jsont ~enc:(fun t -> t.filter) 177 - |> opt_mem "include_all_networks" Jsont.bool ~enc:(fun t -> t.include_all_networks) 178 - |> opt_mem "third_party_instance_id" Jsont.string ~enc:(fun t -> t.third_party_instance_id) 179 - |> finish) 174 + |> opt_member "limit" Json.Codec.int ~enc:(fun t -> t.limit) 175 + |> opt_member "since" Json.Codec.string ~enc:(fun t -> t.since) 176 + |> opt_member "filter" public_rooms_filter_jsont ~enc:(fun t -> t.filter) 177 + |> opt_member "include_all_networks" Json.Codec.bool ~enc:(fun t -> t.include_all_networks) 178 + |> opt_member "third_party_instance_id" Json.Codec.string ~enc:(fun t -> t.third_party_instance_id) 179 + |> seal) 180 180 181 181 (** Search public rooms with filters. 182 182 ··· 215 215 let resolve_alias client ~room_alias = 216 216 let alias_str = Matrix_proto.Id.Room_alias.to_string room_alias in 217 217 let path = Printf.sprintf "/directory/room/%s" (Uri.pct_encode alias_str) in 218 - let response_jsont = Jsont.Object.( 218 + let response_jsont = Json.Codec.Object.( 219 219 map (fun room_id servers -> (room_id, servers)) 220 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 221 - |> mem "servers" (Jsont.list Jsont.string) ~dec_absent:[] 222 - |> finish) 220 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 221 + |> member "servers" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 222 + |> seal) 223 223 in 224 224 match Client.get client ~path () with 225 225 | Error e -> Error e ··· 239 239 in 240 240 let path = Printf.sprintf "/knock/%s" (Uri.pct_encode id_str) in 241 241 let query = if via = [] then None else Some (List.map (fun s -> ("server_name", s)) via) in 242 - let request_jsont = Jsont.Object.( 242 + let request_jsont = Json.Codec.Object.( 243 243 map (fun reason -> reason) 244 - |> opt_mem "reason" Jsont.string ~enc:Fun.id 245 - |> finish) 244 + |> opt_member "reason" Json.Codec.string ~enc:Fun.id 245 + |> seal) 246 246 in 247 - let response_jsont = Jsont.Object.( 247 + let response_jsont = Json.Codec.Object.( 248 248 map (fun room_id -> room_id) 249 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 250 - |> finish) 249 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 250 + |> seal) 251 251 in 252 252 match Client.encode_body request_jsont reason with 253 253 | Error e -> Error e
+4 -4
lib/matrix_client/room_preview.mli
··· 41 41 world_readable : bool option; 42 42 } 43 43 44 - val room_summary_jsont : room_summary Jsont.t 44 + val room_summary_jsont : room_summary Json.codec 45 45 (** JSON codec for room summary. *) 46 46 47 47 val get_summary : ··· 70 70 room_type : string option; 71 71 } 72 72 73 - val public_room_jsont : public_room Jsont.t 73 + val public_room_jsont : public_room Json.codec 74 74 (** JSON codec for public room. *) 75 75 76 76 (** Public rooms response. *) ··· 81 81 total_room_count_estimate : int option; 82 82 } 83 83 84 - val public_rooms_response_jsont : public_rooms_response Jsont.t 84 + val public_rooms_response_jsont : public_rooms_response Json.codec 85 85 (** JSON codec for public rooms response. *) 86 86 87 87 val get_public_rooms : ··· 105 105 room_types : string list option; 106 106 } 107 107 108 - val public_rooms_filter_jsont : public_rooms_filter Jsont.t 108 + val public_rooms_filter_jsont : public_rooms_filter Json.codec 109 109 (** JSON codec for public rooms filter. *) 110 110 111 111 val search_public_rooms :
+100 -100
lib/matrix_client/rooms.ml
··· 19 19 type state_event = { 20 20 ev_type : string; 21 21 state_key : string; 22 - content : Jsont.json; 22 + content : Json.t; 23 23 } [@@warning "-69"] 24 24 25 25 let state_event_jsont = 26 - Jsont.Object.( 26 + Json.Codec.Object.( 27 27 map (fun ev_type state_key content -> { ev_type; state_key; content }) 28 - |> mem "type" Jsont.string ~enc:(fun t -> t.ev_type) 29 - |> mem "state_key" Jsont.string ~enc:(fun t -> t.state_key) 30 - |> mem "content" Jsont.json ~enc:(fun t -> t.content) 31 - |> finish) 28 + |> member "type" Json.Codec.string ~enc:(fun t -> t.ev_type) 29 + |> member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key) 30 + |> member "content" Json.Codec.Value.t ~enc:(fun t -> t.content) 31 + |> seal) 32 32 33 33 (* Create room *) 34 34 type create_request = { ··· 40 40 invite : string list; 41 41 is_direct : bool option; 42 42 room_type : string option; 43 - creation_content : Jsont.json option; 43 + creation_content : Json.t option; 44 44 initial_state : state_event list; 45 45 } [@@warning "-69"] 46 46 47 - let create_request_jsont : create_request Jsont.t = 48 - let open Jsont.Object in 47 + let create_request_jsont : create_request Json.codec = 48 + let open Json.Codec.Object in 49 49 map (fun name topic visibility preset room_alias_local_part invite is_direct room_type creation_content initial_state -> 50 50 ({ name; topic; visibility; preset; room_alias_local_part; invite; is_direct; room_type; creation_content; initial_state } : create_request)) 51 - |> opt_mem "name" Jsont.string ~enc:(fun (t : create_request) -> t.name) 52 - |> opt_mem "topic" Jsont.string ~enc:(fun (t : create_request) -> t.topic) 53 - |> opt_mem "visibility" Jsont.string ~enc:(fun (t : create_request) -> t.visibility) 54 - |> opt_mem "preset" Jsont.string ~enc:(fun (t : create_request) -> t.preset) 55 - |> opt_mem "room_alias_local_part" Jsont.string ~enc:(fun (t : create_request) -> t.room_alias_local_part) 56 - |> mem "invite" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : create_request) -> t.invite) 57 - |> opt_mem "is_direct" Jsont.bool ~enc:(fun (t : create_request) -> t.is_direct) 58 - |> opt_mem "room_type" Jsont.string ~enc:(fun (t : create_request) -> t.room_type) 59 - |> opt_mem "creation_content" Jsont.json ~enc:(fun (t : create_request) -> t.creation_content) 60 - |> mem "initial_state" (Jsont.list state_event_jsont) ~dec_absent:[] ~enc:(fun (t : create_request) -> t.initial_state) 61 - |> finish 51 + |> opt_member "name" Json.Codec.string ~enc:(fun (t : create_request) -> t.name) 52 + |> opt_member "topic" Json.Codec.string ~enc:(fun (t : create_request) -> t.topic) 53 + |> opt_member "visibility" Json.Codec.string ~enc:(fun (t : create_request) -> t.visibility) 54 + |> opt_member "preset" Json.Codec.string ~enc:(fun (t : create_request) -> t.preset) 55 + |> opt_member "room_alias_local_part" Json.Codec.string ~enc:(fun (t : create_request) -> t.room_alias_local_part) 56 + |> member "invite" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : create_request) -> t.invite) 57 + |> opt_member "is_direct" Json.Codec.bool ~enc:(fun (t : create_request) -> t.is_direct) 58 + |> opt_member "room_type" Json.Codec.string ~enc:(fun (t : create_request) -> t.room_type) 59 + |> opt_member "creation_content" Json.Codec.Value.t ~enc:(fun (t : create_request) -> t.creation_content) 60 + |> member "initial_state" (Json.Codec.list state_event_jsont) ~dec_absent:[] ~enc:(fun (t : create_request) -> t.initial_state) 61 + |> seal 62 62 63 63 type create_response = { 64 64 room_id : Matrix_proto.Id.Room_id.t; 65 65 } 66 66 67 67 let create_response_jsont = 68 - Jsont.Object.( 68 + Json.Codec.Object.( 69 69 map (fun room_id -> { room_id }) 70 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 71 - |> finish) 70 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 71 + |> seal) 72 72 73 73 (** Default encryption algorithm for E2EE rooms. *) 74 74 let default_encryption_algorithm = "m.megolm.v1.aes-sha2" 75 75 76 76 (** Build encryption state event for initial_state. *) 77 77 let encryption_state_event algorithm = 78 - let content = Jsont.Object ( 79 - [(("algorithm", Jsont.Meta.none), Jsont.String (algorithm, Jsont.Meta.none))], 80 - Jsont.Meta.none 78 + let content = Json.Object ( 79 + [(("algorithm", Json.Meta.none), Json.String (algorithm, Json.Meta.none))], 80 + Json.Meta.none 81 81 ) in 82 82 { ev_type = "m.room.encryption"; state_key = ""; content } 83 83 ··· 132 132 } [@@warning "-69"] 133 133 134 134 let join_request_jsont = 135 - Jsont.Object.( 135 + Json.Codec.Object.( 136 136 map (fun reason -> { reason }) 137 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 138 - |> finish) 137 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 138 + |> seal) 139 139 140 140 type join_response = { 141 141 room_id : Matrix_proto.Id.Room_id.t; 142 142 } 143 143 144 144 let join_response_jsont = 145 - Jsont.Object.( 145 + Json.Codec.Object.( 146 146 map (fun room_id -> { room_id }) 147 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 148 - |> finish) 147 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 148 + |> seal) 149 149 150 150 let join client ~room_id_or_alias ?via ?reason () = 151 151 let path = Printf.sprintf "/join/%s" (Uri.pct_encode room_id_or_alias) in ··· 170 170 } [@@warning "-69"] 171 171 172 172 let leave_request_jsont = 173 - Jsont.Object.( 173 + Json.Codec.Object.( 174 174 map (fun reason -> { reason }) 175 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 176 - |> finish) 175 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 176 + |> seal) 177 177 178 178 let leave client ~room_id ?reason () = 179 179 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 201 201 } [@@warning "-69"] 202 202 203 203 let invite_request_jsont = 204 - Jsont.Object.( 204 + Json.Codec.Object.( 205 205 map (fun user_id reason -> { user_id; reason }) 206 - |> mem "user_id" Jsont.string 207 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 208 - |> finish) 206 + |> member "user_id" Json.Codec.string 207 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 208 + |> seal) 209 209 210 210 let invite client ~room_id ~user_id ?reason () = 211 211 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 225 225 } [@@warning "-69"] 226 226 227 227 let kick_request_jsont = 228 - Jsont.Object.( 228 + Json.Codec.Object.( 229 229 map (fun user_id reason -> { user_id; reason }) 230 - |> mem "user_id" Jsont.string 231 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 232 - |> finish) 230 + |> member "user_id" Json.Codec.string 231 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 232 + |> seal) 233 233 234 234 let kick client ~room_id ~user_id ?reason () = 235 235 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 249 249 } [@@warning "-69"] 250 250 251 251 let ban_request_jsont = 252 - Jsont.Object.( 252 + Json.Codec.Object.( 253 253 map (fun user_id reason -> { user_id; reason }) 254 - |> mem "user_id" Jsont.string 255 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 256 - |> finish) 254 + |> member "user_id" Json.Codec.string 255 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 256 + |> seal) 257 257 258 258 let ban client ~room_id ~user_id ?reason () = 259 259 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 284 284 } 285 285 286 286 let joined_rooms_response_jsont = 287 - Jsont.Object.( 287 + Json.Codec.Object.( 288 288 map (fun joined_rooms -> { joined_rooms }) 289 - |> mem "joined_rooms" (Jsont.list Jsont.string) ~dec_absent:[] 290 - |> finish) 289 + |> member "joined_rooms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 290 + |> seal) 291 291 292 292 let get_joined_rooms client = 293 293 match Client.get client ~path:"/joined_rooms" () with ··· 322 322 } 323 323 324 324 let member_content_jsont = 325 - Jsont.Object.( 325 + Json.Codec.Object.( 326 326 map (fun membership displayname avatar_url -> 327 327 { membership; displayname; avatar_url }) 328 - |> mem "membership" Jsont.string 329 - |> opt_mem "displayname" Jsont.string ~enc:(fun t -> t.displayname) 330 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 331 - |> finish) 328 + |> member "membership" Json.Codec.string 329 + |> opt_member "displayname" Json.Codec.string ~enc:(fun t -> t.displayname) 330 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 331 + |> seal) 332 332 333 333 let member_event_jsont = 334 - Jsont.Object.( 334 + Json.Codec.Object.( 335 335 map (fun state_key content -> { state_key; content }) 336 - |> mem "state_key" Jsont.string 337 - |> mem "content" member_content_jsont 338 - |> finish) 336 + |> member "state_key" Json.Codec.string 337 + |> member "content" member_content_jsont 338 + |> seal) 339 339 340 340 type members_response = { 341 341 chunk : member_event list; 342 342 } 343 343 344 344 let members_response_jsont = 345 - Jsont.Object.( 345 + Json.Codec.Object.( 346 346 map (fun chunk -> { chunk }) 347 - |> mem "chunk" (Jsont.list member_event_jsont) ~dec_absent:[] 348 - |> finish) 347 + |> member "chunk" (Json.Codec.list member_event_jsont) ~dec_absent:[] 348 + |> seal) 349 349 350 350 let get_members client ~room_id ?membership ?not_membership () = 351 351 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 388 388 } 389 389 390 390 let public_room_jsont = 391 - Jsont.Object.( 391 + Json.Codec.Object.( 392 392 map (fun room_id name topic num_joined_members world_readable guest_can_join avatar_url canonical_alias -> 393 393 { room_id; name; topic; num_joined_members; world_readable; guest_can_join; avatar_url; canonical_alias }) 394 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont 395 - |> opt_mem "name" Jsont.string ~enc:(fun t -> t.name) 396 - |> opt_mem "topic" Jsont.string ~enc:(fun t -> t.topic) 397 - |> mem "num_joined_members" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members) 398 - |> mem "world_readable" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.world_readable) 399 - |> mem "guest_can_join" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join) 400 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 401 - |> opt_mem "canonical_alias" Jsont.string ~enc:(fun t -> t.canonical_alias) 402 - |> finish) 394 + |> member "room_id" Matrix_proto.Id.Room_id.jsont 395 + |> opt_member "name" Json.Codec.string ~enc:(fun t -> t.name) 396 + |> opt_member "topic" Json.Codec.string ~enc:(fun t -> t.topic) 397 + |> member "num_joined_members" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members) 398 + |> member "world_readable" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.world_readable) 399 + |> member "guest_can_join" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join) 400 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 401 + |> opt_member "canonical_alias" Json.Codec.string ~enc:(fun t -> t.canonical_alias) 402 + |> seal) 403 403 404 404 type public_rooms_response = { 405 405 chunk : public_room list; ··· 409 409 } 410 410 411 411 let public_rooms_response_jsont = 412 - Jsont.Object.( 412 + Json.Codec.Object.( 413 413 map (fun chunk next_batch prev_batch total_room_count_estimate -> 414 414 { chunk; next_batch; prev_batch; total_room_count_estimate }) 415 - |> mem "chunk" (Jsont.list public_room_jsont) ~dec_absent:[] 416 - |> opt_mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 417 - |> opt_mem "prev_batch" Jsont.string ~enc:(fun t -> t.prev_batch) 418 - |> opt_mem "total_room_count_estimate" Jsont.int ~enc:(fun t -> t.total_room_count_estimate) 419 - |> finish) 415 + |> member "chunk" (Json.Codec.list public_room_jsont) ~dec_absent:[] 416 + |> opt_member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 417 + |> opt_member "prev_batch" Json.Codec.string ~enc:(fun t -> t.prev_batch) 418 + |> opt_member "total_room_count_estimate" Json.Codec.int ~enc:(fun t -> t.total_room_count_estimate) 419 + |> seal) 420 420 421 421 let get_public_rooms client ?limit ?since ?server () = 422 422 let query = ··· 446 446 447 447 module StringMap = Map.Make(String) 448 448 449 - let string_int_map_jsont : (string * int) list Jsont.t = 450 - let map_jsont = Jsont.Object.as_string_map Jsont.int in 451 - Jsont.map 449 + let string_int_map_jsont : (string * int) list Json.codec = 450 + let map_jsont = Json.Codec.Object.as_string_map Json.Codec.int in 451 + Json.Codec.map 452 452 ~dec:(fun m -> StringMap.bindings m) 453 453 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 454 454 map_jsont 455 455 456 - let power_levels_jsont : power_levels Jsont.t = 457 - Jsont.Object.( 456 + let power_levels_jsont : power_levels Json.codec = 457 + Json.Codec.Object.( 458 458 map (fun ban events events_default invite kick redact state_default users users_default notifications -> 459 459 ({ ban; events; events_default; invite; kick; redact; state_default; users; users_default; notifications } : power_levels)) 460 - |> mem "ban" Jsont.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.ban) 461 - |> mem "events" string_int_map_jsont ~dec_absent:[] ~enc:(fun (t : power_levels) -> t.events) 462 - |> mem "events_default" Jsont.int ~dec_absent:0 ~enc:(fun (t : power_levels) -> t.events_default) 463 - |> mem "invite" Jsont.int ~dec_absent:0 ~enc:(fun (t : power_levels) -> t.invite) 464 - |> mem "kick" Jsont.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.kick) 465 - |> mem "redact" Jsont.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.redact) 466 - |> mem "state_default" Jsont.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.state_default) 467 - |> mem "users" string_int_map_jsont ~dec_absent:[] ~enc:(fun (t : power_levels) -> t.users) 468 - |> mem "users_default" Jsont.int ~dec_absent:0 ~enc:(fun (t : power_levels) -> t.users_default) 469 - |> mem "notifications" string_int_map_jsont ~dec_absent:[] ~enc:(fun (t : power_levels) -> t.notifications) 470 - |> finish) 460 + |> member "ban" Json.Codec.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.ban) 461 + |> member "events" string_int_map_jsont ~dec_absent:[] ~enc:(fun (t : power_levels) -> t.events) 462 + |> member "events_default" Json.Codec.int ~dec_absent:0 ~enc:(fun (t : power_levels) -> t.events_default) 463 + |> member "invite" Json.Codec.int ~dec_absent:0 ~enc:(fun (t : power_levels) -> t.invite) 464 + |> member "kick" Json.Codec.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.kick) 465 + |> member "redact" Json.Codec.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.redact) 466 + |> member "state_default" Json.Codec.int ~dec_absent:50 ~enc:(fun (t : power_levels) -> t.state_default) 467 + |> member "users" string_int_map_jsont ~dec_absent:[] ~enc:(fun (t : power_levels) -> t.users) 468 + |> member "users_default" Json.Codec.int ~dec_absent:0 ~enc:(fun (t : power_levels) -> t.users_default) 469 + |> member "notifications" string_int_map_jsont ~dec_absent:[] ~enc:(fun (t : power_levels) -> t.notifications) 470 + |> seal) 471 471 472 472 let get_power_levels client ~room_id = 473 473 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 507 507 (** m.direct account data is a map from user_id to list of room_ids *) 508 508 let m_direct_jsont = 509 509 let module StringMap = Map.Make(String) in 510 - Jsont.Object.as_string_map (Jsont.list Jsont.string) 511 - |> Jsont.map 510 + Json.Codec.Object.as_string_map (Json.Codec.list Json.Codec.string) 511 + |> Json.Codec.map 512 512 ~dec:(fun m -> StringMap.bindings m) 513 513 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 514 514 ··· 521 521 | Error e -> Error e 522 522 | Ok json -> 523 523 (* Re-encode and decode with our typed codec *) 524 - match Jsont_bytesrw.encode_string Jsont.json json with 524 + match (try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)) with 525 525 | Error e -> Error (Error.Json_error e) 526 526 | Ok json_str -> 527 - match Jsont_bytesrw.decode_string m_direct_jsont json_str with 527 + match (Json.of_string m_direct_jsont json_str |> Result.map_error Json.Error.to_string) with 528 528 | Error e -> 529 529 Log.warn (fun m -> m "Failed to parse m.direct: %s" e); 530 530 Ok [] ··· 574 574 List.filter (fun (k, _) -> k <> user_id_str) bindings 575 575 in 576 576 (* Encode and save *) 577 - match Jsont_bytesrw.encode_string m_direct_jsont new_bindings with 577 + match (try Ok (Json.to_string m_direct_jsont new_bindings) with Json.Error e -> Error (Json.Error.to_string e)) with 578 578 | Error e -> Error (Error.Json_error e) 579 579 | Ok json_str -> 580 - match Jsont_bytesrw.decode_string Jsont.json json_str with 580 + match (Json.of_string Json.Codec.Value.t json_str |> Result.map_error Json.Error.to_string) with 581 581 | Error e -> Error (Error.Json_error e) 582 582 | Ok json -> 583 583 Log.debug (fun m -> m "Updating m.direct for %s" user_id_str);
+14 -14
lib/matrix_client/send_queue.ml
··· 16 16 type request_kind = 17 17 | Event of { 18 18 event_type : string; 19 - content : Jsont.json; 19 + content : Json.t; 20 20 txn_id : string; 21 21 } 22 22 | MediaUpload of { ··· 139 139 140 140 (** Generate a new transaction ID *) 141 141 let generate_txn_id () = 142 - let random_bytes = Mirage_crypto_rng.generate 16 in 142 + let random_bytes = Crypto_rng.generate 16 in 143 143 "m" ^ (Base64.encode_string ~pad:false random_bytes) 144 144 145 145 (** Enqueue a request *) ··· 175 175 176 176 (** Enqueue a text message *) 177 177 let send_text t ~room_id ~body = 178 - let content = Jsont.Object ( 179 - [(("msgtype", Jsont.Meta.none), Jsont.String ("m.text", Jsont.Meta.none)); 180 - (("body", Jsont.Meta.none), Jsont.String (body, Jsont.Meta.none))], 181 - Jsont.Meta.none 178 + let content = Json.Object ( 179 + [(("msgtype", Json.Meta.none), Json.String ("m.text", Json.Meta.none)); 180 + (("body", Json.Meta.none), Json.String (body, Json.Meta.none))], 181 + Json.Meta.none 182 182 ) in 183 183 send_message t ~room_id ~event_type:"m.room.message" ~content 184 184 ··· 402 402 Some (event_type, content, txn_id) 403 403 | Reaction { relates_to; key; txn_id } -> 404 404 let event_id = Matrix_proto.Id.Event_id.to_string relates_to in 405 - let content = Jsont.Object ( 406 - [(("m.relates_to", Jsont.Meta.none), 407 - Jsont.Object ( 408 - [(("rel_type", Jsont.Meta.none), Jsont.String ("m.annotation", Jsont.Meta.none)); 409 - (("event_id", Jsont.Meta.none), Jsont.String (event_id, Jsont.Meta.none)); 410 - (("key", Jsont.Meta.none), Jsont.String (key, Jsont.Meta.none))], 411 - Jsont.Meta.none))], 412 - Jsont.Meta.none 405 + let content = Json.Object ( 406 + [(("m.relates_to", Json.Meta.none), 407 + Json.Object ( 408 + [(("rel_type", Json.Meta.none), Json.String ("m.annotation", Json.Meta.none)); 409 + (("event_id", Json.Meta.none), Json.String (event_id, Json.Meta.none)); 410 + (("key", Json.Meta.none), Json.String (key, Json.Meta.none))], 411 + Json.Meta.none))], 412 + Json.Meta.none 413 413 ) in 414 414 Some ("m.reaction", content, txn_id) 415 415 | MediaUpload _ -> None
+4 -4
lib/matrix_client/send_queue.mli
··· 16 16 type request_kind = 17 17 | Event of { 18 18 event_type : string; 19 - content : Jsont.json; 19 + content : Json.t; 20 20 txn_id : string; 21 21 } 22 22 | MediaUpload of { ··· 125 125 t -> 126 126 room_id:Matrix_proto.Id.Room_id.t -> 127 127 event_type:string -> 128 - content:Jsont.json -> 128 + content:Json.t -> 129 129 send_handle 130 130 (** Enqueue a message event. *) 131 131 ··· 246 246 247 247 (** {1 Local Echo} *) 248 248 249 - val local_echo_event : queued_request -> (string * Jsont.json * string) option 249 + val local_echo_event : queued_request -> (string * Json.t * string) option 250 250 (** Create a local echo event from a queued request. 251 251 Returns [(event_type, content, txn_id)] or [None]. *) 252 252 ··· 269 269 content_type:string -> 270 270 data_size:int -> 271 271 ?local_path:string -> 272 - event_content:Jsont.json -> 272 + event_content:Json.t -> 273 273 unit -> 274 274 send_handle * send_handle 275 275 (** Create a media upload request with dependent event send.
+96 -96
lib/matrix_client/session.ml
··· 3 3 Implementation using tomlt for TOML serialization and 4 4 xdge for XDG directory management. *) 5 5 6 - module Ed25519 = Mirage_crypto_ec.Ed25519 7 - module X25519 = Mirage_crypto_ec.X25519 6 + module Ed25519 = Crypto_ec.Ed25519 7 + module X25519 = Crypto_ec.X25519 8 8 9 9 (* Helper for URI TOML codec *) 10 10 let uri_tomlt : Uri.t Tomlt.t = ··· 351 351 | Ok s -> s 352 352 | Error _ -> failwith "Invalid base64" 353 353 354 - (* Jsont codec for Ed25519 private key *) 355 - let ed25519_priv_jsont : Ed25519.priv Jsont.t = 356 - Jsont.map 354 + (* Json codec for Ed25519 private key *) 355 + let ed25519_priv_jsont : Ed25519.priv Json.codec = 356 + Json.Codec.map 357 357 ~dec:(fun s -> 358 358 let octets = base64_decode s in 359 359 match Ed25519.priv_of_octets octets with 360 360 | Ok priv -> priv 361 361 | Error _ -> failwith "Invalid Ed25519 private key") 362 362 ~enc:(fun priv -> Ed25519.priv_to_octets priv |> base64_encode) 363 - Jsont.string 363 + Json.Codec.string 364 364 365 - (* Jsont codec for Ed25519 public key *) 366 - let ed25519_pub_jsont : Ed25519.pub Jsont.t = 367 - Jsont.map 365 + (* Json codec for Ed25519 public key *) 366 + let ed25519_pub_jsont : Ed25519.pub Json.codec = 367 + Json.Codec.map 368 368 ~dec:(fun s -> 369 369 let octets = base64_decode s in 370 370 match Ed25519.pub_of_octets octets with 371 371 | Ok pub -> pub 372 372 | Error _ -> failwith "Invalid Ed25519 public key") 373 373 ~enc:(fun pub -> Ed25519.pub_to_octets pub |> base64_encode) 374 - Jsont.string 374 + Json.Codec.string 375 375 376 - (* Jsont codec for X25519 secret *) 377 - let x25519_secret_jsont : X25519.secret Jsont.t = 378 - Jsont.map 376 + (* Json codec for X25519 secret *) 377 + let x25519_secret_jsont : X25519.secret Json.codec = 378 + Json.Codec.map 379 379 ~dec:(fun s -> 380 380 let octets = base64_decode s in 381 381 match X25519.secret_of_octets octets with 382 382 | Ok (secret, _) -> secret 383 383 | Error _ -> failwith "Invalid X25519 secret key") 384 384 ~enc:(fun secret -> X25519.secret_to_octets secret |> base64_encode) 385 - Jsont.string 385 + Json.Codec.string 386 386 387 - (* Jsont codec for Ptime.t as ISO 8601 string *) 388 - let ptime_jsont : Ptime.t Jsont.t = 389 - Jsont.map 387 + (* Json codec for Ptime.t as ISO 8601 string *) 388 + let ptime_jsont : Ptime.t Json.codec = 389 + Json.Codec.map 390 390 ~dec:(fun s -> 391 391 match Ptime.of_rfc3339 s with 392 392 | Ok (t, _, _) -> t 393 393 | Error _ -> failwith "Invalid RFC3339 timestamp") 394 394 ~enc:(fun t -> Ptime.to_rfc3339 ~tz_offset_s:0 t) 395 - Jsont.string 395 + Json.Codec.string 396 396 397 397 (* ------------------------------------------------------------ *) 398 398 (* Olm.Account pickle *) ··· 410 410 max_one_time_keys : int; 411 411 } 412 412 413 - let account_pickle_jsont : account_pickle Jsont.t = 414 - Jsont.Object.( 413 + let account_pickle_jsont : account_pickle Json.codec = 414 + Json.Codec.Object.( 415 415 map (fun ed25519_priv ed25519_pub curve25519_secret curve25519_public 416 416 one_time_keys fallback_key next_key_id max_one_time_keys -> 417 417 { ed25519_priv; ed25519_pub; curve25519_secret; curve25519_public; 418 418 one_time_keys; fallback_key; next_key_id; max_one_time_keys }) 419 - |> mem "ed25519_priv" ed25519_priv_jsont 420 - |> mem "ed25519_pub" ed25519_pub_jsont 421 - |> mem "curve25519_secret" x25519_secret_jsont 422 - |> mem "curve25519_public" Jsont.string 423 - |> mem "one_time_keys" 424 - (Jsont.list (Jsont.list Jsont.string |> Jsont.map 419 + |> member "ed25519_priv" ed25519_priv_jsont 420 + |> member "ed25519_pub" ed25519_pub_jsont 421 + |> member "curve25519_secret" x25519_secret_jsont 422 + |> member "curve25519_public" Json.Codec.string 423 + |> member "one_time_keys" 424 + (Json.Codec.list (Json.Codec.list Json.Codec.string |> Json.Codec.map 425 425 ~dec:(function 426 426 | [a; b; c] -> (a, b, c) 427 427 | _ -> failwith "Expected 3 elements") 428 428 ~enc:(fun (a, b, c) -> [a; b; c]))) 429 - |> opt_mem "fallback_key" 430 - (Jsont.list Jsont.string |> Jsont.map 429 + |> opt_member "fallback_key" 430 + (Json.Codec.list Json.Codec.string |> Json.Codec.map 431 431 ~dec:(function 432 432 | [a; b; c] -> (a, b, c) 433 433 | _ -> failwith "Expected 3 elements") 434 434 ~enc:(fun (a, b, c) -> [a; b; c])) 435 - |> mem "next_key_id" Jsont.int 436 - |> mem "max_one_time_keys" Jsont.int 437 - |> finish) 435 + |> member "next_key_id" Json.Codec.int 436 + |> member "max_one_time_keys" Json.Codec.int 437 + |> seal) 438 438 439 439 let pickle_account (account : Olm.Account.t) : string = 440 440 let one_time_keys = ··· 459 459 next_key_id = account.next_key_id; 460 460 max_one_time_keys = account.max_one_time_keys; 461 461 } in 462 - match Jsont_bytesrw.encode_string account_pickle_jsont pickle with 462 + match (try Ok (Json.to_string account_pickle_jsont pickle) with Json.Error e -> Error (Json.Error.to_string e)) with 463 463 | Ok s -> s 464 464 | Error e -> failwith ("Failed to pickle account: " ^ e) 465 465 466 466 let unpickle_account (s : string) : (Olm.Account.t, string) result = 467 - match Jsont_bytesrw.decode_string account_pickle_jsont s with 467 + match (Json.of_string account_pickle_jsont s |> Result.map_error Json.Error.to_string) with 468 468 | Error e -> Error ("Failed to unpickle account: " ^ e) 469 469 | Ok pickle -> 470 470 let one_time_keys = ··· 509 509 index : int; 510 510 } 511 511 512 - let chain_key_pickle_jsont : chain_key_pickle Jsont.t = 513 - Jsont.Object.( 512 + let chain_key_pickle_jsont : chain_key_pickle Json.codec = 513 + Json.Codec.Object.( 514 514 map (fun key index -> { key; index }) 515 - |> mem "key" Jsont.string 516 - |> mem "index" Jsont.int 517 - |> finish) 515 + |> member "key" Json.Codec.string 516 + |> member "index" Json.Codec.int 517 + |> seal) 518 518 519 519 type session_pickle = { 520 520 session_id : string; ··· 530 530 } 531 531 532 532 (* Encode (string, int) pair as a JSON object with "key" and "index" *) 533 - let string_int_pair_jsont : (string * int) Jsont.t = 534 - Jsont.Object.( 533 + let string_int_pair_jsont : (string * int) Json.codec = 534 + Json.Codec.Object.( 535 535 map (fun k i -> (k, i)) 536 - |> mem "key" Jsont.string 537 - |> mem "index" Jsont.int 538 - |> finish) 536 + |> member "key" Json.Codec.string 537 + |> member "index" Json.Codec.int 538 + |> seal) 539 539 540 - let session_pickle_jsont : session_pickle Jsont.t = 541 - Jsont.Object.( 540 + let session_pickle_jsont : session_pickle Json.codec = 541 + Json.Codec.Object.( 542 542 map (fun session_id their_identity_key their_ratchet_key 543 543 our_ratchet_secret our_ratchet_public root_key sending_chain 544 544 receiving_chains skipped_keys creation_time -> 545 545 { session_id; their_identity_key; their_ratchet_key; 546 546 our_ratchet_secret; our_ratchet_public; root_key; sending_chain; 547 547 receiving_chains; skipped_keys; creation_time }) 548 - |> mem "session_id" Jsont.string 549 - |> mem "their_identity_key" Jsont.string 550 - |> opt_mem "their_ratchet_key" Jsont.string 551 - |> mem "our_ratchet_secret" Jsont.string 552 - |> mem "our_ratchet_public" Jsont.string 553 - |> mem "root_key" Jsont.string 554 - |> opt_mem "sending_chain" chain_key_pickle_jsont 555 - |> mem "receiving_chains" 556 - (Jsont.list (Jsont.Object.( 548 + |> member "session_id" Json.Codec.string 549 + |> member "their_identity_key" Json.Codec.string 550 + |> opt_member "their_ratchet_key" Json.Codec.string 551 + |> member "our_ratchet_secret" Json.Codec.string 552 + |> member "our_ratchet_public" Json.Codec.string 553 + |> member "root_key" Json.Codec.string 554 + |> opt_member "sending_chain" chain_key_pickle_jsont 555 + |> member "receiving_chains" 556 + (Json.Codec.list (Json.Codec.Object.( 557 557 map (fun k v -> (k, v)) 558 - |> mem "key" Jsont.string 559 - |> mem "chain" chain_key_pickle_jsont 560 - |> finish))) 561 - |> mem "skipped_keys" 562 - (Jsont.list (Jsont.Object.( 558 + |> member "key" Json.Codec.string 559 + |> member "chain" chain_key_pickle_jsont 560 + |> seal))) 561 + |> member "skipped_keys" 562 + (Json.Codec.list (Json.Codec.Object.( 563 563 map (fun idx_key msg_key -> (idx_key, msg_key)) 564 - |> mem "index_key" string_int_pair_jsont 565 - |> mem "msg_key" Jsont.string 566 - |> finish))) 567 - |> mem "creation_time" ptime_jsont 568 - |> finish) 564 + |> member "index_key" string_int_pair_jsont 565 + |> member "msg_key" Json.Codec.string 566 + |> seal))) 567 + |> member "creation_time" ptime_jsont 568 + |> seal) 569 569 570 570 let pickle_session (session : Olm.Session.t) : string = 571 571 let sending_chain = Option.map (fun (ck : Olm.Session.chain_key) -> ··· 595 595 skipped_keys; 596 596 creation_time = session.creation_time; 597 597 } in 598 - match Jsont_bytesrw.encode_string session_pickle_jsont pickle with 598 + match (try Ok (Json.to_string session_pickle_jsont pickle) with Json.Error e -> Error (Json.Error.to_string e)) with 599 599 | Ok s -> s 600 600 | Error e -> failwith ("Failed to pickle session: " ^ e) 601 601 602 602 let unpickle_session (s : string) : (Olm.Session.t, string) result = 603 - match Jsont_bytesrw.decode_string session_pickle_jsont s with 603 + match (Json.of_string session_pickle_jsont s |> Result.map_error Json.Error.to_string) with 604 604 | Error e -> Error ("Failed to unpickle session: " ^ e) 605 605 | Ok pickle -> 606 606 let our_ratchet_secret = ··· 651 651 creation_time : Ptime.t; 652 652 } 653 653 654 - let megolm_inbound_pickle_jsont : megolm_inbound_pickle Jsont.t = 655 - Jsont.Object.( 654 + let megolm_inbound_pickle_jsont : megolm_inbound_pickle Json.codec = 655 + Json.Codec.Object.( 656 656 map (fun session_id sender_key room_id ratchet message_index 657 657 received_indices signing_key creation_time -> 658 658 { session_id; sender_key; room_id; ratchet; message_index; 659 659 received_indices; signing_key; creation_time }) 660 - |> mem "session_id" Jsont.string 661 - |> mem "sender_key" Jsont.string 662 - |> mem "room_id" Jsont.string 663 - |> mem "ratchet" (Jsont.list Jsont.string) 664 - |> mem "message_index" Jsont.int 665 - |> mem "received_indices" (Jsont.list Jsont.int) 666 - |> mem "signing_key" Jsont.string 667 - |> mem "creation_time" ptime_jsont 668 - |> finish) 660 + |> member "session_id" Json.Codec.string 661 + |> member "sender_key" Json.Codec.string 662 + |> member "room_id" Json.Codec.string 663 + |> member "ratchet" (Json.Codec.list Json.Codec.string) 664 + |> member "message_index" Json.Codec.int 665 + |> member "received_indices" (Json.Codec.list Json.Codec.int) 666 + |> member "signing_key" Json.Codec.string 667 + |> member "creation_time" ptime_jsont 668 + |> seal) 669 669 670 670 let pickle_megolm_inbound (session : Olm.Megolm.Inbound.t) : string = 671 671 let ratchet = Array.to_list session.ratchet |> List.map base64_encode in ··· 679 679 signing_key = session.signing_key; 680 680 creation_time = session.creation_time; 681 681 } in 682 - match Jsont_bytesrw.encode_string megolm_inbound_pickle_jsont pickle with 682 + match (try Ok (Json.to_string megolm_inbound_pickle_jsont pickle) with Json.Error e -> Error (Json.Error.to_string e)) with 683 683 | Ok s -> s 684 684 | Error e -> failwith ("Failed to pickle megolm inbound: " ^ e) 685 685 686 686 let unpickle_megolm_inbound (s : string) 687 687 : (Olm.Megolm.Inbound.t, string) result = 688 - match Jsont_bytesrw.decode_string megolm_inbound_pickle_jsont s with 688 + match (Json.of_string megolm_inbound_pickle_jsont s |> Result.map_error Json.Error.to_string) with 689 689 | Error e -> Error ("Failed to unpickle megolm inbound: " ^ e) 690 690 | Ok pickle -> 691 691 let ratchet = ··· 720 720 shared_with : (string * string) list; (* user_id, device_id pairs *) 721 721 } 722 722 723 - let megolm_outbound_pickle_jsont : megolm_outbound_pickle Jsont.t = 724 - Jsont.Object.( 723 + let megolm_outbound_pickle_jsont : megolm_outbound_pickle Json.codec = 724 + Json.Codec.Object.( 725 725 map (fun session_id room_id ratchet message_index signing_priv 726 726 signing_pub creation_time message_count max_messages max_age_s 727 727 shared_with -> 728 728 { session_id; room_id; ratchet; message_index; signing_priv; 729 729 signing_pub; creation_time; message_count; max_messages; max_age_s; 730 730 shared_with }) 731 - |> mem "session_id" Jsont.string 732 - |> mem "room_id" Jsont.string 733 - |> mem "ratchet" (Jsont.list Jsont.string) 734 - |> mem "message_index" Jsont.int 735 - |> mem "signing_priv" ed25519_priv_jsont 736 - |> mem "signing_pub" ed25519_pub_jsont 737 - |> mem "creation_time" ptime_jsont 738 - |> mem "message_count" Jsont.int 739 - |> mem "max_messages" Jsont.int 740 - |> mem "max_age_s" Jsont.int 741 - |> mem "shared_with" 742 - (Jsont.list (Jsont.list Jsont.string |> Jsont.map 731 + |> member "session_id" Json.Codec.string 732 + |> member "room_id" Json.Codec.string 733 + |> member "ratchet" (Json.Codec.list Json.Codec.string) 734 + |> member "message_index" Json.Codec.int 735 + |> member "signing_priv" ed25519_priv_jsont 736 + |> member "signing_pub" ed25519_pub_jsont 737 + |> member "creation_time" ptime_jsont 738 + |> member "message_count" Json.Codec.int 739 + |> member "max_messages" Json.Codec.int 740 + |> member "max_age_s" Json.Codec.int 741 + |> member "shared_with" 742 + (Json.Codec.list (Json.Codec.list Json.Codec.string |> Json.Codec.map 743 743 ~dec:(function 744 744 | [a; b] -> (a, b) 745 745 | _ -> failwith "Expected 2 elements") 746 746 ~enc:(fun (a, b) -> [a; b]))) 747 - |> finish) 747 + |> seal) 748 748 749 749 let pickle_megolm_outbound (session : Olm.Megolm.Outbound.t) : string = 750 750 let ratchet = Array.to_list session.ratchet |> List.map base64_encode in ··· 766 766 max_age_s; 767 767 shared_with = session.shared_with; 768 768 } in 769 - match Jsont_bytesrw.encode_string megolm_outbound_pickle_jsont pickle with 769 + match (try Ok (Json.to_string megolm_outbound_pickle_jsont pickle) with Json.Error e -> Error (Json.Error.to_string e)) with 770 770 | Ok s -> s 771 771 | Error e -> failwith ("Failed to pickle megolm outbound: " ^ e) 772 772 773 773 let unpickle_megolm_outbound (s : string) 774 774 : (Olm.Megolm.Outbound.t, string) result = 775 - match Jsont_bytesrw.decode_string megolm_outbound_pickle_jsont s with 775 + match (Json.of_string megolm_outbound_pickle_jsont s |> Result.map_error Json.Error.to_string) with 776 776 | Error e -> Error ("Failed to unpickle megolm outbound: " ^ e) 777 777 | Ok pickle -> 778 778 let ratchet =
+154 -154
lib/matrix_client/sliding_sync.ml
··· 12 12 13 13 let state_pair_list_jsont = 14 14 (* Decode array of [event_type, state_key] pairs *) 15 - Jsont.list (Jsont.list Jsont.string) 16 - |> Jsont.map 15 + Json.Codec.list (Json.Codec.list Json.Codec.string) 16 + |> Json.Codec.map 17 17 ~dec:(fun pairs -> 18 18 List.filter_map (function 19 19 | [et; sk] -> Some (et, sk) ··· 22 22 List.map (fun (et, sk) -> [et; sk]) pairs) 23 23 24 24 let room_subscription_jsont = 25 - Jsont.Object.( 25 + Json.Codec.Object.( 26 26 map (fun required_state timeline_limit include_old_rooms -> 27 27 { required_state; timeline_limit; include_old_rooms }) 28 - |> mem "required_state" state_pair_list_jsont ~dec_absent:[] 28 + |> member "required_state" state_pair_list_jsont ~dec_absent:[] 29 29 ~enc:(fun t -> t.required_state) 30 - |> opt_mem "timeline_limit" Jsont.int ~enc:(fun t -> t.timeline_limit) 31 - |> opt_mem "include_old_rooms" Jsont.bool ~enc:(fun t -> t.include_old_rooms) 32 - |> finish) 30 + |> opt_member "timeline_limit" Json.Codec.int ~enc:(fun t -> t.timeline_limit) 31 + |> opt_member "include_old_rooms" Json.Codec.bool ~enc:(fun t -> t.include_old_rooms) 32 + |> seal) 33 33 34 34 (** List operation for sliding window *) 35 35 type list_op = ··· 61 61 } 62 62 63 63 let list_filters_jsont = 64 - Jsont.Object.( 64 + Json.Codec.Object.( 65 65 map (fun is_dm spaces is_encrypted is_invite room_types not_room_types 66 66 room_name_like tags not_tags -> 67 67 { is_dm; spaces; is_encrypted; is_invite; room_types; not_room_types; 68 68 room_name_like; tags; not_tags }) 69 - |> opt_mem "is_dm" Jsont.bool ~enc:(fun t -> t.is_dm) 70 - |> opt_mem "spaces" (Jsont.list Jsont.string) ~enc:(fun t -> t.spaces) 71 - |> opt_mem "is_encrypted" Jsont.bool ~enc:(fun t -> t.is_encrypted) 72 - |> opt_mem "is_invite" Jsont.bool ~enc:(fun t -> t.is_invite) 73 - |> opt_mem "room_types" (Jsont.list Jsont.string) ~enc:(fun t -> t.room_types) 74 - |> opt_mem "not_room_types" (Jsont.list Jsont.string) ~enc:(fun t -> t.not_room_types) 75 - |> opt_mem "room_name_like" Jsont.string ~enc:(fun t -> t.room_name_like) 76 - |> opt_mem "tags" (Jsont.list Jsont.string) ~enc:(fun t -> t.tags) 77 - |> opt_mem "not_tags" (Jsont.list Jsont.string) ~enc:(fun t -> t.not_tags) 78 - |> finish) 69 + |> opt_member "is_dm" Json.Codec.bool ~enc:(fun t -> t.is_dm) 70 + |> opt_member "spaces" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.spaces) 71 + |> opt_member "is_encrypted" Json.Codec.bool ~enc:(fun t -> t.is_encrypted) 72 + |> opt_member "is_invite" Json.Codec.bool ~enc:(fun t -> t.is_invite) 73 + |> opt_member "room_types" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.room_types) 74 + |> opt_member "not_room_types" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.not_room_types) 75 + |> opt_member "room_name_like" Json.Codec.string ~enc:(fun t -> t.room_name_like) 76 + |> opt_member "tags" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.tags) 77 + |> opt_member "not_tags" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.not_tags) 78 + |> seal) 79 79 80 80 let range_jsont = 81 81 (* Decode [start, end] pair as (int * int) *) 82 - Jsont.list Jsont.int 83 - |> Jsont.map 82 + Json.Codec.list Json.Codec.int 83 + |> Json.Codec.map 84 84 ~dec:(function 85 85 | [a; b] -> (a, b) 86 86 | _ -> (0, 0)) ··· 88 88 89 89 let ranges_jsont = 90 90 (* List of ranges *) 91 - Jsont.list range_jsont 91 + Json.Codec.list range_jsont 92 92 93 93 let state_pair_jsont = 94 94 (* Decode [event_type, state_key] as (string * string) *) 95 - Jsont.list Jsont.string 96 - |> Jsont.map 95 + Json.Codec.list Json.Codec.string 96 + |> Json.Codec.map 97 97 ~dec:(function 98 98 | [et; sk] -> (et, sk) 99 99 | _ -> ("", "")) 100 100 ~enc:(fun (et, sk) -> [et; sk]) 101 101 102 102 let list_config_jsont = 103 - Jsont.Object.( 103 + Json.Codec.Object.( 104 104 map (fun ranges sort required_state timeline_limit filters bump_event_types -> 105 105 { ranges; sort; required_state; timeline_limit; filters; bump_event_types }) 106 - |> mem "ranges" ranges_jsont ~dec_absent:[] ~enc:(fun t -> t.ranges) 107 - |> opt_mem "sort" (Jsont.list Jsont.string) ~enc:(fun t -> t.sort) 108 - |> mem "required_state" (Jsont.list state_pair_jsont) ~dec_absent:[] 106 + |> member "ranges" ranges_jsont ~dec_absent:[] ~enc:(fun t -> t.ranges) 107 + |> opt_member "sort" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.sort) 108 + |> member "required_state" (Json.Codec.list state_pair_jsont) ~dec_absent:[] 109 109 ~enc:(fun t -> t.required_state) 110 - |> opt_mem "timeline_limit" Jsont.int ~enc:(fun t -> t.timeline_limit) 111 - |> opt_mem "filters" list_filters_jsont ~enc:(fun t -> t.filters) 112 - |> opt_mem "bump_event_types" (Jsont.list Jsont.string) 110 + |> opt_member "timeline_limit" Json.Codec.int ~enc:(fun t -> t.timeline_limit) 111 + |> opt_member "filters" list_filters_jsont ~enc:(fun t -> t.filters) 112 + |> opt_member "bump_event_types" (Json.Codec.list Json.Codec.string) 113 113 ~enc:(fun t -> t.bump_event_types) 114 - |> finish) 114 + |> seal) 115 115 116 116 (** Sliding sync request *) 117 117 type request = { ··· 160 160 } 161 161 162 162 let to_device_ext_jsont = 163 - Jsont.Object.( 163 + Json.Codec.Object.( 164 164 map (fun enabled since limit -> { enabled; since; limit }) 165 - |> mem "enabled" Jsont.bool ~enc:(fun t -> t.enabled) 166 - |> opt_mem "since" Jsont.string ~enc:(fun t -> t.since) 167 - |> opt_mem "limit" Jsont.int ~enc:(fun t -> t.limit) 168 - |> finish) 165 + |> member "enabled" Json.Codec.bool ~enc:(fun t -> t.enabled) 166 + |> opt_member "since" Json.Codec.string ~enc:(fun t -> t.since) 167 + |> opt_member "limit" Json.Codec.int ~enc:(fun t -> t.limit) 168 + |> seal) 169 169 170 170 let e2ee_ext_jsont = 171 - Jsont.Object.( 171 + Json.Codec.Object.( 172 172 map (fun enabled -> ({ enabled } : e2ee_ext)) 173 - |> mem "enabled" Jsont.bool ~enc:(fun (t : e2ee_ext) -> t.enabled) 174 - |> finish) 173 + |> member "enabled" Json.Codec.bool ~enc:(fun (t : e2ee_ext) -> t.enabled) 174 + |> seal) 175 175 176 176 let account_data_ext_jsont = 177 - Jsont.Object.( 177 + Json.Codec.Object.( 178 178 map (fun enabled lists rooms -> ({ enabled; lists; rooms } : account_data_ext)) 179 - |> mem "enabled" Jsont.bool ~enc:(fun (t : account_data_ext) -> t.enabled) 180 - |> opt_mem "lists" (Jsont.list Jsont.string) ~enc:(fun (t : account_data_ext) -> t.lists) 181 - |> opt_mem "rooms" (Jsont.list Jsont.string) ~enc:(fun (t : account_data_ext) -> t.rooms) 182 - |> finish) 179 + |> member "enabled" Json.Codec.bool ~enc:(fun (t : account_data_ext) -> t.enabled) 180 + |> opt_member "lists" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : account_data_ext) -> t.lists) 181 + |> opt_member "rooms" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : account_data_ext) -> t.rooms) 182 + |> seal) 183 183 184 184 let typing_ext_jsont = 185 - Jsont.Object.( 185 + Json.Codec.Object.( 186 186 map (fun enabled lists rooms -> ({ enabled; lists; rooms } : typing_ext)) 187 - |> mem "enabled" Jsont.bool ~enc:(fun (t : typing_ext) -> t.enabled) 188 - |> opt_mem "lists" (Jsont.list Jsont.string) ~enc:(fun (t : typing_ext) -> t.lists) 189 - |> opt_mem "rooms" (Jsont.list Jsont.string) ~enc:(fun (t : typing_ext) -> t.rooms) 190 - |> finish) 187 + |> member "enabled" Json.Codec.bool ~enc:(fun (t : typing_ext) -> t.enabled) 188 + |> opt_member "lists" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : typing_ext) -> t.lists) 189 + |> opt_member "rooms" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : typing_ext) -> t.rooms) 190 + |> seal) 191 191 192 192 let receipts_ext_jsont = 193 - Jsont.Object.( 193 + Json.Codec.Object.( 194 194 map (fun enabled lists rooms -> ({ enabled; lists; rooms } : receipts_ext)) 195 - |> mem "enabled" Jsont.bool ~enc:(fun (t : receipts_ext) -> t.enabled) 196 - |> opt_mem "lists" (Jsont.list Jsont.string) ~enc:(fun (t : receipts_ext) -> t.lists) 197 - |> opt_mem "rooms" (Jsont.list Jsont.string) ~enc:(fun (t : receipts_ext) -> t.rooms) 198 - |> finish) 195 + |> member "enabled" Json.Codec.bool ~enc:(fun (t : receipts_ext) -> t.enabled) 196 + |> opt_member "lists" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : receipts_ext) -> t.lists) 197 + |> opt_member "rooms" (Json.Codec.list Json.Codec.string) ~enc:(fun (t : receipts_ext) -> t.rooms) 198 + |> seal) 199 199 200 200 let extensions_jsont = 201 - Jsont.Object.( 201 + Json.Codec.Object.( 202 202 map (fun to_device e2ee account_data typing receipts -> 203 203 { to_device; e2ee; account_data; typing; receipts }) 204 - |> opt_mem "to_device" to_device_ext_jsont ~enc:(fun t -> t.to_device) 205 - |> opt_mem "e2ee" e2ee_ext_jsont ~enc:(fun t -> t.e2ee) 206 - |> opt_mem "account_data" account_data_ext_jsont ~enc:(fun t -> t.account_data) 207 - |> opt_mem "typing" typing_ext_jsont ~enc:(fun t -> t.typing) 208 - |> opt_mem "receipts" receipts_ext_jsont ~enc:(fun t -> t.receipts) 209 - |> finish) 204 + |> opt_member "to_device" to_device_ext_jsont ~enc:(fun t -> t.to_device) 205 + |> opt_member "e2ee" e2ee_ext_jsont ~enc:(fun t -> t.e2ee) 206 + |> opt_member "account_data" account_data_ext_jsont ~enc:(fun t -> t.account_data) 207 + |> opt_member "typing" typing_ext_jsont ~enc:(fun t -> t.typing) 208 + |> opt_member "receipts" receipts_ext_jsont ~enc:(fun t -> t.receipts) 209 + |> seal) 210 210 211 211 module StringMap = Map.Make(String) 212 212 213 213 let string_map_jsont value_jsont = 214 - Jsont.Object.as_string_map value_jsont 215 - |> Jsont.map 214 + Json.Codec.Object.as_string_map value_jsont 215 + |> Json.Codec.map 216 216 ~dec:(fun m -> StringMap.bindings m) 217 217 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 218 218 219 219 let request_jsont = 220 - Jsont.Object.( 220 + Json.Codec.Object.( 221 221 map (fun lists room_subscriptions unsubscribe_rooms extensions pos timeout -> 222 222 { lists; room_subscriptions; unsubscribe_rooms; extensions; pos; timeout }) 223 - |> mem "lists" (string_map_jsont list_config_jsont) ~dec_absent:[] 223 + |> member "lists" (string_map_jsont list_config_jsont) ~dec_absent:[] 224 224 ~enc:(fun t -> t.lists) 225 - |> mem "room_subscriptions" (string_map_jsont room_subscription_jsont) ~dec_absent:[] 225 + |> member "room_subscriptions" (string_map_jsont room_subscription_jsont) ~dec_absent:[] 226 226 ~enc:(fun t -> t.room_subscriptions) 227 - |> mem "unsubscribe_rooms" (Jsont.list Jsont.string) ~dec_absent:[] 227 + |> member "unsubscribe_rooms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 228 228 ~enc:(fun t -> t.unsubscribe_rooms) 229 - |> opt_mem "extensions" extensions_jsont ~enc:(fun t -> t.extensions) 230 - |> opt_mem "pos" Jsont.string ~enc:(fun t -> t.pos) 231 - |> opt_mem "timeout" Jsont.int ~enc:(fun t -> t.timeout) 232 - |> finish) 229 + |> opt_member "extensions" extensions_jsont ~enc:(fun t -> t.extensions) 230 + |> opt_member "pos" Json.Codec.string ~enc:(fun t -> t.pos) 231 + |> opt_member "timeout" Json.Codec.int ~enc:(fun t -> t.timeout) 232 + |> seal) 233 233 234 234 (** Sliding sync response room data *) 235 235 type room_response = { ··· 238 238 heroes : hero list option; 239 239 is_dm : bool option; 240 240 initial : bool option; 241 - required_state : Jsont.json list; 242 - timeline : Jsont.json list; 241 + required_state : Json.t list; 242 + timeline : Json.t list; 243 243 prev_batch : string option; 244 244 limited : bool option; 245 245 joined_count : int option; ··· 257 257 } 258 258 259 259 let hero_jsont = 260 - Jsont.Object.( 260 + Json.Codec.Object.( 261 261 map (fun user_id name avatar -> ({ user_id; name; avatar } : hero)) 262 - |> mem "user_id" Jsont.string ~enc:(fun (t : hero) -> t.user_id) 263 - |> opt_mem "name" Jsont.string ~enc:(fun (t : hero) -> t.name) 264 - |> opt_mem "avatar" Jsont.string ~enc:(fun (t : hero) -> t.avatar) 265 - |> finish) 262 + |> member "user_id" Json.Codec.string ~enc:(fun (t : hero) -> t.user_id) 263 + |> opt_member "name" Json.Codec.string ~enc:(fun (t : hero) -> t.name) 264 + |> opt_member "avatar" Json.Codec.string ~enc:(fun (t : hero) -> t.avatar) 265 + |> seal) 266 266 267 267 let room_response_jsont = 268 - Jsont.Object.( 268 + Json.Codec.Object.( 269 269 map (fun name avatar heroes is_dm initial required_state timeline 270 270 prev_batch limited joined_count invited_count notification_count 271 271 highlight_count num_live timestamp -> 272 272 ({ name; avatar; heroes; is_dm; initial; required_state; timeline; 273 273 prev_batch; limited; joined_count; invited_count; notification_count; 274 274 highlight_count; num_live; timestamp } : room_response)) 275 - |> opt_mem "name" Jsont.string ~enc:(fun (t : room_response) -> t.name) 276 - |> opt_mem "avatar" Jsont.string ~enc:(fun (t : room_response) -> t.avatar) 277 - |> opt_mem "heroes" (Jsont.list hero_jsont) ~enc:(fun (t : room_response) -> t.heroes) 278 - |> opt_mem "is_dm" Jsont.bool ~enc:(fun (t : room_response) -> t.is_dm) 279 - |> opt_mem "initial" Jsont.bool ~enc:(fun (t : room_response) -> t.initial) 280 - |> mem "required_state" (Jsont.list Jsont.json) ~dec_absent:[] 275 + |> opt_member "name" Json.Codec.string ~enc:(fun (t : room_response) -> t.name) 276 + |> opt_member "avatar" Json.Codec.string ~enc:(fun (t : room_response) -> t.avatar) 277 + |> opt_member "heroes" (Json.Codec.list hero_jsont) ~enc:(fun (t : room_response) -> t.heroes) 278 + |> opt_member "is_dm" Json.Codec.bool ~enc:(fun (t : room_response) -> t.is_dm) 279 + |> opt_member "initial" Json.Codec.bool ~enc:(fun (t : room_response) -> t.initial) 280 + |> member "required_state" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] 281 281 ~enc:(fun (t : room_response) -> t.required_state) 282 - |> mem "timeline" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun (t : room_response) -> t.timeline) 283 - |> opt_mem "prev_batch" Jsont.string ~enc:(fun (t : room_response) -> t.prev_batch) 284 - |> opt_mem "limited" Jsont.bool ~enc:(fun (t : room_response) -> t.limited) 285 - |> opt_mem "joined_count" Jsont.int ~enc:(fun (t : room_response) -> t.joined_count) 286 - |> opt_mem "invited_count" Jsont.int ~enc:(fun (t : room_response) -> t.invited_count) 287 - |> opt_mem "notification_count" Jsont.int ~enc:(fun (t : room_response) -> t.notification_count) 288 - |> opt_mem "highlight_count" Jsont.int ~enc:(fun (t : room_response) -> t.highlight_count) 289 - |> opt_mem "num_live" Jsont.int ~enc:(fun (t : room_response) -> t.num_live) 290 - |> opt_mem "timestamp" Jsont.int64 ~enc:(fun (t : room_response) -> t.timestamp) 291 - |> finish) 282 + |> member "timeline" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun (t : room_response) -> t.timeline) 283 + |> opt_member "prev_batch" Json.Codec.string ~enc:(fun (t : room_response) -> t.prev_batch) 284 + |> opt_member "limited" Json.Codec.bool ~enc:(fun (t : room_response) -> t.limited) 285 + |> opt_member "joined_count" Json.Codec.int ~enc:(fun (t : room_response) -> t.joined_count) 286 + |> opt_member "invited_count" Json.Codec.int ~enc:(fun (t : room_response) -> t.invited_count) 287 + |> opt_member "notification_count" Json.Codec.int ~enc:(fun (t : room_response) -> t.notification_count) 288 + |> opt_member "highlight_count" Json.Codec.int ~enc:(fun (t : room_response) -> t.highlight_count) 289 + |> opt_member "num_live" Json.Codec.int ~enc:(fun (t : room_response) -> t.num_live) 290 + |> opt_member "timestamp" Json.Codec.int64 ~enc:(fun (t : room_response) -> t.timestamp) 291 + |> seal) 292 292 293 293 (** Sliding sync list response *) 294 294 type list_response = { ··· 305 305 } 306 306 307 307 let list_op_response_jsont = 308 - Jsont.Object.( 308 + Json.Codec.Object.( 309 309 map (fun op range index room_ids room_id -> 310 310 { op; range; index; room_ids; room_id }) 311 - |> mem "op" Jsont.string ~enc:(fun t -> t.op) 312 - |> opt_mem "range" range_jsont ~enc:(fun t -> t.range) 313 - |> opt_mem "index" Jsont.int ~enc:(fun t -> t.index) 314 - |> opt_mem "room_ids" (Jsont.list Jsont.string) ~enc:(fun t -> t.room_ids) 315 - |> opt_mem "room_id" Jsont.string ~enc:(fun t -> t.room_id) 316 - |> finish) 311 + |> member "op" Json.Codec.string ~enc:(fun t -> t.op) 312 + |> opt_member "range" range_jsont ~enc:(fun t -> t.range) 313 + |> opt_member "index" Json.Codec.int ~enc:(fun t -> t.index) 314 + |> opt_member "room_ids" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.room_ids) 315 + |> opt_member "room_id" Json.Codec.string ~enc:(fun t -> t.room_id) 316 + |> seal) 317 317 318 318 let list_response_jsont = 319 - Jsont.Object.( 319 + Json.Codec.Object.( 320 320 map (fun count ops -> { count; ops }) 321 - |> mem "count" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.count) 322 - |> mem "ops" (Jsont.list list_op_response_jsont) ~dec_absent:[] ~enc:(fun t -> t.ops) 323 - |> finish) 321 + |> member "count" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.count) 322 + |> member "ops" (Json.Codec.list list_op_response_jsont) ~dec_absent:[] ~enc:(fun t -> t.ops) 323 + |> seal) 324 324 325 325 (** Extensions response *) 326 326 type extensions_response = { ··· 333 333 334 334 and to_device_response = { 335 335 next_batch : string; 336 - events : Jsont.json list; 336 + events : Json.t list; 337 337 } 338 338 339 339 and e2ee_response = { ··· 348 348 } 349 349 350 350 and account_data_response = { 351 - global : Jsont.json list; 352 - rooms : (string * Jsont.json list) list; 351 + global : Json.t list; 352 + rooms : (string * Json.t list) list; 353 353 } 354 354 355 355 and typing_response = { ··· 357 357 } 358 358 359 359 and receipts_response = { 360 - rooms : (string * Jsont.json) list; (* room_id -> receipt content *) 360 + rooms : (string * Json.t) list; (* room_id -> receipt content *) 361 361 } 362 362 363 363 let to_device_response_jsont = 364 - Jsont.Object.( 364 + Json.Codec.Object.( 365 365 map (fun next_batch events -> { next_batch; events }) 366 - |> mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 367 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun t -> t.events) 368 - |> finish) 366 + |> member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 367 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun t -> t.events) 368 + |> seal) 369 369 370 370 let device_lists_jsont = 371 - Jsont.Object.( 371 + Json.Codec.Object.( 372 372 map (fun changed left -> { changed; left }) 373 - |> mem "changed" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.changed) 374 - |> mem "left" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.left) 375 - |> finish) 373 + |> member "changed" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.changed) 374 + |> member "left" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.left) 375 + |> seal) 376 376 377 377 let int_map_jsont = 378 - Jsont.Object.as_string_map Jsont.int 379 - |> Jsont.map 378 + Json.Codec.Object.as_string_map Json.Codec.int 379 + |> Json.Codec.map 380 380 ~dec:(fun m -> StringMap.bindings m) 381 381 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 382 382 383 383 let e2ee_response_jsont = 384 - Jsont.Object.( 384 + Json.Codec.Object.( 385 385 map (fun device_lists device_one_time_keys_count device_unused_fallback_key_types -> 386 386 { device_lists; device_one_time_keys_count; device_unused_fallback_key_types }) 387 - |> opt_mem "device_lists" device_lists_jsont ~enc:(fun t -> t.device_lists) 388 - |> mem "device_one_time_keys_count" int_map_jsont ~dec_absent:[] 387 + |> opt_member "device_lists" device_lists_jsont ~enc:(fun t -> t.device_lists) 388 + |> member "device_one_time_keys_count" int_map_jsont ~dec_absent:[] 389 389 ~enc:(fun t -> t.device_one_time_keys_count) 390 - |> mem "device_unused_fallback_key_types" (Jsont.list Jsont.string) ~dec_absent:[] 390 + |> member "device_unused_fallback_key_types" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 391 391 ~enc:(fun t -> t.device_unused_fallback_key_types) 392 - |> finish) 392 + |> seal) 393 393 394 394 let json_list_map_jsont = 395 - Jsont.Object.as_string_map (Jsont.list Jsont.json) 396 - |> Jsont.map 395 + Json.Codec.Object.as_string_map (Json.Codec.list Json.Codec.Value.t) 396 + |> Json.Codec.map 397 397 ~dec:(fun m -> StringMap.bindings m) 398 398 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 399 399 400 400 let account_data_response_jsont = 401 - Jsont.Object.( 401 + Json.Codec.Object.( 402 402 map (fun global rooms -> { global; rooms }) 403 - |> mem "global" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun t -> t.global) 404 - |> mem "rooms" json_list_map_jsont ~dec_absent:[] ~enc:(fun t -> t.rooms) 405 - |> finish) 403 + |> member "global" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun t -> t.global) 404 + |> member "rooms" json_list_map_jsont ~dec_absent:[] ~enc:(fun t -> t.rooms) 405 + |> seal) 406 406 407 407 let string_list_map_jsont = 408 - Jsont.Object.as_string_map (Jsont.list Jsont.string) 409 - |> Jsont.map 408 + Json.Codec.Object.as_string_map (Json.Codec.list Json.Codec.string) 409 + |> Json.Codec.map 410 410 ~dec:(fun m -> StringMap.bindings m) 411 411 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 412 412 413 413 let typing_response_jsont = 414 - Jsont.Object.( 414 + Json.Codec.Object.( 415 415 map (fun rooms -> ({ rooms } : typing_response)) 416 - |> mem "rooms" string_list_map_jsont ~dec_absent:[] ~enc:(fun (t : typing_response) -> t.rooms) 417 - |> finish) 416 + |> member "rooms" string_list_map_jsont ~dec_absent:[] ~enc:(fun (t : typing_response) -> t.rooms) 417 + |> seal) 418 418 419 419 let json_map_jsont = 420 - Jsont.Object.as_string_map Jsont.json 421 - |> Jsont.map 420 + Json.Codec.Object.as_string_map Json.Codec.Value.t 421 + |> Json.Codec.map 422 422 ~dec:(fun m -> StringMap.bindings m) 423 423 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 424 424 425 425 let receipts_response_jsont = 426 - Jsont.Object.( 426 + Json.Codec.Object.( 427 427 map (fun rooms -> ({ rooms } : receipts_response)) 428 - |> mem "rooms" json_map_jsont ~dec_absent:[] ~enc:(fun (t : receipts_response) -> t.rooms) 429 - |> finish) 428 + |> member "rooms" json_map_jsont ~dec_absent:[] ~enc:(fun (t : receipts_response) -> t.rooms) 429 + |> seal) 430 430 431 431 let extensions_response_jsont = 432 - Jsont.Object.( 432 + Json.Codec.Object.( 433 433 map (fun to_device e2ee account_data typing receipts -> 434 434 { to_device; e2ee; account_data; typing; receipts }) 435 - |> opt_mem "to_device" to_device_response_jsont ~enc:(fun t -> t.to_device) 436 - |> opt_mem "e2ee" e2ee_response_jsont ~enc:(fun t -> t.e2ee) 437 - |> opt_mem "account_data" account_data_response_jsont ~enc:(fun t -> t.account_data) 438 - |> opt_mem "typing" typing_response_jsont ~enc:(fun t -> t.typing) 439 - |> opt_mem "receipts" receipts_response_jsont ~enc:(fun t -> t.receipts) 440 - |> finish) 435 + |> opt_member "to_device" to_device_response_jsont ~enc:(fun t -> t.to_device) 436 + |> opt_member "e2ee" e2ee_response_jsont ~enc:(fun t -> t.e2ee) 437 + |> opt_member "account_data" account_data_response_jsont ~enc:(fun t -> t.account_data) 438 + |> opt_member "typing" typing_response_jsont ~enc:(fun t -> t.typing) 439 + |> opt_member "receipts" receipts_response_jsont ~enc:(fun t -> t.receipts) 440 + |> seal) 441 441 442 442 (** Full sliding sync response *) 443 443 type response = { ··· 448 448 } 449 449 450 450 let response_jsont = 451 - Jsont.Object.( 451 + Json.Codec.Object.( 452 452 map (fun pos lists rooms extensions -> 453 453 { pos; lists; rooms; extensions }) 454 - |> mem "pos" Jsont.string ~enc:(fun t -> t.pos) 455 - |> mem "lists" (string_map_jsont list_response_jsont) ~dec_absent:[] 454 + |> member "pos" Json.Codec.string ~enc:(fun t -> t.pos) 455 + |> member "lists" (string_map_jsont list_response_jsont) ~dec_absent:[] 456 456 ~enc:(fun t -> t.lists) 457 - |> mem "rooms" (string_map_jsont room_response_jsont) ~dec_absent:[] 457 + |> member "rooms" (string_map_jsont room_response_jsont) ~dec_absent:[] 458 458 ~enc:(fun t -> t.rooms) 459 - |> opt_mem "extensions" extensions_response_jsont ~enc:(fun t -> t.extensions) 460 - |> finish) 459 + |> opt_member "extensions" extensions_response_jsont ~enc:(fun t -> t.extensions) 460 + |> seal) 461 461 462 462 (** Perform a sliding sync request. 463 463
+28 -28
lib/matrix_client/sliding_sync.mli
··· 14 14 include_old_rooms : bool option; 15 15 } 16 16 17 - val room_subscription_jsont : room_subscription Jsont.t 17 + val room_subscription_jsont : room_subscription Json.codec 18 18 (** JSON codec for room subscription. *) 19 19 20 20 (** {1 List Operations} *) ··· 41 41 not_tags : string list option; 42 42 } 43 43 44 - val list_filters_jsont : list_filters Jsont.t 44 + val list_filters_jsont : list_filters Json.codec 45 45 (** JSON codec for list filters. *) 46 46 47 47 (** Sliding sync list configuration. *) ··· 54 54 bump_event_types : string list option; 55 55 } 56 56 57 - val list_config_jsont : list_config Jsont.t 57 + val list_config_jsont : list_config Json.codec 58 58 (** JSON codec for list config. *) 59 59 60 60 (** {1 Extensions} *) ··· 66 66 limit : int option; 67 67 } 68 68 69 - val to_device_ext_jsont : to_device_ext Jsont.t 69 + val to_device_ext_jsont : to_device_ext Json.codec 70 70 (** JSON codec for to_device extension. *) 71 71 72 72 (** E2EE extension. *) ··· 74 74 enabled : bool; 75 75 } 76 76 77 - val e2ee_ext_jsont : e2ee_ext Jsont.t 77 + val e2ee_ext_jsont : e2ee_ext Json.codec 78 78 (** JSON codec for E2EE extension. *) 79 79 80 80 (** Account data extension. *) ··· 84 84 rooms : string list option; 85 85 } 86 86 87 - val account_data_ext_jsont : account_data_ext Jsont.t 87 + val account_data_ext_jsont : account_data_ext Json.codec 88 88 (** JSON codec for account data extension. *) 89 89 90 90 (** Typing extension. *) ··· 94 94 rooms : string list option; 95 95 } 96 96 97 - val typing_ext_jsont : typing_ext Jsont.t 97 + val typing_ext_jsont : typing_ext Json.codec 98 98 (** JSON codec for typing extension. *) 99 99 100 100 (** Receipts extension. *) ··· 104 104 rooms : string list option; 105 105 } 106 106 107 - val receipts_ext_jsont : receipts_ext Jsont.t 107 + val receipts_ext_jsont : receipts_ext Json.codec 108 108 (** JSON codec for receipts extension. *) 109 109 110 110 (** Extensions configuration. *) ··· 116 116 receipts : receipts_ext option; 117 117 } 118 118 119 - val extensions_jsont : extensions Jsont.t 119 + val extensions_jsont : extensions Json.codec 120 120 (** JSON codec for extensions. *) 121 121 122 122 (** {1 Request} *) ··· 131 131 timeout : int option; 132 132 } 133 133 134 - val request_jsont : request Jsont.t 134 + val request_jsont : request Json.codec 135 135 (** JSON codec for request. *) 136 136 137 137 (** {1 Response Types} *) ··· 143 143 avatar : string option; 144 144 } 145 145 146 - val hero_jsont : hero Jsont.t 146 + val hero_jsont : hero Json.codec 147 147 (** JSON codec for hero. *) 148 148 149 149 (** Room response data. *) ··· 153 153 heroes : hero list option; 154 154 is_dm : bool option; 155 155 initial : bool option; 156 - required_state : Jsont.json list; 157 - timeline : Jsont.json list; 156 + required_state : Json.t list; 157 + timeline : Json.t list; 158 158 prev_batch : string option; 159 159 limited : bool option; 160 160 joined_count : int option; ··· 165 165 timestamp : int64 option; 166 166 } 167 167 168 - val room_response_jsont : room_response Jsont.t 168 + val room_response_jsont : room_response Json.codec 169 169 (** JSON codec for room response. *) 170 170 171 171 (** List operation response. *) ··· 177 177 room_id : string option; 178 178 } 179 179 180 - val list_op_response_jsont : list_op_response Jsont.t 180 + val list_op_response_jsont : list_op_response Json.codec 181 181 (** JSON codec for list operation response. *) 182 182 183 183 (** List response. *) ··· 186 186 ops : list_op_response list; 187 187 } 188 188 189 - val list_response_jsont : list_response Jsont.t 189 + val list_response_jsont : list_response Json.codec 190 190 (** JSON codec for list response. *) 191 191 192 192 (** {1 Extensions Response} *) ··· 194 194 (** To-device response. *) 195 195 type to_device_response = { 196 196 next_batch : string; 197 - events : Jsont.json list; 197 + events : Json.t list; 198 198 } 199 199 200 - val to_device_response_jsont : to_device_response Jsont.t 200 + val to_device_response_jsont : to_device_response Json.codec 201 201 (** JSON codec for to_device response. *) 202 202 203 203 (** Device lists. *) ··· 206 206 left : string list; 207 207 } 208 208 209 - val device_lists_jsont : device_lists Jsont.t 209 + val device_lists_jsont : device_lists Json.codec 210 210 (** JSON codec for device lists. *) 211 211 212 212 (** E2EE response. *) ··· 216 216 device_unused_fallback_key_types : string list; 217 217 } 218 218 219 - val e2ee_response_jsont : e2ee_response Jsont.t 219 + val e2ee_response_jsont : e2ee_response Json.codec 220 220 (** JSON codec for E2EE response. *) 221 221 222 222 (** Account data response. *) 223 223 type account_data_response = { 224 - global : Jsont.json list; 225 - rooms : (string * Jsont.json list) list; 224 + global : Json.t list; 225 + rooms : (string * Json.t list) list; 226 226 } 227 227 228 - val account_data_response_jsont : account_data_response Jsont.t 228 + val account_data_response_jsont : account_data_response Json.codec 229 229 (** JSON codec for account data response. *) 230 230 231 231 (** Typing response. *) ··· 233 233 rooms : (string * string list) list; 234 234 } 235 235 236 - val typing_response_jsont : typing_response Jsont.t 236 + val typing_response_jsont : typing_response Json.codec 237 237 (** JSON codec for typing response. *) 238 238 239 239 (** Receipts response. *) 240 240 type receipts_response = { 241 - rooms : (string * Jsont.json) list; 241 + rooms : (string * Json.t) list; 242 242 } 243 243 244 - val receipts_response_jsont : receipts_response Jsont.t 244 + val receipts_response_jsont : receipts_response Json.codec 245 245 (** JSON codec for receipts response. *) 246 246 247 247 (** Extensions response. *) ··· 253 253 receipts : receipts_response option; 254 254 } 255 255 256 - val extensions_response_jsont : extensions_response Jsont.t 256 + val extensions_response_jsont : extensions_response Json.codec 257 257 (** JSON codec for extensions response. *) 258 258 259 259 (** {1 Full Response} *) ··· 266 266 extensions : extensions_response option; 267 267 } 268 268 269 - val response_jsont : response Jsont.t 269 + val response_jsont : response Json.codec 270 270 (** JSON codec for response. *) 271 271 272 272 (** {1 Sync Operations} *)
+26 -26
lib/matrix_client/spaces.ml
··· 26 26 } 27 27 28 28 let child_state_jsont = 29 - Jsont.Object.( 29 + Json.Codec.Object.( 30 30 map (fun state_key via order suggested -> 31 31 { state_key; via; order; suggested }) 32 - |> mem "state_key" Jsont.string ~enc:(fun t -> t.state_key) 33 - |> mem "via" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.via) 34 - |> opt_mem "order" Jsont.string ~enc:(fun t -> t.order) 35 - |> mem "suggested" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.suggested) 36 - |> finish) 32 + |> member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key) 33 + |> member "via" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.via) 34 + |> opt_member "order" Json.Codec.string ~enc:(fun t -> t.order) 35 + |> member "suggested" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.suggested) 36 + |> seal) 37 37 38 38 let space_room_jsont = 39 - Jsont.Object.( 39 + Json.Codec.Object.( 40 40 map (fun room_id name topic canonical_alias avatar_url num_joined_members 41 41 room_type join_rule children_state world_readable guest_can_join -> 42 42 { room_id; name; topic; canonical_alias; avatar_url; num_joined_members; 43 43 room_type; join_rule; children_state; world_readable; guest_can_join }) 44 - |> mem "room_id" Matrix_proto.Id.Room_id.jsont ~enc:(fun t -> t.room_id) 45 - |> opt_mem "name" Jsont.string ~enc:(fun t -> t.name) 46 - |> opt_mem "topic" Jsont.string ~enc:(fun t -> t.topic) 47 - |> opt_mem "canonical_alias" Matrix_proto.Id.Room_alias.jsont ~enc:(fun t -> t.canonical_alias) 48 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 49 - |> mem "num_joined_members" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members) 50 - |> opt_mem "room_type" Jsont.string ~enc:(fun t -> t.room_type) 51 - |> opt_mem "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule) 52 - |> mem "children_state" (Jsont.list child_state_jsont) ~dec_absent:[] 44 + |> member "room_id" Matrix_proto.Id.Room_id.jsont ~enc:(fun t -> t.room_id) 45 + |> opt_member "name" Json.Codec.string ~enc:(fun t -> t.name) 46 + |> opt_member "topic" Json.Codec.string ~enc:(fun t -> t.topic) 47 + |> opt_member "canonical_alias" Matrix_proto.Id.Room_alias.jsont ~enc:(fun t -> t.canonical_alias) 48 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 49 + |> member "num_joined_members" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.num_joined_members) 50 + |> opt_member "room_type" Json.Codec.string ~enc:(fun t -> t.room_type) 51 + |> opt_member "join_rule" Matrix_proto.Event.Join_rule.jsont ~enc:(fun t -> t.join_rule) 52 + |> member "children_state" (Json.Codec.list child_state_jsont) ~dec_absent:[] 53 53 ~enc:(fun t -> t.children_state) 54 - |> mem "world_readable" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.world_readable) 55 - |> mem "guest_can_join" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join) 56 - |> finish) 54 + |> member "world_readable" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.world_readable) 55 + |> member "guest_can_join" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.guest_can_join) 56 + |> seal) 57 57 58 58 (** Response from [GET /_matrix/client/v1/rooms/\{roomId\}/hierarchy]. *) 59 59 type hierarchy_response = { ··· 62 62 } 63 63 64 64 let hierarchy_response_jsont = 65 - Jsont.Object.( 65 + Json.Codec.Object.( 66 66 map (fun rooms next_batch -> { rooms; next_batch }) 67 - |> mem "rooms" (Jsont.list space_room_jsont) ~dec_absent:[] ~enc:(fun t -> t.rooms) 68 - |> opt_mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 69 - |> finish) 67 + |> member "rooms" (Json.Codec.list space_room_jsont) ~dec_absent:[] ~enc:(fun t -> t.rooms) 68 + |> opt_member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 69 + |> seal) 70 70 71 71 (** Get the hierarchy of a space. 72 72 ··· 111 111 } 112 112 113 113 let set_state_response_jsont = 114 - Jsont.Object.( 114 + Json.Codec.Object.( 115 115 map (fun event_id -> { event_id }) 116 - |> mem "event_id" Matrix_proto.Id.Event_id.jsont 117 - |> finish) 116 + |> member "event_id" Matrix_proto.Id.Event_id.jsont 117 + |> seal) 118 118 119 119 let add_child client ~space_id ~child_id ?(via = []) ?order ?(suggested = false) () = 120 120 let space_id_str = Matrix_proto.Id.Room_id.to_string space_id in
+21 -24
lib/matrix_client/state.ml
··· 6 6 let path = Printf.sprintf "/rooms/%s/state" (Uri.pct_encode room_id_str) in 7 7 match Client.get client ~path () with 8 8 | Error e -> Error e 9 - | Ok body -> Client.decode_response (Jsont.list Matrix_proto.Event.Raw_event.jsont) body 9 + | Ok body -> Client.decode_response (Json.Codec.list Matrix_proto.Event.Raw_event.jsont) body 10 10 11 11 (* Get specific state event *) 12 12 let get_state_event client ~room_id ~event_type ?(state_key = "") () = ··· 18 18 in 19 19 match Client.get client ~path () with 20 20 | Error e -> Error e 21 - | Ok body -> Client.decode_response Jsont.json body 21 + | Ok body -> Client.decode_response Json.Codec.Value.t body 22 22 23 23 (* Set state event *) 24 24 type set_state_response = { ··· 26 26 } 27 27 28 28 let set_state_response_jsont = 29 - Jsont.Object.( 29 + Json.Codec.Object.( 30 30 map (fun event_id -> { event_id }) 31 - |> mem "event_id" Matrix_proto.Id.Event_id.jsont 32 - |> finish) 31 + |> member "event_id" Matrix_proto.Id.Event_id.jsont 32 + |> seal) 33 33 34 34 let set_state client ~room_id ~event_type ?(state_key = "") ~content () = 35 35 let room_id_str = Matrix_proto.Id.Room_id.to_string room_id in ··· 38 38 (Uri.pct_encode event_type) 39 39 (Uri.pct_encode state_key) 40 40 in 41 - match Client.encode_body Jsont.json content with 41 + match Client.encode_body Json.Codec.Value.t content with 42 42 | Error e -> Error e 43 43 | Ok body -> 44 44 match Client.put client ~path ~body () with ··· 54 54 } [@@warning "-69"] 55 55 56 56 let name_content_jsont = 57 - Jsont.Object.( 57 + Json.Codec.Object.( 58 58 map (fun name -> { name }) 59 - |> mem "name" Jsont.string 60 - |> finish) 59 + |> member "name" Json.Codec.string 60 + |> seal) 61 61 62 62 let get_name client ~room_id = 63 63 match get_state_event client ~room_id ~event_type:"m.room.name" () with 64 64 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok None 65 65 | Error e -> Error e 66 66 | Ok json -> 67 - match Jsont_bytesrw.decode_string name_content_jsont 68 - (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with 67 + match (Json.of_string name_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with 69 68 | Ok c -> Ok (Some c.name) 70 69 | Error _ -> Ok None 71 70 ··· 74 73 match Client.encode_body name_content_jsont content with 75 74 | Error e -> Error e 76 75 | Ok body -> 77 - match Client.decode_response Jsont.json body with 76 + match Client.decode_response Json.Codec.Value.t body with 78 77 | Error e -> Error e 79 78 | Ok json -> set_state client ~room_id ~event_type:"m.room.name" ~content:json () 80 79 ··· 84 83 } [@@warning "-69"] 85 84 86 85 let topic_content_jsont = 87 - Jsont.Object.( 86 + Json.Codec.Object.( 88 87 map (fun topic -> { topic }) 89 - |> mem "topic" Jsont.string 90 - |> finish) 88 + |> member "topic" Json.Codec.string 89 + |> seal) 91 90 92 91 let get_topic client ~room_id = 93 92 match get_state_event client ~room_id ~event_type:"m.room.topic" () with 94 93 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok None 95 94 | Error e -> Error e 96 95 | Ok json -> 97 - match Jsont_bytesrw.decode_string topic_content_jsont 98 - (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with 96 + match (Json.of_string topic_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with 99 97 | Ok c -> Ok (Some c.topic) 100 98 | Error _ -> Ok None 101 99 ··· 104 102 match Client.encode_body topic_content_jsont content with 105 103 | Error e -> Error e 106 104 | Ok body -> 107 - match Client.decode_response Jsont.json body with 105 + match Client.decode_response Json.Codec.Value.t body with 108 106 | Error e -> Error e 109 107 | Ok json -> set_state client ~room_id ~event_type:"m.room.topic" ~content:json () 110 108 ··· 114 112 } [@@warning "-69"] 115 113 116 114 let avatar_content_jsont = 117 - Jsont.Object.( 115 + Json.Codec.Object.( 118 116 map (fun url -> { url }) 119 - |> mem "url" Jsont.string 120 - |> finish) 117 + |> member "url" Json.Codec.string 118 + |> seal) 121 119 122 120 let get_avatar client ~room_id = 123 121 match get_state_event client ~room_id ~event_type:"m.room.avatar" () with 124 122 | Error (Error.Matrix_error { errcode = Error.M_NOT_FOUND; _ }) -> Ok None 125 123 | Error e -> Error e 126 124 | Ok json -> 127 - match Jsont_bytesrw.decode_string avatar_content_jsont 128 - (Result.get_ok (Jsont_bytesrw.encode_string Jsont.json json)) with 125 + match (Json.of_string avatar_content_jsont (Result.get_ok ((try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)))) |> Result.map_error Json.Error.to_string) with 129 126 | Ok c -> Ok (Some c.url) 130 127 | Error _ -> Ok None 131 128 ··· 134 131 match Client.encode_body avatar_content_jsont content with 135 132 | Error e -> Error e 136 133 | Ok body -> 137 - match Client.decode_response Jsont.json body with 134 + match Client.decode_response Json.Codec.Value.t body with 138 135 | Error e -> Error e 139 136 | Ok json -> set_state client ~room_id ~event_type:"m.room.avatar" ~content:json ()
+2 -2
lib/matrix_client/state.mli
··· 15 15 event_type:string -> 16 16 ?state_key:string -> 17 17 unit -> 18 - (Jsont.json, Error.t) result 18 + (Json.t, Error.t) result 19 19 20 20 (** Set a state event. 21 21 ··· 25 25 room_id:Matrix_proto.Id.Room_id.t -> 26 26 event_type:string -> 27 27 ?state_key:string -> 28 - content:Jsont.json -> 28 + content:Json.t -> 29 29 unit -> 30 30 (Matrix_proto.Id.Event_id.t, Error.t) result 31 31
+25 -25
lib/matrix_client/store.ml
··· 16 16 (** Types of data that can be stored in the state store's KV section *) 17 17 type kv_data = 18 18 | Sync_token of string 19 - | Filter of { filter_id : string; filter : Jsont.json } 19 + | Filter of { filter_id : string; filter : Json.t } 20 20 | User_avatar_url of { user_id : Matrix_proto.Id.User_id.t; url : string option } 21 21 | Recently_visited_rooms of Matrix_proto.Id.Room_id.t list 22 22 | Composer_draft of { ··· 31 31 (** Aggregated state changes from a sync response *) 32 32 type state_changes = { 33 33 sync_token : string option; 34 - account_data : (string * Jsont.json) list; (* event_type -> content *) 35 - presence : (string * Jsont.json) list; (* user_id -> presence event *) 34 + account_data : (string * Json.t) list; (* event_type -> content *) 35 + presence : (string * Json.t) list; (* user_id -> presence event *) 36 36 room_infos : (string * room_info) list; (* room_id -> room info *) 37 - room_state : (string * (string * (string * Jsont.json) list) list) list; 37 + room_state : (string * (string * (string * Json.t) list) list) list; 38 38 (* room_id -> event_type -> state_key -> event *) 39 - room_account_data : (string * (string * Jsont.json) list) list; 39 + room_account_data : (string * (string * Json.t) list) list; 40 40 (* room_id -> event_type -> content *) 41 - stripped_state : (string * (string * (string * Jsont.json) list) list) list; 41 + stripped_state : (string * (string * (string * Json.t) list) list) list; 42 42 (* For invited rooms *) 43 - receipts : (string * Jsont.json) list; (* room_id -> receipt content *) 43 + receipts : (string * Json.t) list; (* room_id -> receipt content *) 44 44 profiles : (string * (string * member_profile) list) list; 45 45 (* room_id -> user_id -> profile *) 46 46 } ··· 106 106 room_id:Matrix_proto.Id.Room_id.t -> 107 107 event_type:string -> 108 108 state_key:string -> 109 - Jsont.json option 109 + Json.t option 110 110 111 111 (** Get all state events of a type for a room *) 112 112 val get_state_events : 113 113 t -> 114 114 room_id:Matrix_proto.Id.Room_id.t -> 115 115 event_type:string -> 116 - (string * Jsont.json) list (* state_key -> event *) 116 + (string * Json.t) list (* state_key -> event *) 117 117 118 118 (** Get room info *) 119 119 val get_room_info : t -> Matrix_proto.Id.Room_id.t -> room_info option ··· 132 132 133 133 (** {2 Account Data} *) 134 134 135 - val get_account_data : t -> event_type:string -> Jsont.json option 135 + val get_account_data : t -> event_type:string -> Json.t option 136 136 val get_room_account_data : 137 - t -> room_id:Matrix_proto.Id.Room_id.t -> event_type:string -> Jsont.json option 137 + t -> room_id:Matrix_proto.Id.Room_id.t -> event_type:string -> Json.t option 138 138 139 139 (** {2 Receipts} *) 140 140 141 - val get_receipts : t -> room_id:Matrix_proto.Id.Room_id.t -> Jsont.json option 141 + val get_receipts : t -> room_id:Matrix_proto.Id.Room_id.t -> Json.t option 142 142 143 143 (** {2 Presence} *) 144 144 145 - val get_presence : t -> user_id:Matrix_proto.Id.User_id.t -> Jsont.json option 145 + val get_presence : t -> user_id:Matrix_proto.Id.User_id.t -> Json.t option 146 146 147 147 (** {2 Key-Value Store} *) 148 148 ··· 164 164 algorithms : string list; 165 165 keys : (string * string) list; (* key_id -> key *) 166 166 signatures : (string * (string * string) list) list; (* user_id -> key_id -> sig *) 167 - unsigned : Jsont.json option; 167 + unsigned : Json.t option; 168 168 } 169 169 170 170 (** Cross-signing identity keys *) ··· 353 353 sender : Matrix_proto.Id.User_id.t; 354 354 origin_server_ts : int64; 355 355 event_type : string; 356 - content : Jsont.json; 357 - unsigned : Jsont.json option; 356 + content : Json.t; 357 + unsigned : Json.t option; 358 358 } 359 359 360 360 (** Gap in event history (for pagination) *) ··· 446 446 447 447 type t = { 448 448 mutable sync_token : string option; 449 - account_data : (string, Jsont.json) Hashtbl.t; 450 - presence : (string, Jsont.json) Hashtbl.t; 449 + account_data : (string, Json.t) Hashtbl.t; 450 + presence : (string, Json.t) Hashtbl.t; 451 451 room_infos : (string, room_info) Hashtbl.t; 452 - room_state : (string, (string, (string, Jsont.json) Hashtbl.t) Hashtbl.t) Hashtbl.t; 453 - room_account_data : (string, (string, Jsont.json) Hashtbl.t) Hashtbl.t; 454 - receipts : (string, Jsont.json) Hashtbl.t; 452 + room_state : (string, (string, (string, Json.t) Hashtbl.t) Hashtbl.t) Hashtbl.t; 453 + room_account_data : (string, (string, Json.t) Hashtbl.t) Hashtbl.t; 454 + receipts : (string, Json.t) Hashtbl.t; 455 455 profiles : (string, (string, member_profile) Hashtbl.t) Hashtbl.t; 456 456 kv_store : (string, kv_data) Hashtbl.t; 457 457 } ··· 930 930 List.filter (fun event -> 931 931 (* Check if event has m.relates_to pointing to target *) 932 932 match event.content with 933 - | Jsont.Object (fields, _) -> 933 + | Json.Object (fields, _) -> 934 934 let has_relation = 935 935 List.exists (fun ((name, _), value) -> 936 936 name = "m.relates_to" && 937 937 match value with 938 - | Jsont.Object (rel_fields, _) -> 938 + | Json.Object (rel_fields, _) -> 939 939 List.exists (fun ((n, _), v) -> 940 940 n = "event_id" && 941 941 match v with 942 - | Jsont.String (s, _) -> s = target_id 942 + | Json.String (s, _) -> s = target_id 943 943 | _ -> false 944 944 ) rel_fields && 945 945 (match rel_type with ··· 948 948 List.exists (fun ((n, _), v) -> 949 949 n = "rel_type" && 950 950 match v with 951 - | Jsont.String (s, _) -> s = rt 951 + | Json.String (s, _) -> s = rt 952 952 | _ -> false 953 953 ) rel_fields) 954 954 | _ -> false
+16 -16
lib/matrix_client/store.mli
··· 16 16 (** Types of data that can be stored in the state store's KV section. *) 17 17 type kv_data = 18 18 | Sync_token of string 19 - | Filter of { filter_id : string; filter : Jsont.json } 19 + | Filter of { filter_id : string; filter : Json.t } 20 20 | User_avatar_url of { user_id : Matrix_proto.Id.User_id.t; url : string option } 21 21 | Recently_visited_rooms of Matrix_proto.Id.Room_id.t list 22 22 | Composer_draft of { ··· 54 54 (** Aggregated state changes from a sync response. *) 55 55 type state_changes = { 56 56 sync_token : string option; 57 - account_data : (string * Jsont.json) list; 58 - presence : (string * Jsont.json) list; 57 + account_data : (string * Json.t) list; 58 + presence : (string * Json.t) list; 59 59 room_infos : (string * room_info) list; 60 - room_state : (string * (string * (string * Jsont.json) list) list) list; 61 - room_account_data : (string * (string * Jsont.json) list) list; 62 - stripped_state : (string * (string * (string * Jsont.json) list) list) list; 63 - receipts : (string * Jsont.json) list; 60 + room_state : (string * (string * (string * Json.t) list) list) list; 61 + room_account_data : (string * (string * Json.t) list) list; 62 + stripped_state : (string * (string * (string * Json.t) list) list) list; 63 + receipts : (string * Json.t) list; 64 64 profiles : (string * (string * member_profile) list) list; 65 65 } 66 66 ··· 100 100 room_id:Matrix_proto.Id.Room_id.t -> 101 101 event_type:string -> 102 102 state_key:string -> 103 - Jsont.json option 103 + Json.t option 104 104 (** Get a specific state event. *) 105 105 106 106 val get_state_events : 107 107 t -> 108 108 room_id:Matrix_proto.Id.Room_id.t -> 109 109 event_type:string -> 110 - (string * Jsont.json) list 110 + (string * Json.t) list 111 111 (** Get all state events of a type for a room. Returns state_key -> event pairs. *) 112 112 113 113 val get_room_info : t -> Matrix_proto.Id.Room_id.t -> room_info option ··· 127 127 128 128 (** {2 Account Data} *) 129 129 130 - val get_account_data : t -> event_type:string -> Jsont.json option 130 + val get_account_data : t -> event_type:string -> Json.t option 131 131 (** Get global account data. *) 132 132 133 133 val get_room_account_data : 134 - t -> room_id:Matrix_proto.Id.Room_id.t -> event_type:string -> Jsont.json option 134 + t -> room_id:Matrix_proto.Id.Room_id.t -> event_type:string -> Json.t option 135 135 (** Get room-specific account data. *) 136 136 137 137 (** {2 Receipts} *) 138 138 139 - val get_receipts : t -> room_id:Matrix_proto.Id.Room_id.t -> Jsont.json option 139 + val get_receipts : t -> room_id:Matrix_proto.Id.Room_id.t -> Json.t option 140 140 (** Get receipt data for a room. *) 141 141 142 142 (** {2 Presence} *) 143 143 144 - val get_presence : t -> user_id:Matrix_proto.Id.User_id.t -> Jsont.json option 144 + val get_presence : t -> user_id:Matrix_proto.Id.User_id.t -> Json.t option 145 145 (** Get presence for a user. *) 146 146 147 147 (** {2 Key-Value Store} *) ··· 170 170 algorithms : string list; 171 171 keys : (string * string) list; 172 172 signatures : (string * (string * string) list) list; 173 - unsigned : Jsont.json option; 173 + unsigned : Json.t option; 174 174 } 175 175 176 176 (** Cross-signing identity keys. *) ··· 361 361 sender : Matrix_proto.Id.User_id.t; 362 362 origin_server_ts : int64; 363 363 event_type : string; 364 - content : Jsont.json; 365 - unsigned : Jsont.json option; 364 + content : Json.t; 365 + unsigned : Json.t option; 366 366 } 367 367 368 368 (** Gap in event history (for pagination). *)
+44 -44
lib/matrix_client/sync.ml
··· 147 147 } 148 148 149 149 (* Filter JSON codecs *) 150 - let event_filter_jsont : event_filter Jsont.t = 151 - let open Jsont.Object in 150 + let event_filter_jsont : event_filter Json.codec = 151 + let open Json.Codec.Object in 152 152 map (fun limit not_senders not_types senders types -> 153 153 ({ limit; not_senders; not_types; senders; types } : event_filter)) 154 - |> opt_mem "limit" Jsont.int ~enc:(fun (t : event_filter) -> t.limit) 155 - |> mem "not_senders" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.not_senders) 156 - |> mem "not_types" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.not_types) 157 - |> mem "senders" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.senders) 158 - |> mem "types" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.types) 159 - |> finish 154 + |> opt_member "limit" Json.Codec.int ~enc:(fun (t : event_filter) -> t.limit) 155 + |> member "not_senders" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.not_senders) 156 + |> member "not_types" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.not_types) 157 + |> member "senders" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.senders) 158 + |> member "types" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : event_filter) -> t.types) 159 + |> seal 160 160 161 - let room_event_filter_jsont : room_event_filter Jsont.t = 162 - let open Jsont.Object in 161 + let room_event_filter_jsont : room_event_filter Json.codec = 162 + let open Json.Codec.Object in 163 163 map (fun limit not_senders not_types senders types lazy_load_members 164 164 include_redundant_members not_rooms rooms contains_url -> 165 165 ({ limit; not_senders; not_types; senders; types; lazy_load_members; 166 166 include_redundant_members; not_rooms; rooms; contains_url } : room_event_filter)) 167 - |> opt_mem "limit" Jsont.int ~enc:(fun (t : room_event_filter) -> t.limit) 168 - |> mem "not_senders" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.not_senders) 169 - |> mem "not_types" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.not_types) 170 - |> mem "senders" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.senders) 171 - |> mem "types" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.types) 172 - |> mem "lazy_load_members" Jsont.bool ~dec_absent:false ~enc:(fun (t : room_event_filter) -> t.lazy_load_members) 173 - |> mem "include_redundant_members" Jsont.bool ~dec_absent:false ~enc:(fun (t : room_event_filter) -> t.include_redundant_members) 174 - |> mem "not_rooms" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.not_rooms) 175 - |> mem "rooms" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.rooms) 176 - |> opt_mem "contains_url" Jsont.bool ~enc:(fun (t : room_event_filter) -> t.contains_url) 177 - |> finish 167 + |> opt_member "limit" Json.Codec.int ~enc:(fun (t : room_event_filter) -> t.limit) 168 + |> member "not_senders" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.not_senders) 169 + |> member "not_types" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.not_types) 170 + |> member "senders" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.senders) 171 + |> member "types" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.types) 172 + |> member "lazy_load_members" Json.Codec.bool ~dec_absent:false ~enc:(fun (t : room_event_filter) -> t.lazy_load_members) 173 + |> member "include_redundant_members" Json.Codec.bool ~dec_absent:false ~enc:(fun (t : room_event_filter) -> t.include_redundant_members) 174 + |> member "not_rooms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.not_rooms) 175 + |> member "rooms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_event_filter) -> t.rooms) 176 + |> opt_member "contains_url" Json.Codec.bool ~enc:(fun (t : room_event_filter) -> t.contains_url) 177 + |> seal 178 178 179 - let room_filter_jsont : room_filter Jsont.t = 180 - let open Jsont.Object in 179 + let room_filter_jsont : room_filter Json.codec = 180 + let open Json.Codec.Object in 181 181 map (fun not_rooms rooms ephemeral include_leave state timeline account_data -> 182 182 ({ not_rooms; rooms; ephemeral; include_leave; state; timeline; account_data } : room_filter)) 183 - |> mem "not_rooms" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_filter) -> t.not_rooms) 184 - |> mem "rooms" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : room_filter) -> t.rooms) 185 - |> opt_mem "ephemeral" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.ephemeral) 186 - |> mem "include_leave" Jsont.bool ~dec_absent:false ~enc:(fun (t : room_filter) -> t.include_leave) 187 - |> opt_mem "state" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.state) 188 - |> opt_mem "timeline" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.timeline) 189 - |> opt_mem "account_data" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.account_data) 190 - |> finish 183 + |> member "not_rooms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_filter) -> t.not_rooms) 184 + |> member "rooms" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : room_filter) -> t.rooms) 185 + |> opt_member "ephemeral" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.ephemeral) 186 + |> member "include_leave" Json.Codec.bool ~dec_absent:false ~enc:(fun (t : room_filter) -> t.include_leave) 187 + |> opt_member "state" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.state) 188 + |> opt_member "timeline" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.timeline) 189 + |> opt_member "account_data" room_event_filter_jsont ~enc:(fun (t : room_filter) -> t.account_data) 190 + |> seal 191 191 192 - let event_format_jsont : [ `Client | `Federation ] Jsont.t = 193 - Jsont.of_of_string ~kind:"event_format" 192 + let event_format_jsont : [ `Client | `Federation ] Json.codec = 193 + Json.Codec.of_of_string ~kind:"event_format" 194 194 ~enc:(function `Client -> "client" | `Federation -> "federation") 195 195 (function 196 196 | "client" -> Ok `Client 197 197 | "federation" -> Ok `Federation 198 198 | s -> Error ("Unknown event_format: " ^ s)) 199 199 200 - let filter_jsont : filter Jsont.t = 201 - let open Jsont.Object in 200 + let filter_jsont : filter Json.codec = 201 + let open Json.Codec.Object in 202 202 map (fun event_fields event_format presence account_data room -> 203 203 ({ event_fields; event_format; presence; account_data; room } : filter)) 204 - |> mem "event_fields" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun (t : filter) -> t.event_fields) 205 - |> mem "event_format" event_format_jsont ~dec_absent:`Client ~enc:(fun (t : filter) -> t.event_format) 206 - |> opt_mem "presence" event_filter_jsont ~enc:(fun (t : filter) -> t.presence) 207 - |> opt_mem "account_data" event_filter_jsont ~enc:(fun (t : filter) -> t.account_data) 208 - |> opt_mem "room" room_filter_jsont ~enc:(fun (t : filter) -> t.room) 209 - |> finish 204 + |> member "event_fields" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun (t : filter) -> t.event_fields) 205 + |> member "event_format" event_format_jsont ~dec_absent:`Client ~enc:(fun (t : filter) -> t.event_format) 206 + |> opt_member "presence" event_filter_jsont ~enc:(fun (t : filter) -> t.presence) 207 + |> opt_member "account_data" event_filter_jsont ~enc:(fun (t : filter) -> t.account_data) 208 + |> opt_member "room" room_filter_jsont ~enc:(fun (t : filter) -> t.room) 209 + |> seal 210 210 211 211 (* Filter API *) 212 212 type filter_response = { ··· 214 214 } [@@warning "-69"] 215 215 216 216 let filter_response_jsont = 217 - Jsont.Object.( 217 + Json.Codec.Object.( 218 218 map (fun filter_id -> { filter_id }) 219 - |> mem "filter_id" Jsont.string 220 - |> finish) 219 + |> member "filter_id" Json.Codec.string 220 + |> seal) 221 221 222 222 let create_filter client ~filter = 223 223 match Client.user_id client with
+4 -4
lib/matrix_client/timeline.ml
··· 143 143 144 144 (** Timeline event wrapper with metadata *) 145 145 type event_item = { 146 - event : Jsont.json; (* Raw event JSON *) 146 + event : Json.t; (* Raw event JSON *) 147 147 event_id : Matrix_proto.Id.Event_id.t; 148 148 sender : Matrix_proto.Id.User_id.t; 149 149 origin_server_ts : int64; ··· 157 157 type state_entry = { 158 158 event_type : string; 159 159 state_key : string; 160 - content : Jsont.json; 160 + content : Json.t; 161 161 sender : Matrix_proto.Id.User_id.t; 162 162 event_id : Matrix_proto.Id.Event_id.t option; 163 163 } ··· 243 243 (** Helper to get a string field from JSON object *) 244 244 let get_json_string_field content field = 245 245 match content with 246 - | Jsont.Object (fields, _meta) -> 246 + | Json.Object (fields, _meta) -> 247 247 (* name is (string * Meta.t) and mem is (name * json) *) 248 248 let find_field name = 249 249 List.find_opt (fun ((n, _meta), _v) -> String.equal n name) fields 250 250 in 251 251 (match find_field field with 252 - | Some (_, Jsont.String (s, _)) -> Some s 252 + | Some (_, Json.String (s, _)) -> Some s 253 253 | _ -> None) 254 254 | _ -> None 255 255
+6 -6
lib/matrix_client/timeline.mli
··· 63 63 64 64 (** Timeline event wrapper with metadata. *) 65 65 type event_item = { 66 - event : Jsont.json; 66 + event : Json.t; 67 67 event_id : Matrix_proto.Id.Event_id.t; 68 68 sender : Matrix_proto.Id.User_id.t; 69 69 origin_server_ts : int64; ··· 76 76 type state_entry = { 77 77 event_type : string; 78 78 state_key : string; 79 - content : Jsont.json; 79 + content : Json.t; 80 80 sender : Matrix_proto.Id.User_id.t; 81 81 event_id : Matrix_proto.Id.Event_id.t option; 82 82 } ··· 116 116 117 117 val add_event : 118 118 t -> 119 - event:Jsont.json -> 119 + event:Json.t -> 120 120 event_id:Matrix_proto.Id.Event_id.t -> 121 121 sender:Matrix_proto.Id.User_id.t -> 122 122 origin_server_ts:int64 -> ··· 129 129 130 130 val add_events_back : 131 131 t -> 132 - (Jsont.json * Matrix_proto.Id.Event_id.t * Matrix_proto.Id.User_id.t * int64 * string * bool) list -> 132 + (Json.t * Matrix_proto.Id.Event_id.t * Matrix_proto.Id.User_id.t * int64 * string * bool) list -> 133 133 unit 134 134 (** Add events from back-pagination (older events). *) 135 135 ··· 148 148 t -> 149 149 event_type:string -> 150 150 state_key:string -> 151 - content:Jsont.json -> 151 + content:Json.t -> 152 152 sender:Matrix_proto.Id.User_id.t -> 153 153 ?event_id:Matrix_proto.Id.Event_id.t -> 154 154 unit -> ··· 229 229 Client.t -> 230 230 t -> 231 231 limit:int -> 232 - ((Jsont.json * Matrix_proto.Id.Event_id.t * Matrix_proto.Id.User_id.t * int64 * string * bool) list, Error.t) result 232 + ((Json.t * Matrix_proto.Id.Event_id.t * Matrix_proto.Id.User_id.t * int64 * string * bool) list, Error.t) result 233 233 (** Fetch older messages via back-pagination. *)
+4 -4
lib/matrix_client/typing.ml
··· 6 6 } [@@warning "-69"] 7 7 8 8 let typing_request_jsont = 9 - Jsont.Object.( 9 + Json.Codec.Object.( 10 10 map (fun typing timeout -> { typing; timeout }) 11 - |> mem "typing" Jsont.bool 12 - |> opt_mem "timeout" Jsont.int ~enc:(fun t -> t.timeout) 13 - |> finish) 11 + |> member "typing" Json.Codec.bool 12 + |> opt_member "timeout" Json.Codec.int ~enc:(fun t -> t.timeout) 13 + |> seal) 14 14 15 15 let set_typing client ~room_id ~typing ?timeout () = 16 16 match Client.user_id client with
+20 -20
lib/matrix_client/uiaa.ml
··· 62 62 63 63 let auth_flow_jsont = 64 64 let json_type = 65 - Jsont.Object.( 65 + Json.Codec.Object.( 66 66 map (fun stages_json -> { stages_json }) 67 - |> mem "stages" (Jsont.list Jsont.string) ~dec_absent:[] 67 + |> member "stages" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 68 68 ~enc:(fun t -> t.stages_json) 69 - |> finish) 69 + |> seal) 70 70 in 71 - Jsont.map 71 + Json.Codec.map 72 72 ~dec:(fun flow -> { stages = List.map auth_type_of_string flow.stages_json }) 73 73 ~enc:(fun flow -> { stages_json = List.map auth_type_to_string flow.stages }) 74 74 json_type ··· 78 78 session : string option; 79 79 flows : auth_flow list; 80 80 completed : auth_type list; 81 - params : Jsont.json option; 81 + params : Json.t option; 82 82 error : string option; 83 83 errcode : string option; 84 84 } ··· 88 88 session_json : string option; 89 89 flows_json : auth_flow list; 90 90 completed_json : string list; 91 - params_json : Jsont.json option; 91 + params_json : Json.t option; 92 92 error_json : string option; 93 93 errcode_json : string option; 94 94 } 95 95 96 96 let uiaa_response_jsont = 97 97 let json_type = 98 - Jsont.Object.( 98 + Json.Codec.Object.( 99 99 map (fun session_json flows_json completed_json params_json error_json errcode_json -> 100 100 { session_json; flows_json; completed_json; params_json; error_json; errcode_json }) 101 - |> opt_mem "session" Jsont.string ~enc:(fun t -> t.session_json) 102 - |> mem "flows" (Jsont.list auth_flow_jsont) ~dec_absent:[] ~enc:(fun t -> t.flows_json) 103 - |> mem "completed" (Jsont.list Jsont.string) ~dec_absent:[] 101 + |> opt_member "session" Json.Codec.string ~enc:(fun t -> t.session_json) 102 + |> member "flows" (Json.Codec.list auth_flow_jsont) ~dec_absent:[] ~enc:(fun t -> t.flows_json) 103 + |> member "completed" (Json.Codec.list Json.Codec.string) ~dec_absent:[] 104 104 ~enc:(fun t -> t.completed_json) 105 - |> opt_mem "params" Jsont.json ~enc:(fun t -> t.params_json) 106 - |> opt_mem "error" Jsont.string ~enc:(fun t -> t.error_json) 107 - |> opt_mem "errcode" Jsont.string ~enc:(fun t -> t.errcode_json) 108 - |> finish) 105 + |> opt_member "params" Json.Codec.Value.t ~enc:(fun t -> t.params_json) 106 + |> opt_member "error" Json.Codec.string ~enc:(fun t -> t.error_json) 107 + |> opt_member "errcode" Json.Codec.string ~enc:(fun t -> t.errcode_json) 108 + |> seal) 109 109 in 110 - Jsont.map 110 + Json.Codec.map 111 111 ~dec:(fun r -> { 112 112 session = r.session_json; 113 113 flows = r.flows_json; ··· 263 263 264 264 (** Parse a UIAA response from error body *) 265 265 let parse_uiaa_response body = 266 - match Jsont_bytesrw.decode_string uiaa_response_jsont body with 266 + match (Json.of_string uiaa_response_jsont body |> Result.map_error Json.Error.to_string) with 267 267 | Ok r -> Some r 268 268 | Error _ -> None 269 269 ··· 387 387 } 388 388 389 389 let request_token_response_jsont = 390 - Jsont.Object.( 390 + Json.Codec.Object.( 391 391 map (fun sid submit_url -> { sid; submit_url }) 392 - |> mem "sid" Jsont.string ~enc:(fun t -> t.sid) 393 - |> opt_mem "submit_url" Jsont.string ~enc:(fun t -> t.submit_url) 394 - |> finish) 392 + |> member "sid" Json.Codec.string ~enc:(fun t -> t.sid) 393 + |> opt_member "submit_url" Json.Codec.string ~enc:(fun t -> t.submit_url) 394 + |> seal) 395 395 396 396 (** Request a token for email validation *) 397 397 let request_email_token client ~email ~client_secret ~send_attempt ?next_link () =
+4 -4
lib/matrix_client/uiaa.mli
··· 41 41 stages : auth_type list; 42 42 } 43 43 44 - val auth_flow_jsont : auth_flow Jsont.t 44 + val auth_flow_jsont : auth_flow Json.codec 45 45 (** JSON codec for auth flow. *) 46 46 47 47 (** {1 UIAA Response} *) ··· 51 51 session : string option; 52 52 flows : auth_flow list; 53 53 completed : auth_type list; 54 - params : Jsont.json option; 54 + params : Json.t option; 55 55 error : string option; 56 56 errcode : string option; 57 57 } 58 58 59 - val uiaa_response_jsont : uiaa_response Jsont.t 59 + val uiaa_response_jsont : uiaa_response Json.codec 60 60 (** JSON codec for UIAA response. *) 61 61 62 62 (** {1 User Identifiers} *) ··· 203 203 submit_url : string option; 204 204 } 205 205 206 - val request_token_response_jsont : request_token_response Jsont.t 206 + val request_token_response_jsont : request_token_response Json.codec 207 207 (** JSON codec for token response. *) 208 208 209 209 val request_email_token :
+5 -5
lib/matrix_client/verification.ml
··· 6 6 - User identity verification 7 7 - SAS (Short Authentication String) verification protocol *) 8 8 9 - open Mirage_crypto_ec 9 + open Crypto_ec 10 10 11 11 (** {1 Trust States} *) 12 12 ··· 166 166 (** Canonicalize JSON for signing (simplified) *) 167 167 let canonicalize_json json = 168 168 (* Simplified canonicalization - remove signatures and unsigned *) 169 - Jsont_bytesrw.encode_string Jsont.json json 169 + (try Ok (Json.to_string Json.Codec.Value.t json) with Json.Error e -> Error (Json.Error.to_string e)) 170 170 |> Result.value ~default:"" 171 171 172 172 (** Verify that a cross-signing key is signed by another key *) ··· 320 320 321 321 (** Generate a random flow ID *) 322 322 let generate_flow_id () = 323 - let random_bytes = Mirage_crypto_rng.generate 16 in 323 + let random_bytes = Crypto_rng.generate 16 in 324 324 Base64.encode_string ~pad:false random_bytes 325 325 326 326 (** Create a new SAS verification session *) ··· 450 450 (** Create QR verification for self-verification *) 451 451 let create_self_qr_verification ~our_user_id ~our_master_key ~mode = 452 452 let flow_id = generate_flow_id () in 453 - let secret = Mirage_crypto_rng.generate 32 |> Base64.encode_string in 453 + let secret = Crypto_rng.generate 32 |> Base64.encode_string in 454 454 { 455 455 flow_id; 456 456 state = Qr_started; ··· 465 465 (** Create QR verification for verifying another user *) 466 466 let create_user_qr_verification ~our_user_id ~their_user_id ~our_master_key ~their_master_key = 467 467 let flow_id = generate_flow_id () in 468 - let secret = Mirage_crypto_rng.generate 32 |> Base64.encode_string in 468 + let secret = Crypto_rng.generate 32 |> Base64.encode_string in 469 469 { 470 470 flow_id; 471 471 state = Qr_started;
+1 -1
lib/matrix_client/verification.mli
··· 116 116 bool 117 117 (** Verify an Ed25519 signature. *) 118 118 119 - val canonicalize_json : Jsont.json -> string 119 + val canonicalize_json : Json.t -> string 120 120 (** Canonicalize JSON for signing. *) 121 121 122 122 val verify_cross_signing_signature :
+1 -1
lib/matrix_eio/send_queue.ml
··· 7 7 type request_kind = Matrix_client.Send_queue.request_kind = 8 8 | Event of { 9 9 event_type : string; 10 - content : Jsont.json; 10 + content : Json.t; 11 11 txn_id : string; 12 12 } 13 13 | MediaUpload of {
+1 -1
lib/matrix_proto/dune
··· 1 1 (library 2 2 (name matrix_proto) 3 3 (public_name matrix.proto) 4 - (libraries jsont ptime)) 4 + (libraries nox-json ptime))
+364 -364
lib/matrix_proto/matrix_event.ml
··· 52 52 53 53 let pp ppf t = Format.fprintf ppf "%Ld" t 54 54 55 - let jsont = Jsont.int64 55 + let jsont = Json.Codec.int64 56 56 end 57 57 58 58 (** {1 Unsigned Event Data} *) ··· 66 66 67 67 type t = { 68 68 age : int64 option; 69 - prev_content : Jsont.json option; 69 + prev_content : Json.t option; 70 70 prev_sender : User_id.t option; 71 - redacted_because : Jsont.json option; 71 + redacted_because : Json.t option; 72 72 transaction_id : Transaction_id.t option; 73 73 } 74 74 ··· 94 94 Format.fprintf ppf "@]" 95 95 96 96 let jsont = 97 - Jsont.Object.( 97 + Json.Codec.Object.( 98 98 map (fun age prev_content prev_sender redacted_because transaction_id -> 99 99 { age; prev_content; prev_sender; redacted_because; transaction_id }) 100 - |> opt_mem "age" Jsont.int64 ~enc:(fun t -> t.age) 101 - |> opt_mem "prev_content" Jsont.json ~enc:(fun t -> t.prev_content) 102 - |> opt_mem "prev_sender" User_id.jsont ~enc:(fun t -> t.prev_sender) 103 - |> opt_mem "redacted_because" Jsont.json ~enc:(fun t -> t.redacted_because) 104 - |> opt_mem "transaction_id" Transaction_id.jsont ~enc:(fun t -> t.transaction_id) 105 - |> finish) 100 + |> opt_member "age" Json.Codec.int64 ~enc:(fun t -> t.age) 101 + |> opt_member "prev_content" Json.Codec.Value.t ~enc:(fun t -> t.prev_content) 102 + |> opt_member "prev_sender" User_id.jsont ~enc:(fun t -> t.prev_sender) 103 + |> opt_member "redacted_because" Json.Codec.Value.t ~enc:(fun t -> t.redacted_because) 104 + |> opt_member "transaction_id" Transaction_id.jsont ~enc:(fun t -> t.transaction_id) 105 + |> seal) 106 106 end 107 107 108 108 (** {1 Room Membership} *) ··· 137 137 let pp ppf t = Format.pp_print_string ppf (to_string t) 138 138 139 139 let jsont = 140 - Jsont.enum [ 140 + Json.Codec.enum [ 141 141 ("join", Join); 142 142 ("invite", Invite); 143 143 ("leave", Leave); ··· 172 172 let pp ppf t = Format.pp_print_string ppf (to_string t) 173 173 174 174 let jsont = 175 - Jsont.enum [ 175 + Json.Codec.enum [ 176 176 ("public", Public); 177 177 ("invite", Invite); 178 178 ("knock", Knock); ··· 204 204 let pp ppf t = Format.pp_print_string ppf (to_string t) 205 205 206 206 let jsont = 207 - Jsont.enum [ 207 + Json.Codec.enum [ 208 208 ("invited", Invited); 209 209 ("joined", Joined); 210 210 ("shared", Shared); ··· 236 236 Room_id.pp t.room_id Event_id.pp t.event_id 237 237 238 238 let jsont = 239 - Jsont.Object.( 239 + Json.Codec.Object.( 240 240 map (fun room_id event_id -> { room_id; event_id }) 241 - |> mem "room_id" Room_id.jsont ~enc:(fun p -> p.room_id) 242 - |> mem "event_id" Event_id.jsont ~enc:(fun p -> p.event_id) 243 - |> finish) 241 + |> member "room_id" Room_id.jsont ~enc:(fun p -> p.room_id) 242 + |> member "event_id" Event_id.jsont ~enc:(fun p -> p.event_id) 243 + |> seal) 244 244 end 245 245 246 246 type predecessor = Predecessor.t ··· 277 277 Format.fprintf ppf "@]" 278 278 279 279 let jsont = 280 - Jsont.Object.( 280 + Json.Codec.Object.( 281 281 map (fun creator room_version predecessor type_ -> 282 282 { creator; room_version; predecessor; type_ }) 283 - |> opt_mem "creator" User_id.jsont ~enc:(fun t -> t.creator) 284 - |> opt_mem "room_version" Jsont.string ~enc:(fun t -> t.room_version) 285 - |> opt_mem "predecessor" Predecessor.jsont ~enc:(fun t -> t.predecessor) 286 - |> opt_mem "type" Jsont.string ~enc:(fun t -> t.type_) 287 - |> finish) 283 + |> opt_member "creator" User_id.jsont ~enc:(fun t -> t.creator) 284 + |> opt_member "room_version" Json.Codec.string ~enc:(fun t -> t.room_version) 285 + |> opt_member "predecessor" Predecessor.jsont ~enc:(fun t -> t.predecessor) 286 + |> opt_member "type" Json.Codec.string ~enc:(fun t -> t.type_) 287 + |> seal) 288 288 end 289 289 290 290 module Room_name_content = struct ··· 300 300 let pp ppf t = Format.fprintf ppf "name: %s" t.name 301 301 302 302 let jsont = 303 - Jsont.Object.( 303 + Json.Codec.Object.( 304 304 map (fun name -> { name }) 305 - |> mem "name" Jsont.string ~enc:(fun t -> t.name) 306 - |> finish) 305 + |> member "name" Json.Codec.string ~enc:(fun t -> t.name) 306 + |> seal) 307 307 end 308 308 309 309 module Room_topic_content = struct ··· 319 319 let pp ppf t = Format.fprintf ppf "topic: %s" t.topic 320 320 321 321 let jsont = 322 - Jsont.Object.( 322 + Json.Codec.Object.( 323 323 map (fun topic -> { topic }) 324 - |> mem "topic" Jsont.string ~enc:(fun t -> t.topic) 325 - |> finish) 324 + |> member "topic" Json.Codec.string ~enc:(fun t -> t.topic) 325 + |> seal) 326 326 end 327 327 328 328 module Room_avatar_content = struct ··· 360 360 Format.fprintf ppf "@]" 361 361 362 362 let jsont = 363 - Jsont.Object.( 363 + Json.Codec.Object.( 364 364 map (fun h w mimetype size -> { h; w; mimetype; size }) 365 - |> opt_mem "h" Jsont.int ~enc:(fun t -> t.h) 366 - |> opt_mem "w" Jsont.int ~enc:(fun t -> t.w) 367 - |> opt_mem "mimetype" Jsont.string ~enc:(fun t -> t.mimetype) 368 - |> opt_mem "size" Jsont.int ~enc:(fun t -> t.size) 369 - |> finish) 365 + |> opt_member "h" Json.Codec.int ~enc:(fun t -> t.h) 366 + |> opt_member "w" Json.Codec.int ~enc:(fun t -> t.w) 367 + |> opt_member "mimetype" Json.Codec.string ~enc:(fun t -> t.mimetype) 368 + |> opt_member "size" Json.Codec.int ~enc:(fun t -> t.size) 369 + |> seal) 370 370 end 371 371 372 372 type image_info = Image_info.t ··· 391 391 Format.fprintf ppf "@]" 392 392 393 393 let jsont = 394 - Jsont.Object.( 394 + Json.Codec.Object.( 395 395 map (fun url info -> { url; info }) 396 - |> opt_mem "url" Jsont.string ~enc:(fun t -> t.url) 397 - |> opt_mem "info" Image_info.jsont ~enc:(fun t -> t.info) 398 - |> finish) 396 + |> opt_member "url" Json.Codec.string ~enc:(fun t -> t.url) 397 + |> opt_member "info" Image_info.jsont ~enc:(fun t -> t.info) 398 + |> seal) 399 399 end 400 400 401 401 module Room_member_content = struct ··· 437 437 Format.fprintf ppf "@]" 438 438 439 439 let jsont = 440 - Jsont.Object.( 440 + Json.Codec.Object.( 441 441 map (fun membership displayname avatar_url is_direct reason -> 442 442 { membership; displayname; avatar_url; is_direct; reason }) 443 - |> mem "membership" Membership.jsont ~enc:(fun t -> t.membership) 444 - |> opt_mem "displayname" Jsont.string ~enc:(fun t -> t.displayname) 445 - |> opt_mem "avatar_url" Jsont.string ~enc:(fun t -> t.avatar_url) 446 - |> opt_mem "is_direct" Jsont.bool ~enc:(fun t -> t.is_direct) 447 - |> opt_mem "reason" Jsont.string ~enc:(fun t -> t.reason) 448 - |> finish) 443 + |> member "membership" Membership.jsont ~enc:(fun t -> t.membership) 444 + |> opt_member "displayname" Json.Codec.string ~enc:(fun t -> t.displayname) 445 + |> opt_member "avatar_url" Json.Codec.string ~enc:(fun t -> t.avatar_url) 446 + |> opt_member "is_direct" Json.Codec.bool ~enc:(fun t -> t.is_direct) 447 + |> opt_member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 448 + |> seal) 449 449 end 450 450 451 451 module Room_join_rules_content = struct ··· 473 473 Format.fprintf ppf "@]" 474 474 475 475 let jsont = 476 - Jsont.Object.( 476 + Json.Codec.Object.( 477 477 map (fun type_ room_id -> { type_; room_id }) 478 - |> mem "type" Jsont.string ~enc:(fun c -> c.type_) 479 - |> opt_mem "room_id" Room_id.jsont ~enc:(fun c -> c.room_id) 480 - |> finish) 478 + |> member "type" Json.Codec.string ~enc:(fun c -> c.type_) 479 + |> opt_member "room_id" Room_id.jsont ~enc:(fun c -> c.room_id) 480 + |> seal) 481 481 end 482 482 483 483 type allow_condition = Allow_condition.t ··· 502 502 Format.fprintf ppf "@]" 503 503 504 504 let jsont = 505 - Jsont.Object.( 505 + Json.Codec.Object.( 506 506 map (fun join_rule allow -> { join_rule; allow }) 507 - |> mem "join_rule" Join_rule.jsont ~enc:(fun t -> t.join_rule) 508 - |> opt_mem "allow" (Jsont.list Allow_condition.jsont) ~enc:(fun t -> t.allow) 509 - |> finish) 507 + |> member "join_rule" Join_rule.jsont ~enc:(fun t -> t.join_rule) 508 + |> opt_member "allow" (Json.Codec.list Allow_condition.jsont) ~enc:(fun t -> t.allow) 509 + |> seal) 510 510 end 511 511 512 512 module Room_history_visibility_content = struct ··· 523 523 Format.fprintf ppf "history_visibility: %a" History_visibility.pp t.history_visibility 524 524 525 525 let jsont = 526 - Jsont.Object.( 526 + Json.Codec.Object.( 527 527 map (fun history_visibility -> { history_visibility }) 528 - |> mem "history_visibility" History_visibility.jsont 528 + |> member "history_visibility" History_visibility.jsont 529 529 ~enc:(fun t -> t.history_visibility) 530 - |> finish) 530 + |> seal) 531 531 end 532 532 533 533 module Room_canonical_alias_content = struct ··· 558 558 Format.fprintf ppf "@]" 559 559 560 560 let jsont = 561 - Jsont.Object.( 561 + Json.Codec.Object.( 562 562 map (fun alias alt_aliases -> { alias; alt_aliases }) 563 - |> opt_mem "alias" Room_alias.jsont ~enc:(fun t -> t.alias) 564 - |> opt_mem "alt_aliases" (Jsont.list Room_alias.jsont) ~enc:(fun t -> t.alt_aliases) 565 - |> finish) 563 + |> opt_member "alias" Room_alias.jsont ~enc:(fun t -> t.alias) 564 + |> opt_member "alt_aliases" (Json.Codec.list Room_alias.jsont) ~enc:(fun t -> t.alt_aliases) 565 + |> seal) 566 566 end 567 567 568 568 module Room_power_levels_content = struct ··· 611 611 module StringMap = Map.Make(String) 612 612 613 613 let int_map_jsont = 614 - Jsont.Object.as_string_map Jsont.int 615 - |> Jsont.map 614 + Json.Codec.Object.as_string_map Json.Codec.int 615 + |> Json.Codec.map 616 616 ~dec:(fun m -> StringMap.bindings m) 617 617 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 618 618 619 619 let jsont = 620 - Jsont.Object.( 620 + Json.Codec.Object.( 621 621 map (fun ban events events_default invite kick redact 622 622 state_default users users_default -> 623 623 { ban; events; events_default; invite; kick; redact; 624 624 state_default; users; users_default }) 625 - |> opt_mem "ban" Jsont.int ~enc:(fun t -> t.ban) 626 - |> opt_mem "events" int_map_jsont ~enc:(fun t -> t.events) 627 - |> opt_mem "events_default" Jsont.int ~enc:(fun t -> t.events_default) 628 - |> opt_mem "invite" Jsont.int ~enc:(fun t -> t.invite) 629 - |> opt_mem "kick" Jsont.int ~enc:(fun t -> t.kick) 630 - |> opt_mem "redact" Jsont.int ~enc:(fun t -> t.redact) 631 - |> opt_mem "state_default" Jsont.int ~enc:(fun t -> t.state_default) 632 - |> opt_mem "users" int_map_jsont ~enc:(fun t -> t.users) 633 - |> opt_mem "users_default" Jsont.int ~enc:(fun t -> t.users_default) 634 - |> finish) 625 + |> opt_member "ban" Json.Codec.int ~enc:(fun t -> t.ban) 626 + |> opt_member "events" int_map_jsont ~enc:(fun t -> t.events) 627 + |> opt_member "events_default" Json.Codec.int ~enc:(fun t -> t.events_default) 628 + |> opt_member "invite" Json.Codec.int ~enc:(fun t -> t.invite) 629 + |> opt_member "kick" Json.Codec.int ~enc:(fun t -> t.kick) 630 + |> opt_member "redact" Json.Codec.int ~enc:(fun t -> t.redact) 631 + |> opt_member "state_default" Json.Codec.int ~enc:(fun t -> t.state_default) 632 + |> opt_member "users" int_map_jsont ~enc:(fun t -> t.users) 633 + |> opt_member "users_default" Json.Codec.int ~enc:(fun t -> t.users_default) 634 + |> seal) 635 635 end 636 636 637 637 module Room_encryption_content = struct ··· 663 663 Format.fprintf ppf "@]" 664 664 665 665 let jsont = 666 - Jsont.Object.( 666 + Json.Codec.Object.( 667 667 map (fun algorithm rotation_period_ms rotation_period_msgs -> 668 668 { algorithm; rotation_period_ms; rotation_period_msgs }) 669 - |> mem "algorithm" Jsont.string ~enc:(fun t -> t.algorithm) 670 - |> opt_mem "rotation_period_ms" Jsont.int64 ~enc:(fun t -> t.rotation_period_ms) 671 - |> opt_mem "rotation_period_msgs" Jsont.int ~enc:(fun t -> t.rotation_period_msgs) 672 - |> finish) 669 + |> member "algorithm" Json.Codec.string ~enc:(fun t -> t.algorithm) 670 + |> opt_member "rotation_period_ms" Json.Codec.int64 ~enc:(fun t -> t.rotation_period_ms) 671 + |> opt_member "rotation_period_msgs" Json.Codec.int ~enc:(fun t -> t.rotation_period_msgs) 672 + |> seal) 673 673 end 674 674 675 675 module Room_pinned_events_content = struct ··· 686 686 Format.fprintf ppf "pinned: [%s]" (String.concat ", " t.pinned) 687 687 688 688 let jsont = 689 - Jsont.Object.( 689 + Json.Codec.Object.( 690 690 map (fun pinned -> { pinned }) 691 - |> mem "pinned" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.pinned) 692 - |> finish) 691 + |> member "pinned" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.pinned) 692 + |> seal) 693 693 end 694 694 695 695 module Room_server_acl_content = struct ··· 715 715 (String.concat ", " t.allow) t.allow_ip_literals (String.concat ", " t.deny) 716 716 717 717 let jsont = 718 - Jsont.Object.( 718 + Json.Codec.Object.( 719 719 map (fun allow allow_ip_literals deny -> 720 720 { allow; allow_ip_literals; deny }) 721 - |> mem "allow" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.allow) 722 - |> mem "allow_ip_literals" Jsont.bool ~dec_absent:true ~enc:(fun t -> t.allow_ip_literals) 723 - |> mem "deny" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.deny) 724 - |> finish) 721 + |> member "allow" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.allow) 722 + |> member "allow_ip_literals" Json.Codec.bool ~dec_absent:true ~enc:(fun t -> t.allow_ip_literals) 723 + |> member "deny" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.deny) 724 + |> seal) 725 725 end 726 726 727 727 module Room_tombstone_content = struct ··· 743 743 t.body Room_id.pp t.replacement_room 744 744 745 745 let jsont = 746 - Jsont.Object.( 746 + Json.Codec.Object.( 747 747 map (fun body replacement_room -> { body; replacement_room }) 748 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 749 - |> mem "replacement_room" Room_id.jsont ~enc:(fun t -> t.replacement_room) 750 - |> finish) 748 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 749 + |> member "replacement_room" Room_id.jsont ~enc:(fun t -> t.replacement_room) 750 + |> seal) 751 751 end 752 752 753 753 module Room_guest_access_content = struct ··· 766 766 let pp_access ppf a = Format.pp_print_string ppf (access_to_string a) 767 767 768 768 let access_jsont = 769 - Jsont.enum [ 769 + Json.Codec.enum [ 770 770 ("can_join", Can_join); 771 771 ("forbidden", Forbidden); 772 772 ] ··· 779 779 let pp ppf t = Format.fprintf ppf "guest_access: %a" pp_access t.guest_access 780 780 781 781 let jsont = 782 - Jsont.Object.( 782 + Json.Codec.Object.( 783 783 map (fun guest_access -> { guest_access }) 784 - |> mem "guest_access" access_jsont ~enc:(fun t -> t.guest_access) 785 - |> finish) 784 + |> member "guest_access" access_jsont ~enc:(fun t -> t.guest_access) 785 + |> seal) 786 786 end 787 787 788 788 (** {1 Space Event Contents} *) ··· 813 813 Format.fprintf ppf "@]" 814 814 815 815 let jsont = 816 - Jsont.Object.( 816 + Json.Codec.Object.( 817 817 map (fun via order suggested -> { via; order; suggested }) 818 - |> opt_mem "via" (Jsont.list Jsont.string) ~enc:(fun t -> t.via) 819 - |> opt_mem "order" Jsont.string ~enc:(fun t -> t.order) 820 - |> opt_mem "suggested" Jsont.bool ~enc:(fun t -> t.suggested) 821 - |> finish) 818 + |> opt_member "via" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.via) 819 + |> opt_member "order" Json.Codec.string ~enc:(fun t -> t.order) 820 + |> opt_member "suggested" Json.Codec.bool ~enc:(fun t -> t.suggested) 821 + |> seal) 822 822 end 823 823 824 824 module Space_parent_content = struct ··· 844 844 Format.fprintf ppf "@]" 845 845 846 846 let jsont = 847 - Jsont.Object.( 847 + Json.Codec.Object.( 848 848 map (fun via canonical -> { via; canonical }) 849 - |> opt_mem "via" (Jsont.list Jsont.string) ~enc:(fun t -> t.via) 850 - |> opt_mem "canonical" Jsont.bool ~enc:(fun t -> t.canonical) 851 - |> finish) 849 + |> opt_member "via" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.via) 850 + |> opt_member "canonical" Json.Codec.bool ~enc:(fun t -> t.canonical) 851 + |> seal) 852 852 end 853 853 854 854 (** {1 Call Event Contents} ··· 893 893 t.call_id t.version t.lifetime 894 894 895 895 let sdp_content_jsont = 896 - Jsont.Object.( 896 + Json.Codec.Object.( 897 897 map (fun type_ sdp -> { type_; sdp }) 898 - |> mem "type" Jsont.string ~enc:(fun t -> t.type_) 899 - |> mem "sdp" Jsont.string ~enc:(fun t -> t.sdp) 900 - |> finish) 898 + |> member "type" Json.Codec.string ~enc:(fun t -> t.type_) 899 + |> member "sdp" Json.Codec.string ~enc:(fun t -> t.sdp) 900 + |> seal) 901 901 902 902 let jsont = 903 - Jsont.Object.( 903 + Json.Codec.Object.( 904 904 map (fun call_id party_id version lifetime offer invitee -> 905 905 { call_id; party_id; version; lifetime; offer; invitee }) 906 - |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id) 907 - |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id) 908 - |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version) 909 - |> mem "lifetime" Jsont.int ~enc:(fun t -> t.lifetime) 910 - |> mem "offer" sdp_content_jsont ~enc:(fun t -> t.offer) 911 - |> opt_mem "invitee" Jsont.string ~enc:(fun t -> t.invitee) 912 - |> finish) 906 + |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id) 907 + |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id) 908 + |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version) 909 + |> member "lifetime" Json.Codec.int ~enc:(fun t -> t.lifetime) 910 + |> member "offer" sdp_content_jsont ~enc:(fun t -> t.offer) 911 + |> opt_member "invitee" Json.Codec.string ~enc:(fun t -> t.invitee) 912 + |> seal) 913 913 end 914 914 915 915 module Call_answer_content = struct ··· 943 943 Format.fprintf ppf "@[<v>call_id: %s@,version: %d@]" t.call_id t.version 944 944 945 945 let sdp_content_jsont = 946 - Jsont.Object.( 946 + Json.Codec.Object.( 947 947 map (fun type_ sdp -> { type_; sdp }) 948 - |> mem "type" Jsont.string ~enc:(fun t -> t.type_) 949 - |> mem "sdp" Jsont.string ~enc:(fun t -> t.sdp) 950 - |> finish) 948 + |> member "type" Json.Codec.string ~enc:(fun t -> t.type_) 949 + |> member "sdp" Json.Codec.string ~enc:(fun t -> t.sdp) 950 + |> seal) 951 951 952 952 let jsont = 953 - Jsont.Object.( 953 + Json.Codec.Object.( 954 954 map (fun call_id party_id version answer -> 955 955 { call_id; party_id; version; answer }) 956 - |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id) 957 - |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id) 958 - |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version) 959 - |> mem "answer" sdp_content_jsont ~enc:(fun t -> t.answer) 960 - |> finish) 956 + |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id) 957 + |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id) 958 + |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version) 959 + |> member "answer" sdp_content_jsont ~enc:(fun t -> t.answer) 960 + |> seal) 961 961 end 962 962 963 963 module Call_hangup_content = struct ··· 984 984 let pp_reason ppf r = Format.pp_print_string ppf (reason_to_string r) 985 985 986 986 let reason_jsont = 987 - Jsont.enum [ 987 + Json.Codec.enum [ 988 988 ("ice_failed", Ice_failed); 989 989 ("invite_timeout", Invite_timeout); 990 990 ("user_hangup", User_hangup); ··· 1014 1014 Format.fprintf ppf "@]" 1015 1015 1016 1016 let jsont = 1017 - Jsont.Object.( 1017 + Json.Codec.Object.( 1018 1018 map (fun call_id party_id version reason -> 1019 1019 { call_id; party_id; version; reason }) 1020 - |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id) 1021 - |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id) 1022 - |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version) 1023 - |> opt_mem "reason" reason_jsont ~enc:(fun t -> t.reason) 1024 - |> finish) 1020 + |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id) 1021 + |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id) 1022 + |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version) 1023 + |> opt_member "reason" reason_jsont ~enc:(fun t -> t.reason) 1024 + |> seal) 1025 1025 end 1026 1026 1027 1027 module Call_candidates_content = struct ··· 1039 1039 { candidate; sdp_mid; sdp_m_line_index } 1040 1040 1041 1041 let candidate_jsont = 1042 - Jsont.Object.( 1042 + Json.Codec.Object.( 1043 1043 map (fun candidate sdp_mid sdp_m_line_index -> 1044 1044 { candidate; sdp_mid; sdp_m_line_index }) 1045 - |> mem "candidate" Jsont.string ~enc:(fun t -> t.candidate) 1046 - |> mem "sdpMid" Jsont.string ~enc:(fun t -> t.sdp_mid) 1047 - |> mem "sdpMLineIndex" Jsont.int ~enc:(fun t -> t.sdp_m_line_index) 1048 - |> finish) 1045 + |> member "candidate" Json.Codec.string ~enc:(fun t -> t.candidate) 1046 + |> member "sdpMid" Json.Codec.string ~enc:(fun t -> t.sdp_mid) 1047 + |> member "sdpMLineIndex" Json.Codec.int ~enc:(fun t -> t.sdp_m_line_index) 1048 + |> seal) 1049 1049 1050 1050 type t = { 1051 1051 call_id : string; ··· 1067 1067 t.call_id t.version (List.length t.candidates) 1068 1068 1069 1069 let jsont = 1070 - Jsont.Object.( 1070 + Json.Codec.Object.( 1071 1071 map (fun call_id party_id version candidates -> 1072 1072 { call_id; party_id; version; candidates }) 1073 - |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id) 1074 - |> opt_mem "party_id" Jsont.string ~enc:(fun t -> t.party_id) 1075 - |> mem "version" Jsont.int ~dec_absent:0 ~enc:(fun t -> t.version) 1076 - |> mem "candidates" (Jsont.list candidate_jsont) ~dec_absent:[] 1073 + |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id) 1074 + |> opt_member "party_id" Json.Codec.string ~enc:(fun t -> t.party_id) 1075 + |> member "version" Json.Codec.int ~dec_absent:0 ~enc:(fun t -> t.version) 1076 + |> member "candidates" (Json.Codec.list candidate_jsont) ~dec_absent:[] 1077 1077 ~enc:(fun t -> t.candidates) 1078 - |> finish) 1078 + |> seal) 1079 1079 end 1080 1080 1081 1081 (** {1 Call Member Content (m.call.member)} *) ··· 1095 1095 { type_; livekit_service_url; livekit_alias } 1096 1096 1097 1097 let focus_jsont = 1098 - Jsont.Object.( 1098 + Json.Codec.Object.( 1099 1099 map (fun type_ livekit_service_url livekit_alias -> 1100 1100 { type_; livekit_service_url; livekit_alias }) 1101 - |> mem "type" Jsont.string ~enc:(fun t -> t.type_) 1102 - |> opt_mem "livekit_service_url" Jsont.string ~enc:(fun t -> t.livekit_service_url) 1103 - |> opt_mem "livekit_alias" Jsont.string ~enc:(fun t -> t.livekit_alias) 1104 - |> finish) 1101 + |> member "type" Json.Codec.string ~enc:(fun t -> t.type_) 1102 + |> opt_member "livekit_service_url" Json.Codec.string ~enc:(fun t -> t.livekit_service_url) 1103 + |> opt_member "livekit_alias" Json.Codec.string ~enc:(fun t -> t.livekit_alias) 1104 + |> seal) 1105 1105 1106 1106 type membership = { 1107 1107 call_id : string; ··· 1118 1118 { call_id; scope; application; device_id; expires; foci_active; membership_id } 1119 1119 1120 1120 let membership_jsont = 1121 - Jsont.Object.( 1121 + Json.Codec.Object.( 1122 1122 map (fun call_id scope application device_id expires foci_active membership_id -> 1123 1123 { call_id; scope; application; device_id; expires; foci_active; membership_id }) 1124 - |> mem "call_id" Jsont.string ~enc:(fun t -> t.call_id) 1125 - |> mem "scope" Jsont.string ~dec_absent:"m.room" ~enc:(fun t -> t.scope) 1126 - |> mem "application" Jsont.string ~enc:(fun t -> t.application) 1127 - |> mem "device_id" Jsont.string ~enc:(fun t -> t.device_id) 1128 - |> mem "expires" Jsont.int64 ~enc:(fun t -> t.expires) 1129 - |> opt_mem "foci_active" (Jsont.list focus_jsont) ~enc:(fun t -> t.foci_active) 1130 - |> opt_mem "membership_id" Jsont.string ~enc:(fun t -> t.membership_id) 1131 - |> finish) 1124 + |> member "call_id" Json.Codec.string ~enc:(fun t -> t.call_id) 1125 + |> member "scope" Json.Codec.string ~dec_absent:"m.room" ~enc:(fun t -> t.scope) 1126 + |> member "application" Json.Codec.string ~enc:(fun t -> t.application) 1127 + |> member "device_id" Json.Codec.string ~enc:(fun t -> t.device_id) 1128 + |> member "expires" Json.Codec.int64 ~enc:(fun t -> t.expires) 1129 + |> opt_member "foci_active" (Json.Codec.list focus_jsont) ~enc:(fun t -> t.foci_active) 1130 + |> opt_member "membership_id" Json.Codec.string ~enc:(fun t -> t.membership_id) 1131 + |> seal) 1132 1132 1133 1133 type t = { memberships : membership list } 1134 1134 ··· 1139 1139 Format.fprintf ppf "@[<v>memberships: %d entries@]" (List.length t.memberships) 1140 1140 1141 1141 let jsont = 1142 - Jsont.Object.( 1142 + Json.Codec.Object.( 1143 1143 map (fun memberships -> { memberships }) 1144 - |> mem "memberships" (Jsont.list membership_jsont) ~dec_absent:[] 1144 + |> member "memberships" (Json.Codec.list membership_jsont) ~dec_absent:[] 1145 1145 ~enc:(fun t -> t.memberships) 1146 - |> finish) 1146 + |> seal) 1147 1147 end 1148 1148 1149 1149 (** {1 Key Verification Event Contents} ··· 1167 1167 } 1168 1168 1169 1169 let jsont = 1170 - Jsont.Object.( 1170 + Json.Codec.Object.( 1171 1171 map (fun from_device methods transaction_id -> 1172 1172 { from_device; methods; transaction_id }) 1173 - |> mem "from_device" Jsont.string ~enc:(fun t -> t.from_device) 1174 - |> mem "methods" (Jsont.list Jsont.string) ~dec_absent:[] ~enc:(fun t -> t.methods) 1175 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1176 - |> finish) 1173 + |> member "from_device" Json.Codec.string ~enc:(fun t -> t.from_device) 1174 + |> member "methods" (Json.Codec.list Json.Codec.string) ~dec_absent:[] ~enc:(fun t -> t.methods) 1175 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1176 + |> seal) 1177 1177 end 1178 1178 1179 1179 module Key_verification_start_content = struct ··· 1188 1188 } 1189 1189 1190 1190 let jsont = 1191 - Jsont.Object.( 1191 + Json.Codec.Object.( 1192 1192 map (fun from_device method_ transaction_id key_agreement_protocols hashes 1193 1193 message_authentication_codes short_authentication_string -> 1194 1194 { from_device; method_; transaction_id; key_agreement_protocols; hashes; 1195 1195 message_authentication_codes; short_authentication_string }) 1196 - |> mem "from_device" Jsont.string ~enc:(fun t -> t.from_device) 1197 - |> mem "method" Jsont.string ~enc:(fun t -> t.method_) 1198 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1199 - |> opt_mem "key_agreement_protocols" (Jsont.list Jsont.string) 1196 + |> member "from_device" Json.Codec.string ~enc:(fun t -> t.from_device) 1197 + |> member "method" Json.Codec.string ~enc:(fun t -> t.method_) 1198 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1199 + |> opt_member "key_agreement_protocols" (Json.Codec.list Json.Codec.string) 1200 1200 ~enc:(fun t -> t.key_agreement_protocols) 1201 - |> opt_mem "hashes" (Jsont.list Jsont.string) ~enc:(fun t -> t.hashes) 1202 - |> opt_mem "message_authentication_codes" (Jsont.list Jsont.string) 1201 + |> opt_member "hashes" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.hashes) 1202 + |> opt_member "message_authentication_codes" (Json.Codec.list Json.Codec.string) 1203 1203 ~enc:(fun t -> t.message_authentication_codes) 1204 - |> opt_mem "short_authentication_string" (Jsont.list Jsont.string) 1204 + |> opt_member "short_authentication_string" (Json.Codec.list Json.Codec.string) 1205 1205 ~enc:(fun t -> t.short_authentication_string) 1206 - |> finish) 1206 + |> seal) 1207 1207 end 1208 1208 1209 1209 module Key_verification_accept_content = struct ··· 1218 1218 } 1219 1219 1220 1220 let jsont = 1221 - Jsont.Object.( 1221 + Json.Codec.Object.( 1222 1222 map (fun transaction_id method_ key_agreement_protocol hash 1223 1223 message_authentication_code short_authentication_string commitment -> 1224 1224 { transaction_id; method_; key_agreement_protocol; hash; 1225 1225 message_authentication_code; short_authentication_string; commitment }) 1226 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1227 - |> mem "method" Jsont.string ~enc:(fun t -> t.method_) 1228 - |> mem "key_agreement_protocol" Jsont.string ~enc:(fun t -> t.key_agreement_protocol) 1229 - |> mem "hash" Jsont.string ~enc:(fun t -> t.hash) 1230 - |> mem "message_authentication_code" Jsont.string 1226 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1227 + |> member "method" Json.Codec.string ~enc:(fun t -> t.method_) 1228 + |> member "key_agreement_protocol" Json.Codec.string ~enc:(fun t -> t.key_agreement_protocol) 1229 + |> member "hash" Json.Codec.string ~enc:(fun t -> t.hash) 1230 + |> member "message_authentication_code" Json.Codec.string 1231 1231 ~enc:(fun t -> t.message_authentication_code) 1232 - |> mem "short_authentication_string" (Jsont.list Jsont.string) 1232 + |> member "short_authentication_string" (Json.Codec.list Json.Codec.string) 1233 1233 ~enc:(fun t -> t.short_authentication_string) 1234 - |> mem "commitment" Jsont.string ~enc:(fun t -> t.commitment) 1235 - |> finish) 1234 + |> member "commitment" Json.Codec.string ~enc:(fun t -> t.commitment) 1235 + |> seal) 1236 1236 end 1237 1237 1238 1238 module Key_verification_key_content = struct ··· 1242 1242 } 1243 1243 1244 1244 let jsont = 1245 - Jsont.Object.( 1245 + Json.Codec.Object.( 1246 1246 map (fun transaction_id key -> { transaction_id; key }) 1247 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1248 - |> mem "key" Jsont.string ~enc:(fun t -> t.key) 1249 - |> finish) 1247 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1248 + |> member "key" Json.Codec.string ~enc:(fun t -> t.key) 1249 + |> seal) 1250 1250 end 1251 1251 1252 1252 module Key_verification_mac_content = struct 1253 1253 module StringMap = Map.Make(String) 1254 1254 1255 1255 let string_map_jsont = 1256 - Jsont.Object.as_string_map Jsont.string 1257 - |> Jsont.map 1256 + Json.Codec.Object.as_string_map Json.Codec.string 1257 + |> Json.Codec.map 1258 1258 ~dec:(fun m -> StringMap.bindings m) 1259 1259 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 1260 1260 ··· 1265 1265 } 1266 1266 1267 1267 let jsont = 1268 - Jsont.Object.( 1268 + Json.Codec.Object.( 1269 1269 map (fun transaction_id mac keys -> { transaction_id; mac; keys }) 1270 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1271 - |> mem "mac" string_map_jsont ~enc:(fun t -> t.mac) 1272 - |> mem "keys" Jsont.string ~enc:(fun t -> t.keys) 1273 - |> finish) 1270 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1271 + |> member "mac" string_map_jsont ~enc:(fun t -> t.mac) 1272 + |> member "keys" Json.Codec.string ~enc:(fun t -> t.keys) 1273 + |> seal) 1274 1274 end 1275 1275 1276 1276 module Key_verification_cancel_content = struct ··· 1281 1281 } 1282 1282 1283 1283 let jsont = 1284 - Jsont.Object.( 1284 + Json.Codec.Object.( 1285 1285 map (fun transaction_id code reason -> { transaction_id; code; reason }) 1286 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1287 - |> mem "code" Jsont.string ~enc:(fun t -> t.code) 1288 - |> mem "reason" Jsont.string ~enc:(fun t -> t.reason) 1289 - |> finish) 1286 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1287 + |> member "code" Json.Codec.string ~enc:(fun t -> t.code) 1288 + |> member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 1289 + |> seal) 1290 1290 end 1291 1291 1292 1292 module Key_verification_done_content = struct ··· 1295 1295 } 1296 1296 1297 1297 let jsont = 1298 - Jsont.Object.( 1298 + Json.Codec.Object.( 1299 1299 map (fun transaction_id -> { transaction_id }) 1300 - |> opt_mem "transaction_id" Jsont.string ~enc:(fun t -> t.transaction_id) 1301 - |> finish) 1300 + |> opt_member "transaction_id" Json.Codec.string ~enc:(fun t -> t.transaction_id) 1301 + |> seal) 1302 1302 end 1303 1303 1304 1304 (** {1 Policy Rule Event Contents} ··· 1327 1327 | s -> Unknown s 1328 1328 1329 1329 let recommendation_jsont = 1330 - Jsont.of_of_string ~kind:"recommendation" 1330 + Json.Codec.of_of_string ~kind:"recommendation" 1331 1331 ~enc:recommendation_to_string 1332 1332 (fun s -> Ok (recommendation_of_string s)) 1333 1333 ··· 1338 1338 } 1339 1339 1340 1340 let jsont = 1341 - Jsont.Object.( 1341 + Json.Codec.Object.( 1342 1342 map (fun entity reason recommendation -> { entity; reason; recommendation }) 1343 - |> mem "entity" Jsont.string ~enc:(fun t -> t.entity) 1344 - |> mem "reason" Jsont.string ~enc:(fun t -> t.reason) 1345 - |> mem "recommendation" recommendation_jsont ~enc:(fun t -> t.recommendation) 1346 - |> finish) 1343 + |> member "entity" Json.Codec.string ~enc:(fun t -> t.entity) 1344 + |> member "reason" Json.Codec.string ~enc:(fun t -> t.reason) 1345 + |> member "recommendation" recommendation_jsont ~enc:(fun t -> t.recommendation) 1346 + |> seal) 1347 1347 end 1348 1348 1349 1349 (** {1 Account Data Contents} ··· 1363 1363 } 1364 1364 1365 1365 let jsont = 1366 - Jsont.Object.( 1366 + Json.Codec.Object.( 1367 1367 map (fun unread -> { unread }) 1368 - |> mem "unread" Jsont.bool ~dec_absent:false ~enc:(fun t -> t.unread) 1369 - |> finish) 1368 + |> member "unread" Json.Codec.bool ~dec_absent:false ~enc:(fun t -> t.unread) 1369 + |> seal) 1370 1370 end 1371 1371 1372 1372 (** {1 Encrypted Event Content} *) ··· 1388 1388 | s -> Unknown s 1389 1389 1390 1390 let algorithm_jsont = 1391 - Jsont.of_of_string ~kind:"algorithm" 1391 + Json.Codec.of_of_string ~kind:"algorithm" 1392 1392 ~enc:algorithm_to_string 1393 1393 (fun s -> Ok (algorithm_of_string s)) 1394 1394 1395 1395 type t = { 1396 1396 algorithm : algorithm; 1397 1397 sender_key : string; 1398 - ciphertext : Jsont.json; (* Can be string or object depending on algorithm *) 1398 + ciphertext : Json.t; (* Can be string or object depending on algorithm *) 1399 1399 session_id : string option; (* Megolm only *) 1400 1400 device_id : string option; 1401 1401 } 1402 1402 1403 1403 let jsont = 1404 - Jsont.Object.( 1404 + Json.Codec.Object.( 1405 1405 map (fun algorithm sender_key ciphertext session_id device_id -> 1406 1406 { algorithm; sender_key; ciphertext; session_id; device_id }) 1407 - |> mem "algorithm" algorithm_jsont ~enc:(fun t -> t.algorithm) 1408 - |> mem "sender_key" Jsont.string ~enc:(fun t -> t.sender_key) 1409 - |> mem "ciphertext" Jsont.json ~enc:(fun t -> t.ciphertext) 1410 - |> opt_mem "session_id" Jsont.string ~enc:(fun t -> t.session_id) 1411 - |> opt_mem "device_id" Jsont.string ~enc:(fun t -> t.device_id) 1412 - |> finish) 1407 + |> member "algorithm" algorithm_jsont ~enc:(fun t -> t.algorithm) 1408 + |> member "sender_key" Json.Codec.string ~enc:(fun t -> t.sender_key) 1409 + |> member "ciphertext" Json.Codec.Value.t ~enc:(fun t -> t.ciphertext) 1410 + |> opt_member "session_id" Json.Codec.string ~enc:(fun t -> t.session_id) 1411 + |> opt_member "device_id" Json.Codec.string ~enc:(fun t -> t.device_id) 1412 + |> seal) 1413 1413 end 1414 1414 1415 1415 (** {1 Reaction Content} *) ··· 1422 1422 } 1423 1423 1424 1424 let relates_to_jsont = 1425 - Jsont.Object.( 1425 + Json.Codec.Object.( 1426 1426 map (fun rel_type event_id key -> { rel_type; event_id; key }) 1427 - |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type) 1428 - |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1429 - |> mem "key" Jsont.string ~enc:(fun t -> t.key) 1430 - |> finish) 1427 + |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type) 1428 + |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1429 + |> member "key" Json.Codec.string ~enc:(fun t -> t.key) 1430 + |> seal) 1431 1431 1432 1432 type t = { 1433 1433 relates_to : relates_to; 1434 1434 } 1435 1435 1436 1436 let jsont = 1437 - Jsont.Object.( 1437 + Json.Codec.Object.( 1438 1438 map (fun relates_to -> { relates_to }) 1439 - |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1440 - |> finish) 1439 + |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1440 + |> seal) 1441 1441 end 1442 1442 1443 1443 (** {1 Beacon/Live Location Content} *) ··· 1451 1451 } 1452 1452 1453 1453 let jsont = 1454 - Jsont.Object.( 1454 + Json.Codec.Object.( 1455 1455 map (fun description live timeout asset_type -> 1456 1456 { description; live; timeout; asset_type }) 1457 - |> opt_mem "description" Jsont.string ~enc:(fun t -> t.description) 1458 - |> mem "live" Jsont.bool ~dec_absent:true ~enc:(fun t -> t.live) 1459 - |> mem "timeout" Jsont.int64 ~enc:(fun t -> t.timeout) 1460 - |> opt_mem "org.matrix.msc3488.asset" Jsont.string ~enc:(fun t -> t.asset_type) 1461 - |> finish) 1457 + |> opt_member "description" Json.Codec.string ~enc:(fun t -> t.description) 1458 + |> member "live" Json.Codec.bool ~dec_absent:true ~enc:(fun t -> t.live) 1459 + |> member "timeout" Json.Codec.int64 ~enc:(fun t -> t.timeout) 1460 + |> opt_member "org.matrix.msc3488.asset" Json.Codec.string ~enc:(fun t -> t.asset_type) 1461 + |> seal) 1462 1462 end 1463 1463 1464 1464 module Beacon_content = struct ··· 1468 1468 } 1469 1469 1470 1470 let location_jsont = 1471 - Jsont.Object.( 1471 + Json.Codec.Object.( 1472 1472 map (fun uri description -> { uri; description }) 1473 - |> mem "uri" Jsont.string ~enc:(fun t -> t.uri) 1474 - |> opt_mem "description" Jsont.string ~enc:(fun t -> t.description) 1475 - |> finish) 1473 + |> member "uri" Json.Codec.string ~enc:(fun t -> t.uri) 1474 + |> opt_member "description" Json.Codec.string ~enc:(fun t -> t.description) 1475 + |> seal) 1476 1476 1477 1477 type relates_to = { 1478 1478 rel_type : string; ··· 1480 1480 } 1481 1481 1482 1482 let relates_to_jsont = 1483 - Jsont.Object.( 1483 + Json.Codec.Object.( 1484 1484 map (fun rel_type event_id -> { rel_type; event_id }) 1485 - |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type) 1486 - |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1487 - |> finish) 1485 + |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type) 1486 + |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1487 + |> seal) 1488 1488 1489 1489 type t = { 1490 1490 location : location; ··· 1493 1493 } 1494 1494 1495 1495 let jsont = 1496 - Jsont.Object.( 1496 + Json.Codec.Object.( 1497 1497 map (fun location timestamp relates_to -> 1498 1498 { location; timestamp; relates_to }) 1499 - |> mem "org.matrix.msc3488.location" location_jsont ~enc:(fun t -> t.location) 1500 - |> mem "org.matrix.msc3488.ts" Jsont.int64 ~enc:(fun t -> t.timestamp) 1501 - |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1502 - |> finish) 1499 + |> member "org.matrix.msc3488.location" location_jsont ~enc:(fun t -> t.location) 1500 + |> member "org.matrix.msc3488.ts" Json.Codec.int64 ~enc:(fun t -> t.timestamp) 1501 + |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1502 + |> seal) 1503 1503 end 1504 1504 1505 1505 (** {1 Poll Event Contents} *) ··· 1511 1511 } 1512 1512 1513 1513 let poll_answer_jsont = 1514 - Jsont.Object.( 1514 + Json.Codec.Object.( 1515 1515 map (fun id text -> { id; text }) 1516 - |> mem "id" Jsont.string ~enc:(fun t -> t.id) 1517 - |> mem "org.matrix.msc1767.text" Jsont.string ~enc:(fun t -> t.text) 1518 - |> finish) 1516 + |> member "id" Json.Codec.string ~enc:(fun t -> t.id) 1517 + |> member "org.matrix.msc1767.text" Json.Codec.string ~enc:(fun t -> t.text) 1518 + |> seal) 1519 1519 1520 1520 type poll_kind = 1521 1521 | Disclosed 1522 1522 | Undisclosed 1523 1523 1524 1524 let poll_kind_jsont = 1525 - Jsont.enum [ 1525 + Json.Codec.enum [ 1526 1526 ("org.matrix.msc3381.poll.disclosed", Disclosed); 1527 1527 ("org.matrix.msc3381.poll.undisclosed", Undisclosed); 1528 1528 ] ··· 1535 1535 } 1536 1536 1537 1537 let poll_start_jsont = 1538 - Jsont.Object.( 1538 + Json.Codec.Object.( 1539 1539 map (fun question kind max_selections answers -> 1540 1540 { question; kind; max_selections; answers }) 1541 - |> mem "question" Jsont.string ~enc:(fun t -> t.question) 1542 - |> mem "kind" poll_kind_jsont ~dec_absent:Disclosed ~enc:(fun t -> t.kind) 1543 - |> mem "max_selections" Jsont.int ~dec_absent:1 ~enc:(fun t -> t.max_selections) 1544 - |> mem "answers" (Jsont.list poll_answer_jsont) ~enc:(fun t -> t.answers) 1545 - |> finish) 1541 + |> member "question" Json.Codec.string ~enc:(fun t -> t.question) 1542 + |> member "kind" poll_kind_jsont ~dec_absent:Disclosed ~enc:(fun t -> t.kind) 1543 + |> member "max_selections" Json.Codec.int ~dec_absent:1 ~enc:(fun t -> t.max_selections) 1544 + |> member "answers" (Json.Codec.list poll_answer_jsont) ~enc:(fun t -> t.answers) 1545 + |> seal) 1546 1546 1547 1547 type t = { 1548 1548 poll_start : poll_start; ··· 1550 1550 } 1551 1551 1552 1552 let jsont = 1553 - Jsont.Object.( 1553 + Json.Codec.Object.( 1554 1554 map (fun poll_start text -> { poll_start; text }) 1555 - |> mem "org.matrix.msc3381.poll.start" poll_start_jsont ~enc:(fun t -> t.poll_start) 1556 - |> mem "org.matrix.msc1767.text" Jsont.string ~enc:(fun t -> t.text) 1557 - |> finish) 1555 + |> member "org.matrix.msc3381.poll.start" poll_start_jsont ~enc:(fun t -> t.poll_start) 1556 + |> member "org.matrix.msc1767.text" Json.Codec.string ~enc:(fun t -> t.text) 1557 + |> seal) 1558 1558 end 1559 1559 1560 1560 module Poll_response_content = struct ··· 1564 1564 } 1565 1565 1566 1566 let relates_to_jsont = 1567 - Jsont.Object.( 1567 + Json.Codec.Object.( 1568 1568 map (fun rel_type event_id -> { rel_type; event_id }) 1569 - |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type) 1570 - |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1571 - |> finish) 1569 + |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type) 1570 + |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1571 + |> seal) 1572 1572 1573 1573 type t = { 1574 1574 relates_to : relates_to; ··· 1576 1576 } 1577 1577 1578 1578 let jsont = 1579 - Jsont.Object.( 1579 + Json.Codec.Object.( 1580 1580 map (fun relates_to answers -> { relates_to; answers }) 1581 - |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1582 - |> mem "org.matrix.msc3381.poll.response" (Jsont.list Jsont.string) 1581 + |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1582 + |> member "org.matrix.msc3381.poll.response" (Json.Codec.list Json.Codec.string) 1583 1583 ~dec_absent:[] ~enc:(fun t -> t.answers) 1584 - |> finish) 1584 + |> seal) 1585 1585 end 1586 1586 1587 1587 module Poll_end_content = struct ··· 1591 1591 } 1592 1592 1593 1593 let relates_to_jsont = 1594 - Jsont.Object.( 1594 + Json.Codec.Object.( 1595 1595 map (fun rel_type event_id -> { rel_type; event_id }) 1596 - |> mem "rel_type" Jsont.string ~enc:(fun t -> t.rel_type) 1597 - |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1598 - |> finish) 1596 + |> member "rel_type" Json.Codec.string ~enc:(fun t -> t.rel_type) 1597 + |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 1598 + |> seal) 1599 1599 1600 1600 type t = { 1601 1601 relates_to : relates_to; ··· 1603 1603 } 1604 1604 1605 1605 let jsont = 1606 - Jsont.Object.( 1606 + Json.Codec.Object.( 1607 1607 map (fun relates_to text -> { relates_to; text }) 1608 - |> mem "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1609 - |> mem "org.matrix.msc1767.text" Jsont.string ~enc:(fun t -> t.text) 1610 - |> finish) 1608 + |> member "m.relates_to" relates_to_jsont ~enc:(fun t -> t.relates_to) 1609 + |> member "org.matrix.msc1767.text" Json.Codec.string ~enc:(fun t -> t.text) 1610 + |> seal) 1611 1611 end 1612 1612 1613 1613 (** {1 Message Event Contents} *) ··· 1653 1653 let pp ppf t = Format.pp_print_string ppf (to_string t) 1654 1654 1655 1655 let jsont = 1656 - Jsont.of_of_string ~kind:"msgtype" 1656 + Json.Codec.of_of_string ~kind:"msgtype" 1657 1657 ~enc:to_string 1658 1658 (fun s -> Ok (of_string s)) 1659 1659 end ··· 1684 1684 Format.fprintf ppf "@[<v>msgtype: %a@,body: %s@]" Msgtype.pp t.msgtype t.body 1685 1685 1686 1686 let jsont = 1687 - Jsont.Object.( 1687 + Json.Codec.Object.( 1688 1688 map (fun body msgtype format formatted_body -> 1689 1689 { body; msgtype; format; formatted_body }) 1690 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 1691 - |> mem "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype) 1692 - |> opt_mem "format" Jsont.string ~enc:(fun t -> t.format) 1693 - |> opt_mem "formatted_body" Jsont.string ~enc:(fun t -> t.formatted_body) 1694 - |> finish) 1690 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 1691 + |> member "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype) 1692 + |> opt_member "format" Json.Codec.string ~enc:(fun t -> t.format) 1693 + |> opt_member "formatted_body" Json.Codec.string ~enc:(fun t -> t.formatted_body) 1694 + |> seal) 1695 1695 end 1696 1696 1697 1697 module Media_info = struct ··· 1711 1711 w : int option; 1712 1712 } 1713 1713 1714 - let thumbnail_info_jsont : thumbnail_info Jsont.t = 1715 - Jsont.Object.( 1714 + let thumbnail_info_jsont : thumbnail_info Json.codec = 1715 + Json.Codec.Object.( 1716 1716 map (fun mimetype size h w -> { mimetype; size; h; w }) 1717 - |> opt_mem "mimetype" Jsont.string ~enc:(fun (t : thumbnail_info) -> t.mimetype) 1718 - |> opt_mem "size" Jsont.int ~enc:(fun (t : thumbnail_info) -> t.size) 1719 - |> opt_mem "h" Jsont.int ~enc:(fun (t : thumbnail_info) -> t.h) 1720 - |> opt_mem "w" Jsont.int ~enc:(fun (t : thumbnail_info) -> t.w) 1721 - |> finish) 1717 + |> opt_member "mimetype" Json.Codec.string ~enc:(fun (t : thumbnail_info) -> t.mimetype) 1718 + |> opt_member "size" Json.Codec.int ~enc:(fun (t : thumbnail_info) -> t.size) 1719 + |> opt_member "h" Json.Codec.int ~enc:(fun (t : thumbnail_info) -> t.h) 1720 + |> opt_member "w" Json.Codec.int ~enc:(fun (t : thumbnail_info) -> t.w) 1721 + |> seal) 1722 1722 1723 1723 let jsont = 1724 - Jsont.Object.( 1724 + Json.Codec.Object.( 1725 1725 map (fun mimetype size duration h w thumbnail_url thumbnail_info -> 1726 1726 { mimetype; size; duration; h; w; thumbnail_url; thumbnail_info }) 1727 - |> opt_mem "mimetype" Jsont.string ~enc:(fun t -> t.mimetype) 1728 - |> opt_mem "size" Jsont.int ~enc:(fun t -> t.size) 1729 - |> opt_mem "duration" Jsont.int ~enc:(fun t -> t.duration) 1730 - |> opt_mem "h" Jsont.int ~enc:(fun t -> t.h) 1731 - |> opt_mem "w" Jsont.int ~enc:(fun t -> t.w) 1732 - |> opt_mem "thumbnail_url" Jsont.string ~enc:(fun t -> t.thumbnail_url) 1733 - |> opt_mem "thumbnail_info" thumbnail_info_jsont ~enc:(fun t -> t.thumbnail_info) 1734 - |> finish) 1727 + |> opt_member "mimetype" Json.Codec.string ~enc:(fun t -> t.mimetype) 1728 + |> opt_member "size" Json.Codec.int ~enc:(fun t -> t.size) 1729 + |> opt_member "duration" Json.Codec.int ~enc:(fun t -> t.duration) 1730 + |> opt_member "h" Json.Codec.int ~enc:(fun t -> t.h) 1731 + |> opt_member "w" Json.Codec.int ~enc:(fun t -> t.w) 1732 + |> opt_member "thumbnail_url" Json.Codec.string ~enc:(fun t -> t.thumbnail_url) 1733 + |> opt_member "thumbnail_info" thumbnail_info_jsont ~enc:(fun t -> t.thumbnail_info) 1734 + |> seal) 1735 1735 end 1736 1736 1737 1737 module Media_message_content = struct ··· 1744 1744 } 1745 1745 and encrypted_file = { 1746 1746 url : string; 1747 - key : Jsont.json; (* JWK *) 1747 + key : Json.t; (* JWK *) 1748 1748 iv : string; 1749 1749 hashes : (string * string) list; 1750 1750 v : string; ··· 1753 1753 module StringMap = Map.Make(String) 1754 1754 1755 1755 let string_map_jsont = 1756 - Jsont.Object.as_string_map Jsont.string 1757 - |> Jsont.map 1756 + Json.Codec.Object.as_string_map Json.Codec.string 1757 + |> Json.Codec.map 1758 1758 ~dec:(fun m -> StringMap.bindings m) 1759 1759 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 1760 1760 1761 - let encrypted_file_jsont : encrypted_file Jsont.t = 1762 - Jsont.Object.( 1761 + let encrypted_file_jsont : encrypted_file Json.codec = 1762 + Json.Codec.Object.( 1763 1763 map (fun url key iv hashes v -> { url; key; iv; hashes; v }) 1764 - |> mem "url" Jsont.string ~enc:(fun (f : encrypted_file) -> f.url) 1765 - |> mem "key" Jsont.json ~enc:(fun (f : encrypted_file) -> f.key) 1766 - |> mem "iv" Jsont.string ~enc:(fun (f : encrypted_file) -> f.iv) 1767 - |> mem "hashes" string_map_jsont ~enc:(fun (f : encrypted_file) -> f.hashes) 1768 - |> mem "v" Jsont.string ~enc:(fun (f : encrypted_file) -> f.v) 1769 - |> finish) 1764 + |> member "url" Json.Codec.string ~enc:(fun (f : encrypted_file) -> f.url) 1765 + |> member "key" Json.Codec.Value.t ~enc:(fun (f : encrypted_file) -> f.key) 1766 + |> member "iv" Json.Codec.string ~enc:(fun (f : encrypted_file) -> f.iv) 1767 + |> member "hashes" string_map_jsont ~enc:(fun (f : encrypted_file) -> f.hashes) 1768 + |> member "v" Json.Codec.string ~enc:(fun (f : encrypted_file) -> f.v) 1769 + |> seal) 1770 1770 1771 1771 let jsont = 1772 - Jsont.Object.( 1772 + Json.Codec.Object.( 1773 1773 map (fun body msgtype url info file -> 1774 1774 { body; msgtype; url; info; file }) 1775 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 1776 - |> mem "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype) 1777 - |> opt_mem "url" Jsont.string ~enc:(fun t -> t.url) 1778 - |> opt_mem "info" Media_info.jsont ~enc:(fun t -> t.info) 1779 - |> opt_mem "file" encrypted_file_jsont ~enc:(fun t -> t.file) 1780 - |> finish) 1775 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 1776 + |> member "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype) 1777 + |> opt_member "url" Json.Codec.string ~enc:(fun t -> t.url) 1778 + |> opt_member "info" Media_info.jsont ~enc:(fun t -> t.info) 1779 + |> opt_member "file" encrypted_file_jsont ~enc:(fun t -> t.file) 1780 + |> seal) 1781 1781 end 1782 1782 1783 1783 (** {1 Sticker Content} *) ··· 1790 1790 } 1791 1791 1792 1792 let jsont = 1793 - Jsont.Object.( 1793 + Json.Codec.Object.( 1794 1794 map (fun body info url -> { body; info; url }) 1795 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 1796 - |> opt_mem "info" Media_info.jsont ~enc:(fun t -> t.info) 1797 - |> mem "url" Jsont.string ~enc:(fun t -> t.url) 1798 - |> finish) 1795 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 1796 + |> opt_member "info" Media_info.jsont ~enc:(fun t -> t.info) 1797 + |> member "url" Json.Codec.string ~enc:(fun t -> t.url) 1798 + |> seal) 1799 1799 end 1800 1800 1801 1801 (** {1 Location Content} *) ··· 1807 1807 } 1808 1808 1809 1809 let location_info_jsont = 1810 - Jsont.Object.( 1810 + Json.Codec.Object.( 1811 1811 map (fun uri description -> { uri; description }) 1812 - |> mem "uri" Jsont.string ~enc:(fun t -> t.uri) 1813 - |> opt_mem "description" Jsont.string ~enc:(fun t -> t.description) 1814 - |> finish) 1812 + |> member "uri" Json.Codec.string ~enc:(fun t -> t.uri) 1813 + |> opt_member "description" Json.Codec.string ~enc:(fun t -> t.description) 1814 + |> seal) 1815 1815 1816 1816 type t = { 1817 1817 body : string; ··· 1821 1821 } 1822 1822 1823 1823 let jsont = 1824 - Jsont.Object.( 1824 + Json.Codec.Object.( 1825 1825 map (fun body msgtype geo_uri info -> 1826 1826 { body; msgtype; geo_uri; info }) 1827 - |> mem "body" Jsont.string ~enc:(fun t -> t.body) 1828 - |> mem "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype) 1829 - |> mem "geo_uri" Jsont.string ~enc:(fun t -> t.geo_uri) 1830 - |> opt_mem "info" location_info_jsont ~enc:(fun t -> t.info) 1831 - |> finish) 1827 + |> member "body" Json.Codec.string ~enc:(fun t -> t.body) 1828 + |> member "msgtype" Msgtype.jsont ~enc:(fun t -> t.msgtype) 1829 + |> member "geo_uri" Json.Codec.string ~enc:(fun t -> t.geo_uri) 1830 + |> opt_member "info" location_info_jsont ~enc:(fun t -> t.info) 1831 + |> seal) 1832 1832 end 1833 1833 1834 1834 (** {1 Event Types} ··· 2044 2044 let pp ppf t = Format.pp_print_string ppf (to_string t) 2045 2045 2046 2046 let jsont = 2047 - Jsont.of_of_string ~kind:"event_type" 2047 + Json.Codec.of_of_string ~kind:"event_type" 2048 2048 ~enc:to_string 2049 2049 (fun s -> Ok (of_string s)) 2050 2050 end ··· 2065 2065 } 2066 2066 2067 2067 let make_jsont content_jsont = 2068 - Jsont.Object.( 2068 + Json.Codec.Object.( 2069 2069 map (fun event_id sender origin_server_ts state_key type_ content unsigned -> 2070 2070 { event_id; sender; origin_server_ts; state_key; type_; content; unsigned }) 2071 - |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 2072 - |> mem "sender" User_id.jsont ~enc:(fun t -> t.sender) 2073 - |> mem "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts) 2074 - |> mem "state_key" Jsont.string ~enc:(fun t -> t.state_key) 2075 - |> mem "type" Event_type.jsont ~enc:(fun t -> t.type_) 2076 - |> mem "content" content_jsont ~enc:(fun t -> t.content) 2077 - |> opt_mem "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned) 2078 - |> finish) 2071 + |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 2072 + |> member "sender" User_id.jsont ~enc:(fun t -> t.sender) 2073 + |> member "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts) 2074 + |> member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key) 2075 + |> member "type" Event_type.jsont ~enc:(fun t -> t.type_) 2076 + |> member "content" content_jsont ~enc:(fun t -> t.content) 2077 + |> opt_member "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned) 2078 + |> seal) 2079 2079 end 2080 2080 2081 2081 (** {1 Room Events} *) ··· 2093 2093 } 2094 2094 2095 2095 let make_jsont content_jsont = 2096 - Jsont.Object.( 2096 + Json.Codec.Object.( 2097 2097 map (fun event_id sender origin_server_ts type_ content unsigned -> 2098 2098 { event_id; sender; origin_server_ts; type_; content; unsigned }) 2099 - |> mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 2100 - |> mem "sender" User_id.jsont ~enc:(fun t -> t.sender) 2101 - |> mem "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts) 2102 - |> mem "type" Event_type.jsont ~enc:(fun t -> t.type_) 2103 - |> mem "content" content_jsont ~enc:(fun t -> t.content) 2104 - |> opt_mem "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned) 2105 - |> finish) 2099 + |> member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 2100 + |> member "sender" User_id.jsont ~enc:(fun t -> t.sender) 2101 + |> member "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts) 2102 + |> member "type" Event_type.jsont ~enc:(fun t -> t.type_) 2103 + |> member "content" content_jsont ~enc:(fun t -> t.content) 2104 + |> opt_member "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned) 2105 + |> seal) 2106 2106 end 2107 2107 2108 2108 (** {1 Raw/Untyped Events} ··· 2116 2116 origin_server_ts : Timestamp.t; 2117 2117 type_ : Event_type.t; 2118 2118 state_key : string option; 2119 - content : Jsont.json; 2119 + content : Json.t; 2120 2120 unsigned : Unsigned.t option; 2121 2121 room_id : Room_id.t option; 2122 2122 } 2123 2123 2124 2124 let jsont = 2125 - Jsont.Object.( 2125 + Json.Codec.Object.( 2126 2126 map (fun event_id sender origin_server_ts type_ state_key content unsigned room_id -> 2127 2127 { event_id; sender; origin_server_ts; type_; state_key; content; unsigned; room_id }) 2128 - |> opt_mem "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 2129 - |> mem "sender" User_id.jsont ~enc:(fun t -> t.sender) 2130 - |> mem "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts) 2131 - |> mem "type" Event_type.jsont ~enc:(fun t -> t.type_) 2132 - |> opt_mem "state_key" Jsont.string ~enc:(fun t -> t.state_key) 2133 - |> mem "content" Jsont.json ~enc:(fun t -> t.content) 2134 - |> opt_mem "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned) 2135 - |> opt_mem "room_id" Room_id.jsont ~enc:(fun t -> t.room_id) 2136 - |> finish) 2128 + |> opt_member "event_id" Event_id.jsont ~enc:(fun t -> t.event_id) 2129 + |> member "sender" User_id.jsont ~enc:(fun t -> t.sender) 2130 + |> member "origin_server_ts" Timestamp.jsont ~enc:(fun t -> t.origin_server_ts) 2131 + |> member "type" Event_type.jsont ~enc:(fun t -> t.type_) 2132 + |> opt_member "state_key" Json.Codec.string ~enc:(fun t -> t.state_key) 2133 + |> member "content" Json.Codec.Value.t ~enc:(fun t -> t.content) 2134 + |> opt_member "unsigned" Unsigned.jsont ~enc:(fun t -> t.unsigned) 2135 + |> opt_member "room_id" Room_id.jsont ~enc:(fun t -> t.room_id) 2136 + |> seal) 2137 2137 end
+63 -63
lib/matrix_proto/matrix_event.mli
··· 21 21 val of_ptime : Ptime.t -> t 22 22 val to_ptime_opt : t -> Ptime.t option 23 23 val pp : Format.formatter -> t -> unit 24 - val jsont : t Jsont.t 24 + val jsont : t Json.codec 25 25 end 26 26 27 27 (** {1 Unsigned Event Data} *) ··· 36 36 37 37 val make : 38 38 ?age:int64 -> 39 - ?prev_content:Jsont.json -> 39 + ?prev_content:Json.t -> 40 40 ?prev_sender:Matrix_id.User_id.t -> 41 - ?redacted_because:Jsont.json -> 41 + ?redacted_because:Json.t -> 42 42 ?transaction_id:Matrix_id.Transaction_id.t -> 43 43 unit -> t 44 44 45 45 val empty : t 46 46 47 47 val age : t -> int64 option 48 - val prev_content : t -> Jsont.json option 48 + val prev_content : t -> Json.t option 49 49 val prev_sender : t -> Matrix_id.User_id.t option 50 - val redacted_because : t -> Jsont.json option 50 + val redacted_because : t -> Json.t option 51 51 val transaction_id : t -> Matrix_id.Transaction_id.t option 52 52 53 53 val pp : Format.formatter -> t -> unit 54 - val jsont : t Jsont.t 54 + val jsont : t Json.codec 55 55 end 56 56 57 57 (** {1 Room Membership} *) ··· 66 66 val to_string : t -> string 67 67 val of_string : string -> (t, [> `Unknown_membership of string ]) result 68 68 val pp : Format.formatter -> t -> unit 69 - val jsont : t Jsont.t 69 + val jsont : t Json.codec 70 70 end 71 71 72 72 (** {1 Join Rules} *) ··· 80 80 81 81 val to_string : t -> string 82 82 val pp : Format.formatter -> t -> unit 83 - val jsont : t Jsont.t 83 + val jsont : t Json.codec 84 84 end 85 85 86 86 (** {1 History Visibility} *) ··· 94 94 95 95 val to_string : t -> string 96 96 val pp : Format.formatter -> t -> unit 97 - val jsont : t Jsont.t 97 + val jsont : t Json.codec 98 98 end 99 99 100 100 (** {1 Room State Event Contents} *) ··· 113 113 val room_id : t -> Matrix_id.Room_id.t 114 114 val event_id : t -> Matrix_id.Event_id.t 115 115 val pp : Format.formatter -> t -> unit 116 - val jsont : t Jsont.t 116 + val jsont : t Json.codec 117 117 end 118 118 119 119 type predecessor = Predecessor.t ··· 132 132 val room_type : t -> string option 133 133 134 134 val pp : Format.formatter -> t -> unit 135 - val jsont : t Jsont.t 135 + val jsont : t Json.codec 136 136 end 137 137 138 138 module Room_name_content : sig ··· 145 145 val make : name:string -> t 146 146 val name : t -> string 147 147 val pp : Format.formatter -> t -> unit 148 - val jsont : t Jsont.t 148 + val jsont : t Json.codec 149 149 end 150 150 151 151 module Room_topic_content : sig ··· 158 158 val make : topic:string -> t 159 159 val topic : t -> string 160 160 val pp : Format.formatter -> t -> unit 161 - val jsont : t Jsont.t 161 + val jsont : t Json.codec 162 162 end 163 163 164 164 module Room_avatar_content : sig ··· 177 177 val mimetype : t -> string option 178 178 val size : t -> int option 179 179 val pp : Format.formatter -> t -> unit 180 - val jsont : t Jsont.t 180 + val jsont : t Json.codec 181 181 end 182 182 183 183 type image_info = Image_info.t ··· 187 187 val url : t -> string option 188 188 val info : t -> Image_info.t option 189 189 val pp : Format.formatter -> t -> unit 190 - val jsont : t Jsont.t 190 + val jsont : t Json.codec 191 191 end 192 192 193 193 module Room_member_content : sig ··· 212 212 val reason : t -> string option 213 213 214 214 val pp : Format.formatter -> t -> unit 215 - val jsont : t Jsont.t 215 + val jsont : t Json.codec 216 216 end 217 217 218 218 module Room_join_rules_content : sig ··· 229 229 val condition_type : t -> string 230 230 val room_id : t -> Matrix_id.Room_id.t option 231 231 val pp : Format.formatter -> t -> unit 232 - val jsont : t Jsont.t 232 + val jsont : t Json.codec 233 233 end 234 234 235 235 type allow_condition = Allow_condition.t ··· 240 240 val allow : t -> Allow_condition.t list option 241 241 242 242 val pp : Format.formatter -> t -> unit 243 - val jsont : t Jsont.t 243 + val jsont : t Json.codec 244 244 end 245 245 246 246 module Room_history_visibility_content : sig ··· 253 253 val make : history_visibility:History_visibility.t -> t 254 254 val history_visibility : t -> History_visibility.t 255 255 val pp : Format.formatter -> t -> unit 256 - val jsont : t Jsont.t 256 + val jsont : t Json.codec 257 257 end 258 258 259 259 module Room_canonical_alias_content : sig ··· 272 272 val alt_aliases : t -> Matrix_id.Room_alias.t list option 273 273 274 274 val pp : Format.formatter -> t -> unit 275 - val jsont : t Jsont.t 275 + val jsont : t Json.codec 276 276 end 277 277 278 278 module Room_power_levels_content : sig ··· 305 305 val users_default : t -> int option 306 306 307 307 val pp : Format.formatter -> t -> unit 308 - val jsont : t Jsont.t 308 + val jsont : t Json.codec 309 309 end 310 310 311 311 module Room_encryption_content : sig ··· 326 326 val rotation_period_msgs : t -> int option 327 327 328 328 val pp : Format.formatter -> t -> unit 329 - val jsont : t Jsont.t 329 + val jsont : t Json.codec 330 330 end 331 331 332 332 module Room_pinned_events_content : sig ··· 339 339 val make : ?pinned:string list -> unit -> t 340 340 val pinned : t -> string list 341 341 val pp : Format.formatter -> t -> unit 342 - val jsont : t Jsont.t 342 + val jsont : t Json.codec 343 343 end 344 344 345 345 module Room_server_acl_content : sig ··· 360 360 val deny : t -> string list 361 361 362 362 val pp : Format.formatter -> t -> unit 363 - val jsont : t Jsont.t 363 + val jsont : t Json.codec 364 364 end 365 365 366 366 module Room_tombstone_content : sig ··· 375 375 val replacement_room : t -> Matrix_id.Room_id.t 376 376 377 377 val pp : Format.formatter -> t -> unit 378 - val jsont : t Jsont.t 378 + val jsont : t Json.codec 379 379 end 380 380 381 381 module Room_guest_access_content : sig ··· 387 387 388 388 val access_to_string : access -> string 389 389 val pp_access : Format.formatter -> access -> unit 390 - val access_jsont : access Jsont.t 390 + val access_jsont : access Json.codec 391 391 392 392 type t 393 393 ··· 395 395 val guest_access : t -> access 396 396 397 397 val pp : Format.formatter -> t -> unit 398 - val jsont : t Jsont.t 398 + val jsont : t Json.codec 399 399 end 400 400 401 401 (** {1 Space Event Contents} *) ··· 416 416 val order : t -> string option 417 417 val suggested : t -> bool option 418 418 val pp : Format.formatter -> t -> unit 419 - val jsont : t Jsont.t 419 + val jsont : t Json.codec 420 420 end 421 421 422 422 module Space_parent_content : sig ··· 433 433 val via : t -> string list option 434 434 val canonical : t -> bool option 435 435 val pp : Format.formatter -> t -> unit 436 - val jsont : t Jsont.t 436 + val jsont : t Json.codec 437 437 end 438 438 439 439 (** {1 Call Event Contents} ··· 467 467 val offer : t -> sdp_content 468 468 val invitee : t -> string option 469 469 val pp : Format.formatter -> t -> unit 470 - val jsont : t Jsont.t 470 + val jsont : t Json.codec 471 471 end 472 472 473 473 module Call_answer_content : sig ··· 491 491 val version : t -> int 492 492 val answer : t -> sdp_content 493 493 val pp : Format.formatter -> t -> unit 494 - val jsont : t Jsont.t 494 + val jsont : t Json.codec 495 495 end 496 496 497 497 module Call_hangup_content : sig ··· 520 520 val version : t -> int 521 521 val reason : t -> reason option 522 522 val pp : Format.formatter -> t -> unit 523 - val jsont : t Jsont.t 523 + val jsont : t Json.codec 524 524 end 525 525 526 526 module Call_candidates_content : sig ··· 551 551 val version : t -> int 552 552 val candidates : t -> candidate list 553 553 val pp : Format.formatter -> t -> unit 554 - val jsont : t Jsont.t 554 + val jsont : t Json.codec 555 555 end 556 556 557 557 (** {1 Call Member Content (m.call.member)} *) ··· 589 589 val make : ?memberships:membership list -> unit -> t 590 590 val memberships : t -> membership list 591 591 val pp : Format.formatter -> t -> unit 592 - val jsont : t Jsont.t 592 + val jsont : t Json.codec 593 593 end 594 594 595 595 (** {1 Key Verification Event Contents} *) ··· 600 600 methods : string list; 601 601 transaction_id : string option; 602 602 } 603 - val jsont : t Jsont.t 603 + val jsont : t Json.codec 604 604 end 605 605 606 606 module Key_verification_start_content : sig ··· 613 613 message_authentication_codes : string list option; 614 614 short_authentication_string : string list option; 615 615 } 616 - val jsont : t Jsont.t 616 + val jsont : t Json.codec 617 617 end 618 618 619 619 module Key_verification_accept_content : sig ··· 626 626 short_authentication_string : string list; 627 627 commitment : string; 628 628 } 629 - val jsont : t Jsont.t 629 + val jsont : t Json.codec 630 630 end 631 631 632 632 module Key_verification_key_content : sig ··· 634 634 transaction_id : string option; 635 635 key : string; 636 636 } 637 - val jsont : t Jsont.t 637 + val jsont : t Json.codec 638 638 end 639 639 640 640 module Key_verification_mac_content : sig ··· 643 643 mac : (string * string) list; 644 644 keys : string; 645 645 } 646 - val jsont : t Jsont.t 646 + val jsont : t Json.codec 647 647 end 648 648 649 649 module Key_verification_cancel_content : sig ··· 652 652 code : string; 653 653 reason : string; 654 654 } 655 - val jsont : t Jsont.t 655 + val jsont : t Json.codec 656 656 end 657 657 658 658 module Key_verification_done_content : sig 659 659 type t = { transaction_id : string option } 660 - val jsont : t Jsont.t 660 + val jsont : t Json.codec 661 661 end 662 662 663 663 (** {1 Policy Rule Event Contents} *) ··· 671 671 reason : string; 672 672 recommendation : recommendation; 673 673 } 674 - val jsont : t Jsont.t 674 + val jsont : t Json.codec 675 675 end 676 676 677 677 (** {1 Account Data Contents} *) 678 678 679 679 module Marked_unread_content : sig 680 680 type t = { unread : bool } 681 - val jsont : t Jsont.t 681 + val jsont : t Json.codec 682 682 end 683 683 684 684 (** {1 Encrypted Event Content} *) ··· 693 693 type t = { 694 694 algorithm : algorithm; 695 695 sender_key : string; 696 - ciphertext : Jsont.json; 696 + ciphertext : Json.t; 697 697 session_id : string option; 698 698 device_id : string option; 699 699 } 700 - val jsont : t Jsont.t 700 + val jsont : t Json.codec 701 701 end 702 702 703 703 (** {1 Reaction Content} *) ··· 709 709 key : string; 710 710 } 711 711 type t = { relates_to : relates_to } 712 - val jsont : t Jsont.t 712 + val jsont : t Json.codec 713 713 end 714 714 715 715 (** {1 Beacon/Live Location Content} *) ··· 721 721 timeout : int64; 722 722 asset_type : string option; 723 723 } 724 - val jsont : t Jsont.t 724 + val jsont : t Json.codec 725 725 end 726 726 727 727 module Beacon_content : sig ··· 732 732 timestamp : int64; 733 733 relates_to : relates_to; 734 734 } 735 - val jsont : t Jsont.t 735 + val jsont : t Json.codec 736 736 end 737 737 738 738 (** {1 Poll Event Contents} *) ··· 747 747 answers : poll_answer list; 748 748 } 749 749 type t = { poll_start : poll_start; text : string } 750 - val jsont : t Jsont.t 750 + val jsont : t Json.codec 751 751 end 752 752 753 753 module Poll_response_content : sig 754 754 type relates_to = { rel_type : string; event_id : Matrix_id.Event_id.t } 755 755 type t = { relates_to : relates_to; answers : string list } 756 - val jsont : t Jsont.t 756 + val jsont : t Json.codec 757 757 end 758 758 759 759 module Poll_end_content : sig 760 760 type relates_to = { rel_type : string; event_id : Matrix_id.Event_id.t } 761 761 type t = { relates_to : relates_to; text : string } 762 - val jsont : t Jsont.t 762 + val jsont : t Json.codec 763 763 end 764 764 765 765 (** {1 Message Event Contents} *) ··· 776 776 val to_string : t -> string 777 777 val of_string : string -> t 778 778 val pp : Format.formatter -> t -> unit 779 - val jsont : t Jsont.t 779 + val jsont : t Json.codec 780 780 end 781 781 782 782 module Text_message_content : sig ··· 798 798 val format : t -> string option 799 799 val formatted_body : t -> string option 800 800 val pp : Format.formatter -> t -> unit 801 - val jsont : t Jsont.t 801 + val jsont : t Json.codec 802 802 end 803 803 804 804 module Media_info : sig ··· 817 817 h : int option; 818 818 w : int option; 819 819 } 820 - val jsont : t Jsont.t 820 + val jsont : t Json.codec 821 821 end 822 822 823 823 module Media_message_content : sig ··· 830 830 } 831 831 and encrypted_file = { 832 832 url : string; 833 - key : Jsont.json; 833 + key : Json.t; 834 834 iv : string; 835 835 hashes : (string * string) list; 836 836 v : string; 837 837 } 838 - val jsont : t Jsont.t 838 + val jsont : t Json.codec 839 839 end 840 840 841 841 (** {1 Sticker Content} *) ··· 846 846 info : Media_info.t option; 847 847 url : string; 848 848 } 849 - val jsont : t Jsont.t 849 + val jsont : t Json.codec 850 850 end 851 851 852 852 (** {1 Location Content} *) ··· 859 859 geo_uri : string; 860 860 info : location_info option; 861 861 } 862 - val jsont : t Jsont.t 862 + val jsont : t Json.codec 863 863 end 864 864 865 865 (** {1 Event Types} *) ··· 906 906 val to_string : t -> string 907 907 val of_string : string -> t 908 908 val pp : Format.formatter -> t -> unit 909 - val jsont : t Jsont.t 909 + val jsont : t Json.codec 910 910 end 911 911 912 912 (** {1 State Events} *) ··· 921 921 content : 'content; 922 922 unsigned : Unsigned.t option; 923 923 } 924 - val make_jsont : 'content Jsont.t -> 'content t Jsont.t 924 + val make_jsont : 'content Json.codec -> 'content t Json.codec 925 925 end 926 926 927 927 (** {1 Room Events} *) ··· 935 935 content : 'content; 936 936 unsigned : Unsigned.t option; 937 937 } 938 - val make_jsont : 'content Jsont.t -> 'content t Jsont.t 938 + val make_jsont : 'content Json.codec -> 'content t Json.codec 939 939 end 940 940 941 941 (** {1 Raw Events} *) ··· 947 947 origin_server_ts : Timestamp.t; 948 948 type_ : Event_type.t; 949 949 state_key : string option; 950 - content : Jsont.json; 950 + content : Json.t; 951 951 unsigned : Unsigned.t option; 952 952 room_id : Matrix_id.Room_id.t option; 953 953 } 954 - val jsont : t Jsont.t 954 + val jsont : t Json.codec 955 955 end
+8 -8
lib/matrix_proto/matrix_id.ml
··· 61 61 62 62 (** JSON codec for server names. *) 63 63 let jsont = 64 - Jsont.of_of_string ~kind:"server_name" 64 + Json.Codec.of_of_string ~kind:"server_name" 65 65 ~enc:to_string 66 66 (fun s -> Result.map_error (fun (`Invalid_server_name s) -> s) (of_string s)) 67 67 end ··· 134 134 135 135 (** JSON codec for user IDs. *) 136 136 let jsont = 137 - Jsont.of_of_string ~kind:"user_id" 137 + Json.Codec.of_of_string ~kind:"user_id" 138 138 ~enc:to_string 139 139 (fun s -> Result.map_error (fun (`Invalid_user_id msg) -> msg) (of_string s)) 140 140 end ··· 196 196 197 197 (** JSON codec for room IDs. *) 198 198 let jsont = 199 - Jsont.of_of_string ~kind:"room_id" 199 + Json.Codec.of_of_string ~kind:"room_id" 200 200 ~enc:to_string 201 201 (fun s -> Result.map_error (fun (`Invalid_room_id msg) -> msg) (of_string s)) 202 202 end ··· 264 264 265 265 (** JSON codec for event IDs. *) 266 266 let jsont = 267 - Jsont.of_of_string ~kind:"event_id" 267 + Json.Codec.of_of_string ~kind:"event_id" 268 268 ~enc:to_string 269 269 (fun s -> Result.map_error (fun (`Invalid_event_id msg) -> msg) (of_string s)) 270 270 end ··· 328 328 329 329 (** JSON codec for room aliases. *) 330 330 let jsont = 331 - Jsont.of_of_string ~kind:"room_alias" 331 + Json.Codec.of_of_string ~kind:"room_alias" 332 332 ~enc:to_string 333 333 (fun s -> Result.map_error (fun (`Invalid_room_alias msg) -> msg) (of_string s)) 334 334 end ··· 369 369 let pp ppf t = Format.pp_print_string ppf t 370 370 371 371 (** JSON codec for device IDs. *) 372 - let jsont = Jsont.string 372 + let jsont = Json.Codec.string 373 373 end 374 374 375 375 (** {1 Session IDs} ··· 400 400 let pp ppf t = Format.pp_print_string ppf t 401 401 402 402 (** JSON codec for session IDs. *) 403 - let jsont = Jsont.string 403 + let jsont = Json.Codec.string 404 404 end 405 405 406 406 (** {1 Transaction IDs} ··· 441 441 let pp ppf t = Format.pp_print_string ppf t 442 442 443 443 (** JSON codec for transaction IDs. *) 444 - let jsont = Jsont.string 444 + let jsont = Json.Codec.string 445 445 end
+8 -8
lib/matrix_proto/matrix_id.mli
··· 12 12 val of_string_exn : string -> t 13 13 val to_string : t -> string 14 14 val pp : Format.formatter -> t -> unit 15 - val jsont : t Jsont.t 15 + val jsont : t Json.codec 16 16 end 17 17 18 18 (** {1 User IDs} ··· 28 28 val localpart : t -> string 29 29 val server_name : t -> Server_name.t 30 30 val pp : Format.formatter -> t -> unit 31 - val jsont : t Jsont.t 31 + val jsont : t Json.codec 32 32 end 33 33 34 34 (** {1 Room IDs} ··· 44 44 val opaque_id : t -> string 45 45 val server_name : t -> Server_name.t 46 46 val pp : Format.formatter -> t -> unit 47 - val jsont : t Jsont.t 47 + val jsont : t Json.codec 48 48 end 49 49 50 50 (** {1 Event IDs} ··· 60 60 val of_string_exn : string -> t 61 61 val to_string : t -> string 62 62 val pp : Format.formatter -> t -> unit 63 - val jsont : t Jsont.t 63 + val jsont : t Json.codec 64 64 end 65 65 66 66 (** {1 Room Aliases} ··· 76 76 val alias : t -> string 77 77 val server_name : t -> Server_name.t 78 78 val pp : Format.formatter -> t -> unit 79 - val jsont : t Jsont.t 79 + val jsont : t Json.codec 80 80 end 81 81 82 82 (** {1 Device IDs} ··· 90 90 val of_string_exn : string -> t 91 91 val to_string : t -> string 92 92 val pp : Format.formatter -> t -> unit 93 - val jsont : t Jsont.t 93 + val jsont : t Json.codec 94 94 end 95 95 96 96 (** {1 Session IDs} ··· 103 103 val of_string : string -> (t, [> `Invalid_session_id of string ]) result 104 104 val to_string : t -> string 105 105 val pp : Format.formatter -> t -> unit 106 - val jsont : t Jsont.t 106 + val jsont : t Json.codec 107 107 end 108 108 109 109 (** {1 Transaction IDs} ··· 117 117 val of_string : string -> t 118 118 val to_string : t -> string 119 119 val pp : Format.formatter -> t -> unit 120 - val jsont : t Jsont.t 120 + val jsont : t Json.codec 121 121 end
+84 -84
lib/matrix_proto/matrix_sync.ml
··· 16 16 } 17 17 18 18 let jsont = 19 - Jsont.Object.( 19 + Json.Codec.Object.( 20 20 map (fun events limited prev_batch -> { events; limited; prev_batch }) 21 - |> mem "events" (Jsont.list Raw_event.jsont) ~dec_absent:[] 21 + |> member "events" (Json.Codec.list Raw_event.jsont) ~dec_absent:[] 22 22 ~enc:(fun t -> t.events) 23 - |> opt_mem "limited" Jsont.bool ~enc:(fun t -> t.limited) 24 - |> opt_mem "prev_batch" Jsont.string ~enc:(fun t -> t.prev_batch) 25 - |> finish) 23 + |> opt_member "limited" Json.Codec.bool ~enc:(fun t -> t.limited) 24 + |> opt_member "prev_batch" Json.Codec.string ~enc:(fun t -> t.prev_batch) 25 + |> seal) 26 26 end 27 27 28 28 (** {1 Ephemeral Events} *) 29 29 30 30 module Ephemeral = struct 31 31 type t = { 32 - events : Jsont.json list; 32 + events : Json.t list; 33 33 } 34 34 35 35 let jsont = 36 - Jsont.Object.( 36 + Json.Codec.Object.( 37 37 map (fun events -> { events }) 38 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun t -> t.events) 39 - |> finish) 38 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun t -> t.events) 39 + |> seal) 40 40 end 41 41 42 42 (** {1 Account Data} *) 43 43 44 44 module Account_data = struct 45 45 type t = { 46 - events : Jsont.json list; 46 + events : Json.t list; 47 47 } 48 48 49 49 let jsont = 50 - Jsont.Object.( 50 + Json.Codec.Object.( 51 51 map (fun events -> { events }) 52 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun t -> t.events) 53 - |> finish) 52 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun t -> t.events) 53 + |> seal) 54 54 end 55 55 56 56 (** {1 Room State} *) ··· 61 61 } 62 62 63 63 let jsont = 64 - Jsont.Object.( 64 + Json.Codec.Object.( 65 65 map (fun events -> { events }) 66 - |> mem "events" (Jsont.list Raw_event.jsont) ~dec_absent:[] 66 + |> member "events" (Json.Codec.list Raw_event.jsont) ~dec_absent:[] 67 67 ~enc:(fun t -> t.events) 68 - |> finish) 68 + |> seal) 69 69 end 70 70 71 71 (** {1 Unread Notification Counts} *) ··· 77 77 } 78 78 79 79 let jsont = 80 - Jsont.Object.( 80 + Json.Codec.Object.( 81 81 map (fun highlight_count notification_count -> 82 82 { highlight_count; notification_count }) 83 - |> opt_mem "highlight_count" Jsont.int ~enc:(fun t -> t.highlight_count) 84 - |> opt_mem "notification_count" Jsont.int ~enc:(fun t -> t.notification_count) 85 - |> finish) 83 + |> opt_member "highlight_count" Json.Codec.int ~enc:(fun t -> t.highlight_count) 84 + |> opt_member "notification_count" Json.Codec.int ~enc:(fun t -> t.notification_count) 85 + |> seal) 86 86 end 87 87 88 88 (** {1 Room Summary} *) ··· 95 95 } 96 96 97 97 let jsont = 98 - Jsont.Object.( 98 + Json.Codec.Object.( 99 99 map (fun heroes joined_member_count invited_member_count -> 100 100 { heroes; joined_member_count; invited_member_count }) 101 - |> opt_mem "m.heroes" (Jsont.list User_id.jsont) ~enc:(fun t -> t.heroes) 102 - |> opt_mem "m.joined_member_count" Jsont.int ~enc:(fun t -> t.joined_member_count) 103 - |> opt_mem "m.invited_member_count" Jsont.int ~enc:(fun t -> t.invited_member_count) 104 - |> finish) 101 + |> opt_member "m.heroes" (Json.Codec.list User_id.jsont) ~enc:(fun t -> t.heroes) 102 + |> opt_member "m.joined_member_count" Json.Codec.int ~enc:(fun t -> t.joined_member_count) 103 + |> opt_member "m.invited_member_count" Json.Codec.int ~enc:(fun t -> t.invited_member_count) 104 + |> seal) 105 105 end 106 106 107 107 (** {1 Joined Room} *) ··· 117 117 } 118 118 119 119 let jsont = 120 - Jsont.Object.( 120 + Json.Codec.Object.( 121 121 map (fun summary state timeline ephemeral account_data unread_notifications -> 122 122 { summary; state; timeline; ephemeral; account_data; unread_notifications }) 123 - |> opt_mem "summary" Room_summary.jsont ~enc:(fun t -> t.summary) 124 - |> opt_mem "state" Room_state.jsont ~enc:(fun t -> t.state) 125 - |> opt_mem "timeline" Timeline.jsont ~enc:(fun t -> t.timeline) 126 - |> opt_mem "ephemeral" Ephemeral.jsont ~enc:(fun t -> t.ephemeral) 127 - |> opt_mem "account_data" Account_data.jsont ~enc:(fun t -> t.account_data) 128 - |> opt_mem "unread_notifications" Unread_notification_counts.jsont ~enc:(fun t -> t.unread_notifications) 129 - |> finish) 123 + |> opt_member "summary" Room_summary.jsont ~enc:(fun t -> t.summary) 124 + |> opt_member "state" Room_state.jsont ~enc:(fun t -> t.state) 125 + |> opt_member "timeline" Timeline.jsont ~enc:(fun t -> t.timeline) 126 + |> opt_member "ephemeral" Ephemeral.jsont ~enc:(fun t -> t.ephemeral) 127 + |> opt_member "account_data" Account_data.jsont ~enc:(fun t -> t.account_data) 128 + |> opt_member "unread_notifications" Unread_notification_counts.jsont ~enc:(fun t -> t.unread_notifications) 129 + |> seal) 130 130 end 131 131 132 132 (** {1 Invited Room} *) ··· 136 136 invite_state : invite_state option; 137 137 } 138 138 and invite_state = { 139 - events : Jsont.json list; 139 + events : Json.t list; 140 140 } 141 141 142 142 let invite_state_jsont = 143 - Jsont.Object.( 143 + Json.Codec.Object.( 144 144 map (fun events -> { events }) 145 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun s -> s.events) 146 - |> finish) 145 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun s -> s.events) 146 + |> seal) 147 147 148 148 let jsont = 149 - Jsont.Object.( 149 + Json.Codec.Object.( 150 150 map (fun invite_state -> { invite_state }) 151 - |> opt_mem "invite_state" invite_state_jsont ~enc:(fun t -> t.invite_state) 152 - |> finish) 151 + |> opt_member "invite_state" invite_state_jsont ~enc:(fun t -> t.invite_state) 152 + |> seal) 153 153 end 154 154 155 155 (** {1 Left Room} *) ··· 162 162 } 163 163 164 164 let jsont = 165 - Jsont.Object.( 165 + Json.Codec.Object.( 166 166 map (fun state timeline account_data -> { state; timeline; account_data }) 167 - |> opt_mem "state" Room_state.jsont ~enc:(fun t -> t.state) 168 - |> opt_mem "timeline" Timeline.jsont ~enc:(fun t -> t.timeline) 169 - |> opt_mem "account_data" Account_data.jsont ~enc:(fun t -> t.account_data) 170 - |> finish) 167 + |> opt_member "state" Room_state.jsont ~enc:(fun t -> t.state) 168 + |> opt_member "timeline" Timeline.jsont ~enc:(fun t -> t.timeline) 169 + |> opt_member "account_data" Account_data.jsont ~enc:(fun t -> t.account_data) 170 + |> seal) 171 171 end 172 172 173 173 (** {1 Knocked Room} *) ··· 177 177 knock_state : knock_state option; 178 178 } 179 179 and knock_state = { 180 - events : Jsont.json list; 180 + events : Json.t list; 181 181 } 182 182 183 183 let knock_state_jsont = 184 - Jsont.Object.( 184 + Json.Codec.Object.( 185 185 map (fun events -> { events }) 186 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun s -> s.events) 187 - |> finish) 186 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun s -> s.events) 187 + |> seal) 188 188 189 189 let jsont = 190 - Jsont.Object.( 190 + Json.Codec.Object.( 191 191 map (fun knock_state -> { knock_state }) 192 - |> opt_mem "knock_state" knock_state_jsont ~enc:(fun t -> t.knock_state) 193 - |> finish) 192 + |> opt_member "knock_state" knock_state_jsont ~enc:(fun t -> t.knock_state) 193 + |> seal) 194 194 end 195 195 196 196 (** {1 Rooms} *) ··· 206 206 module StringMap = Map.Make(String) 207 207 208 208 let room_map_jsont jsont = 209 - Jsont.Object.as_string_map jsont 210 - |> Jsont.map 209 + Json.Codec.Object.as_string_map jsont 210 + |> Json.Codec.map 211 211 ~dec:(fun m -> StringMap.bindings m) 212 212 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 213 213 214 214 let jsont = 215 - Jsont.Object.( 215 + Json.Codec.Object.( 216 216 map (fun join invite leave knock -> { join; invite; leave; knock }) 217 - |> mem "join" (room_map_jsont Joined_room.jsont) ~dec_absent:[] 217 + |> member "join" (room_map_jsont Joined_room.jsont) ~dec_absent:[] 218 218 ~enc:(fun t -> t.join) 219 - |> mem "invite" (room_map_jsont Invited_room.jsont) ~dec_absent:[] 219 + |> member "invite" (room_map_jsont Invited_room.jsont) ~dec_absent:[] 220 220 ~enc:(fun t -> t.invite) 221 - |> mem "leave" (room_map_jsont Left_room.jsont) ~dec_absent:[] 221 + |> member "leave" (room_map_jsont Left_room.jsont) ~dec_absent:[] 222 222 ~enc:(fun t -> t.leave) 223 - |> mem "knock" (room_map_jsont Knocked_room.jsont) ~dec_absent:[] 223 + |> member "knock" (room_map_jsont Knocked_room.jsont) ~dec_absent:[] 224 224 ~enc:(fun t -> t.knock) 225 - |> finish) 225 + |> seal) 226 226 end 227 227 228 228 (** {1 Device Lists} *) ··· 234 234 } 235 235 236 236 let jsont = 237 - Jsont.Object.( 237 + Json.Codec.Object.( 238 238 map (fun changed left -> { changed; left }) 239 - |> mem "changed" (Jsont.list User_id.jsont) ~dec_absent:[] ~enc:(fun t -> t.changed) 240 - |> mem "left" (Jsont.list User_id.jsont) ~dec_absent:[] ~enc:(fun t -> t.left) 241 - |> finish) 239 + |> member "changed" (Json.Codec.list User_id.jsont) ~dec_absent:[] ~enc:(fun t -> t.changed) 240 + |> member "left" (Json.Codec.list User_id.jsont) ~dec_absent:[] ~enc:(fun t -> t.left) 241 + |> seal) 242 242 end 243 243 244 244 (** {1 To-Device Events} *) 245 245 246 246 module To_device = struct 247 247 type t = { 248 - events : Jsont.json list; 248 + events : Json.t list; 249 249 } 250 250 251 251 let jsont = 252 - Jsont.Object.( 252 + Json.Codec.Object.( 253 253 map (fun events -> { events }) 254 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun t -> t.events) 255 - |> finish) 254 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun t -> t.events) 255 + |> seal) 256 256 end 257 257 258 258 (** {1 Presence} *) 259 259 260 260 module Presence = struct 261 261 type t = { 262 - events : Jsont.json list; 262 + events : Json.t list; 263 263 } 264 264 265 265 let jsont = 266 - Jsont.Object.( 266 + Json.Codec.Object.( 267 267 map (fun events -> { events }) 268 - |> mem "events" (Jsont.list Jsont.json) ~dec_absent:[] ~enc:(fun t -> t.events) 269 - |> finish) 268 + |> member "events" (Json.Codec.list Json.Codec.Value.t) ~dec_absent:[] ~enc:(fun t -> t.events) 269 + |> seal) 270 270 end 271 271 272 272 (** {1 Sync Response} *) ··· 286 286 module StringMap = Map.Make(String) 287 287 288 288 let int_map_jsont = 289 - Jsont.Object.as_string_map Jsont.int 290 - |> Jsont.map 289 + Json.Codec.Object.as_string_map Json.Codec.int 290 + |> Json.Codec.map 291 291 ~dec:(fun m -> StringMap.bindings m) 292 292 ~enc:(fun l -> List.to_seq l |> StringMap.of_seq) 293 293 294 294 let jsont = 295 - Jsont.Object.( 295 + Json.Codec.Object.( 296 296 map (fun next_batch rooms presence account_data to_device 297 297 device_lists device_one_time_keys_count 298 298 device_unused_fallback_key_types -> 299 299 { next_batch; rooms; presence; account_data; to_device; 300 300 device_lists; device_one_time_keys_count; 301 301 device_unused_fallback_key_types }) 302 - |> mem "next_batch" Jsont.string ~enc:(fun t -> t.next_batch) 303 - |> opt_mem "rooms" Rooms.jsont ~enc:(fun t -> t.rooms) 304 - |> opt_mem "presence" Presence.jsont ~enc:(fun t -> t.presence) 305 - |> opt_mem "account_data" Account_data.jsont ~enc:(fun t -> t.account_data) 306 - |> opt_mem "to_device" To_device.jsont ~enc:(fun t -> t.to_device) 307 - |> opt_mem "device_lists" Device_lists.jsont ~enc:(fun t -> t.device_lists) 308 - |> mem "device_one_time_keys_count" int_map_jsont ~dec_absent:[] 302 + |> member "next_batch" Json.Codec.string ~enc:(fun t -> t.next_batch) 303 + |> opt_member "rooms" Rooms.jsont ~enc:(fun t -> t.rooms) 304 + |> opt_member "presence" Presence.jsont ~enc:(fun t -> t.presence) 305 + |> opt_member "account_data" Account_data.jsont ~enc:(fun t -> t.account_data) 306 + |> opt_member "to_device" To_device.jsont ~enc:(fun t -> t.to_device) 307 + |> opt_member "device_lists" Device_lists.jsont ~enc:(fun t -> t.device_lists) 308 + |> member "device_one_time_keys_count" int_map_jsont ~dec_absent:[] 309 309 ~enc:(fun t -> t.device_one_time_keys_count) 310 - |> opt_mem "device_unused_fallback_key_types" (Jsont.list Jsont.string) ~enc:(fun t -> t.device_unused_fallback_key_types) 311 - |> finish) 310 + |> opt_member "device_unused_fallback_key_types" (Json.Codec.list Json.Codec.string) ~enc:(fun t -> t.device_unused_fallback_key_types) 311 + |> seal) 312 312 end
+21 -21
lib/matrix_proto/matrix_sync.mli
··· 11 11 limited : bool option; 12 12 prev_batch : string option; 13 13 } 14 - val jsont : t Jsont.t 14 + val jsont : t Json.codec 15 15 end 16 16 17 17 (** {1 Ephemeral Events} *) 18 18 19 19 module Ephemeral : sig 20 - type t = { events : Jsont.json list } 21 - val jsont : t Jsont.t 20 + type t = { events : Json.t list } 21 + val jsont : t Json.codec 22 22 end 23 23 24 24 (** {1 Account Data} *) 25 25 26 26 module Account_data : sig 27 - type t = { events : Jsont.json list } 28 - val jsont : t Jsont.t 27 + type t = { events : Json.t list } 28 + val jsont : t Json.codec 29 29 end 30 30 31 31 (** {1 Room State} *) 32 32 33 33 module Room_state : sig 34 34 type t = { events : Matrix_event.Raw_event.t list } 35 - val jsont : t Jsont.t 35 + val jsont : t Json.codec 36 36 end 37 37 38 38 (** {1 Unread Notification Counts} *) ··· 42 42 highlight_count : int option; 43 43 notification_count : int option; 44 44 } 45 - val jsont : t Jsont.t 45 + val jsont : t Json.codec 46 46 end 47 47 48 48 (** {1 Room Summary} *) ··· 53 53 joined_member_count : int option; 54 54 invited_member_count : int option; 55 55 } 56 - val jsont : t Jsont.t 56 + val jsont : t Json.codec 57 57 end 58 58 59 59 (** {1 Joined Room} *) ··· 67 67 account_data : Account_data.t option; 68 68 unread_notifications : Unread_notification_counts.t option; 69 69 } 70 - val jsont : t Jsont.t 70 + val jsont : t Json.codec 71 71 end 72 72 73 73 (** {1 Invited Room} *) 74 74 75 75 module Invited_room : sig 76 76 type t = { invite_state : invite_state option } 77 - and invite_state = { events : Jsont.json list } 78 - val jsont : t Jsont.t 77 + and invite_state = { events : Json.t list } 78 + val jsont : t Json.codec 79 79 end 80 80 81 81 (** {1 Left Room} *) ··· 86 86 timeline : Timeline.t option; 87 87 account_data : Account_data.t option; 88 88 } 89 - val jsont : t Jsont.t 89 + val jsont : t Json.codec 90 90 end 91 91 92 92 (** {1 Knocked Room} *) 93 93 94 94 module Knocked_room : sig 95 95 type t = { knock_state : knock_state option } 96 - and knock_state = { events : Jsont.json list } 97 - val jsont : t Jsont.t 96 + and knock_state = { events : Json.t list } 97 + val jsont : t Json.codec 98 98 end 99 99 100 100 (** {1 Rooms} *) ··· 106 106 leave : (string * Left_room.t) list; 107 107 knock : (string * Knocked_room.t) list; 108 108 } 109 - val jsont : t Jsont.t 109 + val jsont : t Json.codec 110 110 end 111 111 112 112 (** {1 Device Lists} *) ··· 116 116 changed : Matrix_id.User_id.t list; 117 117 left : Matrix_id.User_id.t list; 118 118 } 119 - val jsont : t Jsont.t 119 + val jsont : t Json.codec 120 120 end 121 121 122 122 (** {1 To-Device Events} *) 123 123 124 124 module To_device : sig 125 - type t = { events : Jsont.json list } 126 - val jsont : t Jsont.t 125 + type t = { events : Json.t list } 126 + val jsont : t Json.codec 127 127 end 128 128 129 129 (** {1 Presence} *) 130 130 131 131 module Presence : sig 132 - type t = { events : Jsont.json list } 133 - val jsont : t Jsont.t 132 + type t = { events : Json.t list } 133 + val jsont : t Json.codec 134 134 end 135 135 136 136 (** {1 Sync Response} *) ··· 146 146 device_one_time_keys_count : (string * int) list; 147 147 device_unused_fallback_key_types : string list option; 148 148 } 149 - val jsont : t Jsont.t 149 + val jsont : t Json.codec 150 150 end
+6 -6
matrix.opam
··· 11 11 depends: [ 12 12 "dune" {>= "3.21"} 13 13 "ocaml" {>= "5.1"} 14 - "jsont" 14 + "nox-json" 15 15 "ptime" 16 16 "requests" 17 17 "tomlt" 18 - "xdge" 18 + "nox-xdge" 19 19 "uri" 20 20 "eio" 21 21 "logs" 22 22 "base64" 23 - "mirage-crypto" 24 - "mirage-crypto-ec" 25 - "mirage-crypto-rng" 23 + "nox-crypto" 24 + "nox-crypto-ec" 25 + "nox-crypto-rng" 26 26 "digestif" 27 - "kdf" 27 + "nox-kdf" 28 28 "fmt" 29 29 "cmdliner" 30 30 "alcotest" {with-test}
+1 -1
test/dune
··· 1 1 (executable 2 2 (name test_matrix_proto) 3 - (libraries matrix.proto jsont jsont.bytesrw)) 3 + (libraries matrix.proto nox-json)) 4 4 5 5 (rule 6 6 (alias runtest)
+3 -3
test/test_matrix_proto.ml
··· 38 38 In_channel.with_open_bin path In_channel.input_all 39 39 40 40 let roundtrip_test jsont json_str = 41 - match Jsont_bytesrw.decode_string jsont json_str with 41 + match (Json.of_string jsont json_str |> Result.map_error Json.Error.to_string) with 42 42 | Error e -> failwith ("decode: " ^ e) 43 43 | Ok value -> 44 - match Jsont_bytesrw.encode_string jsont value with 44 + match (try Ok (Json.to_string jsont value) with Json.Error e -> Error (Json.Error.to_string e)) with 45 45 | Error e -> failwith ("encode: " ^ e) 46 46 | Ok encoded -> 47 - match Jsont_bytesrw.decode_string jsont encoded with 47 + match (Json.of_string jsont encoded |> Result.map_error Json.Error.to_string) with 48 48 | Error e -> failwith ("re-decode: " ^ e) 49 49 | Ok _ -> () 50 50