summaryrefslogtreecommitdiff
path: root/lib/model/path.mli
blob: 50fd1b0cf3659d36588a27e3de25880883f4bcca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(** Evaluation of a path through the fields.

    A path is a list of field names ({!Identifier.t}), like the ones parsed from
    the DSL expressions ({!Dsl.ContentPath}, written [$a.b.c] in a
    configuration).

    Example: from a content [legalEntity], the path [entity; employee; country]
    follows the reference field [entity], then the reference field [employee] of
    its target, and resolves to the field [country] of the [employee] content —
    whose target is the list [country_list]. A path can also end on a
    non-reference field, e.g. [entity; country; code] resolves to the text field
    [code] of the [country_list] list, usable in a rule like
    [$entity.country.code = 'FR']. *)

val resolve :
  Reference.target -> Identifier.t list -> Reference.target Field.t option
(** Resolve a path from a target (a content or a list).

    Each segment is the name of a field of the current target. Intermediate
    segments must be reference fields: the evaluation moves to their target. The
    last segment can be any field.

    The result is the field designated by the last segment. [None] when a
    segment does not exist, or an intermediate segment is not a reference field.
*)

val resolve_from_content :
  Reference.target Content.t ->
  Identifier.t list ->
  Reference.target Field.t option
(** Resolve a path starting from a content *)

val target_of_field : Reference.target Field.t -> Reference.target option
(** The target of a reference field (the content or list it points to), [None]
    for the other field types *)