OCaml library and CLI for OCI and Docker image manipulation
0
fork

Configure Feed

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

codec: let open Json.Codec in cleanup across 16 medium files

10-19 usages each: linkedin/{profile,post}, space-dtn/daemon/config,
gdocs/comments, freebox/{switch,calls,firewall,parental,auth},
slack/team, requests/oauth, oci/spec/{manifest,intoto},
meross/timers, atp/atp/lex, gauth.

Same pattern: per-let `let open Json.Codec in` inside codec bodies,
`Json.Codec.list` qualified at the API call sites that wrap codecs
into HTTP requests. No record-field clashes worth annotating in this
batch.

+35 -37
+15 -14
lib/spec/intoto.ml
··· 9 9 type subject = { name : string; digest : (string * string) list } 10 10 11 11 let digest_map_jsont = 12 - Json.Codec.Object.as_string_map Json.Codec.string 13 - |> Json.Codec.map ~kind:"digest_map" 12 + let open Json.Codec in 13 + Object.as_string_map string 14 + |> map ~kind:"digest_map" 14 15 ~dec:(fun m -> 15 16 let module M = Map.Make (String) in 16 17 M.fold (fun k v acc -> (k, v) :: acc) m []) ··· 19 20 List.fold_left (fun m (k, v) -> M.add k v m) M.empty alist) 20 21 21 22 let subject_jsont = 22 - Json.Codec.Object.map ~kind:"subject" (fun name digest -> { name; digest }) 23 - |> Json.Codec.Object.mem "name" Json.Codec.string ~enc:(fun s -> s.name) 24 - |> Json.Codec.Object.mem "digest" digest_map_jsont ~enc:(fun s -> s.digest) 25 - |> Json.Codec.Object.finish 23 + let open Json.Codec in 24 + Object.map ~kind:"subject" (fun name digest -> { name; digest }) 25 + |> Object.mem "name" string ~enc:(fun s -> s.name) 26 + |> Object.mem "digest" digest_map_jsont ~enc:(fun s -> s.digest) 27 + |> Object.finish 26 28 27 29 type t = { 28 30 type_ : string; ··· 36 38 t.predicate_type (List.length t.subject) 37 39 38 40 let jsont = 39 - Json.Codec.Object.map ~kind:"intoto_statement" 41 + let open Json.Codec in 42 + Object.map ~kind:"intoto_statement" 40 43 (fun type_ predicate_type subject predicate -> 41 44 let predicate = Json.Value.to_string predicate in 42 45 { type_; predicate_type; subject; predicate }) 43 - |> Json.Codec.Object.mem "_type" Json.Codec.string ~enc:(fun t -> t.type_) 44 - |> Json.Codec.Object.mem "predicateType" Json.Codec.string ~enc:(fun t -> 45 - t.predicate_type) 46 - |> Json.Codec.Object.mem "subject" (Json.Codec.list subject_jsont) 47 - ~enc:(fun t -> t.subject) 48 - |> Json.Codec.Object.mem "predicate" Json.Codec.Value.t ~enc:(fun t -> 46 + |> Object.mem "_type" string ~enc:(fun t -> t.type_) 47 + |> Object.mem "predicateType" string ~enc:(fun t -> t.predicate_type) 48 + |> Object.mem "subject" (list subject_jsont) ~enc:(fun t -> t.subject) 49 + |> Object.mem "predicate" Value.t ~enc:(fun t -> 49 50 match Json.Value.of_string t.predicate with 50 51 | Ok json -> json 51 52 | Error _ -> Json.Null ((), Json.Meta.none)) 52 - |> Json.Codec.Object.finish 53 + |> Object.finish 53 54 54 55 let of_string s = 55 56 match Json.of_string jsont s with
+20 -23
lib/spec/manifest.ml
··· 2 2 open Result.Syntax 3 3 4 4 let annotations_jsont = 5 - map_jsont 6 - (fun s -> Ok (Annotation.of_string s)) 7 - Annotation.to_string Json.Codec.string 5 + let open Json.Codec in 6 + map_jsont (fun s -> Ok (Annotation.of_string s)) Annotation.to_string string 8 7 9 8 module OCI = struct 10 9 type t = { ··· 17 16 } 18 17 19 18 let jsont = 20 - Json.Codec.Object.map ~kind:"oci_manifest" 19 + let open Json.Codec in 20 + Object.map ~kind:"oci_manifest" 21 21 (fun 22 22 version _media_type artifact_type config layers subject annotations -> 23 23 { ··· 28 28 subject; 29 29 annotations = Option.value ~default:[] annotations; 30 30 }) 31 - |> Json.Codec.Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 32 - |> Json.Codec.Object.mem "mediaType" Json.Codec.string ~enc:(fun _ -> 31 + |> Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 32 + |> Object.mem "mediaType" string ~enc:(fun _ -> 33 33 Media_type.to_string (OCI Image_manifest)) 34 - |> Json.Codec.Object.opt_mem "artifactType" Json.Codec.string ~enc:(fun t -> 35 - t.artifact_type) 36 - |> Json.Codec.Object.mem "config" Descriptor.jsont ~enc:(fun t -> t.config) 37 - |> Json.Codec.Object.mem "layers" (Json.Codec.list Descriptor.jsont) 38 - ~enc:(fun t -> t.layers) 39 - |> Json.Codec.Object.opt_mem "subject" Descriptor.jsont ~enc:(fun t -> 40 - t.subject) 41 - |> Json.Codec.Object.opt_mem "annotations" annotations_jsont ~enc:(fun t -> 34 + |> Object.opt_mem "artifactType" string ~enc:(fun t -> t.artifact_type) 35 + |> Object.mem "config" Descriptor.jsont ~enc:(fun t -> t.config) 36 + |> Object.mem "layers" (list Descriptor.jsont) ~enc:(fun t -> t.layers) 37 + |> Object.opt_mem "subject" Descriptor.jsont ~enc:(fun t -> t.subject) 38 + |> Object.opt_mem "annotations" annotations_jsont ~enc:(fun t -> 42 39 if t.annotations = [] then None else Some t.annotations) 43 - |> Json.Codec.Object.finish 40 + |> Object.finish 44 41 45 42 let of_yojson json = 46 43 match Json.decode jsont json with ··· 104 101 type t = { version : v2; config : Descriptor.t; layers : Descriptor.t list } 105 102 106 103 let jsont = 107 - Json.Codec.Object.map ~kind:"docker_manifest" 108 - (fun version _media_type config layers -> { version; config; layers }) 109 - |> Json.Codec.Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 110 - |> Json.Codec.Object.mem "mediaType" Json.Codec.string ~enc:(fun _ -> 104 + let open Json.Codec in 105 + Object.map ~kind:"docker_manifest" (fun version _media_type config layers -> 106 + { version; config; layers }) 107 + |> Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 108 + |> Object.mem "mediaType" string ~enc:(fun _ -> 111 109 Media_type.to_string (Docker Image_manifest)) 112 - |> Json.Codec.Object.mem "config" Descriptor.jsont ~enc:(fun t -> t.config) 113 - |> Json.Codec.Object.mem "layers" (Json.Codec.list Descriptor.jsont) 114 - ~enc:(fun t -> t.layers) 115 - |> Json.Codec.Object.finish 110 + |> Object.mem "config" Descriptor.jsont ~enc:(fun t -> t.config) 111 + |> Object.mem "layers" (list Descriptor.jsont) ~enc:(fun t -> t.layers) 112 + |> Object.finish 116 113 117 114 let of_yojson json = 118 115 match Json.decode jsont json with