summaryrefslogtreecommitdiff
path: root/lib/model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/model')
-rw-r--r--lib/model/typ.ml30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/model/typ.ml b/lib/model/typ.ml
index 98429d6..c4acadc 100644
--- a/lib/model/typ.ml
+++ b/lib/model/typ.ml
@@ -1,8 +1,32 @@
type 'a reference = {
- t : 'a; (** The content targeted by this field. *)
+ t : 'a;
+ (** The target of the reference: a content name while the configuration is
+ being parsed, a [Model.Reference.t] once it is resolved. *)
constraints : string list Dsl.t option;
- (** Retrict only the values to thoses ones *)
+ (** Optionally restrict the values allowed for this field, as a DSL
+ expression read from the optional ["constraints"] key of the
+ configuration. Currently carried through to the consumers (e.g. to
+ filter the proposed values); [None] means no restriction. *)
}
+(** A reference from a field to a content.
+
+ The type is parameterized over the representation of the target ['a],
+ because the model is built in two phases:
+
+ - while the configuration is being parsed ([Configuration.Read_conf]), the
+ targeted content is not known yet: ['a] is the target as written in the
+ configuration file (the identifier of the content, paired with its raw
+ JSON value for error reporting);
+ - once the configuration is loaded and checked
+ ([Configuration.Ast.register_content]), [Field.map] rewrites every
+ reference so that ['a = Model.Reference.t], a lazy pointer to the actual
+ content (see {!Model.Reference}). The laziness is what allows contents to
+ reference each other cyclically.
+
+ Everywhere else in the application (query generation in [Query], HTML
+ rendering in [Html.Builder]), a field has type
+ [Model.Reference.t Model.Typ.reference], and the target content is obtained
+ with [Model.Reference.get]. *)
(** Each of the field types available in the application.
@@ -46,7 +70,7 @@ Example for inserting data
[
(* Function providing a value for each field to insert in the database *)
- let f : string -> Model.Reference.t Model.Field.value = function
+ let f : string -> Model.Reference.t Model.Typ.value = function
| "siret" -> V (Model.Typ.Text, Some "siret")
| "name" -> V (Model.Typ.Text, Some "name")
| _ -> None