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 15 small lib files

5-7 usages each. atp/blob_ref, freebox/{calls,firewall,http,parental,
switch}, meross/{consumption,electricity,timers}, oci/spec/{manifest_list,
media_type}, sbom, slack/{channel,reaction,user}. Several `name` and
`id` accessors annotated with `(t : T)` so the codec body's
`~enc:(fun u -> Some (id u))` form picks the local record over
mem_map. freebox call sites that wrap codecs into HTTP requests keep
`Json.Codec.list` / `Json.Codec.null` qualified.

+14 -13
+7 -7
lib/spec/manifest_list.ml
··· 3 3 type t = { version : v2; manifests : Descriptor.t list } 4 4 5 5 let jsont = 6 - Json.Codec.Object.map ~kind:"manifest_list" 7 - (fun version _media_type manifests -> { version; manifests }) 8 - |> Json.Codec.Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 9 - |> Json.Codec.Object.mem "mediaType" Json.Codec.string ~enc:(fun _ -> 6 + let open Json.Codec in 7 + Object.map ~kind:"manifest_list" (fun version _media_type manifests -> 8 + { version; manifests }) 9 + |> Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 10 + |> Object.mem "mediaType" string ~enc:(fun _ -> 10 11 Media_type.to_string (Docker Image_manifest_list)) 11 - |> Json.Codec.Object.mem "manifests" (Json.Codec.list Descriptor.jsont) 12 - ~enc:(fun t -> t.manifests) 13 - |> Json.Codec.Object.finish 12 + |> Object.mem "manifests" (list Descriptor.jsont) ~enc:(fun t -> t.manifests) 13 + |> Object.finish 14 14 15 15 let of_yojson json = 16 16 match Json.decode jsont json with
+7 -6
lib/spec/media_type.ml
··· 106 106 | OCI t -> OCI.to_string t 107 107 108 108 let jsont = 109 - Json.Codec.map ~kind:"media_type" 109 + let open Json.Codec in 110 + map ~kind:"media_type" 110 111 ~dec:(fun s -> 111 112 match of_string s with 112 113 | Ok t -> t 113 114 | Error (`Msg e) -> 114 115 Json.Error.failf Json.Meta.none "invalid media_type: %s" e) 115 - ~enc:to_string Json.Codec.string 116 + ~enc:to_string string 116 117 117 118 let extractor = 118 - Json.Codec.Object.map ~kind:"extractor" (fun media_type -> media_type) 119 - |> Json.Codec.Object.opt_mem "mediaType" Json.Codec.string ~enc:(fun _ -> 120 - None) 121 - |> Json.Codec.Object.skip_unknown |> Json.Codec.Object.finish 119 + let open Json.Codec in 120 + Object.map ~kind:"extractor" (fun media_type -> media_type) 121 + |> Object.opt_mem "mediaType" string ~enc:(fun _ -> None) 122 + |> Object.skip_unknown |> Object.finish 122 123 123 124 let guess str = 124 125 if str = "" then None