summaryrefslogtreecommitdiff
path: root/lib/model
diff options
context:
space:
mode:
Diffstat (limited to 'lib/model')
-rw-r--r--lib/model/data_list.ml1
-rw-r--r--lib/model/data_list.mli18
-rw-r--r--lib/model/model.ml5
-rw-r--r--lib/model/model.mli23
-rw-r--r--lib/model/reference.ml24
-rw-r--r--lib/model/reference.mli10
-rw-r--r--lib/model/typ.ml24
7 files changed, 64 insertions, 41 deletions
diff --git a/lib/model/data_list.ml b/lib/model/data_list.ml
new file mode 100644
index 0000000..11fb0b4
--- /dev/null
+++ b/lib/model/data_list.ml
@@ -0,0 +1 @@
+type 'a t = { id : Identifier.t; fields : 'a Field.t list }
diff --git a/lib/model/data_list.mli b/lib/model/data_list.mli
new file mode 100644
index 0000000..e74bf23
--- /dev/null
+++ b/lib/model/data_list.mli
@@ -0,0 +1,18 @@
+(** A static list declared in the configuration.
+
+ Unlike contents, lists are not editable by the user: their entries are
+ loaded by the data provider (from a file or any other source, which is not
+ part of the model) and they can only be referenced from fields.
+
+ Lists have their own fields, declared directly under the ["field"] key of
+ the list — unlike contents, there is no section grouping them. The fields
+ use the same {!Field.t} as the content fields; the only restriction is that
+ a reference field in a list can only target another list, declared before it
+ (a list cannot reference itself or a later list). *)
+
+type 'a t = {
+ id : Identifier.t;
+ (** Name of the list; usable as the target of a reference field, and as
+ the name of its dedicated table in the database *)
+ fields : 'a Field.t list; (** The fields of each entry of the list *)
+}
diff --git a/lib/model/model.ml b/lib/model/model.ml
index 25179ff..20914b1 100644
--- a/lib/model/model.ml
+++ b/lib/model/model.ml
@@ -6,15 +6,16 @@ module Identifier = Identifier
module Dsl = Dsl
module Typ = Typ
module Reference = Reference
-module List = List
+module DataList = Data_list
module Field = Field
module Section = Section
module Content = Content
(** The target of a reference field, resolved: a lazy pointer to a content, or
a static list. *)
-type target = Reference.t Typ.target
+type target = Reference.target
+type list = target Data_list.t
type content = target Content.t
type section = target Section.t
type field = target Field.t
diff --git a/lib/model/model.mli b/lib/model/model.mli
index 8c097f3..e81a844 100644
--- a/lib/model/model.mli
+++ b/lib/model/model.mli
@@ -7,7 +7,7 @@
list of {!section}s, and optionally sub-contents (a content with a parent is
a subcontent). Each section groups a list of {!field}s. A field has a name,
a label translated in several languages, a {!typ} — text, integer, or a
- reference to another content or to a static {!List.t} (single or
+ reference to another content or to a static {!DataList.t} (single or
multivalued) — and optional validation rules expressed in a small expression
language (see {!Dsl}).
@@ -41,8 +41,8 @@
- {!Content}, {!Section}, {!Field} — the structure of the model.
- {!Typ} — the field types, and the values carried by fields.
- {!Reference} — a link from a reference field to its target content.
- - {!List} — a static list declared in the configuration: referenceable, but
- not editable by the user.
+ - {!DataList} — a static list declared in the configuration: referenceable,
+ but not editable by the user.
- {!Dsl} — the expression language used in validation rules and display
criteria.
@@ -72,9 +72,13 @@ module Content = Content
{!Content.parent} / {!Content.root}; iterate over all its fields with
{!Content.fields}. *)
-type target = Reference.t Typ.target
+type target = Reference.target
(** The target of a reference field, resolved: either a lazy pointer to a
- content ({!Typ.Content}) or a static {!List.t} ({!Typ.List}). *)
+ content ({!Reference.Content}) or a static {!DataList.t}
+ ({!Reference.List}). *)
+
+type list = target Data_list.t
+(** A static list, resolved: its fields are typed with {!target} *)
type content = target Content.t
(** A content : the element produced by the configuration loader and manipulated
@@ -114,10 +118,11 @@ module Reference = Reference
type reference = target Typ.reference
(** A reference field target: a {!target}, plus optional constraints *)
-module List = List
-(** A static list declared in the configuration: its entries are loaded from a
- source (e.g. a CSV file) and the list can be referenced from fields, but it
- is not editable by the user. *)
+module DataList = Data_list
+(** A static list declared in the configuration: its entries are loaded by the
+ data provider and the list can be referenced from fields, but it is not
+ editable by the user. Lists have their own fields (no sections); a reference
+ field in a list can only target another list. *)
module Section = Section
(** A group of fields displayed together, with a per-language [label] and an
diff --git a/lib/model/reference.ml b/lib/model/reference.ml
index 67bbcaf..bdacf54 100644
--- a/lib/model/reference.ml
+++ b/lib/model/reference.ml
@@ -1,11 +1,17 @@
-(** A lazy pointer to a resolved content. The payload is
- [t Typ.target Content.t] — i.e. {!Model.content} — and is only forced once
- every content has been registered (see [Configuration.Ast.check]), which
- is what allows cyclic references between contents. *)
-type t = T : t Typ.target Content.t Lazy.t -> t [@@unboxed]
+(** A lazy pointer to a resolved content. The payload is [target Content.t] —
+ i.e. {!Model.content} — and is only forced once every content has been
+ registered (see [Configuration.Ast.check]), which is what allows cyclic
+ references between contents. *)
+type t = T : target Content.t Lazy.t -> t [@@unboxed]
-let v : (unit -> t Typ.target Content.t) -> t =
- fun f -> T (lazy (f ()))
+(** The target of a reference field, resolved: either a lazy pointer to a
+ content, or a static list. The list case carries the list itself, whose own
+ fields are typed with this very [target] — references inside a list can
+ only target other lists (enforced by the configuration reader). *)
+and target =
+ | Content of t
+ | List of target Data_list.t
-let get : t -> t Typ.target Content.t = fun (T target) ->
- Lazy.force target
+let v : (unit -> target Content.t) -> t = fun f -> T (lazy (f ()))
+
+let get : t -> target Content.t = fun (T target) -> Lazy.force target
diff --git a/lib/model/reference.mli b/lib/model/reference.mli
index 63acf6c..2f9659b 100644
--- a/lib/model/reference.mli
+++ b/lib/model/reference.mli
@@ -1,4 +1,10 @@
type t
-val v : (unit -> t Typ.target Content.t) -> t
-val get : t -> t Typ.target Content.t
+and target =
+ | Content of t
+ | List of target Data_list.t
+ (** The target of a reference field: a content (through the lazy pointer)
+ or a static list *)
+
+val v : (unit -> target Content.t) -> t
+val get : t -> target Content.t
diff --git a/lib/model/typ.ml b/lib/model/typ.ml
index 9427b86..6168c4c 100644
--- a/lib/model/typ.ml
+++ b/lib/model/typ.ml
@@ -1,33 +1,19 @@
-(** The target of a reference field: either a content or a static list.
-
- Only the content side is parameterized: this module cannot depend on
- [Reference] (module cycle through [Content] and [Field]), whereas [List]
- only depends on [Identifier] and can be fixed here. At the resolved level
- (see {!Model.target}) ['c = Reference.t]. *)
-type 'c target =
- | Content of 'c
- | List of List.t
-
type 'a reference = {
t : 'a;
- (** The target of the reference: a {!target} at the resolved level. *)
+ (** The target of the reference: at the resolved level a
+ {!Reference.target} (aliased as {!Model.target}). *)
constraints : string list Dsl.t option;
(** 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 target [t] is a {!Model.Reference.t}: a lazy pointer to the content,
- created while the configuration is parsed (see [Configuration.Read_conf])
- and resolved once all the contents are registered. The laziness is what
- allows contents to reference each other cyclically.
+(** A reference from a field to a target (a content or a static list).
The type stays parameterized over ['a] only to break the module dependency
cycle ([Reference] depends on [Content], which depends on [Field]/[Typ]); in
- practice ['a] is always [Model.Reference.t]. Use the aliases
- [Model.reference], [Model.content], [Model.field], ... at the use sites. *)
+ practice ['a] is always {!Model.target}. Use the aliases [Model.reference],
+ [Model.content], [Model.field], ... at the use sites. *)
(** Each of the field types available in the application.