diff options
author | Marc Coquand <marc@mccd.space> | 2023-12-20 20:46:00 -0600 |
---|---|---|
committer | Marc Coquand <marc@mccd.space> | 2023-12-25 18:22:59 -0600 |
commit | 262f161f42c4e59beec41c6f440336c38385426a (patch) | |
tree | 6491c9b661a0b5a14c9a30ecf25e036f8762239d /lib/activitypub/common.ml | |
parent | cc783c157f31e7e713c8b83be67449b1859dac27 (diff) | |
download | fixgen-262f161f42c4e59beec41c6f440336c38385426a.tar.gz fixgen-262f161f42c4e59beec41c6f440336c38385426a.tar.bz2 fixgen-262f161f42c4e59beec41c6f440336c38385426a.zip |
Initial commit
Diffstat (limited to 'lib/activitypub/common.ml')
-rw-r--r-- | lib/activitypub/common.ml | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/lib/activitypub/common.ml b/lib/activitypub/common.ml deleted file mode 100644 index 59c7099..0000000 --- a/lib/activitypub/common.ml +++ /dev/null @@ -1,47 +0,0 @@ -module D = Decoders_yojson.Safe.Decode - -let timestamp = - let open D in - let* time = string in - match Ptime.of_rfc3339 time |> Ptime.rfc3339_error_to_msg with - | Ok (t, _, _) -> succeed t - | Error `Msg err -> fail err - -let singleton_or_list dec = - D.(one_of ["singleton", (dec >|= fun v -> [v]); - "list", list dec; - "null", null >|= fun () -> []]) - -let lossy_list_of dec = - let open D in - list (one_of ["known", (dec >|= fun v -> `Value v); "unknown", value >|= fun v -> `Raw v]) - - -let constant ?msg target = - let open D in - let* str = string in - if String.equal str target - then succeed () - else match msg with - | None -> fail (Printf.sprintf "expected %s received %s" target str) - | Some msg -> fail (Printf.sprintf msg str) - -let field_or_default field' decoder default = - let open D in - let+ field = field_opt field' decoder in - Option.value ~default field - -let list_ignoring_unknown ty = - let open D in - list (maybe ty) >|= fun v -> List.filter_map Fun.id v - -let items obj = - let open D in - one_of [ - ("ordered items", - let* items = field "orderedItems" (list obj) in - succeed (true, items)); - "items", - let* items = field "items" (list obj) in - succeed (false, items) - ] |