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 10 more files

slack/{message,file,reminder,team,bin/login}, oci/spec/{index,intoto,
platform}, paseto, agent/todo. 8-14 usages each. slack/team and
slack/reminder records have `id` (and team also `name`); hoisted
`let id (t : t) = t.id` / `name` accessors and used `~enc:id` in
codecs. oci/spec/intoto subject record has `name`; uses `(s :
subject)` annotations on the enc lambdas. The rest are clash-free.

+26 -31
+12 -15
lib/spec/index.ml
··· 1 1 open Common 2 2 3 3 let annotations_jsont = 4 - map_jsont 5 - (fun s -> Ok (Annotation.of_string s)) 6 - Annotation.to_string Json.Codec.string 4 + let open Json.Codec in 5 + map_jsont (fun s -> Ok (Annotation.of_string s)) Annotation.to_string string 7 6 8 7 type t = { 9 8 version : v2; (** Schema version - always 2 *) ··· 15 14 } 16 15 17 16 let jsont = 18 - Json.Codec.Object.map ~kind:"index" 17 + let open Json.Codec in 18 + Object.map ~kind:"index" 19 19 (fun 20 20 version 21 21 _media_type ··· 33 33 subject; 34 34 annotations = Option.value ~default:[] annotations; 35 35 }) 36 - |> Json.Codec.Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 37 - |> Json.Codec.Object.opt_mem "mediaType" Json.Codec.string ~enc:(fun _ -> 36 + |> Object.mem "schemaVersion" v2_jsont ~enc:(fun t -> t.version) 37 + |> Object.opt_mem "mediaType" string ~enc:(fun _ -> 38 38 Some (Media_type.to_string (OCI Image_index))) 39 - |> Json.Codec.Object.opt_mem "artifactType" rfc_6838_jsont ~enc:(fun t -> 39 + |> Object.opt_mem "artifactType" rfc_6838_jsont ~enc:(fun t -> 40 40 t.artifact_type) 41 - |> Json.Codec.Object.mem "manifests" (Json.Codec.list Descriptor.jsont) 42 - ~enc:(fun t -> t.manifests) 43 - |> Json.Codec.Object.opt_mem "platform" Platform.jsont ~enc:(fun t -> 44 - t.platform) 45 - |> Json.Codec.Object.opt_mem "subject" Descriptor.jsont ~enc:(fun t -> 46 - t.subject) 47 - |> Json.Codec.Object.opt_mem "annotations" annotations_jsont ~enc:(fun t -> 41 + |> Object.mem "manifests" (list Descriptor.jsont) ~enc:(fun t -> t.manifests) 42 + |> Object.opt_mem "platform" Platform.jsont ~enc:(fun t -> t.platform) 43 + |> Object.opt_mem "subject" Descriptor.jsont ~enc:(fun t -> t.subject) 44 + |> Object.opt_mem "annotations" annotations_jsont ~enc:(fun t -> 48 45 if t.annotations = [] then None else Some t.annotations) 49 - |> Json.Codec.Object.finish 46 + |> Object.finish 50 47 51 48 let of_yojson json = 52 49 match Json.decode jsont json with
+3 -3
lib/spec/intoto.ml
··· 21 21 22 22 let subject_jsont = 23 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) 24 + Object.map ~kind:"subject" (fun name digest : subject -> { name; digest }) 25 + |> Object.mem "name" string ~enc:(fun (s : subject) -> s.name) 26 + |> Object.mem "digest" digest_map_jsont ~enc:(fun (s : subject) -> s.digest) 27 27 |> Object.finish 28 28 29 29 type t = {
+11 -13
lib/spec/platform.ml
··· 12 12 } 13 13 14 14 let jsont = 15 - Json.Codec.Object.map ~kind:"platform" 15 + let open Json.Codec in 16 + Object.map ~kind:"platform" 16 17 (fun architecture os os_version os_features variant features -> 17 18 { 18 19 architecture; ··· 22 23 variant; 23 24 features = Option.value ~default:[] features; 24 25 }) 25 - |> Json.Codec.Object.mem "architecture" Arch.jsont ~enc:(fun p -> 26 - p.architecture) 27 - |> Json.Codec.Object.mem "os" OS.jsont ~enc:(fun p -> p.os) 28 - |> Json.Codec.Object.opt_mem "os.version" Json.Codec.string ~enc:(fun p -> 29 - p.os_version) 30 - |> Json.Codec.Object.opt_mem "os.features" (Json.Codec.list Json.Codec.string) 31 - ~enc:(fun p -> if p.os_features = [] then None else Some p.os_features) 32 - |> Json.Codec.Object.opt_mem "variant" Arch.variant_jsont ~enc:(fun p -> 33 - p.variant) 34 - |> Json.Codec.Object.opt_mem "features" (Json.Codec.list Json.Codec.string) 35 - ~enc:(fun p -> if p.features = [] then None else Some p.features) 36 - |> Json.Codec.Object.finish 26 + |> Object.mem "architecture" Arch.jsont ~enc:(fun p -> p.architecture) 27 + |> Object.mem "os" OS.jsont ~enc:(fun p -> p.os) 28 + |> Object.opt_mem "os.version" string ~enc:(fun p -> p.os_version) 29 + |> Object.opt_mem "os.features" (list string) ~enc:(fun p -> 30 + if p.os_features = [] then None else Some p.os_features) 31 + |> Object.opt_mem "variant" Arch.variant_jsont ~enc:(fun p -> p.variant) 32 + |> Object.opt_mem "features" (list string) ~enc:(fun p -> 33 + if p.features = [] then None else Some p.features) 34 + |> Object.finish 37 35 38 36 let v ?os_version ?(os_features = []) ?variant architecture os = 39 37 { architecture; os; os_version; os_features; variant; features = [] }