diff options
Diffstat (limited to 'lib/model')
| -rw-r--r-- | lib/model/content.ml | 5 | ||||
| -rw-r--r-- | lib/model/data.ml | 6 | ||||
| -rw-r--r-- | lib/model/data.mli | 10 | ||||
| -rw-r--r-- | lib/model/field.ml | 18 | ||||
| -rw-r--r-- | lib/model/field.mli | 10 | ||||
| -rw-r--r-- | lib/model/identifier.ml | 1 | ||||
| -rw-r--r-- | lib/model/model.ml | 6 | ||||
| -rw-r--r-- | lib/model/model.mli | 26 | ||||
| -rw-r--r-- | lib/model/path.ml | 6 | ||||
| -rw-r--r-- | lib/model/types.ml (renamed from lib/model/typ.ml) | 6 | ||||
| -rw-r--r-- | lib/model/types.mli (renamed from lib/model/typ.mli) | 12 |
11 files changed, 56 insertions, 50 deletions
diff --git a/lib/model/content.ml b/lib/model/content.ml index 7b9d9a4..a5e5c10 100644 --- a/lib/model/content.ml +++ b/lib/model/content.ml @@ -32,7 +32,8 @@ let fields : 'a t -> 'a Field.t Seq.t = let find_target : 'a t -> string -> 'a option = fun t name -> let feature_opt = - Seq.find (fun f -> String.equal (Identifier.to_string (Field.name f)) name) + Seq.find + (fun f -> String.equal (Identifier.to_string (Field.name f)) name) (fields t) in @@ -40,5 +41,5 @@ let find_target : 'a t -> string -> 'a option = let* feature : 'a Field.t = feature_opt in let (T feature_type) = Field.type_ feature in match feature_type with - | MonoReference t | MultiReference t -> Some t.Typ.t + | MonoReference t | MultiReference t -> Some t.Types.t | Integer | Text -> None diff --git a/lib/model/data.ml b/lib/model/data.ml index 9c44203..2d00c4e 100644 --- a/lib/model/data.ml +++ b/lib/model/data.ml @@ -8,15 +8,15 @@ representation of the field, e.g. [string option] or [int64 option]) and over ['t], the target of the field for references — a reference is held as an [int64] (the id of the target row), while ['t] records what it points to. - The field type {!Typ.t} stays in the model package; only the data itself + The field type {!Types.t} stays in the model package; only the data itself lives here. *) type ('ocaml, 't) data = | None - | V : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data + | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data let none : ('ocaml, 't) data = None -let v : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data = +let v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data = fun (typ, value) -> V (typ, value) type 't any = Any : ('ocaml, 't) data -> 't any [@@unboxed] diff --git a/lib/model/data.mli b/lib/model/data.mli index 6773589..37e7267 100644 --- a/lib/model/data.mli +++ b/lib/model/data.mli @@ -8,18 +8,18 @@ data held (e.g. [string option], [int64 option], or [int64 Seq.t] for a multivalued reference), and over ['t], the target of the field for references. The DB representation ['db] appears only inside the field type - carried by the constructors. The field type {!Typ.t} stays in the model + carried by the constructors. The field type {!Types.t} stays in the model package; only the data itself lives here. *) type ('ocaml, 't) data = private | None - | V : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data + | V : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data val none : ('ocaml, 't) data (** [none] tells the field is empty in the database (or left as is, on update) *) -val v : ('db, 'ocaml, 't) Typ.t * 'ocaml -> ('ocaml, 't) data +val v : ('db, 'ocaml, 't) Types.t * 'ocaml -> ('ocaml, 't) data (** [v (typ, value)] is the value for the field, in its code representation ['ocaml] — e.g. a single [string option], or an [int64 Seq.t] for a multivalued reference. The field type [typ] is also reported: it ties the @@ -39,7 +39,7 @@ val any : ('ocaml, 't) data -> 't any (* Function providing the data of each field to insert in the database *) let f : string -> Reference.target any = function - | "siret" -> any (v (Typ.Text, Some "siret")) - | "name" -> any (v (Typ.Text, Some "name")) + | "siret" -> any (v (Types.Text, Some "siret")) + | "name" -> any (v (Types.Text, Some "name")) | _ -> any none ] *) diff --git a/lib/model/field.ml b/lib/model/field.ml index feb712d..241a9df 100644 --- a/lib/model/field.ml +++ b/lib/model/field.ml @@ -2,11 +2,11 @@ type textI18n = (string * string) list (** A label is just an association list*) type validation = { rule : string list Dsl.t; message : textI18n } -type 't field_ex = T : ('db, 'ocaml, 't) Typ.t -> 't field_ex +type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex type 't t = | F : { - named : ('db, 'ocaml, 't) Typ.t Typ.named; + named : ('db, 'ocaml, 't) Types.t Types.named; (** Name and type of the field, tied together *) label : textI18n; placeholder : textI18n option; @@ -21,11 +21,11 @@ type 't t = ['a] — this is what lets {!named_of} re-stamp it with a known type. The type stays abstract in the interface. *) -let name : 'ref t -> Identifier.t = fun (F f) -> Typ.name f.named +let name : 'ref t -> Identifier.t = fun (F f) -> Types.name f.named let label : 'ref t -> textI18n = fun (F f) -> f.label let placeholder : 'ref t -> textI18n option = fun (F f) -> f.placeholder let icon : 'ref t -> unit option = fun (F f) -> f.icon -let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T (Typ.typ f.named) +let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T (Types.typ f.named) let required : 'ref t -> bool = fun (F f) -> f.required let validation : 'ref t -> validation list = fun (F f) -> f.validation let criteria : 'ref t -> string list Dsl.t option = fun (F f) -> f.criteria @@ -44,7 +44,7 @@ let create : ?criteria name -> F { - named = Typ.named ~name ~typ; + named = Types.named ~name ~typ; label; placeholder; icon; @@ -54,11 +54,13 @@ let create : } let named_of : type db ocaml ref. - ref t -> (db, ocaml, ref) Typ.t -> ((db, ocaml, ref) Typ.t) Typ.named option = + ref t -> + (db, ocaml, ref) Types.t -> + (db, ocaml, ref) Types.t Types.named option = fun (F f) typ -> - match Typ.eq typ f.named.typ with + match Types.eq typ f.named.typ with | None -> None | Some Type.Equal -> ( - match Typ.eq_ocaml typ f.named.typ with + match Types.eq_ocaml typ f.named.typ with | None -> None | Some Type.Equal -> Some f.named) diff --git a/lib/model/field.mli b/lib/model/field.mli index 0619f33..3a19ab8 100644 --- a/lib/model/field.mli +++ b/lib/model/field.mli @@ -2,16 +2,18 @@ type textI18n = (string * string) list (** A label is just an association list*) type validation = { rule : string list Dsl.t; message : textI18n } -type 't field_ex = T : ('db, 'ocaml, 't) Typ.t -> 't field_ex +type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex type 'ref t (** Description of a field *) val named_of : - 'ref t -> ('db, 'ocaml, 'ref) Typ.t -> (('db, 'ocaml, 'ref) Typ.t) Typ.named option -(** [named_of field typ] is [Some named] — the field's {!Typ.named} type, + 'ref t -> + ('db, 'ocaml, 'ref) Types.t -> + ('db, 'ocaml, 'ref) Types.t Types.named option +(** [named_of field typ] is [Some named] — the field's {!Types.named} type, stamped with ['db] and ['ocaml] — when [typ] matches the declared type of - [field] (checked with {!Typ.eq} and {!Typ.eq_ocaml}); [None] on type + [field] (checked with {!Types.eq} and {!Types.eq_ocaml}); [None] on type mismatch *) val create : diff --git a/lib/model/identifier.ml b/lib/model/identifier.ml index f1a981e..d7d1f3c 100644 --- a/lib/model/identifier.ml +++ b/lib/model/identifier.ml @@ -25,6 +25,7 @@ let to_string : t -> string = fun id -> id (** The fixed columns of the generated schema, predefined so that the SQL generation can refer to them directly. *) let id : t = of_string "id" + let parent : t = of_string "parent" let target : t = of_string "target" let quote : t -> string = fun id -> "\"" ^ id ^ "\"" diff --git a/lib/model/model.ml b/lib/model/model.ml index c3e5b5b..81d8883 100644 --- a/lib/model/model.ml +++ b/lib/model/model.ml @@ -4,7 +4,7 @@ module Identifier = Identifier module Dsl = Dsl -module Typ = Typ +module Types = Types module Data = Data module Reference = Reference module DataList = Data_list @@ -22,5 +22,5 @@ type content = target Content.t type section = target Section.t type field = target Field.t type field_ex = target Field.field_ex -type reference = target Typ.reference -type ('db, 'ocaml) typ = ('db, 'ocaml, target) Typ.t +type reference = target Types.reference +type ('db, 'ocaml) typ = ('db, 'ocaml, target) Types.t diff --git a/lib/model/model.mli b/lib/model/model.mli index 0326eb2..29d6234 100644 --- a/lib/model/model.mli +++ b/lib/model/model.mli @@ -39,8 +39,8 @@ - {!Identifier} — the names of contents and fields, validated so that they are always safe to embed as SQL identifiers. - {!Content}, {!Section}, {!Field} — the structure of the model. - - {!Typ} — the field types (the nature of the data; the data itself lives in - the value package as [Value.value]). + - {!Types} — the field types (the nature of the data; the data itself lives + in the value package as [Value.value]). - {!Reference} — a link from a reference field to its target content. - {!DataList} — a static list declared in the configuration: referenceable, but not editable by the user. @@ -85,25 +85,25 @@ type content = target Content.t (** A content : the element produced by the configuration loader and manipulated by the query and rendering layers. *) -module Typ = Typ +module Types = Types (** The type of a field, and the values a field can carry. A field type is one of: - - {!Typ.Text} — a string, stored as a nullable column; - - {!Typ.Integer} — an integer, stored as a nullable column; - - {!Typ.MonoReference} — a reference to a single target ({!target}), stored - as a nullable foreign key for a content, or as a plain column for a static - list; - - {!Typ.MultiReference} — a reference to several targets of the same kind, + - {!Types.Text} — a string, stored as a nullable column; + - {!Types.Integer} — an integer, stored as a nullable column; + - {!Types.MonoReference} — a reference to a single target ({!target}), + stored as a nullable foreign key for a content, or as a plain column for a + static list; + - {!Types.MultiReference} — a reference to several targets of the same kind, stored in a dedicated table ["content.field"]. - A {!Typ.reference} record carries the target of a reference field (a + A {!Types.reference} record carries the target of a reference field (a {!target}) plus optional [constraints] restricting the allowed values. The data provided for a field when inserting/updating is a [Value.value] (from the value package): [None] (leave as is), [V] (a single value) or [Seq] (a sequence of references, for multivalued fields). *) -type ('db, 'ocaml) typ = ('db, 'ocaml, target) Typ.t +type ('db, 'ocaml) typ = ('db, 'ocaml, target) Types.t (** A field type descriptor ; ['db] is the database representation of the field (e.g. [string option] for a text field, [int64] for a multivalued reference) *) @@ -116,7 +116,7 @@ module Reference = Reference necessarily exists, and resolved once all contents are registered. This is what allows contents to reference each other, including cyclically. *) -type reference = target Typ.reference +type reference = target Types.reference (** A reference field target: a {!target}, plus optional constraints *) module Data = Data @@ -147,7 +147,7 @@ module Field = Field (** A field of a content. A field has a {!Identifier.t} name, a [label] as a list of - [(language, text)] pairs, a {!Typ.field_ex} type, a [required] flag, and + [(language, text)] pairs, a {!Types.field_ex} type, a [required] flag, and optionally a [placeholder], [validation] rules (a {!Dsl} expression plus a per-language error message) and a [criteria] controlling when the field is displayed. Build one with {!Field.create}. *) diff --git a/lib/model/path.ml b/lib/model/path.ml index dd62864..374b23b 100644 --- a/lib/model/path.ml +++ b/lib/model/path.ml @@ -23,9 +23,9 @@ let target_of_field : Reference.target Field.t -> Reference.target option = fun field -> let (Field.T ty) = Field.type_ field in match ty with - | Typ.MonoReference reference | Typ.MultiReference reference -> - Some reference.Typ.t - | Typ.Text | Typ.Integer -> None + | Types.MonoReference reference | Types.MultiReference reference -> + Some reference.Types.t + | Types.Text | Types.Integer -> None (** Resolve a path from a target. diff --git a/lib/model/typ.ml b/lib/model/types.ml index a13653e..ee244d3 100644 --- a/lib/model/typ.ml +++ b/lib/model/types.ml @@ -11,9 +11,9 @@ type 'a reference = { (** 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.target}. Use the aliases [Model.reference], - [Model.content], [Model.field], ... at the use sites. *) + cycle ([Reference] depends on [Content], which depends on [Field]/[Types]); + in 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. diff --git a/lib/model/typ.mli b/lib/model/types.mli index 42350a3..81c9d5b 100644 --- a/lib/model/typ.mli +++ b/lib/model/types.mli @@ -9,8 +9,8 @@ dedicated table (['db = int64]) but manipulated as a sequence in code (['ocaml = int64 Seq.t]). - The third parameter ['t] is the target of the field when it is a - reference (a content or a static list, i.e. {!Model.target}). *) + The third parameter ['t] is the target of the field when it is a reference + (a content or a static list, i.e. {!Model.target}). *) type 'a reference = { t : 'a; @@ -25,7 +25,7 @@ type 'a reference = { (** 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]); + cycle ([Reference] depends on [Content], which depends on [Field]/[Types]); in practice ['a] is always {!Model.target}. *) type ('db, 'ocaml, 't) t = @@ -67,9 +67,9 @@ type 'typ named = { (** A named field type: a {!t} together with the field's name. Named types are built on the fly with {!named} (e.g. from a field, see - {!Field.named_of}) and used locally as typed handles — e.g. to read the - data of a field from a value. A pre-built instance exists for the reserved - field ["id"] (see [Value.id_ref]). *) + {!Field.named_of}) and used locally as typed handles — e.g. to read the data + of a field from a value. A pre-built instance exists for the reserved field + ["id"] (see [Value.id_ref]). *) val named : name:Identifier.t -> typ:'typ -> 'typ named (** Build a named type from a name and a type — no uniqueness involved, so |
