this repo has no description

json-pointer

+81 -10
+3 -2
dune-project
··· 21 21 (description 22 22 "A complete implementation of the JSON Meta Application Protocol (JMAP) as specified in RFC 8620 (core) and RFC 8621 (mail).") 23 23 (depends 24 - (ocaml (>= 4.14.0)) 24 + (ocaml (>= 5.4.0)) 25 25 (jsont (>= 0.2.0)) 26 + json-pointer 26 27 (ptime (>= 1.0.0)))) 27 28 28 29 (package ··· 30 31 (synopsis "JMAP client for Eio") 31 32 (description "High-level JMAP client using Eio for async I/O and the Requests HTTP library.") 32 33 (depends 33 - (ocaml (>= 4.14.0)) 34 + (ocaml (>= 5.4.0)) 34 35 (jmap (= :version)) 35 36 (jsont (>= 0.2.0)) 36 37 eio
+1 -1
jmap-eio.opam
··· 11 11 bug-reports: "https://github.com/avsm/ocaml-jmap/issues" 12 12 depends: [ 13 13 "dune" {>= "3.0"} 14 - "ocaml" {>= "4.14.0"} 14 + "ocaml" {>= "5.4.0"} 15 15 "jmap" {= version} 16 16 "jsont" {>= "0.2.0"} 17 17 "eio"
+2 -1
jmap.opam
··· 11 11 bug-reports: "https://github.com/avsm/ocaml-jmap/issues" 12 12 depends: [ 13 13 "dune" {>= "3.0"} 14 - "ocaml" {>= "4.14.0"} 14 + "ocaml" {>= "5.4.0"} 15 15 "jsont" {>= "0.2.0"} 16 + "json-pointer" 16 17 "ptime" {>= "1.0.0"} 17 18 "odoc" {with-doc} 18 19 ]
+1 -1
proto/dune
··· 1 1 (library 2 2 (name jmap_proto) 3 3 (public_name jmap) 4 - (libraries jsont ptime) 4 + (libraries jsont json-pointer ptime) 5 5 (modules 6 6 jmap_proto 7 7 id
+29 -2
proto/invocation.ml
··· 6 6 type result_reference = { 7 7 result_of : string; 8 8 name : string; 9 - path : string; 9 + path : Json_pointer.Jmap.t; 10 10 } 11 11 12 12 let result_reference ~result_of ~name ~path = 13 13 { result_of; name; path } 14 14 15 + let result_reference_of_strings ~result_of ~name ~path = 16 + { result_of; name; path = Json_pointer.Jmap.of_string path } 17 + 15 18 let result_reference_make result_of name path = 16 19 { result_of; name; path } 17 20 ··· 20 23 Jsont.Object.map ~kind result_reference_make 21 24 |> Jsont.Object.mem "resultOf" Jsont.string ~enc:(fun r -> r.result_of) 22 25 |> Jsont.Object.mem "name" Jsont.string ~enc:(fun r -> r.name) 23 - |> Jsont.Object.mem "path" Jsont.string ~enc:(fun r -> r.path) 26 + |> Jsont.Object.mem "path" Json_pointer.Jmap.jsont ~enc:(fun r -> r.path) 24 27 |> Jsont.Object.finish 28 + 29 + (* Result reference resolution *) 30 + 31 + let find_response ref ~responses = 32 + List.find_map (fun (call_id, name, json) -> 33 + if call_id = ref.result_of && name = ref.name 34 + then Some json 35 + else None 36 + ) responses 37 + 38 + let resolve ref ~responses codec = 39 + match find_response ref ~responses with 40 + | None -> 41 + Jsont.Error.msgf Jsont.Meta.none 42 + "Result reference: no response found for resultOf=%s name=%s" 43 + ref.result_of ref.name 44 + | Some json -> 45 + let extraction_codec = Json_pointer.Jmap.path ref.path codec in 46 + match Jsont.Json.decode' extraction_codec json with 47 + | Ok v -> v 48 + | Error e -> raise (Jsont.Error e) 49 + 50 + let resolve_ids ref ~responses = 51 + resolve ref ~responses (Jsont.list Jsont.string) 25 52 26 53 type t = { 27 54 name : string;
+45 -3
proto/invocation.mli
··· 9 9 10 10 (** A reference to a result from a previous method call. 11 11 12 - Used for back-referencing values within a single request. *) 12 + Used for back-referencing values within a single request. 13 + The path is a JMAP extended JSON Pointer (RFC 8620 Section 3.7) 14 + which may contain [*] wildcards for array mapping. *) 13 15 type result_reference = { 14 16 result_of : string; 15 17 (** The method call id to reference. *) 16 18 name : string; 17 19 (** The method name that was called. *) 18 - path : string; 19 - (** A JSON Pointer to the value within the result. *) 20 + path : Json_pointer.Jmap.t; 21 + (** A JMAP extended JSON Pointer to the value within the result. 22 + May contain [*] wildcards for mapping through arrays. *) 20 23 } 21 24 22 25 val result_reference : 23 26 result_of:string -> 24 27 name:string -> 28 + path:Json_pointer.Jmap.t -> 29 + result_reference 30 + 31 + val result_reference_of_strings : 32 + result_of:string -> 33 + name:string -> 25 34 path:string -> 26 35 result_reference 36 + (** [result_reference_of_strings] creates a result reference, parsing 37 + the path string into a JMAP pointer. 38 + @raise Jsont.Error if the path is not a valid JMAP pointer. *) 27 39 28 40 val result_reference_jsont : result_reference Jsont.t 41 + 42 + (** {2 Typed Extraction} 43 + 44 + These functions extract typed values from method responses using 45 + the result reference's path. *) 46 + 47 + val resolve_ids : 48 + result_reference -> 49 + responses:(string * string * Jsont.json) list -> 50 + string list 51 + (** [resolve_ids ref ~responses] resolves the result reference against 52 + the list of previous responses and extracts a list of string IDs. 53 + 54 + [responses] is a list of [(method_call_id, method_name, result_json)] 55 + tuples from previously executed method calls. 56 + 57 + This is the most common pattern in JMAP where result references are 58 + used to pass IDs between method calls. 59 + 60 + @raise Jsont.Error if resolution fails or the result is not a string list. *) 61 + 62 + val resolve : 63 + result_reference -> 64 + responses:(string * string * Jsont.json) list -> 65 + 'a Jsont.t -> 66 + 'a 67 + (** [resolve ref ~responses codec] resolves the result reference and 68 + decodes the extracted value with [codec]. 69 + 70 + @raise Jsont.Error if resolution fails or decoding fails. *) 29 71 30 72 (** {1 Invocations} *) 31 73