Google Docs API client for OCaml
0
fork

Configure Feed

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

wal, block, sse, zephyr: remove [mutable] from never-reassigned fields

Warning 69 (unused-field, mutable-never-assigned). Four independent
record fields were flagged as mutable but the code only mutates their
referents in place, never rebinds the record slot itself:

- ocaml-wal/lib/wal.ml: [t.file] (the Eio file resource; methods call
Eio.File.pwrite_all etc., the slot is set once at open time).
- ocaml-block/lib/block.ml: [Memory.state.data] (the backing bytes,
written via Bytes.blit_string; [Bytes.t] is already mutable).
- ocaml-sse/lib/sse.ml: [Parser.t.data_buf] (a Buffer.t, written via
Buffer.add_*; the slot never changes).
- ocaml-zephyr/lib/zephyr.ml: drop [mode : Read | Write] entirely —
set at open-time, read nowhere. The open_read / open_write
constructors already distinguish the two call shapes, so mode
tracking was redundant.

+45 -42
+3
dune
··· 1 + (env 2 + (dev 3 + (flags :standard %{dune-warnings})))
+1 -1
dune-project
··· 27 27 (fmt (>= 0.9)) 28 28 (gauth (>= 0.1)) 29 29 (http (>= 0.1)) 30 - (jsont (>= 0.2)) 30 + (json (>= 0.2)) 31 31 (bytesrw (>= 0.1)) 32 32 (logs (>= 0.7)) 33 33 (oauth (>= 0.1))
+1 -1
gdocs.opam
··· 21 21 "fmt" {>= "0.9"} 22 22 "gauth" {>= "0.1"} 23 23 "http" {>= "0.1"} 24 - "jsont" {>= "0.2"} 24 + "json" {>= "0.2"} 25 25 "bytesrw" {>= "0.1"} 26 26 "logs" {>= "0.7"} 27 27 "oauth" {>= "0.1"}
+18 -18
lib/comments.ml
··· 37 37 type raw_author = { display_name : string } 38 38 39 39 let author_jsont = 40 - Jsont.Object.map ~kind:"author" (fun display_name -> { display_name }) 41 - |> Jsont.Object.mem "displayName" Jsont.string ~dec_absent:"" ~enc:(fun a -> 40 + Json.Object.map ~kind:"author" (fun display_name -> { display_name }) 41 + |> Json.Object.mem "displayName" Json.string ~dec_absent:"" ~enc:(fun a -> 42 42 a.display_name) 43 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 43 + |> Json.Object.skip_unknown |> Json.Object.finish 44 44 45 45 type raw_quoted = { value : string } 46 46 47 47 let quoted_jsont = 48 - Jsont.Object.map ~kind:"quotedFileContent" (fun value -> { value }) 49 - |> Jsont.Object.mem "value" Jsont.string ~dec_absent:"" ~enc:(fun q -> 48 + Json.Object.map ~kind:"quotedFileContent" (fun value -> { value }) 49 + |> Json.Object.mem "value" Json.string ~dec_absent:"" ~enc:(fun q -> 50 50 q.value) 51 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 51 + |> Json.Object.skip_unknown |> Json.Object.finish 52 52 53 53 let comment_jsont = 54 - Jsont.Object.map ~kind:"comment" 54 + Json.Object.map ~kind:"comment" 55 55 (fun id author content quoted anchor resolved -> 56 56 { 57 57 id; ··· 61 61 anchor; 62 62 resolved; 63 63 }) 64 - |> Jsont.Object.mem "id" Jsont.string ~enc:(fun c -> c.id) 65 - |> Jsont.Object.opt_mem "author" author_jsont ~enc:(fun _ -> None) 66 - |> Jsont.Object.mem "content" Jsont.string ~dec_absent:"" ~enc:(fun c -> 64 + |> Json.Object.mem "id" Json.string ~enc:(fun c -> c.id) 65 + |> Json.Object.opt_mem "author" author_jsont ~enc:(fun _ -> None) 66 + |> Json.Object.mem "content" Json.string ~dec_absent:"" ~enc:(fun c -> 67 67 c.content) 68 - |> Jsont.Object.opt_mem "quotedFileContent" quoted_jsont ~enc:(fun _ -> None) 69 - |> Jsont.Object.opt_mem "anchor" Jsont.string ~enc:(fun c -> c.anchor) 70 - |> Jsont.Object.mem "resolved" Jsont.bool ~dec_absent:false ~enc:(fun c -> 68 + |> Json.Object.opt_mem "quotedFileContent" quoted_jsont ~enc:(fun _ -> None) 69 + |> Json.Object.opt_mem "anchor" Json.string ~enc:(fun c -> c.anchor) 70 + |> Json.Object.mem "resolved" Json.bool ~dec_absent:false ~enc:(fun c -> 71 71 c.resolved) 72 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 72 + |> Json.Object.skip_unknown |> Json.Object.finish 73 73 74 74 type raw_list = { comments : t list } 75 75 76 76 let list_jsont = 77 - Jsont.Object.map ~kind:"comment_list" (fun comments -> { comments }) 78 - |> Jsont.Object.mem "comments" (Jsont.list comment_jsont) ~dec_absent:[] 77 + Json.Object.map ~kind:"comment_list" (fun comments -> { comments }) 78 + |> Json.Object.mem "comments" (Json.list comment_jsont) ~dec_absent:[] 79 79 ~enc:(fun r -> r.comments) 80 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 80 + |> Json.Object.skip_unknown |> Json.Object.finish 81 81 82 82 let of_json_string body = 83 - match Jsont_bytesrw.decode_string list_jsont body with 83 + match Json_bytesrw.decode_string list_jsont body with 84 84 | Error e -> err_json_decode e 85 85 | Ok r -> Ok r.comments 86 86
+5 -5
lib/document.ml
··· 8 8 let id d = d.document_id 9 9 let title d = d.title 10 10 let to_json d = d.raw 11 - let mem_name ((n, _) : Jsont.name) = n 11 + let mem_name ((n, _) : Json.name) = n 12 12 13 13 (* Walk the document JSON and extract plain text. 14 14 ··· 101 101 102 102 let top_string json field = 103 103 match json with 104 - | Jsont.Object (members, _) -> ( 104 + | Json.Object (members, _) -> ( 105 105 match List.find_opt (fun (name, _) -> mem_name name = field) members with 106 - | Some (_, Jsont.String (s, _)) -> s 106 + | Some (_, Json.String (s, _)) -> s 107 107 | _ -> "") 108 108 | _ -> "" 109 109 110 110 let of_json_string body = 111 - match Jsont_bytesrw.decode_string Jsont.json body with 111 + match Json_bytesrw.decode_string Json.json body with 112 112 | Error e -> err_json_decode e 113 113 | Ok json -> 114 114 let document_id = top_string json "documentId" in ··· 116 116 Ok { document_id; title; raw = body } 117 117 118 118 let to_text d = 119 - match Jsont_bytesrw.decode_string Jsont.json d.raw with 119 + match Json_bytesrw.decode_string Json.json d.raw with 120 120 | Error _ -> "" 121 121 | Ok json -> extract_text json
+2 -2
lib/dune
··· 7 7 fmt 8 8 gauth 9 9 http 10 - jsont 11 - jsont.bytesrw 10 + json 11 + json.bytesrw 12 12 logs 13 13 oauth 14 14 requests
+9 -9
lib/markdown.ml
··· 6 6 we only generate. Tests round-trip the output through 7 7 Cmarkit.Doc.of_string to confirm it parses cleanly. *) 8 8 9 - let mem_name ((n, _) : Jsont.name) = n 9 + let mem_name ((n, _) : Json.name) = n 10 10 11 11 (* Find a named member on an Object node. *) 12 12 let member json field = 13 13 match json with 14 - | Jsont.Object (members, _) -> 14 + | Json.Object (members, _) -> 15 15 List.find_map 16 16 (fun (name, v) -> if mem_name name = field then Some v else None) 17 17 members 18 18 | _ -> None 19 19 20 - let as_string = function Jsont.String (s, _) -> Some s | _ -> None 21 - let as_bool = function Jsont.Bool (b, _) -> Some b | _ -> None 22 - let as_array = function Jsont.Array (l, _) -> Some l | _ -> None 23 - let string_or = function Some (Jsont.String (s, _)) -> s | _ -> "" 20 + let as_string = function Json.String (s, _) -> Some s | _ -> None 21 + let as_bool = function Json.Bool (b, _) -> Some b | _ -> None 22 + let as_array = function Json.Array (l, _) -> Some l | _ -> None 23 + let string_or = function Some (Json.String (s, _)) -> s | _ -> "" 24 24 25 25 (* -- Inline escaping ------------------------------------------ *) 26 26 ··· 88 88 let nesting = 89 89 match 90 90 Option.bind (member b "nestingLevel") (function 91 - | Jsont.Number (n, _) -> Some n 91 + | Json.Number (n, _) -> Some n 92 92 | _ -> None) 93 93 with 94 94 | Some n -> int_of_float n ··· 385 385 let render_document buf doc_json = 386 386 let title = 387 387 match member doc_json "title" with 388 - | Some (Jsont.String (s, _)) -> s 388 + | Some (Json.String (s, _)) -> s 389 389 | _ -> "" 390 390 in 391 391 let starts_with_title = ··· 413 413 | None -> () 414 414 415 415 let of_document doc = 416 - match Jsont_bytesrw.decode_string Jsont.json (Document.to_json doc) with 416 + match Json_bytesrw.decode_string Json.json (Document.to_json doc) with 417 417 | Error _ -> "" 418 418 | Ok json -> 419 419 let buf = Buffer.create 4096 in
+6 -6
lib/store.ml
··· 12 12 type client = { client_id : string; client_secret : string } 13 13 14 14 let client_jsont = 15 - Jsont.Object.map ~kind:"gdocs_client" (fun client_id client_secret -> 15 + Json.Object.map ~kind:"gdocs_client" (fun client_id client_secret -> 16 16 { client_id; client_secret }) 17 - |> Jsont.Object.mem "client_id" Jsont.string ~enc:(fun c -> c.client_id) 18 - |> Jsont.Object.mem "client_secret" Jsont.string ~enc:(fun c -> 17 + |> Json.Object.mem "client_id" Json.string ~enc:(fun c -> c.client_id) 18 + |> Json.Object.mem "client_secret" Json.string ~enc:(fun c -> 19 19 c.client_secret) 20 - |> Jsont.Object.skip_unknown |> Jsont.Object.finish 20 + |> Json.Object.skip_unknown |> Json.Object.finish 21 21 22 22 let save_file path data = 23 23 Eio.Path.save ~create:(`Or_truncate 0o600) path data; ··· 29 29 if Eio.Path.is_file path then Some (Eio.Path.load path) else None 30 30 31 31 let save_client fs c = 32 - match Jsont_bytesrw.encode_string client_jsont c with 32 + match Json_bytesrw.encode_string client_jsont c with 33 33 | Ok s -> save_file (client_path fs) s 34 34 | Error e -> Fmt.failwith "encode client: %s" e 35 35 ··· 37 37 match load_file (client_path fs) with 38 38 | None -> None 39 39 | Some body -> ( 40 - match Jsont_bytesrw.decode_string client_jsont body with 40 + match Json_bytesrw.decode_string client_jsont body with 41 41 | Ok c -> Some c 42 42 | Error _ -> None) 43 43