this repo has no description
1(** Standard JMAP Methods and Core/echo.
2 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-4> RFC 8620, Section 4
3 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5> RFC 8620, Section 5 *)
4
5open Jmap_types
6open Jmap_error
7
8(** Generic representation of a record type. Actual types defined elsewhere. *)
9type generic_record
10
11(** Arguments for /get methods.
12 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.1> RFC 8620, Section 5.1 *)
13module Get_args : sig
14 type 'record t
15
16 val account_id : 'record t -> id
17 val ids : 'record t -> id list option
18 val properties : 'record t -> string list option
19
20 val v :
21 account_id:id ->
22 ?ids:id list ->
23 ?properties:string list ->
24 unit ->
25 'record t
26end
27
28(** Response for /get methods.
29 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.1> RFC 8620, Section 5.1 *)
30module Get_response : sig
31 type 'record t
32
33 val account_id : 'record t -> id
34 val state : 'record t -> string
35 val list : 'record t -> 'record list
36 val not_found : 'record t -> id list
37
38 val v :
39 account_id:id ->
40 state:string ->
41 list:'record list ->
42 not_found:id list ->
43 unit ->
44 'record t
45end
46
47(** Arguments for /changes methods.
48 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.2> RFC 8620, Section 5.2 *)
49module Changes_args : sig
50 type t
51
52 val account_id : t -> id
53 val since_state : t -> string
54 val max_changes : t -> uint option
55
56 val v :
57 account_id:id ->
58 since_state:string ->
59 ?max_changes:uint ->
60 unit ->
61 t
62end
63
64(** Response for /changes methods.
65 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.2> RFC 8620, Section 5.2 *)
66module Changes_response : sig
67 type t
68
69 val account_id : t -> id
70 val old_state : t -> string
71 val new_state : t -> string
72 val has_more_changes : t -> bool
73 val created : t -> id list
74 val updated : t -> id list
75 val destroyed : t -> id list
76 val updated_properties : t -> string list option
77
78 val v :
79 account_id:id ->
80 old_state:string ->
81 new_state:string ->
82 has_more_changes:bool ->
83 created:id list ->
84 updated:id list ->
85 destroyed:id list ->
86 ?updated_properties:string list ->
87 unit ->
88 t
89end
90
91(** Patch object for /set update.
92 A list of (JSON Pointer path, value) pairs.
93 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.3> RFC 8620, Section 5.3 *)
94type patch_object = (json_pointer * Yojson.Safe.t) list
95
96(** Arguments for /set methods.
97 ['create_record] is the record type without server-set/immutable fields.
98 ['update_record] is the patch object type (usually [patch_object]).
99 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.3> RFC 8620, Section 5.3 *)
100module Set_args : sig
101 type ('create_record, 'update_record) t
102
103 val account_id : ('a, 'b) t -> id
104 val if_in_state : ('a, 'b) t -> string option
105 val create : ('a, 'b) t -> 'a id_map option
106 val update : ('a, 'b) t -> 'b id_map option
107 val destroy : ('a, 'b) t -> id list option
108 val on_success_destroy_original : ('a, 'b) t -> bool option
109 val destroy_from_if_in_state : ('a, 'b) t -> string option
110 val on_destroy_remove_emails : ('a, 'b) t -> bool option
111
112 val v :
113 account_id:id ->
114 ?if_in_state:string ->
115 ?create:'a id_map ->
116 ?update:'b id_map ->
117 ?destroy:id list ->
118 ?on_success_destroy_original:bool ->
119 ?destroy_from_if_in_state:string ->
120 ?on_destroy_remove_emails:bool ->
121 unit ->
122 ('a, 'b) t
123end
124
125(** Response for /set methods.
126 ['created_record_info] is the server-set info for created records.
127 ['updated_record_info] is the server-set/computed info for updated records.
128 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.3> RFC 8620, Section 5.3 *)
129module Set_response : sig
130 type ('created_record_info, 'updated_record_info) t
131
132 val account_id : ('a, 'b) t -> id
133 val old_state : ('a, 'b) t -> string option
134 val new_state : ('a, 'b) t -> string
135 val created : ('a, 'b) t -> 'a id_map option
136 val updated : ('a, 'b) t -> 'b option id_map option
137 val destroyed : ('a, 'b) t -> id list option
138 val not_created : ('a, 'b) t -> Set_error.t id_map option
139 val not_updated : ('a, 'b) t -> Set_error.t id_map option
140 val not_destroyed : ('a, 'b) t -> Set_error.t id_map option
141
142 val v :
143 account_id:id ->
144 ?old_state:string ->
145 new_state:string ->
146 ?created:'a id_map ->
147 ?updated:'b option id_map ->
148 ?destroyed:id list ->
149 ?not_created:Set_error.t id_map ->
150 ?not_updated:Set_error.t id_map ->
151 ?not_destroyed:Set_error.t id_map ->
152 unit ->
153 ('a, 'b) t
154end
155
156(** Arguments for /copy methods.
157 ['copy_record_override] contains the record id and override properties.
158 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.4> RFC 8620, Section 5.4 *)
159module Copy_args : sig
160 type 'copy_record_override t
161
162 val from_account_id : 'a t -> id
163 val if_from_in_state : 'a t -> string option
164 val account_id : 'a t -> id
165 val if_in_state : 'a t -> string option
166 val create : 'a t -> 'a id_map
167 val on_success_destroy_original : 'a t -> bool
168 val destroy_from_if_in_state : 'a t -> string option
169
170 val v :
171 from_account_id:id ->
172 ?if_from_in_state:string ->
173 account_id:id ->
174 ?if_in_state:string ->
175 create:'a id_map ->
176 ?on_success_destroy_original:bool ->
177 ?destroy_from_if_in_state:string ->
178 unit ->
179 'a t
180end
181
182(** Response for /copy methods.
183 ['created_record_info] is the server-set info for the created copy.
184 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.4> RFC 8620, Section 5.4 *)
185module Copy_response : sig
186 type 'created_record_info t
187
188 val from_account_id : 'a t -> id
189 val account_id : 'a t -> id
190 val old_state : 'a t -> string option
191 val new_state : 'a t -> string
192 val created : 'a t -> 'a id_map option
193 val not_created : 'a t -> Set_error.t id_map option
194
195 val v :
196 from_account_id:id ->
197 account_id:id ->
198 ?old_state:string ->
199 new_state:string ->
200 ?created:'a id_map ->
201 ?not_created:Set_error.t id_map ->
202 unit ->
203 'a t
204end
205
206(** Module for generic filter representation.
207 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.5> RFC 8620, Section 5.5 *)
208module Filter : sig
209 type t
210
211 (** Create a filter from a raw JSON condition *)
212 val condition : Yojson.Safe.t -> t
213
214 (** Create a filter with a logical operator (AND, OR, NOT) *)
215 val operator : [ `AND | `OR | `NOT ] -> t list -> t
216
217 (** Combine filters with AND *)
218 val and_ : t list -> t
219
220 (** Combine filters with OR *)
221 val or_ : t list -> t
222
223 (** Negate a filter with NOT *)
224 val not_ : t -> t
225
226 (** Convert a filter to JSON *)
227 val to_json : t -> Yojson.Safe.t
228
229 (** Predefined filter helpers *)
230
231 (** Create a filter for a text property containing a string *)
232 val text_contains : string -> string -> t
233
234 (** Create a filter for a property being equal to a value *)
235 val property_equals : string -> Yojson.Safe.t -> t
236
237 (** Create a filter for a property being not equal to a value *)
238 val property_not_equals : string -> Yojson.Safe.t -> t
239
240 (** Create a filter for a property being greater than a value *)
241 val property_gt : string -> Yojson.Safe.t -> t
242
243 (** Create a filter for a property being greater than or equal to a value *)
244 val property_ge : string -> Yojson.Safe.t -> t
245
246 (** Create a filter for a property being less than a value *)
247 val property_lt : string -> Yojson.Safe.t -> t
248
249 (** Create a filter for a property being less than or equal to a value *)
250 val property_le : string -> Yojson.Safe.t -> t
251
252 (** Create a filter for a property value being in a list *)
253 val property_in : string -> Yojson.Safe.t list -> t
254
255 (** Create a filter for a property value not being in a list *)
256 val property_not_in : string -> Yojson.Safe.t list -> t
257
258 (** Create a filter for a property being present (not null) *)
259 val property_exists : string -> t
260
261 (** Create a filter for a string property starting with a prefix *)
262 val string_starts_with : string -> string -> t
263
264 (** Create a filter for a string property ending with a suffix *)
265 val string_ends_with : string -> string -> t
266end
267
268
269
270(** Comparator for sorting.
271 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.5> RFC 8620, Section 5.5 *)
272module Comparator : sig
273 type t
274
275 val property : t -> string
276 val is_ascending : t -> bool option
277 val collation : t -> string option
278 val keyword : t -> string option
279 val other_fields : t -> Yojson.Safe.t string_map
280
281 val v :
282 property:string ->
283 ?is_ascending:bool ->
284 ?collation:string ->
285 ?keyword:string ->
286 ?other_fields:Yojson.Safe.t string_map ->
287 unit ->
288 t
289end
290
291(** Arguments for /query methods.
292 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.5> RFC 8620, Section 5.5 *)
293module Query_args : sig
294 type t
295
296 val account_id : t -> id
297 val filter : t -> Filter.t option
298 val sort : t -> Comparator.t list option
299 val position : t -> jint option
300 val anchor : t -> id option
301 val anchor_offset : t -> jint option
302 val limit : t -> uint option
303 val calculate_total : t -> bool option
304 val collapse_threads : t -> bool option
305 val sort_as_tree : t -> bool option
306 val filter_as_tree : t -> bool option
307
308 val v :
309 account_id:id ->
310 ?filter:Filter.t ->
311 ?sort:Comparator.t list ->
312 ?position:jint ->
313 ?anchor:id ->
314 ?anchor_offset:jint ->
315 ?limit:uint ->
316 ?calculate_total:bool ->
317 ?collapse_threads:bool ->
318 ?sort_as_tree:bool ->
319 ?filter_as_tree:bool ->
320 unit ->
321 t
322end
323
324(** Response for /query methods.
325 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.5> RFC 8620, Section 5.5 *)
326module Query_response : sig
327 type t
328
329 val account_id : t -> id
330 val query_state : t -> string
331 val can_calculate_changes : t -> bool
332 val position : t -> uint
333 val ids : t -> id list
334 val total : t -> uint option
335 val limit : t -> uint option
336
337 val v :
338 account_id:id ->
339 query_state:string ->
340 can_calculate_changes:bool ->
341 position:uint ->
342 ids:id list ->
343 ?total:uint ->
344 ?limit:uint ->
345 unit ->
346 t
347end
348
349(** Item indicating an added record in /queryChanges.
350 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.6> RFC 8620, Section 5.6 *)
351module Added_item : sig
352 type t
353
354 val id : t -> id
355 val index : t -> uint
356
357 val v :
358 id:id ->
359 index:uint ->
360 unit ->
361 t
362end
363
364(** Arguments for /queryChanges methods.
365 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.6> RFC 8620, Section 5.6 *)
366module Query_changes_args : sig
367 type t
368
369 val account_id : t -> id
370 val filter : t -> Filter.t option
371 val sort : t -> Comparator.t list option
372 val since_query_state : t -> string
373 val max_changes : t -> uint option
374 val up_to_id : t -> id option
375 val calculate_total : t -> bool option
376 val collapse_threads : t -> bool option
377
378 val v :
379 account_id:id ->
380 ?filter:Filter.t ->
381 ?sort:Comparator.t list ->
382 since_query_state:string ->
383 ?max_changes:uint ->
384 ?up_to_id:id ->
385 ?calculate_total:bool ->
386 ?collapse_threads:bool ->
387 unit ->
388 t
389end
390
391(** Response for /queryChanges methods.
392 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-5.6> RFC 8620, Section 5.6 *)
393module Query_changes_response : sig
394 type t
395
396 val account_id : t -> id
397 val old_query_state : t -> string
398 val new_query_state : t -> string
399 val total : t -> uint option
400 val removed : t -> id list
401 val added : t -> Added_item.t list
402
403 val v :
404 account_id:id ->
405 old_query_state:string ->
406 new_query_state:string ->
407 ?total:uint ->
408 removed:id list ->
409 added:Added_item.t list ->
410 unit ->
411 t
412end
413
414(** Core/echo method: Arguments are mirrored in the response.
415 @see <https://www.rfc-editor.org/rfc/rfc8620.html#section-4> RFC 8620, Section 4 *)
416type core_echo_args = Yojson.Safe.t
417type core_echo_response = Yojson.Safe.t