ActivityPub in OCaml using jsont/eio/requests
0
fork

Configure Feed

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

wip

+2422
+1
.gitignore
··· 1 + _build
+25
activitypub.opam
··· 1 + # This file is generated by dune, edit dune-project instead 2 + opam-version: "2.0" 3 + synopsis: "ActivityPub protocol types with jsont codecs" 4 + description: 5 + "OCaml types and jsont codecs for the ActivityPub/ActivityStreams protocol" 6 + depends: [ 7 + "dune" {>= "3.0"} 8 + "ocaml" {>= "4.14.0"} 9 + "jsont" {>= "0.2.0"} 10 + "odoc" {with-doc} 11 + ] 12 + build: [ 13 + ["dune" "subst"] {dev} 14 + [ 15 + "dune" 16 + "build" 17 + "-p" 18 + name 19 + "-j" 20 + jobs 21 + "@install" 22 + "@runtest" {with-test} 23 + "@doc" {with-doc} 24 + ] 25 + ]
+12
dune-project
··· 1 + (lang dune 3.0) 2 + (name activitypub) 3 + 4 + (generate_opam_files true) 5 + 6 + (package 7 + (name activitypub) 8 + (synopsis "ActivityPub protocol types with jsont codecs") 9 + (description "OCaml types and jsont codecs for the ActivityPub/ActivityStreams protocol") 10 + (depends 11 + (ocaml (>= 4.14.0)) 12 + (jsont (>= 0.2.0))))
+1686
src/activitypub.ml
··· 1 + (** ActivityPub/ActivityStreams types with jsont codecs. 2 + 3 + This module provides OCaml types and bidirectional JSON codecs for the 4 + ActivityPub and ActivityStreams 2.0 specifications. 5 + 6 + @see <https://www.w3.org/TR/activitypub/> ActivityPub specification 7 + @see <https://www.w3.org/TR/activitystreams-core/> ActivityStreams Core 8 + @see <https://www.w3.org/TR/activitystreams-vocabulary/> ActivityStreams Vocabulary *) 9 + 10 + (** {1 Common Types} *) 11 + 12 + (** Timestamps in ISO 8601 format. *) 13 + module Datetime : sig 14 + type t 15 + val v : string -> t 16 + val to_string : t -> string 17 + val jsont : t Jsont.t 18 + end = struct 19 + type t = string 20 + let v s = s 21 + let to_string t = t 22 + let jsont = Jsont.string |> Jsont.with_doc ~kind:"datetime" 23 + end 24 + 25 + (** URI identifiers. *) 26 + module Uri : sig 27 + type t 28 + val v : string -> t 29 + val to_string : t -> string 30 + val jsont : t Jsont.t 31 + end = struct 32 + type t = string 33 + let v s = s 34 + let to_string t = t 35 + let jsont = Jsont.string |> Jsont.with_doc ~kind:"uri" 36 + end 37 + 38 + (** JSON-LD context. *) 39 + module Context : sig 40 + type t 41 + val default : t 42 + val jsont : t Jsont.t 43 + end = struct 44 + type t = Jsont.json 45 + let default = 46 + Jsont.Json.string "https://www.w3.org/ns/activitystreams" 47 + let jsont = Jsont.json |> Jsont.with_doc ~kind:"@context" 48 + end 49 + 50 + (** {1 Link} *) 51 + 52 + (** Link objects represent references to other resources. 53 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link> *) 54 + module Link : sig 55 + type t 56 + 57 + val make : 58 + ?media_type:string -> 59 + ?name:string -> 60 + ?hreflang:string -> 61 + ?height:int -> 62 + ?width:int -> 63 + ?preview:Uri.t -> 64 + href:Uri.t -> 65 + unit -> t 66 + 67 + val href : t -> Uri.t 68 + val media_type : t -> string option 69 + val name : t -> string option 70 + val hreflang : t -> string option 71 + val height : t -> int option 72 + val width : t -> int option 73 + val preview : t -> Uri.t option 74 + 75 + val jsont : t Jsont.t 76 + end = struct 77 + type t = { 78 + href : Uri.t; 79 + media_type : string option; 80 + name : string option; 81 + hreflang : string option; 82 + height : int option; 83 + width : int option; 84 + preview : Uri.t option; 85 + } 86 + 87 + let make ?media_type ?name ?hreflang ?height ?width ?preview ~href () = 88 + { href; media_type; name; hreflang; height; width; preview } 89 + 90 + let href t = t.href 91 + let media_type t = t.media_type 92 + let name t = t.name 93 + let hreflang t = t.hreflang 94 + let height t = t.height 95 + let width t = t.width 96 + let preview t = t.preview 97 + 98 + let jsont = 99 + Jsont.Object.map ~kind:"Link" 100 + (fun href media_type name hreflang height width preview -> 101 + { href; media_type; name; hreflang; height; width; preview }) 102 + |> Jsont.Object.mem "href" Uri.jsont ~enc:href 103 + |> Jsont.Object.opt_mem "mediaType" Jsont.string ~enc:media_type 104 + |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name 105 + |> Jsont.Object.opt_mem "hreflang" Jsont.string ~enc:hreflang 106 + |> Jsont.Object.opt_mem "height" Jsont.int ~enc:height 107 + |> Jsont.Object.opt_mem "width" Jsont.int ~enc:width 108 + |> Jsont.Object.opt_mem "preview" Uri.jsont ~enc:preview 109 + |> Jsont.Object.finish 110 + end 111 + 112 + (** Reference that can be either a URI string or a Link object. *) 113 + module Link_or_uri : sig 114 + type t = 115 + | Uri of Uri.t 116 + | Link of Link.t 117 + 118 + val uri : Uri.t -> t 119 + val link : Link.t -> t 120 + val jsont : t Jsont.t 121 + end = struct 122 + type t = 123 + | Uri of Uri.t 124 + | Link of Link.t 125 + 126 + let uri u = Uri u 127 + let link l = Link l 128 + 129 + let jsont = 130 + let dec_string = Jsont.map Uri.jsont ~dec:(fun u -> Uri u) 131 + ~enc:(function Uri u -> u | Link _ -> assert false) in 132 + let dec_object = Jsont.map Link.jsont ~dec:(fun l -> Link l) 133 + ~enc:(function Link l -> l | Uri _ -> assert false) in 134 + Jsont.any ~kind:"Link or URI" 135 + ~dec_string ~dec_object 136 + ~enc:(function 137 + | Uri _ -> dec_string 138 + | Link _ -> dec_object) 139 + () 140 + end 141 + 142 + (** {1 Image} *) 143 + 144 + (** Image objects. 145 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image> *) 146 + module Image : sig 147 + type t 148 + 149 + val make : 150 + ?id:Uri.t -> 151 + ?name:string -> 152 + ?media_type:string -> 153 + ?width:int -> 154 + ?height:int -> 155 + url:Link_or_uri.t -> 156 + unit -> t 157 + 158 + val id : t -> Uri.t option 159 + val url : t -> Link_or_uri.t 160 + val name : t -> string option 161 + val media_type : t -> string option 162 + val width : t -> int option 163 + val height : t -> int option 164 + 165 + val jsont : t Jsont.t 166 + end = struct 167 + type t = { 168 + id : Uri.t option; 169 + url : Link_or_uri.t; 170 + name : string option; 171 + media_type : string option; 172 + width : int option; 173 + height : int option; 174 + } 175 + 176 + let make ?id ?name ?media_type ?width ?height ~url () = 177 + { id; url; name; media_type; width; height } 178 + 179 + let id t = t.id 180 + let url t = t.url 181 + let name t = t.name 182 + let media_type t = t.media_type 183 + let width t = t.width 184 + let height t = t.height 185 + 186 + let jsont = 187 + Jsont.Object.map ~kind:"Image" 188 + (fun id url name media_type width height -> 189 + { id; url; name; media_type; width; height }) 190 + |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id 191 + |> Jsont.Object.mem "url" Link_or_uri.jsont ~enc:url 192 + |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name 193 + |> Jsont.Object.opt_mem "mediaType" Jsont.string ~enc:media_type 194 + |> Jsont.Object.opt_mem "width" Jsont.int ~enc:width 195 + |> Jsont.Object.opt_mem "height" Jsont.int ~enc:height 196 + |> Jsont.Object.finish 197 + end 198 + 199 + (** Image reference - can be URI, Link, or full Image object. *) 200 + module Image_ref : sig 201 + type t = 202 + | Uri of Uri.t 203 + | Link of Link.t 204 + | Image of Image.t 205 + 206 + val uri : Uri.t -> t 207 + val link : Link.t -> t 208 + val image : Image.t -> t 209 + val jsont : t Jsont.t 210 + end = struct 211 + type t = 212 + | Uri of Uri.t 213 + | Link of Link.t 214 + | Image of Image.t 215 + 216 + let uri u = Uri u 217 + let link l = Link l 218 + let image i = Image i 219 + 220 + let jsont = 221 + let dec_string = Jsont.map Uri.jsont ~dec:(fun u -> Uri u) 222 + ~enc:(function Uri u -> u | _ -> assert false) in 223 + let link_jsont = 224 + Jsont.map Link.jsont 225 + ~dec:(fun l -> Link l) 226 + ~enc:(function Link l -> l | _ -> assert false) 227 + in 228 + let image_jsont = 229 + Jsont.map Image.jsont 230 + ~dec:(fun i -> Image i) 231 + ~enc:(function Image i -> i | _ -> assert false) 232 + in 233 + let link_case = Jsont.Object.Case.map "Link" link_jsont in 234 + let image_case = Jsont.Object.Case.map "Image" image_jsont in 235 + let dec_object = 236 + Jsont.Object.map ~kind:"Image or Link" Fun.id 237 + |> Jsont.Object.case_mem "@type" Jsont.string 238 + ~tag_compare:String.compare ~tag_to_string:Fun.id 239 + ~dec_absent:"Image" 240 + ~enc:Fun.id 241 + ~enc_case:(function 242 + | Link _ as v -> Jsont.Object.Case.value link_case v 243 + | Image _ as v -> Jsont.Object.Case.value image_case v 244 + | Uri _ -> assert false) 245 + [ Jsont.Object.Case.make link_case; 246 + Jsont.Object.Case.make image_case ] 247 + |> Jsont.Object.finish 248 + in 249 + Jsont.any ~kind:"Image reference" 250 + ~dec_string ~dec_object 251 + ~enc:(function 252 + | Uri _ -> dec_string 253 + | Link _ | Image _ -> dec_object) 254 + () 255 + end 256 + 257 + (** {1 Public Collection} *) 258 + 259 + (** Special public addressing collection. *) 260 + module Public : sig 261 + val id : Uri.t 262 + end = struct 263 + let id = Uri.v "https://www.w3.org/ns/activitystreams#Public" 264 + end 265 + 266 + (** {1 Recipient} *) 267 + 268 + (** Recipient reference - can be URI or inline object with id and type. *) 269 + module Recipient : sig 270 + type t = { 271 + id : Uri.t; 272 + type_ : string option; 273 + } 274 + 275 + val make : ?type_:string -> Uri.t -> t 276 + val id : t -> Uri.t 277 + val type_ : t -> string option 278 + val jsont : t Jsont.t 279 + end = struct 280 + type t = { 281 + id : Uri.t; 282 + type_ : string option; 283 + } 284 + 285 + let make ?type_ id = { id; type_ } 286 + let id t = t.id 287 + let type_ t = t.type_ 288 + 289 + let jsont = 290 + let dec_string = Jsont.map Uri.jsont 291 + ~dec:(fun u -> { id = u; type_ = None }) 292 + ~enc:(fun t -> t.id) in 293 + let dec_object = 294 + Jsont.Object.map ~kind:"Recipient" 295 + (fun id type_ -> { id; type_ }) 296 + |> Jsont.Object.mem "@id" Uri.jsont ~enc:id 297 + |> Jsont.Object.opt_mem "@type" Jsont.string ~enc:type_ 298 + |> Jsont.Object.finish 299 + in 300 + Jsont.any ~kind:"Recipient" 301 + ~dec_string ~dec_object 302 + ~enc:(fun t -> 303 + match t.type_ with 304 + | None -> dec_string 305 + | Some _ -> dec_object) 306 + () 307 + end 308 + 309 + (** {1 Endpoints} *) 310 + 311 + (** Actor endpoints for special server URLs. *) 312 + module Endpoints : sig 313 + type t 314 + 315 + val make : 316 + ?proxy_url:Uri.t -> 317 + ?oauth_authorization_endpoint:Uri.t -> 318 + ?oauth_token_endpoint:Uri.t -> 319 + ?provide_client_key:Uri.t -> 320 + ?sign_client_key:Uri.t -> 321 + ?shared_inbox:Uri.t -> 322 + unit -> t 323 + 324 + val proxy_url : t -> Uri.t option 325 + val oauth_authorization_endpoint : t -> Uri.t option 326 + val oauth_token_endpoint : t -> Uri.t option 327 + val provide_client_key : t -> Uri.t option 328 + val sign_client_key : t -> Uri.t option 329 + val shared_inbox : t -> Uri.t option 330 + 331 + val jsont : t Jsont.t 332 + end = struct 333 + type t = { 334 + proxy_url : Uri.t option; 335 + oauth_authorization_endpoint : Uri.t option; 336 + oauth_token_endpoint : Uri.t option; 337 + provide_client_key : Uri.t option; 338 + sign_client_key : Uri.t option; 339 + shared_inbox : Uri.t option; 340 + } 341 + 342 + let make ?proxy_url ?oauth_authorization_endpoint ?oauth_token_endpoint 343 + ?provide_client_key ?sign_client_key ?shared_inbox () = 344 + { proxy_url; oauth_authorization_endpoint; oauth_token_endpoint; 345 + provide_client_key; sign_client_key; shared_inbox } 346 + 347 + let proxy_url t = t.proxy_url 348 + let oauth_authorization_endpoint t = t.oauth_authorization_endpoint 349 + let oauth_token_endpoint t = t.oauth_token_endpoint 350 + let provide_client_key t = t.provide_client_key 351 + let sign_client_key t = t.sign_client_key 352 + let shared_inbox t = t.shared_inbox 353 + 354 + let jsont = 355 + Jsont.Object.map ~kind:"Endpoints" 356 + (fun proxy_url oauth_authorization_endpoint oauth_token_endpoint 357 + provide_client_key sign_client_key shared_inbox -> 358 + { proxy_url; oauth_authorization_endpoint; oauth_token_endpoint; 359 + provide_client_key; sign_client_key; shared_inbox }) 360 + |> Jsont.Object.opt_mem "proxyUrl" Uri.jsont ~enc:proxy_url 361 + |> Jsont.Object.opt_mem "oauthAuthorizationEndpoint" Uri.jsont 362 + ~enc:oauth_authorization_endpoint 363 + |> Jsont.Object.opt_mem "oauthTokenEndpoint" Uri.jsont 364 + ~enc:oauth_token_endpoint 365 + |> Jsont.Object.opt_mem "provideClientKey" Uri.jsont ~enc:provide_client_key 366 + |> Jsont.Object.opt_mem "signClientKey" Uri.jsont ~enc:sign_client_key 367 + |> Jsont.Object.opt_mem "sharedInbox" Uri.jsont ~enc:shared_inbox 368 + |> Jsont.Object.finish 369 + end 370 + 371 + (** {1 Public Key} *) 372 + 373 + (** Public key for HTTP Signatures. *) 374 + module Public_key : sig 375 + type t 376 + 377 + val make : 378 + id:Uri.t -> 379 + owner:Uri.t -> 380 + public_key_pem:string -> 381 + unit -> t 382 + 383 + val id : t -> Uri.t 384 + val owner : t -> Uri.t 385 + val public_key_pem : t -> string 386 + 387 + val jsont : t Jsont.t 388 + end = struct 389 + type t = { 390 + id : Uri.t; 391 + owner : Uri.t; 392 + public_key_pem : string; 393 + } 394 + 395 + let make ~id ~owner ~public_key_pem () = 396 + { id; owner; public_key_pem } 397 + 398 + let id t = t.id 399 + let owner t = t.owner 400 + let public_key_pem t = t.public_key_pem 401 + 402 + let jsont = 403 + Jsont.Object.map ~kind:"PublicKey" 404 + (fun id owner public_key_pem -> { id; owner; public_key_pem }) 405 + |> Jsont.Object.mem "id" Uri.jsont ~enc:id 406 + |> Jsont.Object.mem "owner" Uri.jsont ~enc:owner 407 + |> Jsont.Object.mem "publicKeyPem" Jsont.string ~enc:public_key_pem 408 + |> Jsont.Object.finish 409 + end 410 + 411 + (** {1 Actor Types} *) 412 + 413 + (** Actor types enumeration. *) 414 + module Actor_type : sig 415 + type t = 416 + | Person 417 + | Service 418 + | Organization 419 + | Group 420 + | Application 421 + 422 + val to_string : t -> string 423 + val of_string : string -> t option 424 + val jsont : t Jsont.t 425 + end = struct 426 + type t = 427 + | Person 428 + | Service 429 + | Organization 430 + | Group 431 + | Application 432 + 433 + let to_string = function 434 + | Person -> "Person" 435 + | Service -> "Service" 436 + | Organization -> "Organization" 437 + | Group -> "Group" 438 + | Application -> "Application" 439 + 440 + let of_string = function 441 + | "Person" -> Some Person 442 + | "Service" -> Some Service 443 + | "Organization" -> Some Organization 444 + | "Group" -> Some Group 445 + | "Application" -> Some Application 446 + | _ -> None 447 + 448 + let jsont = 449 + Jsont.enum ~kind:"ActorType" [ 450 + "Person", Person; 451 + "Service", Service; 452 + "Organization", Organization; 453 + "Group", Group; 454 + "Application", Application; 455 + ] 456 + end 457 + 458 + (** {1 Actor} *) 459 + 460 + (** Actor objects represent entities that can perform activities. 461 + @see <https://www.w3.org/TR/activitypub/#actor-objects> *) 462 + module Actor : sig 463 + type t 464 + 465 + val make : 466 + ?context:Context.t -> 467 + id:Uri.t -> 468 + type_:Actor_type.t -> 469 + ?name:string -> 470 + ?preferred_username:string -> 471 + ?summary:string -> 472 + ?url:Uri.t -> 473 + inbox:Uri.t -> 474 + outbox:Uri.t -> 475 + ?followers:Uri.t -> 476 + ?following:Uri.t -> 477 + ?liked:Uri.t -> 478 + ?streams:Uri.t list -> 479 + ?endpoints:Endpoints.t -> 480 + ?public_key:Public_key.t -> 481 + ?icon:Image_ref.t list -> 482 + ?image:Image_ref.t list -> 483 + ?manually_approves_followers:bool -> 484 + unit -> t 485 + 486 + val context : t -> Context.t option 487 + val id : t -> Uri.t 488 + val type_ : t -> Actor_type.t 489 + val name : t -> string option 490 + val preferred_username : t -> string option 491 + val summary : t -> string option 492 + val url : t -> Uri.t option 493 + val inbox : t -> Uri.t 494 + val outbox : t -> Uri.t 495 + val followers : t -> Uri.t option 496 + val following : t -> Uri.t option 497 + val liked : t -> Uri.t option 498 + val streams : t -> Uri.t list option 499 + val endpoints : t -> Endpoints.t option 500 + val public_key : t -> Public_key.t option 501 + val icon : t -> Image_ref.t list option 502 + val image : t -> Image_ref.t list option 503 + val manually_approves_followers : t -> bool option 504 + 505 + val jsont : t Jsont.t 506 + end = struct 507 + type t = { 508 + context : Context.t option; 509 + id : Uri.t; 510 + type_ : Actor_type.t; 511 + name : string option; 512 + preferred_username : string option; 513 + summary : string option; 514 + url : Uri.t option; 515 + inbox : Uri.t; 516 + outbox : Uri.t; 517 + followers : Uri.t option; 518 + following : Uri.t option; 519 + liked : Uri.t option; 520 + streams : Uri.t list option; 521 + endpoints : Endpoints.t option; 522 + public_key : Public_key.t option; 523 + icon : Image_ref.t list option; 524 + image : Image_ref.t list option; 525 + manually_approves_followers : bool option; 526 + } 527 + 528 + let make ?context ~id ~type_ ?name ?preferred_username ?summary ?url 529 + ~inbox ~outbox ?followers ?following ?liked ?streams ?endpoints 530 + ?public_key ?icon ?image ?manually_approves_followers () = 531 + { context; id; type_; name; preferred_username; summary; url; 532 + inbox; outbox; followers; following; liked; streams; endpoints; 533 + public_key; icon; image; manually_approves_followers } 534 + 535 + let context t = t.context 536 + let id t = t.id 537 + let type_ t = t.type_ 538 + let name t = t.name 539 + let preferred_username t = t.preferred_username 540 + let summary t = t.summary 541 + let url t = t.url 542 + let inbox t = t.inbox 543 + let outbox t = t.outbox 544 + let followers t = t.followers 545 + let following t = t.following 546 + let liked t = t.liked 547 + let streams t = t.streams 548 + let endpoints t = t.endpoints 549 + let public_key t = t.public_key 550 + let icon t = t.icon 551 + let image t = t.image 552 + let manually_approves_followers t = t.manually_approves_followers 553 + 554 + let jsont = 555 + Jsont.Object.map ~kind:"Actor" 556 + (fun context id type_ name preferred_username summary url inbox outbox 557 + followers following liked streams endpoints public_key icon image 558 + manually_approves_followers -> 559 + { context; id; type_; name; preferred_username; summary; url; 560 + inbox; outbox; followers; following; liked; streams; endpoints; 561 + public_key; icon; image; manually_approves_followers }) 562 + |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context 563 + |> Jsont.Object.mem "@id" Uri.jsont ~enc:id 564 + |> Jsont.Object.mem "@type" Actor_type.jsont ~enc:type_ 565 + |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name 566 + |> Jsont.Object.opt_mem "preferredUsername" Jsont.string 567 + ~enc:preferred_username 568 + |> Jsont.Object.opt_mem "summary" Jsont.string ~enc:summary 569 + |> Jsont.Object.opt_mem "url" Uri.jsont ~enc:url 570 + |> Jsont.Object.mem "inbox" Uri.jsont ~enc:inbox 571 + |> Jsont.Object.mem "outbox" Uri.jsont ~enc:outbox 572 + |> Jsont.Object.opt_mem "followers" Uri.jsont ~enc:followers 573 + |> Jsont.Object.opt_mem "following" Uri.jsont ~enc:following 574 + |> Jsont.Object.opt_mem "liked" Uri.jsont ~enc:liked 575 + |> Jsont.Object.opt_mem "streams" (Jsont.list Uri.jsont) ~enc:streams 576 + |> Jsont.Object.opt_mem "endpoints" Endpoints.jsont ~enc:endpoints 577 + |> Jsont.Object.opt_mem "publicKey" Public_key.jsont ~enc:public_key 578 + |> Jsont.Object.opt_mem "icon" (Jsont.list Image_ref.jsont) ~enc:icon 579 + |> Jsont.Object.opt_mem "image" (Jsont.list Image_ref.jsont) ~enc:image 580 + |> Jsont.Object.opt_mem "manuallyApprovesFollowers" Jsont.bool 581 + ~enc:manually_approves_followers 582 + |> Jsont.Object.finish 583 + end 584 + 585 + (** Actor reference - can be URI or full Actor object. *) 586 + module Actor_ref : sig 587 + type t = 588 + | Uri of Uri.t 589 + | Actor of Actor.t 590 + 591 + val uri : Uri.t -> t 592 + val actor : Actor.t -> t 593 + val jsont : t Jsont.t 594 + end = struct 595 + type t = 596 + | Uri of Uri.t 597 + | Actor of Actor.t 598 + 599 + let uri u = Uri u 600 + let actor a = Actor a 601 + 602 + let jsont = 603 + let dec_string = Jsont.map Uri.jsont 604 + ~dec:(fun u -> Uri u) 605 + ~enc:(function Uri u -> u | Actor _ -> assert false) in 606 + let dec_object = Jsont.map Actor.jsont 607 + ~dec:(fun a -> Actor a) 608 + ~enc:(function Actor a -> a | Uri _ -> assert false) in 609 + Jsont.any ~kind:"Actor reference" 610 + ~dec_string ~dec_object 611 + ~enc:(function 612 + | Uri _ -> dec_string 613 + | Actor _ -> dec_object) 614 + () 615 + end 616 + 617 + (** {1 Object Types} *) 618 + 619 + (** Object types enumeration. *) 620 + module Object_type : sig 621 + type t = 622 + | Note 623 + | Article 624 + | Page 625 + | Event 626 + | Image 627 + | Video 628 + | Audio 629 + | Document 630 + | Place 631 + | Profile 632 + | Tombstone 633 + | Collection 634 + | OrderedCollection 635 + 636 + val to_string : t -> string 637 + val of_string : string -> t option 638 + val jsont : t Jsont.t 639 + end = struct 640 + type t = 641 + | Note 642 + | Article 643 + | Page 644 + | Event 645 + | Image 646 + | Video 647 + | Audio 648 + | Document 649 + | Place 650 + | Profile 651 + | Tombstone 652 + | Collection 653 + | OrderedCollection 654 + 655 + let to_string = function 656 + | Note -> "Note" 657 + | Article -> "Article" 658 + | Page -> "Page" 659 + | Event -> "Event" 660 + | Image -> "Image" 661 + | Video -> "Video" 662 + | Audio -> "Audio" 663 + | Document -> "Document" 664 + | Place -> "Place" 665 + | Profile -> "Profile" 666 + | Tombstone -> "Tombstone" 667 + | Collection -> "Collection" 668 + | OrderedCollection -> "OrderedCollection" 669 + 670 + let of_string = function 671 + | "Note" -> Some Note 672 + | "Article" -> Some Article 673 + | "Page" -> Some Page 674 + | "Event" -> Some Event 675 + | "Image" -> Some Image 676 + | "Video" -> Some Video 677 + | "Audio" -> Some Audio 678 + | "Document" -> Some Document 679 + | "Place" -> Some Place 680 + | "Profile" -> Some Profile 681 + | "Tombstone" -> Some Tombstone 682 + | "Collection" -> Some Collection 683 + | "OrderedCollection" -> Some OrderedCollection 684 + | _ -> None 685 + 686 + let jsont = 687 + Jsont.enum ~kind:"ObjectType" [ 688 + "Note", Note; 689 + "Article", Article; 690 + "Page", Page; 691 + "Event", Event; 692 + "Image", Image; 693 + "Video", Video; 694 + "Audio", Audio; 695 + "Document", Document; 696 + "Place", Place; 697 + "Profile", Profile; 698 + "Tombstone", Tombstone; 699 + "Collection", Collection; 700 + "OrderedCollection", OrderedCollection; 701 + ] 702 + end 703 + 704 + (** {1 Object} *) 705 + 706 + (** ActivityStreams objects. 707 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#object-types> *) 708 + module Object : sig 709 + type t 710 + 711 + val make : 712 + ?context:Context.t -> 713 + ?id:Uri.t -> 714 + type_:Object_type.t -> 715 + ?name:string -> 716 + ?summary:string -> 717 + ?content:string -> 718 + ?media_type:string -> 719 + ?url:Link_or_uri.t list -> 720 + ?attributed_to:Actor_ref.t -> 721 + ?in_reply_to:Uri.t -> 722 + ?published:Datetime.t -> 723 + ?updated:Datetime.t -> 724 + ?deleted:Datetime.t -> 725 + ?to_:Recipient.t list -> 726 + ?cc:Recipient.t list -> 727 + ?bto:Recipient.t list -> 728 + ?bcc:Recipient.t list -> 729 + ?replies:Uri.t -> 730 + ?attachment:Link_or_uri.t list -> 731 + ?tag:Link_or_uri.t list -> 732 + ?generator:Uri.t -> 733 + ?icon:Image_ref.t list -> 734 + ?image:Image_ref.t list -> 735 + ?start_time:Datetime.t -> 736 + ?end_time:Datetime.t -> 737 + ?duration:string -> 738 + ?sensitive:bool -> 739 + unit -> t 740 + 741 + val context : t -> Context.t option 742 + val id : t -> Uri.t option 743 + val type_ : t -> Object_type.t 744 + val name : t -> string option 745 + val summary : t -> string option 746 + val content : t -> string option 747 + val media_type : t -> string option 748 + val url : t -> Link_or_uri.t list option 749 + val attributed_to : t -> Actor_ref.t option 750 + val in_reply_to : t -> Uri.t option 751 + val published : t -> Datetime.t option 752 + val updated : t -> Datetime.t option 753 + val deleted : t -> Datetime.t option 754 + val to_ : t -> Recipient.t list option 755 + val cc : t -> Recipient.t list option 756 + val bto : t -> Recipient.t list option 757 + val bcc : t -> Recipient.t list option 758 + val replies : t -> Uri.t option 759 + val attachment : t -> Link_or_uri.t list option 760 + val tag : t -> Link_or_uri.t list option 761 + val generator : t -> Uri.t option 762 + val icon : t -> Image_ref.t list option 763 + val image : t -> Image_ref.t list option 764 + val start_time : t -> Datetime.t option 765 + val end_time : t -> Datetime.t option 766 + val duration : t -> string option 767 + val sensitive : t -> bool option 768 + 769 + val jsont : t Jsont.t 770 + end = struct 771 + type t = { 772 + context : Context.t option; 773 + id : Uri.t option; 774 + type_ : Object_type.t; 775 + name : string option; 776 + summary : string option; 777 + content : string option; 778 + media_type : string option; 779 + url : Link_or_uri.t list option; 780 + attributed_to : Actor_ref.t option; 781 + in_reply_to : Uri.t option; 782 + published : Datetime.t option; 783 + updated : Datetime.t option; 784 + deleted : Datetime.t option; 785 + to_ : Recipient.t list option; 786 + cc : Recipient.t list option; 787 + bto : Recipient.t list option; 788 + bcc : Recipient.t list option; 789 + replies : Uri.t option; 790 + attachment : Link_or_uri.t list option; 791 + tag : Link_or_uri.t list option; 792 + generator : Uri.t option; 793 + icon : Image_ref.t list option; 794 + image : Image_ref.t list option; 795 + start_time : Datetime.t option; 796 + end_time : Datetime.t option; 797 + duration : string option; 798 + sensitive : bool option; 799 + } 800 + 801 + let make ?context ?id ~type_ ?name ?summary ?content ?media_type ?url 802 + ?attributed_to ?in_reply_to ?published ?updated ?deleted ?to_ ?cc 803 + ?bto ?bcc ?replies ?attachment ?tag ?generator ?icon ?image 804 + ?start_time ?end_time ?duration ?sensitive () = 805 + { context; id; type_; name; summary; content; media_type; url; 806 + attributed_to; in_reply_to; published; updated; deleted; 807 + to_; cc; bto; bcc; replies; attachment; tag; generator; 808 + icon; image; start_time; end_time; duration; sensitive } 809 + 810 + let context t = t.context 811 + let id t = t.id 812 + let type_ t = t.type_ 813 + let name t = t.name 814 + let summary t = t.summary 815 + let content t = t.content 816 + let media_type t = t.media_type 817 + let url t = t.url 818 + let attributed_to t = t.attributed_to 819 + let in_reply_to t = t.in_reply_to 820 + let published t = t.published 821 + let updated t = t.updated 822 + let deleted t = t.deleted 823 + let to_ t = t.to_ 824 + let cc t = t.cc 825 + let bto t = t.bto 826 + let bcc t = t.bcc 827 + let replies t = t.replies 828 + let attachment t = t.attachment 829 + let tag t = t.tag 830 + let generator t = t.generator 831 + let icon t = t.icon 832 + let image t = t.image 833 + let start_time t = t.start_time 834 + let end_time t = t.end_time 835 + let duration t = t.duration 836 + let sensitive t = t.sensitive 837 + 838 + let jsont = 839 + Jsont.Object.map ~kind:"Object" 840 + (fun context id type_ name summary content media_type url attributed_to 841 + in_reply_to published updated deleted to_ cc bto bcc replies 842 + attachment tag generator icon image start_time end_time duration 843 + sensitive -> 844 + { context; id; type_; name; summary; content; media_type; url; 845 + attributed_to; in_reply_to; published; updated; deleted; 846 + to_; cc; bto; bcc; replies; attachment; tag; generator; 847 + icon; image; start_time; end_time; duration; sensitive }) 848 + |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context 849 + |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id 850 + |> Jsont.Object.mem "@type" Object_type.jsont ~enc:type_ 851 + |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name 852 + |> Jsont.Object.opt_mem "summary" Jsont.string ~enc:summary 853 + |> Jsont.Object.opt_mem "content" Jsont.string ~enc:content 854 + |> Jsont.Object.opt_mem "mediaType" Jsont.string ~enc:media_type 855 + |> Jsont.Object.opt_mem "url" (Jsont.list Link_or_uri.jsont) ~enc:url 856 + |> Jsont.Object.opt_mem "attributedTo" Actor_ref.jsont ~enc:attributed_to 857 + |> Jsont.Object.opt_mem "inReplyTo" Uri.jsont ~enc:in_reply_to 858 + |> Jsont.Object.opt_mem "published" Datetime.jsont ~enc:published 859 + |> Jsont.Object.opt_mem "updated" Datetime.jsont ~enc:updated 860 + |> Jsont.Object.opt_mem "deleted" Datetime.jsont ~enc:deleted 861 + |> Jsont.Object.opt_mem "to" (Jsont.list Recipient.jsont) ~enc:to_ 862 + |> Jsont.Object.opt_mem "cc" (Jsont.list Recipient.jsont) ~enc:cc 863 + |> Jsont.Object.opt_mem "bto" (Jsont.list Recipient.jsont) ~enc:bto 864 + |> Jsont.Object.opt_mem "bcc" (Jsont.list Recipient.jsont) ~enc:bcc 865 + |> Jsont.Object.opt_mem "replies" Uri.jsont ~enc:replies 866 + |> Jsont.Object.opt_mem "attachment" (Jsont.list Link_or_uri.jsont) 867 + ~enc:attachment 868 + |> Jsont.Object.opt_mem "tag" (Jsont.list Link_or_uri.jsont) ~enc:tag 869 + |> Jsont.Object.opt_mem "generator" Uri.jsont ~enc:generator 870 + |> Jsont.Object.opt_mem "icon" (Jsont.list Image_ref.jsont) ~enc:icon 871 + |> Jsont.Object.opt_mem "image" (Jsont.list Image_ref.jsont) ~enc:image 872 + |> Jsont.Object.opt_mem "startTime" Datetime.jsont ~enc:start_time 873 + |> Jsont.Object.opt_mem "endTime" Datetime.jsont ~enc:end_time 874 + |> Jsont.Object.opt_mem "duration" Jsont.string ~enc:duration 875 + |> Jsont.Object.opt_mem "sensitive" Jsont.bool ~enc:sensitive 876 + |> Jsont.Object.finish 877 + end 878 + 879 + (** Object reference - can be URI or full Object. *) 880 + module Object_ref : sig 881 + type t = 882 + | Uri of Uri.t 883 + | Object of Object.t 884 + 885 + val uri : Uri.t -> t 886 + val obj : Object.t -> t 887 + val jsont : t Jsont.t 888 + end = struct 889 + type t = 890 + | Uri of Uri.t 891 + | Object of Object.t 892 + 893 + let uri u = Uri u 894 + let obj o = Object o 895 + 896 + let jsont = 897 + let dec_string = Jsont.map Uri.jsont 898 + ~dec:(fun u -> Uri u) 899 + ~enc:(function Uri u -> u | Object _ -> assert false) in 900 + let dec_object = Jsont.map Object.jsont 901 + ~dec:(fun o -> Object o) 902 + ~enc:(function Object o -> o | Uri _ -> assert false) in 903 + Jsont.any ~kind:"Object reference" 904 + ~dec_string ~dec_object 905 + ~enc:(function 906 + | Uri _ -> dec_string 907 + | Object _ -> dec_object) 908 + () 909 + end 910 + 911 + (** {1 Activity Types} *) 912 + 913 + (** Activity types enumeration. *) 914 + module Activity_type : sig 915 + type t = 916 + | Create 917 + | Update 918 + | Delete 919 + | Follow 920 + | Accept 921 + | Reject 922 + | Add 923 + | Remove 924 + | Like 925 + | Announce 926 + | Undo 927 + | Block 928 + | Flag 929 + | Dislike 930 + | Ignore 931 + | Invite 932 + | Join 933 + | Leave 934 + | Listen 935 + | Move 936 + | Offer 937 + | Question 938 + | Read 939 + | TentativeAccept 940 + | TentativeReject 941 + | Travel 942 + | View 943 + 944 + val to_string : t -> string 945 + val of_string : string -> t option 946 + val jsont : t Jsont.t 947 + end = struct 948 + type t = 949 + | Create 950 + | Update 951 + | Delete 952 + | Follow 953 + | Accept 954 + | Reject 955 + | Add 956 + | Remove 957 + | Like 958 + | Announce 959 + | Undo 960 + | Block 961 + | Flag 962 + | Dislike 963 + | Ignore 964 + | Invite 965 + | Join 966 + | Leave 967 + | Listen 968 + | Move 969 + | Offer 970 + | Question 971 + | Read 972 + | TentativeAccept 973 + | TentativeReject 974 + | Travel 975 + | View 976 + 977 + let to_string = function 978 + | Create -> "Create" 979 + | Update -> "Update" 980 + | Delete -> "Delete" 981 + | Follow -> "Follow" 982 + | Accept -> "Accept" 983 + | Reject -> "Reject" 984 + | Add -> "Add" 985 + | Remove -> "Remove" 986 + | Like -> "Like" 987 + | Announce -> "Announce" 988 + | Undo -> "Undo" 989 + | Block -> "Block" 990 + | Flag -> "Flag" 991 + | Dislike -> "Dislike" 992 + | Ignore -> "Ignore" 993 + | Invite -> "Invite" 994 + | Join -> "Join" 995 + | Leave -> "Leave" 996 + | Listen -> "Listen" 997 + | Move -> "Move" 998 + | Offer -> "Offer" 999 + | Question -> "Question" 1000 + | Read -> "Read" 1001 + | TentativeAccept -> "TentativeAccept" 1002 + | TentativeReject -> "TentativeReject" 1003 + | Travel -> "Travel" 1004 + | View -> "View" 1005 + 1006 + let of_string = function 1007 + | "Create" -> Some Create 1008 + | "Update" -> Some Update 1009 + | "Delete" -> Some Delete 1010 + | "Follow" -> Some Follow 1011 + | "Accept" -> Some Accept 1012 + | "Reject" -> Some Reject 1013 + | "Add" -> Some Add 1014 + | "Remove" -> Some Remove 1015 + | "Like" -> Some Like 1016 + | "Announce" -> Some Announce 1017 + | "Undo" -> Some Undo 1018 + | "Block" -> Some Block 1019 + | "Flag" -> Some Flag 1020 + | "Dislike" -> Some Dislike 1021 + | "Ignore" -> Some Ignore 1022 + | "Invite" -> Some Invite 1023 + | "Join" -> Some Join 1024 + | "Leave" -> Some Leave 1025 + | "Listen" -> Some Listen 1026 + | "Move" -> Some Move 1027 + | "Offer" -> Some Offer 1028 + | "Question" -> Some Question 1029 + | "Read" -> Some Read 1030 + | "TentativeAccept" -> Some TentativeAccept 1031 + | "TentativeReject" -> Some TentativeReject 1032 + | "Travel" -> Some Travel 1033 + | "View" -> Some View 1034 + | _ -> None 1035 + 1036 + let jsont = 1037 + Jsont.enum ~kind:"ActivityType" [ 1038 + "Create", Create; 1039 + "Update", Update; 1040 + "Delete", Delete; 1041 + "Follow", Follow; 1042 + "Accept", Accept; 1043 + "Reject", Reject; 1044 + "Add", Add; 1045 + "Remove", Remove; 1046 + "Like", Like; 1047 + "Announce", Announce; 1048 + "Undo", Undo; 1049 + "Block", Block; 1050 + "Flag", Flag; 1051 + "Dislike", Dislike; 1052 + "Ignore", Ignore; 1053 + "Invite", Invite; 1054 + "Join", Join; 1055 + "Leave", Leave; 1056 + "Listen", Listen; 1057 + "Move", Move; 1058 + "Offer", Offer; 1059 + "Question", Question; 1060 + "Read", Read; 1061 + "TentativeAccept", TentativeAccept; 1062 + "TentativeReject", TentativeReject; 1063 + "Travel", Travel; 1064 + "View", View; 1065 + ] 1066 + end 1067 + 1068 + (** {1 Activity} *) 1069 + 1070 + (** ActivityPub activities. 1071 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#activity-types> *) 1072 + module Activity : sig 1073 + type t 1074 + 1075 + val make : 1076 + ?context:Context.t -> 1077 + ?id:Uri.t -> 1078 + type_:Activity_type.t -> 1079 + actor:Actor_ref.t -> 1080 + ?object_:Object_ref.t -> 1081 + ?target:Object_ref.t -> 1082 + ?result:Object_ref.t -> 1083 + ?origin:Object_ref.t -> 1084 + ?instrument:Object_ref.t -> 1085 + ?to_:Recipient.t list -> 1086 + ?cc:Recipient.t list -> 1087 + ?bto:Recipient.t list -> 1088 + ?bcc:Recipient.t list -> 1089 + ?published:Datetime.t -> 1090 + ?updated:Datetime.t -> 1091 + ?summary:string -> 1092 + unit -> t 1093 + 1094 + val context : t -> Context.t option 1095 + val id : t -> Uri.t option 1096 + val type_ : t -> Activity_type.t 1097 + val actor : t -> Actor_ref.t 1098 + val object_ : t -> Object_ref.t option 1099 + val target : t -> Object_ref.t option 1100 + val result : t -> Object_ref.t option 1101 + val origin : t -> Object_ref.t option 1102 + val instrument : t -> Object_ref.t option 1103 + val to_ : t -> Recipient.t list option 1104 + val cc : t -> Recipient.t list option 1105 + val bto : t -> Recipient.t list option 1106 + val bcc : t -> Recipient.t list option 1107 + val published : t -> Datetime.t option 1108 + val updated : t -> Datetime.t option 1109 + val summary : t -> string option 1110 + 1111 + val jsont : t Jsont.t 1112 + end = struct 1113 + type t = { 1114 + context : Context.t option; 1115 + id : Uri.t option; 1116 + type_ : Activity_type.t; 1117 + actor : Actor_ref.t; 1118 + object_ : Object_ref.t option; 1119 + target : Object_ref.t option; 1120 + result : Object_ref.t option; 1121 + origin : Object_ref.t option; 1122 + instrument : Object_ref.t option; 1123 + to_ : Recipient.t list option; 1124 + cc : Recipient.t list option; 1125 + bto : Recipient.t list option; 1126 + bcc : Recipient.t list option; 1127 + published : Datetime.t option; 1128 + updated : Datetime.t option; 1129 + summary : string option; 1130 + } 1131 + 1132 + let make ?context ?id ~type_ ~actor ?object_ ?target ?result ?origin 1133 + ?instrument ?to_ ?cc ?bto ?bcc ?published ?updated ?summary () = 1134 + { context; id; type_; actor; object_; target; result; origin; 1135 + instrument; to_; cc; bto; bcc; published; updated; summary } 1136 + 1137 + let context t = t.context 1138 + let id t = t.id 1139 + let type_ t = t.type_ 1140 + let actor t = t.actor 1141 + let object_ t = t.object_ 1142 + let target t = t.target 1143 + let result t = t.result 1144 + let origin t = t.origin 1145 + let instrument t = t.instrument 1146 + let to_ t = t.to_ 1147 + let cc t = t.cc 1148 + let bto t = t.bto 1149 + let bcc t = t.bcc 1150 + let published t = t.published 1151 + let updated t = t.updated 1152 + let summary t = t.summary 1153 + 1154 + let jsont = 1155 + Jsont.Object.map ~kind:"Activity" 1156 + (fun context id type_ actor object_ target result origin instrument 1157 + to_ cc bto bcc published updated summary -> 1158 + { context; id; type_; actor; object_; target; result; origin; 1159 + instrument; to_; cc; bto; bcc; published; updated; summary }) 1160 + |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context 1161 + |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id 1162 + |> Jsont.Object.mem "@type" Activity_type.jsont ~enc:type_ 1163 + |> Jsont.Object.mem "actor" Actor_ref.jsont ~enc:actor 1164 + |> Jsont.Object.opt_mem "object" Object_ref.jsont ~enc:object_ 1165 + |> Jsont.Object.opt_mem "target" Object_ref.jsont ~enc:target 1166 + |> Jsont.Object.opt_mem "result" Object_ref.jsont ~enc:result 1167 + |> Jsont.Object.opt_mem "origin" Object_ref.jsont ~enc:origin 1168 + |> Jsont.Object.opt_mem "instrument" Object_ref.jsont ~enc:instrument 1169 + |> Jsont.Object.opt_mem "to" (Jsont.list Recipient.jsont) ~enc:to_ 1170 + |> Jsont.Object.opt_mem "cc" (Jsont.list Recipient.jsont) ~enc:cc 1171 + |> Jsont.Object.opt_mem "bto" (Jsont.list Recipient.jsont) ~enc:bto 1172 + |> Jsont.Object.opt_mem "bcc" (Jsont.list Recipient.jsont) ~enc:bcc 1173 + |> Jsont.Object.opt_mem "published" Datetime.jsont ~enc:published 1174 + |> Jsont.Object.opt_mem "updated" Datetime.jsont ~enc:updated 1175 + |> Jsont.Object.opt_mem "summary" Jsont.string ~enc:summary 1176 + |> Jsont.Object.finish 1177 + end 1178 + 1179 + (** Activity reference - can be URI or full Activity. *) 1180 + module Activity_ref : sig 1181 + type t = 1182 + | Uri of Uri.t 1183 + | Activity of Activity.t 1184 + 1185 + val uri : Uri.t -> t 1186 + val activity : Activity.t -> t 1187 + val jsont : t Jsont.t 1188 + end = struct 1189 + type t = 1190 + | Uri of Uri.t 1191 + | Activity of Activity.t 1192 + 1193 + let uri u = Uri u 1194 + let activity a = Activity a 1195 + 1196 + let jsont = 1197 + let dec_string = Jsont.map Uri.jsont 1198 + ~dec:(fun u -> Uri u) 1199 + ~enc:(function Uri u -> u | Activity _ -> assert false) in 1200 + let dec_object = Jsont.map Activity.jsont 1201 + ~dec:(fun a -> Activity a) 1202 + ~enc:(function Activity a -> a | Uri _ -> assert false) in 1203 + Jsont.any ~kind:"Activity reference" 1204 + ~dec_string ~dec_object 1205 + ~enc:(function 1206 + | Uri _ -> dec_string 1207 + | Activity _ -> dec_object) 1208 + () 1209 + end 1210 + 1211 + (** {1 Collection} *) 1212 + 1213 + (** Collection objects. 1214 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection> *) 1215 + module Collection : sig 1216 + type 'a t 1217 + 1218 + val make : 1219 + ?context:Context.t -> 1220 + ?id:Uri.t -> 1221 + ?total_items:int -> 1222 + ?current:Uri.t -> 1223 + ?first:Uri.t -> 1224 + ?last:Uri.t -> 1225 + ?items:'a list -> 1226 + ordered:bool -> 1227 + unit -> 'a t 1228 + 1229 + val context : 'a t -> Context.t option 1230 + val id : 'a t -> Uri.t option 1231 + val total_items : 'a t -> int option 1232 + val current : 'a t -> Uri.t option 1233 + val first : 'a t -> Uri.t option 1234 + val last : 'a t -> Uri.t option 1235 + val items : 'a t -> 'a list option 1236 + val ordered : 'a t -> bool 1237 + 1238 + val jsont : 'a Jsont.t -> 'a t Jsont.t 1239 + end = struct 1240 + type 'a t = { 1241 + context : Context.t option; 1242 + id : Uri.t option; 1243 + total_items : int option; 1244 + current : Uri.t option; 1245 + first : Uri.t option; 1246 + last : Uri.t option; 1247 + items : 'a list option; 1248 + ordered : bool; 1249 + } 1250 + 1251 + let make ?context ?id ?total_items ?current ?first ?last ?items ~ordered () = 1252 + { context; id; total_items; current; first; last; items; ordered } 1253 + 1254 + let context t = t.context 1255 + let id t = t.id 1256 + let total_items t = t.total_items 1257 + let current t = t.current 1258 + let first t = t.first 1259 + let last t = t.last 1260 + let items t = t.items 1261 + let ordered t = t.ordered 1262 + 1263 + let jsont item_jsont = 1264 + let type_jsont = 1265 + Jsont.enum ~kind:"CollectionType" [ 1266 + "Collection", false; 1267 + "OrderedCollection", true; 1268 + ] 1269 + in 1270 + Jsont.Object.map ~kind:"Collection" 1271 + (fun context id ordered total_items current first last items -> 1272 + { context; id; total_items; current; first; last; items; ordered }) 1273 + |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context 1274 + |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id 1275 + |> Jsont.Object.mem "@type" type_jsont ~enc:ordered 1276 + |> Jsont.Object.opt_mem "totalItems" Jsont.int ~enc:total_items 1277 + |> Jsont.Object.opt_mem "current" Uri.jsont ~enc:current 1278 + |> Jsont.Object.opt_mem "first" Uri.jsont ~enc:first 1279 + |> Jsont.Object.opt_mem "last" Uri.jsont ~enc:last 1280 + |> Jsont.Object.opt_mem "items" (Jsont.list item_jsont) ~enc:items 1281 + |> Jsont.Object.finish 1282 + end 1283 + 1284 + (** {1 Collection Page} *) 1285 + 1286 + (** Collection page objects. 1287 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage> *) 1288 + module Collection_page : sig 1289 + type 'a t 1290 + 1291 + val make : 1292 + ?context:Context.t -> 1293 + ?id:Uri.t -> 1294 + ?total_items:int -> 1295 + ?current:Uri.t -> 1296 + ?first:Uri.t -> 1297 + ?last:Uri.t -> 1298 + ?prev:Uri.t -> 1299 + ?next:Uri.t -> 1300 + ?part_of:Uri.t -> 1301 + ?items:'a list -> 1302 + ordered:bool -> 1303 + unit -> 'a t 1304 + 1305 + val context : 'a t -> Context.t option 1306 + val id : 'a t -> Uri.t option 1307 + val total_items : 'a t -> int option 1308 + val current : 'a t -> Uri.t option 1309 + val first : 'a t -> Uri.t option 1310 + val last : 'a t -> Uri.t option 1311 + val prev : 'a t -> Uri.t option 1312 + val next : 'a t -> Uri.t option 1313 + val part_of : 'a t -> Uri.t option 1314 + val items : 'a t -> 'a list option 1315 + val ordered : 'a t -> bool 1316 + 1317 + val jsont : 'a Jsont.t -> 'a t Jsont.t 1318 + end = struct 1319 + type 'a t = { 1320 + context : Context.t option; 1321 + id : Uri.t option; 1322 + total_items : int option; 1323 + current : Uri.t option; 1324 + first : Uri.t option; 1325 + last : Uri.t option; 1326 + prev : Uri.t option; 1327 + next : Uri.t option; 1328 + part_of : Uri.t option; 1329 + items : 'a list option; 1330 + ordered : bool; 1331 + } 1332 + 1333 + let make ?context ?id ?total_items ?current ?first ?last ?prev ?next 1334 + ?part_of ?items ~ordered () = 1335 + { context; id; total_items; current; first; last; prev; next; 1336 + part_of; items; ordered } 1337 + 1338 + let context t = t.context 1339 + let id t = t.id 1340 + let total_items t = t.total_items 1341 + let current t = t.current 1342 + let first t = t.first 1343 + let last t = t.last 1344 + let prev t = t.prev 1345 + let next t = t.next 1346 + let part_of t = t.part_of 1347 + let items t = t.items 1348 + let ordered t = t.ordered 1349 + 1350 + let jsont item_jsont = 1351 + let type_jsont = 1352 + Jsont.enum ~kind:"CollectionPageType" [ 1353 + "CollectionPage", false; 1354 + "OrderedCollectionPage", true; 1355 + ] 1356 + in 1357 + Jsont.Object.map ~kind:"CollectionPage" 1358 + (fun context id ordered total_items current first last prev next 1359 + part_of items -> 1360 + { context; id; total_items; current; first; last; prev; next; 1361 + part_of; items; ordered }) 1362 + |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context 1363 + |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id 1364 + |> Jsont.Object.mem "@type" type_jsont ~enc:ordered 1365 + |> Jsont.Object.opt_mem "totalItems" Jsont.int ~enc:total_items 1366 + |> Jsont.Object.opt_mem "current" Uri.jsont ~enc:current 1367 + |> Jsont.Object.opt_mem "first" Uri.jsont ~enc:first 1368 + |> Jsont.Object.opt_mem "last" Uri.jsont ~enc:last 1369 + |> Jsont.Object.opt_mem "prev" Uri.jsont ~enc:prev 1370 + |> Jsont.Object.opt_mem "next" Uri.jsont ~enc:next 1371 + |> Jsont.Object.opt_mem "partOf" Uri.jsont ~enc:part_of 1372 + |> Jsont.Object.opt_mem "items" (Jsont.list item_jsont) ~enc:items 1373 + |> Jsont.Object.finish 1374 + end 1375 + 1376 + (** {1 Convenience type aliases} *) 1377 + 1378 + (** Activity collection. *) 1379 + module Activity_collection : sig 1380 + type t = Activity.t Collection.t 1381 + val jsont : t Jsont.t 1382 + end = struct 1383 + type t = Activity.t Collection.t 1384 + let jsont = Collection.jsont Activity.jsont 1385 + end 1386 + 1387 + (** Object collection. *) 1388 + module Object_collection : sig 1389 + type t = Object.t Collection.t 1390 + val jsont : t Jsont.t 1391 + end = struct 1392 + type t = Object.t Collection.t 1393 + let jsont = Collection.jsont Object.jsont 1394 + end 1395 + 1396 + (** Activity collection page. *) 1397 + module Activity_collection_page : sig 1398 + type t = Activity.t Collection_page.t 1399 + val jsont : t Jsont.t 1400 + end = struct 1401 + type t = Activity.t Collection_page.t 1402 + let jsont = Collection_page.jsont Activity.jsont 1403 + end 1404 + 1405 + (** Object collection page. *) 1406 + module Object_collection_page : sig 1407 + type t = Object.t Collection_page.t 1408 + val jsont : t Jsont.t 1409 + end = struct 1410 + type t = Object.t Collection_page.t 1411 + let jsont = Collection_page.jsont Object.jsont 1412 + end 1413 + 1414 + (** {1 Webfinger} *) 1415 + 1416 + (** Webfinger JRD (JSON Resource Descriptor) for actor discovery. 1417 + @see <https://www.rfc-editor.org/rfc/rfc7033> Webfinger RFC *) 1418 + module Webfinger : sig 1419 + (** A link in the Webfinger response. *) 1420 + module Jrd_link : sig 1421 + type t 1422 + 1423 + val make : 1424 + rel:string -> 1425 + ?type_:string -> 1426 + ?href:Uri.t -> 1427 + ?template:string -> 1428 + unit -> t 1429 + 1430 + val rel : t -> string 1431 + val type_ : t -> string option 1432 + val href : t -> Uri.t option 1433 + val template : t -> string option 1434 + 1435 + val jsont : t Jsont.t 1436 + end 1437 + 1438 + (** The Webfinger JRD response. *) 1439 + type t 1440 + 1441 + val make : 1442 + subject:string -> 1443 + ?aliases:string list -> 1444 + ?properties:(string * string) list -> 1445 + ?links:Jrd_link.t list -> 1446 + unit -> t 1447 + 1448 + val subject : t -> string 1449 + val aliases : t -> string list option 1450 + val properties : t -> (string * string) list option 1451 + val links : t -> Jrd_link.t list option 1452 + 1453 + val jsont : t Jsont.t 1454 + end = struct 1455 + module Jrd_link = struct 1456 + type t = { 1457 + rel : string; 1458 + type_ : string option; 1459 + href : Uri.t option; 1460 + template : string option; 1461 + } 1462 + 1463 + let make ~rel ?type_ ?href ?template () = 1464 + { rel; type_; href; template } 1465 + 1466 + let rel t = t.rel 1467 + let type_ t = t.type_ 1468 + let href t = t.href 1469 + let template t = t.template 1470 + 1471 + let jsont = 1472 + Jsont.Object.map ~kind:"JrdLink" 1473 + (fun rel type_ href template -> { rel; type_; href; template }) 1474 + |> Jsont.Object.mem "rel" Jsont.string ~enc:rel 1475 + |> Jsont.Object.opt_mem "type" Jsont.string ~enc:type_ 1476 + |> Jsont.Object.opt_mem "href" Uri.jsont ~enc:href 1477 + |> Jsont.Object.opt_mem "template" Jsont.string ~enc:template 1478 + |> Jsont.Object.finish 1479 + end 1480 + 1481 + type t = { 1482 + subject : string; 1483 + aliases : string list option; 1484 + properties : (string * string) list option; 1485 + links : Jrd_link.t list option; 1486 + } 1487 + 1488 + let make ~subject ?aliases ?properties ?links () = 1489 + { subject; aliases; properties; links } 1490 + 1491 + let subject t = t.subject 1492 + let aliases t = t.aliases 1493 + let properties t = t.properties 1494 + let links t = t.links 1495 + 1496 + module String_map = Map.Make(String) 1497 + 1498 + let properties_jsont = 1499 + Jsont.Object.as_string_map Jsont.string 1500 + |> Jsont.map 1501 + ~dec:(fun m -> String_map.bindings m) 1502 + ~enc:(fun l -> List.fold_left (fun m (k, v) -> 1503 + String_map.add k v m) String_map.empty l) 1504 + 1505 + let jsont = 1506 + Jsont.Object.map ~kind:"Webfinger" 1507 + (fun subject aliases properties links -> 1508 + { subject; aliases; properties; links }) 1509 + |> Jsont.Object.mem "subject" Jsont.string ~enc:subject 1510 + |> Jsont.Object.opt_mem "aliases" (Jsont.list Jsont.string) ~enc:aliases 1511 + |> Jsont.Object.opt_mem "properties" properties_jsont ~enc:properties 1512 + |> Jsont.Object.opt_mem "links" (Jsont.list Jrd_link.jsont) ~enc:links 1513 + |> Jsont.Object.finish 1514 + end 1515 + 1516 + (** {1 NodeInfo} *) 1517 + 1518 + (** NodeInfo protocol for server metadata discovery. 1519 + @see <https://nodeinfo.diaspora.software/> NodeInfo specification *) 1520 + module Nodeinfo : sig 1521 + (** Software information. *) 1522 + module Software : sig 1523 + type t 1524 + 1525 + val make : 1526 + name:string -> 1527 + version:string -> 1528 + ?repository:Uri.t -> 1529 + ?homepage:Uri.t -> 1530 + unit -> t 1531 + 1532 + val name : t -> string 1533 + val version : t -> string 1534 + val repository : t -> Uri.t option 1535 + val homepage : t -> Uri.t option 1536 + 1537 + val jsont : t Jsont.t 1538 + end 1539 + 1540 + (** Usage statistics. *) 1541 + module Usage : sig 1542 + type t 1543 + 1544 + val make : 1545 + ?users_total:int -> 1546 + ?users_active_half_year:int -> 1547 + ?users_active_month:int -> 1548 + ?local_posts:int -> 1549 + ?local_comments:int -> 1550 + unit -> t 1551 + 1552 + val users_total : t -> int option 1553 + val users_active_half_year : t -> int option 1554 + val users_active_month : t -> int option 1555 + val local_posts : t -> int option 1556 + val local_comments : t -> int option 1557 + 1558 + val jsont : t Jsont.t 1559 + end 1560 + 1561 + type t 1562 + 1563 + val make : 1564 + version:string -> 1565 + software:Software.t -> 1566 + protocols:string list -> 1567 + usage:Usage.t -> 1568 + open_registrations:bool -> 1569 + ?metadata:Jsont.json -> 1570 + unit -> t 1571 + 1572 + val version : t -> string 1573 + val software : t -> Software.t 1574 + val protocols : t -> string list 1575 + val usage : t -> Usage.t 1576 + val open_registrations : t -> bool 1577 + val metadata : t -> Jsont.json option 1578 + 1579 + val jsont : t Jsont.t 1580 + end = struct 1581 + module Software = struct 1582 + type t = { 1583 + name : string; 1584 + version : string; 1585 + repository : Uri.t option; 1586 + homepage : Uri.t option; 1587 + } 1588 + 1589 + let make ~name ~version ?repository ?homepage () = 1590 + { name; version; repository; homepage } 1591 + 1592 + let name t = t.name 1593 + let version t = t.version 1594 + let repository t = t.repository 1595 + let homepage t = t.homepage 1596 + 1597 + let jsont = 1598 + Jsont.Object.map ~kind:"Software" 1599 + (fun name version repository homepage -> 1600 + { name; version; repository; homepage }) 1601 + |> Jsont.Object.mem "name" Jsont.string ~enc:name 1602 + |> Jsont.Object.mem "version" Jsont.string ~enc:version 1603 + |> Jsont.Object.opt_mem "repository" Uri.jsont ~enc:repository 1604 + |> Jsont.Object.opt_mem "homepage" Uri.jsont ~enc:homepage 1605 + |> Jsont.Object.finish 1606 + end 1607 + 1608 + module Usage = struct 1609 + type t = { 1610 + users_total : int option; 1611 + users_active_half_year : int option; 1612 + users_active_month : int option; 1613 + local_posts : int option; 1614 + local_comments : int option; 1615 + } 1616 + 1617 + let make ?users_total ?users_active_half_year ?users_active_month 1618 + ?local_posts ?local_comments () = 1619 + { users_total; users_active_half_year; users_active_month; 1620 + local_posts; local_comments } 1621 + 1622 + let users_total t = t.users_total 1623 + let users_active_half_year t = t.users_active_half_year 1624 + let users_active_month t = t.users_active_month 1625 + let local_posts t = t.local_posts 1626 + let local_comments t = t.local_comments 1627 + 1628 + let users_jsont = 1629 + Jsont.Object.map ~kind:"Users" 1630 + (fun total active_half_year active_month -> 1631 + (total, active_half_year, active_month)) 1632 + |> Jsont.Object.opt_mem "total" Jsont.int 1633 + ~enc:(fun (t, _, _) -> t) 1634 + |> Jsont.Object.opt_mem "activeHalfyear" Jsont.int 1635 + ~enc:(fun (_, h, _) -> h) 1636 + |> Jsont.Object.opt_mem "activeMonth" Jsont.int 1637 + ~enc:(fun (_, _, m) -> m) 1638 + |> Jsont.Object.finish 1639 + 1640 + let jsont = 1641 + Jsont.Object.map ~kind:"Usage" 1642 + (fun (users_total, users_active_half_year, users_active_month) 1643 + local_posts local_comments -> 1644 + { users_total; users_active_half_year; users_active_month; 1645 + local_posts; local_comments }) 1646 + |> Jsont.Object.mem "users" users_jsont 1647 + ~dec_absent:(None, None, None) 1648 + ~enc:(fun t -> (t.users_total, t.users_active_half_year, 1649 + t.users_active_month)) 1650 + |> Jsont.Object.opt_mem "localPosts" Jsont.int ~enc:local_posts 1651 + |> Jsont.Object.opt_mem "localComments" Jsont.int ~enc:local_comments 1652 + |> Jsont.Object.finish 1653 + end 1654 + 1655 + type t = { 1656 + version : string; 1657 + software : Software.t; 1658 + protocols : string list; 1659 + usage : Usage.t; 1660 + open_registrations : bool; 1661 + metadata : Jsont.json option; 1662 + } 1663 + 1664 + let make ~version ~software ~protocols ~usage ~open_registrations 1665 + ?metadata () = 1666 + { version; software; protocols; usage; open_registrations; metadata } 1667 + 1668 + let version t = t.version 1669 + let software t = t.software 1670 + let protocols t = t.protocols 1671 + let usage t = t.usage 1672 + let open_registrations t = t.open_registrations 1673 + let metadata t = t.metadata 1674 + 1675 + let jsont = 1676 + Jsont.Object.map ~kind:"Nodeinfo" 1677 + (fun version software protocols usage open_registrations metadata -> 1678 + { version; software; protocols; usage; open_registrations; metadata }) 1679 + |> Jsont.Object.mem "version" Jsont.string ~enc:version 1680 + |> Jsont.Object.mem "software" Software.jsont ~enc:software 1681 + |> Jsont.Object.mem "protocols" (Jsont.list Jsont.string) ~enc:protocols 1682 + |> Jsont.Object.mem "usage" Usage.jsont ~enc:usage 1683 + |> Jsont.Object.mem "openRegistrations" Jsont.bool ~enc:open_registrations 1684 + |> Jsont.Object.opt_mem "metadata" Jsont.json ~enc:metadata 1685 + |> Jsont.Object.finish 1686 + end
+694
src/activitypub.mli
··· 1 + (** ActivityPub/ActivityStreams types with jsont codecs. 2 + 3 + This module provides OCaml types and bidirectional JSON codecs for the 4 + ActivityPub and ActivityStreams 2.0 specifications. 5 + 6 + {1 Example} 7 + 8 + {[ 9 + (* Decode an actor from JSON *) 10 + let json_str = {|{"@id": "...", "@type": "Person", ...}|} in 11 + match Jsont_codec.decode_string Actor.jsont json_str with 12 + | Ok actor -> Printf.printf "Actor: %s\n" (Actor.name actor) 13 + | Error e -> Printf.eprintf "Error: %s\n" e 14 + 15 + (* Create and encode a Note *) 16 + let note = Object.make ~type_:Object_type.Note 17 + ~content:"Hello ActivityPub!" () in 18 + match Jsont_codec.encode_string Object.jsont note with 19 + | Ok json_str -> print_endline json_str 20 + | Error e -> Printf.eprintf "Error: %s\n" e 21 + ]} 22 + 23 + @see <https://www.w3.org/TR/activitypub/> ActivityPub specification 24 + @see <https://www.w3.org/TR/activitystreams-core/> ActivityStreams Core 25 + @see <https://www.w3.org/TR/activitystreams-vocabulary/> ActivityStreams Vocabulary *) 26 + 27 + (** {1 Common Types} *) 28 + 29 + (** Timestamps in ISO 8601 format. *) 30 + module Datetime : sig 31 + type t 32 + 33 + val v : string -> t 34 + (** [v s] creates a datetime from the string [s]. *) 35 + 36 + val to_string : t -> string 37 + (** [to_string t] returns the datetime as an ISO 8601 string. *) 38 + 39 + val jsont : t Jsont.t 40 + (** JSON type for datetimes. *) 41 + end 42 + 43 + (** URI identifiers. *) 44 + module Uri : sig 45 + type t 46 + 47 + val v : string -> t 48 + (** [v s] creates a URI from the string [s]. *) 49 + 50 + val to_string : t -> string 51 + (** [to_string t] returns the URI as a string. *) 52 + 53 + val jsont : t Jsont.t 54 + (** JSON type for URIs. *) 55 + end 56 + 57 + (** JSON-LD context. *) 58 + module Context : sig 59 + type t 60 + 61 + val default : t 62 + (** The default ActivityStreams context. *) 63 + 64 + val jsont : t Jsont.t 65 + (** JSON type for contexts. *) 66 + end 67 + 68 + (** {1 Link} *) 69 + 70 + (** Link objects represent references to other resources. 71 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link> *) 72 + module Link : sig 73 + type t 74 + 75 + val make : 76 + ?media_type:string -> 77 + ?name:string -> 78 + ?hreflang:string -> 79 + ?height:int -> 80 + ?width:int -> 81 + ?preview:Uri.t -> 82 + href:Uri.t -> 83 + unit -> t 84 + (** Create a new Link. *) 85 + 86 + val href : t -> Uri.t 87 + val media_type : t -> string option 88 + val name : t -> string option 89 + val hreflang : t -> string option 90 + val height : t -> int option 91 + val width : t -> int option 92 + val preview : t -> Uri.t option 93 + 94 + val jsont : t Jsont.t 95 + (** JSON type for Links. *) 96 + end 97 + 98 + (** Reference that can be either a URI string or a Link object. *) 99 + module Link_or_uri : sig 100 + type t = 101 + | Uri of Uri.t 102 + | Link of Link.t 103 + 104 + val uri : Uri.t -> t 105 + val link : Link.t -> t 106 + val jsont : t Jsont.t 107 + end 108 + 109 + (** {1 Image} *) 110 + 111 + (** Image objects. 112 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image> *) 113 + module Image : sig 114 + type t 115 + 116 + val make : 117 + ?id:Uri.t -> 118 + ?name:string -> 119 + ?media_type:string -> 120 + ?width:int -> 121 + ?height:int -> 122 + url:Link_or_uri.t -> 123 + unit -> t 124 + 125 + val id : t -> Uri.t option 126 + val url : t -> Link_or_uri.t 127 + val name : t -> string option 128 + val media_type : t -> string option 129 + val width : t -> int option 130 + val height : t -> int option 131 + 132 + val jsont : t Jsont.t 133 + end 134 + 135 + (** Image reference - can be URI, Link, or full Image object. *) 136 + module Image_ref : sig 137 + type t = 138 + | Uri of Uri.t 139 + | Link of Link.t 140 + | Image of Image.t 141 + 142 + val uri : Uri.t -> t 143 + val link : Link.t -> t 144 + val image : Image.t -> t 145 + val jsont : t Jsont.t 146 + end 147 + 148 + (** {1 Public Collection} *) 149 + 150 + (** Special public addressing collection. *) 151 + module Public : sig 152 + val id : Uri.t 153 + (** The public collection URI for addressing public posts. *) 154 + end 155 + 156 + (** {1 Recipient} *) 157 + 158 + (** Recipient reference - can be URI or inline object with id and type. *) 159 + module Recipient : sig 160 + type t 161 + 162 + val make : ?type_:string -> Uri.t -> t 163 + val id : t -> Uri.t 164 + val type_ : t -> string option 165 + val jsont : t Jsont.t 166 + end 167 + 168 + (** {1 Endpoints} *) 169 + 170 + (** Actor endpoints for special server URLs. *) 171 + module Endpoints : sig 172 + type t 173 + 174 + val make : 175 + ?proxy_url:Uri.t -> 176 + ?oauth_authorization_endpoint:Uri.t -> 177 + ?oauth_token_endpoint:Uri.t -> 178 + ?provide_client_key:Uri.t -> 179 + ?sign_client_key:Uri.t -> 180 + ?shared_inbox:Uri.t -> 181 + unit -> t 182 + 183 + val proxy_url : t -> Uri.t option 184 + val oauth_authorization_endpoint : t -> Uri.t option 185 + val oauth_token_endpoint : t -> Uri.t option 186 + val provide_client_key : t -> Uri.t option 187 + val sign_client_key : t -> Uri.t option 188 + val shared_inbox : t -> Uri.t option 189 + 190 + val jsont : t Jsont.t 191 + end 192 + 193 + (** {1 Public Key} *) 194 + 195 + (** Public key for HTTP Signatures. *) 196 + module Public_key : sig 197 + type t 198 + 199 + val make : 200 + id:Uri.t -> 201 + owner:Uri.t -> 202 + public_key_pem:string -> 203 + unit -> t 204 + 205 + val id : t -> Uri.t 206 + val owner : t -> Uri.t 207 + val public_key_pem : t -> string 208 + 209 + val jsont : t Jsont.t 210 + end 211 + 212 + (** {1 Actor Types} *) 213 + 214 + (** Actor types enumeration. *) 215 + module Actor_type : sig 216 + type t = 217 + | Person 218 + | Service 219 + | Organization 220 + | Group 221 + | Application 222 + 223 + val to_string : t -> string 224 + val of_string : string -> t option 225 + val jsont : t Jsont.t 226 + end 227 + 228 + (** {1 Actor} *) 229 + 230 + (** Actor objects represent entities that can perform activities. 231 + @see <https://www.w3.org/TR/activitypub/#actor-objects> *) 232 + module Actor : sig 233 + type t 234 + 235 + val make : 236 + ?context:Context.t -> 237 + id:Uri.t -> 238 + type_:Actor_type.t -> 239 + ?name:string -> 240 + ?preferred_username:string -> 241 + ?summary:string -> 242 + ?url:Uri.t -> 243 + inbox:Uri.t -> 244 + outbox:Uri.t -> 245 + ?followers:Uri.t -> 246 + ?following:Uri.t -> 247 + ?liked:Uri.t -> 248 + ?streams:Uri.t list -> 249 + ?endpoints:Endpoints.t -> 250 + ?public_key:Public_key.t -> 251 + ?icon:Image_ref.t list -> 252 + ?image:Image_ref.t list -> 253 + ?manually_approves_followers:bool -> 254 + unit -> t 255 + (** Create a new Actor. *) 256 + 257 + val context : t -> Context.t option 258 + val id : t -> Uri.t 259 + val type_ : t -> Actor_type.t 260 + val name : t -> string option 261 + val preferred_username : t -> string option 262 + val summary : t -> string option 263 + val url : t -> Uri.t option 264 + val inbox : t -> Uri.t 265 + val outbox : t -> Uri.t 266 + val followers : t -> Uri.t option 267 + val following : t -> Uri.t option 268 + val liked : t -> Uri.t option 269 + val streams : t -> Uri.t list option 270 + val endpoints : t -> Endpoints.t option 271 + val public_key : t -> Public_key.t option 272 + val icon : t -> Image_ref.t list option 273 + val image : t -> Image_ref.t list option 274 + val manually_approves_followers : t -> bool option 275 + 276 + val jsont : t Jsont.t 277 + (** JSON type for Actors. *) 278 + end 279 + 280 + (** Actor reference - can be URI or full Actor object. *) 281 + module Actor_ref : sig 282 + type t = 283 + | Uri of Uri.t 284 + | Actor of Actor.t 285 + 286 + val uri : Uri.t -> t 287 + val actor : Actor.t -> t 288 + val jsont : t Jsont.t 289 + end 290 + 291 + (** {1 Object Types} *) 292 + 293 + (** Object types enumeration. *) 294 + module Object_type : sig 295 + type t = 296 + | Note 297 + | Article 298 + | Page 299 + | Event 300 + | Image 301 + | Video 302 + | Audio 303 + | Document 304 + | Place 305 + | Profile 306 + | Tombstone 307 + | Collection 308 + | OrderedCollection 309 + 310 + val to_string : t -> string 311 + val of_string : string -> t option 312 + val jsont : t Jsont.t 313 + end 314 + 315 + (** {1 Object} *) 316 + 317 + (** ActivityStreams objects. 318 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#object-types> *) 319 + module Object : sig 320 + type t 321 + 322 + val make : 323 + ?context:Context.t -> 324 + ?id:Uri.t -> 325 + type_:Object_type.t -> 326 + ?name:string -> 327 + ?summary:string -> 328 + ?content:string -> 329 + ?media_type:string -> 330 + ?url:Link_or_uri.t list -> 331 + ?attributed_to:Actor_ref.t -> 332 + ?in_reply_to:Uri.t -> 333 + ?published:Datetime.t -> 334 + ?updated:Datetime.t -> 335 + ?deleted:Datetime.t -> 336 + ?to_:Recipient.t list -> 337 + ?cc:Recipient.t list -> 338 + ?bto:Recipient.t list -> 339 + ?bcc:Recipient.t list -> 340 + ?replies:Uri.t -> 341 + ?attachment:Link_or_uri.t list -> 342 + ?tag:Link_or_uri.t list -> 343 + ?generator:Uri.t -> 344 + ?icon:Image_ref.t list -> 345 + ?image:Image_ref.t list -> 346 + ?start_time:Datetime.t -> 347 + ?end_time:Datetime.t -> 348 + ?duration:string -> 349 + ?sensitive:bool -> 350 + unit -> t 351 + (** Create a new Object. *) 352 + 353 + val context : t -> Context.t option 354 + val id : t -> Uri.t option 355 + val type_ : t -> Object_type.t 356 + val name : t -> string option 357 + val summary : t -> string option 358 + val content : t -> string option 359 + val media_type : t -> string option 360 + val url : t -> Link_or_uri.t list option 361 + val attributed_to : t -> Actor_ref.t option 362 + val in_reply_to : t -> Uri.t option 363 + val published : t -> Datetime.t option 364 + val updated : t -> Datetime.t option 365 + val deleted : t -> Datetime.t option 366 + val to_ : t -> Recipient.t list option 367 + val cc : t -> Recipient.t list option 368 + val bto : t -> Recipient.t list option 369 + val bcc : t -> Recipient.t list option 370 + val replies : t -> Uri.t option 371 + val attachment : t -> Link_or_uri.t list option 372 + val tag : t -> Link_or_uri.t list option 373 + val generator : t -> Uri.t option 374 + val icon : t -> Image_ref.t list option 375 + val image : t -> Image_ref.t list option 376 + val start_time : t -> Datetime.t option 377 + val end_time : t -> Datetime.t option 378 + val duration : t -> string option 379 + val sensitive : t -> bool option 380 + 381 + val jsont : t Jsont.t 382 + (** JSON type for Objects. *) 383 + end 384 + 385 + (** Object reference - can be URI or full Object. *) 386 + module Object_ref : sig 387 + type t = 388 + | Uri of Uri.t 389 + | Object of Object.t 390 + 391 + val uri : Uri.t -> t 392 + val obj : Object.t -> t 393 + val jsont : t Jsont.t 394 + end 395 + 396 + (** {1 Activity Types} *) 397 + 398 + (** Activity types enumeration. *) 399 + module Activity_type : sig 400 + type t = 401 + | Create 402 + | Update 403 + | Delete 404 + | Follow 405 + | Accept 406 + | Reject 407 + | Add 408 + | Remove 409 + | Like 410 + | Announce 411 + | Undo 412 + | Block 413 + | Flag 414 + | Dislike 415 + | Ignore 416 + | Invite 417 + | Join 418 + | Leave 419 + | Listen 420 + | Move 421 + | Offer 422 + | Question 423 + | Read 424 + | TentativeAccept 425 + | TentativeReject 426 + | Travel 427 + | View 428 + 429 + val to_string : t -> string 430 + val of_string : string -> t option 431 + val jsont : t Jsont.t 432 + end 433 + 434 + (** {1 Activity} *) 435 + 436 + (** ActivityPub activities. 437 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#activity-types> *) 438 + module Activity : sig 439 + type t 440 + 441 + val make : 442 + ?context:Context.t -> 443 + ?id:Uri.t -> 444 + type_:Activity_type.t -> 445 + actor:Actor_ref.t -> 446 + ?object_:Object_ref.t -> 447 + ?target:Object_ref.t -> 448 + ?result:Object_ref.t -> 449 + ?origin:Object_ref.t -> 450 + ?instrument:Object_ref.t -> 451 + ?to_:Recipient.t list -> 452 + ?cc:Recipient.t list -> 453 + ?bto:Recipient.t list -> 454 + ?bcc:Recipient.t list -> 455 + ?published:Datetime.t -> 456 + ?updated:Datetime.t -> 457 + ?summary:string -> 458 + unit -> t 459 + (** Create a new Activity. *) 460 + 461 + val context : t -> Context.t option 462 + val id : t -> Uri.t option 463 + val type_ : t -> Activity_type.t 464 + val actor : t -> Actor_ref.t 465 + val object_ : t -> Object_ref.t option 466 + val target : t -> Object_ref.t option 467 + val result : t -> Object_ref.t option 468 + val origin : t -> Object_ref.t option 469 + val instrument : t -> Object_ref.t option 470 + val to_ : t -> Recipient.t list option 471 + val cc : t -> Recipient.t list option 472 + val bto : t -> Recipient.t list option 473 + val bcc : t -> Recipient.t list option 474 + val published : t -> Datetime.t option 475 + val updated : t -> Datetime.t option 476 + val summary : t -> string option 477 + 478 + val jsont : t Jsont.t 479 + (** JSON type for Activities. *) 480 + end 481 + 482 + (** Activity reference - can be URI or full Activity. *) 483 + module Activity_ref : sig 484 + type t = 485 + | Uri of Uri.t 486 + | Activity of Activity.t 487 + 488 + val uri : Uri.t -> t 489 + val activity : Activity.t -> t 490 + val jsont : t Jsont.t 491 + end 492 + 493 + (** {1 Collection} *) 494 + 495 + (** Collection objects. 496 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection> *) 497 + module Collection : sig 498 + type 'a t 499 + 500 + val make : 501 + ?context:Context.t -> 502 + ?id:Uri.t -> 503 + ?total_items:int -> 504 + ?current:Uri.t -> 505 + ?first:Uri.t -> 506 + ?last:Uri.t -> 507 + ?items:'a list -> 508 + ordered:bool -> 509 + unit -> 'a t 510 + (** Create a new Collection. Use [~ordered:true] for OrderedCollection. *) 511 + 512 + val context : 'a t -> Context.t option 513 + val id : 'a t -> Uri.t option 514 + val total_items : 'a t -> int option 515 + val current : 'a t -> Uri.t option 516 + val first : 'a t -> Uri.t option 517 + val last : 'a t -> Uri.t option 518 + val items : 'a t -> 'a list option 519 + val ordered : 'a t -> bool 520 + 521 + val jsont : 'a Jsont.t -> 'a t Jsont.t 522 + (** JSON type for Collections, parameterized by item type. *) 523 + end 524 + 525 + (** {1 Collection Page} *) 526 + 527 + (** Collection page objects. 528 + @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage> *) 529 + module Collection_page : sig 530 + type 'a t 531 + 532 + val make : 533 + ?context:Context.t -> 534 + ?id:Uri.t -> 535 + ?total_items:int -> 536 + ?current:Uri.t -> 537 + ?first:Uri.t -> 538 + ?last:Uri.t -> 539 + ?prev:Uri.t -> 540 + ?next:Uri.t -> 541 + ?part_of:Uri.t -> 542 + ?items:'a list -> 543 + ordered:bool -> 544 + unit -> 'a t 545 + (** Create a new CollectionPage. Use [~ordered:true] for OrderedCollectionPage. *) 546 + 547 + val context : 'a t -> Context.t option 548 + val id : 'a t -> Uri.t option 549 + val total_items : 'a t -> int option 550 + val current : 'a t -> Uri.t option 551 + val first : 'a t -> Uri.t option 552 + val last : 'a t -> Uri.t option 553 + val prev : 'a t -> Uri.t option 554 + val next : 'a t -> Uri.t option 555 + val part_of : 'a t -> Uri.t option 556 + val items : 'a t -> 'a list option 557 + val ordered : 'a t -> bool 558 + 559 + val jsont : 'a Jsont.t -> 'a t Jsont.t 560 + (** JSON type for CollectionPages, parameterized by item type. *) 561 + end 562 + 563 + (** {1 Convenience type aliases} *) 564 + 565 + (** Activity collection. *) 566 + module Activity_collection : sig 567 + type t = Activity.t Collection.t 568 + val jsont : t Jsont.t 569 + end 570 + 571 + (** Object collection. *) 572 + module Object_collection : sig 573 + type t = Object.t Collection.t 574 + val jsont : t Jsont.t 575 + end 576 + 577 + (** Activity collection page. *) 578 + module Activity_collection_page : sig 579 + type t = Activity.t Collection_page.t 580 + val jsont : t Jsont.t 581 + end 582 + 583 + (** Object collection page. *) 584 + module Object_collection_page : sig 585 + type t = Object.t Collection_page.t 586 + val jsont : t Jsont.t 587 + end 588 + 589 + (** {1 Webfinger} *) 590 + 591 + (** Webfinger JRD (JSON Resource Descriptor) for actor discovery. 592 + @see <https://www.rfc-editor.org/rfc/rfc7033> Webfinger RFC *) 593 + module Webfinger : sig 594 + (** A link in the Webfinger response. *) 595 + module Jrd_link : sig 596 + type t 597 + 598 + val make : 599 + rel:string -> 600 + ?type_:string -> 601 + ?href:Uri.t -> 602 + ?template:string -> 603 + unit -> t 604 + 605 + val rel : t -> string 606 + val type_ : t -> string option 607 + val href : t -> Uri.t option 608 + val template : t -> string option 609 + 610 + val jsont : t Jsont.t 611 + end 612 + 613 + type t 614 + 615 + val make : 616 + subject:string -> 617 + ?aliases:string list -> 618 + ?properties:(string * string) list -> 619 + ?links:Jrd_link.t list -> 620 + unit -> t 621 + 622 + val subject : t -> string 623 + val aliases : t -> string list option 624 + val properties : t -> (string * string) list option 625 + val links : t -> Jrd_link.t list option 626 + 627 + val jsont : t Jsont.t 628 + end 629 + 630 + (** {1 NodeInfo} *) 631 + 632 + (** NodeInfo protocol for server metadata discovery. 633 + @see <https://nodeinfo.diaspora.software/> NodeInfo specification *) 634 + module Nodeinfo : sig 635 + (** Software information. *) 636 + module Software : sig 637 + type t 638 + 639 + val make : 640 + name:string -> 641 + version:string -> 642 + ?repository:Uri.t -> 643 + ?homepage:Uri.t -> 644 + unit -> t 645 + 646 + val name : t -> string 647 + val version : t -> string 648 + val repository : t -> Uri.t option 649 + val homepage : t -> Uri.t option 650 + 651 + val jsont : t Jsont.t 652 + end 653 + 654 + (** Usage statistics. *) 655 + module Usage : sig 656 + type t 657 + 658 + val make : 659 + ?users_total:int -> 660 + ?users_active_half_year:int -> 661 + ?users_active_month:int -> 662 + ?local_posts:int -> 663 + ?local_comments:int -> 664 + unit -> t 665 + 666 + val users_total : t -> int option 667 + val users_active_half_year : t -> int option 668 + val users_active_month : t -> int option 669 + val local_posts : t -> int option 670 + val local_comments : t -> int option 671 + 672 + val jsont : t Jsont.t 673 + end 674 + 675 + type t 676 + 677 + val make : 678 + version:string -> 679 + software:Software.t -> 680 + protocols:string list -> 681 + usage:Usage.t -> 682 + open_registrations:bool -> 683 + ?metadata:Jsont.json -> 684 + unit -> t 685 + 686 + val version : t -> string 687 + val software : t -> Software.t 688 + val protocols : t -> string list 689 + val usage : t -> Usage.t 690 + val open_registrations : t -> bool 691 + val metadata : t -> Jsont.json option 692 + 693 + val jsont : t Jsont.t 694 + end
+4
src/dune
··· 1 + (library 2 + (name activitypub) 3 + (public_name activitypub) 4 + (libraries jsont))