From 8708171877054c98aad45079d85d4e699420f2fe Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 19 Nov 2026 11:32:16 +0100 Subject: Added fields in lists --- test/insert.ml | 55 +++++++++++++++++++++++++------------------------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'test/insert.ml') diff --git a/test/insert.ml b/test/insert.ml index c30cde4..ee2c927 100644 --- a/test/insert.ml +++ b/test/insert.ml @@ -82,19 +82,17 @@ module Make (S : Decoders.Decode.S) = struct ( "reference", match Model.Content.find_target content key with | None -> S.fail "Not a feature" - | Some (Model.Typ.List list) -> + | Some (Model.Reference.List _ as t) -> (* A list is referenced by the id of one of its rows *) + let reference = + Model.Typ.MonoReference { t; constraints = None } + in S.map (fun v -> - Lwt.return - ( key, - Model.Typ.( - V - ( MonoReference - { t = Model.Typ.List list; constraints = None }, - Some (Int64.of_int v) )) )) + let value = Some (Int64.of_int v) in + Lwt.return (key, Model.Typ.V (reference, value))) S.int - | Some (Model.Typ.Content target_ref) -> + | Some (Model.Reference.Content target_ref as t) -> let target = Model.Reference.get target_ref in let* properties = self#properties target in let sequence = @@ -104,29 +102,24 @@ module Make (S : Decoders.Decode.S) = struct insert_and_get_result db target properties in let reference = - Model.Typ.{ t = Model.Typ.Content target_ref; constraints = None } + Model.Typ.MonoReference { t; constraints = None } in - Lwt.return - ( key, - Model.Typ.( - V (Model.Typ.MonoReference reference, Some id)) ) + Lwt.return (key, Model.Typ.V (reference, Some id)) in S.succeed sequence ); ( "references", match Model.Content.find_target content key with | None -> S.fail "Not a feature" - | Some (Model.Typ.List list) -> + | Some (Model.Reference.List _ as t) -> + let multireference = + Model.Typ.MultiReference { t; constraints = None } + in S.map (fun ids -> Lwt.return - ( key, - Model.Typ.( - Seq - ( MultiReference - { t = Model.Typ.List list; constraints = None }, - List.to_seq ids )) )) + (key, Model.Typ.Seq (multireference, List.to_seq ids))) (S.map (List.map ~f:Int64.of_int) (S.list S.int)) - | Some (Model.Typ.Content target_ref) -> + | Some (Model.Reference.Content target_ref as t) -> let target = Model.Reference.get target_ref in let* properties = self#values target in let sequence = @@ -134,14 +127,10 @@ module Make (S : Decoders.Decode.S) = struct self#insert_and_return_references target properties in let reference = - Model.Typ.{ t = Model.Typ.Content target_ref; constraints = None } + Model.Typ.MultiReference { t; constraints = None } in Lwt.return - ( key, - Model.Typ.( - Seq - ( Model.Typ.MultiReference reference, - List.to_seq ids )) ) + (key, Model.Typ.Seq (reference, List.to_seq ids)) in S.succeed sequence ); @@ -167,7 +156,10 @@ module Make (S : Decoders.Decode.S) = struct [ ( "content", fun v -> - match (Configuration.Ast.get_content conf) (Model.Identifier.of_string key) with + match + (Configuration.Ast.get_content conf) + (Model.Identifier.of_string key) + with | None -> Error (Decoders.Error.make "no content") | Some subcontent -> let values = self#values subcontent v in @@ -195,7 +187,10 @@ module Make (S : Decoders.Decode.S) = struct fun name -> (* In this syntax, the content is supposed to follow the definition and will never be None *) - let content = Configuration.Ast.get_content conf (Model.Identifier.of_string name) |> Option.get in + let content = + Configuration.Ast.get_content conf (Model.Identifier.of_string name) + |> Option.get + in let* properties = S.field_opt_or ~default:(Lwt.return []) "values" (self#values content) -- cgit v1.2.3