mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 16:28:12 +03:00
refactor(api_web): factorizes the api_web code + updates .gitattributes
This commit is contained in:
parent
97b6e14740
commit
6e825906de
6
.gitattributes
vendored
6
.gitattributes
vendored
@ -2,8 +2,14 @@
|
||||
*.mld linguist-documentation
|
||||
*.md linguist-documentation
|
||||
*.hints linguist-generated
|
||||
|
||||
french_law/js/french_law.js binary linguist-generated
|
||||
|
||||
french_law/ocaml/law_source/allocations_familiales.ml binary linguist-generated
|
||||
french_law/ocaml/law_source/allocations_familiales_api_web.ml binary linguist-generated
|
||||
french_law/ocaml/law_source/unit_tests/tests_allocations_famiales.ml binary linguist-generated
|
||||
french_law/python/src/allocations_familiales.py binary linguist-generated
|
||||
|
||||
french_law/ocaml/law_source/aides_logement.ml binary linguist-generated
|
||||
french_law/ocaml/law_source/aides_logement_api_web.ml binary linguist-generated
|
||||
french_law/python/src/aides_logement.py binary linguist-generated
|
||||
|
9091
french_law/js/french_law.js
generated
9091
french_law/js/french_law.js
generated
File diff suppressed because one or more lines are too long
@ -17,58 +17,35 @@
|
||||
|
||||
open Js_of_ocaml
|
||||
open Law_source
|
||||
open Runtime_jsoo.Runtime
|
||||
module AF = Allocations_familiales
|
||||
module AF_web = Allocations_familiales_api_web
|
||||
module AL = Aides_logement
|
||||
module AL_web = Aides_logement_api_web
|
||||
|
||||
let throw_no_value_provided_error
|
||||
(position : Runtime_ocaml.Runtime.source_position) : 'a =
|
||||
let msg =
|
||||
Js.string
|
||||
(Format.asprintf
|
||||
"No rule applies in the given context to give a value to the variable \
|
||||
declared in file %s, position %d:%d--%d:%d."
|
||||
position.filename position.start_line position.start_column
|
||||
position.end_line position.end_column)
|
||||
in
|
||||
Js.Js_error.raise_
|
||||
(Js.Js_error.of_error
|
||||
(object%js
|
||||
val mutable name = Js.string "NoValueProvided"
|
||||
val mutable message = msg
|
||||
val mutable stack = Js.Optdef.empty
|
||||
method toString = msg
|
||||
end))
|
||||
|
||||
let _ =
|
||||
Js.export_all
|
||||
(object%js
|
||||
val eventsManager = Runtime_jsoo.Runtime.event_manager
|
||||
val eventsManager = event_manager
|
||||
|
||||
method computeAllocationsFamiliales
|
||||
: (AF_web.interface_allocations_familiales_in -> float) Js.callback =
|
||||
Js.wrap_callback (fun interface_allocations_familiales_in ->
|
||||
try
|
||||
let result =
|
||||
interface_allocations_familiales_in
|
||||
|> AF_web.interface_allocations_familiales
|
||||
in
|
||||
result##.iMontantVerseOut
|
||||
with Runtime_ocaml.Runtime.NoValueProvided position ->
|
||||
throw_no_value_provided_error position)
|
||||
execute_or_throw_no_value_provided_error (fun () ->
|
||||
let result =
|
||||
interface_allocations_familiales_in
|
||||
|> AF_web.interface_allocations_familiales
|
||||
in
|
||||
result##.iMontantVerseOut))
|
||||
|
||||
method computeAidesAuLogement
|
||||
: (AL_web.calculette_aides_au_logement_garde_alternee_in -> float)
|
||||
Js.callback =
|
||||
Js.wrap_callback (fun calculette_aides_au_logement_garde_alternee_in ->
|
||||
try
|
||||
let result :
|
||||
AL_web.calculette_aides_au_logement_garde_alternee_out Js.t =
|
||||
calculette_aides_au_logement_garde_alternee_in
|
||||
|> AL_web.calculette_aides_au_logement_garde_alternee
|
||||
in
|
||||
result##.aideFinaleOut
|
||||
with Runtime_ocaml.Runtime.NoValueProvided position ->
|
||||
throw_no_value_provided_error position)
|
||||
execute_or_throw_no_value_provided_error (fun () ->
|
||||
let result =
|
||||
calculette_aides_au_logement_garde_alternee_in
|
||||
|> AL_web.calculette_aides_au_logement_garde_alternee
|
||||
in
|
||||
result##.aideFinaleOut))
|
||||
end)
|
||||
|
@ -147,3 +147,23 @@ let event_manager : event_manager Js.t =
|
||||
end)
|
||||
(R_ocaml.retrieve_log ()))))
|
||||
end
|
||||
|
||||
let execute_or_throw_no_value_provided_error f =
|
||||
try f ()
|
||||
with R_ocaml.NoValueProvided pos ->
|
||||
let msg =
|
||||
Js.string
|
||||
(Format.asprintf
|
||||
"No rule applies in the given context to give a value to the \
|
||||
variable declared in file %s, position %d:%d--%d:%d."
|
||||
pos.filename pos.start_line pos.start_column pos.end_line
|
||||
pos.end_column)
|
||||
in
|
||||
Js.Js_error.raise_
|
||||
(Js.Js_error.of_error
|
||||
(object%js
|
||||
val mutable name = Js.string "NoValueProvided"
|
||||
val mutable message = msg
|
||||
val mutable stack = Js.Optdef.empty
|
||||
method toString = msg
|
||||
end))
|
||||
|
@ -88,7 +88,7 @@ class type event_manager =
|
||||
end
|
||||
|
||||
val event_manager : event_manager Js.t
|
||||
(** Composable JS object to retrieve and reset log events. *)
|
||||
(** JS object usable to retrieve and reset log events. *)
|
||||
|
||||
(** {1 Duration} *)
|
||||
|
||||
@ -107,3 +107,10 @@ val duration_to_jsoo : Runtime_ocaml.Runtime.duration -> duration Js.t
|
||||
|
||||
val date_of_jsoo : Js.date Js.t -> Runtime_ocaml.Runtime.date
|
||||
val date_to_jsoo : Runtime_ocaml.Runtime.date -> Js.date Js.t
|
||||
|
||||
(** {1 Error management} *)
|
||||
|
||||
val execute_or_throw_no_value_provided_error : (unit -> 'a) -> 'a
|
||||
(** [execute_or_throw_no_value_provided_error f] calls [f ()] and propagates the
|
||||
{!Runtime_ocaml.Runtime.NoValueProvided} exception by raising a JS error if
|
||||
needed.*)
|
||||
|
Loading…
Reference in New Issue
Block a user