···11+# This file is generated by dune, edit dune-project instead
22+opam-version: "2.0"
33+synopsis: "ActivityPub protocol types with jsont codecs"
44+description:
55+ "OCaml types and jsont codecs for the ActivityPub/ActivityStreams protocol"
66+depends: [
77+ "dune" {>= "3.0"}
88+ "ocaml" {>= "4.14.0"}
99+ "jsont" {>= "0.2.0"}
1010+ "odoc" {with-doc}
1111+]
1212+build: [
1313+ ["dune" "subst"] {dev}
1414+ [
1515+ "dune"
1616+ "build"
1717+ "-p"
1818+ name
1919+ "-j"
2020+ jobs
2121+ "@install"
2222+ "@runtest" {with-test}
2323+ "@doc" {with-doc}
2424+ ]
2525+]
+12
dune-project
···11+(lang dune 3.0)
22+(name activitypub)
33+44+(generate_opam_files true)
55+66+(package
77+ (name activitypub)
88+ (synopsis "ActivityPub protocol types with jsont codecs")
99+ (description "OCaml types and jsont codecs for the ActivityPub/ActivityStreams protocol")
1010+ (depends
1111+ (ocaml (>= 4.14.0))
1212+ (jsont (>= 0.2.0))))
+1686
src/activitypub.ml
···11+(** ActivityPub/ActivityStreams types with jsont codecs.
22+33+ This module provides OCaml types and bidirectional JSON codecs for the
44+ ActivityPub and ActivityStreams 2.0 specifications.
55+66+ @see <https://www.w3.org/TR/activitypub/> ActivityPub specification
77+ @see <https://www.w3.org/TR/activitystreams-core/> ActivityStreams Core
88+ @see <https://www.w3.org/TR/activitystreams-vocabulary/> ActivityStreams Vocabulary *)
99+1010+(** {1 Common Types} *)
1111+1212+(** Timestamps in ISO 8601 format. *)
1313+module Datetime : sig
1414+ type t
1515+ val v : string -> t
1616+ val to_string : t -> string
1717+ val jsont : t Jsont.t
1818+end = struct
1919+ type t = string
2020+ let v s = s
2121+ let to_string t = t
2222+ let jsont = Jsont.string |> Jsont.with_doc ~kind:"datetime"
2323+end
2424+2525+(** URI identifiers. *)
2626+module Uri : sig
2727+ type t
2828+ val v : string -> t
2929+ val to_string : t -> string
3030+ val jsont : t Jsont.t
3131+end = struct
3232+ type t = string
3333+ let v s = s
3434+ let to_string t = t
3535+ let jsont = Jsont.string |> Jsont.with_doc ~kind:"uri"
3636+end
3737+3838+(** JSON-LD context. *)
3939+module Context : sig
4040+ type t
4141+ val default : t
4242+ val jsont : t Jsont.t
4343+end = struct
4444+ type t = Jsont.json
4545+ let default =
4646+ Jsont.Json.string "https://www.w3.org/ns/activitystreams"
4747+ let jsont = Jsont.json |> Jsont.with_doc ~kind:"@context"
4848+end
4949+5050+(** {1 Link} *)
5151+5252+(** Link objects represent references to other resources.
5353+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link> *)
5454+module Link : sig
5555+ type t
5656+5757+ val make :
5858+ ?media_type:string ->
5959+ ?name:string ->
6060+ ?hreflang:string ->
6161+ ?height:int ->
6262+ ?width:int ->
6363+ ?preview:Uri.t ->
6464+ href:Uri.t ->
6565+ unit -> t
6666+6767+ val href : t -> Uri.t
6868+ val media_type : t -> string option
6969+ val name : t -> string option
7070+ val hreflang : t -> string option
7171+ val height : t -> int option
7272+ val width : t -> int option
7373+ val preview : t -> Uri.t option
7474+7575+ val jsont : t Jsont.t
7676+end = struct
7777+ type t = {
7878+ href : Uri.t;
7979+ media_type : string option;
8080+ name : string option;
8181+ hreflang : string option;
8282+ height : int option;
8383+ width : int option;
8484+ preview : Uri.t option;
8585+ }
8686+8787+ let make ?media_type ?name ?hreflang ?height ?width ?preview ~href () =
8888+ { href; media_type; name; hreflang; height; width; preview }
8989+9090+ let href t = t.href
9191+ let media_type t = t.media_type
9292+ let name t = t.name
9393+ let hreflang t = t.hreflang
9494+ let height t = t.height
9595+ let width t = t.width
9696+ let preview t = t.preview
9797+9898+ let jsont =
9999+ Jsont.Object.map ~kind:"Link"
100100+ (fun href media_type name hreflang height width preview ->
101101+ { href; media_type; name; hreflang; height; width; preview })
102102+ |> Jsont.Object.mem "href" Uri.jsont ~enc:href
103103+ |> Jsont.Object.opt_mem "mediaType" Jsont.string ~enc:media_type
104104+ |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name
105105+ |> Jsont.Object.opt_mem "hreflang" Jsont.string ~enc:hreflang
106106+ |> Jsont.Object.opt_mem "height" Jsont.int ~enc:height
107107+ |> Jsont.Object.opt_mem "width" Jsont.int ~enc:width
108108+ |> Jsont.Object.opt_mem "preview" Uri.jsont ~enc:preview
109109+ |> Jsont.Object.finish
110110+end
111111+112112+(** Reference that can be either a URI string or a Link object. *)
113113+module Link_or_uri : sig
114114+ type t =
115115+ | Uri of Uri.t
116116+ | Link of Link.t
117117+118118+ val uri : Uri.t -> t
119119+ val link : Link.t -> t
120120+ val jsont : t Jsont.t
121121+end = struct
122122+ type t =
123123+ | Uri of Uri.t
124124+ | Link of Link.t
125125+126126+ let uri u = Uri u
127127+ let link l = Link l
128128+129129+ let jsont =
130130+ let dec_string = Jsont.map Uri.jsont ~dec:(fun u -> Uri u)
131131+ ~enc:(function Uri u -> u | Link _ -> assert false) in
132132+ let dec_object = Jsont.map Link.jsont ~dec:(fun l -> Link l)
133133+ ~enc:(function Link l -> l | Uri _ -> assert false) in
134134+ Jsont.any ~kind:"Link or URI"
135135+ ~dec_string ~dec_object
136136+ ~enc:(function
137137+ | Uri _ -> dec_string
138138+ | Link _ -> dec_object)
139139+ ()
140140+end
141141+142142+(** {1 Image} *)
143143+144144+(** Image objects.
145145+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image> *)
146146+module Image : sig
147147+ type t
148148+149149+ val make :
150150+ ?id:Uri.t ->
151151+ ?name:string ->
152152+ ?media_type:string ->
153153+ ?width:int ->
154154+ ?height:int ->
155155+ url:Link_or_uri.t ->
156156+ unit -> t
157157+158158+ val id : t -> Uri.t option
159159+ val url : t -> Link_or_uri.t
160160+ val name : t -> string option
161161+ val media_type : t -> string option
162162+ val width : t -> int option
163163+ val height : t -> int option
164164+165165+ val jsont : t Jsont.t
166166+end = struct
167167+ type t = {
168168+ id : Uri.t option;
169169+ url : Link_or_uri.t;
170170+ name : string option;
171171+ media_type : string option;
172172+ width : int option;
173173+ height : int option;
174174+ }
175175+176176+ let make ?id ?name ?media_type ?width ?height ~url () =
177177+ { id; url; name; media_type; width; height }
178178+179179+ let id t = t.id
180180+ let url t = t.url
181181+ let name t = t.name
182182+ let media_type t = t.media_type
183183+ let width t = t.width
184184+ let height t = t.height
185185+186186+ let jsont =
187187+ Jsont.Object.map ~kind:"Image"
188188+ (fun id url name media_type width height ->
189189+ { id; url; name; media_type; width; height })
190190+ |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id
191191+ |> Jsont.Object.mem "url" Link_or_uri.jsont ~enc:url
192192+ |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name
193193+ |> Jsont.Object.opt_mem "mediaType" Jsont.string ~enc:media_type
194194+ |> Jsont.Object.opt_mem "width" Jsont.int ~enc:width
195195+ |> Jsont.Object.opt_mem "height" Jsont.int ~enc:height
196196+ |> Jsont.Object.finish
197197+end
198198+199199+(** Image reference - can be URI, Link, or full Image object. *)
200200+module Image_ref : sig
201201+ type t =
202202+ | Uri of Uri.t
203203+ | Link of Link.t
204204+ | Image of Image.t
205205+206206+ val uri : Uri.t -> t
207207+ val link : Link.t -> t
208208+ val image : Image.t -> t
209209+ val jsont : t Jsont.t
210210+end = struct
211211+ type t =
212212+ | Uri of Uri.t
213213+ | Link of Link.t
214214+ | Image of Image.t
215215+216216+ let uri u = Uri u
217217+ let link l = Link l
218218+ let image i = Image i
219219+220220+ let jsont =
221221+ let dec_string = Jsont.map Uri.jsont ~dec:(fun u -> Uri u)
222222+ ~enc:(function Uri u -> u | _ -> assert false) in
223223+ let link_jsont =
224224+ Jsont.map Link.jsont
225225+ ~dec:(fun l -> Link l)
226226+ ~enc:(function Link l -> l | _ -> assert false)
227227+ in
228228+ let image_jsont =
229229+ Jsont.map Image.jsont
230230+ ~dec:(fun i -> Image i)
231231+ ~enc:(function Image i -> i | _ -> assert false)
232232+ in
233233+ let link_case = Jsont.Object.Case.map "Link" link_jsont in
234234+ let image_case = Jsont.Object.Case.map "Image" image_jsont in
235235+ let dec_object =
236236+ Jsont.Object.map ~kind:"Image or Link" Fun.id
237237+ |> Jsont.Object.case_mem "@type" Jsont.string
238238+ ~tag_compare:String.compare ~tag_to_string:Fun.id
239239+ ~dec_absent:"Image"
240240+ ~enc:Fun.id
241241+ ~enc_case:(function
242242+ | Link _ as v -> Jsont.Object.Case.value link_case v
243243+ | Image _ as v -> Jsont.Object.Case.value image_case v
244244+ | Uri _ -> assert false)
245245+ [ Jsont.Object.Case.make link_case;
246246+ Jsont.Object.Case.make image_case ]
247247+ |> Jsont.Object.finish
248248+ in
249249+ Jsont.any ~kind:"Image reference"
250250+ ~dec_string ~dec_object
251251+ ~enc:(function
252252+ | Uri _ -> dec_string
253253+ | Link _ | Image _ -> dec_object)
254254+ ()
255255+end
256256+257257+(** {1 Public Collection} *)
258258+259259+(** Special public addressing collection. *)
260260+module Public : sig
261261+ val id : Uri.t
262262+end = struct
263263+ let id = Uri.v "https://www.w3.org/ns/activitystreams#Public"
264264+end
265265+266266+(** {1 Recipient} *)
267267+268268+(** Recipient reference - can be URI or inline object with id and type. *)
269269+module Recipient : sig
270270+ type t = {
271271+ id : Uri.t;
272272+ type_ : string option;
273273+ }
274274+275275+ val make : ?type_:string -> Uri.t -> t
276276+ val id : t -> Uri.t
277277+ val type_ : t -> string option
278278+ val jsont : t Jsont.t
279279+end = struct
280280+ type t = {
281281+ id : Uri.t;
282282+ type_ : string option;
283283+ }
284284+285285+ let make ?type_ id = { id; type_ }
286286+ let id t = t.id
287287+ let type_ t = t.type_
288288+289289+ let jsont =
290290+ let dec_string = Jsont.map Uri.jsont
291291+ ~dec:(fun u -> { id = u; type_ = None })
292292+ ~enc:(fun t -> t.id) in
293293+ let dec_object =
294294+ Jsont.Object.map ~kind:"Recipient"
295295+ (fun id type_ -> { id; type_ })
296296+ |> Jsont.Object.mem "@id" Uri.jsont ~enc:id
297297+ |> Jsont.Object.opt_mem "@type" Jsont.string ~enc:type_
298298+ |> Jsont.Object.finish
299299+ in
300300+ Jsont.any ~kind:"Recipient"
301301+ ~dec_string ~dec_object
302302+ ~enc:(fun t ->
303303+ match t.type_ with
304304+ | None -> dec_string
305305+ | Some _ -> dec_object)
306306+ ()
307307+end
308308+309309+(** {1 Endpoints} *)
310310+311311+(** Actor endpoints for special server URLs. *)
312312+module Endpoints : sig
313313+ type t
314314+315315+ val make :
316316+ ?proxy_url:Uri.t ->
317317+ ?oauth_authorization_endpoint:Uri.t ->
318318+ ?oauth_token_endpoint:Uri.t ->
319319+ ?provide_client_key:Uri.t ->
320320+ ?sign_client_key:Uri.t ->
321321+ ?shared_inbox:Uri.t ->
322322+ unit -> t
323323+324324+ val proxy_url : t -> Uri.t option
325325+ val oauth_authorization_endpoint : t -> Uri.t option
326326+ val oauth_token_endpoint : t -> Uri.t option
327327+ val provide_client_key : t -> Uri.t option
328328+ val sign_client_key : t -> Uri.t option
329329+ val shared_inbox : t -> Uri.t option
330330+331331+ val jsont : t Jsont.t
332332+end = struct
333333+ type t = {
334334+ proxy_url : Uri.t option;
335335+ oauth_authorization_endpoint : Uri.t option;
336336+ oauth_token_endpoint : Uri.t option;
337337+ provide_client_key : Uri.t option;
338338+ sign_client_key : Uri.t option;
339339+ shared_inbox : Uri.t option;
340340+ }
341341+342342+ let make ?proxy_url ?oauth_authorization_endpoint ?oauth_token_endpoint
343343+ ?provide_client_key ?sign_client_key ?shared_inbox () =
344344+ { proxy_url; oauth_authorization_endpoint; oauth_token_endpoint;
345345+ provide_client_key; sign_client_key; shared_inbox }
346346+347347+ let proxy_url t = t.proxy_url
348348+ let oauth_authorization_endpoint t = t.oauth_authorization_endpoint
349349+ let oauth_token_endpoint t = t.oauth_token_endpoint
350350+ let provide_client_key t = t.provide_client_key
351351+ let sign_client_key t = t.sign_client_key
352352+ let shared_inbox t = t.shared_inbox
353353+354354+ let jsont =
355355+ Jsont.Object.map ~kind:"Endpoints"
356356+ (fun proxy_url oauth_authorization_endpoint oauth_token_endpoint
357357+ provide_client_key sign_client_key shared_inbox ->
358358+ { proxy_url; oauth_authorization_endpoint; oauth_token_endpoint;
359359+ provide_client_key; sign_client_key; shared_inbox })
360360+ |> Jsont.Object.opt_mem "proxyUrl" Uri.jsont ~enc:proxy_url
361361+ |> Jsont.Object.opt_mem "oauthAuthorizationEndpoint" Uri.jsont
362362+ ~enc:oauth_authorization_endpoint
363363+ |> Jsont.Object.opt_mem "oauthTokenEndpoint" Uri.jsont
364364+ ~enc:oauth_token_endpoint
365365+ |> Jsont.Object.opt_mem "provideClientKey" Uri.jsont ~enc:provide_client_key
366366+ |> Jsont.Object.opt_mem "signClientKey" Uri.jsont ~enc:sign_client_key
367367+ |> Jsont.Object.opt_mem "sharedInbox" Uri.jsont ~enc:shared_inbox
368368+ |> Jsont.Object.finish
369369+end
370370+371371+(** {1 Public Key} *)
372372+373373+(** Public key for HTTP Signatures. *)
374374+module Public_key : sig
375375+ type t
376376+377377+ val make :
378378+ id:Uri.t ->
379379+ owner:Uri.t ->
380380+ public_key_pem:string ->
381381+ unit -> t
382382+383383+ val id : t -> Uri.t
384384+ val owner : t -> Uri.t
385385+ val public_key_pem : t -> string
386386+387387+ val jsont : t Jsont.t
388388+end = struct
389389+ type t = {
390390+ id : Uri.t;
391391+ owner : Uri.t;
392392+ public_key_pem : string;
393393+ }
394394+395395+ let make ~id ~owner ~public_key_pem () =
396396+ { id; owner; public_key_pem }
397397+398398+ let id t = t.id
399399+ let owner t = t.owner
400400+ let public_key_pem t = t.public_key_pem
401401+402402+ let jsont =
403403+ Jsont.Object.map ~kind:"PublicKey"
404404+ (fun id owner public_key_pem -> { id; owner; public_key_pem })
405405+ |> Jsont.Object.mem "id" Uri.jsont ~enc:id
406406+ |> Jsont.Object.mem "owner" Uri.jsont ~enc:owner
407407+ |> Jsont.Object.mem "publicKeyPem" Jsont.string ~enc:public_key_pem
408408+ |> Jsont.Object.finish
409409+end
410410+411411+(** {1 Actor Types} *)
412412+413413+(** Actor types enumeration. *)
414414+module Actor_type : sig
415415+ type t =
416416+ | Person
417417+ | Service
418418+ | Organization
419419+ | Group
420420+ | Application
421421+422422+ val to_string : t -> string
423423+ val of_string : string -> t option
424424+ val jsont : t Jsont.t
425425+end = struct
426426+ type t =
427427+ | Person
428428+ | Service
429429+ | Organization
430430+ | Group
431431+ | Application
432432+433433+ let to_string = function
434434+ | Person -> "Person"
435435+ | Service -> "Service"
436436+ | Organization -> "Organization"
437437+ | Group -> "Group"
438438+ | Application -> "Application"
439439+440440+ let of_string = function
441441+ | "Person" -> Some Person
442442+ | "Service" -> Some Service
443443+ | "Organization" -> Some Organization
444444+ | "Group" -> Some Group
445445+ | "Application" -> Some Application
446446+ | _ -> None
447447+448448+ let jsont =
449449+ Jsont.enum ~kind:"ActorType" [
450450+ "Person", Person;
451451+ "Service", Service;
452452+ "Organization", Organization;
453453+ "Group", Group;
454454+ "Application", Application;
455455+ ]
456456+end
457457+458458+(** {1 Actor} *)
459459+460460+(** Actor objects represent entities that can perform activities.
461461+ @see <https://www.w3.org/TR/activitypub/#actor-objects> *)
462462+module Actor : sig
463463+ type t
464464+465465+ val make :
466466+ ?context:Context.t ->
467467+ id:Uri.t ->
468468+ type_:Actor_type.t ->
469469+ ?name:string ->
470470+ ?preferred_username:string ->
471471+ ?summary:string ->
472472+ ?url:Uri.t ->
473473+ inbox:Uri.t ->
474474+ outbox:Uri.t ->
475475+ ?followers:Uri.t ->
476476+ ?following:Uri.t ->
477477+ ?liked:Uri.t ->
478478+ ?streams:Uri.t list ->
479479+ ?endpoints:Endpoints.t ->
480480+ ?public_key:Public_key.t ->
481481+ ?icon:Image_ref.t list ->
482482+ ?image:Image_ref.t list ->
483483+ ?manually_approves_followers:bool ->
484484+ unit -> t
485485+486486+ val context : t -> Context.t option
487487+ val id : t -> Uri.t
488488+ val type_ : t -> Actor_type.t
489489+ val name : t -> string option
490490+ val preferred_username : t -> string option
491491+ val summary : t -> string option
492492+ val url : t -> Uri.t option
493493+ val inbox : t -> Uri.t
494494+ val outbox : t -> Uri.t
495495+ val followers : t -> Uri.t option
496496+ val following : t -> Uri.t option
497497+ val liked : t -> Uri.t option
498498+ val streams : t -> Uri.t list option
499499+ val endpoints : t -> Endpoints.t option
500500+ val public_key : t -> Public_key.t option
501501+ val icon : t -> Image_ref.t list option
502502+ val image : t -> Image_ref.t list option
503503+ val manually_approves_followers : t -> bool option
504504+505505+ val jsont : t Jsont.t
506506+end = struct
507507+ type t = {
508508+ context : Context.t option;
509509+ id : Uri.t;
510510+ type_ : Actor_type.t;
511511+ name : string option;
512512+ preferred_username : string option;
513513+ summary : string option;
514514+ url : Uri.t option;
515515+ inbox : Uri.t;
516516+ outbox : Uri.t;
517517+ followers : Uri.t option;
518518+ following : Uri.t option;
519519+ liked : Uri.t option;
520520+ streams : Uri.t list option;
521521+ endpoints : Endpoints.t option;
522522+ public_key : Public_key.t option;
523523+ icon : Image_ref.t list option;
524524+ image : Image_ref.t list option;
525525+ manually_approves_followers : bool option;
526526+ }
527527+528528+ let make ?context ~id ~type_ ?name ?preferred_username ?summary ?url
529529+ ~inbox ~outbox ?followers ?following ?liked ?streams ?endpoints
530530+ ?public_key ?icon ?image ?manually_approves_followers () =
531531+ { context; id; type_; name; preferred_username; summary; url;
532532+ inbox; outbox; followers; following; liked; streams; endpoints;
533533+ public_key; icon; image; manually_approves_followers }
534534+535535+ let context t = t.context
536536+ let id t = t.id
537537+ let type_ t = t.type_
538538+ let name t = t.name
539539+ let preferred_username t = t.preferred_username
540540+ let summary t = t.summary
541541+ let url t = t.url
542542+ let inbox t = t.inbox
543543+ let outbox t = t.outbox
544544+ let followers t = t.followers
545545+ let following t = t.following
546546+ let liked t = t.liked
547547+ let streams t = t.streams
548548+ let endpoints t = t.endpoints
549549+ let public_key t = t.public_key
550550+ let icon t = t.icon
551551+ let image t = t.image
552552+ let manually_approves_followers t = t.manually_approves_followers
553553+554554+ let jsont =
555555+ Jsont.Object.map ~kind:"Actor"
556556+ (fun context id type_ name preferred_username summary url inbox outbox
557557+ followers following liked streams endpoints public_key icon image
558558+ manually_approves_followers ->
559559+ { context; id; type_; name; preferred_username; summary; url;
560560+ inbox; outbox; followers; following; liked; streams; endpoints;
561561+ public_key; icon; image; manually_approves_followers })
562562+ |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context
563563+ |> Jsont.Object.mem "@id" Uri.jsont ~enc:id
564564+ |> Jsont.Object.mem "@type" Actor_type.jsont ~enc:type_
565565+ |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name
566566+ |> Jsont.Object.opt_mem "preferredUsername" Jsont.string
567567+ ~enc:preferred_username
568568+ |> Jsont.Object.opt_mem "summary" Jsont.string ~enc:summary
569569+ |> Jsont.Object.opt_mem "url" Uri.jsont ~enc:url
570570+ |> Jsont.Object.mem "inbox" Uri.jsont ~enc:inbox
571571+ |> Jsont.Object.mem "outbox" Uri.jsont ~enc:outbox
572572+ |> Jsont.Object.opt_mem "followers" Uri.jsont ~enc:followers
573573+ |> Jsont.Object.opt_mem "following" Uri.jsont ~enc:following
574574+ |> Jsont.Object.opt_mem "liked" Uri.jsont ~enc:liked
575575+ |> Jsont.Object.opt_mem "streams" (Jsont.list Uri.jsont) ~enc:streams
576576+ |> Jsont.Object.opt_mem "endpoints" Endpoints.jsont ~enc:endpoints
577577+ |> Jsont.Object.opt_mem "publicKey" Public_key.jsont ~enc:public_key
578578+ |> Jsont.Object.opt_mem "icon" (Jsont.list Image_ref.jsont) ~enc:icon
579579+ |> Jsont.Object.opt_mem "image" (Jsont.list Image_ref.jsont) ~enc:image
580580+ |> Jsont.Object.opt_mem "manuallyApprovesFollowers" Jsont.bool
581581+ ~enc:manually_approves_followers
582582+ |> Jsont.Object.finish
583583+end
584584+585585+(** Actor reference - can be URI or full Actor object. *)
586586+module Actor_ref : sig
587587+ type t =
588588+ | Uri of Uri.t
589589+ | Actor of Actor.t
590590+591591+ val uri : Uri.t -> t
592592+ val actor : Actor.t -> t
593593+ val jsont : t Jsont.t
594594+end = struct
595595+ type t =
596596+ | Uri of Uri.t
597597+ | Actor of Actor.t
598598+599599+ let uri u = Uri u
600600+ let actor a = Actor a
601601+602602+ let jsont =
603603+ let dec_string = Jsont.map Uri.jsont
604604+ ~dec:(fun u -> Uri u)
605605+ ~enc:(function Uri u -> u | Actor _ -> assert false) in
606606+ let dec_object = Jsont.map Actor.jsont
607607+ ~dec:(fun a -> Actor a)
608608+ ~enc:(function Actor a -> a | Uri _ -> assert false) in
609609+ Jsont.any ~kind:"Actor reference"
610610+ ~dec_string ~dec_object
611611+ ~enc:(function
612612+ | Uri _ -> dec_string
613613+ | Actor _ -> dec_object)
614614+ ()
615615+end
616616+617617+(** {1 Object Types} *)
618618+619619+(** Object types enumeration. *)
620620+module Object_type : sig
621621+ type t =
622622+ | Note
623623+ | Article
624624+ | Page
625625+ | Event
626626+ | Image
627627+ | Video
628628+ | Audio
629629+ | Document
630630+ | Place
631631+ | Profile
632632+ | Tombstone
633633+ | Collection
634634+ | OrderedCollection
635635+636636+ val to_string : t -> string
637637+ val of_string : string -> t option
638638+ val jsont : t Jsont.t
639639+end = struct
640640+ type t =
641641+ | Note
642642+ | Article
643643+ | Page
644644+ | Event
645645+ | Image
646646+ | Video
647647+ | Audio
648648+ | Document
649649+ | Place
650650+ | Profile
651651+ | Tombstone
652652+ | Collection
653653+ | OrderedCollection
654654+655655+ let to_string = function
656656+ | Note -> "Note"
657657+ | Article -> "Article"
658658+ | Page -> "Page"
659659+ | Event -> "Event"
660660+ | Image -> "Image"
661661+ | Video -> "Video"
662662+ | Audio -> "Audio"
663663+ | Document -> "Document"
664664+ | Place -> "Place"
665665+ | Profile -> "Profile"
666666+ | Tombstone -> "Tombstone"
667667+ | Collection -> "Collection"
668668+ | OrderedCollection -> "OrderedCollection"
669669+670670+ let of_string = function
671671+ | "Note" -> Some Note
672672+ | "Article" -> Some Article
673673+ | "Page" -> Some Page
674674+ | "Event" -> Some Event
675675+ | "Image" -> Some Image
676676+ | "Video" -> Some Video
677677+ | "Audio" -> Some Audio
678678+ | "Document" -> Some Document
679679+ | "Place" -> Some Place
680680+ | "Profile" -> Some Profile
681681+ | "Tombstone" -> Some Tombstone
682682+ | "Collection" -> Some Collection
683683+ | "OrderedCollection" -> Some OrderedCollection
684684+ | _ -> None
685685+686686+ let jsont =
687687+ Jsont.enum ~kind:"ObjectType" [
688688+ "Note", Note;
689689+ "Article", Article;
690690+ "Page", Page;
691691+ "Event", Event;
692692+ "Image", Image;
693693+ "Video", Video;
694694+ "Audio", Audio;
695695+ "Document", Document;
696696+ "Place", Place;
697697+ "Profile", Profile;
698698+ "Tombstone", Tombstone;
699699+ "Collection", Collection;
700700+ "OrderedCollection", OrderedCollection;
701701+ ]
702702+end
703703+704704+(** {1 Object} *)
705705+706706+(** ActivityStreams objects.
707707+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#object-types> *)
708708+module Object : sig
709709+ type t
710710+711711+ val make :
712712+ ?context:Context.t ->
713713+ ?id:Uri.t ->
714714+ type_:Object_type.t ->
715715+ ?name:string ->
716716+ ?summary:string ->
717717+ ?content:string ->
718718+ ?media_type:string ->
719719+ ?url:Link_or_uri.t list ->
720720+ ?attributed_to:Actor_ref.t ->
721721+ ?in_reply_to:Uri.t ->
722722+ ?published:Datetime.t ->
723723+ ?updated:Datetime.t ->
724724+ ?deleted:Datetime.t ->
725725+ ?to_:Recipient.t list ->
726726+ ?cc:Recipient.t list ->
727727+ ?bto:Recipient.t list ->
728728+ ?bcc:Recipient.t list ->
729729+ ?replies:Uri.t ->
730730+ ?attachment:Link_or_uri.t list ->
731731+ ?tag:Link_or_uri.t list ->
732732+ ?generator:Uri.t ->
733733+ ?icon:Image_ref.t list ->
734734+ ?image:Image_ref.t list ->
735735+ ?start_time:Datetime.t ->
736736+ ?end_time:Datetime.t ->
737737+ ?duration:string ->
738738+ ?sensitive:bool ->
739739+ unit -> t
740740+741741+ val context : t -> Context.t option
742742+ val id : t -> Uri.t option
743743+ val type_ : t -> Object_type.t
744744+ val name : t -> string option
745745+ val summary : t -> string option
746746+ val content : t -> string option
747747+ val media_type : t -> string option
748748+ val url : t -> Link_or_uri.t list option
749749+ val attributed_to : t -> Actor_ref.t option
750750+ val in_reply_to : t -> Uri.t option
751751+ val published : t -> Datetime.t option
752752+ val updated : t -> Datetime.t option
753753+ val deleted : t -> Datetime.t option
754754+ val to_ : t -> Recipient.t list option
755755+ val cc : t -> Recipient.t list option
756756+ val bto : t -> Recipient.t list option
757757+ val bcc : t -> Recipient.t list option
758758+ val replies : t -> Uri.t option
759759+ val attachment : t -> Link_or_uri.t list option
760760+ val tag : t -> Link_or_uri.t list option
761761+ val generator : t -> Uri.t option
762762+ val icon : t -> Image_ref.t list option
763763+ val image : t -> Image_ref.t list option
764764+ val start_time : t -> Datetime.t option
765765+ val end_time : t -> Datetime.t option
766766+ val duration : t -> string option
767767+ val sensitive : t -> bool option
768768+769769+ val jsont : t Jsont.t
770770+end = struct
771771+ type t = {
772772+ context : Context.t option;
773773+ id : Uri.t option;
774774+ type_ : Object_type.t;
775775+ name : string option;
776776+ summary : string option;
777777+ content : string option;
778778+ media_type : string option;
779779+ url : Link_or_uri.t list option;
780780+ attributed_to : Actor_ref.t option;
781781+ in_reply_to : Uri.t option;
782782+ published : Datetime.t option;
783783+ updated : Datetime.t option;
784784+ deleted : Datetime.t option;
785785+ to_ : Recipient.t list option;
786786+ cc : Recipient.t list option;
787787+ bto : Recipient.t list option;
788788+ bcc : Recipient.t list option;
789789+ replies : Uri.t option;
790790+ attachment : Link_or_uri.t list option;
791791+ tag : Link_or_uri.t list option;
792792+ generator : Uri.t option;
793793+ icon : Image_ref.t list option;
794794+ image : Image_ref.t list option;
795795+ start_time : Datetime.t option;
796796+ end_time : Datetime.t option;
797797+ duration : string option;
798798+ sensitive : bool option;
799799+ }
800800+801801+ let make ?context ?id ~type_ ?name ?summary ?content ?media_type ?url
802802+ ?attributed_to ?in_reply_to ?published ?updated ?deleted ?to_ ?cc
803803+ ?bto ?bcc ?replies ?attachment ?tag ?generator ?icon ?image
804804+ ?start_time ?end_time ?duration ?sensitive () =
805805+ { context; id; type_; name; summary; content; media_type; url;
806806+ attributed_to; in_reply_to; published; updated; deleted;
807807+ to_; cc; bto; bcc; replies; attachment; tag; generator;
808808+ icon; image; start_time; end_time; duration; sensitive }
809809+810810+ let context t = t.context
811811+ let id t = t.id
812812+ let type_ t = t.type_
813813+ let name t = t.name
814814+ let summary t = t.summary
815815+ let content t = t.content
816816+ let media_type t = t.media_type
817817+ let url t = t.url
818818+ let attributed_to t = t.attributed_to
819819+ let in_reply_to t = t.in_reply_to
820820+ let published t = t.published
821821+ let updated t = t.updated
822822+ let deleted t = t.deleted
823823+ let to_ t = t.to_
824824+ let cc t = t.cc
825825+ let bto t = t.bto
826826+ let bcc t = t.bcc
827827+ let replies t = t.replies
828828+ let attachment t = t.attachment
829829+ let tag t = t.tag
830830+ let generator t = t.generator
831831+ let icon t = t.icon
832832+ let image t = t.image
833833+ let start_time t = t.start_time
834834+ let end_time t = t.end_time
835835+ let duration t = t.duration
836836+ let sensitive t = t.sensitive
837837+838838+ let jsont =
839839+ Jsont.Object.map ~kind:"Object"
840840+ (fun context id type_ name summary content media_type url attributed_to
841841+ in_reply_to published updated deleted to_ cc bto bcc replies
842842+ attachment tag generator icon image start_time end_time duration
843843+ sensitive ->
844844+ { context; id; type_; name; summary; content; media_type; url;
845845+ attributed_to; in_reply_to; published; updated; deleted;
846846+ to_; cc; bto; bcc; replies; attachment; tag; generator;
847847+ icon; image; start_time; end_time; duration; sensitive })
848848+ |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context
849849+ |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id
850850+ |> Jsont.Object.mem "@type" Object_type.jsont ~enc:type_
851851+ |> Jsont.Object.opt_mem "name" Jsont.string ~enc:name
852852+ |> Jsont.Object.opt_mem "summary" Jsont.string ~enc:summary
853853+ |> Jsont.Object.opt_mem "content" Jsont.string ~enc:content
854854+ |> Jsont.Object.opt_mem "mediaType" Jsont.string ~enc:media_type
855855+ |> Jsont.Object.opt_mem "url" (Jsont.list Link_or_uri.jsont) ~enc:url
856856+ |> Jsont.Object.opt_mem "attributedTo" Actor_ref.jsont ~enc:attributed_to
857857+ |> Jsont.Object.opt_mem "inReplyTo" Uri.jsont ~enc:in_reply_to
858858+ |> Jsont.Object.opt_mem "published" Datetime.jsont ~enc:published
859859+ |> Jsont.Object.opt_mem "updated" Datetime.jsont ~enc:updated
860860+ |> Jsont.Object.opt_mem "deleted" Datetime.jsont ~enc:deleted
861861+ |> Jsont.Object.opt_mem "to" (Jsont.list Recipient.jsont) ~enc:to_
862862+ |> Jsont.Object.opt_mem "cc" (Jsont.list Recipient.jsont) ~enc:cc
863863+ |> Jsont.Object.opt_mem "bto" (Jsont.list Recipient.jsont) ~enc:bto
864864+ |> Jsont.Object.opt_mem "bcc" (Jsont.list Recipient.jsont) ~enc:bcc
865865+ |> Jsont.Object.opt_mem "replies" Uri.jsont ~enc:replies
866866+ |> Jsont.Object.opt_mem "attachment" (Jsont.list Link_or_uri.jsont)
867867+ ~enc:attachment
868868+ |> Jsont.Object.opt_mem "tag" (Jsont.list Link_or_uri.jsont) ~enc:tag
869869+ |> Jsont.Object.opt_mem "generator" Uri.jsont ~enc:generator
870870+ |> Jsont.Object.opt_mem "icon" (Jsont.list Image_ref.jsont) ~enc:icon
871871+ |> Jsont.Object.opt_mem "image" (Jsont.list Image_ref.jsont) ~enc:image
872872+ |> Jsont.Object.opt_mem "startTime" Datetime.jsont ~enc:start_time
873873+ |> Jsont.Object.opt_mem "endTime" Datetime.jsont ~enc:end_time
874874+ |> Jsont.Object.opt_mem "duration" Jsont.string ~enc:duration
875875+ |> Jsont.Object.opt_mem "sensitive" Jsont.bool ~enc:sensitive
876876+ |> Jsont.Object.finish
877877+end
878878+879879+(** Object reference - can be URI or full Object. *)
880880+module Object_ref : sig
881881+ type t =
882882+ | Uri of Uri.t
883883+ | Object of Object.t
884884+885885+ val uri : Uri.t -> t
886886+ val obj : Object.t -> t
887887+ val jsont : t Jsont.t
888888+end = struct
889889+ type t =
890890+ | Uri of Uri.t
891891+ | Object of Object.t
892892+893893+ let uri u = Uri u
894894+ let obj o = Object o
895895+896896+ let jsont =
897897+ let dec_string = Jsont.map Uri.jsont
898898+ ~dec:(fun u -> Uri u)
899899+ ~enc:(function Uri u -> u | Object _ -> assert false) in
900900+ let dec_object = Jsont.map Object.jsont
901901+ ~dec:(fun o -> Object o)
902902+ ~enc:(function Object o -> o | Uri _ -> assert false) in
903903+ Jsont.any ~kind:"Object reference"
904904+ ~dec_string ~dec_object
905905+ ~enc:(function
906906+ | Uri _ -> dec_string
907907+ | Object _ -> dec_object)
908908+ ()
909909+end
910910+911911+(** {1 Activity Types} *)
912912+913913+(** Activity types enumeration. *)
914914+module Activity_type : sig
915915+ type t =
916916+ | Create
917917+ | Update
918918+ | Delete
919919+ | Follow
920920+ | Accept
921921+ | Reject
922922+ | Add
923923+ | Remove
924924+ | Like
925925+ | Announce
926926+ | Undo
927927+ | Block
928928+ | Flag
929929+ | Dislike
930930+ | Ignore
931931+ | Invite
932932+ | Join
933933+ | Leave
934934+ | Listen
935935+ | Move
936936+ | Offer
937937+ | Question
938938+ | Read
939939+ | TentativeAccept
940940+ | TentativeReject
941941+ | Travel
942942+ | View
943943+944944+ val to_string : t -> string
945945+ val of_string : string -> t option
946946+ val jsont : t Jsont.t
947947+end = struct
948948+ type t =
949949+ | Create
950950+ | Update
951951+ | Delete
952952+ | Follow
953953+ | Accept
954954+ | Reject
955955+ | Add
956956+ | Remove
957957+ | Like
958958+ | Announce
959959+ | Undo
960960+ | Block
961961+ | Flag
962962+ | Dislike
963963+ | Ignore
964964+ | Invite
965965+ | Join
966966+ | Leave
967967+ | Listen
968968+ | Move
969969+ | Offer
970970+ | Question
971971+ | Read
972972+ | TentativeAccept
973973+ | TentativeReject
974974+ | Travel
975975+ | View
976976+977977+ let to_string = function
978978+ | Create -> "Create"
979979+ | Update -> "Update"
980980+ | Delete -> "Delete"
981981+ | Follow -> "Follow"
982982+ | Accept -> "Accept"
983983+ | Reject -> "Reject"
984984+ | Add -> "Add"
985985+ | Remove -> "Remove"
986986+ | Like -> "Like"
987987+ | Announce -> "Announce"
988988+ | Undo -> "Undo"
989989+ | Block -> "Block"
990990+ | Flag -> "Flag"
991991+ | Dislike -> "Dislike"
992992+ | Ignore -> "Ignore"
993993+ | Invite -> "Invite"
994994+ | Join -> "Join"
995995+ | Leave -> "Leave"
996996+ | Listen -> "Listen"
997997+ | Move -> "Move"
998998+ | Offer -> "Offer"
999999+ | Question -> "Question"
10001000+ | Read -> "Read"
10011001+ | TentativeAccept -> "TentativeAccept"
10021002+ | TentativeReject -> "TentativeReject"
10031003+ | Travel -> "Travel"
10041004+ | View -> "View"
10051005+10061006+ let of_string = function
10071007+ | "Create" -> Some Create
10081008+ | "Update" -> Some Update
10091009+ | "Delete" -> Some Delete
10101010+ | "Follow" -> Some Follow
10111011+ | "Accept" -> Some Accept
10121012+ | "Reject" -> Some Reject
10131013+ | "Add" -> Some Add
10141014+ | "Remove" -> Some Remove
10151015+ | "Like" -> Some Like
10161016+ | "Announce" -> Some Announce
10171017+ | "Undo" -> Some Undo
10181018+ | "Block" -> Some Block
10191019+ | "Flag" -> Some Flag
10201020+ | "Dislike" -> Some Dislike
10211021+ | "Ignore" -> Some Ignore
10221022+ | "Invite" -> Some Invite
10231023+ | "Join" -> Some Join
10241024+ | "Leave" -> Some Leave
10251025+ | "Listen" -> Some Listen
10261026+ | "Move" -> Some Move
10271027+ | "Offer" -> Some Offer
10281028+ | "Question" -> Some Question
10291029+ | "Read" -> Some Read
10301030+ | "TentativeAccept" -> Some TentativeAccept
10311031+ | "TentativeReject" -> Some TentativeReject
10321032+ | "Travel" -> Some Travel
10331033+ | "View" -> Some View
10341034+ | _ -> None
10351035+10361036+ let jsont =
10371037+ Jsont.enum ~kind:"ActivityType" [
10381038+ "Create", Create;
10391039+ "Update", Update;
10401040+ "Delete", Delete;
10411041+ "Follow", Follow;
10421042+ "Accept", Accept;
10431043+ "Reject", Reject;
10441044+ "Add", Add;
10451045+ "Remove", Remove;
10461046+ "Like", Like;
10471047+ "Announce", Announce;
10481048+ "Undo", Undo;
10491049+ "Block", Block;
10501050+ "Flag", Flag;
10511051+ "Dislike", Dislike;
10521052+ "Ignore", Ignore;
10531053+ "Invite", Invite;
10541054+ "Join", Join;
10551055+ "Leave", Leave;
10561056+ "Listen", Listen;
10571057+ "Move", Move;
10581058+ "Offer", Offer;
10591059+ "Question", Question;
10601060+ "Read", Read;
10611061+ "TentativeAccept", TentativeAccept;
10621062+ "TentativeReject", TentativeReject;
10631063+ "Travel", Travel;
10641064+ "View", View;
10651065+ ]
10661066+end
10671067+10681068+(** {1 Activity} *)
10691069+10701070+(** ActivityPub activities.
10711071+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#activity-types> *)
10721072+module Activity : sig
10731073+ type t
10741074+10751075+ val make :
10761076+ ?context:Context.t ->
10771077+ ?id:Uri.t ->
10781078+ type_:Activity_type.t ->
10791079+ actor:Actor_ref.t ->
10801080+ ?object_:Object_ref.t ->
10811081+ ?target:Object_ref.t ->
10821082+ ?result:Object_ref.t ->
10831083+ ?origin:Object_ref.t ->
10841084+ ?instrument:Object_ref.t ->
10851085+ ?to_:Recipient.t list ->
10861086+ ?cc:Recipient.t list ->
10871087+ ?bto:Recipient.t list ->
10881088+ ?bcc:Recipient.t list ->
10891089+ ?published:Datetime.t ->
10901090+ ?updated:Datetime.t ->
10911091+ ?summary:string ->
10921092+ unit -> t
10931093+10941094+ val context : t -> Context.t option
10951095+ val id : t -> Uri.t option
10961096+ val type_ : t -> Activity_type.t
10971097+ val actor : t -> Actor_ref.t
10981098+ val object_ : t -> Object_ref.t option
10991099+ val target : t -> Object_ref.t option
11001100+ val result : t -> Object_ref.t option
11011101+ val origin : t -> Object_ref.t option
11021102+ val instrument : t -> Object_ref.t option
11031103+ val to_ : t -> Recipient.t list option
11041104+ val cc : t -> Recipient.t list option
11051105+ val bto : t -> Recipient.t list option
11061106+ val bcc : t -> Recipient.t list option
11071107+ val published : t -> Datetime.t option
11081108+ val updated : t -> Datetime.t option
11091109+ val summary : t -> string option
11101110+11111111+ val jsont : t Jsont.t
11121112+end = struct
11131113+ type t = {
11141114+ context : Context.t option;
11151115+ id : Uri.t option;
11161116+ type_ : Activity_type.t;
11171117+ actor : Actor_ref.t;
11181118+ object_ : Object_ref.t option;
11191119+ target : Object_ref.t option;
11201120+ result : Object_ref.t option;
11211121+ origin : Object_ref.t option;
11221122+ instrument : Object_ref.t option;
11231123+ to_ : Recipient.t list option;
11241124+ cc : Recipient.t list option;
11251125+ bto : Recipient.t list option;
11261126+ bcc : Recipient.t list option;
11271127+ published : Datetime.t option;
11281128+ updated : Datetime.t option;
11291129+ summary : string option;
11301130+ }
11311131+11321132+ let make ?context ?id ~type_ ~actor ?object_ ?target ?result ?origin
11331133+ ?instrument ?to_ ?cc ?bto ?bcc ?published ?updated ?summary () =
11341134+ { context; id; type_; actor; object_; target; result; origin;
11351135+ instrument; to_; cc; bto; bcc; published; updated; summary }
11361136+11371137+ let context t = t.context
11381138+ let id t = t.id
11391139+ let type_ t = t.type_
11401140+ let actor t = t.actor
11411141+ let object_ t = t.object_
11421142+ let target t = t.target
11431143+ let result t = t.result
11441144+ let origin t = t.origin
11451145+ let instrument t = t.instrument
11461146+ let to_ t = t.to_
11471147+ let cc t = t.cc
11481148+ let bto t = t.bto
11491149+ let bcc t = t.bcc
11501150+ let published t = t.published
11511151+ let updated t = t.updated
11521152+ let summary t = t.summary
11531153+11541154+ let jsont =
11551155+ Jsont.Object.map ~kind:"Activity"
11561156+ (fun context id type_ actor object_ target result origin instrument
11571157+ to_ cc bto bcc published updated summary ->
11581158+ { context; id; type_; actor; object_; target; result; origin;
11591159+ instrument; to_; cc; bto; bcc; published; updated; summary })
11601160+ |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context
11611161+ |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id
11621162+ |> Jsont.Object.mem "@type" Activity_type.jsont ~enc:type_
11631163+ |> Jsont.Object.mem "actor" Actor_ref.jsont ~enc:actor
11641164+ |> Jsont.Object.opt_mem "object" Object_ref.jsont ~enc:object_
11651165+ |> Jsont.Object.opt_mem "target" Object_ref.jsont ~enc:target
11661166+ |> Jsont.Object.opt_mem "result" Object_ref.jsont ~enc:result
11671167+ |> Jsont.Object.opt_mem "origin" Object_ref.jsont ~enc:origin
11681168+ |> Jsont.Object.opt_mem "instrument" Object_ref.jsont ~enc:instrument
11691169+ |> Jsont.Object.opt_mem "to" (Jsont.list Recipient.jsont) ~enc:to_
11701170+ |> Jsont.Object.opt_mem "cc" (Jsont.list Recipient.jsont) ~enc:cc
11711171+ |> Jsont.Object.opt_mem "bto" (Jsont.list Recipient.jsont) ~enc:bto
11721172+ |> Jsont.Object.opt_mem "bcc" (Jsont.list Recipient.jsont) ~enc:bcc
11731173+ |> Jsont.Object.opt_mem "published" Datetime.jsont ~enc:published
11741174+ |> Jsont.Object.opt_mem "updated" Datetime.jsont ~enc:updated
11751175+ |> Jsont.Object.opt_mem "summary" Jsont.string ~enc:summary
11761176+ |> Jsont.Object.finish
11771177+end
11781178+11791179+(** Activity reference - can be URI or full Activity. *)
11801180+module Activity_ref : sig
11811181+ type t =
11821182+ | Uri of Uri.t
11831183+ | Activity of Activity.t
11841184+11851185+ val uri : Uri.t -> t
11861186+ val activity : Activity.t -> t
11871187+ val jsont : t Jsont.t
11881188+end = struct
11891189+ type t =
11901190+ | Uri of Uri.t
11911191+ | Activity of Activity.t
11921192+11931193+ let uri u = Uri u
11941194+ let activity a = Activity a
11951195+11961196+ let jsont =
11971197+ let dec_string = Jsont.map Uri.jsont
11981198+ ~dec:(fun u -> Uri u)
11991199+ ~enc:(function Uri u -> u | Activity _ -> assert false) in
12001200+ let dec_object = Jsont.map Activity.jsont
12011201+ ~dec:(fun a -> Activity a)
12021202+ ~enc:(function Activity a -> a | Uri _ -> assert false) in
12031203+ Jsont.any ~kind:"Activity reference"
12041204+ ~dec_string ~dec_object
12051205+ ~enc:(function
12061206+ | Uri _ -> dec_string
12071207+ | Activity _ -> dec_object)
12081208+ ()
12091209+end
12101210+12111211+(** {1 Collection} *)
12121212+12131213+(** Collection objects.
12141214+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection> *)
12151215+module Collection : sig
12161216+ type 'a t
12171217+12181218+ val make :
12191219+ ?context:Context.t ->
12201220+ ?id:Uri.t ->
12211221+ ?total_items:int ->
12221222+ ?current:Uri.t ->
12231223+ ?first:Uri.t ->
12241224+ ?last:Uri.t ->
12251225+ ?items:'a list ->
12261226+ ordered:bool ->
12271227+ unit -> 'a t
12281228+12291229+ val context : 'a t -> Context.t option
12301230+ val id : 'a t -> Uri.t option
12311231+ val total_items : 'a t -> int option
12321232+ val current : 'a t -> Uri.t option
12331233+ val first : 'a t -> Uri.t option
12341234+ val last : 'a t -> Uri.t option
12351235+ val items : 'a t -> 'a list option
12361236+ val ordered : 'a t -> bool
12371237+12381238+ val jsont : 'a Jsont.t -> 'a t Jsont.t
12391239+end = struct
12401240+ type 'a t = {
12411241+ context : Context.t option;
12421242+ id : Uri.t option;
12431243+ total_items : int option;
12441244+ current : Uri.t option;
12451245+ first : Uri.t option;
12461246+ last : Uri.t option;
12471247+ items : 'a list option;
12481248+ ordered : bool;
12491249+ }
12501250+12511251+ let make ?context ?id ?total_items ?current ?first ?last ?items ~ordered () =
12521252+ { context; id; total_items; current; first; last; items; ordered }
12531253+12541254+ let context t = t.context
12551255+ let id t = t.id
12561256+ let total_items t = t.total_items
12571257+ let current t = t.current
12581258+ let first t = t.first
12591259+ let last t = t.last
12601260+ let items t = t.items
12611261+ let ordered t = t.ordered
12621262+12631263+ let jsont item_jsont =
12641264+ let type_jsont =
12651265+ Jsont.enum ~kind:"CollectionType" [
12661266+ "Collection", false;
12671267+ "OrderedCollection", true;
12681268+ ]
12691269+ in
12701270+ Jsont.Object.map ~kind:"Collection"
12711271+ (fun context id ordered total_items current first last items ->
12721272+ { context; id; total_items; current; first; last; items; ordered })
12731273+ |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context
12741274+ |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id
12751275+ |> Jsont.Object.mem "@type" type_jsont ~enc:ordered
12761276+ |> Jsont.Object.opt_mem "totalItems" Jsont.int ~enc:total_items
12771277+ |> Jsont.Object.opt_mem "current" Uri.jsont ~enc:current
12781278+ |> Jsont.Object.opt_mem "first" Uri.jsont ~enc:first
12791279+ |> Jsont.Object.opt_mem "last" Uri.jsont ~enc:last
12801280+ |> Jsont.Object.opt_mem "items" (Jsont.list item_jsont) ~enc:items
12811281+ |> Jsont.Object.finish
12821282+end
12831283+12841284+(** {1 Collection Page} *)
12851285+12861286+(** Collection page objects.
12871287+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage> *)
12881288+module Collection_page : sig
12891289+ type 'a t
12901290+12911291+ val make :
12921292+ ?context:Context.t ->
12931293+ ?id:Uri.t ->
12941294+ ?total_items:int ->
12951295+ ?current:Uri.t ->
12961296+ ?first:Uri.t ->
12971297+ ?last:Uri.t ->
12981298+ ?prev:Uri.t ->
12991299+ ?next:Uri.t ->
13001300+ ?part_of:Uri.t ->
13011301+ ?items:'a list ->
13021302+ ordered:bool ->
13031303+ unit -> 'a t
13041304+13051305+ val context : 'a t -> Context.t option
13061306+ val id : 'a t -> Uri.t option
13071307+ val total_items : 'a t -> int option
13081308+ val current : 'a t -> Uri.t option
13091309+ val first : 'a t -> Uri.t option
13101310+ val last : 'a t -> Uri.t option
13111311+ val prev : 'a t -> Uri.t option
13121312+ val next : 'a t -> Uri.t option
13131313+ val part_of : 'a t -> Uri.t option
13141314+ val items : 'a t -> 'a list option
13151315+ val ordered : 'a t -> bool
13161316+13171317+ val jsont : 'a Jsont.t -> 'a t Jsont.t
13181318+end = struct
13191319+ type 'a t = {
13201320+ context : Context.t option;
13211321+ id : Uri.t option;
13221322+ total_items : int option;
13231323+ current : Uri.t option;
13241324+ first : Uri.t option;
13251325+ last : Uri.t option;
13261326+ prev : Uri.t option;
13271327+ next : Uri.t option;
13281328+ part_of : Uri.t option;
13291329+ items : 'a list option;
13301330+ ordered : bool;
13311331+ }
13321332+13331333+ let make ?context ?id ?total_items ?current ?first ?last ?prev ?next
13341334+ ?part_of ?items ~ordered () =
13351335+ { context; id; total_items; current; first; last; prev; next;
13361336+ part_of; items; ordered }
13371337+13381338+ let context t = t.context
13391339+ let id t = t.id
13401340+ let total_items t = t.total_items
13411341+ let current t = t.current
13421342+ let first t = t.first
13431343+ let last t = t.last
13441344+ let prev t = t.prev
13451345+ let next t = t.next
13461346+ let part_of t = t.part_of
13471347+ let items t = t.items
13481348+ let ordered t = t.ordered
13491349+13501350+ let jsont item_jsont =
13511351+ let type_jsont =
13521352+ Jsont.enum ~kind:"CollectionPageType" [
13531353+ "CollectionPage", false;
13541354+ "OrderedCollectionPage", true;
13551355+ ]
13561356+ in
13571357+ Jsont.Object.map ~kind:"CollectionPage"
13581358+ (fun context id ordered total_items current first last prev next
13591359+ part_of items ->
13601360+ { context; id; total_items; current; first; last; prev; next;
13611361+ part_of; items; ordered })
13621362+ |> Jsont.Object.opt_mem "@context" Context.jsont ~enc:context
13631363+ |> Jsont.Object.opt_mem "@id" Uri.jsont ~enc:id
13641364+ |> Jsont.Object.mem "@type" type_jsont ~enc:ordered
13651365+ |> Jsont.Object.opt_mem "totalItems" Jsont.int ~enc:total_items
13661366+ |> Jsont.Object.opt_mem "current" Uri.jsont ~enc:current
13671367+ |> Jsont.Object.opt_mem "first" Uri.jsont ~enc:first
13681368+ |> Jsont.Object.opt_mem "last" Uri.jsont ~enc:last
13691369+ |> Jsont.Object.opt_mem "prev" Uri.jsont ~enc:prev
13701370+ |> Jsont.Object.opt_mem "next" Uri.jsont ~enc:next
13711371+ |> Jsont.Object.opt_mem "partOf" Uri.jsont ~enc:part_of
13721372+ |> Jsont.Object.opt_mem "items" (Jsont.list item_jsont) ~enc:items
13731373+ |> Jsont.Object.finish
13741374+end
13751375+13761376+(** {1 Convenience type aliases} *)
13771377+13781378+(** Activity collection. *)
13791379+module Activity_collection : sig
13801380+ type t = Activity.t Collection.t
13811381+ val jsont : t Jsont.t
13821382+end = struct
13831383+ type t = Activity.t Collection.t
13841384+ let jsont = Collection.jsont Activity.jsont
13851385+end
13861386+13871387+(** Object collection. *)
13881388+module Object_collection : sig
13891389+ type t = Object.t Collection.t
13901390+ val jsont : t Jsont.t
13911391+end = struct
13921392+ type t = Object.t Collection.t
13931393+ let jsont = Collection.jsont Object.jsont
13941394+end
13951395+13961396+(** Activity collection page. *)
13971397+module Activity_collection_page : sig
13981398+ type t = Activity.t Collection_page.t
13991399+ val jsont : t Jsont.t
14001400+end = struct
14011401+ type t = Activity.t Collection_page.t
14021402+ let jsont = Collection_page.jsont Activity.jsont
14031403+end
14041404+14051405+(** Object collection page. *)
14061406+module Object_collection_page : sig
14071407+ type t = Object.t Collection_page.t
14081408+ val jsont : t Jsont.t
14091409+end = struct
14101410+ type t = Object.t Collection_page.t
14111411+ let jsont = Collection_page.jsont Object.jsont
14121412+end
14131413+14141414+(** {1 Webfinger} *)
14151415+14161416+(** Webfinger JRD (JSON Resource Descriptor) for actor discovery.
14171417+ @see <https://www.rfc-editor.org/rfc/rfc7033> Webfinger RFC *)
14181418+module Webfinger : sig
14191419+ (** A link in the Webfinger response. *)
14201420+ module Jrd_link : sig
14211421+ type t
14221422+14231423+ val make :
14241424+ rel:string ->
14251425+ ?type_:string ->
14261426+ ?href:Uri.t ->
14271427+ ?template:string ->
14281428+ unit -> t
14291429+14301430+ val rel : t -> string
14311431+ val type_ : t -> string option
14321432+ val href : t -> Uri.t option
14331433+ val template : t -> string option
14341434+14351435+ val jsont : t Jsont.t
14361436+ end
14371437+14381438+ (** The Webfinger JRD response. *)
14391439+ type t
14401440+14411441+ val make :
14421442+ subject:string ->
14431443+ ?aliases:string list ->
14441444+ ?properties:(string * string) list ->
14451445+ ?links:Jrd_link.t list ->
14461446+ unit -> t
14471447+14481448+ val subject : t -> string
14491449+ val aliases : t -> string list option
14501450+ val properties : t -> (string * string) list option
14511451+ val links : t -> Jrd_link.t list option
14521452+14531453+ val jsont : t Jsont.t
14541454+end = struct
14551455+ module Jrd_link = struct
14561456+ type t = {
14571457+ rel : string;
14581458+ type_ : string option;
14591459+ href : Uri.t option;
14601460+ template : string option;
14611461+ }
14621462+14631463+ let make ~rel ?type_ ?href ?template () =
14641464+ { rel; type_; href; template }
14651465+14661466+ let rel t = t.rel
14671467+ let type_ t = t.type_
14681468+ let href t = t.href
14691469+ let template t = t.template
14701470+14711471+ let jsont =
14721472+ Jsont.Object.map ~kind:"JrdLink"
14731473+ (fun rel type_ href template -> { rel; type_; href; template })
14741474+ |> Jsont.Object.mem "rel" Jsont.string ~enc:rel
14751475+ |> Jsont.Object.opt_mem "type" Jsont.string ~enc:type_
14761476+ |> Jsont.Object.opt_mem "href" Uri.jsont ~enc:href
14771477+ |> Jsont.Object.opt_mem "template" Jsont.string ~enc:template
14781478+ |> Jsont.Object.finish
14791479+ end
14801480+14811481+ type t = {
14821482+ subject : string;
14831483+ aliases : string list option;
14841484+ properties : (string * string) list option;
14851485+ links : Jrd_link.t list option;
14861486+ }
14871487+14881488+ let make ~subject ?aliases ?properties ?links () =
14891489+ { subject; aliases; properties; links }
14901490+14911491+ let subject t = t.subject
14921492+ let aliases t = t.aliases
14931493+ let properties t = t.properties
14941494+ let links t = t.links
14951495+14961496+ module String_map = Map.Make(String)
14971497+14981498+ let properties_jsont =
14991499+ Jsont.Object.as_string_map Jsont.string
15001500+ |> Jsont.map
15011501+ ~dec:(fun m -> String_map.bindings m)
15021502+ ~enc:(fun l -> List.fold_left (fun m (k, v) ->
15031503+ String_map.add k v m) String_map.empty l)
15041504+15051505+ let jsont =
15061506+ Jsont.Object.map ~kind:"Webfinger"
15071507+ (fun subject aliases properties links ->
15081508+ { subject; aliases; properties; links })
15091509+ |> Jsont.Object.mem "subject" Jsont.string ~enc:subject
15101510+ |> Jsont.Object.opt_mem "aliases" (Jsont.list Jsont.string) ~enc:aliases
15111511+ |> Jsont.Object.opt_mem "properties" properties_jsont ~enc:properties
15121512+ |> Jsont.Object.opt_mem "links" (Jsont.list Jrd_link.jsont) ~enc:links
15131513+ |> Jsont.Object.finish
15141514+end
15151515+15161516+(** {1 NodeInfo} *)
15171517+15181518+(** NodeInfo protocol for server metadata discovery.
15191519+ @see <https://nodeinfo.diaspora.software/> NodeInfo specification *)
15201520+module Nodeinfo : sig
15211521+ (** Software information. *)
15221522+ module Software : sig
15231523+ type t
15241524+15251525+ val make :
15261526+ name:string ->
15271527+ version:string ->
15281528+ ?repository:Uri.t ->
15291529+ ?homepage:Uri.t ->
15301530+ unit -> t
15311531+15321532+ val name : t -> string
15331533+ val version : t -> string
15341534+ val repository : t -> Uri.t option
15351535+ val homepage : t -> Uri.t option
15361536+15371537+ val jsont : t Jsont.t
15381538+ end
15391539+15401540+ (** Usage statistics. *)
15411541+ module Usage : sig
15421542+ type t
15431543+15441544+ val make :
15451545+ ?users_total:int ->
15461546+ ?users_active_half_year:int ->
15471547+ ?users_active_month:int ->
15481548+ ?local_posts:int ->
15491549+ ?local_comments:int ->
15501550+ unit -> t
15511551+15521552+ val users_total : t -> int option
15531553+ val users_active_half_year : t -> int option
15541554+ val users_active_month : t -> int option
15551555+ val local_posts : t -> int option
15561556+ val local_comments : t -> int option
15571557+15581558+ val jsont : t Jsont.t
15591559+ end
15601560+15611561+ type t
15621562+15631563+ val make :
15641564+ version:string ->
15651565+ software:Software.t ->
15661566+ protocols:string list ->
15671567+ usage:Usage.t ->
15681568+ open_registrations:bool ->
15691569+ ?metadata:Jsont.json ->
15701570+ unit -> t
15711571+15721572+ val version : t -> string
15731573+ val software : t -> Software.t
15741574+ val protocols : t -> string list
15751575+ val usage : t -> Usage.t
15761576+ val open_registrations : t -> bool
15771577+ val metadata : t -> Jsont.json option
15781578+15791579+ val jsont : t Jsont.t
15801580+end = struct
15811581+ module Software = struct
15821582+ type t = {
15831583+ name : string;
15841584+ version : string;
15851585+ repository : Uri.t option;
15861586+ homepage : Uri.t option;
15871587+ }
15881588+15891589+ let make ~name ~version ?repository ?homepage () =
15901590+ { name; version; repository; homepage }
15911591+15921592+ let name t = t.name
15931593+ let version t = t.version
15941594+ let repository t = t.repository
15951595+ let homepage t = t.homepage
15961596+15971597+ let jsont =
15981598+ Jsont.Object.map ~kind:"Software"
15991599+ (fun name version repository homepage ->
16001600+ { name; version; repository; homepage })
16011601+ |> Jsont.Object.mem "name" Jsont.string ~enc:name
16021602+ |> Jsont.Object.mem "version" Jsont.string ~enc:version
16031603+ |> Jsont.Object.opt_mem "repository" Uri.jsont ~enc:repository
16041604+ |> Jsont.Object.opt_mem "homepage" Uri.jsont ~enc:homepage
16051605+ |> Jsont.Object.finish
16061606+ end
16071607+16081608+ module Usage = struct
16091609+ type t = {
16101610+ users_total : int option;
16111611+ users_active_half_year : int option;
16121612+ users_active_month : int option;
16131613+ local_posts : int option;
16141614+ local_comments : int option;
16151615+ }
16161616+16171617+ let make ?users_total ?users_active_half_year ?users_active_month
16181618+ ?local_posts ?local_comments () =
16191619+ { users_total; users_active_half_year; users_active_month;
16201620+ local_posts; local_comments }
16211621+16221622+ let users_total t = t.users_total
16231623+ let users_active_half_year t = t.users_active_half_year
16241624+ let users_active_month t = t.users_active_month
16251625+ let local_posts t = t.local_posts
16261626+ let local_comments t = t.local_comments
16271627+16281628+ let users_jsont =
16291629+ Jsont.Object.map ~kind:"Users"
16301630+ (fun total active_half_year active_month ->
16311631+ (total, active_half_year, active_month))
16321632+ |> Jsont.Object.opt_mem "total" Jsont.int
16331633+ ~enc:(fun (t, _, _) -> t)
16341634+ |> Jsont.Object.opt_mem "activeHalfyear" Jsont.int
16351635+ ~enc:(fun (_, h, _) -> h)
16361636+ |> Jsont.Object.opt_mem "activeMonth" Jsont.int
16371637+ ~enc:(fun (_, _, m) -> m)
16381638+ |> Jsont.Object.finish
16391639+16401640+ let jsont =
16411641+ Jsont.Object.map ~kind:"Usage"
16421642+ (fun (users_total, users_active_half_year, users_active_month)
16431643+ local_posts local_comments ->
16441644+ { users_total; users_active_half_year; users_active_month;
16451645+ local_posts; local_comments })
16461646+ |> Jsont.Object.mem "users" users_jsont
16471647+ ~dec_absent:(None, None, None)
16481648+ ~enc:(fun t -> (t.users_total, t.users_active_half_year,
16491649+ t.users_active_month))
16501650+ |> Jsont.Object.opt_mem "localPosts" Jsont.int ~enc:local_posts
16511651+ |> Jsont.Object.opt_mem "localComments" Jsont.int ~enc:local_comments
16521652+ |> Jsont.Object.finish
16531653+ end
16541654+16551655+ type t = {
16561656+ version : string;
16571657+ software : Software.t;
16581658+ protocols : string list;
16591659+ usage : Usage.t;
16601660+ open_registrations : bool;
16611661+ metadata : Jsont.json option;
16621662+ }
16631663+16641664+ let make ~version ~software ~protocols ~usage ~open_registrations
16651665+ ?metadata () =
16661666+ { version; software; protocols; usage; open_registrations; metadata }
16671667+16681668+ let version t = t.version
16691669+ let software t = t.software
16701670+ let protocols t = t.protocols
16711671+ let usage t = t.usage
16721672+ let open_registrations t = t.open_registrations
16731673+ let metadata t = t.metadata
16741674+16751675+ let jsont =
16761676+ Jsont.Object.map ~kind:"Nodeinfo"
16771677+ (fun version software protocols usage open_registrations metadata ->
16781678+ { version; software; protocols; usage; open_registrations; metadata })
16791679+ |> Jsont.Object.mem "version" Jsont.string ~enc:version
16801680+ |> Jsont.Object.mem "software" Software.jsont ~enc:software
16811681+ |> Jsont.Object.mem "protocols" (Jsont.list Jsont.string) ~enc:protocols
16821682+ |> Jsont.Object.mem "usage" Usage.jsont ~enc:usage
16831683+ |> Jsont.Object.mem "openRegistrations" Jsont.bool ~enc:open_registrations
16841684+ |> Jsont.Object.opt_mem "metadata" Jsont.json ~enc:metadata
16851685+ |> Jsont.Object.finish
16861686+end
+694
src/activitypub.mli
···11+(** ActivityPub/ActivityStreams types with jsont codecs.
22+33+ This module provides OCaml types and bidirectional JSON codecs for the
44+ ActivityPub and ActivityStreams 2.0 specifications.
55+66+ {1 Example}
77+88+ {[
99+ (* Decode an actor from JSON *)
1010+ let json_str = {|{"@id": "...", "@type": "Person", ...}|} in
1111+ match Jsont_codec.decode_string Actor.jsont json_str with
1212+ | Ok actor -> Printf.printf "Actor: %s\n" (Actor.name actor)
1313+ | Error e -> Printf.eprintf "Error: %s\n" e
1414+1515+ (* Create and encode a Note *)
1616+ let note = Object.make ~type_:Object_type.Note
1717+ ~content:"Hello ActivityPub!" () in
1818+ match Jsont_codec.encode_string Object.jsont note with
1919+ | Ok json_str -> print_endline json_str
2020+ | Error e -> Printf.eprintf "Error: %s\n" e
2121+ ]}
2222+2323+ @see <https://www.w3.org/TR/activitypub/> ActivityPub specification
2424+ @see <https://www.w3.org/TR/activitystreams-core/> ActivityStreams Core
2525+ @see <https://www.w3.org/TR/activitystreams-vocabulary/> ActivityStreams Vocabulary *)
2626+2727+(** {1 Common Types} *)
2828+2929+(** Timestamps in ISO 8601 format. *)
3030+module Datetime : sig
3131+ type t
3232+3333+ val v : string -> t
3434+ (** [v s] creates a datetime from the string [s]. *)
3535+3636+ val to_string : t -> string
3737+ (** [to_string t] returns the datetime as an ISO 8601 string. *)
3838+3939+ val jsont : t Jsont.t
4040+ (** JSON type for datetimes. *)
4141+end
4242+4343+(** URI identifiers. *)
4444+module Uri : sig
4545+ type t
4646+4747+ val v : string -> t
4848+ (** [v s] creates a URI from the string [s]. *)
4949+5050+ val to_string : t -> string
5151+ (** [to_string t] returns the URI as a string. *)
5252+5353+ val jsont : t Jsont.t
5454+ (** JSON type for URIs. *)
5555+end
5656+5757+(** JSON-LD context. *)
5858+module Context : sig
5959+ type t
6060+6161+ val default : t
6262+ (** The default ActivityStreams context. *)
6363+6464+ val jsont : t Jsont.t
6565+ (** JSON type for contexts. *)
6666+end
6767+6868+(** {1 Link} *)
6969+7070+(** Link objects represent references to other resources.
7171+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-link> *)
7272+module Link : sig
7373+ type t
7474+7575+ val make :
7676+ ?media_type:string ->
7777+ ?name:string ->
7878+ ?hreflang:string ->
7979+ ?height:int ->
8080+ ?width:int ->
8181+ ?preview:Uri.t ->
8282+ href:Uri.t ->
8383+ unit -> t
8484+ (** Create a new Link. *)
8585+8686+ val href : t -> Uri.t
8787+ val media_type : t -> string option
8888+ val name : t -> string option
8989+ val hreflang : t -> string option
9090+ val height : t -> int option
9191+ val width : t -> int option
9292+ val preview : t -> Uri.t option
9393+9494+ val jsont : t Jsont.t
9595+ (** JSON type for Links. *)
9696+end
9797+9898+(** Reference that can be either a URI string or a Link object. *)
9999+module Link_or_uri : sig
100100+ type t =
101101+ | Uri of Uri.t
102102+ | Link of Link.t
103103+104104+ val uri : Uri.t -> t
105105+ val link : Link.t -> t
106106+ val jsont : t Jsont.t
107107+end
108108+109109+(** {1 Image} *)
110110+111111+(** Image objects.
112112+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-image> *)
113113+module Image : sig
114114+ type t
115115+116116+ val make :
117117+ ?id:Uri.t ->
118118+ ?name:string ->
119119+ ?media_type:string ->
120120+ ?width:int ->
121121+ ?height:int ->
122122+ url:Link_or_uri.t ->
123123+ unit -> t
124124+125125+ val id : t -> Uri.t option
126126+ val url : t -> Link_or_uri.t
127127+ val name : t -> string option
128128+ val media_type : t -> string option
129129+ val width : t -> int option
130130+ val height : t -> int option
131131+132132+ val jsont : t Jsont.t
133133+end
134134+135135+(** Image reference - can be URI, Link, or full Image object. *)
136136+module Image_ref : sig
137137+ type t =
138138+ | Uri of Uri.t
139139+ | Link of Link.t
140140+ | Image of Image.t
141141+142142+ val uri : Uri.t -> t
143143+ val link : Link.t -> t
144144+ val image : Image.t -> t
145145+ val jsont : t Jsont.t
146146+end
147147+148148+(** {1 Public Collection} *)
149149+150150+(** Special public addressing collection. *)
151151+module Public : sig
152152+ val id : Uri.t
153153+ (** The public collection URI for addressing public posts. *)
154154+end
155155+156156+(** {1 Recipient} *)
157157+158158+(** Recipient reference - can be URI or inline object with id and type. *)
159159+module Recipient : sig
160160+ type t
161161+162162+ val make : ?type_:string -> Uri.t -> t
163163+ val id : t -> Uri.t
164164+ val type_ : t -> string option
165165+ val jsont : t Jsont.t
166166+end
167167+168168+(** {1 Endpoints} *)
169169+170170+(** Actor endpoints for special server URLs. *)
171171+module Endpoints : sig
172172+ type t
173173+174174+ val make :
175175+ ?proxy_url:Uri.t ->
176176+ ?oauth_authorization_endpoint:Uri.t ->
177177+ ?oauth_token_endpoint:Uri.t ->
178178+ ?provide_client_key:Uri.t ->
179179+ ?sign_client_key:Uri.t ->
180180+ ?shared_inbox:Uri.t ->
181181+ unit -> t
182182+183183+ val proxy_url : t -> Uri.t option
184184+ val oauth_authorization_endpoint : t -> Uri.t option
185185+ val oauth_token_endpoint : t -> Uri.t option
186186+ val provide_client_key : t -> Uri.t option
187187+ val sign_client_key : t -> Uri.t option
188188+ val shared_inbox : t -> Uri.t option
189189+190190+ val jsont : t Jsont.t
191191+end
192192+193193+(** {1 Public Key} *)
194194+195195+(** Public key for HTTP Signatures. *)
196196+module Public_key : sig
197197+ type t
198198+199199+ val make :
200200+ id:Uri.t ->
201201+ owner:Uri.t ->
202202+ public_key_pem:string ->
203203+ unit -> t
204204+205205+ val id : t -> Uri.t
206206+ val owner : t -> Uri.t
207207+ val public_key_pem : t -> string
208208+209209+ val jsont : t Jsont.t
210210+end
211211+212212+(** {1 Actor Types} *)
213213+214214+(** Actor types enumeration. *)
215215+module Actor_type : sig
216216+ type t =
217217+ | Person
218218+ | Service
219219+ | Organization
220220+ | Group
221221+ | Application
222222+223223+ val to_string : t -> string
224224+ val of_string : string -> t option
225225+ val jsont : t Jsont.t
226226+end
227227+228228+(** {1 Actor} *)
229229+230230+(** Actor objects represent entities that can perform activities.
231231+ @see <https://www.w3.org/TR/activitypub/#actor-objects> *)
232232+module Actor : sig
233233+ type t
234234+235235+ val make :
236236+ ?context:Context.t ->
237237+ id:Uri.t ->
238238+ type_:Actor_type.t ->
239239+ ?name:string ->
240240+ ?preferred_username:string ->
241241+ ?summary:string ->
242242+ ?url:Uri.t ->
243243+ inbox:Uri.t ->
244244+ outbox:Uri.t ->
245245+ ?followers:Uri.t ->
246246+ ?following:Uri.t ->
247247+ ?liked:Uri.t ->
248248+ ?streams:Uri.t list ->
249249+ ?endpoints:Endpoints.t ->
250250+ ?public_key:Public_key.t ->
251251+ ?icon:Image_ref.t list ->
252252+ ?image:Image_ref.t list ->
253253+ ?manually_approves_followers:bool ->
254254+ unit -> t
255255+ (** Create a new Actor. *)
256256+257257+ val context : t -> Context.t option
258258+ val id : t -> Uri.t
259259+ val type_ : t -> Actor_type.t
260260+ val name : t -> string option
261261+ val preferred_username : t -> string option
262262+ val summary : t -> string option
263263+ val url : t -> Uri.t option
264264+ val inbox : t -> Uri.t
265265+ val outbox : t -> Uri.t
266266+ val followers : t -> Uri.t option
267267+ val following : t -> Uri.t option
268268+ val liked : t -> Uri.t option
269269+ val streams : t -> Uri.t list option
270270+ val endpoints : t -> Endpoints.t option
271271+ val public_key : t -> Public_key.t option
272272+ val icon : t -> Image_ref.t list option
273273+ val image : t -> Image_ref.t list option
274274+ val manually_approves_followers : t -> bool option
275275+276276+ val jsont : t Jsont.t
277277+ (** JSON type for Actors. *)
278278+end
279279+280280+(** Actor reference - can be URI or full Actor object. *)
281281+module Actor_ref : sig
282282+ type t =
283283+ | Uri of Uri.t
284284+ | Actor of Actor.t
285285+286286+ val uri : Uri.t -> t
287287+ val actor : Actor.t -> t
288288+ val jsont : t Jsont.t
289289+end
290290+291291+(** {1 Object Types} *)
292292+293293+(** Object types enumeration. *)
294294+module Object_type : sig
295295+ type t =
296296+ | Note
297297+ | Article
298298+ | Page
299299+ | Event
300300+ | Image
301301+ | Video
302302+ | Audio
303303+ | Document
304304+ | Place
305305+ | Profile
306306+ | Tombstone
307307+ | Collection
308308+ | OrderedCollection
309309+310310+ val to_string : t -> string
311311+ val of_string : string -> t option
312312+ val jsont : t Jsont.t
313313+end
314314+315315+(** {1 Object} *)
316316+317317+(** ActivityStreams objects.
318318+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#object-types> *)
319319+module Object : sig
320320+ type t
321321+322322+ val make :
323323+ ?context:Context.t ->
324324+ ?id:Uri.t ->
325325+ type_:Object_type.t ->
326326+ ?name:string ->
327327+ ?summary:string ->
328328+ ?content:string ->
329329+ ?media_type:string ->
330330+ ?url:Link_or_uri.t list ->
331331+ ?attributed_to:Actor_ref.t ->
332332+ ?in_reply_to:Uri.t ->
333333+ ?published:Datetime.t ->
334334+ ?updated:Datetime.t ->
335335+ ?deleted:Datetime.t ->
336336+ ?to_:Recipient.t list ->
337337+ ?cc:Recipient.t list ->
338338+ ?bto:Recipient.t list ->
339339+ ?bcc:Recipient.t list ->
340340+ ?replies:Uri.t ->
341341+ ?attachment:Link_or_uri.t list ->
342342+ ?tag:Link_or_uri.t list ->
343343+ ?generator:Uri.t ->
344344+ ?icon:Image_ref.t list ->
345345+ ?image:Image_ref.t list ->
346346+ ?start_time:Datetime.t ->
347347+ ?end_time:Datetime.t ->
348348+ ?duration:string ->
349349+ ?sensitive:bool ->
350350+ unit -> t
351351+ (** Create a new Object. *)
352352+353353+ val context : t -> Context.t option
354354+ val id : t -> Uri.t option
355355+ val type_ : t -> Object_type.t
356356+ val name : t -> string option
357357+ val summary : t -> string option
358358+ val content : t -> string option
359359+ val media_type : t -> string option
360360+ val url : t -> Link_or_uri.t list option
361361+ val attributed_to : t -> Actor_ref.t option
362362+ val in_reply_to : t -> Uri.t option
363363+ val published : t -> Datetime.t option
364364+ val updated : t -> Datetime.t option
365365+ val deleted : t -> Datetime.t option
366366+ val to_ : t -> Recipient.t list option
367367+ val cc : t -> Recipient.t list option
368368+ val bto : t -> Recipient.t list option
369369+ val bcc : t -> Recipient.t list option
370370+ val replies : t -> Uri.t option
371371+ val attachment : t -> Link_or_uri.t list option
372372+ val tag : t -> Link_or_uri.t list option
373373+ val generator : t -> Uri.t option
374374+ val icon : t -> Image_ref.t list option
375375+ val image : t -> Image_ref.t list option
376376+ val start_time : t -> Datetime.t option
377377+ val end_time : t -> Datetime.t option
378378+ val duration : t -> string option
379379+ val sensitive : t -> bool option
380380+381381+ val jsont : t Jsont.t
382382+ (** JSON type for Objects. *)
383383+end
384384+385385+(** Object reference - can be URI or full Object. *)
386386+module Object_ref : sig
387387+ type t =
388388+ | Uri of Uri.t
389389+ | Object of Object.t
390390+391391+ val uri : Uri.t -> t
392392+ val obj : Object.t -> t
393393+ val jsont : t Jsont.t
394394+end
395395+396396+(** {1 Activity Types} *)
397397+398398+(** Activity types enumeration. *)
399399+module Activity_type : sig
400400+ type t =
401401+ | Create
402402+ | Update
403403+ | Delete
404404+ | Follow
405405+ | Accept
406406+ | Reject
407407+ | Add
408408+ | Remove
409409+ | Like
410410+ | Announce
411411+ | Undo
412412+ | Block
413413+ | Flag
414414+ | Dislike
415415+ | Ignore
416416+ | Invite
417417+ | Join
418418+ | Leave
419419+ | Listen
420420+ | Move
421421+ | Offer
422422+ | Question
423423+ | Read
424424+ | TentativeAccept
425425+ | TentativeReject
426426+ | Travel
427427+ | View
428428+429429+ val to_string : t -> string
430430+ val of_string : string -> t option
431431+ val jsont : t Jsont.t
432432+end
433433+434434+(** {1 Activity} *)
435435+436436+(** ActivityPub activities.
437437+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#activity-types> *)
438438+module Activity : sig
439439+ type t
440440+441441+ val make :
442442+ ?context:Context.t ->
443443+ ?id:Uri.t ->
444444+ type_:Activity_type.t ->
445445+ actor:Actor_ref.t ->
446446+ ?object_:Object_ref.t ->
447447+ ?target:Object_ref.t ->
448448+ ?result:Object_ref.t ->
449449+ ?origin:Object_ref.t ->
450450+ ?instrument:Object_ref.t ->
451451+ ?to_:Recipient.t list ->
452452+ ?cc:Recipient.t list ->
453453+ ?bto:Recipient.t list ->
454454+ ?bcc:Recipient.t list ->
455455+ ?published:Datetime.t ->
456456+ ?updated:Datetime.t ->
457457+ ?summary:string ->
458458+ unit -> t
459459+ (** Create a new Activity. *)
460460+461461+ val context : t -> Context.t option
462462+ val id : t -> Uri.t option
463463+ val type_ : t -> Activity_type.t
464464+ val actor : t -> Actor_ref.t
465465+ val object_ : t -> Object_ref.t option
466466+ val target : t -> Object_ref.t option
467467+ val result : t -> Object_ref.t option
468468+ val origin : t -> Object_ref.t option
469469+ val instrument : t -> Object_ref.t option
470470+ val to_ : t -> Recipient.t list option
471471+ val cc : t -> Recipient.t list option
472472+ val bto : t -> Recipient.t list option
473473+ val bcc : t -> Recipient.t list option
474474+ val published : t -> Datetime.t option
475475+ val updated : t -> Datetime.t option
476476+ val summary : t -> string option
477477+478478+ val jsont : t Jsont.t
479479+ (** JSON type for Activities. *)
480480+end
481481+482482+(** Activity reference - can be URI or full Activity. *)
483483+module Activity_ref : sig
484484+ type t =
485485+ | Uri of Uri.t
486486+ | Activity of Activity.t
487487+488488+ val uri : Uri.t -> t
489489+ val activity : Activity.t -> t
490490+ val jsont : t Jsont.t
491491+end
492492+493493+(** {1 Collection} *)
494494+495495+(** Collection objects.
496496+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collection> *)
497497+module Collection : sig
498498+ type 'a t
499499+500500+ val make :
501501+ ?context:Context.t ->
502502+ ?id:Uri.t ->
503503+ ?total_items:int ->
504504+ ?current:Uri.t ->
505505+ ?first:Uri.t ->
506506+ ?last:Uri.t ->
507507+ ?items:'a list ->
508508+ ordered:bool ->
509509+ unit -> 'a t
510510+ (** Create a new Collection. Use [~ordered:true] for OrderedCollection. *)
511511+512512+ val context : 'a t -> Context.t option
513513+ val id : 'a t -> Uri.t option
514514+ val total_items : 'a t -> int option
515515+ val current : 'a t -> Uri.t option
516516+ val first : 'a t -> Uri.t option
517517+ val last : 'a t -> Uri.t option
518518+ val items : 'a t -> 'a list option
519519+ val ordered : 'a t -> bool
520520+521521+ val jsont : 'a Jsont.t -> 'a t Jsont.t
522522+ (** JSON type for Collections, parameterized by item type. *)
523523+end
524524+525525+(** {1 Collection Page} *)
526526+527527+(** Collection page objects.
528528+ @see <https://www.w3.org/TR/activitystreams-vocabulary/#dfn-collectionpage> *)
529529+module Collection_page : sig
530530+ type 'a t
531531+532532+ val make :
533533+ ?context:Context.t ->
534534+ ?id:Uri.t ->
535535+ ?total_items:int ->
536536+ ?current:Uri.t ->
537537+ ?first:Uri.t ->
538538+ ?last:Uri.t ->
539539+ ?prev:Uri.t ->
540540+ ?next:Uri.t ->
541541+ ?part_of:Uri.t ->
542542+ ?items:'a list ->
543543+ ordered:bool ->
544544+ unit -> 'a t
545545+ (** Create a new CollectionPage. Use [~ordered:true] for OrderedCollectionPage. *)
546546+547547+ val context : 'a t -> Context.t option
548548+ val id : 'a t -> Uri.t option
549549+ val total_items : 'a t -> int option
550550+ val current : 'a t -> Uri.t option
551551+ val first : 'a t -> Uri.t option
552552+ val last : 'a t -> Uri.t option
553553+ val prev : 'a t -> Uri.t option
554554+ val next : 'a t -> Uri.t option
555555+ val part_of : 'a t -> Uri.t option
556556+ val items : 'a t -> 'a list option
557557+ val ordered : 'a t -> bool
558558+559559+ val jsont : 'a Jsont.t -> 'a t Jsont.t
560560+ (** JSON type for CollectionPages, parameterized by item type. *)
561561+end
562562+563563+(** {1 Convenience type aliases} *)
564564+565565+(** Activity collection. *)
566566+module Activity_collection : sig
567567+ type t = Activity.t Collection.t
568568+ val jsont : t Jsont.t
569569+end
570570+571571+(** Object collection. *)
572572+module Object_collection : sig
573573+ type t = Object.t Collection.t
574574+ val jsont : t Jsont.t
575575+end
576576+577577+(** Activity collection page. *)
578578+module Activity_collection_page : sig
579579+ type t = Activity.t Collection_page.t
580580+ val jsont : t Jsont.t
581581+end
582582+583583+(** Object collection page. *)
584584+module Object_collection_page : sig
585585+ type t = Object.t Collection_page.t
586586+ val jsont : t Jsont.t
587587+end
588588+589589+(** {1 Webfinger} *)
590590+591591+(** Webfinger JRD (JSON Resource Descriptor) for actor discovery.
592592+ @see <https://www.rfc-editor.org/rfc/rfc7033> Webfinger RFC *)
593593+module Webfinger : sig
594594+ (** A link in the Webfinger response. *)
595595+ module Jrd_link : sig
596596+ type t
597597+598598+ val make :
599599+ rel:string ->
600600+ ?type_:string ->
601601+ ?href:Uri.t ->
602602+ ?template:string ->
603603+ unit -> t
604604+605605+ val rel : t -> string
606606+ val type_ : t -> string option
607607+ val href : t -> Uri.t option
608608+ val template : t -> string option
609609+610610+ val jsont : t Jsont.t
611611+ end
612612+613613+ type t
614614+615615+ val make :
616616+ subject:string ->
617617+ ?aliases:string list ->
618618+ ?properties:(string * string) list ->
619619+ ?links:Jrd_link.t list ->
620620+ unit -> t
621621+622622+ val subject : t -> string
623623+ val aliases : t -> string list option
624624+ val properties : t -> (string * string) list option
625625+ val links : t -> Jrd_link.t list option
626626+627627+ val jsont : t Jsont.t
628628+end
629629+630630+(** {1 NodeInfo} *)
631631+632632+(** NodeInfo protocol for server metadata discovery.
633633+ @see <https://nodeinfo.diaspora.software/> NodeInfo specification *)
634634+module Nodeinfo : sig
635635+ (** Software information. *)
636636+ module Software : sig
637637+ type t
638638+639639+ val make :
640640+ name:string ->
641641+ version:string ->
642642+ ?repository:Uri.t ->
643643+ ?homepage:Uri.t ->
644644+ unit -> t
645645+646646+ val name : t -> string
647647+ val version : t -> string
648648+ val repository : t -> Uri.t option
649649+ val homepage : t -> Uri.t option
650650+651651+ val jsont : t Jsont.t
652652+ end
653653+654654+ (** Usage statistics. *)
655655+ module Usage : sig
656656+ type t
657657+658658+ val make :
659659+ ?users_total:int ->
660660+ ?users_active_half_year:int ->
661661+ ?users_active_month:int ->
662662+ ?local_posts:int ->
663663+ ?local_comments:int ->
664664+ unit -> t
665665+666666+ val users_total : t -> int option
667667+ val users_active_half_year : t -> int option
668668+ val users_active_month : t -> int option
669669+ val local_posts : t -> int option
670670+ val local_comments : t -> int option
671671+672672+ val jsont : t Jsont.t
673673+ end
674674+675675+ type t
676676+677677+ val make :
678678+ version:string ->
679679+ software:Software.t ->
680680+ protocols:string list ->
681681+ usage:Usage.t ->
682682+ open_registrations:bool ->
683683+ ?metadata:Jsont.json ->
684684+ unit -> t
685685+686686+ val version : t -> string
687687+ val software : t -> Software.t
688688+ val protocols : t -> string list
689689+ val usage : t -> Usage.t
690690+ val open_registrations : t -> bool
691691+ val metadata : t -> Jsont.json option
692692+693693+ val jsont : t Jsont.t
694694+end