Something went wrong. Try again.
Correctness- and interoperability-oriented Tangled CLI
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244open Camlet_domain
let optional_string to_string = function | None -> `Null | Some value -> `String (to_string value)
let int64_json value = `Intlit (Int64.to_string value)
let blob_json (blob : Issue_view.blob) = `Assoc [ ("cid", `String (Cid.to_string blob.Issue_view.cid)) ; ("mime_type", `String blob.mime_type) ; ("size", int64_json blob.size) ]
let strong_ref_json (reference : Issue_view.strong_ref) = `Assoc [ ("uri", `String (At_uri.to_string reference.Issue_view.uri)) ; ("cid", `String (Cid.to_string reference.cid)) ]
let coverage_json (coverage : Issue_list.coverage) = `Assoc [ ("ready", `Bool coverage.Issue_list.ready) ; ("events_processed", int64_json coverage.events_processed) ; ("last_cursor", int64_json coverage.last_cursor) ]
let state_record_json = function | None -> `Null | Some (state : Issue_view.state_record) -> `Assoc [ ("uri", `String (At_uri.to_string state.Issue_view.uri)) ; ("cid", optional_string Cid.to_string state.cid) ]
let comment_json (comment : Issue_view.comment) = `Assoc [ ("author_did", `String (Did.to_string comment.Issue_view.author_did)) ; ( "record" , `Assoc [ ("uri", `String (At_uri.to_string comment.uri)) ; ("cid", optional_string Cid.to_string comment.cid) ; ("created_at", `String (Timestamp.to_string comment.created_at)) ] ) ; ( "content" , `Assoc [ ("format", `String "markdown") ; ("text", `String comment.body.text) ; ("original", optional_string Fun.id comment.body.original) ; ("blobs", `List (List.map blob_json comment.body.blobs)) ] ) ; ("subject", strong_ref_json comment.subject) ; ( "reply_to" , match comment.reply_to with | None -> `Null | Some reference -> strong_ref_json reference ) ]
let json view = let issue = view.Issue_view.issue in `Assoc [ ("schema", `String "org.camlet.issue.v1") ; ( "result" , `Assoc [ ( "repository" , `Assoc [ ( "did" , `String (Repository_did.to_string view.repository.repository_did) ) ] ) ; ( "issue" , `Assoc [ ("id", `String (Record_key.to_string issue.record_key)) ; ( "author" , `Assoc [ ("did", `String (Did.to_string issue.author_did)) ] ) ; ( "record" , `Assoc [ ("uri", `String (At_uri.to_string issue.uri)) ; ("cid", optional_string Cid.to_string issue.cid) ; ( "created_at" , `String (Timestamp.to_string issue.created_at) ) ] ) ; ( "content" , `Assoc [ ("title", `String issue.title) ; ("body", optional_string Fun.id issue.body) ; ( "mentions" , `List (List.map (fun did -> `String did) issue.mentions) ) ; ( "references" , `List (List.map (fun uri -> `String (At_uri.to_string uri)) issue.references) ) ; ("blobs", `List (List.map blob_json issue.blobs)) ] ) ; ( "derived" , `Assoc [ ( "state" , `String (Issue_list.state_to_string view.state) ) ; ( "state_updated_at" , optional_string Timestamp.to_string (Option.map (fun (state : Issue_view.state_record) -> state.created_at) view.state_record) ) ; ("state_record", state_record_json view.state_record) ] ) ] ) ; ("comments", `List (List.map comment_json view.comments)) ; ( "observation" , `Assoc [ ("observed_at", `String (Timestamp.to_string view.observed_at)) ; ( "base" , `Assoc [ ( "freshness" , `String "author_pds_latest_record_at_observation" ) ] ) ; ( "relations" , `Assoc [ ( "source" , `Assoc [ ("kind", `String "bobbin") ; ( "endpoint" , `String (Origin.to_string view.bobbin) ) ] ) ; ("enumeration", `String "bobbin_complete_pagination") ; ( "verification" , `String "source_pds_current_record_match" ) ; ("snapshot", `String "non_atomic") ; ("completeness", `String "indexed_observation_only") ; ( "coverage" , `Assoc [ ("before", coverage_json view.coverage_before) ; ("after", coverage_json view.coverage_after) ] ) ] ) ; ( "authorities" , `List (List.map (fun value -> `String value) [ "plc_directory" ; "issue_author_pds_record" ; "repository_identity_chain" ; "bobbin_relation_index" ; "related_record_author_pds" ]) ) ] ) ] ) ] |> Yojson.Safe.to_string
let human_cid = function | None -> "not returned" | Some value -> Cid.to_string value
let human_state_record = function | None -> "none; state defaults to open" | Some (state : Issue_view.state_record) -> At_uri.to_string state.uri
let human_state_updated = function | None -> "not applicable" | Some (state : Issue_view.state_record) -> Timestamp.to_string state.created_at
let human_comment index (comment : Issue_view.comment) = let reply = match comment.reply_to with | None -> [] | Some reference -> [ Human_format.field ~indent:4 "Reply to" (At_uri.to_string reference.uri) ] in Human_format.section (Printf.sprintf " Comment %d" index) ([ Human_format.field ~indent:4 "Author" (Did.to_string comment.author_did) ; Human_format.field ~indent:4 "Created" (Timestamp.to_string comment.created_at) ; Human_format.field ~indent:4 "URI" (At_uri.to_string comment.uri) ; Human_format.field ~indent:4 "CID" (human_cid comment.cid) ] @ reply @ (" Body:" :: Human_format.escaped_lines ~indent:6 comment.body.text))
let coverage_human before after = let readiness value = if value.Issue_list.ready then "ready" else "warming" in Printf.sprintf "%s -> %s; events %Ld -> %Ld; cursor %Ld -> %Ld" (readiness before) (readiness after) before.events_processed after.events_processed before.last_cursor after.last_cursor
let human (view : Issue_view.t) = let issue = view.Issue_view.issue in let content_lines = match issue.body with | None -> [ Human_format.field "Body" "none" ] | Some value -> " Body:" :: Human_format.escaped_lines ~indent:4 value in let comments = match view.comments with | [] -> [ Human_format.field "Status" "no indexed comments observed" ] | values -> List.mapi (fun index value -> human_comment (index + 1) value) values |> Human_format.blocks in Human_format.document [ Human_format.section "Issue" [ Human_format.field "ID" (Record_key.to_string issue.record_key) ; Human_format.field "URI" (At_uri.to_string issue.uri) ; Human_format.field "CID" (human_cid issue.cid) ; Human_format.field "Repository" (Repository_did.to_string issue.repository_did) ; Human_format.field "Author" (Did.to_string issue.author_did) ; Human_format.field "State" (Issue_list.state_to_string view.state |> String.escaped) ; Human_format.field "State record" (human_state_record view.state_record) ; Human_format.field "State updated" (human_state_updated view.state_record) ] ; Human_format.section "Content" ([ Human_format.field "Created" (Timestamp.to_string issue.created_at) ; Human_format.field "Title" (String.escaped issue.title) ] @ content_lines) ; Human_format.section (Printf.sprintf "Comments (%d)" (List.length view.comments)) comments ; Human_format.section "Observation" [ Human_format.field "Time" (Timestamp.to_string view.observed_at) ; Human_format.field "Base" "latest issue-author PDS record" ; Human_format.field "Relations" "Bobbin complete pagination; source-PDS verified" ; Human_format.field "Coverage" (coverage_human view.coverage_before view.coverage_after) ; Human_format.field "Snapshot" "non-atomic" ; Human_format.field "Completeness" "indexed relations only" ] ]