From 056fcabaeec238a7aa927df39a90acea028b1aa0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 22 Nov 2026 13:58:16 +0100 Subject: Added an option for loading a value content without the multivaluated fields (allow single query) --- lib/model/field.ml | 36 +++++++----------------------------- lib/model/field.mli | 9 --------- lib/model/types.ml | 50 ++++++-------------------------------------------- lib/model/types.mli | 45 ++++++--------------------------------------- 4 files changed, 19 insertions(+), 121 deletions(-) (limited to 'lib/model') diff --git a/lib/model/field.ml b/lib/model/field.ml index 241a9df..42a2d2a 100644 --- a/lib/model/field.ml +++ b/lib/model/field.ml @@ -6,8 +6,8 @@ type 't field_ex = T : ('db, 'ocaml, 't) Types.t -> 't field_ex type 't t = | F : { - named : ('db, 'ocaml, 't) Types.t Types.named; - (** Name and type of the field, tied together *) + name : Identifier.t; + t : ('db, 'ocaml, 't) Types.t; label : textI18n; placeholder : textI18n option; icon : unit option; @@ -17,15 +17,14 @@ type 't t = (** Display the field when the criteria is valid *) } -> 't t - (** The record is a GADT so that [named] keeps its existential data type - ['a] — this is what lets {!named_of} re-stamp it with a known type. - The type stays abstract in the interface. *) + (** The record is a GADT so that [t] keeps its type parameters ['db] and + ['ocaml] existential. The type stays abstract in the interface. *) -let name : 'ref t -> Identifier.t = fun (F f) -> Types.name f.named +let name : 'ref t -> Identifier.t = fun (F f) -> f.name 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 (Types.typ f.named) +let type_ : 'ref t -> 'ref field_ex = fun (F f) -> T f.t 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 @@ -42,25 +41,4 @@ let create : 't t = fun (T typ) label ?placeholder ?icon ?(required = false) ?(validation = []) ?criteria name -> - F - { - named = Types.named ~name ~typ; - label; - placeholder; - icon; - required; - validation; - criteria; - } - -let named_of : type db ocaml ref. - ref t -> - (db, ocaml, ref) Types.t -> - (db, ocaml, ref) Types.t Types.named option = - fun (F f) typ -> - match Types.eq typ f.named.typ with - | None -> None - | Some Type.Equal -> ( - match Types.eq_ocaml typ f.named.typ with - | None -> None - | Some Type.Equal -> Some f.named) + F { name; t = typ; label; placeholder; icon; required; validation; criteria } diff --git a/lib/model/field.mli b/lib/model/field.mli index 3a19ab8..2217f97 100644 --- a/lib/model/field.mli +++ b/lib/model/field.mli @@ -7,15 +7,6 @@ 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) 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 {!Types.eq} and {!Types.eq_ocaml}); [None] on type - mismatch *) - val create : 'ref field_ex -> textI18n -> diff --git a/lib/model/types.ml b/lib/model/types.ml index ee244d3..7226d6f 100644 --- a/lib/model/types.ml +++ b/lib/model/types.ml @@ -49,8 +49,12 @@ let default_value : type a b c. (a, b, c) t -> a = function | MonoReference _ -> None | MultiReference _ -> raise Not_found -(** Constructor-level equality on the ['db] representation *) -let eq : type a b x y c. (a, x, c) t -> (b, y, c) t -> (a, b) Type.eq option = +(** Constructor-level equality: [eq t1 t2] is [Some Equal] when [t1] and [t2] + have the same constructor. The pair ['a * 'x] is injective, so [Equal] + proves both ['a = 'b] (the database representations) and ['x = 'y] (the code + representations) at once *) +let eq : type a b x y c. + (a, x, c) t -> (b, y, c) t -> (a * x, b * y) Type.eq option = fun t1 t2 -> match (t1, t2) with | MultiReference _, MultiReference _ -> Some Type.Equal @@ -58,45 +62,3 @@ let eq : type a b x y c. (a, x, c) t -> (b, y, c) t -> (a, b) Type.eq option = | Integer, Integer -> Some Type.Equal | Text, Text -> Some Type.Equal | _ -> None - -(** Constructor-level equality on the ['ocaml] representation *) -let eq_ocaml : type a b x y c. - (a, x, c) t -> (b, y, c) t -> (x, y) Type.eq option = - fun t1 t2 -> - match (t1, t2) with - | MultiReference _, MultiReference _ -> Some Type.Equal - | MonoReference _, MonoReference _ -> Some Type.Equal - | Integer, Integer -> Some Type.Equal - | Text, Text -> Some Type.Equal - | _ -> None - -type 'typ named = { - name : Identifier.t; (** The internal name of the field *) - typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) -} -(** 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]). *) - -(** Build a named type from a name and a type — no uniqueness involved, so - values built on the fly denote the same field *) -let named : name:Identifier.t -> typ:'typ -> 'typ named = - fun ~name ~typ -> { name; typ } - -let name : 'typ named -> Identifier.t = fun n -> n.name -let typ : 'typ named -> 'typ = fun n -> n.typ - -(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same - field — same name — and their types match, which also proves that their - ['ocaml] representations are equal *) -let provably_equal (type a b x y c) (n1 : (a, x, c) t named) - (n2 : (b, y, c) t named) : (x, y) Type.eq option = - if Identifier.equal n1.name n2.name then eq_ocaml n1.typ n2.typ else None - -(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching - types *) -let same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool = - fun n1 n2 -> provably_equal n1 n2 <> None diff --git a/lib/model/types.mli b/lib/model/types.mli index 81c9d5b..12f9c79 100644 --- a/lib/model/types.mli +++ b/lib/model/types.mli @@ -50,43 +50,10 @@ type 'target multireference = (int64, int64 Seq.t, 'target) t val default_value : ('a, 'b, 'c) t -> 'a (** The value to insert in the database when the field is empty *) -val eq : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('a, 'b) Type.eq option -(** Constructor-level equality on the ['db] representation: [eq t1 t2] is - [Some Equal] when [t1] and [t2] have the same constructor, which also proves - ['a = 'b] *) +val eq : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('a * 'x, 'b * 'y) Type.eq option +(** Constructor-level equality: [eq t1 t2] is [Some Equal] when [t1] and [t2] + have the same constructor. -val eq_ocaml : ('a, 'x, 'c) t -> ('b, 'y, 'c) t -> ('x, 'y) Type.eq option -(** Constructor-level equality on the ['ocaml] representation: [eq_ocaml t1 t2] - is [Some Equal] when [t1] and [t2] have the same constructor, which also - proves ['x = 'y] *) - -type 'typ named = { - name : Identifier.t; (** The internal name of the field *) - typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) -} -(** 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]). *) - -val named : name:Identifier.t -> typ:'typ -> 'typ named -(** Build a named type from a name and a type — no uniqueness involved, so - values built on the fly denote the same field *) - -val name : 'typ named -> Identifier.t -(** The name of the field *) - -val typ : 'typ named -> 'typ -(** The type of the named field *) - -val provably_equal : - ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> ('x, 'y) Type.eq option -(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same - field — same name — and their types match, which also proves that their - ['ocaml] representations are equal *) - -val same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool -(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching - types *) + Since the pair type is injective, [Equal] proves at once that ['a = 'b] (the + database representations match) and ['x = 'y] (the code representations + match). *) -- cgit v1.2.3