OSV.dev vulnerability database client
0
fork

Configure Feed

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

ocaml-osv: rewrite README example to typecheck

Quick Start opened with [Eio_main.run] at top level (executes during
mdx) and the Filtering block referenced unbound [vulns]. Wrap each
block as a function ([run ()] for the live query, [summarise vulns]
for filtering), switch [Printf]/[Printf.eprintf] to [Fmt.pr]/[Fmt.epr],
and add the [eio*] / [fmt] libraries to the mdx stanza.

+24 -25
+23 -24
README.md
··· 27 27 ## Quick Start 28 28 29 29 ```ocaml 30 - Eio_main.run @@ fun env -> 31 - Eio.Switch.run @@ fun sw -> 32 - let vulns = 33 - Osv.query_purl ~sw ~net:env#net ~clock:env#clock 34 - "pkg:npm/lodash@4.17.20" 35 - in 36 - match vulns with 37 - | Ok vulns -> 38 - List.iter 39 - (fun v -> 40 - Printf.printf "%s [%s]: %s\n" v.Osv.id 41 - (Osv.severity_to_string v.severity) 42 - v.summary) 43 - vulns 44 - | Error msg -> 45 - Printf.eprintf "Query failed: %s\n" msg 30 + let run () = 31 + Eio_main.run @@ fun env -> 32 + Eio.Switch.run @@ fun sw -> 33 + match 34 + Osv.query_purl ~sw ~net:env#net ~clock:env#clock 35 + "pkg:npm/lodash@4.17.20" 36 + with 37 + | Ok vulns -> 38 + List.iter 39 + (fun v -> 40 + Fmt.pr "%s [%s]: %s@." v.Osv.id 41 + (Osv.severity_to_string v.severity) 42 + v.summary) 43 + vulns 44 + | Error msg -> Fmt.epr "Query failed: %s@." msg 46 45 ``` 47 46 48 47 ## Query Methods ··· 55 54 ## Filtering 56 55 57 56 ```ocaml 58 - (* Keep only high and critical vulnerabilities *) 59 - let critical = Osv.filter_severity ~min:High vulns 60 - 61 - (* Check if a fix is available *) 62 - let fixable = List.filter Osv.has_fix vulns 63 - 64 - (* Extract CVE identifiers *) 65 - let cves = List.concat_map Osv.cve_ids vulns 57 + let summarise (vulns : Osv.vulnerability list) = 58 + (* Keep only high and critical vulnerabilities. *) 59 + let critical = Osv.filter_severity ~min:High vulns in 60 + (* Check if a fix is available. *) 61 + let fixable = List.filter Osv.has_fix vulns in 62 + (* Extract CVE identifiers. *) 63 + let cves = List.concat_map Osv.cve_ids vulns in 64 + (List.length critical, List.length fixable, cves) 66 65 ``` 67 66 68 67 ## License
+1 -1
dune
··· 4 4 5 5 (mdx 6 6 (files README.md) 7 - (libraries osv eio_main)) 7 + (libraries osv eio_main eio eio.core eio.unix fmt))