Matrix protocol in OCaml, Eio specialised
at main 121 lines 2.8 kB view raw
1(** Matrix identifiers with validation and JSON codecs. 2 3 Matrix uses several types of identifiers that follow specific formats. 4 All identifiers are case-sensitive. *) 5 6(** {1 Server Names} *) 7 8module Server_name : sig 9 type t 10 11 val of_string : string -> (t, [> `Invalid_server_name of string ]) result 12 val of_string_exn : string -> t 13 val to_string : t -> string 14 val pp : Format.formatter -> t -> unit 15 val jsont : t Jsont.t 16end 17 18(** {1 User IDs} 19 20 User IDs have the format [@localpart:server_name]. *) 21 22module User_id : sig 23 type t 24 25 val of_string : string -> (t, [> `Invalid_user_id of string ]) result 26 val of_string_exn : string -> t 27 val to_string : t -> string 28 val localpart : t -> string 29 val server_name : t -> Server_name.t 30 val pp : Format.formatter -> t -> unit 31 val jsont : t Jsont.t 32end 33 34(** {1 Room IDs} 35 36 Room IDs have the format [!opaque_id:server_name]. *) 37 38module Room_id : sig 39 type t 40 41 val of_string : string -> (t, [> `Invalid_room_id of string ]) result 42 val of_string_exn : string -> t 43 val to_string : t -> string 44 val opaque_id : t -> string 45 val server_name : t -> Server_name.t 46 val pp : Format.formatter -> t -> unit 47 val jsont : t Jsont.t 48end 49 50(** {1 Event IDs} 51 52 Event IDs can be either: 53 - Version 1-3: [$opaque_id:server_name] 54 - Version 4+: [$base64_opaque_id] (no server name) *) 55 56module Event_id : sig 57 type t 58 59 val of_string : string -> (t, [> `Invalid_event_id of string ]) result 60 val of_string_exn : string -> t 61 val to_string : t -> string 62 val pp : Format.formatter -> t -> unit 63 val jsont : t Jsont.t 64end 65 66(** {1 Room Aliases} 67 68 Room aliases have the format [#alias:server_name]. *) 69 70module Room_alias : sig 71 type t 72 73 val of_string : string -> (t, [> `Invalid_room_alias of string ]) result 74 val of_string_exn : string -> t 75 val to_string : t -> string 76 val alias : t -> string 77 val server_name : t -> Server_name.t 78 val pp : Format.formatter -> t -> unit 79 val jsont : t Jsont.t 80end 81 82(** {1 Device IDs} 83 84 Device IDs are opaque strings. *) 85 86module Device_id : sig 87 type t 88 89 val of_string : string -> (t, [> `Invalid_device_id of string ]) result 90 val of_string_exn : string -> t 91 val to_string : t -> string 92 val pp : Format.formatter -> t -> unit 93 val jsont : t Jsont.t 94end 95 96(** {1 Session IDs} 97 98 Megolm session IDs. *) 99 100module Session_id : sig 101 type t 102 103 val of_string : string -> (t, [> `Invalid_session_id of string ]) result 104 val to_string : t -> string 105 val pp : Format.formatter -> t -> unit 106 val jsont : t Jsont.t 107end 108 109(** {1 Transaction IDs} 110 111 Client-generated transaction IDs for idempotency. *) 112 113module Transaction_id : sig 114 type t 115 116 val generate : unit -> t 117 val of_string : string -> t 118 val to_string : t -> string 119 val pp : Format.formatter -> t -> unit 120 val jsont : t Jsont.t 121end